Skip to content

Commit 7134a2d

Browse files
Rafał Miłeckimiquelraynal
authored andcommitted
mtd: parsers: ofpart: support Linksys Northstar partitions
This allows extending ofpart parser with support for Linksys Northstar devices. That support uses recently added quirks mechanism. 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/20210312134919.7767-2-zajec5@gmail.com
1 parent 2fa7294 commit 7134a2d

5 files changed

Lines changed: 85 additions & 0 deletions

File tree

drivers/mtd/parsers/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ config MTD_OF_PARTS_BCM4908
7676
that can have multiple "firmware" partitions. It takes care of
7777
finding currently used one and backup ones.
7878

79+
config MTD_OF_PARTS_LINKSYS_NS
80+
bool "Linksys Northstar partitioning support"
81+
depends on MTD_OF_PARTS && (ARCH_BCM_5301X || ARCH_BCM4908 || COMPILE_TEST)
82+
default ARCH_BCM_5301X
83+
help
84+
This provides partitions parser for Linksys devices based on Broadcom
85+
Northstar architecture. Linksys commonly uses fixed flash layout with
86+
two "firmware" partitions. Currently used firmware has to be detected
87+
using CFE environment variable.
88+
7989
config MTD_PARSER_IMAGETAG
8090
tristate "Parser for BCM963XX Image Tag format partitions"
8191
depends on BCM63XX || BMIPS_GENERIC || COMPILE_TEST

drivers/mtd/parsers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
66
obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
77
ofpart-y += ofpart_core.o
88
ofpart-$(CONFIG_MTD_OF_PARTS_BCM4908) += ofpart_bcm4908.o
9+
ofpart-$(CONFIG_MTD_OF_PARTS_LINKSYS_NS)+= ofpart_linksys_ns.o
910
obj-$(CONFIG_MTD_PARSER_IMAGETAG) += parser_imagetag.o
1011
obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
1112
obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o

drivers/mtd/parsers/ofpart_core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/mtd/partitions.h>
1818

1919
#include "ofpart_bcm4908.h"
20+
#include "ofpart_linksys_ns.h"
2021

2122
struct fixed_partitions_quirks {
2223
int (*post_parse)(struct mtd_info *mtd, struct mtd_partition *parts, int nr_parts);
@@ -26,6 +27,10 @@ static struct fixed_partitions_quirks bcm4908_partitions_quirks = {
2627
.post_parse = bcm4908_partitions_post_parse,
2728
};
2829

30+
static struct fixed_partitions_quirks linksys_ns_partitions_quirks = {
31+
.post_parse = linksys_ns_partitions_post_parse,
32+
};
33+
2934
static const struct of_device_id parse_ofpart_match_table[];
3035

3136
static bool node_has_compatible(struct device_node *pp)
@@ -167,6 +172,7 @@ static const struct of_device_id parse_ofpart_match_table[] = {
167172
{ .compatible = "fixed-partitions" },
168173
/* Customized */
169174
{ .compatible = "brcm,bcm4908-partitions", .data = &bcm4908_partitions_quirks, },
175+
{ .compatible = "linksys,ns-partitions", .data = &linksys_ns_partitions_quirks, },
170176
{},
171177
};
172178
MODULE_DEVICE_TABLE(of, parse_ofpart_match_table);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 *parts,
34+
int nr_parts)
35+
{
36+
int bootpartition = ofpart_linksys_ns_bootpartition();
37+
int trx_idx = 0;
38+
int i;
39+
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";
44+
else
45+
parts[i].name = "backup";
46+
}
47+
}
48+
49+
return 0;
50+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __OFPART_LINKSYS_NS_H
3+
#define __OFPART_LINKSYS_NS_H
4+
5+
#ifdef CONFIG_MTD_OF_PARTS_LINKSYS_NS
6+
int linksys_ns_partitions_post_parse(struct mtd_info *mtd,
7+
struct mtd_partition *parts,
8+
int nr_parts);
9+
#else
10+
static inline int linksys_ns_partitions_post_parse(struct mtd_info *mtd,
11+
struct mtd_partition *parts,
12+
int nr_parts)
13+
{
14+
return -EOPNOTSUPP;
15+
}
16+
#endif
17+
18+
#endif

0 commit comments

Comments
 (0)