From: "Rafał Miłecki" <zajec5@gmail.com>
To: David Woodhouse <dwmw2@infradead.org>,
Brian Norris <computersforpeace@gmail.com>,
Boris Brezillon <boris.brezillon@free-electrons.com>,
Marek Vasut <marek.vasut@gmail.com>,
Richard Weinberger <richard@nod.at>,
Cyrille Pitchen <cyrille.pitchen@atmel.com>
Cc: linux-mtd@lists.infradead.org,
"Hauke Mehrtens" <hauke@hauke-m.de>,
"Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH 2/2] mtd: bcm47xxpart: support layouts with multiple TRX partitions
Date: Tue, 10 Jan 2017 12:50:45 +0100 [thread overview]
Message-ID: <20170110115045.9134-2-zajec5@gmail.com> (raw)
In-Reply-To: <20170110115045.9134-1-zajec5@gmail.com>
From: Rafał Miłecki <rafal@milecki.pl>
Some devices may have an extra TRX partition used as failsafe one. If
we detect such partition we should set a proper name for it and don't
parse it.
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
drivers/mtd/bcm47xxpart.c | 56 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 46 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/bcm47xxpart.c b/drivers/mtd/bcm47xxpart.c
index d7d1b6e..95cfd88 100644
--- a/drivers/mtd/bcm47xxpart.c
+++ b/drivers/mtd/bcm47xxpart.c
@@ -9,6 +9,7 @@
*
*/
+#include <linux/bcm47xx_nvram.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
@@ -147,6 +148,30 @@ static int bcm47xxpart_parse_trx(struct mtd_info *master,
return curr_part;
}
+/**
+ * bcm47xxpart_bootpartition - gets index of TRX partition used by bootloader
+ *
+ * Some devices may have more than one TRX partition. In such case one of them
+ * is the main one and another a failsafe one. Bootloader may fallback to the
+ * failsafe firmware if it detects corruption of the main image.
+ *
+ * This function provides info about currently used TRX partition. It's the one
+ * containing kernel started by the bootloader.
+ */
+static int bcm47xxpart_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;
+}
+
static int bcm47xxpart_parse(struct mtd_info *master,
const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
@@ -157,7 +182,8 @@ static int bcm47xxpart_parse(struct mtd_info *master,
size_t bytes_read;
uint32_t offset;
uint32_t blocksize = master->erasesize;
- int trx_part = -1;
+ int trx_parts[2]; /* Array with indexes of TRX partitions */
+ int trx_num = 0; /* Number of found TRX partitions */
int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
int err;
@@ -246,7 +272,11 @@ static int bcm47xxpart_parse(struct mtd_info *master,
if (buf[0x000 / 4] == TRX_MAGIC) {
struct trx_header *trx;
- trx_part = curr_part;
+ if (trx_num >= ARRAY_SIZE(trx_parts))
+ pr_warn("No enough space to store another TRX found at 0x%X\n",
+ offset);
+ else
+ trx_parts[trx_num++] = curr_part;
bcm47xxpart_add_part(&parts[curr_part++], "firmware",
offset, 0);
@@ -332,14 +362,20 @@ static int bcm47xxpart_parse(struct mtd_info *master,
}
/* If there was TRX parse it now */
- if (trx_part >= 0) {
- int num_parts;
-
- num_parts = bcm47xxpart_parse_trx(master, &parts[trx_part],
- parts + curr_part,
- BCM47XXPART_MAX_PARTS - curr_part);
- if (num_parts > 0)
- curr_part += num_parts;
+ for (i = 0; i < trx_num; i++) {
+ struct mtd_partition *trx = &parts[trx_parts[i]];
+
+ if (i == bcm47xxpart_bootpartition()) {
+ int num_parts;
+
+ num_parts = bcm47xxpart_parse_trx(master, trx,
+ parts + curr_part,
+ BCM47XXPART_MAX_PARTS - curr_part);
+ if (num_parts > 0)
+ curr_part += num_parts;
+ } else {
+ trx->name = "failsafe";
+ }
}
*pparts = parts;
--
2.10.1
next prev parent reply other threads:[~2017-01-10 11:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 11:50 [PATCH 1/2] mtd: bcm47xxpart: move TRX parsing code to separated function Rafał Miłecki
2017-01-10 11:50 ` Rafał Miłecki [this message]
2017-01-10 16:19 ` Marek Vasut
2017-01-10 16:27 ` Rafał Miłecki
2017-01-10 17:42 ` Marek Vasut
2017-01-10 22:15 ` [PATCH V2 " Rafał Miłecki
2017-01-10 22:15 ` [PATCH V2 2/2] mtd: bcm47xxpart: support layouts with multiple TRX partitions Rafał Miłecki
2017-02-09 16:54 ` [PATCH V2 1/2] mtd: bcm47xxpart: move TRX parsing code to separated function Rafał Miłecki
2017-02-09 17:29 ` Marek Vasut
2017-02-09 17:28 ` Marek Vasut
2017-02-09 18:05 ` Rafał Miłecki
2017-02-09 18:21 ` Marek Vasut
2017-02-09 19:11 ` Boris Brezillon
2017-02-09 19:33 ` Marek Vasut
2017-02-10 3:00 ` Brian Norris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170110115045.9134-2-zajec5@gmail.com \
--to=zajec5@gmail.com \
--cc=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@atmel.com \
--cc=dwmw2@infradead.org \
--cc=hauke@hauke-m.de \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=rafal@milecki.pl \
--cc=richard@nod.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).