Patchwork [V2] mtd: bcm47xxpart: find NVRAM partitions in middle blocks

login
register
mail settings
Submitter Rafał Miłecki
Date Aug. 18, 2014, 6:20 p.m.
Message ID <1408386027-12120-1-git-send-email-zajec5@gmail.com>
Download mbox | patch
Permalink /patch/381091/
State New
Headers show

Comments

Rafał Miłecki - Aug. 18, 2014, 6:20 p.m.
Old devices used to have NVRAM at the very end of flash and they could
be unaligned (starting at some offset in a block).
In new devices NVRAM can be located quite randomly, however it seems to
always start at the beginning of a block. For example Netgear R6250 has
NVRAM located right after the bootloader, before the kernel partition.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
---
V2: Ignore last block to avoid having two "nvram" partitions.
---
 drivers/mtd/bcm47xxpart.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Patch

diff --git a/drivers/mtd/bcm47xxpart.c b/drivers/mtd/bcm47xxpart.c
index 035690e..da641ac 100644
--- a/drivers/mtd/bcm47xxpart.c
+++ b/drivers/mtd/bcm47xxpart.c
@@ -224,6 +224,16 @@  static int bcm47xxpart_parse(struct mtd_info *master,
 			continue;
 		}
 
+		/* New (ARM?) devices may have NVRAM in some middle block. Last
+		 * block will be checked later, so skip it.
+		 */
+		if (offset != master->size - blocksize &&
+		    buf[0x000 / 4] == NVRAM_HEADER) {
+			bcm47xxpart_add_part(&parts[curr_part++], "nvram",
+					     offset, 0);
+			continue;
+		}
+
 		/* Read middle of the block */
 		if (mtd_read(master, offset + 0x8000, 0x4,
 			     &bytes_read, (uint8_t *)buf) < 0) {