如何更改MTD设备序列号?

时间:2016-09-20 11:09:18

标签: linux linux-device-driver embedded-linux device-driver

我有一些带有MTD设备的嵌入式系统,还增加了一个MTD设备(SPI闪存)。这个新设备现在是mtd0,所有以前的MTD设备的数字都是+1。如何为此新驱动程序分配MTD设备编号以保持以前MTD设备的数量不变?

在:

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

后:

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

我想实现:

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

3 个答案:

答案 0 :(得分:1)

我建议您查看这篇文章https://wiki.archlinux.org/index.php/persistent_block_device_naming。 Udev可以帮助您命名块设备,而无需依赖设备被发现的顺序。

答案 1 :(得分:1)

您可以在设备树源文件中指定MTD分区号(如果您的内核不使用DTB,则可以在板.c文件中)。你需要这样的东西:

&spi0{
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins>;
    /* DO is MOSI, D1 is MISO */
    /*ti,pindir-d0-out-d1-in = <0>;*/
    m25p80@0 {
            #address-cells = <1>;
            #size-cells = <1>;
            compatible = "st,m25pe80";
            reg = <0>;
            spi-max-frequency = <1000000>;
            /*m25p,fast-read;*/
             partition@12 {
                            label = "spi-nor-spl1";
                            reg = <0x0 0x20000>; /* 128k */
                    };

    };
};

(取自here的示例)用于SPI闪存和其他具有MTD分区的设备。

答案 2 :(得分:0)

可能的解决方法:将SPI闪存驱动程序作为可加载模块并在系统引导后加载它:

/ # 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"
相关问题