diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2020-11-24 20:36:44 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-11-25 06:30:54 +0100 |
commit | 8248621078de084fd991ce67e823ea78eb6edb83 (patch) | |
tree | c4cb172df7284bf0c685f43fbb07cb8de40651d1 | |
parent | fa9179444c36f9daf5010215cf8e4dcb3bd1ffb2 (diff) | |
download | barebox-8248621078de084fd991ce67e823ea78eb6edb83.tar.gz barebox-8248621078de084fd991ce67e823ea78eb6edb83.tar.xz |
mtd: Add hook to fix up kernel partitions
Some drivers have special requirements for fixing up the partition
nodes for the kernel. This adds a hook to struct mtd_info that can
be used by drivers to replace the generic fixup with a special one.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/mtd/core.c | 30 | ||||
-rw-r--r-- | include/linux/mtd/mtd.h | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c index e21c71b816..af33ad665c 100644 --- a/drivers/mtd/core.c +++ b/drivers/mtd/core.c @@ -639,6 +639,34 @@ static int mtd_detect(struct device_d *dev) return ret; } +static int mtd_partition_fixup_generic(struct mtd_info *mtd, struct device_node *root) +{ + struct cdev *cdev = &mtd->cdev; + struct device_node *np, *mtdnp = mtd_get_of_node(mtd); + char *name; + + name = of_get_reproducible_name(mtdnp); + np = of_find_node_by_reproducible_name(root, name); + free(name); + if (!np) { + dev_err(&mtd->dev, "Cannot find nodepath %s, cannot fixup\n", + mtdnp->full_name); + return -EINVAL; + } + + return of_fixup_partitions(np, cdev); +} + +static int mtd_partition_fixup(struct device_node *root, void *ctx) +{ + struct mtd_info *mtd = ctx; + + if (mtd->of_fixup) + return mtd->of_fixup(mtd, root); + + return mtd_partition_fixup_generic(mtd, root); +} + int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id) { struct mtddev_hook *hook; @@ -706,7 +734,7 @@ int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id) dev_add_param_string(&mtd->dev, "partitions", mtd_partition_set, mtd_partition_get, &mtd->partition_string, mtd); if (IS_ENABLED(CONFIG_OFDEVICE) && np) { of_parse_partitions(&mtd->cdev, np); - ret = of_partitions_register_fixup(&mtd->cdev); + ret = of_register_fixup(mtd_partition_fixup, mtd); if (ret) goto err1; } diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 0e2ff4526d..0d977fea25 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -206,6 +206,8 @@ struct mtd_info { int (*_block_markbad) (struct mtd_info *mtd, loff_t ofs); int (*_block_markgood) (struct mtd_info *mtd, loff_t ofs); + int (*of_fixup)(struct mtd_info *mtd, struct device_node *root); + /* ECC status information */ struct mtd_ecc_stats ecc_stats; /* Subpage shift (NAND) */ |