好记性不如烂笔头,每每遇到之前做个的东西时,由于时间过去比较久,有些细节就忘记了。本文旨在记录 jffs2 的相关打开与创建,同时分享给搜索到本文的有缘人(>‿◠)✌。如有不足,请多指教。
Linux Debian 4.9.0-8-amd64 #1 SMP Debian 4.9.110-3+deb9u6 (2018-10-08) x86_64 GNU/Linux
这里用到了 mtd-utils 工具,未安装的在使用前需通过命令安装:
sudo apt-get install mtd-utils
加载相关驱动,设置mtd大小(这里设置为12M,擦除块大小256k)
sudo modprobe -v mtd
sudo modprobe -v jffs2
sudo modprobe mtdram total_size=12288 erase_size=256 #(单位:K)
sudo flash_eraseall /dev/mtd0
sudo modprobe mtdblock
将现有的 rootfs.jffs2
文件写入到块设备,并挂载到 fsmount
文件夹,
sudo dd if=rootfs.jffs2 of=/dev/mtdblock0
sudo mount -t jffs2 /dev/mtdblock0 fsmount
这时,就可以在文件夹 fsmount
中查看 jffs2 文件系统中的内容。
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.
Set according to target system's memory management
page 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: priority)
-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 available 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
--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 Display this help text
-v, --verbose Verbose operation
-V, --version Display version information
-i, --incremental=FILE Parse FILE and generate appendage output for it
-s 页大小
-e 擦除块大小
-d 构建文件系统目录
-o 生成的文件系统名
-p 生成文件系统大小
cat /proc/mtd
rootfs
文件夹,使用如下命令生成 rootfs.jffs2
文件系统,大小为2Msudo mkfs.jffs2 -s 0x1000 -e 0x40000 -d ./rootfs/ -o rootfs.jffs2 -p 0x200000
注:
若擦除块大小与 flash 不对应,就会有一堆错误打印dd if=rootfs.jffs2 of=/dev/mtd1
mount -t jffs2 /dev/mtdblock1 /mnt