Chinaunix首页 | 论坛 | 博客
  • 博客访问: 923895
  • 博文数量: 63
  • 博客积分: 568
  • 博客等级: 中士
  • 技术积分: 3435
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-05 11:44
文章分类
文章存档

2016年(4)

2015年(6)

2014年(3)

2013年(27)

2012年(23)

分类: LINUX

2013-12-01 10:02:18

nandsim模拟mtd测试UBI模块

nandsim是在PC机上模拟nand flash设备的一个小模块,本文使用这个工具,在pc机器上模拟一块nand flash.
然后在虚拟的nand flash上对UBI相关的操作进行测试。这样操作的好处就是不需要搭建开发板的环境,在PC
机环境下,快速测试UBI模块。

1、载入相关模块
PC机上不一定有mtd和mtdblock模块,要进行整个实验必须先保证PC机上已经安装了这两个模块,并使用下面的
命令载入这两个模块:

  1. modprobe mtd
  2. modprobe mtdblock
2、载入nandsim模拟一个flash设备

  1. andy@andy-desktop:~/test$ sudo modprobe nandsim
  2. andy@andy-desktop:~/test$
  3. andy@andy-desktop:~/test$
  4. andy@andy-desktop:~/test$ mtdinfo /dev/mtd0
  5. mtd0
  6. Name: NAND simulator partition 0
  7. Type: nand
  8. Eraseblock size: 16384 bytes, 16.0 KiB
  9. Amount of eraseblocks: 8192 (134217728 bytes, 128.0 MiB)
  10. Minimum input/output unit size: 512 bytes
  11. Sub-page size: 256 bytes
  12. OOB size: 16 bytes
  13. Character device major/minor: 90:0
  14. Bad blocks are allowed: true
  15. Device is writable: true

  16. andy@andy-desktop:~/test$ ls /dev/mtd
  17. mtd0 mtd0ro mtdblock0
  18. andy@andy-desktop:~/test$ ls /dev/mtd
从上面执行的命令可以看到在dev下面存在了mtd0 和mtdblock0两个设备

3、载入ubi和gluebi两个模块
这里需要说明一下gluebi这个模块实际上是ubi系统下面的一个子系统,它的作用就是对ubi系统下面建立起来的
每一个卷(volume)再建立一个块设备,块设备名字一般为mtdblockx.这样ubi中的每一个卷就可以当成一个块
设备被上层的软件(主要是文件系统)来操作了

  1. andy@andy-desktop:~/test$ sudo modprobe ubi mtd=0
  2. andy@andy-desktop:~/test$ sudo modprobe gluebi
  3. andy@andy-desktop:~/test$
  4. andy@andy-desktop:~/test$
  5. andy@andy-desktop:~/test$
  6. andy@andy-desktop:~/test$ ls /dev/mtd*
  7. /dev/mtd0 /dev/mtd0ro /dev/mtdblock0
  8. andy@andy-desktop:~/test$ ls /dev/ubi*
  9. /dev/ubi0 /dev/ubi_ctrl
  10. andy@andy-desktop:~/test$
4、创建ubi卷

  1. andy@andy-desktop:~/test$ sudo ubimkvol /dev/ubi0 -N ubi-vol0 -s 60MiB
  2. Volume ID 0, size 3964 LEBs (62916608 bytes, 60.0 MiB), LEB size 15872 bytes (15.5 KiB), dynamic, name "ubi-vol0", alignment 1
  3. andy@andy-desktop:~/test$ ls /dev/mtd*
  4. /dev/mtd0 /dev/mtd1 /dev/mtdblock0
  5. /dev/mtd0ro /dev/mtd1ro /dev/mtdblock1
  6. andy@andy-desktop:~/test$ ls /dev/ubi*
  7. /dev/ubi0 /dev/ubi0_0 /dev/ubi_ctrl
  8. andy@andy-desktop:~/test$
5、把/dev/mtdblock1格式化为vfat格式并挂载

  1. andy@andy-desktop:~/test$ sudo mkfs.vfat /dev/mtdblock1
  2. mkfs.vfat 3.0.7 (24 Dec 2009)
  3. unable to get drive geometry, using default 255/63
  4. andy@andy-desktop:~/test$ sudo mount -t vfat /dev/mtdblock1 ./ubimount
  5. andy@andy-desktop:~/test$ cd ./ubimount/
  6. andy@andy-desktop:~/test/ubimount$ ls
  7. andy@andy-desktop:~/test/ubimount$ cp ../
  8. hello/ hello.txt jffs.img ubimount/
  9. andy@andy-desktop:~/test/ubimount$ cp ../hello
  10. hello/ hello.txt
  11. andy@andy-desktop:~/test/ubimount$ cp ../hello/hello.txt ./hello
  12. cp: 无法创建普通文件"./hello": 权限不够
  13. andy@andy-desktop:~/test/ubimount$ sudo cp ../hello/hello.txt ./hello
  14. andy@andy-desktop:~/test/ubimount$ ls
  15. hello
  16. andy@andy-desktop:~/test/ubimount$ cat hello
  17. hello
  18. andy@andy-desktop:~/test/ubimount$
6、制作jffs2的镜像文件并挂载
首先查看一下虚拟出来的ubi卷的信息,ubi卷的mtd设备是mtd1,mtd0是nandsim虚拟的mtd设备

  1. andy@andy-desktop:~/test$ mtdinfo /dev/mtd1
  2. mtd1
  3. Name: ubi-vol0
  4. Type: ubi
  5. Eraseblock size: 15872 bytes, 15.5 KiB
  6. Amount of eraseblocks: 3964 (62916608 bytes, 60.0 MiB)
  7. Minimum input/output unit size: 512 bytes
  8. Sub-page size: 512 bytes
  9. Character device major/minor: 90:2
  10. Bad blocks are allowed: false
  11. Device is writable: true
然后将./hello目录作为根目录制作一个jffs2的镜像

  1. andy@andy-desktop:~/test$ sudo mkfs.jffs2 -e 0x3e00 -s 0x200 -p 0x500000 -d ./hello
  2. hello/ hello.txt
  3. andy@andy-desktop:~/test$ sudo mkfs.jffs2 -e 0x3e00 -s 0x200 -p 0x500000 -d ./hello -o jffs.img
  4. andy@andy-desktop:~/test$ ls
  5. hello hello.txt jffs_bak.img jffs.img ubimount
使用dd命令将镜像写入到/dev/mtdblock1设备中

  1. andy@andy-desktop:~/test$ dd if=jffs.img of=/dev/mtdblock1
  2. dd: 正在打开"/dev/mtdblock1": 权限不够
  3. andy@andy-desktop:~/test$ sudo dd if=jffs.img of=/dev/mtdblock1
  4. 记录了31+0 的读入
  5. 记录了31+0 的写出
  6. 15872字节(16 kB)已复制,0.0078479 秒,2.0 MB/秒
使用jffs2格式挂载/dev/mtdblock1这个设备

  1. andy@andy-desktop:~/test$ sudo mount -t jffs2 /dev/mtdblock1 ./ubimount/
  2. andy@andy-desktop:~/test$ cd ./ubimount/
  3. andy@andy-desktop:~/test/ubimount$ ls
  4. hello.txt
  5. andy@andy-desktop:~/test/ubimount$ cat hello.txt
  6. hello
  7. andy@andy-desktop:~/test/ubimount$


阅读(9862) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~