raspberry pi 3上使用jffs2

本文介绍了如何在raspberry pi 3上使用内核模拟mtd设备,通过nandsim创建不同类型的nand flash,并详细讲述了配置kernel、生成mtd设备、制作jffs2镜像文件以及如何格式化和挂载jffs2的过程。

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/

挂载完成。

嵌入式Linux环境配置是一个涉及到多个方面的任务,包括选择适合的硬件平台、选择合适的Linux发行版、配置内核和文件系统等等。以下是一个基本的嵌入式Linux环境配置的步骤: 1. 硬件平台选择:根据项目需求选择适合的硬件平台,如Raspberry Pi、BeagleBone等。确保平台具备足够的处理能力和扩展性。 2. Linux发行版选择:根据硬件平台的要求选择合适的Linux发行版,如Debian、Ubuntu、Buildroot等。考虑到嵌入式系统的资源限制,建议选择轻量级的发行版。 3. 内核配置:根据项目需求配置Linux内核。可以使用交叉编译工具链进行内核编译,配置相关选项,如设备驱动、文件系统支持、网络协议等。参考平台提供的文档和社区资源进行配置。 4. 文件系统配置:选择合适的文件系统,如ext4、JFFS2等,并进行相应的配置。文件系统需要包含所需的应用程序、库文件和配置文件等。 5. 交叉编译工具链配置:安装并配置交叉编译工具链,用于编译嵌入式应用程序和驱动程序。交叉编译工具链可以在主机上进行开发,生成针对目标平台的可执行文件。 6. 应用程序开发:使用交叉编译工具链进行应用程序开发,包括编写应用程序代码、编译和调试等。可以使用常见的开发工具,如GCC、Make、GDB等。 7. 调试和测试:使用调试工具和测试框架对嵌入式系统进行调试和测试。可以使用JTAG调试器、串口调试等方式进行硬件和软件调试。 8. 部署和更新:将编译好的文件系统和应用程序部署到目标硬件平台上,并进行系统更新和维护。可以使用工具如TFTP、NFS等进行文件传输和更新。 以上是一个基本的嵌入式Linux环境配置的步骤,具体的配置过程会因项目需求和平台差异而有所不同。建议参考相关的文档和社区资源,以获取更详细的配置指导。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值