How to mount ubifs image with nandsim on Linux over 512MB


#1

I have to simulate two MTD partition, first one must be 512MB and second one is 256MB in capacity to mount two ubifs images on my desktop Linux system.

I’m trying to make MTD device simulation with nandsim module but simulated device has only 128MB of capacity. How can I increase the capacity and after that how can make partitions on it?


#2

It is possible to simulate MTD device over 128MB capacity with nandsim module.

To do this, you need to give correct parameters when loading nandsim kernel module with modprobe.

Some of them listed on here:
http://www.linux-mtd.infradead.org/faq/nand.html#L_nand_nandsim

To simulate a 1GB nand device, correct command must be:

$ sudo modprobe nandsim first_id_byte=0xec \
                        second_id_byte=0xd3 \
                        third_id_byte=0x51 \
                        fourth_id_byte=0x95

You can check on output of dmesg command:

$ dmesg
...
nand: device found, Manufacturer ID: 0xec, Chip ID: 0xd3
nand: Samsung NAND 1GiB 3,3V 8-bit
nand: 1024 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64

The link above only includes parameters for nand device up to 1GB in size. If you need much more capacity, you need to find correct chip id’s which is in the drivers/mtd/nand/nand_ids.c file in Linux kernel:
http://lxr.free-electrons.com/source/drivers/mtd/nand/nand_ids.c

For example, if you change second_id_byte value from 0xd3 to 0xa5, you will get a nand device with 2GB in size. You can simulate nand device up to 64GB with giving correct parameters. But, please note that, device will be create in RAM, so it will be not a good idea to simulate large nand devices if you don’t have enough memory.

To make partitions on the nand device, you need to use parts parameter of the nandsim module. Parts parameter must be in the form of number of eraseblock, not the exact size of the partition.

For example, if your simulated nand device’s eraseblock size is 128KB and you want a 512MB partition, 4096 (0x1000) eraseblocks needed. Like this, number of eraseblock must be 0x800 for a 256MB partition. All these numbers must be separated by comma, so your final command must be:

$ sudo modprobe nandsim first_id_byte=0xec \
                        second_id_byte=0xd3 \
                        third_id_byte=0x51 \
                        fourth_id_byte=0x95 \
                        parts=0x1000,0x800

You can check the output of the /proc/mtd

$ cat /proc/mtd
dev:    size   erasesize  name
mtd0: 20000000 00020000 "NAND simulator partition 0"
mtd1: 10000000 00020000 "NAND simulator partition 1"
mtd2: 10000000 00020000 "NAND simulator partition 2"

As you will see, mtd0 is 512MB, mtd1 is 256MB and mtd2 fills the remaining capacity.