On Thu, 9 Feb 2012 18:40:18 +0100
Stefan Tauner <[email protected]> wrote:

> this one now is somewhat tested and not THAT broken as the one from
> last night... :)
> 
> i have (at least)...
>  - removed the sfdp_fetch_pt function and integrated the hexdump-like
>    code into the loop. it fits there better imo.
>  - corrected the overflow check to use a 24b boundary instead of 16b
>    because SFDP has 24b-addressing just like normal SPI flash space.
>  - refined the output verbosity of probe_spi_sfdp (again).
>  - renamed the struct flash's model from "SFDP device" to "SFDP-capable
>    chip".
> 

two addon patches... 
-- 
Kind regards/Mit freundlichen Grüßen, Stefan Tauner
>From 384261200aae51abe163406d7ea4d6d248fd4a72 Mon Sep 17 00:00:00 2001
From: Stefan Tauner <[email protected]>
Date: Thu, 9 Feb 2012 20:35:13 +0100
Subject: [PATCH 1/2] fixup! Add support for SFDP (JESD216).

minor changes:
 - rename blocksize to block_size to better match total_size
 - source code formatting
 - additional checks in sfdp_add_uniform_eraser

Signed-off-by: Stefan Tauner <[email protected]>
---
 sfdp.c |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/sfdp.c b/sfdp.c
index 9fbcddc..397c8af 100644
--- a/sfdp.c
+++ b/sfdp.c
@@ -72,22 +72,36 @@ struct sfdp_tbl_hdr {
 	uint32_t ptp; /* 24b pointer */
 };
 
-static int sfdp_add_uniform_eraser(struct flashctx *flash, uint8_t opcode, uint32_t blocksize)
+static int sfdp_add_uniform_eraser(struct flashctx *flash, uint8_t opcode, uint32_t block_size)
 {
-	uint32_t total_size = flash->total_size * 1024;
 	int i;
+	uint32_t total_size = flash->total_size * 1024;
 	erasefunc_t *erasefn = spi_get_erasefn_from_opcode(opcode);
-	if (erasefn == NULL)
+
+	if (erasefn == NULL || block_size == 0 || total_size % block_size != 0)
 		return 1;
+
 	for (i = 0; i < NUM_ERASEFUNCTIONS; i++) {
 		struct block_eraser *eraser = &flash->block_erasers[i];
-		if (eraser->eraseblocks[0].size != 0 || !eraser->block_erase)
+		/* Check for duplicates (including (some) non-uniform ones). */
+		if (eraser->eraseblocks[0].size == block_size &&
+		    eraser->block_erase == erasefn) {
+			msg_cdbg2("  Tried to add a duplicate block eraser: "
+				  "%d x %d B with opcode 0x%02x\n",
+				  total_size/block_size, block_size, opcode);
+			return 1;
+		}
+		if (eraser->eraseblocks[0].size != 0 || !eraser->block_erase) {
+			msg_cspew("  Block Eraser %d is already occupied.\n",
+				  i);
 			continue;
+		}
+
 		eraser->block_erase = erasefn;
-		eraser->eraseblocks[0].size = blocksize;
-		eraser->eraseblocks[0].count = total_size/blocksize;
+		eraser->eraseblocks[0].size = block_size;
+		eraser->eraseblocks[0].count = total_size/block_size;
 		msg_cdbg2("  Block eraser %d: %d x %d B with opcode "
-			  "0x%02x\n", i, total_size/blocksize, blocksize,
+			  "0x%02x\n", i, total_size/block_size, block_size,
 			  opcode);
 		return 0;
 	}
@@ -102,8 +116,8 @@ static int sfdp_fill_flash(struct flashctx *flash, uint8_t *buf, uint16_t len)
 	uint32_t tmp32;
 	uint8_t tmp8;
 	uint32_t total_size; /* in bytes */
-	uint32_t blocksize;
 	uint8_t opcode_4k = 0xFF;
+	uint32_t block_size;
 	int dw, j;
 
 	msg_cdbg("Parsing JEDEC flash parameter table... ");
@@ -205,15 +219,15 @@ static int sfdp_fill_flash(struct flashctx *flash, uint8_t *buf, uint16_t len)
 				  "for flashrom.\n", j, tmp8);
 			continue;
 		}
-		blocksize = 1 << (tmp8); /* blocksize = 2 ^ field */
+		block_size = 1 << (tmp8); /* block_size = 2 ^ field */
 
 		tmp8 = buf[(4 * dw) + (2 * j) + 1];
-		if (sfdp_add_uniform_eraser(flash, tmp8, blocksize))
+		if (sfdp_add_uniform_eraser(flash, tmp8, block_size))
 			continue;
 		/* If there is a valid 4k value in the last double words,
 		 * we want to override the value from double word 1, hence force
 		 * skipping its processing: */
-		if (blocksize == 4 * 1024 && tmp8 == opcode_4k)
+		if (block_size == 4 * 1024 && tmp8 == opcode_4k)
 			opcode_4k = 0xFF;
 	}
 
-- 
1.7.1

>From d65d292a7adbb659846bdd91615503ff96c40ccb Mon Sep 17 00:00:00 2001
From: Stefan Tauner <[email protected]>
Date: Thu, 9 Feb 2012 20:33:50 +0100
Subject: [PATCH 2/2] fixup! Add support for SFDP (JESD216).

suggested simplified 4k handling

Signed-off-by: Stefan Tauner <[email protected]>
---
 sfdp.c |   15 +++------------
 1 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/sfdp.c b/sfdp.c
index 397c8af..70f2872 100644
--- a/sfdp.c
+++ b/sfdp.c
@@ -116,7 +116,6 @@ static int sfdp_fill_flash(struct flashctx *flash, uint8_t *buf, uint16_t len)
 	uint32_t tmp32;
 	uint8_t tmp8;
 	uint32_t total_size; /* in bytes */
-	uint8_t opcode_4k = 0xFF;
 	uint32_t block_size;
 	int dw, j;
 
@@ -179,7 +178,7 @@ static int sfdp_fill_flash(struct flashctx *flash, uint8_t *buf, uint16_t len)
 	}
 
 	if ((tmp32 & 0x3) == 0x1) {
-		opcode_4k = (tmp32 >> 8) & 0xFF; /* will be dealt with later */
+		sfdp_add_uniform_eraser(flash, (tmp32 >> 8) & 0xFF, 4 * 1024);
 	}
 
 	/* 2. double word */
@@ -203,7 +202,7 @@ static int sfdp_fill_flash(struct flashctx *flash, uint8_t *buf, uint16_t len)
 		msg_cdbg("It seems like this chip supports the preliminary "
 			 "Intel version of SFDP, skipping processing of double "
 			 "words 3-9.\n");
-		goto proc_4k;
+		goto done;
 	}
 
 	dw = 8;
@@ -224,17 +223,9 @@ static int sfdp_fill_flash(struct flashctx *flash, uint8_t *buf, uint16_t len)
 		tmp8 = buf[(4 * dw) + (2 * j) + 1];
 		if (sfdp_add_uniform_eraser(flash, tmp8, block_size))
 			continue;
-		/* If there is a valid 4k value in the last double words,
-		 * we want to override the value from double word 1, hence force
-		 * skipping its processing: */
-		if (block_size == 4 * 1024 && tmp8 == opcode_4k)
-			opcode_4k = 0xFF;
 	}
 
-proc_4k:
-	if (opcode_4k != 0xFF) {
-		sfdp_add_uniform_eraser(flash, opcode_4k, 4 * 1024);
-	}
+done:
 	msg_cdbg("done.\n");
 	return 0;
 }
-- 
1.7.1

_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to