diff options
author | Rafał Miłecki <rafal@milecki.pl> | 2017-01-10 15:12:04 +0100 |
---|---|---|
committer | Rafał Miłecki <rafal@milecki.pl> | 2017-01-10 15:37:22 +0100 |
commit | 1a5cb4ac1bd0f1a7047e2a6825950654c44ca01f (patch) | |
tree | eaab394a052a5a943f6a33b52a5c4d798f8779da /target/linux/generic/patches-4.4/141-0002-mtd-bcm47xxpart-support-layouts-with-multiple-TRX-pa.patch | |
parent | ef9208c51eff93c58de02691a87749fb184a2889 (diff) | |
download | upstream-1a5cb4ac1bd0f1a7047e2a6825950654c44ca01f.tar.gz upstream-1a5cb4ac1bd0f1a7047e2a6825950654c44ca01f.tar.bz2 upstream-1a5cb4ac1bd0f1a7047e2a6825950654c44ca01f.zip |
kernel: add pending bcm47xxpart support for failsafe TRX partition
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Diffstat (limited to 'target/linux/generic/patches-4.4/141-0002-mtd-bcm47xxpart-support-layouts-with-multiple-TRX-pa.patch')
-rw-r--r-- | target/linux/generic/patches-4.4/141-0002-mtd-bcm47xxpart-support-layouts-with-multiple-TRX-pa.patch | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/target/linux/generic/patches-4.4/141-0002-mtd-bcm47xxpart-support-layouts-with-multiple-TRX-pa.patch b/target/linux/generic/patches-4.4/141-0002-mtd-bcm47xxpart-support-layouts-with-multiple-TRX-pa.patch new file mode 100644 index 0000000000..1065322fd8 --- /dev/null +++ b/target/linux/generic/patches-4.4/141-0002-mtd-bcm47xxpart-support-layouts-with-multiple-TRX-pa.patch @@ -0,0 +1,108 @@ +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl> +Subject: [PATCH 2/2] mtd: bcm47xxpart: support layouts with multiple TRX + partitions +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +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(-) + +--- 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 + 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, + struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +@@ -157,7 +182,8 @@ static int bcm47xxpart_parse(struct mtd_ + 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_ + 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_ + } + + /* If there was TRX parse it now */ +- if (trx_part >= 0) { +- int num_parts; ++ for (i = 0; i < trx_num; i++) { ++ struct mtd_partition *trx = &parts[trx_parts[i]]; + +- 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; ++ 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; |