forked from torvalds/linux
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
mtd: parsers: ofpart: support BCM4908 fixed partitions
BCM4908 partitioning is based on fixed layout but allows specifying multiple firmware partitions. It requires detecting which firmware partition was used for booting current kernel. 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 callback 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>
- Loading branch information
1 parent
74a0b3a
commit 4453a81e3dd814c506fc96674433702c2a25a3c8
Showing
4 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // 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> | ||
|
|
||
| #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; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0 */ | ||
| #ifndef __BCM4908_PARTITIONS_H | ||
| #define __BCM4908_PARTITIONS_H | ||
|
|
||
| int bcm4908_partitions_post_parse(struct mtd_info *mtd, struct mtd_partition *parts, int nr_parts); | ||
|
|
||
| #endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters