1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Subject: [PATCH 2/2] mtd: bcm47xxpart: support layouts with multiple TRX
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
8 Some devices may have an extra TRX partition used as failsafe one. If
9 we detect such partition we should set a proper name for it and don't
12 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
14 drivers/mtd/bcm47xxpart.c | 56 ++++++++++++++++++++++++++++++++++++++---------
15 1 file changed, 46 insertions(+), 10 deletions(-)
17 --- a/drivers/mtd/bcm47xxpart.c
18 +++ b/drivers/mtd/bcm47xxpart.c
23 +#include <linux/bcm47xx_nvram.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 @@ -144,6 +145,30 @@ static int bcm47xxpart_parse_trx(struct
32 + * bcm47xxpart_bootpartition - gets index of TRX partition used by bootloader
34 + * Some devices may have more than one TRX partition. In such case one of them
35 + * is the main one and another a failsafe one. Bootloader may fallback to the
36 + * failsafe firmware if it detects corruption of the main image.
38 + * This function provides info about currently used TRX partition. It's the one
39 + * containing kernel started by the bootloader.
41 +static int bcm47xxpart_bootpartition(void)
46 + /* Check CFE environment variable */
47 + if (bcm47xx_nvram_getenv("bootpartition", buf, sizeof(buf)) > 0) {
48 + if (!kstrtoint(buf, 0, &bootpartition))
49 + return bootpartition;
55 static int bcm47xxpart_parse(struct mtd_info *master,
56 struct mtd_partition **pparts,
57 struct mtd_part_parser_data *data)
58 @@ -154,7 +179,8 @@ static int bcm47xxpart_parse(struct mtd_
61 uint32_t blocksize = master->erasesize;
63 + int trx_parts[2]; /* Array with indexes of TRX partitions */
64 + int trx_num = 0; /* Number of found TRX partitions */
65 int possible_nvram_sizes[] = { 0x8000, 0xF000, 0x10000, };
68 @@ -243,7 +269,11 @@ static int bcm47xxpart_parse(struct mtd_
69 if (buf[0x000 / 4] == TRX_MAGIC) {
70 struct trx_header *trx;
72 - trx_part = curr_part;
73 + if (trx_num >= ARRAY_SIZE(trx_parts))
74 + pr_warn("No enough space to store another TRX found at 0x%X\n",
77 + trx_parts[trx_num++] = curr_part;
78 bcm47xxpart_add_part(&parts[curr_part++], "firmware",
81 @@ -329,14 +359,20 @@ static int bcm47xxpart_parse(struct mtd_
84 /* If there was TRX parse it now */
85 - if (trx_part >= 0) {
87 + for (i = 0; i < trx_num; i++) {
88 + struct mtd_partition *trx = &parts[trx_parts[i]];
90 - num_parts = bcm47xxpart_parse_trx(master, &parts[trx_part],
92 - BCM47XXPART_MAX_PARTS - curr_part);
94 - curr_part += num_parts;
95 + if (i == bcm47xxpart_bootpartition()) {
98 + num_parts = bcm47xxpart_parse_trx(master, trx,
100 + BCM47XXPART_MAX_PARTS - curr_part);
102 + curr_part += num_parts;
104 + trx->name = "failsafe";