Aivars Aivars - 2 months ago 20
Linux Question

How to change MTD device serial number?

I have embedded system with some MTD devices and added one more MTD device (SPI flash). This new device now is mtd0 and number for all previous MTD devices are +1. How can I assign MTD device number for this new driver to keep numbers of previous MTD devices unchanged ?

Before:

# cat /proc/mtd
dev: size erasesize name
mtd0: 00100000 00020000 "u-boot"
...


After:

# cat /proc/mtd
dev: size erasesize name
mtd0: 00100000 00001000 "spi-nor-flash"
mtd1: 00100000 00020000 "u-boot"
...


I want to achieve:

# cat /proc/mtd
dev: size erasesize name
mtd0: 00100000 00020000 "u-boot"
...
mtd5: 00100000 00001000 "spi-nor-flash"

Answer

Solution is simple: make SPI flash driver as loadable module and load it after system booting:

/ # cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00800000 00020000 "u-boot"
...
mtd4: 0c8c0000 00020000 "ubipart"

/ # insmod m25p80.ko
[  365.735184] m25p80 spi0.0: n25q256a (32768 Kbytes)
[  365.739903] 1 ofpart partitions found on MTD device spi0.0
[  365.745396] Creating 1 MTD partitions on "spi0.0":
[  365.750133] 0x000000000000-0x000000800000 : "spi-flash"

/ # cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00800000 00020000 "u-boot"
...
mtd4: 0c8c0000 00020000 "ubipart"
mtd5: 00800000 00001000 "spi-flash"
Comments