Currently we can choose two versions of linux kernel to boot with nios2, which are uclinux distribution and linux-socfpga with buildroot. Preparing materials uclinux version set up steps: 1. Set up toolchain 1.1 First choice, codesourcery (according to toolchain setup step of nios2 linux manual on rocketboards) https://sourcery.mentor.com/GNUToolchain/release2499 Choose version of IA32 GNU/Linux Installer and install it. By /bin/sh <Codesourcery>.bin Then □ export PATH=/<your path>/CodeSourcery/Sourcery_CodeBench_Lite_for_Nios_II_GNU_Linux/bin/:$PATH □ export ARCH=nios2 □ export CROSS_COMPILE=nios2-linux-gnu1.2 Second choice, old toolchain-mmu. Download git clone git://sopc.et.ntust.edu.tw/git/toolchain-mmu.git Then set your path to: export PATH=$PATH:/<your path>/toolchain-mmu/x86-linux2/bin/ Very important notification: Only choose one toolchain and make sure only one path of above in your “echo $PATH”, or there will be a lot of strange errors when compiling linux kernel. Don’t mess up your path. 2. Download and set uclinux-dist git clone git://gitorious.org/linux-nios2/uclinux-dist.git Set git branch to trunk by: git checkout –f trunk 3. Download linux-2.6 kernel git clone git://sopc.et.ntust.edu.tw/git/linux-2.6.git Set git branch to nios2: git checkout –f master 4. Sopc2dts tool and generate your device tree. 4.1 Download git clone git://sopc.et.ntust.edu.tw/git/tools.git 4.2 Set up your tool, execute following command: □ cd tools/sopc2dts □ make □ java –jar sopc2dts.jar - - gui 4.3 Generate Device Tree □ In Input->choose file, select your .sopcinfo file. □ In Boardinfo menu, hit Apply. Then change debug console=ttyAL0.11520 to debug console=ttyJ0.11520 to enable jtag-uart console □ In output menu, save it as .dts file. socfpga version set up steps: reference: http://www.rocketboards.org/foswiki/Documentation/NiosIILinuxUserManual 1. set up toolchain exactly as uclinux-dist set-up toolchain step. 2. Set up buildroot for root files system 2.1 Get your file: □ git clone http://git.buildroot.net/git/buildroot.git □ cd buildroot □ git branch -a (to check for latest remote version) □ X don’t use this step git checkout -t -b 2013.08.x origin/2013.08.x (use the latest version) Only branch of master has nios2 architecture. Download Nios II config file for Buildroot: http://www.rocketboards.org/pub/Documentation/NiosIILinuxUserManual/nios2_defconfig. 2.2 Generate rootfs for nios2. Add this file to <buildroot_top_directory>/configs. Go to Buildroot top directory and configure Buildroot for Nios II: □ make nios2_defconfig To customize Buildroot configuration: □ make menuconfig To build: You need to be connected to the network before make as the script must download and install packages. □ make Output file name : rootfs.jffs2, rootfs.cpio, rootfs.tar Output directory : <Buildroot_top_directory>/output/images 2.3 Download linux kernel git clone http://git.rocketboards.org/linux-socfpga.git cd linux-socfpga □ git branch -a (to check for latest remote version) □ git checkout -t -b <socfpga-3.11> origin/<socfpga-3.11> (use the latest version) Go to Linux top directory and configure Linux kernel for Nios II. □ make 3c120_defconfig To build: □ make vmImage The kernel we could use is: <your_kernel_path>/vmlinux. New Kernel building procedure 1. Go to linux-socfpga top directory, type command □ make menuconfig 2. Include your root files system in your RAM: General setup -> Initial RAM filesystem and RAM disk (initramfs/initrd) support (press Y as enable, press N as disenable). Next, enter the path "<your_path>/buildroot/output/images/rootfs.cpio" under General setup -> Initramfs source file(s) 3. Set Kernel features ->Timer frequency to 1000HZ. 4. Set Platform options -> Memory base address to your main memory’s address. Here our main memory is ddr3 sdram. Its base address is 0x04000000. 5. Enable Platform options -> Compile and link device tree into kernel image and type your device tree in the path. 6. Don’t touch Advance setup, treat it as default. 7. Make vmImage 8. bash /opt/altera/13.0sp1/nios2eds/nios2_command_shell.sh 9. nios2-download –g vmlinux && nios2-terminal So far, we could only move this far. Booting stop at msgmni has been set to 114. We don’t know what causes this problem. However we have tested cases as below: □ Toolchain-mmu with uclinux □ Toolchain-mmu with socfpga □ Codesourcery toolchain with uclinux □ Codesourcery toolchain with socfpga Different buildroot branch What’s more, we have tried case in which we change buildroot branch to 2013.08.x (latest version), then we build the kernel with different files systems. The error message is different as: No root files systems results Conclusion: The result of make old uclinux-dist is the same, stucking at ‘msgmni has been set to 115’. According to the cases I have tested, I don’t think it is the problem of toolchain. And I believe, though it is suggested that we should use lastest buildroot branch, we should use the branch of ‘master’ to choose nios2 as the architecture. The tutorial for make uclinux kernel can be: http://www.youtube.com/watch?v=RxlyezOf0Rs Error and solution Most of my errors occurs when I build the old uclinux. Error1: glob.c error: “ARG_MAX” undeclared && Glob.c error:”ARG_MAX” undeclared . . . & CC loginutils/passwd.o loginutils/passwd.c: In function ‘passwd_main’: loginutils/passwd.c:104:16: error: storage size of ‘rlimit_fsize’ isn’t known loginutils/passwd.c:188:2: warning: implicit declaration of function ‘setrlimit‘ [-Wimplicit-function-declaration] loginutils/passwd.c:188:12: error: ‘RLIMIT_FSIZE’ undeclared (first use in this function) loginutils/passwd.c:188:12: note: each undeclared identifier is reported only once for each function it appears in loginutils/passwd.c:104:16: warning: unused variable ‘rlimit_fsize’ [-Wunusedvariable] make[1]: *** [loginutils/passwd.o] Error make: *** [loginutils] Error 2 Solution: First in your uclinux-dist top directory □ find ./ -name libbb.h, Then add #include <sys/resource.h> to libbb.h Error2: stdm++.cxx:1:18: error: stdm++: No such file or directory stdm++.cxx:4: error: 'MATT' has not been declared stdm++.cxx:4: error: expected constructor, destructor, or type conversion before '(' token stdm++.cxx:21: error: 'MATT' has not been declared stdm++.cxx:21: error: expected constructor, destructor, or type conversion before '::' token stdm++.cxx:34: error: 'MATT' has not been declared stdm++.cxx:34: error: 'int operator<<(char*)' must have an argument of class or enumerated type stdm++.cxx:34: error: 'int operator<<(char*)' must take exactly two arguments stdm++.cxx: In function 'int operator<<(char*)': stdm++.cxx:36: error: invalid use of 'this' in non-member function stdm++.cxx:36: error: 'fprintf' was not declared in this scope stdm++.cxx: At global scope: stdm++.cxx:41: error: 'MATT' has not been declared stdm++.cxx:41: error: expected constructor, destructor, or type conversion before 'MATT'Solution: Solution: Generally, if you set your toolchain PATH correctly, it will compile the kernel after all. If you get stuck at this error, you may have some problems with PATH. The most secure solution is to set Codesourcery as your toolchain PATH. Error3: /opt/altera/13.0sp1/nios2eds/bin/nios2-gdb-server-wrapped: error while loading shared libraries: libjtag_client.so: cannot open shared object file: No such file or directory Solution: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/altera/13.0sp1/quartus/linux/ Error4: I found these errors when I boot the kernel. □ Timer’s IRQ number should not be 0. Though it is suggested by the old uclinux version, this will cause booting stuck at ‘Calibrating delay loop...’ We would better set Timer’s IRQ to 11. □ nios2 cpu’s exception vector offset should be set to 0x00000020! Otherwise it cause unhandled exception vector as below: