从uboot代码中知道,uboot支持linux下几种常用文件系统,如cramfs, ext2, jffs2。由于我的linux系统用的根文件系统是jffs2, 就想能不能让uboot支持jffs2文件系统,然后将linux内核直接放到根文件系统中,由uboot来读出内核再启动,就可以减少一个flash分区,并且linux系统起来后,更新内核并不需要重新烧写内核分区,只需要wget一个内核文件就可以了,少掉很多事。
答案是肯定的,并且更改也非常简单,但一切的前提是flash读写操作正常,这可以从本论坛中“RM9200的uboot中调试flash的经历”中找到调试flash的方法。
在include/configs/at91rm9200dk.h配置文件中定义:
#undef CONFIG_JFFS2_CMDLINE
#define CONFIG_JFFS2_DEV "nor0"
#define CONFIG_JFFS2_PART_SIZE 0x1C0000
#define CONFIG_JFFS2_PART_OFFSET 0x40000
uboot支持多个jffs2分区,可以通过命令设置分区,及激活不同的工作分区。但由于我们并不需要在uboot中有太多操作(一个关键问题是uboot中不能写文件,只能读文件,做不了太多有意义的事),所以不支持命令对jffs2分区,只支持一个jffs2分区。上面参数分别定义的分区大小与分区起始偏移地址,比较好理解。实际上,我的flash只分三个区,分别是uboot, rootfs, userfs,rootfs分区起始地址是0x40000, 大小是0x1c0000, 正是上面设置的参数值。
设置uboot的启动参数为:#define CONFIG_BOOTCOMMAND "fsload uImage; bootm"
将linux内核文件uImage放到根文件系统中,启动后如下:
U-Boot code: 21F00000 -> 21F21F48 BSS: -> 21F3FA88
RAM Configuration:
Bank #0: 20000000 32 MB
SST 39VF3201 flash
Flash: 4 MB
NAND: 64 MB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
uboot> ls
Scanning JFFS2 FS: .. done.
drwxr-xr-x 0 Wed May 02 06:36:59 2007 dev
drwxr-xr-x 0 Sun Apr 01 08:23:29 2007 home
drwxr-xr-x 0 Sat Jun 02 12:23:10 2007 bin
drwxr-xr-x 0 Sat May 12 03:21:46 2007 opt
drwxr-xr-x 0 Sat Jun 02 12:23:10 2007 sbin
drwxr-xr-x 0 Wed May 09 13:33:23 2007 mnt
drwxr-xr-x 0 Sun Apr 01 08:23:51 2007 usr
drwxr-xr-x 0 Tue Jun 19 13:09:31 2007 lib
drwxr-xr-x 0 Wed May 30 12:36:11 2007 etc
drwxr-xr-x 0 Sun Apr 01 08:23:29 2007 root
lrwxrwxrwx 11 Sat Jun 02 12:23:10 2007 linuxrc -> bin/busybox
lrwxrwxrwx 12 Sun May 27 01:08:47 2007 var -> /mnt/ram/var
lrwxrwxrwx 9 Sun May 27 01:07:02 2007 proc -> /tmp/proc
lrwxrwxrwx 16 Sun May 27 01:07:50 2007 tmp -> /mnt/ram/var/tmp
-rw-r--r-- 1071560 Thu Jan 01 00:01:42 1970 uImage
uboot>
linux内核启动如下,显然jffs2文件系统从uboot中启动成功:
U-Boot 1.1.4 (Jun 26 2007 - 17:39:49)
U-Boot code: 21F00000 -> 21F21F48 BSS: -> 21F3FA88
RAM Configuration:
Bank #0: 20000000 32 MB
SST 39VF3201 flash
Flash: 4 MB
NAND: 64 MB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
### JFFS2 loading 'uImage' to 0x20008000
Scanning JFFS2 FS: .. done.
### JFFS2 load complete: 1071560 bytes loaded to 0x20008000
## Booting image at 20008000 ...
Image Name: Linux-2.6.14
Created: 2007-06-27 13:04:05 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1071496 Bytes = 1 MB
Load Address: 20008000
Entry Point: 20008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
Starting kernel ...
Uncompressing Linux.............................................................Linux version 2.6.14 ( root@localhost.localdomain) (gcc version 3.4.1) #74 Wed J7CPU: ARM920Tid(wb) [41129200] revision 0 (ARMv4T)
Machine: Atmel AT91RM9200-DK
Memory policy: ECC disabled, Data cache writeback
Clocks: CPU 179 MHz, master 59 MHz, main 18.432 MHz
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Built 1 zonelists
Kernel command line: mem=32M noinitrd console=ttyS0,115200 init=/linuxrc root=/2AT91: 128 gpio irqs in 4 banks
PID hash table entries: 256 (order: 8, 4096 bytes)
Console: colour dummy device 80x30
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 32MB = 32MB total
Memory: 30116KB available (1795K code, 344K data, 96K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
softlockup thread 0 started up.
NET: Registered protocol family 16
NetWinder Floating Point Emulator V0.97 (double precision)
devfs: 2004-01-31 Richard Gooch ( rgooch@atnf.csiro.au)
devfs: boot_options: 0x1
JFFS2 version 2.2. (NAND) (C) 2001-2003 Red Hat, Inc.
JFFS2: default compression mode: priority
yaffs Jun 27 2007 21:03:42 Installing.
。。。。。。
答案是肯定的,并且更改也非常简单,但一切的前提是flash读写操作正常,这可以从本论坛中“RM9200的uboot中调试flash的经历”中找到调试flash的方法。
在include/configs/at91rm9200dk.h配置文件中定义:
#undef CONFIG_JFFS2_CMDLINE
#define CONFIG_JFFS2_DEV "nor0"
#define CONFIG_JFFS2_PART_SIZE 0x1C0000
#define CONFIG_JFFS2_PART_OFFSET 0x40000
uboot支持多个jffs2分区,可以通过命令设置分区,及激活不同的工作分区。但由于我们并不需要在uboot中有太多操作(一个关键问题是uboot中不能写文件,只能读文件,做不了太多有意义的事),所以不支持命令对jffs2分区,只支持一个jffs2分区。上面参数分别定义的分区大小与分区起始偏移地址,比较好理解。实际上,我的flash只分三个区,分别是uboot, rootfs, userfs,rootfs分区起始地址是0x40000, 大小是0x1c0000, 正是上面设置的参数值。
设置uboot的启动参数为:#define CONFIG_BOOTCOMMAND "fsload uImage; bootm"
将linux内核文件uImage放到根文件系统中,启动后如下:
U-Boot code: 21F00000 -> 21F21F48 BSS: -> 21F3FA88
RAM Configuration:
Bank #0: 20000000 32 MB
SST 39VF3201 flash
Flash: 4 MB
NAND: 64 MB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
uboot> ls
Scanning JFFS2 FS: .. done.
drwxr-xr-x 0 Wed May 02 06:36:59 2007 dev
drwxr-xr-x 0 Sun Apr 01 08:23:29 2007 home
drwxr-xr-x 0 Sat Jun 02 12:23:10 2007 bin
drwxr-xr-x 0 Sat May 12 03:21:46 2007 opt
drwxr-xr-x 0 Sat Jun 02 12:23:10 2007 sbin
drwxr-xr-x 0 Wed May 09 13:33:23 2007 mnt
drwxr-xr-x 0 Sun Apr 01 08:23:51 2007 usr
drwxr-xr-x 0 Tue Jun 19 13:09:31 2007 lib
drwxr-xr-x 0 Wed May 30 12:36:11 2007 etc
drwxr-xr-x 0 Sun Apr 01 08:23:29 2007 root
lrwxrwxrwx 11 Sat Jun 02 12:23:10 2007 linuxrc -> bin/busybox
lrwxrwxrwx 12 Sun May 27 01:08:47 2007 var -> /mnt/ram/var
lrwxrwxrwx 9 Sun May 27 01:07:02 2007 proc -> /tmp/proc
lrwxrwxrwx 16 Sun May 27 01:07:50 2007 tmp -> /mnt/ram/var/tmp
-rw-r--r-- 1071560 Thu Jan 01 00:01:42 1970 uImage
uboot>
linux内核启动如下,显然jffs2文件系统从uboot中启动成功:
U-Boot 1.1.4 (Jun 26 2007 - 17:39:49)
U-Boot code: 21F00000 -> 21F21F48 BSS: -> 21F3FA88
RAM Configuration:
Bank #0: 20000000 32 MB
SST 39VF3201 flash
Flash: 4 MB
NAND: 64 MB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
### JFFS2 loading 'uImage' to 0x20008000
Scanning JFFS2 FS: .. done.
### JFFS2 load complete: 1071560 bytes loaded to 0x20008000
## Booting image at 20008000 ...
Image Name: Linux-2.6.14
Created: 2007-06-27 13:04:05 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1071496 Bytes = 1 MB
Load Address: 20008000
Entry Point: 20008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
Starting kernel ...
Uncompressing Linux.............................................................Linux version 2.6.14 ( root@localhost.localdomain) (gcc version 3.4.1) #74 Wed J7CPU: ARM920Tid(wb) [41129200] revision 0 (ARMv4T)
Machine: Atmel AT91RM9200-DK
Memory policy: ECC disabled, Data cache writeback
Clocks: CPU 179 MHz, master 59 MHz, main 18.432 MHz
CPU0: D VIVT write-back cache
CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets
Built 1 zonelists
Kernel command line: mem=32M noinitrd console=ttyS0,115200 init=/linuxrc root=/2AT91: 128 gpio irqs in 4 banks
PID hash table entries: 256 (order: 8, 4096 bytes)
Console: colour dummy device 80x30
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 32MB = 32MB total
Memory: 30116KB available (1795K code, 344K data, 96K init)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
softlockup thread 0 started up.
NET: Registered protocol family 16
NetWinder Floating Point Emulator V0.97 (double precision)
devfs: 2004-01-31 Richard Gooch ( rgooch@atnf.csiro.au)
devfs: boot_options: 0x1
JFFS2 version 2.2. (NAND) (C) 2001-2003 Red Hat, Inc.
JFFS2: default compression mode: priority
yaffs Jun 27 2007 21:03:42 Installing.
。。。。。。