b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl> |
| 4 | */ |
| 5 | |
| 6 | #include <linux/bcm47xx_nvram.h> |
| 7 | #include <linux/mtd/mtd.h> |
| 8 | #include <linux/mtd/partitions.h> |
| 9 | |
| 10 | #include "ofpart_linksys_ns.h" |
| 11 | |
| 12 | #define NVRAM_BOOT_PART "bootpartition" |
| 13 | |
| 14 | static int ofpart_linksys_ns_bootpartition(void) |
| 15 | { |
| 16 | char buf[4]; |
| 17 | int bootpartition; |
| 18 | |
| 19 | /* Check CFE environment variable */ |
| 20 | if (bcm47xx_nvram_getenv(NVRAM_BOOT_PART, buf, sizeof(buf)) > 0) { |
| 21 | if (!kstrtoint(buf, 0, &bootpartition)) |
| 22 | return bootpartition; |
| 23 | pr_warn("Failed to parse %s value \"%s\"\n", NVRAM_BOOT_PART, |
| 24 | buf); |
| 25 | } else { |
| 26 | pr_warn("Failed to get NVRAM \"%s\"\n", NVRAM_BOOT_PART); |
| 27 | } |
| 28 | |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | int linksys_ns_partitions_post_parse(struct mtd_info *mtd, |
| 33 | struct mtd_partition **pparts, |
| 34 | int nr_parts) |
| 35 | { |
| 36 | struct mtd_partition *parts = *pparts; |
| 37 | int bootpartition = ofpart_linksys_ns_bootpartition(); |
| 38 | int trx_idx = 0; |
| 39 | int i; |
| 40 | |
| 41 | for (i = 0; i < nr_parts; i++) { |
| 42 | if (of_device_is_compatible(parts[i].of_node, "linksys,ns-firmware")) { |
| 43 | if (trx_idx++ == bootpartition) |
| 44 | parts[i].name = "firmware"; |
| 45 | else |
| 46 | parts[i].name = "backup"; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return nr_parts; |
| 51 | } |