raspberry pi 3上使用jffs2

来源:互联网 发布:算法笔记 pdf 编辑:程序博客网 时间:2024/05/12 19:35

raspberry pi 3上使用jffs2

最近准备学习linux mtd以及nand flash驱动,无奈手上的mini6410无法使用,而另一块板子—raspberry pi 3上没有nand flash,顿时感觉很囧……。偶然发现kernel可以将内存模拟成mtd,那么就用内存模拟的mtd玩玩好了。

配置kernel

raspberry pi 3的默认配置貌似没有配置mtd,自己需要选上配置,保证mtd.ko,mtdblock.ko,及nandsim.ko能够被编译出来。jffs2.ko也需要编译出来。具体自己通过make menuconfig选上。

生成mtd设备

modprobe mtd

之后就会生成/proc/mtd文件,表示mtd.ko已经插入到kernel

接着,插入nandsim模块,这个模块用于将系统中一部分内存模拟成nand flash。插入之后,在/dev/下就有了mtd0相关的设备节点了。这个nandsim模块在插入的过程中可以接参数,模拟不同型号的nand flash。摘自官网的一段说明:

NAND simulator (nandsim) is an extremely useful debugging and development tool which simulates NAND flashes in RAM or a file. To select the simulated flash type one should specify ID bytes of your flash - the ones which are returned by the “Read ID” command (0x90) - consult the flash manual. The following are examples of input parameters:

modprobe nandsim first_id_byte=0x20 second_id_byte=0x33 - 16MiB, 512 bytes page;
modprobe nandsim first_id_byte=0x20 second_id_byte=0x35 - 32MiB, 512 bytes page;
modprobe nandsim first_id_byte=0x20 second_id_byte=0x36 - 64MiB, 512 bytes page;
modprobe nandsim first_id_byte=0x20 second_id_byte=0x78 - 128MiB, 512 bytes page;
modprobe nandsim first_id_byte=0x20 second_id_byte=0x71 - 256MiB, 512 bytes page;
modprobe nandsim first_id_byte=0x20 second_id_byte=0xa2 third_id_byte=0x00 fourth_id_byte=0x15 - 64MiB, 2048 bytes page;
modprobe nandsim first_id_byte=0xec second_id_byte=0xa1 third_id_byte=0x00 fourth_id_byte=0x15 - 128MiB, 2048 bytes page;
modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15 - 256MiB, 2048 bytes page;
modprobe nandsim first_id_byte=0x20 second_id_byte=0xac third_id_byte=0x00 fourth_id_byte=0x15 - 512MiB, 2048 bytes page;
modprobe nandsim first_id_byte=0xec second_id_byte=0xd3 third_id_byte=0x51 fourth_id_byte=0x95 - 1GiB, 2048 bytes page;
If you do not have enough RAM, you can make nandsim emulate the flash on top of a file. Please, use the cache_file nandsim module parameter.

nandsim can emulate various errors and report wear statistics, which is extremely useful when testing how flash software handles errors (e.g., what does JFFS2 do in case of bit-flips or write errors).

Note, theoretically nandsim can emulate 16-bit bus width devices, but it may not work.

下面我们随意设置一个nand flash的参数

modprobe nandsim first_id_byte=0x20 second_id_byte=0x33

这样在/dev/下就生成了mtd0及mtd0ro 。然后将mtdblock模块插入,才会生成mtdblock设备节点。

modprobe mtdblock

生成jffs2镜像文件

首先肯定是需要安装mtd-utls的,然后通过mkfs.jffs2生成相应的镜像文件

mkfs.jffs2 -s 0x800 -e 0x20000 -p 0x800000 -d mm -o test.img

说明:
页大小0x800,也就是2K
block大小 0x20000 128K
镜像大小 8M
mm是需要打包的目录名,这个可以随意指定
test.img就是最终的镜像文件了

格式化并且挂载jffs2

dd if=test.img of=/dev/mtdblock0
mount -t jffs2 /dev/mtdblock0 /mnt/usb/

挂载完成。

0 0
原创粉丝点击