Linux: Create multiple partitions in an virtual mtd device created by nandsim

Hi,

this post describes creating an virtual mtd device by nandsim with multiple partitions.

First of all install the mtd and ubi related tools. On debian install the mtd-utils package.

root@debdev ~# apt-get -y install  mtd-utils

I want to emulate an “NAND device: Manufacturer ID: 0x98, Chip ID: 0xd1 (Toshiba NAND 128MiB 3,3V 8-bit)” which is used in hikvisions IP cameras. The NAND device has 128MiB space with aa erasesize of 128KiB. To get the parameter for the nandsim kernel module I looked into the kernel source tree linux-source-4.7/drivers/mtd/nand_ids.c (Source: Kernel Sources www.kernel.org).

{"TC58NVG0S3E 1G 3.3V 8-bit",
                { .id = {0x98, 0xd1, 0x90, 0x15, 0x76, 0x14, 0x01, 0x00} },
                  SZ_2K, SZ_128, SZ_128K, 0, 8, 64, NAND_ECC_INFO(1, SZ_512),
                  2 },

To Create a mtd device with just one partition load nandsim with

root@debdev ~# modprobe nandsim first_id_byte=0x98 second_id_byte=0xd1 third_id_byte=0x90 fourth_id_byte=0x15
root@debdev ~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 08000000 00020000 "NAND simulator partition 0"

Check dmesg for details

root@debdev ~# dmesg
[   86.117813] nand: device found, Manufacturer ID: 0x98, Chip ID: 0xd1
[   86.117823] nand: Toshiba NAND 128MiB 3,3V 8-bit
[   86.117835] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[   86.117874] flash size: 128 MiB
[   86.117884] page size: 2048 bytes
[   86.117892] OOB area size: 64 bytes
[   86.117901] sector size: 128 KiB
[   86.117910] pages number: 65536
[   86.117919] pages per sector: 64
[   86.117927] bus width: 8
[   86.117935] bits in sector size: 17
[   86.117943] bits in page size: 11
[   86.117951] bits in OOB size: 6
[   86.117960] flash size with OOB: 135168 KiB
[   86.117969] page address bytes: 4
[   86.117977] sector address bytes: 2
[   86.117985] options: 0x8

To delete the device, unload the kernel module

 
root@debdev ~# rmmod nandsim

To create multiple partitions add the parts parameter to the modprobe command. The parts parameter accept a comma seperated list of partition sizes. Size is not the size in bytes. The partitons size is the parts parameter multiplied with the Sectorsize/Erasesize of the device. An example:

root@debdev ~# modprobe nandsim first_id_byte=0x98 second_id_byte=0xd1 third_id_byte=0x90 fourth_id_byte=0x15 parts=4,8
  • Partition 0 – 4 x 128KiB = 512KiB
  • Partition 1 – 8 x 128KiB = 1MiB
  • Partition 2  – The Rest of the device.
 
root@debdev ~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00080000 00020000 "NAND simulator partition 0"
mtd1: 00100000 00020000 "NAND simulator partition 1"
mtd2: 07e80000 00020000 "NAND simulator partition 2"
root@debdev:~# mtdinfo
Count of MTD devices:           3
Present MTD devices:            mtd0, mtd1, mtd2
Sysfs interface supported:      yes

Or detailed info with

 
root@debdev:~# mtdinfo --all

Michael

Leave a Reply Cancel reply