下載:
或者使用命令:
apt-get install mtd-utils
命令使用實(shí)例:
mkfs.jffs2 -s 0x1000 -e 0x40000 -p 0x500000 -d rootfs/ -o jffs2.img
說(shuō)明:
頁(yè)大小0x1000 4k
塊大小0x40000 256k
jffs2分區(qū)總空間0x500000即5M
當(dāng)然生成的jffs2.img并沒(méi)有一下子分配5M,還是實(shí)際大小0xc0000
mkfs.jffs2使用方法
選項(xiàng)含義(man a mkfs.jffs2)
mkfs.jffs2: Usage: mkfs.jffs2 [OPTIONS]
Make a JFFS2 file system image from an existing directory tree
Options:
-p, --pad[=SIZE] 用16進(jìn)制來(lái)表示所要輸出檔案的大小,也就是root.jffs2的size。
很重要的是, 為了不浪費(fèi)flash空間, 這個(gè)值最好符合flash driver所規(guī)劃的區(qū)塊大小。
如果不足則使用0xff來(lái)填充補(bǔ)滿。
-r, -d, --root=DIR 指定要做成image的源資料夾.(默認(rèn):當(dāng)前文件夾)
-s, --pagesize=SIZE 節(jié)點(diǎn)頁(yè)大小(默認(rèn): 4KiB)
-e, --eraseblock=SIZE 設(shè)定擦除塊的大小為(默認(rèn): 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 指明不添加清楚標(biāo)記(nand flash 有自己的校檢塊,存放相關(guān)的信息。)
如果掛載后會(huì)出現(xiàn)類似:
CLEANMARKER node found at 0x0042c000 has totlen 0xc != normal 0x0
的警告,則加上-n 就會(huì)消失。
-o, --output=FILE 指定輸出image檔案的文件名.(default: stdout)
-l, --little-endian 指定使用小端格式
-b, --big-endian 指定使用大端格式
-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 將所有文件的擁有者設(shè)為root用戶
-P, --squash-perms Squash permissions on all files
--with-xattr stuff all xattr entries into image
--with-selinux stuff only SELinux Labels into jffs2 image
--with-posix-acl stuff only POSIX ACL entries into jffs2 image
-h, --help 顯示這些文字
-v, --verbose Verbose operation
-V, --version 顯示版本
-i, --incremental=FILE Parse FILE and generate appendage output for it
生成的rootfs.img可通過(guò)u-boot直接燒寫(xiě)至nand flash:
nand erase 0x200000 0x3e00000//擦寫(xiě)
tftp 0x30000000 rootfs.img//下載
nand write.jffs2 0x200000 $(filesize)//燒入
(二) 在linux的PC上掛載jffs2根文件系統(tǒng)映像
因?yàn)閖ffs2是構(gòu)建于MTD設(shè)備上的文件系統(tǒng),所以無(wú)法通過(guò)loop設(shè)備來(lái)掛載,但是可以通過(guò)mtdram設(shè)備來(lái)掛載。mtdram是在用RAM實(shí)現(xiàn)的MTD設(shè)備,可以通過(guò)mtdblock設(shè)備來(lái)訪問(wèn)。使用mtdram設(shè)備很簡(jiǎn)單,只要加載mtdram和mtdblock兩個(gè)內(nèi)核模塊即可。這兩個(gè)內(nèi)核模塊一般的linux內(nèi)核發(fā)行版都有編譯好的,直接用modprobe命令加載。
下面是具體步驟:
(1).加載mtdblock內(nèi)核模塊
modprobe mtdblock
(2).加載mtdram內(nèi)核模塊,將該設(shè)備的大小指定為jffs2根文件系統(tǒng)映像的大小,塊擦除大?。磃lash的塊大小)指定為制作該jffs2根文件系統(tǒng)時(shí)“-e”參數(shù)指定的大小,缺省為64KB。下面兩個(gè)參數(shù)的單位都是KB。
modprobe mtdram total_size=5120 erase_size=256
(3).這時(shí)將出現(xiàn)MTD設(shè)備/dev/mtdblock0,使用dd命令將jffs2根文件系統(tǒng)拷貝到/dev/mtdblock0設(shè)備中。
dd if=jffs2.img of=/dev/mtdblock0
(4).將保存了jffs2根文件系統(tǒng)的MTD設(shè)備掛載到指定的目錄上。
mount -t jffs2 /dev/mtdblock0 /mnt/mtd
這之后就可以到/mnt/mtd目錄查看、修改掛載的jffs2根文件系統(tǒng)了,修改后的jffs2根文件系統(tǒng)可以通過(guò)dd命令拷貝為一個(gè)jffs2的映像文件