Using nandsim to mount large images

August 21, 2009

[Warning: This post is a backup recovery from my previous Wordpress blog. All content was automatically converted accessing a MySQL database using a Python script (details). Mostly are in Portuguese but if you are interest I can translate to English. If you found any problem dont’t hesitate to contact me in comments.]

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 here.

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