redboot下jffs2文件系统详解
来源:互联网 发布:js正则表达式\< 编辑:程序博客网 时间:2024/04/29 08:50
1 引导过程:FLASH根文件系统
# 使用 mkfs.jffs2 工具,制作根文件系统映像
# -d fakeroot :根文件系统的内容放在fakeroot目录中
# -e 0x20000 :FLASH的eraseblock大小为0x20000字节
# -p :以0xff填充文件尾部的空间对齐eraseblock
# -o fakeroot.jffs2.img :输出映像文件名
[root@lips arm]# mkfs.jffs2 -d fakeroot -e 0x20000 -p -o fakeroot.jffs2.
img
# 将映像文件复制到TFTP服务器的根目录(这里是/root/arm/boot/)
[root@lips arm]# cp fakeroot.jffs2.img boot/
[root@lips arm]#
# 查看一下当前FLASH的布局,确定空闲空间的地址
RedBoot> fis list
Name FLASH addr Mem addr Length Entry point
RedBoot 0xF0000000 0xF0000000 0x00040000 0x00000000
RedBoot config 0xF07C0000 0xF07C0000 0x00001000 0x00000000
FIS directory 0xF07E0000 0xF07E0000 0x00020000 0x00000000
kernel 0xF0040000 0x00100000 0x000E0000 0x00100000
RedBoot> fis free
0xF0120000 .. 0xF07C0000
# 通过网络从主机TFTP服务器下载fakeroot.jffs2.img文件,并装入内存地址0x10
0000
# 这里几个参数的意义可以参考上一节
# -b 0x100000 :确定该值的原则与下载内核文件时相同,并且可以使用一个不一
样的地址
RedBoot> load -r -b 0x100000 -h 192.168.0.20 fakeroot.jffs2.img
Raw file loaded 0x00100000-0x0023ffff, assumed entry at 0x00100000
# 用fis工具的erase命令擦除指定的FLASH区域
# 擦除之后的区域被填充为0xFF,这样做是为了保证没有写有效数据的空间是“干
净”的,从而避免因为文件尾部有垃圾数据而导致的错误。这个步骤并非必须执行
。
RedBoot> fis erase -f 0xf0120000 -l 0x140000
# 用fis工具的write命令将内存中的内容写入FLASH
# -b 0x100000 :数据在内存中的地址
# -f 0xf0120000 :数据写入FLASH的地址(怎么确定这个地址?从上面的fis fre
e命令可以知道当前可用空间的起始地址,从而确定这个地址。当然也可以靠后一些
,比如0xf0200000,不过要注意这样的话就会出现一个空闲空间的空洞,并且会影
响根设备的编号,即/dev/mtdblock?。)
# -l 0x140000 :数据块的长度(怎么确定这个长度?从load命令的返回信息知道
映像文件的大小,然后取一个稍大并且对齐erase block size 0x20000的值。)
RedBoot> fis write -b 0x100000 -f 0xf0120000 -l 0x140000
* CAUTION * about to program FLASH
at 0xf0120000..0xf025ffff from 0x00100000 - continue (y/n)?
y
... Erase from 0xf0120000-0xf0260000: ..........
... Program from 0x00100000-0x00240000 at 0xf0120000: ..........
# 用fis工具的create命令命名刚才写入的内容为fakeroot
# -n :该参数指定仅创建了目录节点
RedBoot> fis create -f 0xf0120000 -l 0x140000 -n fakeroot
... Unlock from 0xf07e0000-0xf0800000: .
... Erase from 0xf07e0000-0xf0800000: .
... Program from 0x01fdf000-0x01fff000 at 0xf07e0000: .
... Lock from 0xf07e0000-0xf0800000: .
# 查看一下,确认写入成功
RedBoot> fis list
Name FLASH addr Mem addr Length Entry point
RedBoot 0xF0000000 0xF0000000 0x00040000 0x00000000
RedBoot config 0xF07C0000 0xF07C0000 0x00001000 0x00000000
FIS directory 0xF07E0000 0xF07E0000 0x00020000 0x00000000
kernel 0xF0040000 0x00100000 0x000E0000 0x00100000
fakeroot 0xF0120000 0xF0120000 0x00140000 0x00100000
RedBoot> fis free
0xF0260000 .. 0xF07C0000
# 从FLASH加载内核
RedBoot> fis load kernel
# exec命令执行内核,-c指定引导参数
# console=ttyS0,115200 :设置串口控制台
# root=/dev/mtdblock2 :设置根文件系统为/dev/mtdblock2
# 这个“/dev/mtdblock2”是怎么确定的?我们已经创建了设备节点mtdblock0~m
tdblock7,这里要确定写入FLASH的jffs2文件系统对应哪个设备。方法是,从FLAS
H的起始地址往后数,看写入的jffs2位于第几个分区;计数从0开始;在IQ80321板
子上第一个分区是RedBoot;”unallocated space”也要算。准确的信息可以在引
导过程中看到,比如下面的”Creating 6 MTD partitions on IOP3xx Flash:”;
或者在引导成功后的/proc/mtd文件中也可以看到。
RedBoot> exec -c "console=ttyS0,115200 root=/dev/mtdblock2"
Using base address 0x00100000 and length 0x000e0000
Uncompressing Linux.....................................................
.... done, booting the kernel.
Linux version 2.4.21-rmk1-ds0-dj9 (root@lips) (gcc version 2.95.3 200103
15 (release)) #1 Mon Jul 5 14:34:15 CST 2004
CPU: XScale-IOP80321 revision 2
Machine: Intel IQ80321
alloc_bootmem_low
memtable_init
On node 0 totalpages: 16384
zone(0): 16384 pages.
zone(1): 0 pages.
zone(2): 0 pages.
Kernel command line: console=ttyS0,115200 root=/dev/mtdblock2
Calibrating delay loop... 599.65 BogoMIPS
Memory: 64MB = 64MB total
Memory: 62904KB available (1398K code, 261K data, 232K init)
XScale Cache/TLB Locking Copyright(c) 2001 MontaVista Software, Inc.
Dentry cache hash table entries: 8192 (order: 4, 65536 bytes)
Inode cache hash table entries: 4096 (order: 3, 32768 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer-cache hash table entries: 4096 (order: 2, 16384 bytes)
Page-cache hash table entries: 16384 (order: 4, 65536 bytes)
POSIX conformance testing by UNIFIX
PCI: bus0: Fast back to back transfers disabled
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Intel IOP3xx AAU RAID Copyright(c) 2003 Intel Corporation
Starting kswapd
JFFS2 version 2.1. (C) 2001 Red Hat, Inc., designed by Axis Communicatio
ns AB.
pty: 256 Unix98 ptys configured
Serial driver version 5.05c (2001-07-08) with MANY_PORTS SHARE_IRQ SERIA
L_PCI enabled
ttyS00 at 0xfe800000x (irq = 28) is a 16550A
Real Time Clock Driver v1.10e
RAMDISK driver initialized: 16 RAM disks of 8192K size 1024 blocksize
Intel(R) PRO/1000 Network Driver - version 5.0.43-k1
Copyright (c) 1999-2003 Intel Corporation.
eth0: Intel(R) PRO/1000 Network Connection
Uniform Multi-Platform E-IDE driver Revision: 7.00beta4-2.4
ide: Assuming 33MHz system bus speed for PIO modes; override with idebus
=xx
cfi_cmdset_0001: Erase suspend on write enabled
Using buffer write method
Using RedBoot partition definition
Creating 6 MTD partitions on "IOP3xx Flash":
0x00000000-0x00040000 : "RedBoot"
0x00040000-0x00120000 : "kernel"
0x00120000-0x00260000 : "fakeroot"
0x00260000-0x007c0000 : "unallocated space"
0x007c0000-0x007c1000 : "RedBoot config"
mtd: partition "RedBoot config" doesn't end on an erase block -- force r
ead-only
0x007e0000-0x00800000 : "FIS directory"
md: raid5 personality registered as nr 4
raid5: measuring checksumming speed
iop3xx_aau: 223.200 MB/sec
raid5: using function: iop3xx_aau (223.200 MB/sec)
md: md driver 0.90.0 MAX_MD_DEVS=256, MD_SB_DISKS=27
md: Autodetecting RAID arrays.
md: autorun ...
md: ... autorun DONE.
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 4096 bind 4096)
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
NetWinder Floating Point Emulator V0.97 (double precision)
VFS: Mounted root (jffs2 filesystem).
Freeing init memory: 232K
Setting hostname iq80321:
Mounting proc filesystem:
mount: Mounting none on /proc failed: Device or resource busy
Please press Enter to activate this console.
BusyBox v1.00-pre10 (2004.04.27-01:28+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
# 得到shell提示符,引导成功!
/ #
# 前面我们使用erase/write/create连续三个命令完成了jffs2映像根文件系统的写
入,主要是为了保证0xff填充非有效数据的空间,如果能够保证这一点的话,使用
create命令直接写入FLASH也是可以的。怎么保证0xff填充呢?经验是,执行 fis
init –f 命令对FLASH完全初始化之后,空闲空间以0xFF填充;或者用 fis erase
命令擦除FLASH;或者用 mfill 命令将一段内存区域填充为0xFF之后再load文件至
该区域;必要的话可以用 dump 命令查看确认一下FLASH的内容。总之,理解了“为
什么”就可以灵活使用这些命令,而不必拘泥于文档中的演示。
# 下面是测试过程:
RedBoot> fis free
0xF0260000 .. 0xF07C0000
RedBoot> load -r -b 0x200000 -h 192.168.0.20 fakeroot.jffs2.img
Raw file loaded 0x00200000-0x0033ffff, assumed entry at 0x00200000
RedBoot> fis create -b 0x200000 -f 0xf0260000 -l 0x140000 fakeroot2
... Erase from 0xf0260000-0xf03a0000: ..........
... Program from 0x00200000-0x00340000 at 0xf0260000: ..........
... Unlock from 0xf07e0000-0xf0800000: .
... Erase from 0xf07e0000-0xf0800000: .
... Program from 0x01fdf000-0x01fff000 at 0xf07e0000: .
... Lock from 0xf07e0000-0xf0800000: .
RedBoot> fis list
Name FLASH addr Mem addr Length Entry point
RedBoot 0xF0000000 0xF0000000 0x00040000 0x00000000
RedBoot config 0xF07C0000 0xF07C0000 0x00001000 0x00000000
FIS directory 0xF07E0000 0xF07E0000 0x00020000 0x00000000
kernel 0xF0040000 0x00100000 0x000E0000 0x00100000
fakeroot
# -d fakeroot
# -e 0x20000
# -p
# -o fakeroot.jffs2.img :输出映像文件名
[root@lips arm]# mkfs.jffs2 -d fakeroot -e 0x20000 -p -o fakeroot.jffs2.
img
# 将映像文件复制到TFTP服务器的根目录(这里是/root/arm/boot/)
[root@lips arm]# cp fakeroot.jffs2.img boot/
[root@lips arm]#
# 查看一下当前FLASH的布局,确定空闲空间的地址
RedBoot> fis list
Name
RedBoot
RedBoot config
FIS directory
kernel
RedBoot> fis free
# 通过网络从主机TFTP服务器下载fakeroot.jffs2.img文件,并装入内存地址0x10
0000
# 这里几个参数的意义可以参考上一节
# -b 0x100000
样的地址
RedBoot> load -r -b 0x100000 -h 192.168.0.20 fakeroot.jffs2.img
Raw file loaded 0x00100000-0x0023ffff, assumed entry at 0x00100000
# 用fis工具的erase命令擦除指定的FLASH区域
# 擦除之后的区域被填充为0xFF,这样做是为了保证没有写有效数据的空间是“干
净”的,从而避免因为文件尾部有垃圾数据而导致的错误。这个步骤并非必须执行
。
RedBoot> fis erase -f 0xf0120000 -l 0x140000
# 用fis工具的write命令将内存中的内容写入FLASH
# -b 0x100000
# -f 0xf0120000 :数据写入FLASH的地址(怎么确定这个地址?从上面的fis fre
e命令可以知道当前可用空间的起始地址,从而确定这个地址。当然也可以靠后一些
,比如0xf0200000,不过要注意这样的话就会出现一个空闲空间的空洞,并且会影
响根设备的编号,即/dev/mtdblock?。)
# -l 0x140000
映像文件的大小,然后取一个稍大并且对齐erase block size 0x20000的值。)
RedBoot> fis write -b 0x100000 -f 0xf0120000 -l 0x140000
* CAUTION * about to program FLASH
y
... Erase from 0xf0120000-0xf0260000: ..........
... Program from 0x00100000-0x00240000 at 0xf0120000: ..........
# 用fis工具的create命令命名刚才写入的内容为fakeroot
# -n
RedBoot> fis create -f 0xf0120000 -l 0x140000 -n fakeroot
... Unlock from 0xf07e0000-0xf0800000: .
... Erase from 0xf07e0000-0xf0800000: .
... Program from 0x01fdf000-0x01fff000 at 0xf07e0000: .
... Lock from 0xf07e0000-0xf0800000: .
# 查看一下,确认写入成功
RedBoot> fis list
Name
RedBoot
RedBoot config
FIS directory
kernel
fakeroot
RedBoot> fis free
# 从FLASH加载内核
RedBoot> fis load kernel
# exec命令执行内核,-c指定引导参数
# console=ttyS0,115200
# root=/dev/mtdblock2
# 这个“/dev/mtdblock2”是怎么确定的?我们已经创建了设备节点mtdblock0~m
tdblock7,这里要确定写入FLASH的jffs2文件系统对应哪个设备。方法是,从FLAS
H的起始地址往后数,看写入的jffs2位于第几个分区;计数从0开始;在IQ80321板
子上第一个分区是RedBoot;”unallocated space”也要算。准确的信息可以在引
导过程中看到,比如下面的”Creating 6 MTD partitions on IOP3xx Flash:”;
或者在引导成功后的/proc/mtd文件中也可以看到。
RedBoot> exec -c "console=ttyS0,115200 root=/dev/mtdblock2"
Using base address 0x00100000 and length 0x000e0000
Uncompressing Linux.....................................................
.... done, booting the kernel.
Linux version 2.4.21-rmk1-ds0-dj9 (root@lips) (gcc version 2.95.3 200103
15 (release)) #1 Mon Jul 5 14:34:15 CST 2004
CPU: XScale-IOP80321 revision 2
Machine: Intel IQ80321
alloc_bootmem_low
memtable_init
On node 0 totalpages: 16384
zone(0): 16384 pages.
zone(1): 0 pages.
zone(2): 0 pages.
Kernel command line: console=ttyS0,115200 root=/dev/mtdblock2
Calibrating delay loop... 599.65 BogoMIPS
Memory: 64MB = 64MB total
Memory: 62904KB available (1398K code, 261K data, 232K init)
XScale Cache/TLB Locking Copyright(c) 2001 MontaVista Software, Inc.
Dentry cache hash table entries: 8192 (order: 4, 65536 bytes)
Inode cache hash table entries: 4096 (order: 3, 32768 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer-cache hash table entries: 4096 (order: 2, 16384 bytes)
Page-cache hash table entries: 16384 (order: 4, 65536 bytes)
POSIX conformance testing by UNIFIX
PCI: bus0: Fast back to back transfers disabled
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Intel IOP3xx AAU RAID Copyright(c) 2003 Intel Corporation
Starting kswapd
JFFS2 version 2.1. (C) 2001 Red Hat, Inc., designed by Axis Communicatio
ns AB.
pty: 256 Unix98 ptys configured
Serial driver version 5.05c (2001-07-08) with MANY_PORTS SHARE_IRQ SERIA
L_PCI enabled
ttyS00 at 0xfe800000x (irq = 28) is a 16550A
Real Time Clock Driver v1.10e
RAMDISK driver initialized: 16 RAM disks of 8192K size 1024 blocksize
Intel(R) PRO/1000 Network Driver - version 5.0.43-k1
Copyright (c) 1999-2003 Intel Corporation.
eth0: Intel(R) PRO/1000 Network Connection
Uniform Multi-Platform E-IDE driver Revision: 7.00beta4-2.4
ide: Assuming 33MHz system bus speed for PIO modes; override with idebus
=xx
cfi_cmdset_0001: Erase suspend on write enabled
Using buffer write method
Using RedBoot partition definition
Creating 6 MTD partitions on "IOP3xx Flash":
0x00000000-0x00040000 : "RedBoot"
0x00040000-0x00120000 : "kernel"
0x00120000-0x00260000 : "fakeroot"
0x00260000-0x007c0000 : "unallocated space"
0x007c0000-0x007c1000 : "RedBoot config"
mtd: partition "RedBoot config" doesn't end on an erase block -- force r
ead-only
0x007e0000-0x00800000 : "FIS directory"
md: raid5 personality registered as nr 4
raid5: measuring checksumming speed
raid5: using function: iop3xx_aau (223.200 MB/sec)
md: md driver 0.90.0 MAX_MD_DEVS=256, MD_SB_DISKS=27
md: Autodetecting RAID arrays.
md: autorun ...
md: ... autorun DONE.
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 4096 bind 4096)
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
NetWinder Floating Point Emulator V0.97 (double precision)
VFS: Mounted root (jffs2 filesystem).
Freeing init memory: 232K
Setting hostname iq80321:
Mounting proc filesystem:
mount: Mounting none on /proc failed: Device or resource busy
Please press Enter to activate this console.
BusyBox v1.00-pre10 (2004.04.27-01:28+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
# 得到shell提示符,引导成功!
/ #
# 前面我们使用erase/write/create连续三个命令完成了jffs2映像根文件系统的写
入,主要是为了保证0xff填充非有效数据的空间,如果能够保证这一点的话,使用
create命令直接写入FLASH也是可以的。怎么保证0xff填充呢?经验是,执行 fis
init –f 命令对FLASH完全初始化之后,空闲空间以0xFF填充;或者用 fis erase
命令擦除FLASH;或者用 mfill 命令将一段内存区域填充为0xFF之后再load文件至
该区域;必要的话可以用 dump 命令查看确认一下FLASH的内容。总之,理解了“为
什么”就可以灵活使用这些命令,而不必拘泥于文档中的演示。
# 下面是测试过程:
RedBoot> fis free
RedBoot> load -r -b 0x200000 -h 192.168.0.20 fakeroot.jffs2.img
Raw file loaded 0x00200000-0x0033ffff, assumed entry at 0x00200000
RedBoot> fis create -b 0x200000 -f 0xf0260000 -l 0x140000 fakeroot2
... Erase from 0xf0260000-0xf03a0000: ..........
... Program from 0x00200000-0x00340000 at 0xf0260000: ..........
... Unlock from 0xf07e0000-0xf0800000: .
... Erase from 0xf07e0000-0xf0800000: .
... Program from 0x01fdf000-0x01fff000 at 0xf07e0000: .
... Lock from 0xf07e0000-0xf0800000: .
RedBoot> fis list
Name
RedBoot
RedBoot config
FIS directory
kernel
fakeroot