TryOutuClinux
Version 26, changed by hippo5329@yahoo.com.tw. 03/29/2007. Show version history
You may try out the uClinux on you Altera Nios II dev board before compiling anything. You can lean how to run a compiled program on your board. (It is a very basic and important step.)
The images for std_2c35 and de2_net are built from uClinux-dist-20060803 and 20070130. It uses the default Nios II config. It has Ethernet driver, telnetd, ftpd, and httpd servers. Please check UClinuxDist for booting up and usage.
Others were buit with the minimal config ~/download/kernel.config using the buildroot tools. for 2s60es and 1s10es, use 2s60 and 1s10es 's zImage.
If you have installed QuartusforLinux (recommended), you can run these examples on Linux.
For Altera Nios dev board 2C35 edition (not apply to dsp board 2C35),
1. use web brower to download zImage_std_2c35 file to a dir, eg, c:/download
In your quartus install dir, copy sof file from altera7.0/nios2eds/examples/verilog/niosII_cycloneII_2c35/standard/standard.sof to c:/temp
2. open a nios2 command shell from Windows Start-->Programs-->Altera-->Nios II 7.0 -->Nios II Command Shell
Note the drives mapping in nios2 shell, drive c: is /cygdrive/c/
3. in nios2 command shell, cd to that dir,
cd /cygdrive/c/download
nios2-configure-sof standard.sof
nios2-download -g zImage_std_2c35
it will show "Starting processor at address 0x04500000"
4. nios2-terminal
For DE2 2C35 dev board,
1. use web brower to download zImage_de2_net and DE2_NET.sof . put these files in c:/download. (which is regenerated from the DE2 System CD v. 1.5—ZIP , using Quartus II v7.0. The original sof has problems, and cause download verify error. And the updated ptf is system_0.ptf )
2. open a nios2 command shell from Windows Start-->Programs-->Altera-->Nios II 7.0 -->Nios II Command Shell
Note the drives mapping in nios2 shell, drive c: is /cygdrive/c/
3. in nios2 command shell, cd to that dir,
cd /cygdrive/c/download
nios2-configure-sof DE2_NET.sof
nios2-download -g zImage_de2_net
it will show "Starting processor at address 0x00d00000"
4. nios2-terminal
You may follow the messages displayed in UClinuxDist , and try out the example shell commands.
The sof and zImage didn't write to the cfi flash or epcs with nios2-configure-sof and nios2-download. They will lost after power off. Follow FlashProgrammer when you want them loaded after power on.
If you want to use full-featured examples or modify hardware, please check in SOPC builder, the interrupt vector (ie, exception vector) must be in sdram. Remap irq and don't use irq0. After you change SOPC project and regenerate sof, you have to "make clean" the uClinux-dist dir. Then start from "make vendor_hwselect ...." all over again
BinaryToolchain
Version 13, changed by hippo5329@yahoo.com.tw. 01/03/2007. Show version history
Attached are binary of the tools to run on Linux PC and root fs from buildroot. You can use it to compile kernel and apps.You don't have to download and build buildroot. (but you should try it later, when you got more experiences)
Login as a user account on Linux PC, eg, hippo. The user home dir will be /home/hippo, short form. as ~/ .
use web browser to download the cross gcc, nios2gcc.tar.bz2
put it in ~/download (ie /home/hippo/download )dir.
open a terminal. Run,
su - # your root passwd
tar jxf /home/hippo/download/nios2gcc.tar.bz2 -C /
exit
The cross gcc tools will be in /opt/nios dir.
Then setup the PATH for the cross gcc, you can update the path of the cross gcc in file ~/.bash_profile ( the file is hidden, you have to use "ls -a" to find it . For "gedit" use open Location, and enter the file name)
PATH=$PATH:/opt/nios2/bin:$HOME/bin
so that it will be in the PATH when you login Linux next time.
Or , to test it in current terminal session,
PATH=$PATH:/opt/nios2/bin
But the path will be lost when the session closed.
To verify the cross gcc, try out,
nios2-linux-uclibc-gcc -v
It should display the info,
Reading specs from /opt/nios2/lib/gcc/nios2-linux-uclibc/3.4.6/specs
Configured with: /root/buildroot/toolchain_build_nios2/gcc-3.4.6/configure --prefix=/opt/nios2 --build=i386-pc-linux-gnu --host=i386-pc-linux-gnu --target=nios2-linux-uclibc --enable-languages=c --enable-shared --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-nls --enable-threads --disable-multilib --enable-cxx-flags=-static
Thread model: posix
gcc version 3.4.6
Then try build kernel and apps as in the UClinuxDist .
OPTIONAL, the nios2libs.tar.bz2 are headers and lib for zlib,openssl,ncurses. (ssh need openssl and zlib) . You need to copy the runtime data from /opt/nios2/usr to your rootfs if you want to use them.
su - # your root passwd
tar jxf /home/hippo/download/nios2libs.tar.bz2 -C /
exit
If you want to follow BuildrootGuide (NOT recommended for newbie) to build kernel and apps,
cd ~
tar jxf nios2rootfs.tar.bz2
The rootfs with busybox will be in ~/rootfs and ~/download/rootfs_list .
Changelog of nios2gcc.tar.bz2
ver 3. fix elf2flt,flthdr for "-z" flag.
UClinuxDist
Version 121, changed by hippo5329@yahoo.com.tw. 04/01/2007. Show version history
uClinux-dist-20070130 release , the kernel is linux-2.6.19-uc1
This is about building the kernel and apps using uClinux-dist sources.
(This is different from the older buildroot guide approach. DO NOT MIX UP)
First, you should (recommended for newbie) install the BinaryToolchain
You need ncurses,ncurses-devel and bison installed on your Linux PC.
(Or you can build the cross compiler from sources with BuildrootGuide , but it might be difficult for beginner)
check if you have "cc" which is a symlink to "gcc" ?
which gcc
gcc -v
which cc
cc -v
if not,
su -
cd /usr/bin
ln -s gcc cc
Download the full source bzip2 archive,ie uClinux-dist-20070130.tar.bz2 from
uClinux-dist , to dir ~/download.
Or try this
link of the bz2, if the offical site dwon.
Download the nios2 patches
uClinux-dist-20070130-nios2-02.diff.gz to dir ~/download , which is attached at the end of this page. And
apply the patches for Nios II, ONLY ONCE.
# login as a user account, don't use root account.
cd ~
rm -rf uClinux-dist # you must remove or rename old dir, you must apply the patches ONLY ONCE.
tar jxf ~/download/uClinux-dist-20070130.tar.bz2
cd uClinux-dist
gunzip -c ~/download/uClinux-dist-20070130-nios2-02.diff.gz | patch -p0
still in uClinux-dist dir, DO NOT cd linux-2.6.x
make menuconfig
check if you have the correct target? Altera, nios2nommu, and Libc must be None.
Vendor/Product Selection --->
--- Select the Vendor you wish to target
(Altera) Vendor
--- Select the Product you wish to target
(nios2nommu) Altera Products
Kernel/Library/Defaults Selection --->
(linux-2.6.x) Kernel Version
(None) Libc Version
[*] Default all settings (lose changes)
[ ] Customize Kernel Settings
[ ] Customize Vendor/User Settings
[ ] Update Default Vendor Settings
Then <exit> <exit> <yes>
DO NOT change any other setting until first successful boot.
Setup memory and io port address map of your Nios II board (see LinuxHwselect for details) .
(still in uClinux-dist dir, DO NOT cd linux-2.6.x)
make vendor_hwselect SYSPTF=~/your_hardware_project/your_system.ptf # you must give the path to ptf
make romfs # to create romfs dir, make will fail, ignored. You must do this before the first make
# compile kernel and apps
make # first make may fail, just ignore the error, and do another make. this is caused by parallel compilation. it does not matter.
make
make linux image # rebuild kernel for initramfs
If you meet errors, you can use "NON_SMP_BUILD=1 make", which avoids parallel make. The messages will be cleaner.
The compressed kernel is images/zImage of elf format. You can follow TryOutuClinux to run the new zImage .
Below is the the start up message of Altera University Program DE2 dev board with EtherNet enabled.
Using make vendor_hwselect SYSPTF=~/donwload/system_0.ptf . The zImge, ptf and sof are attached in TryOutuClinux .
#nios2-download -g /home/hippo/uClinux-dist/images/zImage
Using cable "USB-Blaster [USB 4-1.2]", device 1, instance 0x00
Pausing target processor: OK
Initializing
cpu cache (if present)
OK
Downloaded 1201KB in 19.2s (62.5KB/s)
Verified OK
Starting processor at address 0x00D00000
# nios2-terminal
nios2-terminal: connected to hardware target using JTAG UART on cable
nios2-terminal: "USB-Blaster [USB 4-1.2]", device 1, instance 0
nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)
Uncompressing Linux... Ok, booting the kernel.
Linux version 2.6.19-uc1 (hippo@darkstar) (gcc version 3.4.6) #10 PREEMPT Wed Mar 28 20:44:34 CST 2007
uClinux/Nios II
Altera Nios II support (C) 2004 Microtronix Datacom Ltd.
setup_arch: No persistant network settings signature at 003F0000
Built 1 zonelists. Total pages: 2032
Kernel command line:
PID hash table entries: 32 (order: 5, 128 bytes)
Dentry cache hash table entries: 1024 (order: 0, 4096 bytes)
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
Memory available: 5948k/8192k RAM, 0k/0k ROM (1471k kernel code, 683k data)
Mount-cache hash table entries: 512
NET: Registered protocol family 16
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 0, 4096 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP reno registered
io scheduler noop registered
io scheduler deadline registered (default)
Serial: JTAG UART driver $Revision: 1.3 $
ttyJ0 at MMIO 0x806810f0 (irq = 1) is a jtag_uart
<DM9KS> I/O: 806810f8, VID: 90000a46
TCP cubic registered
NET: Registered protocol family 1
NET: Registered protocol family 17
Freeing unused kernel memory: 572k freed (0x97c000 - 0xa0a000)
Shell invoked to run /etc/rc
Command: hostname uClinux
Command: mount -t proc proc /proc
Command: mount -t sysfs sysfs /sys
Command: mount -t usbfs none /proc/bus/usb
mount: Mounting none on /proc/bus/usb failed: No such file or directory
Command: mkdir /var/tmp
Command: mkdir /var/log
Command: mkdir /var/run
Command: mkdir /var/lock
Command: mkdir /var/empty
Command: ifconfig lo 127.0.0.1
Command: route add -net 127.0.0.0 netmask 255.0.0.0 lo
Command: cat /etc/motd
Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|
For further information check:
http://www.uclinux.org/
Execution Finished, Exiting
Sash command shell (version 1.1.1)
/> ifconfig eth0 up
/> dhcpcd & # get network config from a dhcp server, eg, ip,gateway,nameserver
[19]
/> ifconfig
eth0 Link encap:Ethernet HWaddr 00:07:ED:00:00:00
inet addr:192.168.1.85 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 :0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2260 (2.2 KiB) TX bytes:2854 (2.7 KiB)
Interrupt:8
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 :0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
/> inetd &
# start inetd to invoke telnetd and ftpd services
[22]
/> boa & # start httpd with cgi-demo
[23]
/> netstat -a # show network services
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 *:telnet *:* LISTEN
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
/> TZ=CST-8 # my time zone
/> ntpdate pool.ntp.org # get date and time from ntp server
Looking for host pool.ntp.org and service ntp
host found : 218-185-224-9-broadband.tpnet.co.nz
Clock: old time 1999/11/30 - 00:01:32 GMT
Clock: new time 2007/02/09 - 02:12:04 GMT
9 Feb 10:12:04 ntpdate[25]: step time server 218.185.224.9 offset 227067031.864302 sec
/> free
MemTotal: 6520 kB
MemFree: 4340 kB
Buffers: 0 kB
/> ps
PID PORT STAT SIZE SHARED %CPU COMMAND
1 S 147K 0K 2.8 /init
2 S 0K 0K 0.0 ksoftirqd/0
3 S 0K 0K 0.0 events/0
4 S 0K 0K 0.0 khelper
5 S 0K 0K 0.0 kthread
6 S 0K 0K 0.0 kblockd/0
7 S 0K 0K 0.0 pdflush
8 S 0K 0K 0.0 pdflush
9 S 0K 0K 0.0 kswapd0
10 S 0K 0K 0.0 aio/0
17 R 147K 0K 0.3 -/bin/sh
19 S 147K 0K 0.2 dhcpcd
22 S 95K 0K 0.1 inetd
23 S 275K 0K 0.4 boa
/>
ftpd usage, user : ftp, password: <anything> , dir : /home/ftp
boa and cgi usage, dir : /home/httpd
You can check what is in busybox, by running "busybox" on uClinux.
You can check what is in sash, by "help" .
We use initramfs instead of the default romfs . The initramfs is generated from romfs dir and the dev file in vendors/Altera/nios2nommu/romfs_list .
If you make any change to the kernel or filesystem, you must run "make" and "make linux image" again to update the initramfs. See InitramfsUpdate .
The simplified "init" program will run etc/rc and etc/inittab during startup.
If you want to customize startup, eg inet servers and eth config, you should update the files vendors/Altera/nios2nommu/ rc and inittab.
We arrange to minimize the memory usage. We use sash as default shell, it is smaller than busybox and take less memory. We include some standalone networking servers, such as inetd and telnetd. We build some networking utility into busybox, such as ifconfig,route,netstat,telnet,wget..etc. We don't use sh in busybox, and don't use servers in busybox as it takes a lot of memory.
Now, you can config uClinux-dist for costmize kernel and select your apps. I enabled only SMC91C111 and DM9000 Ethernet device drivers for Altera dev board in default config, you should enable your
EtherNet driver in kernel config otherwise. see
LinuxConfig for kernel config items.
Still in uClinux-dist dir, DO NOT cd linux-2.6.x
make menuconfig
Kernel/Library/Defaults Selection --->
(linux-2.6.x) Kernel Version
(None) Libc Version
[ ] Default all settings (lose changes)
[*] Customize Kernel Settings
[*] Customize Vendor/User Settings
[ ] Update Default Vendor Settings
Then <exit> <exit> <yes> .
It will enter kernel config first, then it will enter user apps config, you can select more apps.
After you change config,
make
make linux image # rebuild kernel for initramfs
Note, the uClinux-dist dependency list may not work well, in some case you may need to "make -C <some dir> clean" before "make".
If you change busybox setting, you need to "rm user/busybox/busybox" .
You may use the simple history in sash. Use "h" to list history. Use "!<d>" , d=1..20, to recall one of the history, eg "!3" for the 3rd cmd line.
Use control-H for backspace.
/> h
1: netstat -a
2: date
3: ntpdate pool.ntp.org
4: date
5: boa &
6: inetd &
7: ifconfig
8: dhcpcd &
9: free
10: ps
/> !10
PID PORT STAT SIZE SHARED %CPU COMMAND
1 S 147K 0K 1.7 /init
2 S 0K 0K 0.0 ksoftirqd/0
3 S 0K 0K 0.0 events/0
4 S 0K 0K 0.0 khelper
5 S 0K 0K 0.0 kthread
6 S 0K 0K 0.0 kblockd/0
7 S 0K 0K 0.0 pdflush
8 S 0K 0K 0.0 pdflush
9 S 0K 0K 0.0 kswapd0
10 S 0K 0K 0.0 aio/0
11 S 0K 0K 0.0 mtdblockd
18 R 147K 0K 0.1 /bin/sh
19 S 147K 0K 0.0 dhcpcd
22 S 95K 0K 0.0 inetd
23 S 275K 0K 0.0 boa
/>
These nios2 patches has been submitted to uClinux-dist, and merged. So the last patch was smaller, and just some minor update after the release. Don't use older patches on newer dist release, or it will be over patched.
update the patches
If you have uClinux-dist and old patches already, you can reverse old patches and add new patches, without removing all the uCliunx-dist dir.
eg, if you have uClinux-dist and patched with uClinux-dist-20070130-nios2-02.diff.gz ver 6. And now you want to update to ver 7.
cd ~/uClinux-dist
# rename old patches uClinux-dist-20070130-nios2-02.diff.gz, eg uClinux-dist-20070130-nios2-02-r6.diff.gz for ver 6 , then reverse patch
gunzip -c uClinux-dist-20070130-nios2-02-r6.diff.gz | patch -p0 -R
# download new patches, rename it, eg uClinux-dist-20070130-nios2-02-r7.diff.gz for ver 7 , then apply the patch
gunzip -c uClinux-dist-20070130-nios2-02-r7.diff.gz | patch -p0
Later, when there are ver 14 patches, then you can reverse from ver 7, and update to ver 14.
Changelog of uClinux-dist-20060803-nios2-02.diff.gz,
ver 14, add initrd support for u-boot.
ver 15, bring back altera pio button and spi drivers.
ver 16, add lcd 16207 driver. remove pio button default in Kconfig.
ver 17. enable dm9000 to default kernel config.
ver 18. add more dev nodes, namely ttyJ0,button,spi,i2c-0.
ver 19. fixup hw ether addr of net driver smc91x.c and dm9000.c . fix ntp compile.
ver 20. fix /etc/dhcpc dir for dhcpcd. default cp,rm,mount in busybox, ntpdate.
ver 21. fix compressed kernel of odd size.
ver 22. add DM9000A vendor driver dm9ks, with IP/TCP/UDP checksum offloading will speed up around 10%.
add Altera VGA buffer driver altfb. fix microwin.
use zflat object, NOTE, the binary tools
nios2gcc.tar.bz2 must be updated for "elf2flt -z" to work.
ver 23. fix microwin mouse dev.
ver 24. add Altera UP PS/2 support keyboard, mouse . see
Buffer.
ver 25. two PS/2 devices in setup.c.
ver 26. fix microwin keyboard dev.
ver 27. remove -lz from arch.config .
ver 28. fix microwin nterm, nxterm.
ver 29.30. add lib path built by uClinux-dist in config.arch.
ver 32. fix remap pfn, add i2c-
gpio
Changelog of uClinux-dist-test-20070108-nios2-02.diff.gz,
ver 2, only uart drivers are included.
apply
atlenisse"s 2.6.19 patches, new interrupt API, kernel_execve()
move vga fb,ps2,i2c platform. dirvers to arch//drivers (so that it will be easier to merge into newer kernel/distro.)
Changelog of uClinux-dist-20060803-nios2-02.diff.gz,
ver 1, move altcf,spi to arch//drivers. see
LinuxConfig for kernel config changes.
Only dm9ks, isp1362-hcd added in drivers tree. Removed smc91111.c , dm9000x.c , as we have other drivers for them.
ver 2, fix microwin