jffs2制作与烧写

JFFS2全名是Journalling Flash File System Version2.
最早只支持Nor Flash,自2.6版以后开始支持Nand Flash。

JFFS2是Flash上应用最广的一个日志结构文件系统。它提供的垃圾机制,不需要马上对擦写越界的块进行擦写,而只需要将其设置一个标志,表明为脏块,当可用的块数不足时,垃圾机制才开始处理这些节点。同时,由于JFFS2基于日志结构,在意外掉电后仍然可以保持数据的完整性,而不会丢失数据。

1.制作jffs2文件系统,需要用到工具mkfs.jffs2.
mkfs.jffs2 -r nfs -o fs.jffs2 -e 0x10000 -s 0x10000 -l -n
注:SST6401的擦出块和每块的大小都按32KiWord即64KiB计算,0x10000。
注:此外可查看内核提供的块大小:cat /proc/mtd.
注:若指定块大小不对时:Empty flash at 0x00347ff0 ends at 0x00348000。
注:若未加-n则:CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0

Mkfs.jffs2各参数的意义如下:
-r:指定要做成image的目录名。


-o:指定输出image的文件名。


-e:每一块要擦除的block size,默认是64KB.要注意,不同的flash, 其block size会不一样,三星的K9F2G08U0A的block size为0x20000(从其datasheet里可以找到)。在没有加-e选项是,启动会出现以下错误:at91sam user.warn kernel: Empty flash at 0x00f0fffc ends at 0x00f10000。因此,若有类似的错误,加上-e选项,并配置nandflash的块大小,即可消除。


--pad(-p):用16进制来表示所要输出文件的大小,也就是fs.jffs2的大小,如果实际大小不足此设定的大小,则用0xFF补足。也可以不用此选项,生成的文件系统的大小跟本身大小一致,暂时还不知道有和妙用,但是加上后会少出现很多错误。


-n,-no-cleanmarkers:指明不添加清楚标记(nandflash有自己的校检块,存放相关的信息)。如果挂载后会出现类似:CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0的警告,则加上-n就会消失。


-l,--little-endian:指定使用小端格式。

2.烧写
NorFlash:

mkfs.jffs2 -r nfs -o fs.jffs2 -e 0x10000  -l -n
erase 10380000 107fffff;
//tftp 20008000 rootfs_3gvideo_20141201.jffs2;
//cp.b 0x20008000 0x10380000 0x2aca28;
tftp 20008000 fs.jffs2;
cp.b 0x20008000 0x10380000 0x34bac0;

NandFlash:

mkfs.jffs2 -r rootfs -o rootfs.jffs2 -e 0x20000 -n      ;K9F2G08

tftp 0x21100000 rootfs.jffs2
nand erase 0x8a0000 0x400000  ;擦出整个分区
nand write.jffs2 21100000 0x8a0000 0x230e10  ;写到/dev/mtd3
setenv bootargs root=/dev/mtdblock3 rootfstype=jffs2 rw console=ttyS0,115200 init=/linuxrc mem=64M

 3.  mkfs.jffs2用法

~$mkfs.jffs2 --help
mkfs.jffs2: Usage: mkfs.jffs2 [OPTIONS]
Make a JFFS2 file system image from an existing directory tree

Options:
  -p, --pad[=SIZE]        Pad output to SIZE bytes with 0xFF. If SIZE is
                          not specified, the output is padded to the end of
                          the final erase block
  -r, -d, --root=DIR      Build file system from directory DIR (default: cwd)
  -s, --pagesize=SIZE     Use page size (max data node size) SIZE (default: 4KiB)
  -e, --eraseblock=SIZE   Use erase block size SIZE (default: 64KiB)
  -c, --cleanmarker=SIZE  Size of cleanmarker (default 12)
  -m, --compr-mode=MODE   Select compression mode (default: priortiry)
  -x, --disable-compressor=COMPRESSOR_NAME
                          Disable a compressor
  -X, --enable-compressor=COMPRESSOR_NAME
                          Enable a compressor
  -y, --compressor-priority=PRIORITY:COMPRESSOR_NAME
                          Set the priority of a compressor
  -L, --list-compressors  Show the list of the avaiable compressors
  -t, --test-compression  Call decompress and compare with the original (for test)
  -n, --no-cleanmarkers   Don't add a cleanmarker to every eraseblock
  -o, --output=FILE       Output to FILE (default: stdout)
  -l, --little-endian     Create a little-endian filesystem
  -b, --big-endian        Create a big-endian filesystem
  -D, --devtable=FILE     Use the named FILE as a device table file
  -f, --faketime          Change all file times to '0' for regression testing
  -q, --squash            Squash permissions and owners making all files be owned by root
  -U, --squash-uids       Squash owners making all files be owned by root
  -P, --squash-perms      Squash permissions on all files
  -h, --help              Display this help text
  -v, --verbose           Verbose operation
  -V, --version           Display version information
  -i, --incremental=FILE  Parse FILE and generate appendage output for it

原文地址:https://www.cnblogs.com/embedded-linux/p/4823931.html