Chinaunix首页 | 论坛 | 博客
  • 博客访问: 284996
  • 博文数量: 91
  • 博客积分: 1772
  • 博客等级: 上尉
  • 技术积分: 930
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-17 19:49
文章分类

全部博文(91)

文章存档

2012年(1)

2011年(36)

2010年(50)

2008年(4)

我的朋友

分类: LINUX

2010-08-11 18:30:11

Using nandsim to mount large images

Since I’m still using 32-bit machines I had to switch the way I mount large (> 128MiB) JFFS2 images. Now I’m using NAND simulator, an extremely useful debugging and development tool which simulates NAND flashes in RAM. The main problem with mtdram is  related with space reserved to vmalloc function on 32-bits processors (an hardware dependent issue). Checking /proc/meminfo you can see the difference:

32-bit: VmallocTotal:   122880 kB
64-bit: VmallocTotal: 34359738367 kB

Nandsim uses another design to access memory, it creates a slab allocation for an array to allow large chunks of memory, the following functions contains more information:

static int __init init_mtdram(void) in drivers/mtd/devices/mtdram.c
static int alloc_device(struct nandsim *ns) in drivers/mtd/nand/nandsim.c

Lets remember the “original” way (using mdtram) to mount an JFFS2 image:

modprobe mtd
modprobe mtdblock
modprobe mtdram total_size=10240 erase_size=16
dd if=image.jffs2 of=/dev/mtdblock0
mount -t jffs2 /dev/mtdblock0 /mount-point

And the new one with nandsim:

modprobe mtd
modprobe mtdblock
modprobe nandsim first_id_byte=0x20 second_id_byte=0x71
dd if=image.jffs2 of=/dev/mtdblock0
mount -t jffs2 /dev/mtdblock0 /mount-point

And check both:

cat /proc/mtd
dev: size erasesize name
mtd0: 08000000 00004000 "NAND simulator partition 0"
mtd1: 00400000 00004000 "mtdram test device"

With mtdram you can define any value to erase_size but with nandsim you need pre-defined memory parameters found in manufacturer datasheet, to select the simulated flash type one should specify ID bytes of your flasher (I’ve tested with pages of 512 and 2048 bytes).  For more information click .

You can use nandsim to mount another flash file systems, such as: YAFFS2, CramFS and UBIFS.

As described on first paragraph, nandsim is much more than just a “mount tool”. It can reproduce real condition of memory and lead developers make experiments without real hardware. I’m still learning the possibilities, if you would like to contribute leave an comment.

Endianess issue

If you need convert an image from big endian to little endian (specially on x86 systems) use jffs2dump.

jffs2dump -b big_endian.img -e new_little_endian.img

tags: , ,
posted in by Tiago Maluta

Follow comments via the RSS Feed | Deixe um comentário | Trackback URL


If you wish to use the mtd nandsim device as a simulator for testing
yaffs, you can follow these steps:

1) Make sure you have a recent 2.6 kernel with a recent MTD tree. (If
you ask the MTD folk, they'll tell you to run the mtd patchin script
from the latest cvs version of MTD.)

2) Configure your kernel to enable the mtd nand support and nandsim
driver. Make sure that the following are set in .config:

CONFIG_MTD=m
CONFIG_MTD_CHAR=m
CONFIG_MTD_BLOCK=m
CONFIG_MTD_NAND=m
CONFIG_MTD_NAND_NANDSIM=m

You can set them to 'y' rather than 'm' if you don't want the modules
form.

3) make and install your kernel and modules in the usual way, then boot.

4) To use the nandsim, you need to load some MTD modules, unless you've
configured MTD into the kernel:

modprobe mtdblock
modprobe mtdchar
modprobe nandsim

5) Verify that the nandsim device has loaded properly:

cat /proc/mtd

You will see something like

dev: size erasesize name
mtd0: 00800000 00002000 "NAND simulator partition"

If everything went well.

6) what the nand device is called will depend on your Linux distro, and
whether you are using devfs or udev, but the '0', or whatever mtd
reports as the device associated with the simulator, in the above will
show up in the name. On my ubuntu system, if /proc/mtd reports 'mtd0'
then the block device is /dev/mtdblock0 and the char device is
/dev/mtd0.

7) You can mount yaffs on the nandsim in the usual way. I have
/mnt/nand as the directory I mount on, so I would mount using

mount -t yaffs /dev/mtdblock0 /mnt/nand


If you find any errors in this, please let me know. It wll eventually
find its way into the yaffs documentation.

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