>From 7ce947bc906dcc8e66e4d6e6cae5a2d303b92a43 Mon Sep 17 00:00:00 2001
From: Sean Nelson <audiohacked@gmail.com>
Date: Thu, 18 Mar 2010 23:47:42 -0700
Subject: [PATCH] rename print_82802ab_status to print_status_82802ab
 add unlock_82802ab
 strip unlock code from erase_block_82802ab
 rename erase_82802ab_block  to erase_block_80280ab
 delete sharplhf00l04.o from Makefile
 delete *_lhf00l04* from chipdrivers.h
 add unlock_stm50flw0x0x
 delete wait_stm50flw0x0x
 delete write_page_stm50flw0x0x
 convert erase_stm50flw0x0x to erase_chip_stm50flw0x0x
 delete write_stm50flw0x0x


Signed-off-by: Sean Nelson <audiohacked@gmail.com>
---
 82802ab.c       |   27 ++++++---
 Makefile        |    2 +-
 chipdrivers.h   |   14 ++----
 flashchips.c    |   63 +++++++++++++---------
 sharplhf00l04.c |    4 +-
 stm50flw0x0x.c  |  156 +++++++------------------------------------------------
 6 files changed, 82 insertions(+), 184 deletions(-)

diff --git a/82802ab.c b/82802ab.c
index ca08b65..cdc3d73 100644
--- a/82802ab.c
+++ b/82802ab.c
@@ -22,27 +22,27 @@
  * Datasheet:
  *  - Name: Intel 82802AB/82802AC Firmware Hub (FWH)
  *  - URL: http://www.intel.com/design/chipsets/datashts/290658.htm
  *  - PDF: http://download.intel.com/design/chipsets/datashts/29065804.pdf
  *  - Order number: 290658-004
  */
 
 #include <string.h>
 #include <stdlib.h>
 #include "flash.h"
 #include "chipdrivers.h"
 
 // I need that Berkeley bit-map printer
-void print_82802ab_status(uint8_t status)
+void print_status_82802ab(uint8_t status)
 {
 	printf_debug("%s", status & 0x80 ? "Ready:" : "Busy:");
 	printf_debug("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
 	printf_debug("%s", status & 0x20 ? "BE ERROR:" : "BE OK:");
 	printf_debug("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:");
 	printf_debug("%s", status & 0x8 ? "VP ERR:" : "VPP OK:");
 	printf_debug("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:");
 	printf_debug("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
 }
 
 int probe_82802ab(struct flashchip *flash)
 {
 	chipaddr bios = flash->virtual_memory;
@@ -82,65 +82,74 @@ uint8_t wait_82802ab(chipaddr bios)
 	chip_writeb(0x70, bios);
 	if ((chip_readb(bios) & 0x80) == 0) {	// it's busy
 		while ((chip_readb(bios) & 0x80) == 0) ;
 	}
 
 	status = chip_readb(bios);
 
 	/* Reset to get a clean state */
 	chip_writeb(0xFF, bios);
 
 	return status;
 }
 
-int erase_82802ab_block(struct flashchip *flash, unsigned int page, unsigned int pagesize)
+int unlock_82802ab(struct flashchip *flash)
+{
+	int i;
+	//chipaddr wrprotect = flash->virtual_registers + page + 2;
+
+	for (i = 0; i < flash->total_size; i+= flash->page_size)
+	{
+		chip_writeb(0, flash->virtual_registers + i + 2);
+	}
+
+	return 0;
+}
+
+int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize)
 {
 	chipaddr bios = flash->virtual_memory;
-	chipaddr wrprotect = flash->virtual_registers + page + 2;
 	uint8_t status;
 
 	// clear status register
 	chip_writeb(0x50, bios + page);
 
-	// clear write protect
-	chip_writeb(0, wrprotect);
-
 	// now start it
 	chip_writeb(0x20, bios + page);
 	chip_writeb(0xd0, bios + page);
 	programmer_delay(10);
 
 	// now let's see what the register is
 	status = wait_82802ab(bios);
-	print_82802ab_status(status);
+	print_status_82802ab(status);
 
 	if (check_erased_range(flash, page, pagesize)) {
 		fprintf(stderr, "ERASE FAILED!\n");
 		return -1;
 	}
 	printf("DONE BLOCK 0x%x\n", page);
 
 	return 0;
 }
 
 int erase_82802ab(struct flashchip *flash)
 {
 	int i;
 	unsigned int total_size = flash->total_size * 1024;
 
 	printf("total_size is %d; flash->page_size is %d\n",
 	       total_size, flash->page_size);
 	for (i = 0; i < total_size; i += flash->page_size)
-		if (erase_82802ab_block(flash, i, flash->page_size)) {
+		if (erase_block_82802ab(flash, i, flash->page_size)) {
 			fprintf(stderr, "ERASE FAILED!\n");
 			return -1;
 		}
 	printf("DONE ERASE\n");
 
 	return 0;
 }
 
 void write_page_82802ab(chipaddr bios, uint8_t *src,
 			chipaddr dst, int page_size)
 {
 	int i;
 
@@ -174,25 +183,25 @@ int write_82802ab(struct flashchip *flash, uint8_t *buf)
 		 * Faster, because we only write, what has changed
 		 * More secure, because blocks, which are excluded
 		 * (with the exclude or layout feature)
 		 * or not erased and rewritten; their data is retained also in
 		 * sudden power off situations
 		 */
 		chip_readn(tmpbuf, bios + i * page_size, page_size);
 		if (!memcmp((void *)(buf + i * page_size), tmpbuf, page_size)) {
 			printf("SKIPPED\n");
 			continue;
 		}
 
 		/* erase block by block and write block by block; this is the most secure way */
-		if (erase_82802ab_block(flash, i * page_size, page_size)) {
+		if (erase_block_82802ab(flash, i * page_size, page_size)) {
 			fprintf(stderr, "ERASE FAILED!\n");
 			return -1;
 		}
 		write_page_82802ab(bios, buf + i * page_size,
 				   bios + i * page_size, page_size);
 	}
 	printf("\n");
 	free(tmpbuf);
 
 	return 0;
 }
diff --git a/Makefile b/Makefile
index 9245624..85cd7eb 100644
--- a/Makefile
+++ b/Makefile
@@ -31,27 +31,27 @@ EXPORTDIR ?= .
 OS_ARCH	= $(shell uname)
 ifneq ($(OS_ARCH), SunOS)
 STRIP_ARGS = -s
 endif
 ifeq ($(OS_ARCH), Darwin)
 CPPFLAGS += -I/opt/local/include -I/usr/local/include
 LDFLAGS += -framework IOKit -framework DirectIO -L/opt/local/lib -L/usr/local/lib
 endif
 ifeq ($(OS_ARCH), FreeBSD)
 CPPFLAGS += -I/usr/local/include
 LDFLAGS += -L/usr/local/lib
 endif
 
-CHIP_OBJS = jedec.o stm50flw0x0x.o w39v040c.o w39v080fa.o sharplhf00l04.o w29ee011.o \
+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
 
 LIB_OBJS = layout.o
 
 CLI_OBJS = flashrom.o cli_classic.o cli_output.o print.o
 
 PROGRAMMER_OBJS = udelay.o programmer.o
 
 all: pciutils features dep $(PROGRAM)
 
 # Set the flashrom version string from the highest revision number
 # of the checked out flashrom files.
diff --git a/chipdrivers.h b/chipdrivers.h
index ca82c2d..d8a5bcc 100644
--- a/chipdrivers.h
+++ b/chipdrivers.h
@@ -47,30 +47,31 @@ int spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
 int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
 uint8_t spi_read_status_register(void);
 int spi_disable_blockprotect(void);
 int spi_byte_program(int addr, uint8_t databyte);
 int spi_nbyte_program(int addr, uint8_t *bytes, int len);
 int spi_nbyte_read(int addr, uint8_t *bytes, int len);
 int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize);
 int spi_aai_write(struct flashchip *flash, uint8_t *buf);
 
 /* 82802ab.c */
 uint8_t wait_82802ab(chipaddr bios);
 int probe_82802ab(struct flashchip *flash);
 int erase_82802ab(struct flashchip *flash);
-int erase_82802ab_block(struct flashchip *flash, unsigned int page, unsigned int pagesize);
+int erase_block_82802ab(struct flashchip *flash, unsigned int page, unsigned int pagesize);
 int write_82802ab(struct flashchip *flash, uint8_t *buf);
-void print_82802ab_status(uint8_t status);
+void print_status_82802ab(uint8_t status);
 void write_page_82802ab(chipaddr bios, uint8_t *src, chipaddr dst, int page_size);
+int unlock_82802ab(struct flashchip *flash);
 
 /* jedec.c */
 uint8_t oddparity(uint8_t val);
 void toggle_ready_jedec(chipaddr dst);
 void data_polling_jedec(chipaddr dst, uint8_t data);
 int write_byte_program_jedec(chipaddr bios, uint8_t *src,
 			     chipaddr dst);
 int probe_jedec(struct flashchip *flash);
 int erase_chip_jedec(struct flashchip *flash);
 int write_jedec(struct flashchip *flash, uint8_t *buf);
 int write_jedec_1(struct flashchip *flash, uint8_t *buf);
 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);
@@ -82,30 +83,26 @@ int probe_m29f400bt(struct flashchip *flash);
 int erase_m29f400bt(struct flashchip *flash);
 int block_erase_m29f400bt(struct flashchip *flash, unsigned int start, unsigned int len);
 int block_erase_chip_m29f400bt(struct flashchip *flash, unsigned int start, unsigned int len);
 int write_m29f400bt(struct flashchip *flash, uint8_t *buf);
 int write_coreboot_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);
 
 /* pm49fl00x.c */
 int unlock_49fl00x(struct flashchip *flash);
 int lock_49fl00x(struct flashchip *flash);
 
-/* sharplhf00l04.c */
-int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen);
-int write_lhf00l04(struct flashchip *flash, uint8_t *buf);
-
 /* sst28sf040.c */
 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);
 
 /* sst49lfxxxc.c */
 int probe_49lfxxxc(struct flashchip *flash);
 int erase_49lfxxxc(struct flashchip *flash);
 int erase_sector_49lfxxxc(struct flashchip *flash, unsigned int address, unsigned int sector_size);
 int erase_block_49lfxxxc(struct flashchip *flash, unsigned int address, unsigned int sector_size);
 int erase_chip_49lfxxxc(struct flashchip *flash, unsigned int addr, unsigned int blocksize);
 int write_49lfxxxc(struct flashchip *flash, uint8_t *buf);
 int unlock_49lfxxxc(struct flashchip *flash);
@@ -114,21 +111,18 @@ int unlock_49lfxxxc(struct flashchip *flash);
 int printlock_sst_fwhub(struct flashchip *flash);
 int unlock_sst_fwhub(struct flashchip *flash);
 
 /* w39v040c.c */
 int printlock_w39v040c(struct flashchip *flash);
 
 /* w39V080fa.c */
 int unlock_winbond_fwhub(struct flashchip *flash);
 
 /* w29ee011.c */
 int probe_w29ee011(struct flashchip *flash);
 
 /* stm50flw0x0x.c */
-int probe_stm50flw0x0x(struct flashchip *flash);
-int erase_stm50flw0x0x(struct flashchip *flash);
-int erase_block_stm50flw0x0x(struct flashchip *flash, unsigned int block, unsigned int blocksize);
 int erase_sector_stm50flw0x0x(struct flashchip *flash, unsigned int block, unsigned int blocksize);
 int erase_chip_stm50flw0x0x(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
-int write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf);
+int unlock_stm50flw0x0x(struct flashchip *flash);
 
 #endif /* !__CHIPDRIVERS_H__ */
diff --git a/flashchips.c b/flashchips.c
index 3670731..b329588 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -2318,124 +2318,127 @@ struct flashchip flashchips[] = {
 		.page_size	= 128 * 1024, /* 8k + 2x4k + 112k */
 		.feature_bits	= 0,
 		.tested		= TEST_BAD_WRITE,
 		.probe		= probe_jedec,
 		.probe_timing	= TIMING_ZERO,	/* Datasheet has no timing info specified */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = { 
 					{8 * 1024, 1},
 					{4 * 1024, 2},
 					{112 * 1024, 1},
 				},
-				.block_erase = erase_82802ab_block,
+				.block_erase = erase_block_82802ab,
 			},
 		},
 		.write		= NULL,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "Intel",
 		.name		= "28F001BX-T",
 		.bustype	= CHIP_BUSTYPE_PARALLEL,
 		.manufacture_id	= INTEL_ID,
 		.model_id	= P28F001BXT,
 		.total_size	= 128,
 		.page_size	= 128 * 1024, /* 112k + 2x4k + 8k */
 		.feature_bits	= 0,
 		.tested		= TEST_BAD_WRITE,
 		.probe		= probe_jedec,
 		.probe_timing	= TIMING_ZERO,	/* Datasheet has no timing info specified */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = { 
 					{112 * 1024, 1},
 					{4 * 1024, 2},
 					{8 * 1024, 1},
 				},
-				.block_erase = erase_82802ab_block,
+				.block_erase = erase_block_82802ab,
 			},
 		},
 		.write		= NULL,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "Intel",
 		.name		= "28F004S5",
 		.bustype	= CHIP_BUSTYPE_PARALLEL,
 		.manufacture_id	= INTEL_ID,
 		.model_id	= E_28F004S5,
 		.total_size	= 512,
 		.page_size	= 256,
 		.tested		= TEST_UNTESTED,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_ZERO,	/* Datasheet has no timing info specified */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = { {64 * 1024, 8} },
-				.block_erase = erase_82802ab_block,
+				.block_erase = erase_block_82802ab,
 			},
 		},
+		.unlock		= unlock_82802ab,
 		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "Intel",
 		.name		= "82802AB",
 		.bustype	= CHIP_BUSTYPE_FWH,
 		.manufacture_id	= INTEL_ID,
 		.model_id	= I_82802AB,
 		.total_size	= 512,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_OK_PRW,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_IGNORED, /* routine does not use probe_timing (82802ab.c) */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = { {64 * 1024, 8} },
-				.block_erase = erase_82802ab_block,
+				.block_erase = erase_block_82802ab,
 			},
 		},
+		.unlock		= unlock_82802ab,
 		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "Intel",
 		.name		= "82802AC",
 		.bustype	= CHIP_BUSTYPE_FWH,
 		.manufacture_id	= INTEL_ID,
 		.model_id	= I_82802AC,
 		.total_size	= 1024,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_OK_PRW,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_IGNORED, /* routine does not use probe_timing (82802ab.c) */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = { {64 * 1024, 16} },
-				.block_erase = erase_82802ab_block,
+				.block_erase = erase_block_82802ab,
 			},
 		},
+		.unlock		= unlock_82802ab,
 		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "Macronix",
 		.name		= "MX25L512",
 		.bustype	= CHIP_BUSTYPE_SPI,
 		.manufacture_id	= MX_ID,
 		.model_id	= MX_25L512,
 		.total_size	= 64,
 		.page_size	= 256,
 		.tested		= TEST_UNTESTED,
@@ -3443,35 +3446,36 @@ struct flashchip flashchips[] = {
 		.total_size	= 1024,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_EITHER_RESET | FEATURE_REGISTERMAP,
 		.tested		= TEST_UNTESTED,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_ZERO,
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = {
 					{64 * 1024, 15},
 					{8 * 1024, 8}
 				 },
-				.block_erase = erase_lhf00l04_block,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = {
 					{1024 * 1024, 1}
 				},
 				.block_erase = NULL, /* 30 D0, only in A/A mux mode */
 			},
 		},
-		.write		= write_lhf00l04,
+		.unlock		= unlock_82802ab,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "Spansion",
 		.name		= "S25FL008A",
 		.bustype	= CHIP_BUSTYPE_SPI,
 		.manufacture_id	= SPANSION_ID,
 		.model_id	= SPANSION_S25FL008A,
 		.total_size	= 1024,
 		.page_size	= 256,
 		.tested		= TEST_OK_PREW,
 		.probe		= probe_spi_rdid,
@@ -4984,33 +4988,34 @@ struct flashchip flashchips[] = {
 		.probe_timing	= TIMING_FIXME,
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = {
 					{4 * 1024, 16},  /* sector */
 					{64 * 1024, 5}, /* block */
 					{4 * 1024, 16}, /* sector */
 					{4 * 1024, 16}, /* sector */
 				},
 				.block_erase = NULL,
 			}, {
 				.eraseblocks = { {64 * 1024, 8}, },
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {512 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "ST",
 		.name		= "M50FLW040B",
 		.bustype	= CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_LPC, /* A/A Mux */
 		.manufacture_id	= ST_ID,
 		.model_id	= ST_M50FLW040B,
 		.total_size	= 512,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_UNTESTED,
@@ -5018,33 +5023,34 @@ struct flashchip flashchips[] = {
 		.probe_timing	= TIMING_FIXME,
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = {
 					{4 * 1024, 16},  /* sector */
 					{4 * 1024, 16}, /* sector */
 					{64 * 1024, 5}, /* block */
 					{4 * 1024, 16}, /* sector */
 				},
 				.block_erase = NULL,
 			}, {
 				.eraseblocks = { {64 * 1024, 8}, },
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {512 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "ST",
 		.name		= "M50FLW080A",
 		.bustype	= CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_LPC, /* A/A Mux */
 		.manufacture_id	= ST_ID,
 		.model_id	= ST_M50FLW080A,
 		.total_size	= 1024,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_UNTESTED,
@@ -5052,33 +5058,34 @@ struct flashchip flashchips[] = {
 		.probe_timing	= TIMING_FIXME,
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = {
 					{4 * 1024, 16},  /* sector */
 					{64 * 1024, 13}, /* block */
 					{4 * 1024, 16}, /* sector */
 					{4 * 1024, 16}, /* sector */
 				},
 				.block_erase = NULL,
 			}, {
 				.eraseblocks = { {64 * 1024, 16}, },
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {1024 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "ST",
 		.name		= "M50FLW080B",
 		.bustype	= CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_LPC, /* A/A Mux */
 		.manufacture_id	= ST_ID,
 		.model_id	= ST_M50FLW080B,
 		.total_size	= 1024,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_UNTESTED,
@@ -5086,174 +5093,180 @@ struct flashchip flashchips[] = {
 		.probe_timing	= TIMING_FIXME,
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = {
 					{4 * 1024, 16},  /* sector */
 					{4 * 1024, 16}, /* sector */
 					{64 * 1024, 13}, /* block */
 					{4 * 1024, 16}, /* sector */
 				},
 				.block_erase = NULL,
 			}, {
 				.eraseblocks = { {64 * 1024, 16}, },
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {1024 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "ST",
 		.name		= "M50FW002",
 		.bustype	= CHIP_BUSTYPE_FWH, /* A/A Mux */
 		.manufacture_id	= ST_ID,
 		.model_id	= ST_M50FW002,
 		.total_size	= 256,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_UNTESTED,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_IGNORED, /* routine don't use probe_timing (sst49lfxxxc.c) */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = {
 					{64 * 1024, 3},
 					{32 * 1024, 1},
 					{8 * 1024, 2},
 					{16 * 1024, 1},
 				},
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {256 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "ST",
 		.name		= "M50FW016",
 		.bustype	= CHIP_BUSTYPE_FWH, /* A/A Mux */
 		.manufacture_id	= ST_ID,
 		.model_id	= ST_M50FW016,
 		.total_size	= 2048,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_UNTESTED,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = { {64 * 1024, 32}, },
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {2 * 1024 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "ST",
 		.name		= "M50FW040",
 		.bustype	= CHIP_BUSTYPE_FWH, /* A/A Mux */
 		.manufacture_id	= ST_ID,
 		.model_id	= ST_M50FW040,
 		.total_size	= 512,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_OK_PRW,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = { {64 * 1024, 8}, },
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {512 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "ST",
 		.name		= "M50FW080",
 		.bustype	= CHIP_BUSTYPE_FWH, /* A/A Mux */
 		.manufacture_id	= ST_ID,
 		.model_id	= ST_M50FW080,
 		.total_size	= 1024,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_OK_PRW,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_IGNORED, /* routine don't use probe_timing (82802ab.c) */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = { {64 * 1024, 16}, },
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {1024 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "ST",
 		.name		= "M50LPW116",
 		.bustype	= CHIP_BUSTYPE_LPC, /* A/A Mux */
 		.manufacture_id	= ST_ID,
 		.model_id	= ST_M50LPW116,
 		.total_size	= 2048,
 		.page_size	= 64 * 1024,
 		.feature_bits	= FEATURE_REGISTERMAP,
 		.tested		= TEST_UNTESTED,
 		.probe		= probe_82802ab,
 		.probe_timing	= TIMING_ZERO,	/* Datasheet has no timing info specified */
 		.block_erasers	=
 		{
 			{
 				.eraseblocks = {
 					{4 * 1024, 16},
 					{64 * 1024, 30},
 					{32 * 1024, 1},
 					{8 * 1024, 2},
 					{16 * 1024, 1},
 				},
-				.block_erase = erase_block_stm50flw0x0x,
+				.block_erase = erase_block_82802ab,
 			}, {
 				.eraseblocks = { {2 * 1024 * 1024, 1} },
 				.block_erase = erase_chip_stm50flw0x0x,
 			}
 		},
-		.write		= write_stm50flw0x0x,
+		.unlock		= unlock_stm50flw0x0x,
+		.write		= write_82802ab,
 		.read		= read_memmapped,
 	},
 
 	{
 		.vendor		= "SyncMOS",
 		.name		= "S29C31004T",
 		.bustype	= CHIP_BUSTYPE_PARALLEL,
 		.manufacture_id	= SYNCMOS_ID,
 		.model_id	= S29C31004T,
 		.total_size	= 512,
 		.page_size	= 128,
 		.feature_bits	= FEATURE_EITHER_RESET,
 		.tested		= TEST_UNTESTED,
diff --git a/sharplhf00l04.c b/sharplhf00l04.c
index 659f129..3f5cf3d 100644
--- a/sharplhf00l04.c
+++ b/sharplhf00l04.c
@@ -26,40 +26,40 @@
  * or wait_82802ab.
  */
 
 int erase_lhf00l04_block(struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen)
 {
 	chipaddr bios = flash->virtual_memory + blockaddr;
 	chipaddr wrprotect = flash->virtual_registers + blockaddr + 2;
 	uint8_t status;
 
 	// clear status register
 	chip_writeb(0x50, bios);
 	printf("Erase at 0x%lx\n", bios);
 	status = wait_82802ab(flash->virtual_memory);
-	print_82802ab_status(status);
+	print_status_82802ab(status);
 	// clear write protect
 	printf("write protect is at 0x%lx\n", (wrprotect));
 	printf("write protect is 0x%x\n", chip_readb(wrprotect));
 	chip_writeb(0, wrprotect);
 	printf("write protect is 0x%x\n", chip_readb(wrprotect));
 
 	// now start it
 	chip_writeb(0x20, bios);
 	chip_writeb(0xd0, bios);
 	programmer_delay(10);
 	// now let's see what the register is
 	status = wait_82802ab(flash->virtual_memory);
-	print_82802ab_status(status);
+	print_status_82802ab(status);
 	printf("DONE BLOCK 0x%x\n", blockaddr);
 
 	if (check_erased_range(flash, blockaddr, blocklen)) {
 		fprintf(stderr, "ERASE FAILED!\n");
 		return -1;
 	}
 	return 0;
 }
 
 int write_lhf00l04(struct flashchip *flash, uint8_t *buf)
 {
 	int i;
 	int total_size = flash->total_size * 1024;
diff --git a/stm50flw0x0x.c b/stm50flw0x0x.c
index 7095aec..1838efc 100644
--- a/stm50flw0x0x.c
+++ b/stm50flw0x0x.c
@@ -23,46 +23,26 @@
  * This module is designed for supporting the devices
  * ST M50FLW040A (not yet tested)
  * ST M50FLW040B (not yet tested)
  * ST M50FLW080A
  * ST M50FLW080B (not yet tested)
  */
 
 #include <string.h>
 #include <stdlib.h>
 #include "flash.h"
 #include "flashchips.h"
 #include "chipdrivers.h"
 
-static void wait_stm50flw0x0x(chipaddr bios)
-{
-	chip_writeb(0x70, bios);
-	if ((chip_readb(bios) & 0x80) == 0) {	// it's busy
-		while ((chip_readb(bios) & 0x80) == 0) ;
-	}
-
-	// put another command to get out of status register mode
-
-	chip_writeb(0x90, bios);
-	programmer_delay(10);
-
-	chip_readb(bios); // Read device ID (to make sure?)
-
-	// this is needed to jam it out of "read id" mode
-	chip_writeb(0xAA, bios + 0x5555);
-	chip_writeb(0x55, bios + 0x2AAA);
-	chip_writeb(0xF0, bios + 0x5555);
-}
-
 /*
  * claus.gindhart@kontron.com
  * The ST M50FLW080B and STM50FLW080B chips have to be unlocked,
  * before you can erase them or write to them.
  */
 int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset)
 {
 	chipaddr wrprotect = flash->virtual_registers + 2;
 	const uint8_t unlock_sector = 0x00;
 	int j;
 
 	/*
 	 * These chips have to be unlocked before you can erase them or write
@@ -91,178 +71,80 @@ int unlock_block_stm50flw0x0x(struct flashchip *flash, int offset)
 		}
 	} else {
 		printf_debug("unlocking at 0x%x\n", offset);
 		chip_writeb(unlock_sector, wrprotect + offset);
 		if (chip_readb(wrprotect + offset) != unlock_sector) {
 			printf("Cannot unlock sector @ 0x%x\n", offset);
 			return -1;
 		}
 	}
 
 	return 0;
 }
 
-int erase_block_stm50flw0x0x(struct flashchip *flash, unsigned int block, unsigned int blocksize)
+int unlock_stm50flw0x0x(struct flashchip *flash)
 {
-	chipaddr bios = flash->virtual_memory + block;
-
-	// clear status register
-	chip_writeb(0x50, bios);
-	printf_debug("Erase at 0x%lx\n", bios);
-	// now start it
-	chip_writeb(0x20, bios);
-	chip_writeb(0xd0, bios);
-	programmer_delay(10);
-
-	wait_stm50flw0x0x(flash->virtual_memory);
+	int i;
 
-	if (check_erased_range(flash, block, blocksize)) {
-		fprintf(stderr, "ERASE FAILED!\n");
-		return -1;
+	for (i = 0; i < flash->total_size; i+= flash->page_size) {
+		if(unlock_block_stm50flw0x0x(flash, i)) {
+			fprintf(stderr, "UNLOCK FAILED!\n");
+			return -1;
+		}
 	}
-	printf("DONE BLOCK 0x%x\n", block);
 
 	return 0;
 }
 
 int erase_sector_stm50flw0x0x(struct flashchip *flash, unsigned int sector, unsigned int sectorsize)
 {
 	chipaddr bios = flash->virtual_memory + sector;
 
 	// clear status register
 	chip_writeb(0x50, bios);
 	printf_debug("Erase at 0x%lx\n", bios);
 	// now start it
 	chip_writeb(0x32, bios);
 	chip_writeb(0xd0, bios);
 	programmer_delay(10);
 
-	wait_stm50flw0x0x(flash->virtual_memory);
+	wait_82802ab(flash->virtual_memory);
 
 	if (check_erased_range(flash, sector, sectorsize)) {
 		fprintf(stderr, "ERASE FAILED!\n");
 		return -1;
 	}
 	printf("DONE BLOCK 0x%x\n", sector);
 
 	return 0;
 }
 
-int write_page_stm50flw0x0x(chipaddr bios, uint8_t *src,
-			    chipaddr dst, int page_size)
-{
-	int i, rc = 0;
-	chipaddr d = dst;
-	uint8_t *s = src;
-
-	/* transfer data from source to destination */
-	for (i = 0; i < page_size; i++) {
-		chip_writeb(0x40, dst);
-		chip_writeb(*src++, dst++);
-		wait_stm50flw0x0x(bios);
-	}
-
-/* claus.gindhart@kontron.com
- * TODO
- * I think, that verification is not required, but
- * i leave it in anyway
- */
-	dst = d;
-	src = s;
-	for (i = 0; i < page_size; i++) {
-		if (chip_readb(dst) != *src) {
-			rc = -1;
-			break;
-		}
-		dst++;
-		src++;
-	}
-
-	if (rc) {
-		fprintf(stderr, " page 0x%lx failed!\n",
-			(d - bios) / page_size);
-	}
-
-	return rc;
-}
-
-/* I simply erase block by block
- * I Chip This is not the fastest way, but it works
- */
-int erase_stm50flw0x0x(struct flashchip *flash)
+int erase_chip_stm50flw0x0x(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
 {
 	int i;
 	int total_size = flash->total_size * 1024;
 	int page_size = flash->page_size;
 
-	printf("Erasing page:\n");
-	for (i = 0; i < total_size / page_size; i++) {
-		printf
-		    ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
-		printf("%04d at address: 0x%08x ", i, i * page_size);
-		if (unlock_block_stm50flw0x0x(flash, i * page_size)) {
-			fprintf(stderr, "UNLOCK FAILED!\n");
-			return -1;
-		}
-		if (erase_block_stm50flw0x0x(flash, i * page_size, page_size)) {
-			fprintf(stderr, "ERASE FAILED!\n");
-			return -1;
-		}
-	}
-	printf("\n");
-
-	return 0;
-}
-
-int erase_chip_stm50flw0x0x(struct flashchip *flash, unsigned int addr, unsigned int blocklen)
-{
 	if ((addr != 0) || (blocklen != flash->total_size * 1024)) {
 		msg_cerr("%s called with incorrect arguments\n",
 			__func__);
 		return -1;
 	}
-	return erase_stm50flw0x0x(flash);
-}
-
-int write_stm50flw0x0x(struct flashchip *flash, uint8_t * buf)
-{
-	int i, rc = 0;
-	int total_size = flash->total_size * 1024;
-	int page_size = flash->page_size;
-	chipaddr bios = flash->virtual_memory;
-	uint8_t *tmpbuf = malloc(page_size);
 
-	if (!tmpbuf) {
-		printf("Could not allocate memory!\n");
-		exit(1);
-	}
-	printf("Programming page: \n");
-	for (i = 0; (i < total_size / page_size) && (rc == 0); i++) {
+	printf("Erasing page:\n");
+	for (i = 0; i < total_size / page_size; i++) {
 		printf
 		    ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
 		printf("%04d at address: 0x%08x ", i, i * page_size);
-
-		/* Auto Skip Blocks, which already contain the desired data
-		 * Faster, because we only write, what has changed
-		 * More secure, because blocks, which are excluded
-		 * (with the exclude or layout feature)
-		 * are not erased and rewritten; data is retained also
-		 * in sudden power off situations
-		 */
-		chip_readn(tmpbuf, bios + i * page_size, page_size);
-		if (!memcmp((void *)(buf + i * page_size), tmpbuf, page_size)) {
-			printf("SKIPPED\n");
-			continue;
+		//if (unlock_block_stm50flw0x0x(flash, i * page_size)) {
+		//	fprintf(stderr, "UNLOCK FAILED!\n");
+		//	return -1;
+		//}
+		if (erase_block_82802ab(flash, i * page_size, page_size)) {
+			fprintf(stderr, "ERASE FAILED!\n");
+			return -1;
 		}
-
-		rc = unlock_block_stm50flw0x0x(flash, i * page_size);
-		if (!rc)
-			rc = erase_block_stm50flw0x0x(flash, i * page_size, page_size);
-		if (!rc)
-			write_page_stm50flw0x0x(bios, buf + i * page_size,
-					bios + i * page_size, page_size);
 	}
 	printf("\n");
-	free(tmpbuf);
 
-	return rc;
+	return 0;
 }
-- 
1.6.6

