1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
6 #include <linux/bcm47xx_nvram.h>
7 #include <linux/mtd/mtd.h>
8 #include <linux/mtd/partitions.h>
10 #include "ofpart_linksys_ns.h"
12 #define NVRAM_BOOT_PART "bootpartition"
14 static int ofpart_linksys_ns_bootpartition(void)
19 /* Check CFE environment variable */
20 if (bcm47xx_nvram_getenv(NVRAM_BOOT_PART, buf, sizeof(buf)) > 0) {
21 if (!kstrtoint(buf, 0, &bootpartition))
23 pr_warn("Failed to parse %s value \"%s\"\n", NVRAM_BOOT_PART,
26 pr_warn("Failed to get NVRAM \"%s\"\n", NVRAM_BOOT_PART);
32 int linksys_ns_partitions_post_parse(struct mtd_info *mtd,
33 struct mtd_partition *parts,
36 int bootpartition = ofpart_linksys_ns_bootpartition();
40 for (i = 0; i < nr_parts; i++) {
41 if (of_device_is_compatible(parts[i].of_node, "linksys,ns-firmware")) {
42 if (trx_idx++ == bootpartition)
43 parts[i].name = "firmware";
45 parts[i].name = "backup";