bcm53xx: add Linksys Northstar parser
authorRafał Miłecki <rafal@milecki.pl>
Thu, 11 Mar 2021 08:00:05 +0000 (09:00 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Sat, 13 Mar 2021 08:28:02 +0000 (09:28 +0100)
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
target/linux/bcm53xx/patches-5.4/400-mtd-parsers-ofpart-support-Linksys-Northstar-partiti.patch [new file with mode: 0644]

diff --git a/target/linux/bcm53xx/patches-5.4/400-mtd-parsers-ofpart-support-Linksys-Northstar-partiti.patch b/target/linux/bcm53xx/patches-5.4/400-mtd-parsers-ofpart-support-Linksys-Northstar-partiti.patch
new file mode 100644 (file)
index 0000000..0f4d81b
--- /dev/null
@@ -0,0 +1,138 @@
+From e250d3fcf5b8e74672ecffc0addb29b3e6ba6e90 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
+Date: Tue, 2 Mar 2021 08:57:52 +0100
+Subject: [PATCH] mtd: parsers: ofpart: support Linksys Northstar partitions
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
+---
+ drivers/mtd/parsers/ofpart_core.c       |  6 ++++
+ drivers/mtd/parsers/ofpart_linksys_ns.c | 43 +++++++++++++++++++++++++
+ drivers/mtd/parsers/ofpart_linksys_ns.h | 16 +++++++++
+ drivers/mtd/parsers/parser_trx.c        |  4 +++
+ 4 files changed, 69 insertions(+)
+ create mode 100644 drivers/mtd/parsers/ofpart_linksys_ns.c
+ create mode 100644 drivers/mtd/parsers/ofpart_linksys_ns.h
+
+diff --git a/drivers/mtd/parsers/ofpart_core.c b/drivers/mtd/parsers/ofpart_core.c
+index 2b407c4e5..f88df9291 100644
+--- a/drivers/mtd/parsers/ofpart_core.c
++++ b/drivers/mtd/parsers/ofpart_core.c
+@@ -17,6 +17,7 @@
+ #include <linux/mtd/partitions.h>
+ #include "ofpart_bcm4908.h"
++#include "ofpart_linksys_ns.h"
+ struct fixed_partitions_quirks {
+       int (*post_parse)(struct mtd_info *mtd, struct mtd_partition *parts, int nr_parts);
+@@ -26,6 +27,10 @@ struct fixed_partitions_quirks bcm4908_partitions_quirks = {
+       .post_parse = bcm4908_partitions_post_parse,
+ };
++struct fixed_partitions_quirks linksys_ns_partitions_quirks = {
++      .post_parse = linksys_ns_partitions_post_parse,
++};
++
+ static const struct of_device_id parse_ofpart_match_table[];
+ static bool node_has_compatible(struct device_node *pp)
+@@ -162,6 +167,7 @@ static const struct of_device_id parse_ofpart_match_table[] = {
+       { .compatible = "fixed-partitions" },
+       /* Customized */
+       { .compatible = "brcm,bcm4908-partitions", .data = &bcm4908_partitions_quirks, },
++      { .compatible = "linksys,ns-partitions", .data = &linksys_ns_partitions_quirks, },
+       {},
+ };
+ MODULE_DEVICE_TABLE(of, parse_ofpart_match_table);
+diff --git a/drivers/mtd/parsers/ofpart_linksys_ns.c b/drivers/mtd/parsers/ofpart_linksys_ns.c
+new file mode 100644
+index 000000000..254b1eb18
+--- /dev/null
++++ b/drivers/mtd/parsers/ofpart_linksys_ns.c
+@@ -0,0 +1,43 @@
++// SPDX-License-Identifier: GPL-2.0
++/*
++ * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
++ */
++
++#include <linux/bcm47xx_nvram.h>
++#include <linux/mtd/mtd.h>
++#include <linux/mtd/partitions.h>
++
++#include "ofpart_linksys_ns.h"
++
++static int ofpart_linksys_ns_bootpartition(void)
++{
++      char buf[4];
++      int bootpartition;
++
++      /* Check CFE environment variable */
++      if (bcm47xx_nvram_getenv("bootpartition", buf, sizeof(buf)) > 0) {
++              if (!kstrtoint(buf, 0, &bootpartition))
++                      return bootpartition;
++      }
++
++      return 0;
++}
++
++int linksys_ns_partitions_post_parse(struct mtd_info *mtd, struct mtd_partition *parts,
++                                   int nr_parts)
++{
++      int bootpartition = ofpart_linksys_ns_bootpartition();
++      int trx_idx = 0;
++      int i;
++
++      for (i = 0; i < nr_parts; i++) {
++              if (of_device_is_compatible(parts[i].of_node, "brcm,trx")) {
++                      if (trx_idx++ == bootpartition)
++                              parts[i].name = "firmware";
++                      else
++                              parts[i].name = "backup";
++              }
++      }
++
++      return 0;
++}
+diff --git a/drivers/mtd/parsers/ofpart_linksys_ns.h b/drivers/mtd/parsers/ofpart_linksys_ns.h
+new file mode 100644
+index 000000000..574c1c601
+--- /dev/null
++++ b/drivers/mtd/parsers/ofpart_linksys_ns.h
+@@ -0,0 +1,16 @@
++/* SPDX-License-Identifier: GPL-2.0 */
++#ifndef __OFPART_LINKSYS_NS_H
++#define __OFPART_LINKSYS_NS_H
++
++#ifdef CONFIG_MTD_OF_PARTS_LINKSYS_NS
++int linksys_ns_partitions_post_parse(struct mtd_info *mtd, struct mtd_partition *parts,
++                                   int nr_parts);
++#else
++static inline int linksys_ns_partitions_post_parse(struct mtd_info *mtd,
++                                                 struct mtd_partition *parts, int nr_parts)
++{
++      return -EOPNOTSUPP;
++}
++#endif
++
++#endif
+diff --git a/drivers/mtd/parsers/parser_trx.c b/drivers/mtd/parsers/parser_trx.c
+index 555d7c263..8570d6633 100644
+--- a/drivers/mtd/parsers/parser_trx.c
++++ b/drivers/mtd/parsers/parser_trx.c
+@@ -85,6 +85,10 @@ static int parser_trx_parse(struct mtd_info *mtd,
+       uint8_t curr_part = 0, i = 0;
+       int err;
++      /* Don't parse backup partitions */
++      if (strcmp(mtd->name, "firmware"))
++              return -EINVAL;
++
+       parts = kcalloc(TRX_PARSER_MAX_PARTS, sizeof(struct mtd_partition),
+                       GFP_KERNEL);
+       if (!parts)
+-- 
+2.26.2
+