Skip to contentSkip to conversation

mtd0 device is missing in /sys/class/mtd

DISCUSSION Manojkiran Eda 2 participants 4 messages Dec 28, 2023 – Jan 2, 2024 1 message not in the archive Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

Hi All,

I was as beginner in linux device driver development, and recently I was working on a device driver for espi protocol and was stuck with a problem.

I have an mtd device driver through which one could access the NOR flash connected to the other end of espi bus. The driver seems to have probed successfully , I see an entry for my mtd device in /proc/mtd but , I dont see an entry for my mtd device in the /sys/class/mtd.

Here are few logs of interest :

root@mybox:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 04000000 00001000 "aspeed-espi-flash” <<<<<—— This is my mtd device
mtd1: 04000000 00010000 "bmc"
mtd2: 000e0000 00010000 "u-boot"
mtd3: 00020000 00010000 "u-boot-env"
mtd4: 00900000 00010000 "kernel"
mtd5: 02000000 00010000 "rofs"
mtd6: 01600000 00010000 "rwfs"
mtd7: 04000000 00010000 "alt-bmc"
mtd8: 000e0000 00010000 "alt-u-boot"
mtd9: 00020000 00010000 "alt-u-boot-env"
mtd10: 00900000 00010000 "alt-kernel"
mtd11: 02000000 00010000 "alt-rofs"
mtd12: 01600000 00010000 "alt-rwfs”
root@mybox:/sys/class/mtd# ls
mtd1     mtd10ro  mtd11ro  mtd12ro  mtd2     mtd3     mtd4     mtd5     mtd6     mtd7     mtd8     mtd9
mtd10    mtd11    mtd12    mtd1ro   mtd2ro   mtd3ro   mtd4ro   mtd5ro   mtd6ro   mtd7ro   mtd8ro   mtd9ro

I was expecting mtd0 to be present in the /sys/class/mtd, but its not there.

Looking at dmesg:

root@mybox:/sys/class/mtd# dmesg | grep -ie mtd -A5 -ie espi
[    0.685006] Entered the aspeed_espi_ctrl_probe function
[    0.690990] device matched :  1
[    0.699225] espi alloc started
[    0.704726] espi read from device tree, flash size :  67108864
[    0.712416] espi flash enabled
[    0.716572] espi flash channel is ready
[    0.720940] espi flash allocation completed
[    0.725259] aspeed-espi-ctrl 1e6ee000.espi-ctrl: module loaded
--
[    0.962764] 5 fixed-partitions partitions found on MTD device bmc
[    0.969675] Creating 5 MTD partitions on "bmc":
[    0.974776] 0x000000000000-0x0000000e0000 : "u-boot"
[    0.981982] 0x0000000e0000-0x000000100000 : "u-boot-env"
[    0.989557] 0x000000100000-0x000000a00000 : "kernel"
[    0.996772] 0x000000a00000-0x000002a00000 : "rofs"
[    1.003759] 0x000002a00000-0x000004000000 : "rwfs"
--
[    1.048304] 5 fixed-partitions partitions found on MTD device alt-bmc
[    1.055563] Creating 5 MTD partitions on "alt-bmc":
[    1.061096] 0x000000000000-0x0000000e0000 : "alt-u-boot"
[    1.068672] 0x0000000e0000-0x000000100000 : "alt-u-boot-env"
[    1.076607] 0x000000100000-0x000000a00000 : "alt-kernel"
[    1.084211] 0x000000a00000-0x000002a00000 : "alt-rofs"
[    1.091594] 0x000002a00000-0x000004000000 : "alt-rwfs”

and the mtd devices listed in /sys/class/mtd from mtd1 through mtd12 are basically from the partitions list above.

root@mybox:/sys/class/mtd# for dir in *; do cat $dir/name; done
bmc
alt-kernel
alt-rofs
alt-rwfs
u-boot
u-boot-env
kernel
rofs
rwfs
alt-bmc
alt-u-boot
alt-u-boot-env

Does anyone know what could be the possible reason for the problem ? Any hints/help would be appreciated.

Thanks,
Manoj

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#1 lore raw

Try adding MTD_PARTITIONED_MASTER to your kernel config

________________________________________
From: linux-mtd <[email protected]> on behalf of Manojkiran Eda <[email protected]>
Sent: 28 December 2023 17:38
To: [email protected]
Subject: mtd0 device is missing in /sys/class/mtd

Hi All,

I was as beginner in linux device driver development, and recently I was working on a device driver for espi protocol and was stuck with a problem.

I have an mtd device driver through which one could access the NOR flash connected to the other end of espi bus. The driver seems to have probed successfully , I see an entry for my mtd device in /proc/mtd but , I dont see an entry for my mtd device in the /sys/class/mtd.

Here are few logs of interest :

root@mybox:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 04000000 00001000 "aspeed-espi-flash” <<<<<—— This is my mtd device
mtd1: 04000000 00010000 "bmc"
mtd2: 000e0000 00010000 "u-boot"
mtd3: 00020000 00010000 "u-boot-env"
mtd4: 00900000 00010000 "kernel"
mtd5: 02000000 00010000 "rofs"
mtd6: 01600000 00010000 "rwfs"
mtd7: 04000000 00010000 "alt-bmc"
mtd8: 000e0000 00010000 "alt-u-boot"
mtd9: 00020000 00010000 "alt-u-boot-env"
mtd10: 00900000 00010000 "alt-kernel"
mtd11: 02000000 00010000 "alt-rofs"
mtd12: 01600000 00010000 "alt-rwfs”
root@mybox:/sys/class/mtd# ls
mtd1     mtd10ro  mtd11ro  mtd12ro  mtd2     mtd3     mtd4     mtd5     mtd6     mtd7     mtd8     mtd9
mtd10    mtd11    mtd12    mtd1ro   mtd2ro   mtd3ro   mtd4ro   mtd5ro   mtd6ro   mtd7ro   mtd8ro   mtd9ro

I was expecting mtd0 to be present in the /sys/class/mtd, but its not there.

Looking at dmesg:

root@mybox:/sys/class/mtd# dmesg | grep -ie mtd -A5 -ie espi
[    0.685006] Entered the aspeed_espi_ctrl_probe function
[    0.690990] device matched :  1
[    0.699225] espi alloc started
[    0.704726] espi read from device tree, flash size :  67108864
[    0.712416] espi flash enabled
[    0.716572] espi flash channel is ready
[    0.720940] espi flash allocation completed
[    0.725259] aspeed-espi-ctrl 1e6ee000.espi-ctrl: module loaded
--
[    0.962764] 5 fixed-partitions partitions found on MTD device bmc
[    0.969675] Creating 5 MTD partitions on "bmc":
[    0.974776] 0x000000000000-0x0000000e0000 : "u-boot"
[    0.981982] 0x0000000e0000-0x000000100000 : "u-boot-env"
[    0.989557] 0x000000100000-0x000000a00000 : "kernel"
[    0.996772] 0x000000a00000-0x000002a00000 : "rofs"
[    1.003759] 0x000002a00000-0x000004000000 : "rwfs"
--
[    1.048304] 5 fixed-partitions partitions found on MTD device alt-bmc
[    1.055563] Creating 5 MTD partitions on "alt-bmc":
[    1.061096] 0x000000000000-0x0000000e0000 : "alt-u-boot"
[    1.068672] 0x0000000e0000-0x000000100000 : "alt-u-boot-env"
[    1.076607] 0x000000100000-0x000000a00000 : "alt-kernel"
[    1.084211] 0x000000a00000-0x000002a00000 : "alt-rofs"
[    1.091594] 0x000002a00000-0x000004000000 : "alt-rwfs”

and the mtd devices listed in /sys/class/mtd from mtd1 through mtd12 are basically from the partitions list above.

root@mybox:/sys/class/mtd# for dir in *; do cat $dir/name; done
bmc
alt-kernel
alt-rofs
alt-rwfs
u-boot
u-boot-env
kernel
rofs
rwfs
alt-bmc
alt-u-boot
alt-u-boot-env

Does anyone know what could be the possible reason for the problem ? Any hints/help would be appreciated.

Thanks,
Manoj

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

I tried adding MTD_PARTITIONED_MASTER to my kernel config, and still facing the same issue. Debugging a little more , I figured out that my driver is being probed a lot early than the mtd class being registered. So the code is bailing out lot early since the class_to_subsys() returns null (https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L3180)

console traces:

[    9.128866] Entered the aspeed_espi_ctrl_probe function
….
[   11.581081] mtd class is registering now

Looking more, I see a class_is_registered() method available at (https://elixir.bootlin.com/linux/latest/source/drivers/base/class.c#L644) . Is that something that I could check in my driver and return an EPROBE_DEFER ? Or should this logic be incorporated in the mtdcore.c ? Because the mtd_class definition is been declared in the mtdcore and is not passed down from my driver code. All I was doing is calling mtd_device_register() and expecting it to return EPROBE_DEFER if the mtd core subsystem/class is not registered/probed in the kernel.

But I am not sure what’s the right direction. Can any one help me out on this ?

Thanks,

Manoj

Quoted 87 lines
Quoted 87 lines · Joakim Tjernlund

Try adding MTD_PARTITIONED_MASTER to your kernel config

________________________________________
From: linux-mtd <[email protected]> on behalf of Manojkiran Eda <[email protected]>
Sent: 28 December 2023 17:38
To: [email protected]
Subject: mtd0 device is missing in /sys/class/mtd

Hi All,

I was as beginner in linux device driver development, and recently I was working on a device driver for espi protocol and was stuck with a problem.

I have an mtd device driver through which one could access the NOR flash connected to the other end of espi bus. The driver seems to have probed successfully , I see an entry for my mtd device in /proc/mtd but , I dont see an entry for my mtd device in the /sys/class/mtd.

Here are few logs of interest :

root@mybox:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 04000000 00001000 "aspeed-espi-flash” <<<<<—— This is my mtd device
mtd1: 04000000 00010000 "bmc"
mtd2: 000e0000 00010000 "u-boot"
mtd3: 00020000 00010000 "u-boot-env"
mtd4: 00900000 00010000 "kernel"
mtd5: 02000000 00010000 "rofs"
mtd6: 01600000 00010000 "rwfs"
mtd7: 04000000 00010000 "alt-bmc"
mtd8: 000e0000 00010000 "alt-u-boot"
mtd9: 00020000 00010000 "alt-u-boot-env"
mtd10: 00900000 00010000 "alt-kernel"
mtd11: 02000000 00010000 "alt-rofs"
mtd12: 01600000 00010000 "alt-rwfs”
root@mybox:/sys/class/mtd# ls
mtd1     mtd10ro  mtd11ro  mtd12ro  mtd2     mtd3     mtd4     mtd5     mtd6     mtd7     mtd8     mtd9
mtd10    mtd11    mtd12    mtd1ro   mtd2ro   mtd3ro   mtd4ro   mtd5ro   mtd6ro   mtd7ro   mtd8ro   mtd9ro

I was expecting mtd0 to be present in the /sys/class/mtd, but its not there.

Looking at dmesg:

root@mybox:/sys/class/mtd# dmesg | grep -ie mtd -A5 -ie espi
[    0.685006] Entered the aspeed_espi_ctrl_probe function
[    0.690990] device matched :  1
[    0.699225] espi alloc started
[    0.704726] espi read from device tree, flash size :  67108864
[    0.712416] espi flash enabled
[    0.716572] espi flash channel is ready
[    0.720940] espi flash allocation completed
[    0.725259] aspeed-espi-ctrl 1e6ee000.espi-ctrl: module loaded
--
[    0.962764] 5 fixed-partitions partitions found on MTD device bmc
[    0.969675] Creating 5 MTD partitions on "bmc":
[    0.974776] 0x000000000000-0x0000000e0000 : "u-boot"
[    0.981982] 0x0000000e0000-0x000000100000 : "u-boot-env"
[    0.989557] 0x000000100000-0x000000a00000 : "kernel"
[    0.996772] 0x000000a00000-0x000002a00000 : "rofs"
[    1.003759] 0x000002a00000-0x000004000000 : "rwfs"
--
[    1.048304] 5 fixed-partitions partitions found on MTD device alt-bmc
[    1.055563] Creating 5 MTD partitions on "alt-bmc":
[    1.061096] 0x000000000000-0x0000000e0000 : "alt-u-boot"
[    1.068672] 0x0000000e0000-0x000000100000 : "alt-u-boot-env"
[    1.076607] 0x000000100000-0x000000a00000 : "alt-kernel"
[    1.084211] 0x000000a00000-0x000002a00000 : "alt-rofs"
[    1.091594] 0x000002a00000-0x000004000000 : "alt-rwfs”

and the mtd devices listed in /sys/class/mtd from mtd1 through mtd12 are basically from the partitions list above.

root@mybox:/sys/class/mtd# for dir in *; do cat $dir/name; done
bmc
alt-kernel
alt-rofs
alt-rwfs
u-boot
u-boot-env
kernel
rofs
rwfs
alt-bmc
alt-u-boot
alt-u-boot-env

Does anyone know what could be the possible reason for the problem ? Any hints/help would be appreciated.

Quoted 8 lines
Quoted 7 lines

Thanks,
Manoj

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#4 lore raw
In reply to a message not in the archive

I was reading somewhere that , modules that are declared with subsys_initcall() are guaranteed to be executed before the modules that are declared with module_init() , so declaring the mtdcore with subsys_initcall() rather than module_init() solved the issue.

But wondering if this is the right way to solve the problem ?

What is the right way EPROBE_DEFER ? Or Changing the subsystem’s procedure to subsys_initcall() ?

Thanks,
Manoj

Quoted 11 lines · Manojkiran Eda

I tried adding MTD_PARTITIONED_MASTER to my kernel config, and still facing the same issue. Debugging a little more , I figured out that my driver is being probed a lot early than the mtd class being registered. So the code is bailing out lot early since the class_to_subsys() returns null (https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L3180)

console traces:

[    9.128866] Entered the aspeed_espi_ctrl_probe function
….
[   11.581081] mtd class is registering now
Quoted 102 lines

Looking more, I see a class_is_registered() method available at https://elixir.bootlin.com/linux/latest/source/drivers/base/class.c#L644 . Is that something that I could check in my driver and return an EPROBE_DEFER ? Or should this logic be incorporated in the mtdcore.c ? Because the mtd_class definition is been declared in the mtdcore and is not passed down from my driver code. All I was doing is calling mtd_device_register() and expecting it to return EPROBE_DEFER if the mtd core subsystem/class is not registered/probed in the kernel.

But I am not sure what’s the right direction. Can any one help me out on this ?

Thanks,
Manoj

Quoted 94 lines · Joakim Tjernlund

Try adding MTD_PARTITIONED_MASTER to your kernel config

________________________________________
From: linux-mtd <[email protected]> on behalf of Manojkiran Eda <[email protected]>
Sent: 28 December 2023 17:38
To: [email protected]
Subject: mtd0 device is missing in /sys/class/mtd

Hi All,

I was as beginner in linux device driver development, and recently I was working on a device driver for espi protocol and was stuck with a problem.

I have an mtd device driver through which one could access the NOR flash connected to the other end of espi bus. The driver seems to have probed successfully , I see an entry for my mtd device in /proc/mtd but , I dont see an entry for my mtd device in the /sys/class/mtd.

Here are few logs of interest :

root@mybox:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 04000000 00001000 "aspeed-espi-flash” <<<<<—— This is my mtd device
mtd1: 04000000 00010000 "bmc"
mtd2: 000e0000 00010000 "u-boot"
mtd3: 00020000 00010000 "u-boot-env"
mtd4: 00900000 00010000 "kernel"
mtd5: 02000000 00010000 "rofs"
mtd6: 01600000 00010000 "rwfs"
mtd7: 04000000 00010000 "alt-bmc"
mtd8: 000e0000 00010000 "alt-u-boot"
mtd9: 00020000 00010000 "alt-u-boot-env"
mtd10: 00900000 00010000 "alt-kernel"
mtd11: 02000000 00010000 "alt-rofs"
mtd12: 01600000 00010000 "alt-rwfs”
root@mybox:/sys/class/mtd# ls
mtd1     mtd10ro  mtd11ro  mtd12ro  mtd2     mtd3     mtd4     mtd5     mtd6     mtd7     mtd8     mtd9
mtd10    mtd11    mtd12    mtd1ro   mtd2ro   mtd3ro   mtd4ro   mtd5ro   mtd6ro   mtd7ro   mtd8ro   mtd9ro

I was expecting mtd0 to be present in the /sys/class/mtd, but its not there.

Looking at dmesg:

root@mybox:/sys/class/mtd# dmesg | grep -ie mtd -A5 -ie espi
[    0.685006] Entered the aspeed_espi_ctrl_probe function
[    0.690990] device matched :  1
[    0.699225] espi alloc started
[    0.704726] espi read from device tree, flash size :  67108864
[    0.712416] espi flash enabled
[    0.716572] espi flash channel is ready
[    0.720940] espi flash allocation completed
[    0.725259] aspeed-espi-ctrl 1e6ee000.espi-ctrl: module loaded
--
[    0.962764] 5 fixed-partitions partitions found on MTD device bmc
[    0.969675] Creating 5 MTD partitions on "bmc":
[    0.974776] 0x000000000000-0x0000000e0000 : "u-boot"
[    0.981982] 0x0000000e0000-0x000000100000 : "u-boot-env"
[    0.989557] 0x000000100000-0x000000a00000 : "kernel"
[    0.996772] 0x000000a00000-0x000002a00000 : "rofs"
[    1.003759] 0x000002a00000-0x000004000000 : "rwfs"
--
[    1.048304] 5 fixed-partitions partitions found on MTD device alt-bmc
[    1.055563] Creating 5 MTD partitions on "alt-bmc":
[    1.061096] 0x000000000000-0x0000000e0000 : "alt-u-boot"
[    1.068672] 0x0000000e0000-0x000000100000 : "alt-u-boot-env"
[    1.076607] 0x000000100000-0x000000a00000 : "alt-kernel"
[    1.084211] 0x000000a00000-0x000002a00000 : "alt-rofs"
[    1.091594] 0x000002a00000-0x000004000000 : "alt-rwfs”

and the mtd devices listed in /sys/class/mtd from mtd1 through mtd12 are basically from the partitions list above.

root@mybox:/sys/class/mtd# for dir in *; do cat $dir/name; done
bmc
alt-kernel
alt-rofs
alt-rwfs
u-boot
u-boot-env
kernel
rofs
rwfs
alt-bmc
alt-u-boot
alt-u-boot-env

Does anyone know what could be the possible reason for the problem ? Any hints/help would be appreciated.

Thanks,
Manoj

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/