1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
6 #include <linux/module.h>
7 #include <linux/init.h>
9 #include <linux/mtd/mtd.h>
10 #include <linux/slab.h>
11 #include <linux/mtd/partitions.h>
13 #include "ofpart_bcm4908.h"
15 #define BLPARAMS_FW_OFFSET "NAND_RFS_OFS"
17 static long long bcm4908_partitions_fw_offset(void)
19 struct device_node
*root
;
20 struct property
*prop
;
23 root
= of_find_node_by_path("/");
27 of_property_for_each_string(root
, "brcm_blparms", prop
, s
) {
28 size_t len
= strlen(BLPARAMS_FW_OFFSET
);
32 if (strncmp(s
, BLPARAMS_FW_OFFSET
, len
) || s
[len
] != '=')
35 err
= kstrtoul(s
+ len
+ 1, 0, &offset
);
37 pr_err("failed to parse %s\n", s
+ len
+ 1);
50 int bcm4908_partitions_post_parse(struct mtd_info
*mtd
, struct mtd_partition
*parts
, int nr_parts
)
55 fw_offset
= bcm4908_partitions_fw_offset();
57 for (i
= 0; i
< nr_parts
; i
++) {
58 if (of_device_is_compatible(parts
[i
].of_node
, "brcm,bcm4908-firmware")) {
59 if (fw_offset
< 0 || parts
[i
].offset
== fw_offset
)
60 parts
[i
].name
= "firmware";
62 parts
[i
].name
= "backup";