[PATCH] mtd: expose ooblayout information via sysfs
Gabor Juhos
j4g8y7 at gmail.com
Sat Jul 19 05:06:48 PDT 2025
Add two new sysfs device attributes which allows to determine the OOB
layout used by a given MTD device. This can be useful to verify the
current layout during driver development without adding extra debug
code. The exposed information also makes it easier to analyze NAND
dumps without the need of cravling out the layout from the driver code.
The content of the new sysfs files is similar to this:
# cat /sys/class/mtd/mtd0/ooblayout_ecc
0 0 49
1 65 63
# cat /sys/class/mtd/mtd0/ooblayout_free
0 49 16
Also update the ABI documentation about the new attributes.
Signed-off-by: Gabor Juhos <j4g8y7 at gmail.com>
---
Documentation/ABI/testing/sysfs-class-mtd | 14 +++++++++++
drivers/mtd/mtdcore.c | 40 +++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-class-mtd b/Documentation/ABI/testing/sysfs-class-mtd
index f77fa4f6d46571175b156113a1afeeb9f5f51c0f..fd3000b9cc7aee4ea9069d1869f310fefa24f97a 100644
--- a/Documentation/ABI/testing/sysfs-class-mtd
+++ b/Documentation/ABI/testing/sysfs-class-mtd
@@ -240,3 +240,17 @@ Contact: linux-mtd at lists.infradead.org
Description:
Number of bytes available for a client to place data into
the out of band area.
+
+What: /sys/class/mtd/mtdX/ooblayout_ecc
+What: /sys/class/mtd/mtdX/ooblayout_free
+Date: July 2025
+KernelVersion: 6.17
+Contact: linux-mtd at lists.infradead.org
+Description:
+ Newline separated list of the regions in the out of band area.
+
+ Each line contains three decimal numbers separated by spaces.
+ The first number indicates the index of the region. The second
+ number describes the starting offset within the out of band
+ area. The last number specifies the amount of bytes available
+ in the region.
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 429d8c16baf045e6a030e309ce0fb1cbec669098..552d12f749e43b7d9abb07e0235a3ef2d2a98546 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -254,6 +254,44 @@ static ssize_t mtd_oobavail_show(struct device *dev,
}
MTD_DEVICE_ATTR_RO(oobavail);
+static ssize_t mtd_ooblayout_show(struct device *dev,
+ struct device_attribute *attr, char *buf,
+ int (*iter)(struct mtd_info *, int section,
+ struct mtd_oob_region *region))
+{
+ struct mtd_info *mtd = dev_get_drvdata(dev);
+ ssize_t size = 0;
+ int section;
+
+ for (section = 0;; section++) {
+ struct mtd_oob_region region;
+ int err;
+
+ err = iter(mtd, section, ®ion);
+ if (err)
+ break;
+
+ size += sysfs_emit_at(buf, size, "%-3d %4u %4u\n", section,
+ region.offset, region.length);
+ }
+
+ return size;
+}
+
+static ssize_t mtd_ooblayout_ecc_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ return mtd_ooblayout_show(dev, attr, buf, mtd_ooblayout_ecc);
+}
+MTD_DEVICE_ATTR_RO(ooblayout_ecc);
+
+static ssize_t mtd_ooblayout_free_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ return mtd_ooblayout_show(dev, attr, buf, mtd_ooblayout_free);
+}
+MTD_DEVICE_ATTR_RO(ooblayout_free);
+
static ssize_t mtd_numeraseregions_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -366,6 +404,8 @@ static struct attribute *mtd_attrs[] = {
&dev_attr_subpagesize.attr,
&dev_attr_oobsize.attr,
&dev_attr_oobavail.attr,
+ &dev_attr_ooblayout_ecc.attr,
+ &dev_attr_ooblayout_free.attr,
&dev_attr_numeraseregions.attr,
&dev_attr_name.attr,
&dev_attr_ecc_strength.attr,
---
base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
change-id: 20250719-mtd-ooblayout-sysfs-77af651b3738
Best regards,
--
Gabor Juhos <j4g8y7 at gmail.com>
More information about the linux-mtd
mailing list