Skip to contentSkip to conversation

mtd: bcm47xxpart: find NVRAM partitions in middle blocks

PATCH Superseded Rafał Miłecki 2 participants 3 messages Aug 14, 2014 – Sep 18, 2014 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: bcm47xxpart: find NVRAM partitions in middle blocks

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.

---
 drivers/mtd/bcm47xxpart.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/mtd/bcm47xxpart.c +7 -0
index adfa74c..407a444 100644
@@ -199,6 +199,13 @@ static int bcm47xxpart_parse(struct mtd_info *master,
 			continue;
 		}
 
+		/* New (ARM?) devices may have NVRAM in some middle block */
+		if (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) {
Signature · 1 line
1.8.4.5
#1 lore raw

PATCH v2 1/1 mtd: bcm47xxpart: find NVRAM partitions in middle blocks

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.

---
V2: Ignore last block to avoid having two "nvram" partitions.

---
 drivers/mtd/bcm47xxpart.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/mtd/bcm47xxpart.c +10 -0
index 035690e..da641ac 100644
@@ -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) {
Signature · 1 line
1.8.4.5
#2 lore raw
Quoted 9 lines · Rafał Miłecki

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.

---
V2: Ignore last block to avoid having two "nvram" partitions.

Tweaked the multi-line comment style and pushed to l2-mtd.git. Thanks!

Quoted 15 lines
---
 drivers/mtd/bcm47xxpart.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/mtd/bcm47xxpart.c +3 -0
index 035690e..da641ac 100644
@@ -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.
+		 */

drivers/mtd/bcm47xxpart.c static int bcm47xxpart_parse(struct mtd_info *master, · line 239

Quoted 10 lines
drivers/mtd/bcm47xxpart.c +7 -0
+		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) {

Brian