Monday, October 17, 2011

根文件系统,JFFS2镜像

Ref: http://blog.ednchina.com/xiong_gang_whut/240013/message.aspx# 
Ref: http://www.lslnet.com/linux/f/docs1/i30/big5237034.htm

一、环境

Ubuntu 8.04
U-Boot 1.3.3(支持tftp)


二、过程

1、制作jffs2镜像需要使用mkfs.jffs2工具,首先 安装mkfs.jffs2工具
   sudo apt-get install mtd-tools


2、退到已做好的rootfs目录的上一级
   ~/rootfs$ cd ..
   #mkfs.jffs2 -r rootfs -o rootfs.jffs2 -e 0x4000 --pad=0x500000 -s 0x200 -n
    即可生成 rootfs.jffs2


 注:
 各参数的意义:
 (1)-r : 指定要做成image的目录名。
 (2)-o : 指定输出image的文件名。
 (3)-e : 每一块要擦除的block size,默认是64KB.要注意,不同的flash, 其block size会不一样,这里用的是三星的K9F1208U0B。
 (4)--pad (-p): 用16进制來表示所要输出文件的大小,也就是rootfs.jffs2的size。很重要的是, 为了不浪费flash空间, 这个值最好符合flash driver所规划的分区的大小。
 (5)如果挂载后会出现类似:CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0  的警告,则加上 -n 就会消失。
 (6) 还有的选项,自己看帮助!-h



3、启动u-boot,将rootfs.jffs2下载到ram并烧写到nand flash的某个分区上。
   nand flash 的分区为:
 Creating 6 MTD partitions on "NAND 64MiB 3,3V 8-bit":
 0x00000000-0x00030000 : "bootloader"
 0x00030000-0x00200000 : "kernel"
 0x00200000-0x00400000 : "ramdisk"
 0x00400000-0x00800000 : "cramfs"
 0x00800000-0x01000000 : "jffs2"
 0x01000000-0x04000000 : "data"

   我们可以将rootfs.cramfs烧写到0x800000上,对应的结点为/dev/mtdblock/4。
  tftp 32000000 rootfs.jffs2
  nand erase 800000 1000000
  nand write.jffs2 32000000 800000 500000


4、要从cramfs启动,可将u-boot的启动参数改为:
root="/dev/mtdblock/4" rootfstype="jffs2" rw console="ttySAC0",115200 init="/linuxrc" noinitrd mem="64M"
   即可。

注意:使用jffs2文件系统时,对内核进行配置时需要选上对jffs2的支持。
注:经验表明,如果jffs2分区太大,可能会出现以下问题:
jffs2: Erase block size too small (16KiB). Using virtual blocks size (32KiB) instead
Empty flash at 0x00003ffc ends at 0x00004000
Empty flash at 0x0000bffc ends at 0x0000c000
Empty flash at 0x00013ffc ends at 0x00014000
Empty flash at 0x0001bffc ends at 0x0001c000
Empty flash at 0x00023ffc ends at 0x00024000
Empty flash at 0x0002bf40 ends at 0x0002c000
Empty flash at 0x0003bffc ends at 0x0003c000
Empty flash at 0x00043fb0 ends at 0x00044000
Empty flash at 0x0004bf98 ends at 0x0004c000
Empty flash at 0x00053ffc ends at 0x00054000
Empty flash at 0x0005bfc8 ends at 0x0005c000
Empty flash at 0x00063fd0 ends at 0x00064000
Empty flash at 0x0006bf50 ends at 0x0006c000
Empty flash at 0x00073ffc ends at 0x00074000
Empty flash at 0x0007bf74 ends at 0x0007c000


   如果需要在其它文件系统中挂载该jffs2文件系统,可以这样做
  #cd /tmp
  #mkdir jffs2
  #mount -t jffs2 /dev/mtdblock/4 jffs2

MarkS Note:
  • In general the erase block size in mkfs.jffs2 should be equal to erase block size in u-boot with flash.
There some questions in the '' is good to read. List as following,

flash + mtd + jffs問題 
1. mtd字符設備的次設備號應當是與其對應的mtd塊設備的兩倍(具體原因看Documentations/devices.txt)
2. 如果你要複製文件到mtd設備,最好複製到mtd塊設備,因為在對mtd字符設備的寫過程是不擦除的,而對塊設備的操作是先擦後寫的
3. 不要mount一個字符設備.
4. mtd字符設備的次設備號應當是與其對應的mtd塊設備的兩倍(具體原因看Documentations/devices.txt),mtd字符設備的次設備號與mtd塊設備號的關係,
如果是只讀設備,mtdchar minor = 2 * mtdblock minor +1;
如果是可讀寫設備,mtdchar minor = 2 * mtdblock minor
不知和Documentations/devices.txt中的說明是否衝突。 
5. jffs_scan_flash()..., 表示你在mount一個mtdblock的時候,其中必須有一個文件系統映像,或者是被擦除的(erased, is '1') 
>jffs_scan_flash(): Did not find even a single chunk of free space. This is BAD! 






No comments:

Post a Comment