diff options
author | Rafał Miłecki <rafal@milecki.pl> | 2021-03-01 13:58:23 +0300 |
---|---|---|
committer | Miquel Raynal <miquel.raynal@bootlin.com> | 2021-03-11 11:37:49 +0300 |
commit | bb17230c61a6424b622e92006ec52ba23aa5a967 (patch) | |
tree | af733f0e7d8191970aa843567622d3489241bc30 /drivers/mtd/parsers/ofpart_bcm4908.c | |
parent | 462d69a2dc3d6d8289d99479961632411b9d30ad (diff) | |
download | linux-bb17230c61a6424b622e92006ec52ba23aa5a967.tar.xz |
mtd: parsers: ofpart: support BCM4908 fixed partitions
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.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210301105823.31032-1-zajec5@gmail.com
Diffstat (limited to 'drivers/mtd/parsers/ofpart_bcm4908.c')
-rw-r--r-- | drivers/mtd/parsers/ofpart_bcm4908.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/drivers/mtd/parsers/ofpart_bcm4908.c b/drivers/mtd/parsers/ofpart_bcm4908.c new file mode 100644 index 000000000000..0eddef4c198e --- /dev/null +++ b/drivers/mtd/parsers/ofpart_bcm4908.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl> + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/of.h> +#include <linux/mtd/mtd.h> +#include <linux/slab.h> +#include <linux/mtd/partitions.h> + +#include "ofpart_bcm4908.h" + +#define BLPARAMS_FW_OFFSET "NAND_RFS_OFS" + +static long long bcm4908_partitions_fw_offset(void) +{ + struct device_node *root; + struct property *prop; + const char *s; + + root = of_find_node_by_path("/"); + if (!root) + return -ENOENT; + + of_property_for_each_string(root, "brcm_blparms", prop, s) { + size_t len = strlen(BLPARAMS_FW_OFFSET); + unsigned long offset; + int err; + + if (strncmp(s, BLPARAMS_FW_OFFSET, len) || s[len] != '=') + continue; + + err = kstrtoul(s + len + 1, 0, &offset); + if (err) { + pr_err("failed to parse %s\n", s + len + 1); + return err; + } + + return offset << 10; + } + + return -ENOENT; +} + +int bcm4908_partitions_post_parse(struct mtd_info *mtd, struct mtd_partition *parts, int nr_parts) +{ + long long fw_offset; + int i; + + fw_offset = bcm4908_partitions_fw_offset(); + + for (i = 0; i < nr_parts; i++) { + if (of_device_is_compatible(parts[i].of_node, "brcm,bcm4908-firmware")) { + if (fw_offset < 0 || parts[i].offset == fw_offset) + parts[i].name = "firmware"; + else + parts[i].name = "backup"; + } + } + + return 0; +} |