[PATCH v1 0/2] mtd: Allow to parse DT partitions for raw nand

This series is fixing issue where "mtd list" command can't displayed nand raw partitions even if the flash DT node is populated with partitions subnode with "fixed-partitions" compatible.
Patrice Chotard (2): mtd: Add flash_node in struct mtd_info mtd: Update the way partitions are parsed
drivers/mtd/mtdpart.c | 8 ++++++-- drivers/mtd/nand/raw/nand_base.c | 1 + include/linux/mtd/mtd.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-)

Currently, add_mtd_partitions_of() can be used only if dev field of mtd_info struct is populated. It's the case, for example, for a spi nor flash, which has a DT compatible "jedec,spi-nor" and an associated device. mtd->dev is populated in spi_nor_scan().
But in case of a raw nand node, mtd_info's dev field can't be populated as flash node has no compatible, so no associated device. add_mtd_partitions_of() can't be used to parse "partitions" subnode.
To remove this constraint, add an ofnode field in mtd_info struct which reference the DT flash node. This new field is populated by nand_scan_tail(). This new field will be used by add_mtd_partitions_of() to parse the flash node for "partitions" defined in DT.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Farhan Ali farhan.ali@broadcom.com Cc: Heinrich Schuchardt xypron.glpk@gmx.de Cc: Jagan Teki jagan@amarulasolutions.com Cc: Marek Behun marek.behun@nic.cz Cc: Miquel Raynal miquel.raynal@bootlin.com Cc: Simon Glass sjg@chromium.org Cc: Wolfgang Denk wd@denx.de ---
drivers/mtd/nand/raw/nand_base.c | 1 + include/linux/mtd/mtd.h | 1 + 2 files changed, 2 insertions(+)
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index f7616985d9..a007603df1 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -5257,6 +5257,7 @@ int nand_scan_tail(struct mtd_info *mtd) break; }
+ mtd->flash_node = chip->flash_node; /* Fill in remaining MTD driver data */ mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH; mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM : diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 7455400981..af45e63bf9 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -305,6 +305,7 @@ struct mtd_info { struct device dev; #else struct udevice *dev; + ofnode flash_node; #endif int usecount;

On Mon, Mar 21, 2022 at 09:13:36AM +0100, Patrice Chotard wrote:
Currently, add_mtd_partitions_of() can be used only if dev field of mtd_info struct is populated. It's the case, for example, for a spi nor flash, which has a DT compatible "jedec,spi-nor" and an associated device. mtd->dev is populated in spi_nor_scan().
But in case of a raw nand node, mtd_info's dev field can't be populated as flash node has no compatible, so no associated device. add_mtd_partitions_of() can't be used to parse "partitions" subnode.
To remove this constraint, add an ofnode field in mtd_info struct which reference the DT flash node. This new field is populated by nand_scan_tail(). This new field will be used by add_mtd_partitions_of() to parse the flash node for "partitions" defined in DT.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com Cc: Farhan Ali farhan.ali@broadcom.com Cc: Heinrich Schuchardt xypron.glpk@gmx.de Cc: Jagan Teki jagan@amarulasolutions.com Cc: Marek Behun marek.behun@nic.cz Cc: Miquel Raynal miquel.raynal@bootlin.com Cc: Simon Glass sjg@chromium.org Cc: Wolfgang Denk wd@denx.de
Applied to u-boot/master, thanks!

In case mtd_info's dev field is not populated (raw nand's case), use the flash_node new field which reference the DT flash node where can be found "partitions" node with "fixed-partitions" compatible.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
Cc: Farhan Ali farhan.ali@broadcom.com Cc: Heinrich Schuchardt xypron.glpk@gmx.de Cc: Jagan Teki jagan@amarulasolutions.com Cc: Marek Behun marek.behun@nic.cz Cc: Miquel Raynal miquel.raynal@bootlin.com Cc: Simon Glass sjg@chromium.org Cc: Wolfgang Denk wd@denx.de
---
drivers/mtd/mtdpart.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 4119ea4ff6..d077897e4a 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -887,10 +887,14 @@ int add_mtd_partitions_of(struct mtd_info *master) ofnode parts, child; int i = 0;
- if (!master->dev) + if (!master->dev && !ofnode_valid(master->flash_node)) return 0;
- parts = ofnode_find_subnode(mtd_get_ofnode(master), "partitions"); + if (master->dev) + parts = ofnode_find_subnode(mtd_get_ofnode(master), "partitions"); + else + parts = ofnode_find_subnode(master->flash_node, "partitions"); + if (!ofnode_valid(parts) || !ofnode_is_available(parts) || !ofnode_device_is_compatible(parts, "fixed-partitions")) return 0;

On Mon, Mar 21, 2022 at 09:13:37AM +0100, Patrice Chotard wrote:
In case mtd_info's dev field is not populated (raw nand's case), use the flash_node new field which reference the DT flash node where can be found "partitions" node with "fixed-partitions" compatible.
Signed-off-by: Patrice Chotard patrice.chotard@foss.st.com
Cc: Farhan Ali farhan.ali@broadcom.com Cc: Heinrich Schuchardt xypron.glpk@gmx.de Cc: Jagan Teki jagan@amarulasolutions.com Cc: Marek Behun marek.behun@nic.cz Cc: Miquel Raynal miquel.raynal@bootlin.com Cc: Simon Glass sjg@chromium.org Cc: Wolfgang Denk wd@denx.de
Applied to u-boot/master, thanks!
participants (2)
-
Patrice Chotard
-
Tom Rini