Forum Discussion
Altera_Forum
Honored Contributor
16 years agoLinux, U-Boot, and Root File Systems
I'm working with a Nios II design with an MMU, on a Nios II Development Kit, Cyclone II Edition board (EP2C35).
I'm trying to figure out how to get to a system that boots with some sort of root filesystem stored in flash. With help from hippo's wiki page (http://www.nioswiki.com/linux) (http://www.nioswiki.com/linux%29), I can now:- Build a kernel
- Download it with nios2-download
- Connect with nios2-terminal
- Get a Linux Command Prompt
13 Replies
- Altera_Forum
Honored Contributor
Why using u-Boot ?
>>> "images/zImge.initramfs.gz is the compressed elf image with initramfs built-in" AFAIK, same just needs to be copied into RAM and started, now it will spawn the file system automatically. -Michael - Altera_Forum
Honored Contributor
There are a few reasons I would like to use U-Boot.
It allows me to switch between kernel builds easily. It allows me to boot with an nfs filesystem, which is convenient for application development. I have an I2C-based RTC added to my board, and the Linux RTC driver expects the clock chip to be initialized by pre-Linux code. I'm looking to U-Boot to provide that pre-Linux initialization code. (Getting the I2C working in U-Boot is my next project.) -- I downloaded the zImage.initramfs.gz file to the board, with nios2-download. This runs, and gets me to a command prompt, just like linux.initramfs.gz does. zImage.initramfs.gz does not seem to be an image suitable for U-Boot. I tried downloading it directly to the board via U-Boot tftp, then running it using the U-Boot command "go". I also tried packing it up with mkimage, then downloading the result to the board with tftp, and booting from it with the U-Boot command "bootm". I eventually want to burn the filesystem into flash, and boot from U-Boot without a network connection. -Pinta - Altera_Forum
Honored Contributor
Please find some example u-boot scripts in this file,
ftp://ftp.altera.com/outgoing/devkit/altera_niosii_wrlinux_deliverables.zip You may enable passing command line from u-boot with this kernel config, "NiosII Configuration"-->"Passed kernel command line from u-boot" It will be more flexible to keep compile-in command line empty and pass it from u-boot. So that you are free to boot from nfs or flash. You may enable jffs2 and mtd in kernel config, (or ubifs etc) so that your can root your fs on it. as stated in the wiki, "images/rootfs.jffs2 is jffs2 image, eg, cp rootfs.jffs2 /dev/mtd0. This is available when jffs2 is selected in kernel. Please note the flash erase sector size on 3c120 dev board is 128KB, you will have to specify "MKFS_JFFS2_FLAGS = -l -p -e 128" at the beginning of your product Makefile." I am working with Altera to prepare a user guide, which should be released soon. - Hippo - Altera_Forum
Honored Contributor
--- Quote Start --- It allows me to boot with an nfs filesystem, which is convenient for application development. --- Quote End --- You can mount ntfs within initramfs. It might or might no be sensible to chroot top same. -Michael - Altera_Forum
Honored Contributor
Hippo wrote:
--- Quote Start --- You may enable passing command line from u-boot with this kernel config, "NiosII Configuration"-->"Passed kernel command line from u-boot" --- Quote End --- When I was trying to figure out what was going on, I verified that this was set in the kernel config. Despite this, when the kernel output prints "Kernel command line: ", it shows no bootargs (even when I set bootargs in U-Boot). I had to do weird things with the addresses in U-Boot, to get it to work with the MMU, as I documented in http://www.nioswiki.com/dasuboot/u-boot_with_mmu. It could be that I missed something, and the bootargs are being written to non-existent memory. Specifically, I prefixed the flash address and all the device addresses with "E". For example, my custom_fpga.h shows JTAG_UART_BASE is 0x21208B0. My EP2C35.h defines JTAG_UART_BASE as 0xE21208B0. (Getting the UART right is essential.... without it, you get no output to tell you what is wrong.) I did not move CFG_SDRAM_BASE and CFG_SRAM_BASE. They are still at 0x06000000 and 0x01400000 respectively (the same as in my custom_fpga.h). I did define TEXT_BASE as 0xC7FC0000, 256k from the end of the RAM, in kernel space. If I didn't do this, nios2-download failed. Should CFG_SDRAM_BASE be a 0xC6000000 (in kernel space) instead of 0x06000000? --- Quote Start --- You may enable jffs2 and mtd in kernel config, (or ubifs etc) so that your can root your fs on it. as stated in the wiki, "images/rootfs.jffs2 is jffs2 image, eg, cp rootfs.jffs2 /dev/mtd0. This is available when jffs2 is selected in kernel. Please note the flash erase sector size on 3c120 dev board is 128KB, you will have to specify "MKFS_JFFS2_FLAGS = -l -p -e 128" at the beginning of your product Makefile." --- Quote End --- The Altera EP2C35 board uses either the AM29LV128M or the S29GL128M10TFIR1, both of which have 64 kB sectors. I assume that means I should switch to "MKFS_JFFS2_FLAGS = -l -p -e 64". I turned on jffs2 support in the kernel build. The kernel builds, but the tools fail:
This seems to be due to a lack of a zlib.h. Recommendations?make: Entering directory `/home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user/mtd-utils' unset CC CFLAGS CPPFLAGS CROSS LDFLAGS; make -C 606f38a2221648ca5c5fa292c9f71d2ddd59fa66/ WITHOUT_XATTR=1 SUBDIRS= BUILDDIR=$PWD/build-606f38a2221648ca5c5fa292c9f71d2ddd59fa66-host/ TARGETS=" mkfs.jffs2" make: Entering directory `/home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user/mtd-utils/606f38a2221648ca5c5fa292c9f71d2ddd59fa66' mkdir -p /home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user/mtd-utils/build-606f38a2221648ca5c5fa292c9f71d2ddd59fa66-host/ gcc -I./include -DWITHOUT_XATTR -D_FILE_OFFSET_BITS=64 -O2 -g -Wall -Wextra -Wwrite-strings -Wno-sign-compare -c -o /home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user/mtd-utils/build-606f38a2221648ca5c5fa292c9f71d2ddd59fa66-host/mkfs.jffs2.o mkfs.jffs2.c -g -Wp,-MD,/home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user/mtd-utils/build-606f38a2221648ca5c5fa292c9f71d2ddd59fa66-host/.mkfs.jffs2.c.dep mkfs.jffs2.c:73:18: error: zlib.h: No such file or directory mkfs.jffs2.c: In function ‘recursive_populate_directory’: mkfs.jffs2.c:1336: warning: format ‘%9lu’ expects type ‘long unsigned int’, but argument 3 has type ‘__off64_t’ mkfs.jffs2.c:1345: warning: format ‘%9lu’ expects type ‘long unsigned int’, but argument 3 has type ‘__off64_t’ mkfs.jffs2.c:1354: warning: format ‘%9lu’ expects type ‘long unsigned int’, but argument 3 has type ‘__off64_t’ mkfs.jffs2.c:1384: warning: format ‘%9lu’ expects type ‘long unsigned int’, but argument 3 has type ‘__off64_t’ mkfs.jffs2.c:1395: warning: format ‘%9lu’ expects type ‘long unsigned int’, but argument 3 has type ‘__off64_t’ mkfs.jffs2.c: At top level: mkfs.jffs2.c:1519: warning: initialization discards qualifiers from pointer target type mkfs.jffs2.c:1521: warning: initialization discards qualifiers from pointer target type mkfs.jffs2.c: In function ‘main’: mkfs.jffs2.c:1881: warning: passing argument 2 of ‘recursive_add_host_directory’ discards qualifiers from pointer target type make: *** Error 1 make: Leaving directory `/home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user/mtd-utils/606f38a2221648ca5c5fa292c9f71d2ddd59fa66' make: *** Error 2 make: Leaving directory `/home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user/mtd-utils' make: *** Error 2 make: Leaving directory `/home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user' make: *** Error 2 make: Leaving directory `/home/nina/projects/micropump/nios_linux/nios2-linux/uClinux-dist/user' make: *** Error 1 - Altera_Forum
Honored Contributor
zlib : please check if you have installed zlib-devel in your Linux desktop.
64KB is the default of mkfs.jffs2, so there is no need to specify the flag in your case. u-boot: please adapt the 3c120 config, which is for nios2mmu. or you may find the u-boot in the zip file I pointed. - Hippo - Altera_Forum
Honored Contributor
zlib: zlib-devel was the problem. lzo-devel is also required.
I also realized I was using the wrong branch of the U-Boot repository. Thats why the bootargs were not being passed. When I switched to the "nios2" branch, bootargs worked. Now that I can get kernel arguments passed in, my life should be easier. Next I'm trying to figure out what to do with the rootfs.jffs2 file. I think I need to:- Compile MTDPARTS and JFFS2 support into U-Boot
- Define a Partition Table in U-Boot
- Define a matching Linux partition table in arch/nios2/kernel/config.c after the line "static struct mtd_partition nios2_partitions
- Burn rootfs.jffs2 to flash
- Altera_Forum
Honored Contributor
You will need to define your mtd parts and flash bus width in config.c.
The u-boot don't really need mtd part and jffs2 support. You can tftp the file and cp.b to the flash address of your filesystem in u-boot. - Hippo - Altera_Forum
Honored Contributor
--- Quote Start --- You will need to define your mtd parts and flash bus width in config.c. --- Quote End --- You are talking about this section for the bus width, right?
And this variable for the MTD parts?static struct physmap_flash_data nios2_flash_data = {# if defined(CONFIG_ALTERA_NEEK_C3) || defined(CONFIG_ALTERA_CYCLONE_III) .width = 2, /* 16 bits data bus */# else .width = 1, /* 8 bits data bus */# endif .parts = nios2_partitions, .nr_parts = ARRAY_SIZE(nios2_partitions), };
I have a 16 bit wide flash. I am sure I am compiling with ".width = 2" because I dumped a "#warning" macro in the correct code, and an "#error" macro in the alternative. Despite this, the CFI detection finds 2 x8 devices, instead of 1 x16 device. It correctly recognizes that it is a 16MB device, but thinks there are two of them. As a result, it thinks there are 32 MB of flash. The flash drivers then generate a lot of errors (I assume resulting from the incorrect detection of flash). I inserted a "printk" into physmap.c:physmap_flash_probe(), to print the value of physmap_data->width. It outputs "Physmap Width: 2". I've included the boot log below. I truncated the flash errors, because they seemed endless.static struct mtd_partition nios2_partitions = { .... }Linux version 2.6.30-00494-g84a224b-dirty (pinta@drake-linux) (gcc version 4.1.2)# 40 Mon Oct 5 18:05:24 EDT 2009 console enabled Early printk initialized Linux/Nios II-MMU init_bootmem_node(?,0x62bd, 0x6000, 0x8000) free_bootmem(0x62bd000, 0x1d43000) reserve_bootmem(0x62bd000, 0x400) Built 1 zonelists in Zone order, mobility grouping on. Total pages: 8128 Kernel command line: noinitrd rw root=/dev/mtdblock2 rootfstype=jffs2 NR_IRQS:32 PID hash table entries: 128 (order: 7, 512 bytes) Dentry cache hash table entries: 4096 (order: 2, 16384 bytes) Inode-cache hash table entries: 2048 (order: 1, 8192 bytes) We have 32768 pages of RAM Memory available: 29672k/2800k RAM, 0k/0k ROM (2119k kernel code, 680k data) Calibrating delay loop... 41.98 BogoMIPS (lpj=209920) Mount-cache hash table entries: 512 net_namespace: 492 bytes NET: Registered protocol family 16 init_BSP(): registering device resources bio: create slab <bio-0> at 0 NET: Registered protocol family 2 IP route cache hash table entries: 1024 (order: 0, 4096 bytes) TCP established hash table entries: 1024 (order: 1, 8192 bytes) TCP bind hash table entries: 1024 (order: 0, 4096 bytes) TCP: Hash tables configured (established 1024 bind 1024) TCP reno registered NET: Registered protocol family 1 JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc. JFFS2: default compression mode: priority msgmni has been set to 57 io scheduler noop registered io scheduler anticipatory registered io scheduler deadline registered io scheduler cfq registered (default) ttyJ0 at MMIO 0x21208b0 (irq = 1) is a Altera JTAG UART ttyS0 at MMIO 0x2120840 (irq = 4) is a Altera UART console handover: boot -> real ttyS1 at MMIO 0x2120b00 (irq = 8) is a Altera UART smc91x.c: v1.1, sep 22 2004 by Nicolas Pitre <[email protected]> eth0: SMC91C11xFD (rev 2) at e2110300 IRQ 6 eth0: Ethernet addr: 00:07:ed:0f:0a:53 physmap platform flash device: 01000000 at 00000000 Physmap Width: 2 physmap-flash.0: Found 2 x8 devices at 0x0 in 16-bit bank in cfi_chip_setup NOR chip too large to fit in mapping. Attempting to cope... Amd/Fujitsu Extended Query Table at 0x0040 physmap-flash.0: CFI does not contain boot bank location. Assuming top. number of CFI chips: 1 cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness. Reducing visibility of 32768KiB chip to 16384KiB cmdlinepart partition parsing not available RedBoot partition parsing not available Using physmap partition information Creating 3 MTD partitions on "physmap-flash.0": 0x000000000000-0x000000060000 : "U-Boot" 0x000000060000-0x000000200000 : "uImage" 0x000000200000-0x000001000000 : "romfs/jffs2" TCP cubic registered NET: Registered protocol family 10 NET: Registered protocol family 17 RPC: Registered udp transport module. RPC: Registered tcp transport module. /home/pinta/projects/micropump/nios_linux/nios2-linux/linux-2.6/drivers/rtc/hctosys.c: unable to open rtc device (rtc0) eth0: link down ADDRCONF(NETDEV_UP): eth0: link is not ready IP-Config: Unable to set interface netmask (-22). Empty flash at 0x0000fffc ends at 0x00010000 CLEANMARKER node found at 0x00010000, not first node in block (0x00000000) Empty flash at 0x0002fffc ends at 0x00030000 CLEANMARKER node found at 0x00030000, not first node in block (0x00020000) Empty flash at 0x0004fffc ends at 0x00050000 CLEANMARKER node found at 0x00050000, not first node in block (0x00040000) eth0: link up, 100Mbps, full-duplex, lpa 0x45E1 Empty flash at 0x0006fffc ends at 0x00070000 CLEANMARKER node found at 0x00070000, not first node in block (0x00060000) Empty flash at 0x0008fffc ends at 0x00090000 CLEANMARKER node found at 0x00090000, not first node in block (0x00080000) Empty flash at 0x000afffc ends at 0x000b0000 CLEANMARKER node found at 0x000b0000, not first node in block (0x000a0000) Empty flash at 0x000cffe8 ends at 0x000d0000 CLEANMARKER node found at 0x000d0000, not first node in block (0x000c0000) jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00120000: 0x55ff instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00440000: 0x55ff instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00760000: 0x55ff instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00a00010: 0xd76a instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00a00014: 0x5000 instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00a00018: 0x6a00 instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00a0001c: 0x0040 instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00a00020: 0x0068 instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00a00024: 0x40ff instead jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00a00028: 0x6880 instead Empty flash at 0x00a0002c ends at 0x00a0004c eth0: link up, 100Mbps, full-duplex, lpa 0x45E1 jffs2_scan_eraseblock(): Magic bitmask 0x1985 not found at 0x00a0004c: 0x0400 instead - Altera_Forum
Honored Contributor
I think there are problems in the flash configuration. Could you post the hardware design? schematic/pdf and quartus project? (maybe somewhere in the wiki)
- Hippo