[flashrom] [commit] r1208 - trunk

repository service svn at flashrom.org
Sun Oct 10 16:02:28 CEST 2010


Author: hailfinger
Date: Sun Oct 10 16:02:27 2010
New Revision: 1208
URL: http://flashrom.org/trac/flashrom/changeset/1208

Log:
The currently used write functions (wrappers) all use helpers which
perform the actual write (inner functions).

The signature of the write wrappers is:
int write_chip(struct flashchip *flash, uint8_t * buf);

The signature of the inner write functions varied a lot. This patch
changes them to:
int write_part(struct flashchip *flash, uint8_t *src, int start, int len);

Did you know that flashrom has only 8 inner write functions for all
flash chips?
write_page_write_jedec_common
write_sector_jedec_common
write_sector_28sf040
spi_chip_write_256_new
spi_chip_write_1_new
spi_aai_write_new
write_page_82802ab
write_page_m29f400bt

Export all inner write functions.

Change the function signature of wait_82802ab to eliminate single-use
variables.

Remove an error message in write_page_m29f400bt which was printed for
every byte written regardless of success.

Add sharplhf00l04.c to the list of flash chip drivers in the Makefile.
While the functions in there are unused, I suspect we will need them
later, and by hooking the file up we ensure that compilation won't
break.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Acked-by: Uwe Hermann <uwe at hermann-uwe.de>

Modified:
   trunk/82802ab.c
   trunk/Makefile
   trunk/chipdrivers.h
   trunk/jedec.c
   trunk/m29f400bt.c
   trunk/sharplhf00l04.c
   trunk/sst28sf040.c
   trunk/sst49lfxxxc.c
   trunk/stm50flw0x0x.c

Modified: trunk/82802ab.c
==============================================================================
--- trunk/82802ab.c	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/82802ab.c	Sun Oct 10 16:02:27 2010	(r1208)
@@ -88,9 +88,10 @@
 	return 1;
 }
 
-uint8_t wait_82802ab(chipaddr bios)
+uint8_t wait_82802ab(struct flashchip *flash)
 {
 	uint8_t status;
+	chipaddr bios = flash->virtual_memory;
 
 	chip_writeb(0x70, bios);
 	if ((chip_readb(bios) & 0x80) == 0) {	// it's busy
@@ -132,7 +133,7 @@
 	programmer_delay(10);
 
 	// now let's see what the register is
-	status = wait_82802ab(bios);
+	status = wait_82802ab(flash);
 	print_status_82802ab(status);
 
 	if (check_erased_range(flash, page, pagesize)) {
@@ -143,26 +144,28 @@
 	return 0;
 }
 
-void write_page_82802ab(chipaddr bios, uint8_t *src,
-			chipaddr dst, int page_size)
+int write_page_82802ab(struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i;
+	chipaddr dst = flash->virtual_memory + start;
 
-	for (i = 0; i < page_size; i++) {
+	for (i = 0; i < len; i++) {
 		/* transfer data from source to destination */
 		chip_writeb(0x40, dst);
 		chip_writeb(*src++, dst++);
-		wait_82802ab(bios);
+		wait_82802ab(flash);
 	}
+
+	/* FIXME: Ignore errors for now. */
+	return 0;
 }
 
 int write_82802ab(struct flashchip *flash, uint8_t *buf)
 {
 	int i;
-	chipaddr bios = flash->virtual_memory;
 
 	for (i = 0; i < flash->total_size; i++) {
-                write_page_82802ab(bios, buf + i * 1024, bios + i * 1024, 1024);
+                write_page_82802ab(flash, buf + i * 1024, i * 1024, 1024);
 	}
 
 	return 0;

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/Makefile	Sun Oct 10 16:02:27 2010	(r1208)
@@ -84,7 +84,7 @@
 
 CHIP_OBJS = jedec.o stm50flw0x0x.o w39v040c.o w39v080fa.o w29ee011.o \
 	sst28sf040.o m29f400bt.o 82802ab.o pm49fl00x.o \
-	sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o
+	sst49lfxxxc.o sst_fwhub.o flashchips.o spi.o spi25.o sharplhf00l04.o
 
 LIB_OBJS = layout.o
 

Modified: trunk/chipdrivers.h
==============================================================================
--- trunk/chipdrivers.h	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/chipdrivers.h	Sun Oct 10 16:02:27 2010	(r1208)
@@ -65,12 +65,12 @@
 int spi_aai_write(struct flashchip *flash, uint8_t *buf);
 
 /* 82802ab.c */
-uint8_t wait_82802ab(chipaddr bios);
+uint8_t wait_82802ab(struct flashchip *flash);
 int probe_82802ab(struct flashchip *flash);
 int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize);
 int write_82802ab(struct flashchip *flash, uint8_t *buf);
 void print_status_82802ab(uint8_t status);
-void write_page_82802ab(chipaddr bios, uint8_t *src, chipaddr dst, int page_size);
+int write_page_82802ab(struct flashchip *flash, uint8_t *src, int start, int len);
 int unlock_82802ab(struct flashchip *flash);
 int unlock_28f004s5(struct flashchip *flash);
 
@@ -86,7 +86,8 @@
 int erase_sector_jedec(struct flashchip *flash, unsigned int page, unsigned int pagesize);
 int erase_block_jedec(struct flashchip *flash, unsigned int page, unsigned int blocksize);
 int erase_chip_block_jedec(struct flashchip *flash, unsigned int page, unsigned int blocksize);
-int write_sector_jedec_common(struct flashchip *flash, uint8_t *src, chipaddr dst, unsigned int page_size, unsigned int mask);
+int write_sector_jedec_common(struct flashchip *flash, uint8_t *src, int start, int len, unsigned int mask);
+int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, int start, int page_size, unsigned int mask);
 
 /* m29f400bt.c */
 int probe_m29f400bt(struct flashchip *flash);
@@ -94,8 +95,7 @@
 int block_erase_chip_m29f400bt(struct flashchip *flash, unsigned int start, unsigned int len);
 int write_m29f400bt(struct flashchip *flash, uint8_t *buf);
 void protect_m29f400bt(chipaddr bios);
-void write_page_m29f400bt(chipaddr bios, uint8_t *src,
-			  chipaddr dst, int page_size);
+int write_page_m29f400bt(struct flashchip *flash, uint8_t *src, int start, int len);
 
 /* pm49fl00x.c */
 int unlock_49fl00x(struct flashchip *flash);
@@ -105,6 +105,7 @@
 int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
 int erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned int sector_size);
 int write_28sf040(struct flashchip *flash, uint8_t *buf);
+int write_sector_28sf040(struct flashchip *flash, uint8_t *src, int start, int len);
 
 /* sst49lfxxxc.c */
 int erase_sector_49lfxxxc(struct flashchip *flash, unsigned int address, unsigned int sector_size);

Modified: trunk/jedec.c
==============================================================================
--- trunk/jedec.c	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/jedec.c	Sun Oct 10 16:02:27 2010	(r1208)
@@ -317,14 +317,14 @@
 	return failed;
 }
 
-int write_sector_jedec_common(struct flashchip *flash, uint8_t *src,
-		       chipaddr dst, unsigned int page_size, unsigned int mask)
+int write_sector_jedec_common(struct flashchip *flash, uint8_t *src, int start, int len, unsigned int mask)
 {
 	int i, failed = 0;
+	chipaddr dst = flash->virtual_memory + start;
 	chipaddr olddst;
 
 	olddst = dst;
-	for (i = 0; i < page_size; i++) {
+	for (i = 0; i < len; i++) {
 		if (write_byte_program_jedec_common(flash, src, dst, mask))
 			failed = 1;
 		dst++, src++;
@@ -335,8 +335,7 @@
 	return failed;
 }
 
-static int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src,
-			   int start, int page_size, unsigned int mask)
+int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, int start, int page_size, unsigned int mask)
 {
 	int i, tried = 0, failed;
 	uint8_t *s = src;
@@ -403,8 +402,7 @@
 	mask = getaddrmask(flash);
 
 	for (i = 0; i < total_size / page_size; i++) {
-		if (write_page_write_jedec_common(flash, buf + i * page_size,
-					   i * page_size, page_size, mask))
+		if (write_page_write_jedec_common(flash, buf + i * page_size, i * page_size, page_size, mask))
 			failed = 1;
 	}
 
@@ -414,14 +412,12 @@
 int write_jedec_1(struct flashchip *flash, uint8_t * buf)
 {
 	int i;
-	chipaddr bios = flash->virtual_memory;
-	chipaddr dst = bios;
 	int mask;
 
 	mask = getaddrmask(flash);
 
 	for (i = 0; i < flash->total_size; i++) {
-                write_sector_jedec_common(flash, buf + i * 1024, dst + i * 1024, 1024, mask);
+		write_sector_jedec_common(flash, buf + i * 1024, i * 1024, 1024, mask);
 	}
 
 	return 0;

Modified: trunk/m29f400bt.c
==============================================================================
--- trunk/m29f400bt.c	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/m29f400bt.c	Sun Oct 10 16:02:27 2010	(r1208)
@@ -27,12 +27,13 @@
    0x555 instead of 0x2AA. Do *not* blindly replace with standard JEDEC
    functions. */
 
-void write_page_m29f400bt(chipaddr bios, uint8_t *src,
-			  chipaddr dst, int page_size)
+int write_page_m29f400bt(struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i;
+	chipaddr bios = flash->virtual_memory;
+	chipaddr dst = flash->virtual_memory + start;
 
-	for (i = 0; i < page_size; i++) {
+	for (i = 0; i < len; i++) {
 		chip_writeb(0xAA, bios + 0xAAA);
 		chip_writeb(0x55, bios + 0x555);
 		chip_writeb(0xA0, bios + 0xAAA);
@@ -40,11 +41,17 @@
 		/* transfer data from source to destination */
 		chip_writeb(*src, dst);
 		toggle_ready_jedec(dst);
+#if 0
+		/* We only want to print something in the error case. */
 		msg_cerr("Value in the flash at address 0x%lx = %#x, want %#x\n",
 		     (dst - bios), chip_readb(dst), *src);
+#endif
 		dst++;
 		src++;
 	}
+
+	/* FIXME: Ignore errors for now. */
+	return 0;
 }
 
 int probe_m29f400bt(struct flashchip *flash)
@@ -138,20 +145,15 @@
 	int i;
 	int total_size = flash->total_size * 1024;
 	int page_size = flash->page_size;
-	chipaddr bios = flash->virtual_memory;
 
 	for (i = 0; i < (total_size / page_size) - 1; i++) {
-		write_page_m29f400bt(bios, buf + i * page_size,
-				     bios + i * page_size, page_size);
+		write_page_m29f400bt(flash, buf + i * page_size, i * page_size, page_size);
 	}
 
-	write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, 32 * 1024);
-
-	write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, 8 * 1024);
-
-	write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, 8 * 1024);
-
-	write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, 16 * 1024);
+	write_page_m29f400bt(flash, buf + 0x70000, 0x70000, 32 * 1024);
+	write_page_m29f400bt(flash, buf + 0x78000, 0x78000, 8 * 1024);
+	write_page_m29f400bt(flash, buf + 0x7a000, 0x7a000, 8 * 1024);
+	write_page_m29f400bt(flash, buf + 0x7c000, 0x7c000, 16 * 1024);
 
 	return 0;
 }

Modified: trunk/sharplhf00l04.c
==============================================================================
--- trunk/sharplhf00l04.c	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/sharplhf00l04.c	Sun Oct 10 16:02:27 2010	(r1208)
@@ -23,6 +23,7 @@
 
 /* FIXME: The datasheet is unclear whether we should use toggle_ready_jedec
  * or wait_82802ab.
+ * FIXME: This file is unused.
  */
 
 int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen)
@@ -33,7 +34,7 @@
 
 	// clear status register
 	chip_writeb(0x50, bios);
-	status = wait_82802ab(flash->virtual_memory);
+	status = wait_82802ab(flash);
 	print_status_82802ab(status);
 	// clear write protect
 	msg_cspew("write protect is at 0x%lx\n", (wrprotect));
@@ -46,7 +47,7 @@
 	chip_writeb(0xd0, bios);
 	programmer_delay(10);
 	// now let's see what the register is
-	status = wait_82802ab(flash->virtual_memory);
+	status = wait_82802ab(flash);
 	print_status_82802ab(status);
 
 	if (check_erased_range(flash, blockaddr, blocklen)) {
@@ -61,11 +62,9 @@
 	int i;
 	int total_size = flash->total_size * 1024;
 	int page_size = flash->page_size;
-	chipaddr bios = flash->virtual_memory;
 
 	for (i = 0; i < total_size / page_size; i++) {
-		write_page_82802ab(bios, buf + i * page_size,
-				    bios + i * page_size, page_size);
+		write_page_82802ab(flash, buf + i * page_size, i * page_size, page_size);
 	}
 
 	return 0;

Modified: trunk/sst28sf040.c
==============================================================================
--- trunk/sst28sf040.c	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/sst28sf040.c	Sun Oct 10 16:02:27 2010	(r1208)
@@ -30,8 +30,10 @@
 #define RESET			0xFF
 #define READ_ID			0x90
 
-static void protect_28sf040(chipaddr bios)
+static void protect_28sf040(struct flashchip *flash)
 {
+	chipaddr bios = flash->virtual_memory;
+
 	chip_readb(bios + 0x1823);
 	chip_readb(bios + 0x1820);
 	chip_readb(bios + 0x1822);
@@ -41,8 +43,10 @@
 	chip_readb(bios + 0x040A);
 }
 
-static void unprotect_28sf040(chipaddr bios)
+static void unprotect_28sf040(struct flashchip *flash)
 {
+	chipaddr bios = flash->virtual_memory;
+
 	chip_readb(bios + 0x1823);
 	chip_readb(bios + 0x1820);
 	chip_readb(bios + 0x1822);
@@ -59,7 +63,7 @@
 	chip_writeb(AUTO_PG_ERASE1, bios);
 	chip_writeb(AUTO_PG_ERASE2, bios + address);
 
-	/* wait for Toggle bit ready         */
+	/* wait for Toggle bit ready */
 	toggle_ready_jedec(bios);
 
 	if (check_erased_range(flash, address, sector_size)) {
@@ -69,12 +73,13 @@
 	return 0;
 }
 
-static int write_sector_28sf040(chipaddr bios, uint8_t *src, chipaddr dst,
-				unsigned int page_size)
+int write_sector_28sf040(struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i;
+	chipaddr bios = flash->virtual_memory;
+	chipaddr dst = flash->virtual_memory + start;
 
-	for (i = 0; i < page_size; i++) {
+	for (i = 0; i < len; i++) {
 		/* transfer data from source to destination */
 		if (*src == 0xFF) {
 			dst++, src++;
@@ -96,10 +101,10 @@
 {
 	chipaddr bios = flash->virtual_memory;
 
-	unprotect_28sf040(bios);
+	unprotect_28sf040(flash);
 	chip_writeb(CHIP_ERASE, bios);
 	chip_writeb(CHIP_ERASE, bios);
-	protect_28sf040(bios);
+	protect_28sf040(flash);
 
 	programmer_delay(10);
 	toggle_ready_jedec(bios);
@@ -116,17 +121,14 @@
 	int i;
 	int total_size = flash->total_size * 1024;
 	int page_size = flash->page_size;
-	chipaddr bios = flash->virtual_memory;
 
-	unprotect_28sf040(bios);
+	unprotect_28sf040(flash);
 
 	for (i = 0; i < total_size / page_size; i++) {
-		/* write to the sector */
-		write_sector_28sf040(bios, buf + i * page_size,
-				     bios + i * page_size, page_size);
+		write_sector_28sf040(flash, buf + i * page_size, i * page_size, page_size);
 	}
 
-	protect_28sf040(bios);
+	protect_28sf040(flash);
 
 	return 0;
 }

Modified: trunk/sst49lfxxxc.c
==============================================================================
--- trunk/sst49lfxxxc.c	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/sst49lfxxxc.c	Sun Oct 10 16:02:27 2010	(r1208)
@@ -67,7 +67,7 @@
 	chip_writeb(0x30, bios);
 	chip_writeb(0xD0, bios + address);
 
-	status = wait_82802ab(bios);
+	status = wait_82802ab(flash);
 
 	if (check_erased_range(flash, address, sector_size)) {
 		msg_cerr("ERASE FAILED!\n");
@@ -85,9 +85,7 @@
 
 	write_lockbits_49lfxxxc(flash, 0);
 	for (i = 0; i < total_size / page_size; i++) {
-		/* write to the sector */
-		write_page_82802ab(bios, buf + i * page_size,
-				      bios + i * page_size, page_size);
+		write_page_82802ab(flash, buf + i * page_size, i * page_size, page_size);
 	}
 
 	chip_writeb(0xFF, bios);

Modified: trunk/stm50flw0x0x.c
==============================================================================
--- trunk/stm50flw0x0x.c	Fri Oct  8 22:29:57 2010	(r1207)
+++ trunk/stm50flw0x0x.c	Sun Oct 10 16:02:27 2010	(r1208)
@@ -105,7 +105,7 @@
 	chip_writeb(0xd0, bios);
 	programmer_delay(10);
 
-	wait_82802ab(flash->virtual_memory);
+	wait_82802ab(flash);
 
 	if (check_erased_range(flash, sector, sectorsize)) {
 		msg_cerr("ERASE FAILED!\n");




More information about the flashrom mailing list