| |
This post is moved to Nios Wiki,
I don't recommend the buildroot approach to newbie now.
Please go to the nios wiki, http://nioswiki.jot.com/WikiHome/Operating...ms/%C2%B5Clinux
try out the prebuilt zImge if you have altera nios dev board,
install binary toolchain, and follow the uClinux-dist to build kernel and apps.
--Please note, this thread is getting too long, please post your question/discussion as a new topic over the uClinux forum. It will be easier to follow.
This is a guide to nios2 uClinux. We build tools, compile kernel and port applications for nios2 uclinux on a Linux platform.
Why build the tools when you have the IDE on Windows?
The IDE on Windows are not good for kernel/apps development. The IDE's compiler default to newlib, while we would use uClibc in uClinux.
The tools run much faster and less trouble on Linux. You will feel IDE moves like turtle after you use Linux.
If you want uClinux, you should work on Linux and learn Linux. You can learn a lot when working on Linux, and the "Linux know-how" is the key to success on nios2 uClinux.
You can find links to major linux distributions,
http://distrowatch.com/dwres.php?resource=major
Just add a PC to run Linux. You can use quartusII and nios2 on Windows to design hardware, then build sofware on Linux. You DON'T have to run quartusII on Linux. You can setup a samba server or client on Linux, so that they can share files. Always update your tools to the latest ones, ie, quartusII v6.0, niosII v6.0, ddr 3.4.0 at this moment.
If you are new to uClinux, it is very helpful to read the FAQ on the www.ucdot.org.
You should start with a mininal system with only nios2 cpu core,sdram,full featured timer,jtag/serial console and a cfi flash, (cfi flash can be dummy and removed later). Note, the interrupt vector (ie, execption vector) should be in uClinux program memory, ie sdram.
Note in Linux, irq 0 used to be auto-detected and that is not supported in Nios II, so you should not use irq 0 for your devices. Only timer_0 may use irq 0.
There is no MMU on current nios2, so no virtual memory,no shared objs/libs, no fork, and stack size is fixed.
The app exec format on uClinux is not ELF, but binary flat format, FLT.
We will use initramfs (which is quite new to uClinux), instead of romfs. The initramfs is compressed. The rootfs (initrd) image can be linked into the kernel, and make the booting easier. You don't need other devices, such as MTD,CF/IDE,NFS for rootfs to start up your nios2 uClinux. As they may be not available for a new custom board. You can mount other devices or filesystem later,eg jffs2, in user space.
Let's start it step by step.
You should use gcc3 to build this cross-compiler. the gcc4 has problem on binutils-2.15.
If you use Fedora core 5, you should select development packages during installation, and run "yum update" after installation. (redhat 9 is too old, that make failed)
There is compat-gcc-32 package.
If you have a working buildroot toolchain, there is no need to rebuild all each time. You should edit the build script and update only what is needed. During the build, if you fail (or too slow) when downloading (wget) some files, you can use your browser to search and download them from other sites into ~/download dir. Then you can edit the build script, and restart from the middle.
If you have old builds, and you want a fresh build from begin, you must remove all old build dirs. uncomment line1 of the build script, which will remove all old build dirs.
(Please NOTE, the latest buildroot/uClibc/busybox snapshot may still have problems on nios2, so we will download -20060320, the last known good shot, and save them as -snapshot instead in the build script.)
During the build, you can cut the command lines in this guide with your brower, and paste in the shell console or save to a script. So that you can save some typing and errors.
1. login with a user account, eg, jack. do not use root account.
your home dir will be /home/jack, or in short ~/
2. download microtronix's port of nios2 linux from the forum into the ~/download dir,
http://forum.niosforum.com/downloads/1_4/nios2linux-1.4.zip
3. download http://hungryhippo.jot.com/WikiHome/build.zip , into dir ~/download
The build script will download (using wget) the 20060320 snapshot ,untar, patch and make.
(The configs are binutils-2.15,gcc-3.4.6,uClibc-0.9.29-pre,busybox-1.1.1-pre0 and kernel header 2.6.11.)
The c++ and libstdc++ will be built, too. (but they still have problems to run)
The ~/rootfs dir will be created. The kenel will use this dir and ~/download/rootfs_list file to generate initramfs image.
You may edit the ~/download/rootfs_list file, to add or remove dev nodes.
There is a minimal .config file.
The uClinux-dist will be prepared in ~/uClinux-dist.
The apps ported by microtronix will be in ~/apps .
And the 2.6.11-uc0 kernel will be in ~/linux-2.6.x , with zImage, EPCS MTD,avalon watchdog drivers added.
4. You should include this PATH to use the cross gcc after it is built
Or you can update the path of the cross gcc in file ~/.bash_profile
so that it will be in the PATH when you login Linux.
Run this to verify that you have it in your command search path,
Run this to verify that you have the proper busybox in FLT format,
it should display the FLT header like this,
5. Then config and compile kernel.
If you use Altera CycloneII NIOS dev board with 2C35, the ptf file is altera/kits/nios2/examples/verilog/niosII_cycloneII_2c35/standard/ std_2C35.ptf,
and the sof is standard.sof . The ptf must match your board.
Here is the hwselect of std_2C35.ptf,
In menuconfig, you should select your serial or jtag console in menu,
If your user id and group id on Linux are not 500, change these to your id instead,
If you use DEII with 8M sdram, change the link address of the uncompress loader,
Then
Whenever you update the ~/rootfs, you have to compile the kernel and update the initramfs.
If you didn't see the "CPIO" and "GZIP" in compile message, the initramfs is not updated. You will have to remove the file usr/initramfs_list in kernel dir, and compile again to force the update of initramfs.
6. Now the compressed kernel image is ready, arch/nios2nommu/boot/zImage .
you can run it on windows,
First, download the sof of your hardware to your board with quartusII programmer,
Then open a nios2 sdk shell,
Note the drives mapping in nios2 sdk shell,
drive c: is /cygdrive/c/
if you map your linux home to h: on windows with samba server,
then drive h: is /cygdrive/h/
so the image file is
/cygdrive/h/linux-2.6.x/arch/nios2nommu/boot/zImage
Here is the boot message on my custom board,
(Note, don't use jtag uart in production, it will not run without a nios2-terminal connection)
7. After you have tested the uClinux from sdram, you may want to program the flash.
If you use EPCS flash, find out and change the sof path and epcs base below.
on nios2 sdk shell,
Or if you use cfi flash,
8. If you use EPCS, you can use jffs2 to provide a nonvolatile filesystem.
Check the very nice guide from Jdhar,
http://via.dynalias.org/svn/uclinux/doc/trunk/epcs-ug.pdf
In kernel menuconfig
Or if you use cfi flash, in kernel menuconfig,
Then rebuild the kernel, and boot nios2 uclinux.
It should display jffs2 support and detect mtd partitions.
here, /mnt is your mount dir. You can access files under the mount dir.
After you finish the access,
Note, you may have to erase the mtd part or preload jffs2 image with nios2-flash-programmer. You may have to customize the map file for different flash size and part size, in drivers/mtd/maps/
either epcs_map.c or altera.c .
9. To enable network support, eg if you use the Altera dev board with SMC91111,
Then rebuild the kernel, and boot nios2 uclinux.
It should detect the SCM 91111 device as eth0.
Then config the ip address and router.
You may add these setup for "eth0" to ~/rootfs/etc/inittab, follow the setup for "lo" .
So that eth0 will be configed by init.
10. If you will write driver, try out the hello world module example in the (must have) book "Linux Device Driver 3rd ed.".
In your kernel dir,
save the file to drivers/misc/hello.c
Add these lines to drivers/misc/Kconfig, before the "endmenu" line.
Add the line to drivers/misc/Makefile
Enable module support in menuconfig, then build the hello.ko module.
Boot nios2 uClinux, and load module
11. To compile a simple program, just add -elf2flt to link flag
Rebuild the kernel image for initramfs, boot nios2 uClinux, and run
The default stack size of application is 4KB, you can change it with -elf2flt="-s
will have stack size as 16KiB.
12. There are many applications built into busybox, enter 'help" to find out and read doc of busybox to learn them (eg udhcp server and client). You may config busybox, for more apps or to reduce size.
Rebuild the kernel image for initramfs.( I have removed old ~/rootfs for simplicity in the example, you may have to reinstall others, such as kernel modules, apps, configs)
If you want to add or port apps to uClinux, you should think of adding it to busybox first. Because there are no shared objs, add apps to busybox will save some memory usage.
13. to use the apps ported by Microtronix. I have patched the Makefile of inetd,ftpd and boa using ~/download/mx140apps.diff . You can look at the patches and update other apps yourself. Note you have to prepare proper config files to run these apps.
To run boa web server,
put your index.html and other content into ~/rootfs/home/httpd .
Then rebuild zImage for initramfs, boot nios2 uclinux, and run,
If you want cgi, check ~/uClinux-dist-test/user/cgi_generic , in next step.
To run inetd and ftpd,
to use anonymous ftp user,
add "ftp:x:14:50:FTP User:/home/ftp:" to etc/passwd
add "ftp:x:50:" to etc/group
make dir home/ftp
add ftp contents to home/ftp
rebuild zImage for initramfs, boot nios uclinux, and run,
inetd will invoke ftpd.
14. to use user apps ported to uClinux from uClinux-dist.
In menuconfig, select
Kernel/Library/Defaults Selection ---> [*] Customize Vendor/User Settings (NEW)
Then
It will enter user apps select, make your selection.
It has pre-selected dhcpd and net-snmp for testing.
To compile
copy apps to ~/rootfs
Note, you have to setup config files to ~/rootfs/etc for apps (eg dhcpd.conf), check doc for each of them. You should also check ~/uClinux-dist-test/romfs/etc for other config files.
~/uClinux-dist-test/user/dhcpd/samples/dhcpd.conf
Then rebuild zImage for initramfs.
(note, the boa port in uClinux-dist has problems on nios2)
To use telnetd, you have to enable pty in kernel config,
Select telnetd in uClinux-dist-test menuconfig,
add "telnet stream tcp nowait root /bin/telnetd" to ~/rootfs/etc/inetd.conf .
The password files are etc/passwd,etc/group,etc/shadow .
Use "addgroup","adduser","passwd" to create password on nios2 uClinux.
Then update the password files in ~/rootfs.
Add ptyp0-9 to , or remove the file etc/securetty, if you want root login on telnetd.
15. If you want to port apps, look in ~/buildroot/build_nios2/busybox, ~/apps, and ~/uClinux-dist-test/user first. There may be ported apps already.
Read the file INSTALL of it. If it need "./configure", you should check it with "./configure -help" and add options. You may have to update the file config.sub, check ~/download/uClinux-dist.diff on how to add $basic_machine, eg wget
Then run "./configure --host=nios2-linux-uclibc --disable-shared ...." ,a Makefile will be generated.
You may have to modify the Makefile or Rules.mak.
The stdinc dir and stdlib dir are default to uClibc.
So you don't need the "-nostdinc" and "-nostdlib" stuf.
You should add something like this to link flags to generate FLT obj,
Remove unused items, or that is for PC host.
You can setup the install path to your rootfs.
Then,"make","make install".
Remeber to update the kernel image for initramfs.
A sample patch, mtools-Makefile.diff, to mtools-3.9.10 Makefile is included in the attached build.zip.
16. to use CF drive on the dev board, download the example design,
http://forum.niosforum.com/downloads/cflash/cf5_0.zip
Run generate in SOPC and compile again with the latest quartusII and niosII.
Use the new sof and ptf, do hwselect and menuconfig for the kernel, select altera cf, and we want FAT support in this example,
Rebuild the kernel image for initramfs, boot nios2 uClinux, and it should detected the cf drive. assume part1 on the CF, /dev/hda1, is preformated FAT,
Or if the windows formats the CF without part,
after you finish the access, umount to flush the disk cache,
17. to use altera pci host bridge, check the hardware design example,
http://forum.niosforum.com/forum/index.php?showtopic=3059
dev0 is sdram,
dev1 is your pci device1, using irqn_0 to irqn_3 for inta..intd
dev2 is your pci device2, using irqn_4 to irqn_7 for inta..intd
(update the number of irqn in the example design to 8)
The PCI driver is in the altpci.zip, attached at the end of this post.
download to ~/download dir.
You have to update arch/nios2nommu/drivers/pci/altpci.c to fix up pci slots and irqs mapping for your board, seach for "FIX ME".
Then kernel menuconfig,
Bus options (PCI, PCMCIA, EISA, MCA, ISA)
[*] PCI support
[*] Altera PCI host bridge
And enable support for your pci devices.
18. STRONGLY RECOMMANDED, You should use subversion to help tracking your works, including both hardware and software.
Try "svn help", if you don't have it, install it with "yum install subversion". (for fedora core)
a. create the svn store, and check your original as rev1.
b. make your change to Makefile, misc.c ....
build and test....
c. after you finished, or when you want to save your change to store, as rev2
Then you can send webs.diff to others
d. when other get your diff file, he can apply the patch and get the same update from yours.
The subversion is very helpful. You can find more usages from the subversion guide on their web.
(PS..)
Marc sent the nios2 port of buildroot to busybox.net, and I did some patches, too. Vapier, one of the developers of busybox/uClibc/buildroot, helps to clean up the codes and incoporate into the "trunk". And he forwarded the elf2flt patches to uClinux dev team, too. All these works bring this project, simple and easy to use tools to build uClinux for the Nios2. Best thanks to marc, jdhar, and vapier.
Links:
marc's site for nios2, with buildroot
http://scorpius.homelinux.org/~marc/nios2.html
web site, docs and bug report for busybox/uClibc/buildroot/udhcp
http://busybox.net/
uclinux-dist, with a lots of apps ported to uclinux
http://www.uclinux.org/pub/uClinux/dist/
More information about Initramfs can be found on LWN, "Initramfs arrives" and
"Patch: Documentation for ramfs, rootfs, initramfs."
kernel tree and svn, including many drivers, (including epcs,mmc and i2c...) ported by Jdhar
http://via.dynalias.org/svn/uclinux/linux-2.6.11/trunk/
how to run the uClinux in NIOS2 in chinese by Alex.liu.
http://www.icwin.net/ShowArtitle.ASP?art_id=8313&cat_id=52[COLOR=red][COLOR=red]
Attached File(s)
altpci.zip ( 14.85k ) Number of downloads: 55
kernel2.zip ( 337.57k ) Number of downloads: 79
isp1362.zip ( 59.35k ) Number of downloads: 65
zimage.zip ( 4.8k ) Number of downloads: 48
build0411.zip ( 52.42k ) Number of downloads: 175