mtd: parsers: ofpart: support BCM4908 fixed partitions
PATCH v4 1/1 mtd: parsers: ofpart: support BCM4908 fixed partitions
From: Rafał Miłecki <[email protected]>
Some devices use fixed partitioning with some partitions requiring some extra logic. E.g. BCM4908 may have multiple firmware partitions but detecting currently used one requires checking bootloader parameters.
To support such cases without duplicating a lot of code (without copying most of the ofpart.c code) support for post-parsing callback was added.
BCM4908 support in ofpart can be enabled using config option and results in compiling & executing a specific callback. It simply reads offset of currently used firmware partition from the DT. Bootloader specifies it using the "brcm_blparms" property.
---
V4: Rework Makefile changes, use ofpart_core.c to avoid compilation and
module loading problems. Kernel doesn't like building object files using source file of the same name + additional source files.
This patch has been compile-tested using 4 config variants:
CONFIG_MTD_OF_PARTS=m
# CONFIG_MTD_OF_PARTS_BCM4908 is not set
CONFIG_MTD_OF_PARTS=mCONFIG_MTD_OF_PARTS_BCM4908=y
CONFIG_MTD_OF_PARTS=y
# CONFIG_MTD_OF_PARTS_BCM4908 is not set
CONFIG_MTD_OF_PARTS=yCONFIG_MTD_OF_PARTS_BCM4908=y
Additionally both: "fixed-partitions" and "brcm,bcm4908-partitions" were runtime-tested using 2 config variants:
CONFIG_MTD_OF_PARTS=y
# CONFIG_MTD_OF_PARTS_BCM4908 is not set
CONFIG_MTD_OF_PARTS=yCONFIG_MTD_OF_PARTS_BCM4908=y
---
drivers/mtd/parsers/Kconfig | 9 +++
drivers/mtd/parsers/Makefile | 2 +
drivers/mtd/parsers/ofpart_bcm4908.c | 64 +++++++++++++++++++
drivers/mtd/parsers/ofpart_bcm4908.h | 15 +++++
.../mtd/parsers/{ofpart.c => ofpart_core.c} | 28 +++++++-
5 files changed, 116 insertions(+), 2 deletions(-)
create mode 100644 drivers/mtd/parsers/ofpart_bcm4908.c
create mode 100644 drivers/mtd/parsers/ofpart_bcm4908.h
rename drivers/mtd/parsers/{ofpart.c => ofpart_core.c} (88%)drivers/mtd/parsers/Kconfig +9 -0
@@ -67,6 +67,15 @@ config MTD_OF_PARTS flash memory node, as described in Documentation/devicetree/bindings/mtd/partition.txt. +config MTD_OF_PARTS_BCM4908 + bool "BCM4908 partitioning support" + depends on MTD_OF_PARTS && (ARCH_BCM4908 || COMPILE_TEST) + default ARCH_BCM4908 + help + This provides partitions parser for BCM4908 family devices + that can have multiple "firmware" partitions. It takes care of + finding currently used one and backup ones. + config MTD_PARSER_IMAGETAG tristate "Parser for BCM963XX Image Tag format partitions" depends on BCM63XX || BMIPS_GENERIC || COMPILE_TEST
drivers/mtd/parsers/Makefile +2 -0
@@ -4,6 +4,8 @@ obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o +ofpart-y += ofpart_core.o +ofpart-$(CONFIG_MTD_OF_PARTS_BCM4908) += ofpart_bcm4908.o obj-$(CONFIG_MTD_PARSER_IMAGETAG) += parser_imagetag.o obj-$(CONFIG_MTD_AFS_PARTS) += afs.o obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o
drivers/mtd/parsers/ofpart_bcm4908.c new file +64 -0
64 lines not on this page · raw message
drivers/mtd/parsers/ofpart_bcm4908.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __BCM4908_PARTITIONS_H +#define __BCM4908_PARTITIONS_H + +#ifdef CONFIG_MTD_OF_PARTS_BCM4908 +int bcm4908_partitions_post_parse (struct mtd_info *mtd,struct mtd_partition *parts,int nr_parts); +#else +static inline int bcm4908_partitions_post_parse (struct mtd_info *mtd,struct mtd_partition *parts, +int nr_parts) +{ +return -EOPNOTSUPP ; +} +#endif + +#endif
drivers/mtd/parsers/ofpart_core.c renamed from drivers/mtd/parsers/ofpart.c +26 -2
@@ -16,6 +16,18 @@#include <linux/slab.h> #include <linux/mtd/partitions.h> +#include "ofpart_bcm4908.h" + +struct fixed_partitions_quirks { +int (*post_parse)(struct mtd_info *mtd,struct mtd_partition *parts,int nr_parts); +}; + +struct fixed_partitions_quirks bcm4908_partitions_quirks = { + .post_parse = bcm4908_partitions_post_parse, +}; + +static const struct of_device_id parse_ofpart_match_table[]; +static bool node_has_compatible (struct device_node *pp) {return of_get_property (pp,"compatible" ,NULL );
@@ -25,6 +37,8 @@ static int parse_fixed_partitions(struct mtd_info *master,const struct mtd_partition **pparts, struct mtd_part_parser_data *data) { + const struct fixed_partitions_quirks *quirks; +const struct of_device_id *of_id;struct mtd_partition *parts;struct device_node *mtd_node;struct device_node *ofpart_node;
@@ -33,7 +47,6 @@ static int parse_fixed_partitions(struct mtd_info *master,int nr_parts, i, ret =0 ;bool dedicated = true; -/* Pull of_node from the master device node */ mtd_node =mtd_get_of_node (master);if (!mtd_node)
@@ -50,11 +63,16 @@ static int parse_fixed_partitions(struct mtd_info *master, master->name, mtd_node); ofpart_node = mtd_node; dedicated = false; - }else if (!of_device_is_compatible (ofpart_node,"fixed-partitions" )) { + } + + of_id =of_match_node (parse_ofpart_match_table, ofpart_node); +if (dedicated && !of_id) {/* The 'partitions' subnode might be used by another parser */ return 0 ; } + quirks = of_id ? of_id->data :NULL ; +/* First count the subnodes */ nr_parts =0 ;for_each_child_of_node (ofpart_node, pp) {
@@ -126,6 +144,9 @@ static int parse_fixed_partitions(struct mtd_info *master,if (!nr_parts) goto ofpart_none; +if (quirks && quirks->post_parse) + quirks->post_parse (master, parts, nr_parts); + *pparts = parts;return nr_parts;
@@ -140,7 +161,10 @@ static int parse_fixed_partitions(struct mtd_info *master, }static const struct of_device_id parse_ofpart_match_table[] = { +/* Generic */ { .compatible ="fixed-partitions" }, +/* Customized */ + { .compatible ="brcm,bcm4908-partitions" , .data = &bcm4908_partitions_quirks, }, {}, };MODULE_DEVICE_TABLE (of, parse_ofpart_match_table);
Signature · 6 lines
2.26.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Quoted 9 lines · On Mon, 2021-03-01 at 10:58:23 UTC, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= wrote:
From: Rafał Miłecki <[email protected]>
Some devices use fixed partitioning with some partitions requiring some extra logic. E.g. BCM4908 may have multiple firmware partitions but detecting currently used one requires checking bootloader parameters.
To support such cases without duplicating a lot of code (without copying most of the
ofpart.ccode) support for post-parsing callback was added.
Quoted 6 lines
BCM4908 support in ofpart can be enabled using config option and results in compiling & executing a specific callback. It simply reads offset of currently used firmware partition from the DT. Bootloader specifies it using the "
brcm_blparms" property.Signed-off-by Rafał Miłecki <[email protected]>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.
Miquel
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/