[coreboot] flashrom: simplify ich spi read/write operations

FENG Yu Ning fengyuning1984 at gmail.com
Tue Nov 25 06:15:44 CET 2008


This patch simplifies ich spi read/write operations, and changes
naming from "page" to "block".

The impact of modification have been made minimal, other parts of
flashrom should
not be affected.

Not tested due to lack of facility. Very appreciated if anyone can help.

Signed-off-by: FENG yu ning <fengyuning1984 at gmail.com>

Index: flashrom/ichspi.c
===================================================================
--- flashrom/ichspi.c	(revision 3767)
+++ flashrom/ichspi.c	(working copy)
@@ -150,10 +150,10 @@
 static int program_opcodes(OPCODES * op);
 static int run_opcode(OPCODE op, uint32_t offset,
 		      uint8_t datalength, uint8_t * data);
-static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf,
-			     int offset, int maxdata);
-static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes,
-			      int offset, int maxdata);
+static int ich_spi_read_block(struct flashchip *flash, uint8_t * buf,
+			      int offset, int block_size, int maxdata);
+static int ich_spi_write_block(struct flashchip *flash, uint8_t * bytes,
+			       int offset, int block_size, int maxdata);

 OPCODES O_ST_M25P = {
 	{
@@ -478,28 +478,25 @@
 	return -1;
 }

-static int ich_spi_read_page(struct flashchip *flash, uint8_t * buf,
int offset,
-			     int maxdata)
+static int ich_spi_read_block(struct flashchip *flash, uint8_t * buf,
+			      int offset, int block_size, int maxdata)
 {
-	int page_size = flash->page_size;
-	uint32_t remaining = flash->page_size;
+	uint32_t remaining = block_size;
 	int a;

-	printf_debug("ich_spi_read_page: offset=%d, number=%d, buf=%p\n",
-		     offset, page_size, buf);
+	printf_debug("ich_spi_read_block: offset=%d, block size=%d, buf=%p\n",
+		     offset, block_size, buf);

-	for (a = 0; a < page_size; a += maxdata) {
+	for (a = 0; a < block_size; a += maxdata) {
 		if (remaining < maxdata) {

-			if (spi_nbyte_read(offset + (page_size - remaining),
-				&buf[page_size - remaining], remaining)) {
+			if (spi_nbyte_read(offset + a, &buf[a], remaining)) {
 				printf_debug("Error reading");
 				return 1;
 			}
 			remaining = 0;
 		} else {
-			if (spi_nbyte_read(offset + (page_size - remaining),
-				&buf[page_size - remaining], maxdata)) {
+			if (spi_nbyte_read(offset + a, &buf[a], maxdata)) {
 				printf_debug("Error reading");
 				return 1;
 			}
@@ -510,22 +507,21 @@
 	return 0;
 }

-static int ich_spi_write_page(struct flashchip *flash, uint8_t * bytes,
-			      int offset, int maxdata)
+static int ich_spi_write_block(struct flashchip *flash, uint8_t * bytes,
+			       int offset, int block_size, int maxdata)
 {
-	int page_size = flash->page_size;
-	uint32_t remaining = page_size;
+	uint32_t remaining = block_size;
 	int a;

-	printf_debug("ich_spi_write_page: offset=%d, number=%d, buf=%p\n",
-		     offset, page_size, bytes);
+	printf_debug("ich_spi_write_block: offset=%d, block size=%d, buf=%p\n",
+		     offset, block_size, bytes);

-	for (a = 0; a < page_size; a += maxdata) {
+	for (a = 0; a < block_size; a += maxdata) {
 		if (remaining < maxdata) {
 			if (run_opcode
 			    (curopcodes->opcode[0],
-			     offset + (page_size - remaining), remaining,
-			     &bytes[page_size - remaining]) != 0) {
+			     offset + a, remaining,
+			     &bytes[a]) != 0) {
 				printf_debug("Error writing");
 				return 1;
 			}
@@ -533,8 +529,8 @@
 		} else {
 			if (run_opcode
 			    (curopcodes->opcode[0],
-			     offset + (page_size - remaining), maxdata,
-			     &bytes[page_size - remaining]) != 0) {
+			     offset + a, maxdata,
+			     &bytes[a]) != 0) {
 				printf_debug("Error writing");
 				return 1;
 			}
@@ -547,34 +543,29 @@

 int ich_spi_read(struct flashchip *flash, uint8_t * buf)
 {
-	int i, rc = 0;
+	int rc = 0;
 	int total_size = flash->total_size * 1024;
-	int page_size = flash->page_size;
 	int maxdata = 64;

 	if (flashbus == BUS_TYPE_VIA_SPI) {
 		maxdata = 16;
 	}

-	for (i = 0; (i < total_size / page_size) && (rc == 0); i++) {
-		rc = ich_spi_read_page(flash, (void *)(buf + i * page_size),
-				       i * page_size, maxdata);
-	}
+	rc = ich_spi_read_block(flash, buf, 0, total_size, maxdata);

 	return rc;
 }

 int ich_spi_write(struct flashchip *flash, uint8_t * buf)
 {
-	int i, j, rc = 0;
+	int i, rc = 0;
 	int total_size = flash->total_size * 1024;
-	int page_size = flash->page_size;
 	int erase_size = 64 * 1024;
 	int maxdata = 64;

 	spi_disable_blockprotect();

-	printf("Programming page: \n");
+	printf("Programming flashchip: \n");

 	for (i = 0; i < total_size / erase_size; i++) {
 		/* FIMXE: call the chip-specific spi_block_erase_XX instead.
@@ -590,11 +581,12 @@
 		if (flashbus == BUS_TYPE_VIA_SPI)
 			maxdata = 16;

-		for (j = 0; j < erase_size / page_size; j++) {
-			ich_spi_write_page(flash,
-			   (void *)(buf + (i * erase_size) + (j * page_size)),
-			   (i * erase_size) + (j * page_size), maxdata);
-		}
+		ich_spi_write_block(flash,
+				    (void *)(buf + (i * erase_size)),
+				    i * erase_size,
+				    erase_size,
+				    maxdata);
+
 	}

 	printf("\n");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ich_spi_rw.patch
Type: text/x-diff
Size: 4735 bytes
Desc: not available
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20081125/6c7365d9/attachment.bin>


More information about the coreboot mailing list