[flashrom] [PATCH 2/4] Add granularity handling for AT45DB series.

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Sun Mar 3 23:57:11 CET 2013


Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---
 flash.h    |    2 ++
 flashrom.c |   38 +++++++++++++++++++++++---------------
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/flash.h b/flash.h
index 7dd9d9f..1df43c4 100644
--- a/flash.h
+++ b/flash.h
@@ -66,11 +66,13 @@ enum chipbustype {
  * - 128 bytes: If less than 128 bytes are written, the rest will be erased. Each write to a 128-byte region
  *   will trigger an automatic erase before anything is written. Very uncommon behaviour.
  * - 256 bytes: If less than 256 bytes are written, the contents of the unwritten bytes are undefined.
+ * - 264 bytes: FIXME
  */
 enum write_granularity {
 	write_gran_256bytes = 0, /* We assume 256 byte granularity on default. */
 	write_gran_1bit,
 	write_gran_1byte,
+	write_gran_264bytes,
 };
 
 /*
diff --git a/flashrom.c b/flashrom.c
index 225b6f0..fc5e34a 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -676,6 +676,21 @@ out_free:
 	return ret;
 }
 
+static int need_erase_n_byte(uint8_t *have, uint8_t *want, unsigned int len, unsigned int n)
+{
+	unsigned int i, j, limit;
+	for (j = 0; j < len / n; j++) {
+		limit = min (n, len - j * n);
+		/* Are 'have' and 'want' identical? */
+		if (!memcmp(have + j * n, want + j * n, limit))
+			continue;
+		/* have needs to be in erased state. */
+		for (i = 0; i < limit; i++)
+			if (have[j * n + i] != 0xff)
+				return 1;
+	}
+	return 0;
+}
 /*
  * Check if the buffer @have can be programmed to the content of @want without
  * erasing. This is only possible if all chunks of size @gran are either kept
@@ -693,7 +708,7 @@ out_free:
 int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granularity gran)
 {
 	int result = 0;
-	unsigned int i, j, limit;
+	unsigned int i;
 
 	switch (gran) {
 	case write_gran_1bit:
@@ -711,20 +726,10 @@ int need_erase(uint8_t *have, uint8_t *want, unsigned int len, enum write_granul
 			}
 		break;
 	case write_gran_256bytes:
-		for (j = 0; j < len / 256; j++) {
-			limit = min (256, len - j * 256);
-			/* Are 'have' and 'want' identical? */
-			if (!memcmp(have + j * 256, want + j * 256, limit))
-				continue;
-			/* have needs to be in erased state. */
-			for (i = 0; i < limit; i++)
-				if (have[j * 256 + i] != 0xff) {
-					result = 1;
-					break;
-				}
-			if (result)
-				break;
-		}
+		result = need_erase_n_byte(have, want, len, 256);
+		break;
+	case write_gran_264bytes:
+		result = need_erase_n_byte(have, want, len, 264);
 		break;
 	default:
 		msg_cerr("%s: Unsupported granularity! Please report a bug at "
@@ -772,6 +777,9 @@ static unsigned int get_next_write(uint8_t *have, uint8_t *want, unsigned int le
 	case write_gran_256bytes:
 		stride = 256;
 		break;
+	case write_gran_264bytes:
+		stride = 264;
+		break;
 	default:
 		msg_cerr("%s: Unsupported granularity! Please report a bug at "
 			 "flashrom at flashrom.org\n", __func__);
-- 
Kind regards, Stefan Tauner





More information about the flashrom mailing list