如何更改MTD设备序列号?
How to change MTD device serial number?
我有带有一些 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"
我建议看看这篇文章https://wiki.archlinux.org/index.php/persistent_block_device_naming。 Udev 可以帮助您命名块设备,而不依赖于发现设备的顺序。
可能的解决方法:将 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"
您可以在设备树源文件中指定 MTD 分区号(或者如果您的内核不使用 DTB,则在 board.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 分区的设备。
我有带有一些 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"
我建议看看这篇文章https://wiki.archlinux.org/index.php/persistent_block_device_naming。 Udev 可以帮助您命名块设备,而不依赖于发现设备的顺序。
可能的解决方法:将 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"
您可以在设备树源文件中指定 MTD 分区号(或者如果您的内核不使用 DTB,则在 board.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 分区的设备。