aboutsummaryrefslogtreecommitdiff
path: root/util/flashrom
diff options
context:
space:
mode:
authorStefan Reinauer <stepan@openbios.org>2005-11-24 10:45:34 +0000
committerStefan Reinauer <stepan@openbios.org>2005-11-24 10:45:34 +0000
commit7d5c7a7f1794cf846f2b62813c81f0f2a0ac5b54 (patch)
tree3ea89e5f20c249f3c0c8f31408577d3141214d3a /util/flashrom
parente0e137844adc8366de58514b10ed962da46ce77b (diff)
rename the directory to match the program name
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@2102 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/flashrom')
-rw-r--r--util/flashrom/82802ab.c201
-rw-r--r--util/flashrom/82802ab.h48
-rw-r--r--util/flashrom/Makefile33
-rw-r--r--util/flashrom/README20
-rw-r--r--util/flashrom/am29f040b.c135
-rw-r--r--util/flashrom/am29f040b.h8
-rw-r--r--util/flashrom/flash.h65
-rw-r--r--util/flashrom/flash_enable.c343
-rw-r--r--util/flashrom/flash_on.c77
-rw-r--r--util/flashrom/flash_rom.c328
-rw-r--r--util/flashrom/jedec.c219
-rw-r--r--util/flashrom/jedec.h67
-rw-r--r--util/flashrom/m29f400bt.c199
-rw-r--r--util/flashrom/m29f400bt.h79
-rw-r--r--util/flashrom/msys_doc.c282
-rw-r--r--util/flashrom/msys_doc.h110
-rw-r--r--util/flashrom/mx29f002.c119
-rw-r--r--util/flashrom/mx29f002.h8
-rw-r--r--util/flashrom/pm49fl004.c57
-rw-r--r--util/flashrom/pm49fl004.h8
-rw-r--r--util/flashrom/sst28sf040.c173
-rw-r--r--util/flashrom/sst28sf040.h8
-rw-r--r--util/flashrom/sst39sf020.c71
-rw-r--r--util/flashrom/sst39sf020.h7
-rw-r--r--util/flashrom/sst49lf040.c72
-rw-r--r--util/flashrom/sst49lf040.h7
-rw-r--r--util/flashrom/sst_fwhub.c114
-rw-r--r--util/flashrom/sst_fwhub.h8
-rw-r--r--util/flashrom/udelay.c37
-rw-r--r--util/flashrom/w49f002u.c56
-rw-r--r--util/flashrom/w49f002u.h6
31 files changed, 2965 insertions, 0 deletions
diff --git a/util/flashrom/82802ab.c b/util/flashrom/82802ab.c
new file mode 100644
index 0000000000..80945ad832
--- /dev/null
+++ b/util/flashrom/82802ab.c
@@ -0,0 +1,201 @@
+/*
+ * 82802ab.c: driver for programming JEDEC standard flash parts
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference: http://www.intel.com/design/chipsets/datashts/290658.htm
+ *
+ * $Id$
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/io.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "flash.h"
+#include "82802ab.h"
+
+// I need that Berkeley bit-map printer
+void print_82802ab_status(unsigned char status)
+{
+ printf("%s", status & 0x80 ? "Ready:" : "Busy:");
+ printf("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
+ printf("%s", status & 0x20 ? "BE ERROR:" : "BE OK:");
+ printf("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:");
+ printf("%s", status & 0x8 ? "VP ERR:" : "VPP OK:");
+ printf("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:");
+ printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
+}
+
+int probe_82802ab(struct flashchip *flash)
+{
+ volatile unsigned char *bios = flash->virt_addr;
+ unsigned char id1, id2;
+
+#if 0
+ *(volatile unsigned char *) (bios + 0x5555) = 0xAA;
+ *(volatile unsigned char *) (bios + 0x2AAA) = 0x55;
+ *(volatile unsigned char *) (bios + 0x5555) = 0x90;
+#endif
+
+ *bios = 0xff;
+ myusec_delay(10);
+ *bios = 0x90;
+ myusec_delay(10);
+
+ id1 = *(volatile unsigned char *) bios;
+ id2 = *(volatile unsigned char *) (bios + 0x01);
+
+#if 1
+ *(volatile unsigned char *) (bios + 0x5555) = 0xAA;
+ *(volatile unsigned char *) (bios + 0x2AAA) = 0x55;
+ *(volatile unsigned char *) (bios + 0x5555) = 0xF0;
+
+#endif
+ myusec_delay(10);
+
+ printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
+
+ if (id1 == flash->manufacture_id && id2 == flash->model_id) {
+ size_t size = flash->total_size * 1024;
+ // we need to mmap the write-protect space.
+ bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
+ flash->fd_mem, (off_t) (0 - 0x400000 - size));
+ if (bios == MAP_FAILED) {
+ // it's this part but we can't map it ...
+ perror("Error MMAP /dev/mem");
+ exit(1);
+ }
+
+ flash->virt_addr_2 = bios;
+ return 1;
+ }
+
+ return 0;
+}
+
+unsigned char wait_82802ab(volatile unsigned char *bios)
+{
+
+ unsigned char status;
+ unsigned char id1, id2;
+
+ *bios = 0x70;
+ if ((*bios & 0x80) == 0) { // it's busy
+ while ((*bios & 0x80) == 0);
+ }
+
+ status = *bios;
+
+ // put another command to get out of status register mode
+
+ *bios = 0x90;
+ myusec_delay(10);
+
+ id1 = *(volatile unsigned char *) bios;
+ id2 = *(volatile unsigned char *) (bios + 0x01);
+
+ // this is needed to jam it out of "read id" mode
+ *(volatile unsigned char *) (bios + 0x5555) = 0xAA;
+ *(volatile unsigned char *) (bios + 0x2AAA) = 0x55;
+ *(volatile unsigned char *) (bios + 0x5555) = 0xF0;
+ return status;
+
+}
+int erase_82802ab_block(struct flashchip *flash, int offset)
+{
+ volatile unsigned char *bios = flash->virt_addr + offset;
+ volatile unsigned char *wrprotect =
+ flash->virt_addr_2 + offset + 2;
+ unsigned char status;
+
+ // clear status register
+ *bios = 0x50;
+ //printf("Erase at %p\n", bios);
+ // clear write protect
+ //printf("write protect is at %p\n", (wrprotect));
+ //printf("write protect is 0x%x\n", *(wrprotect));
+ *(wrprotect) = 0;
+ //printf("write protect is 0x%x\n", *(wrprotect));
+
+ // now start it
+ *(volatile unsigned char *) (bios) = 0x20;
+ *(volatile unsigned char *) (bios) = 0xd0;
+ myusec_delay(10);
+ // now let's see what the register is
+ status = wait_82802ab(flash->virt_addr);
+ //print_82802ab_status(status);
+ printf("DONE BLOCK 0x%x\n", offset);
+ 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)
+ erase_82802ab_block(flash, i);
+ printf("DONE ERASE\n");
+ return (0);
+}
+
+void write_page_82802ab(volatile char *bios, char *src, volatile char *dst,
+ int page_size)
+{
+ int i;
+
+ for (i = 0; i < page_size; i++) {
+ /* transfer data from source to destination */
+ *dst = 0x40;
+ *dst++ = *src++;
+ wait_82802ab(bios);
+ }
+
+}
+
+int write_82802ab(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile unsigned char *bios = flash->virt_addr;
+
+ erase_82802ab(flash);
+ if (*bios != 0xff) {
+ printf("ERASE FAILED\n");
+ return -1;
+ }
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ printf("%04d at address: 0x%08x", i, i * page_size);
+ write_page_82802ab(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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("\n");
+ protect_82802ab(bios);
+ return (0);
+}
diff --git a/util/flashrom/82802ab.h b/util/flashrom/82802ab.h
new file mode 100644
index 0000000000..05420685d6
--- /dev/null
+++ b/util/flashrom/82802ab.h
@@ -0,0 +1,48 @@
+#ifndef __82802AB_H__
+#define __82802AB_H__ 1
+
+extern int probe_82802ab(struct flashchip *flash);
+extern int erase_82802ab(struct flashchip *flash);
+extern int write_82802ab(struct flashchip *flash, unsigned char *buf);
+
+extern __inline__ void toggle_ready_82802ab(volatile char *dst)
+{
+ unsigned int i = 0;
+ char tmp1, tmp2;
+
+ tmp1 = *dst & 0x40;
+
+ while (i++ < 0xFFFFFF) {
+ tmp2 = *dst & 0x40;
+ if (tmp1 == tmp2) {
+ break;
+ }
+ tmp1 = tmp2;
+ }
+}
+
+extern __inline__ void data_polling_82802ab(volatile char *dst, char data)
+{
+ unsigned int i = 0;
+ char tmp;
+
+ data &= 0x80;
+
+ while (i++ < 0xFFFFFF) {
+ tmp = *dst & 0x80;
+ if (tmp == data) {
+ break;
+ }
+ }
+}
+
+extern __inline__ void protect_82802ab(volatile char *bios)
+{
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ *(volatile char *) (bios + 0x5555) = 0xA0;
+
+ usleep(200);
+}
+
+#endif /* !__82802AB_H__ */
diff --git a/util/flashrom/Makefile b/util/flashrom/Makefile
new file mode 100644
index 0000000000..9d4124f31f
--- /dev/null
+++ b/util/flashrom/Makefile
@@ -0,0 +1,33 @@
+OBJS = flash_enable.o udelay.o jedec.o sst28sf040.o am29f040b.o mx29f002.c sst39sf020.o \
+ m29f400bt.o w49f002u.o 82802ab.o msys_doc.o pm49fl004.o sst49lf040.o sst_fwhub.o
+CC = gcc -O2 -g -Wall -Werror
+
+all: flash_rom flash_on
+
+flash_rom: flash_rom.o ${OBJS}
+ ${CC} -o flash_rom flash_rom.c ${OBJS} -lpci
+
+flash_on: flash_on.c
+ ${CC} -o flash_on flash_on.c
+
+clean:
+ rm -f flash_rom flash_on *.o *~
+
+flash_rom.o: flash_rom.c flash.h jedec.h \
+ 82802ab.h am29f040b.h m29f400bt.h msys_doc.h mx29f002.h sst28sf040.h \
+ sst39sf020.h w49f002u.h sst49lf040.h
+flash_on.o: flash_on.c
+
+82802ab.o: 82802ab.c 82802ab.h flash.h
+am29f040b.o: am29f040b.c am29f040b.h jedec.h flash.h
+m29f400bt.o: m29f400bt.c m29f400bt.h flash.h
+msys_doc.o: msys_doc.c msys_doc.h flash.h
+mx29f002.o: mx29f002.c mx29f002.h jedec.h flash.h
+sst28sf040.o: sst28sf040.c sst28sf040.h jedec.h flash.h
+sst39sf020.o: sst39sf020.c sst39sf020.h jedec.h flash.h
+sst49lf040.o: sst49lf040.c sst49lf040.h jedec.h flash.h
+w49f002u.o: w49f002u.c w49f002u.h jedec.h flash.h
+pm49fl004.o: pm49fl004.c pm49fl004.h jedec.h flash.h
+flash_enable.o: flash_enable.c
+udelay.o: udelay.c
+jedec.o: jedec.c jedec.h flash.h
diff --git a/util/flashrom/README b/util/flashrom/README
new file mode 100644
index 0000000000..48f6fb8754
--- /dev/null
+++ b/util/flashrom/README
@@ -0,0 +1,20 @@
+on the cs5530 southbridge,
+
+setpci -s 0:12.0 52.b=ee
+setpci -x 0:12.0 5b.b= 0x20 (| with whatever is there)
+
+I am making this a general-purpose userland flash burner -- RGM
+
+Earlier notes from Ollie:
+
+Here is some utilities for using/programming flash ROM on SiS 630/950 M/Bs
+
+ 1. flash_on, turnning on the flash writer enable for 630/950 M/Bs,
+ you have to run this before load DoC drivers.
+
+ 2. flash_rom, use your 630/950 M/Bs as a flash programmer for some
+ flash parts. This utility is made as modular as possible. If
+ you find your flash part is not supported, you can add a driver
+ your own. Or sending me the data sheet.
+
+Ollie
diff --git a/util/flashrom/am29f040b.c b/util/flashrom/am29f040b.c
new file mode 100644
index 0000000000..3ebfe8653f
--- /dev/null
+++ b/util/flashrom/am29f040b.c
@@ -0,0 +1,135 @@
+/*
+ * am29f040.c: driver for programming AMD am29f040b models
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ * AMD Am29F040B data sheet
+ * $Id$
+ */
+
+#include <stdio.h>
+#include "flash.h"
+#include "jedec.h"
+
+static __inline__ int erase_sector_29f040b(volatile char *bios,
+ unsigned long address)
+{
+ *(bios + 0x555) = 0xAA;
+ *(bios + 0x2AA) = 0x55;
+ *(bios + 0x555) = 0x80;
+ *(bios + 0x555) = 0xAA;
+ *(bios + 0x2AA) = 0x55;
+ *(bios + address) = 0x30;
+
+ sleep(2);
+
+ /* wait for Toggle bit ready */
+ toggle_ready_jedec(bios + address);
+
+ return (0);
+}
+
+static __inline__ int write_sector_29f040b(volatile char *bios,
+ unsigned char *src,
+ volatile unsigned char *dst,
+ unsigned int page_size)
+{
+ int i;
+
+ for (i = 0; i < page_size; i++) {
+ printf("0x%08lx",
+ (unsigned long) dst - (unsigned long) bios);
+
+ *(bios + 0x555) = 0xAA;
+ *(bios + 0x2AA) = 0x55;
+ *(bios + 0x555) = 0xA0;
+ *dst++ = *src++;
+
+ /* wait for Toggle bit ready */
+ toggle_ready_jedec(bios);
+
+ printf("\b\b\b\b\b\b\b\b\b\b");
+ }
+
+ return (0);
+}
+
+int probe_29f040b(struct flashchip *flash)
+{
+ volatile unsigned char *bios = flash->virt_addr;
+ unsigned char id1, id2;
+
+ *(bios + 0x555) = 0xAA;
+ *(bios + 0x2AA) = 0x55;
+ *(bios + 0x555) = 0x90;
+
+ id1 = *bios;
+ id2 = *(bios + 0x01);
+
+ *bios = 0xF0;
+
+ myusec_delay(10);
+
+ printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
+ if (id1 == flash->manufacture_id && id2 == flash->model_id)
+ return 1;
+
+ return 0;
+}
+
+int erase_29f040b(struct flashchip *flash)
+{
+ volatile unsigned char *bios = flash->virt_addr;
+
+ *(bios + 0x555) = 0xAA;
+ *(bios + 0x2AA) = 0x55;
+ *(bios + 0x555) = 0x80;
+ *(bios + 0x555) = 0xAA;
+ *(bios + 0x2AA) = 0x55;
+ *(bios + 0x555) = 0x10;
+
+ myusec_delay(10);
+ toggle_ready_jedec(bios);
+
+ return (0);
+}
+
+int write_29f040b(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile char *bios = flash->virt_addr;
+
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ /* erase the page before programming */
+ erase_sector_29f040b(bios, i * page_size);
+
+ /* write to the sector */
+ printf("%04d at address: ", i);
+ write_sector_29f040b(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
+ }
+ printf("\n");
+
+ return (0);
+}
diff --git a/util/flashrom/am29f040b.h b/util/flashrom/am29f040b.h
new file mode 100644
index 0000000000..08c6c92fae
--- /dev/null
+++ b/util/flashrom/am29f040b.h
@@ -0,0 +1,8 @@
+#ifndef __AM29F040B_H__
+#define __AM29F040B_H__ 1
+
+extern int probe_29f040b(struct flashchip *flash);
+extern int erase_29f040b(struct flashchip *flash);
+extern int write_29f040b(struct flashchip *flash, unsigned char *buf);
+
+#endif /* !__AM29F040B_H__ */
diff --git a/util/flashrom/flash.h b/util/flashrom/flash.h
new file mode 100644
index 0000000000..3dfefe259a
--- /dev/null
+++ b/util/flashrom/flash.h
@@ -0,0 +1,65 @@
+#ifndef __FLASH_H__
+#define __FLASH_H__ 1
+
+#include <sys/io.h>
+#include <unistd.h>
+
+struct flashchip {
+ char *name;
+ int manufacture_id;
+ int model_id;
+
+ volatile char *virt_addr;
+ int total_size;
+ int page_size;
+
+ int (*probe) (struct flashchip * flash);
+ int (*erase) (struct flashchip * flash);
+ int (*write) (struct flashchip * flash, unsigned char *buf);
+ int (*read) (struct flashchip * flash, unsigned char *buf);
+
+ int fd_mem;
+ volatile char *virt_addr_2;
+};
+
+#define AMD_ID 0x01
+#define AM_29F040B 0xA4
+
+#define ATMEL_ID 0x1F /* Winbond Manufacture ID code */
+#define AT_29C040A 0xA4 /* Winbond w29c020c device code */
+
+#define MX_ID 0xC2
+#define MX_29F002 0xB0
+
+#define SST_ID 0xBF /* SST Manufacturer ID code */
+#define SST_29EE020A 0x10 /* SST 29EE020 device code */
+#define SST_28SF040 0x04 /* SST 29EE040 device code */
+#define SST_39SF020 0xB6 /* SST 39SF020 device */
+#define SST_39VF020 0xD6 /* SST 39VF020 device */
+#define SST_49LF040 0x51 /* SST 49LF040 device */
+#define SST_49LF080A 0x5B /* SST 48LF080A device */
+#define SST_49LF002A 0x57 /* SST 49LF002A device */
+#define SST_49LF003A 0x1B /* SST 49LF003A device */
+#define SST_49LF004A 0x60 /* SST 49LF004A device */
+#define SST_49LF008A 0x5A /* SST 49LF008A device */
+
+#define PMC_ID 0x9D /* PMC Manufacturer ID[B code */
+#define PMC_49FL004 0x6E /* PMC 49FL004 device code */
+
+#define WINBOND_ID 0xDA /* Winbond Manufacture ID code */
+#define W_29C011 0xC1 /* Winbond w29c011 device code */
+#define W_29C020C 0x45 /* Winbond w29c020c device code */
+#define W_49F002U 0x0B /* Winbond w29c020c device code */
+
+#define ST_ID 0x20
+#define ST_M29F400BT 0xD5
+
+#define MSYSTEMS_ID 0x156f
+#define MSYSTEMS_MD2200 0xdb /* ? */
+#define MSYSTEMS_MD2800 0x30 /* hmm -- both 0x30 */
+#define MSYSTEMS_MD2802 0x30 /* hmm -- both 0x30 */
+
+extern void myusec_delay(int time);
+extern void myusec_calibrate_delay();
+extern int enable_flash_write(void);
+#endif /* !__FLASH_H__ */
diff --git a/util/flashrom/flash_enable.c b/util/flashrom/flash_enable.c
new file mode 100644
index 0000000000..19fd9b07eb
--- /dev/null
+++ b/util/flashrom/flash_enable.c
@@ -0,0 +1,343 @@
+#include <sys/io.h>
+#include <stdio.h>
+#include <pci/pci.h>
+#include <stdlib.h>
+
+static int enable_flash_sis630(struct pci_dev *dev, char *name)
+{
+ char b;
+
+ /* get io privilege access PCI configuration space */
+ if (iopl(3) != 0) {
+ perror("Can not set io priviliage");
+ exit(1);
+ }
+
+ /* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630 */
+ outl(0x80000840, 0x0cf8);
+ b = inb(0x0cfc) | 0x0b;
+ outb(b, 0xcfc);
+ /* Flash write enable on SiS 540/630 */
+ outl(0x80000845, 0x0cf8);
+ b = inb(0x0cfd) | 0x40;
+ outb(b, 0xcfd);
+
+ /* The same thing on SiS 950 SuperIO side */
+ outb(0x87, 0x2e);
+ outb(0x01, 0x2e);
+ outb(0x55, 0x2e);
+ outb(0x55, 0x2e);
+
+ if (inb(0x2f) != 0x87) {
+ outb(0x87, 0x4e);
+ outb(0x01, 0x4e);
+ outb(0x55, 0x4e);
+ outb(0xaa, 0x4e);
+ if (inb(0x4f) != 0x87) {
+ printf("Can not access SiS 950\n");
+ return -1;
+ }
+ outb(0x24, 0x4e);
+ b = inb(0x4f) | 0xfc;
+ outb(0x24, 0x4e);
+ outb(b, 0x4f);
+ outb(0x02, 0x4e);
+ outb(0x02, 0x4f);
+ }
+
+ outb(0x24, 0x2e);
+ printf("2f is %#x\n", inb(0x2f));
+ b = inb(0x2f) | 0xfc;
+ outb(0x24, 0x2e);
+ outb(b, 0x2f);
+
+ outb(0x02, 0x2e);
+ outb(0x02, 0x2f);
+
+ return 0;
+}
+
+static int enable_flash_e7500(struct pci_dev *dev, char *name)
+{
+ /* register 4e.b gets or'ed with one */
+ unsigned char old, new;
+ /* if it fails, it fails. There are so many variations of broken mobos
+ * that it is hard to argue that we should quit at this point.
+ */
+
+ old = pci_read_byte(dev, 0x4e);
+
+ new = old | 1;
+
+ if (new == old)
+ return 0;
+
+ pci_write_byte(dev, 0x4e, new);
+
+ if (pci_read_byte(dev, 0x4e) != new) {
+ printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x4e, new, name);
+ return -1;
+ }
+ return 0;
+}
+
+static int enable_flash_ich4(struct pci_dev *dev, char *name)
+{
+ /* register 4e.b gets or'ed with one */
+ unsigned char old, new;
+ /* if it fails, it fails. There are so many variations of broken mobos
+ * that it is hard to argue that we should quit at this point.
+ */
+
+ old = pci_read_byte(dev, 0x4e);
+
+ new = old | 1;
+
+ if (new == old)
+ return 0;
+
+ pci_write_byte(dev, 0x4e, new);
+
+ if (pci_read_byte(dev, 0x4e) != new) {
+ printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x4e, new, name);
+ return -1;
+ }
+ return 0;
+}
+
+static int enable_flash_vt8235(struct pci_dev *dev, char *name)
+{
+ unsigned char old, new, val;
+ unsigned int base;
+ int ok;
+
+ /* get io privilege access PCI configuration space */
+ if (iopl(3) != 0) {
+ perror("Can not set io priviliage");
+ exit(1);
+ }
+
+ old = pci_read_byte(dev, 0x40);
+
+ new = old | 0x10;
+
+ if (new == old)
+ return 0;
+
+ ok = pci_write_byte(dev, 0x40, new);
+ if (ok != 0) {
+ printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ old, new, name);
+ }
+
+ /* enable GPIO15 which is connected to write protect. */
+ base = ((pci_read_byte(dev, 0x88) & 0x80) | pci_read_byte(dev, 0x89) << 8);
+ val = inb(base + 0x4d);
+ val |= 0x80;
+ outb(val, base + 0x4d);
+
+ if (ok != 0) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+static int enable_flash_vt8231(struct pci_dev *dev, char *name)
+{
+ unsigned char val;
+
+ val = pci_read_byte(dev, 0x40);
+ val |= 0x10;
+ pci_write_byte(dev, 0x40, val);
+
+ if (pci_read_byte(dev, 0x40) != val) {
+ printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x40, val, name);
+ return -1;
+ }
+ return 0;
+}
+
+static int enable_flash_cs5530(struct pci_dev *dev, char *name)
+{
+ unsigned char new;
+
+ pci_write_byte(dev, 0x52, 0xee);
+
+ new = pci_read_byte(dev, 0x52);
+
+ if (new != 0xee) {
+ printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x52, new, name);
+ return -1;
+ }
+ return 0;
+}
+
+static int enable_flash_sc1100(struct pci_dev *dev, char *name)
+{
+ unsigned char new;
+
+ pci_write_byte(dev, 0x52, 0xee);
+
+ new = pci_read_byte(dev, 0x52);
+
+ if (new != 0xee) {
+ printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x52, new, name);
+ return -1;
+ }
+ return 0;
+}
+
+static int enable_flash_sis5595(struct pci_dev *dev, char *name)
+{
+ unsigned char new, newer;
+
+ new = pci_read_byte(dev, 0x45);
+
+ /* clear bit 5 */
+ new &= (~0x20);
+ /* set bit 2 */
+ new |= 0x4;
+
+ pci_write_byte(dev, 0x45, new);
+
+ newer = pci_read_byte(dev, 0x45);
+ if (newer != new) {
+ printf("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x45, new, name);
+ printf("Stuck at 0x%x\n", newer);
+ return -1;
+ }
+ return 0;
+}
+
+static int enable_flash_amd8111(struct pci_dev *dev, char *name)
+{
+ /* register 4e.b gets or'ed with one */
+ unsigned char old, new;
+ /* if it fails, it fails. There are so many variations of broken mobos
+ * that it is hard to argue that we should quit at this point.
+ */
+
+ /* enable decoding at 0xffb00000 to 0xffffffff */
+ old = pci_read_byte(dev, 0x43);
+ new = old | 0xC0;
+ if (new != old) {
+ pci_write_byte(dev, 0x43, new);
+ if (pci_read_byte(dev, 0x43) != new) {
+ printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x43, new, name);
+ }
+ }
+
+ old = pci_read_byte(dev, 0x40);
+ new = old | 0x01;
+ if (new == old)
+ return 0;
+ pci_write_byte(dev, 0x40, new);
+
+ if (pci_read_byte(dev, 0x40) != new) {
+ printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x40, new, name);
+ return -1;
+ }
+ return 0;
+}
+
+//By yhlu
+static int enable_flash_ck804(struct pci_dev *dev, char *name)
+{
+ /* register 4e.b gets or'ed with one */
+ unsigned char old, new;
+ /* if it fails, it fails. There are so many variations of broken mobos
+ * that it is hard to argue that we should quit at this point.
+ */
+
+ //dump_pci_device(dev);
+
+ old = pci_read_byte(dev, 0x88);
+ new = old | 0xc0;
+ if (new != old) {
+ pci_write_byte(dev, 0x88, new);
+ if (pci_read_byte(dev, 0x88) != new) {
+ printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x88, new, name);
+ }
+ }
+
+ old = pci_read_byte(dev, 0x6d);
+ new = old | 0x01;
+ if (new == old)
+ return 0;
+ pci_write_byte(dev, 0x6d, new);
+
+ if (pci_read_byte(dev, 0x6d) != new) {
+ printf("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
+ 0x6d, new, name);
+ return -1;
+ }
+ return 0;
+}
+
+typedef struct penable {
+ unsigned short vendor, device;
+ char *name;
+ int (*doit) (struct pci_dev * dev, char *name);
+} FLASH_ENABLE;
+
+static FLASH_ENABLE enables[] = {
+ {0x1039, 0x0630, "sis630", enable_flash_sis630},
+ {0x8086, 0x2480, "E7500", enable_flash_e7500},
+ {0x8086, 0x24c0, "ICH4", enable_flash_ich4},
+ {0x1106, 0x8231, "VT8231", enable_flash_vt8231},
+ {0x1106, 0x3177, "VT8235", enable_flash_vt8235},
+ {0x1078, 0x0100, "CS5530", enable_flash_cs5530},
+ {0x100b, 0x0510, "SC1100", enable_flash_sc1100},
+ {0x1039, 0x0008, "SIS5595", enable_flash_sis5595},
+ {0x1022, 0x7468, "AMD8111", enable_flash_amd8111},
+ {0x10de, 0x0050, "NVIDIA CK804", enable_flash_ck804}, // LPC
+ {0x10de, 0x0051, "NVIDIA CK804", enable_flash_ck804}, // Pro
+ {0x10de, 0x00d3, "NVIDIA CK804", enable_flash_ck804}, // Slave, should not be here, to fix known bug for A01.
+};
+
+int enable_flash_write()
+{
+ int i;
+ struct pci_access *pacc;
+ struct pci_dev *dev = 0;
+ FLASH_ENABLE *enable = 0;
+
+ pacc = pci_alloc(); /* Get the pci_access structure */
+ /* Set all options you want -- here we stick with the defaults */
+ pci_init(pacc); /* Initialize the PCI library */
+ pci_scan_bus(pacc); /* We want to get the list of devices */
+
+ /* now let's try to find the chipset we have ... */
+ for (i = 0; i < sizeof(enables) / sizeof(enables[0]) && (!dev);
+ i++) {
+ struct pci_filter f;
+ struct pci_dev *z;
+ /* the first param is unused. */
+ pci_filter_init((struct pci_access *) 0, &f);
+ f.vendor = enables[i].vendor;
+ f.device = enables[i].device;
+ for (z = pacc->devices; z; z = z->next)
+ if (pci_filter_match(&f, z)) {
+ enable = &enables[i];
+ dev = z;
+ }
+ }
+
+ /* now do the deed. */
+ if (enable) {
+ printf("Enabling flash write on %s...", enable->name);
+ if (enable->doit(dev, enable->name) == 0)
+ printf("OK\n");
+ }
+ return 0;
+}
diff --git a/util/flashrom/flash_on.c b/util/flashrom/flash_on.c
new file mode 100644
index 0000000000..f1e8aca38d
--- /dev/null
+++ b/util/flashrom/flash_on.c
@@ -0,0 +1,77 @@
+/*
+ * flash_rom.c: Turnning on Flash Write Enable for SiS 630/950 M/Bs,
+ * use this program before loading DoC drivers.
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ * 1. SiS 630 Specification
+ * 2. SiS 950 Specification
+ *
+ * $Id$
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/io.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ char b;
+
+ /* get io privilege access PCI configuration space */
+ if (iopl(3) != 0) {
+ perror("Can not set io priviliage");
+ exit(1);
+ }
+
+ /* Enable 0xFFF8000~0xFFFF0000 decoding on SiS 540/630 */
+ outl(0x80000840, 0x0cf8);
+ b = inb(0x0cfc) | 0x0b;
+ outb(b, 0xcfc);
+ /* Flash write enable on SiS 540/630 */
+ outl(0x80000845, 0x0cf8);
+ b = inb(0x0cfd) | 0x40;
+ outb(b, 0xcfd);
+
+ /* The same thing on SiS 950 SuperIO side */
+ outb(0x87, 0x2e);
+ outb(0x01, 0x2e);
+ outb(0x55, 0x2e);
+ outb(0x55, 0x2e);
+
+ if (inb(0x2f) != 0x87) {
+ printf("Can not access SiS 950\n");
+ return -1;
+ }
+
+ outb(0x24, 0x2e);
+ b = inb(0x2f) | 0xfc;
+ outb(0x24, 0x2e);
+ outb(b, 0x2f);
+
+ outb(0x02, 0x2e);
+ outb(0x02, 0x2f);
+
+ return (0);
+}
diff --git a/util/flashrom/flash_rom.c b/util/flashrom/flash_rom.c
new file mode 100644
index 0000000000..ceb56ad8f6
--- /dev/null
+++ b/util/flashrom/flash_rom.c
@@ -0,0 +1,328 @@
+/*
+ * flash_rom.c: Flash programming utility for SiS 630/950 M/Bs
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ * Copyright 2004 Tyan Corp
+ * yhlu yhlu@tyan.com add exclude start and end option
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ * 1. SiS 630 Specification
+ * 2. SiS 950 Specification
+ *
+ * $Id$
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "flash.h"
+#include "jedec.h"
+#include "m29f400bt.h"
+#include "82802ab.h"
+#include "msys_doc.h"
+#include "am29f040b.h"
+#include "sst28sf040.h"
+#include "w49f002u.h"
+#include "sst39sf020.h"
+#include "sst49lf040.h"
+#include "pm49fl004.h"
+#include "mx29f002.h"
+#include "sst_fwhub.h"
+
+struct flashchip flashchips[] = {
+ {"Am29F040B", AMD_ID, AM_29F040B, NULL, 512, 64 * 1024,
+ probe_29f040b, erase_29f040b, write_29f040b, NULL},
+ {"At29C040A", ATMEL_ID, AT_29C040A, NULL, 512, 256,
+ probe_jedec, erase_chip_jedec, write_jedec, NULL},
+ {"Mx29f002", MX_ID, MX_29F002, NULL, 256, 64 * 1024,
+ probe_29f002, erase_29f002, write_29f002, NULL},
+ {"SST29EE020A", SST_ID, SST_29EE020A, NULL, 256, 128,
+ probe_jedec, erase_chip_jedec, write_jedec, NULL},
+ {"SST28SF040A", SST_ID, SST_28SF040, NULL, 512, 256,
+ probe_28sf040, erase_28sf040, write_28sf040, NULL},
+ {"SST39SF020A", SST_ID, SST_39SF020, NULL, 256, 4096,
+ probe_jedec, erase_chip_jedec, write_39sf020,NULL},
+ {"SST39VF020", SST_ID, SST_39VF020, NULL, 256, 4096,
+ probe_jedec, erase_chip_jedec, write_39sf020,NULL},
+ {"SST49LF040", SST_ID, SST_49LF040, NULL, 512, 4096,
+ probe_jedec, erase_49lf040, write_49lf040,NULL},
+ {"SST49LF080A", SST_ID, SST_49LF080A, NULL, 1024, 4096,
+ probe_jedec, erase_chip_jedec, write_49lf040,NULL},
+ {"SST49LF002A/B", SST_ID, SST_49LF002A, NULL, 256, 16 * 1024,
+ probe_sst_fwhub, erase_sst_fwhub, write_sst_fwhub, NULL},
+ {"SST49LF003A/B", SST_ID, SST_49LF003A, NULL, 384, 64 * 1024,
+ probe_sst_fwhub, erase_sst_fwhub, write_sst_fwhub,NULL},
+ {"SST49LF004A/B", SST_ID, SST_49LF004A, NULL, 512, 64 * 1024,
+ probe_sst_fwhub, erase_sst_fwhub, write_sst_fwhub,NULL},
+ {"SST49LF008A", SST_ID, SST_49LF008A, NULL, 1024, 64 * 1024 ,
+ probe_sst_fwhub, erase_sst_fwhub, write_sst_fwhub, NULL},
+ {"Pm49FL004", PMC_ID, PMC_49FL004, NULL, 512, 64 * 1024,
+ probe_jedec, erase_chip_jedec, write_49fl004,NULL},
+ {"W29C011", WINBOND_ID, W_29C011, NULL, 128, 128,
+ probe_jedec, erase_chip_jedec, write_jedec, NULL},
+ {"W29C020C", WINBOND_ID, W_29C020C, NULL, 256, 128,
+ probe_jedec, erase_chip_jedec, write_jedec, NULL},
+ {"W49F002U", WINBOND_ID, W_49F002U, NULL, 256, 128,
+ probe_jedec, erase_chip_jedec, write_49f002, NULL},
+ {"M29F400BT", ST_ID, ST_M29F400BT, NULL, 512, 64 * 1024,
+ probe_m29f400bt, erase_m29f400bt, write_linuxbios_m29f400bt, NULL},
+ {"82802ab", 137, 173, NULL, 512, 64 * 1024,
+ probe_82802ab, erase_82802ab, write_82802ab, NULL},
+ {"82802ac", 137, 172, NULL, 1024, 64 * 1024,
+ probe_82802ab, erase_82802ab, write_82802ab, NULL},
+ {"MD-2802 (M-Systems DiskOnChip Millennium Module)",
+ MSYSTEMS_ID, MSYSTEMS_MD2802,
+ NULL, 8, 8 * 1024,
+ probe_md2802, erase_md2802, write_md2802, read_md2802},
+ {NULL,}
+};
+
+char *chip_to_probe = NULL;
+
+struct flashchip *probe_flash(struct flashchip *flash)
+{
+ int fd_mem;
+ volatile char *bios;
+ unsigned long size;
+
+ if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
+ perror("Can not open /dev/mem");
+ exit(1);
+ }
+
+ while (flash->name != NULL) {
+ if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) {
+ flash++;
+ continue;
+ }
+ printf("Trying %s, %d KB\n", flash->name, flash->total_size);
+ size = flash->total_size * 1024;
+ /* BUG? what happens if getpagesize() > size!?
+ -> ``Error MMAP /dev/mem: Invalid argument'' NIKI */
+ if (getpagesize() > size) {
+ size = getpagesize();
+ printf("%s: warning: size: %d -> %ld\n",
+ __FUNCTION__, flash->total_size * 1024,
+ (unsigned long) size);
+ }
+ bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
+ fd_mem, (off_t) (0xffffffff - size + 1));
+ if (bios == MAP_FAILED) {
+ perror("Error MMAP /dev/mem");
+ exit(1);
+ }
+ flash->virt_addr = bios;
+ flash->fd_mem = fd_mem;
+
+ if (flash->probe(flash) == 1) {
+ printf("%s found at physical address: 0x%lx\n",
+ flash->name, (0xffffffff - size + 1));
+ return flash;
+ }
+ munmap((void *) bios, size);
+ flash++;
+ }
+ return NULL;
+}
+
+int verify_flash(struct flashchip *flash, char *buf, int verbose)
+{
+ int i;
+ int total_size = flash->total_size * 1024;
+ volatile char *bios = flash->virt_addr;
+
+ printf("Verifying address: ");
+ for (i = 0; i < total_size; i++) {
+ if (verbose)
+ printf("0x%08x", i);
+ if (*(bios + i) != *(buf + i)) {
+ printf("FAILED\n");
+ return 0;
+ }
+ if (verbose)
+ printf("\b\b\b\b\b\b\b\b\b\b");
+ }
+ if (verbose)
+ printf("\n");
+ else
+ printf("VERIFIED\n");
+ return 1;
+}
+
+
+void usage(const char *name)
+{
+ printf("usage: %s [-rwv] [-c chipname] [-s exclude_start] [-e exclude_end] [file]\n", name);
+ printf("-r: read flash and save into file\n"
+ "-w: write file into flash (default when file is specified)\n"
+ "-v: verify flash against file\n"
+ "-c: probe only for specified flash chip\n"
+ "-s: exclude start position\n"
+ "-e: exclude end postion\n"
+ " If no file is specified, then all that happens\n"
+ " is that flash info is dumped\n");
+ exit(1);
+}
+
+int exclude_start_page, exclude_end_page;
+
+int main(int argc, char *argv[])
+{
+ char *buf;
+ unsigned long size;
+ FILE *image;
+ struct flashchip *flash;
+ int opt;
+ int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0,
+ verbose = 0;
+ char *filename = NULL;
+
+
+ unsigned int exclude_start_position=0, exclude_end_position=0; // [x,y)
+ char *tempstr=NULL;
+
+ if (argc > 1) {
+ /* Yes, print them. */
+ int i;
+ printf ("The arguments are:\n");
+ for (i = 1; i < argc; ++i)
+ printf ("%s\n", argv[i]);
+ }
+
+ setbuf(stdout, NULL);
+
+ while ((opt = getopt(argc, argv, "rwvVEc:s:e:")) != EOF) {
+ switch (opt) {
+ case 'r':
+ read_it = 1;
+ break;
+ case 'w':
+ write_it = 1;
+ break;
+ case 'v':
+ verify_it = 1;
+ break;
+ case 'c':
+ chip_to_probe = strdup(optarg);
+ break;
+ case 'V':
+ verbose = 1;
+ break;
+ case 'E':
+ erase_it = 1;
+ break;
+ case 's':
+ tempstr = strdup(optarg);
+ sscanf(tempstr,"%x",&exclude_start_position);
+ break;
+ case 'e':
+ tempstr = strdup(optarg);
+ sscanf(tempstr,"%x",&exclude_end_position);
+ break;
+
+ default:
+ usage(argv[0]);
+ break;
+ }
+ }
+
+ if (read_it && write_it) {
+ printf("-r and -w are mutually exclusive\n");
+ usage(argv[0]);
+ }
+
+ if (optind < argc)
+ filename = argv[optind++];
+
+ printf("Calibrating timer since microsleep sucks ... takes a second\n");
+ myusec_calibrate_delay();
+ printf("OK, calibrated, now do the deed\n");
+
+ /* try to enable it. Failure IS an option, since not all motherboards
+ * really need this to be done, etc., etc. It sucks.
+ */
+ (void) enable_flash_write();
+
+ if ((flash = probe_flash(flashchips)) == NULL) {
+ printf("EEPROM not found\n");
+ exit(1);
+ }
+
+ printf("Part is %s\n", flash->name);
+ if (!filename && !erase_it) {
+ printf("OK, only ENABLING flash write, but NOT FLASHING\n");
+ return 0;
+ }
+ size = flash->total_size * 1024;
+ buf = (char *) calloc(size, sizeof(char));
+
+ if (erase_it) {
+ printf("Erasing flash chip\n");
+ flash->erase(flash);
+ exit(0);
+ } else if (read_it) {
+ if ((image = fopen(filename, "w")) == NULL) {
+ perror(filename);
+ exit(1);
+ }
+ printf("Reading Flash...");
+ if (flash->read == NULL)
+ memcpy(buf, (const char *) flash->virt_addr, size);
+ else
+ flash->read(flash, buf);
+
+ if (exclude_end_position - exclude_start_position > 0)
+ memset(buf+exclude_start_position, 0,
+ exclude_end_position-exclude_start_position);
+
+ fwrite(buf, sizeof(char), size, image);
+ fclose(image);
+ printf("done\n");
+ } else {
+ if ((image = fopen(filename, "r")) == NULL) {
+ perror(filename);
+ exit(1);
+ }
+ fread(buf, sizeof(char), size, image);
+ fclose(image);
+ }
+
+ if (exclude_end_position - exclude_start_position > 0)
+ memcpy(buf+exclude_start_position,
+ (const char *) flash->virt_addr+exclude_start_position,
+ exclude_end_position-exclude_start_position);
+
+ exclude_start_page = exclude_start_position/flash->page_size;
+ if ((exclude_start_position%flash->page_size) != 0) {
+ exclude_start_page++;
+ }
+ exclude_end_page = exclude_end_position/flash->page_size;
+
+ if (write_it || (!read_it && !verify_it)) {
+ flash->write(flash, buf);
+ }
+ if (verify_it)
+ verify_flash(flash, buf, verbose);
+ return 0;
+}
diff --git a/util/flashrom/jedec.c b/util/flashrom/jedec.c
new file mode 100644
index 0000000000..353b17ab98
--- /dev/null
+++ b/util/flashrom/jedec.c
@@ -0,0 +1,219 @@
+/*
+ * jedec.c: driver for programming JEDEC standard flash parts
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include "flash.h"
+#include "jedec.h"
+
+int probe_jedec(struct flashchip *flash)
+{
+ volatile unsigned char *bios = flash->virt_addr;
+ unsigned char id1, id2;
+
+ /* Issue JEDEC Product ID Entry command */
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x5555) = 0x90;
+ myusec_delay(10);
+
+ /* Read product ID */
+ id1 = *(volatile unsigned char *) bios;
+ id2 = *(volatile unsigned char *) (bios + 0x01);
+
+ /* Issue JEDEC Product ID Exit command */
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x5555) = 0xF0;
+ myusec_delay(10);
+
+ printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
+ if (id1 == flash->manufacture_id && id2 == flash->model_id)
+ return 1;
+
+ return 0;
+}
+
+int erase_sector_jedec(volatile unsigned char *bios, unsigned int page)
+{
+ /* Issue the Sector Erase command */
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x5555) = 0x80;
+ myusec_delay(10);
+
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ myusec_delay(10);
+ *(volatile char *) (bios + page) = 0x30;
+ myusec_delay(10);
+
+ /* wait for Toggle bit ready */
+ toggle_ready_jedec(bios);
+
+ return (0);
+}
+
+int erase_block_jedec(volatile unsigned char *bios, unsigned int block)
+{
+ /* Issue the Sector Erase command */
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x5555) = 0x80;
+ myusec_delay(10);
+
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ myusec_delay(10);
+ *(volatile char *) (bios + block) = 0x50;
+ myusec_delay(10);
+
+ /* wait for Toggle bit ready */
+ toggle_ready_jedec(bios);
+
+ return (0);
+}
+
+int erase_chip_jedec(struct flashchip *flash)
+{
+ volatile unsigned char *bios = flash->virt_addr;
+
+ /* Issue the JEDEC Chip Erase command */
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x5555) = 0x80;
+ myusec_delay(10);
+
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ myusec_delay(10);
+ *(volatile char *) (bios + 0x5555) = 0x10;
+ myusec_delay(10);
+
+ toggle_ready_jedec(bios);
+
+ return (0);
+}
+
+int write_page_write_jedec(volatile unsigned char *bios, unsigned char *src,
+ volatile unsigned char *dst, int page_size)
+{
+ int i;
+
+ /* Issue JEDEC Data Unprotect comand */
+ *(volatile unsigned char *) (bios + 0x5555) = 0xAA;
+ *(volatile unsigned char *) (bios + 0x2AAA) = 0x55;
+ *(volatile unsigned char *) (bios + 0x5555) = 0xA0;
+
+ /* transfer data from source to destination */
+ for (i = 0; i < page_size; i++) {
+ /* If the data is 0xFF, don't program it */
+ if (*src == 0xFF)
+ continue;
+ *dst++ = *src++;
+ }
+
+ toggle_ready_jedec(dst - 1);
+
+ return 0;
+}
+
+int write_byte_program_jedec(volatile unsigned char *bios, unsigned char *src,
+ volatile unsigned char *dst)
+{
+ int tried = 0;
+
+ /* If the data is 0xFF, don't program it */
+ if (*src == 0xFF) {
+ return 0;
+ }
+
+retry:
+ /* Issue JEDEC Byte Program command */
+ *(volatile unsigned char *) (bios + 0x5555) = 0xAA;
+ *(volatile unsigned char *) (bios + 0x2AAA) = 0x55;
+ *(volatile unsigned char *) (bios + 0x5555) = 0xA0;
+
+ /* transfer data from source to destination */
+ *dst = *src;
+ toggle_ready_jedec(bios);
+
+ if (*dst != *src && tried++ < 0x10) {
+ goto retry;
+ }
+
+ return 0;
+}
+
+int write_sector_jedec(volatile unsigned char *bios, unsigned char *src,
+ volatile unsigned char *dst, unsigned int page_size)
+{
+ int i;
+
+ for (i = 0; i < page_size; i++) {
+ write_byte_program_jedec(bios, src, dst);
+ dst++, src++;
+ }
+
+ return (0);
+}
+
+int write_jedec(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024;
+ int page_size = flash->page_size;
+ volatile unsigned char *bios = flash->virt_addr;
+
+ erase_chip_jedec(flash);
+ if (*bios != (unsigned char) 0xff) {
+ printf("ERASE FAILED\n");
+ return -1;
+ }
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ printf("%04d at address: 0x%08x", i, i * page_size);
+ write_page_write_jedec(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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("\n");
+ protect_jedec(bios);
+
+ return (0);
+}
diff --git a/util/flashrom/jedec.h b/util/flashrom/jedec.h
new file mode 100644
index 0000000000..2a9f977711
--- /dev/null
+++ b/util/flashrom/jedec.h
@@ -0,0 +1,67 @@
+#ifndef __JEDEC_H__
+#define __JEDEC_H__ 1
+int write_byte_program_jedec(volatile unsigned char *bios, unsigned char *src,
+ volatile unsigned char *dst);
+
+extern int probe_jedec(struct flashchip *flash);
+extern int erase_chip_jedec(struct flashchip *flash);
+extern int write_jedec(struct flashchip *flash, unsigned char *buf);
+extern int erase_sector_jedec(volatile unsigned char *bios, unsigned int page);
+extern int erase_block_jedec(volatile unsigned char *bios, unsigned int page);
+extern int write_sector_jedec(volatile unsigned char *bios, unsigned char *src,
+ volatile unsigned char *dst,
+ unsigned int page_size);
+
+extern __inline__ void toggle_ready_jedec(volatile char *dst)
+{
+ unsigned int i = 0;
+ char tmp1, tmp2;
+
+ tmp1 = *dst & 0x40;
+
+ while (i++ < 0xFFFFFFF) {
+ tmp2 = *dst & 0x40;
+ if (tmp1 == tmp2) {
+ break;
+ }
+ tmp1 = tmp2;
+ }
+}
+
+extern __inline__ void data_polling_jedec(volatile char *dst, char data)
+{
+ unsigned int i = 0;
+ char tmp;
+
+ data &= 0x80;
+
+ while (i++ < 0xFFFFFFF) {
+ tmp = *dst & 0x80;
+ if (tmp == data) {
+ break;
+ }
+ }
+}
+
+extern __inline__ void unprotect_jedec(volatile char *bios)
+{
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ *(volatile char *) (bios + 0x5555) = 0x80;
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ *(volatile char *) (bios + 0x5555) = 0x20;
+
+ usleep(200);
+}
+
+extern __inline__ void protect_jedec(volatile char *bios)
+{
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ *(volatile char *) (bios + 0x5555) = 0xA0;
+
+ usleep(200);
+}
+
+#endif /* !__JEDEC_H__ */
diff --git a/util/flashrom/m29f400bt.c b/util/flashrom/m29f400bt.c
new file mode 100644
index 0000000000..842e35d7d8
--- /dev/null
+++ b/util/flashrom/m29f400bt.c
@@ -0,0 +1,199 @@
+/*
+ * m29f400bt.c: driver for programming JEDEC standard flash parts
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ *
+ * $Id$
+ */
+
+#include "flash.h"
+#include "m29f400bt.h"
+
+int probe_m29f400bt(struct flashchip *flash)
+{
+ volatile char *bios = flash->virt_addr;
+ unsigned char id1, id2;
+
+ *(volatile char *) (bios + 0xAAA) = 0xAA;
+ *(volatile char *) (bios + 0x555) = 0x55;
+ *(volatile char *) (bios + 0xAAA) = 0x90;
+
+ myusec_delay(10);
+
+ id1 = *(volatile unsigned char *) bios;
+ id2 = *(volatile unsigned char *) (bios + 0x02);
+
+ *(volatile char *) (bios + 0xAAA) = 0xAA;
+ *(volatile char *) (bios + 0x555) = 0x55;
+ *(volatile char *) (bios + 0xAAA) = 0xF0;
+
+ myusec_delay(10);
+
+ printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
+
+
+ if (id1 == flash->manufacture_id && id2 == flash->model_id)
+ return 1;
+
+ return 0;
+}
+
+int erase_m29f400bt(struct flashchip *flash)
+{
+ volatile char *bios = flash->virt_addr;
+
+ *(volatile char *) (bios + 0xAAA) = 0xAA;
+ *(volatile char *) (bios + 0x555) = 0x55;
+ *(volatile char *) (bios + 0xAAA) = 0x80;
+
+ *(volatile char *) (bios + 0xAAA) = 0xAA;
+ *(volatile char *) (bios + 0x555) = 0x55;
+ *(volatile char *) (bios + 0xAAA) = 0x10;
+
+ myusec_delay(10);
+ toggle_ready_m29f400bt(bios);
+
+ return (0);
+}
+
+int block_erase_m29f400bt(volatile char *bios, volatile char *dst)
+{
+
+ *(volatile char *) (bios + 0xAAA) = 0xAA;
+ *(volatile char *) (bios + 0x555) = 0x55;
+ *(volatile char *) (bios + 0xAAA) = 0x80;
+
+ *(volatile char *) (bios + 0xAAA) = 0xAA;
+ *(volatile char *) (bios + 0x555) = 0x55;
+ //*(volatile char *) (bios + 0xAAA) = 0x10;
+ *dst = 0x30;
+
+ myusec_delay(10);
+ toggle_ready_m29f400bt(bios);
+
+ return (0);
+}
+
+int write_m29f400bt(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile char *bios = flash->virt_addr;
+
+ //erase_m29f400bt (flash);
+ printf("Programming Page:\n ");
+ /*********************************
+ *Pages for M29F400BT:
+ * 16 0x7c000 0x7ffff TOP
+ * 8 0x7a000 0x7bfff
+ * 8 0x78000 0x79fff
+ * 32 0x70000 0x77fff
+ * 64 0x60000 0x6ffff
+ * 64 0x50000 0x5ffff
+ * 64 0x40000 0x4ffff
+ *---------------------------------
+ * 64 0x30000 0x3ffff
+ * 64 0x20000 0x2ffff
+ * 64 0x10000 0x1ffff
+ * 64 0x00000 0x0ffff BOTTOM
+ *********************************/
+ printf("total_size/page_size = %d\n", total_size / page_size);
+ for (i = 0; i < (total_size / page_size) - 1; i++) {
+ printf("%04d at address: 0x%08x\n", i, i * page_size);
+ block_erase_m29f400bt(bios, bios + i * page_size);
+ write_page_m29f400bt(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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\n", 7, 0x70000);
+ block_erase_m29f400bt(bios, bios + 0x70000);
+ write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000,
+ 32 * 1024);
+
+ printf("%04d at address: 0x%08x\n", 8, 0x78000);
+ block_erase_m29f400bt(bios, bios + 0x78000);
+ write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000,
+ 8 * 1024);
+
+ printf("%04d at address: 0x%08x\n", 9, 0x7a000);
+ block_erase_m29f400bt(bios, bios + 0x7a000);
+ write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000,
+ 8 * 1024);
+
+ printf("%04d at address: 0x%08x\n", 10, 0x7c000);
+ block_erase_m29f400bt(bios, bios + 0x7c000);
+ write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000,
+ 16 * 1024);
+
+ printf("\n");
+ //protect_m29f400bt (bios);
+
+ return (0);
+}
+
+int write_linuxbios_m29f400bt(struct flashchip *flash, unsigned char *buf)
+{
+ volatile char *bios = flash->virt_addr;
+
+ printf("Programming Page:\n ");
+ /*********************************
+ *Pages for M29F400BT:
+ * 16 0x7c000 0x7ffff TOP
+ * 8 0x7a000 0x7bfff
+ * 8 0x78000 0x79fff
+ * 32 0x70000 0x77fff
+ * 64 0x60000 0x6ffff
+ * 64 0x50000 0x5ffff
+ * 64 0x40000 0x4ffff
+ *---------------------------------
+ * 64 0x30000 0x3ffff
+ * 64 0x20000 0x2ffff
+ * 64 0x10000 0x1ffff
+ * 64 0x00000 0x0ffff BOTTOM
+ *********************************/
+ printf("%04d at address: 0x%08x\n", 7, 0x00000);
+ block_erase_m29f400bt(bios, bios + 0x00000);
+ write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000,
+ 64 * 1024);
+
+ printf("%04d at address: 0x%08x\n", 7, 0x10000);
+ block_erase_m29f400bt(bios, bios + 0x10000);
+ write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000,
+ 64 * 1024);
+
+ printf("%04d at address: 0x%08x\n", 7, 0x20000);
+ block_erase_m29f400bt(bios, bios + 0x20000);
+ write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000,
+ 64 * 1024);
+
+ printf("%04d at address: 0x%08x\n", 7, 0x30000);
+ block_erase_m29f400bt(bios, bios + 0x30000);
+ write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000,
+ 64 * 1024);
+
+ printf("\n");
+ //protect_m29f400bt (bios);
+
+ return (0);
+}
diff --git a/util/flashrom/m29f400bt.h b/util/flashrom/m29f400bt.h
new file mode 100644
index 0000000000..efe0953701
--- /dev/null
+++ b/util/flashrom/m29f400bt.h
@@ -0,0 +1,79 @@
+#ifndef __M29F400BT_H__
+#define __M29F400BT_H__ 1
+
+#include <stdio.h>
+
+extern int probe_m29f400bt(struct flashchip *flash);
+extern int erase_m29f400bt(struct flashchip *flash);
+extern int block_erase_m29f400bt(volatile char *bios, volatile char *dst);
+extern int write_m29f400bt(struct flashchip *flash, unsigned char *buf);
+extern int write_linuxbios_m29f400bt(struct flashchip *flash,
+ unsigned char *buf);
+
+extern __inline__ void toggle_ready_m29f400bt(volatile char *dst)
+{
+ unsigned int i = 0;
+ char tmp1, tmp2;
+
+ tmp1 = *dst & 0x40;
+
+ while (i++ < 0xFFFFFF) {
+ tmp2 = *dst & 0x40;
+ if (tmp1 == tmp2) {
+ break;
+ }
+ tmp1 = tmp2;
+ }
+}
+
+extern __inline__ void data_polling_m29f400bt(volatile char *dst,
+ unsigned char data)
+{
+ unsigned int i = 0;
+ char tmp;
+
+ data &= 0x80;
+
+ while (i++ < 0xFFFFFF) {
+ tmp = *dst & 0x80;
+ if (tmp == data) {
+ break;
+ }
+ }
+}
+
+extern __inline__ void protect_m29f400bt(volatile char *bios)
+{
+ *(volatile char *) (bios + 0xAAA) = 0xAA;
+ *(volatile char *) (bios + 0x555) = 0x55;
+ *(volatile char *) (bios + 0xAAA) = 0xA0;
+
+ usleep(200);
+}
+
+extern __inline__ void write_page_m29f400bt(volatile char *bios, char *src,
+ volatile char *dst,
+ int page_size)
+{
+ int i;
+
+ for (i = 0; i < page_size; i++) {
+ *(volatile char *) (bios + 0xAAA) = 0xAA;
+ *(volatile char *) (bios + 0x555) = 0x55;
+ *(volatile char *) (bios + 0xAAA) = 0xA0;
+
+ /* transfer data from source to destination */
+ *dst = *src;
+ //*(volatile char *) (bios) = 0xF0;
+ //usleep(5);
+ toggle_ready_m29f400bt(dst);
+ printf
+ ("Value in the flash at address %p = %#x, want %#x\n",
+ (char *) (dst - bios), *dst, *src);
+ dst++;
+ src++;
+ }
+
+}
+
+#endif /* !__M29F400BT_H__ */
diff --git a/util/flashrom/msys_doc.c b/util/flashrom/msys_doc.c
new file mode 100644
index 0000000000..7e9ca9ac08
--- /dev/null
+++ b/util/flashrom/msys_doc.c
@@ -0,0 +1,282 @@
+/*
+ * msys_doc.c: driver for programming m-systems doc devices
+ *
+ *
+ * Copyright 2003 Niki W. Waibel <niki.waibel@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include "flash.h"
+#include "msys_doc.h"
+
+
+
+
+
+static int doc_wait(volatile char *bios, int timeout);
+static unsigned char doc_read_chipid(volatile char *bios);
+static unsigned char doc_read_docstatus(volatile char *bios);
+static unsigned char doc_read_cdsncontrol(volatile char *bios);
+static void doc_write_cdsncontrol(volatile char *bios, unsigned char data);
+
+
+
+
+
+int probe_md2802(struct flashchip *flash)
+{
+ volatile char *bios = flash->virt_addr;
+ unsigned char chipid;
+#ifndef MSYSTEMS_DOC_NO_55AA_CHECKING
+ unsigned char id_0x55, id_0xAA;
+#endif /* !MSYSTEMS_DOC_NO_55AA_CHECKING */
+ int i, toggle_a, toggle_b;
+
+ printf("%s:\n", __FUNCTION__);
+ printf("%s: *******************************\n", __FUNCTION__);
+ printf("%s: * THIS IS A PRE ALPHA VERSION *\n", __FUNCTION__);
+ printf("%s: * IN THE DEVELOPEMENT *********\n", __FUNCTION__);
+ printf("%s: * PROCESS RIGHT NOW. **********\n", __FUNCTION__);
+ printf("%s: *******************************\n", __FUNCTION__);
+ printf("%s: * IF YOU ARE NOT A DEVELOPER **\n", __FUNCTION__);
+ printf("%s: * THEN DO NOT TRY TO READ OR **\n", __FUNCTION__);
+ printf("%s: * WRITE TO THIS DEVICE ********\n", __FUNCTION__);
+ printf("%s: *******************************\n", __FUNCTION__);
+ printf("%s:\n", __FUNCTION__);
+
+ printf("%s: switching off reset mode ...\n", __FUNCTION__);
+ doc_write(0x85, bios, DOCControl);
+ doc_write(0x85, bios, DOCControl);
+ doc_read_4nop(bios);
+ if (doc_wait(bios, 5000))
+ return (-1);
+ printf("%s: switching off reset mode ... done\n", __FUNCTION__);
+ printf("%s:\n", __FUNCTION__);
+
+ printf("%s: switching off write protection ...\n", __FUNCTION__);
+ doc_write_cdsncontrol(bios, doc_read_cdsncontrol(bios) & (~0x08));
+ printf("%s: switching off write protection ... done\n",
+ __FUNCTION__);
+ printf("%s:\n", __FUNCTION__);
+
+
+ chipid = doc_read_chipid(bios);
+#ifndef MSYSTEMS_DOC_NO_55AA_CHECKING
+ id_0x55 = doc_read(bios, IPL_0x0000);
+ id_0xAA = doc_read(bios, IPL_0x0001);
+#endif /* !MSYSTEMS_DOC_NO_55AA_CHECKING */
+ printf("%s: IPL_0x0000: 0x%02x\n", __FUNCTION__, id_0x55);
+ printf("%s: IPL_0x0001: 0x%02x\n", __FUNCTION__, id_0xAA);
+ printf("%s: IPL_0x0002: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, IPL_0x0002));
+ printf("%s: IPL_0x0003: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, IPL_0x0003));
+ printf("%s:\n", __FUNCTION__);
+ printf("%s: ChipID: 0x%02x\n", __FUNCTION__, chipid);
+ printf("%s: DOCStatus: 0x%02x\n", __FUNCTION__,
+ doc_read_docstatus(bios));
+ printf("%s: FloorSelect: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, FloorSelect));
+ printf("%s: CDSNControl: 0x%02x\n", __FUNCTION__,
+ doc_read_cdsncontrol(bios));
+ printf("%s: CDSNDeviceSelect: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, CDSNDeviceSelect));
+ printf("%s: ECCConfiguration: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ECCConfiguration));
+ printf("%s: CDSNSlowIO: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, CDSNSlowIO));
+ printf("%s: ECCSyndrome0: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ECCSyndrome0));
+ printf("%s: ECCSyndrome1: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ECCSyndrome1));
+ printf("%s: ECCSyndrome2: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ECCSyndrome2));
+ printf("%s: ECCSyndrome3: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ECCSyndrome3));
+ printf("%s: ECCSyndrome4: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ECCSyndrome4));
+ printf("%s: ECCSyndrome5: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ECCSyndrome5));
+ printf("%s: AliasResolution: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, AliasResolution));
+ printf("%s: ConfigurationInput: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ConfigurationInput));
+ printf("%s: ReadPipelineInitialization: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, ReadPipelineInitialization));
+ printf("%s: LastDataRead: 0x%02x\n", __FUNCTION__,
+ doc_read(bios, LastDataRead));
+ printf("%s:\n", __FUNCTION__);
+
+ printf("%s: checking ECCConfiguration toggle bit\n", __FUNCTION__);
+ printf("%s:", __FUNCTION__);
+ toggle_a = toggle_b = 0;
+ for (i = 0; i < 10; i++) {
+ unsigned char toggle = doc_toggle(bios);
+
+ printf(" 0x%02x", toggle);
+
+ if (i % 2)
+ toggle_a += toggle;
+ else
+ toggle_b += toggle;
+ } /* for(i=0; i<10; i++) */
+ printf("\n%s: toggle result: %d/%d\n", __FUNCTION__, toggle_a,
+ toggle_b);
+
+ if (chipid == flash->model_id
+ && ((toggle_a == 5 && toggle_b == 0)
+ || (toggle_a == 0 && toggle_b == 5))
+#ifndef MSYSTEMS_DOC_NO_55AA_CHECKING
+ && id_0x55 == 0x55 && id_0xAA == 0xaa
+#endif /* !MSYSTEMS_DOC_NO_55AA_CHECKING */
+ ) {
+ return (1);
+ }
+
+ return (0);
+} /* int probe_md2802(struct flashchip *flash) */
+
+
+
+int read_md2802(struct flashchip *flash, unsigned char *buf)
+{
+
+ return (0);
+} /* int read_md2802(struct flashchip *flash, unsigned char *buf) */
+
+
+
+int erase_md2802(struct flashchip *flash)
+{
+ volatile char *bios = flash->virt_addr;
+
+ return (1);
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ *(volatile char *) (bios + 0x5555) = 0x80;
+
+ *(volatile char *) (bios + 0x5555) = 0xAA;
+ *(volatile char *) (bios + 0x2AAA) = 0x55;
+ *(volatile char *) (bios + 0x5555) = 0x10;
+} /* int erase_md2802(struct flashchip *flash) */
+
+
+
+int write_md2802(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile unsigned char *bios = flash->virt_addr;
+
+ return (1);
+ erase_md2802(flash);
+ if (*bios != (unsigned char) 0xff) {
+ printf("ERASE FAILED\n");
+ return -1;
+ }
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ printf("%04d at address: 0x%08x", i, i * page_size);
+ //write_page_md2802(bios, buf + i * page_size, bios + i * page_size, page_size);
+ 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("\n");
+ //protect_md2802(bios);
+
+ return 0;
+} /* int write_md2802(struct flashchip *flash, char *buf) */
+
+
+
+
+
+
+/*
+ wait timeout msec for doc to become ready
+ return:
+ 0: ready
+ -1: timeout expired
+*/
+static int doc_wait(volatile char *bios, int timeout)
+{
+ int i = 20;
+
+ doc_read_4nop(bios);
+
+ while (_doc_busy(bios) && (i != 0)) {
+ usleep(timeout * 1000 / 20);
+ i--;
+ }
+
+ doc_read_2nop(bios);
+
+ if (_doc_busy(bios)) {
+ doc_read_2nop(bios);
+ return (-1);
+ }
+
+ return (0);
+} /* static int doc_wait(volatile char *bios, int timeout) */
+
+
+
+static unsigned char doc_read_docstatus(volatile char *bios)
+{
+ doc_read(bios, CDSNSlowIO);
+ doc_read_2nop(bios);
+
+ return (doc_read(bios, _DOCStatus));
+} /* static unsigned char doc_read_docstatus(volatile char *bios) */
+
+
+
+static unsigned char doc_read_chipid(volatile char *bios)
+{
+ doc_read(bios, CDSNSlowIO);
+ doc_read_2nop(bios);
+
+ return (doc_read(bios, _ChipID));
+} /* static unsigned char doc_read_chipid(volatile char *bios) */
+
+
+
+static unsigned char doc_read_cdsncontrol(volatile char *bios)
+{
+ unsigned char value;
+
+ /* the delays might be necessary when reading the busy bit,
+ but because a read to this reg reads the busy bit
+ anyway we better do this delays... */
+ doc_read_4nop(bios);
+ value = doc_read(bios, _CDSNControl);
+ doc_read_2nop(bios);
+
+ return (value);
+} /* static unsigned char doc_read_chipid(volatile char *bios) */
+
+
+
+static void doc_write_cdsncontrol(volatile char *bios, unsigned char data)
+{
+ doc_write(data, bios, _CDSNControl);
+ doc_read_4nop(bios);
+} /* static void doc_write_chipid(volatile char *bios, unsigned char data) */
diff --git a/util/flashrom/msys_doc.h b/util/flashrom/msys_doc.h
new file mode 100644
index 0000000000..3e2028b44b
--- /dev/null
+++ b/util/flashrom/msys_doc.h
@@ -0,0 +1,110 @@
+/*
+ * msys_doc.h: header file of msys_doc.c
+ *
+ *
+ * Copyright 2003 Niki W. Waibel <niki.waibel@gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+
+#ifndef __MSYS_DOC_H__
+#define __MSYS_DOC_H__ 1
+
+
+
+/* idea from include/linux/mtd/doc2000.h */
+/* registers with __ should not be read/written directly */
+#define MSYSTEMS_DOC_R__ChipID 0x1000
+#define MSYSTEMS_DOC_R__DOCStatus 0x1001
+#define MSYSTEMS_DOC_W_DOCControl 0x1002
+#define MSYSTEMS_DOC_R_FloorSelect 0x1003
+#define MSYSTEMS_DOC_W_FloorSelect 0x1003
+#define MSYSTEMS_DOC_R__CDSNControl 0x1004
+#define MSYSTEMS_DOC_W__CDSNControl 0x1004
+#define MSYSTEMS_DOC_R_CDSNDeviceSelect 0x1005
+#define MSYSTEMS_DOC_W_CDSNDeviceSelect 0x1005
+#define MSYSTEMS_DOC_R_ECCConfiguration 0x1006
+#define MSYSTEMS_DOC_W_ECCConfiguration 0x1006
+#define MSYSTEMS_DOC_R_CDSNSlowIO 0x100d
+#define MSYSTEMS_DOC_W_CDSNSlowIO 0x100d
+#define MSYSTEMS_DOC_R_ECCSyndrome0 0x1010
+#define MSYSTEMS_DOC_R_ECCSyndrome1 0x1011
+#define MSYSTEMS_DOC_R_ECCSyndrome2 0x1012
+#define MSYSTEMS_DOC_R_ECCSyndrome3 0x1013
+#define MSYSTEMS_DOC_R_ECCSyndrome4 0x1014
+#define MSYSTEMS_DOC_R_ECCSyndrome5 0x1015
+#define MSYSTEMS_DOC_R_AliasResolution 0x101b
+#define MSYSTEMS_DOC_W_AliasResolution 0x101b
+#define MSYSTEMS_DOC_R_ConfigurationInput 0x101c
+#define MSYSTEMS_DOC_W_ConfigurationInput 0x101c
+#define MSYSTEMS_DOC_R_ReadPipelineInitialization 0x101d
+#define MSYSTEMS_DOC_W_WritePipelineTermination 0x101e
+#define MSYSTEMS_DOC_R_LastDataRead 0x101f
+#define MSYSTEMS_DOC_W_LastDataRead 0x101f
+#define MSYSTEMS_DOC_R_NOP 0x1020
+#define MSYSTEMS_DOC_W_NOP 0x1020
+
+#define MSYSTEMS_DOC_R_IPL_0x0000 0x0000
+#define MSYSTEMS_DOC_R_IPL_0x0001 0x0001
+#define MSYSTEMS_DOC_R_IPL_0x0002 0x0002
+#define MSYSTEMS_DOC_R_IPL_0x0003 0x0003
+
+#define MSYSTEMS_DOC_R_CDSNIO_BASE 0x0800
+#define MSYSTEMS_DOC_W_CDSNIO_BASE 0x0800
+
+
+
+#define doc_read(base,reg) \
+ (*(volatile unsigned char *)(base + MSYSTEMS_DOC_R_##reg))
+
+#define doc_read_nop(base) \
+ doc_read(base, NOP)
+
+#define doc_read_2nop(base) \
+ { doc_read_nop(base); doc_read_nop(base); }
+
+#define doc_read_4nop(base) \
+ { doc_read_2nop(base); doc_read_2nop(base); }
+
+#define doc_write(data,base,reg) \
+ (*(volatile unsigned char *)(base + MSYSTEMS_DOC_W_##reg)) = data
+
+#define doc_write_nop(base) \
+ doc_write(0, base, NOP)
+
+#define doc_write_2nop(base) \
+ { doc_write_nop(base); doc_write_nop(base); }
+
+#define doc_write_4nop(base) \
+ { doc_write_2nop(base); doc_write_2nop(base); }
+
+#define _doc_busy(base) /* 0: ready; -1: busy */ \
+ ( ((doc_read(base, _CDSNControl) & 0x80) >> 7) - 1)
+
+#define doc_toggle(base) /* 0, 1, 0, 1, 0, 1, ... if a doc is present */ \
+ ( (doc_read(base, ECCConfiguration) & 0x04) >> 2 )
+
+
+
+extern int probe_md2802(struct flashchip *flash);
+extern int read_md2802(struct flashchip *flash, unsigned char *buf);
+extern int erase_md2802(struct flashchip *flash);
+extern int write_md2802(struct flashchip *flash, unsigned char *buf);
+
+
+
+#endif /* !__MSYS_DOC_H__ */
diff --git a/util/flashrom/mx29f002.c b/util/flashrom/mx29f002.c
new file mode 100644
index 0000000000..b281528935
--- /dev/null
+++ b/util/flashrom/mx29f002.c
@@ -0,0 +1,119 @@
+/*
+ * mx29f002.c: driver for MXIC MX29F002 flash models
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ * MX29F002/002N data sheet
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include "flash.h"
+#include "jedec.h"
+#include "mx29f002.h"
+
+int probe_29f002(struct flashchip *flash)
+{
+ volatile char *bios = flash->virt_addr;
+ unsigned char id1, id2;
+
+ *(bios + 0x5555) = 0xAA;
+ *(bios + 0x2AAA) = 0x55;
+ *(bios + 0x5555) = 0x90;
+
+ id1 = *(volatile unsigned char *) bios;
+ id2 = *(volatile unsigned char *) (bios + 0x01);
+
+ *bios = 0xF0;
+
+ myusec_delay(10);
+
+ printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
+ if (id1 == flash->manufacture_id && id2 == flash->model_id)
+ return 1;
+
+ return 0;
+}
+
+int erase_29f002(struct flashchip *flash)
+{
+ volatile char *bios = flash->virt_addr;
+
+ *(bios + 0x555) = 0xF0;
+ *(bios + 0x555) = 0xAA;
+ *(bios + 0x2AA) = 0x55;
+ *(bios + 0x555) = 0x80;
+ *(bios + 0x555) = 0xAA;
+ *(bios + 0x2AA) = 0x55;
+ *(bios + 0x555) = 0x10;
+
+ myusec_delay(100);
+ toggle_ready_jedec(bios);
+
+ // while ((*bios & 0x40) != 0x40)
+ //;
+
+#if 0
+ toggle_ready_jedec(bios);
+ *(bios + 0x0ffff) = 0x30;
+ *(bios + 0x1ffff) = 0x30;
+ *(bios + 0x2ffff) = 0x30;
+ *(bios + 0x37fff) = 0x30;
+ *(bios + 0x39fff) = 0x30;
+ *(bios + 0x3bfff) = 0x30;
+#endif
+
+ return (0);
+}
+
+int write_29f002(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024;
+ volatile char *bios = flash->virt_addr;
+ volatile char *dst = bios;
+
+ *bios = 0xF0;
+ myusec_delay(10);
+ erase_29f002(flash);
+ //*bios = 0xF0;
+#if 1
+ printf("Programming Page: ");
+ for (i = 0; i < total_size; i++) {
+ /* write to the sector */
+ if ((i & 0xfff) == 0)
+ printf("address: 0x%08lx", (unsigned long) i);
+ *(bios + 0x5555) = 0xAA;
+ *(bios + 0x2AAA) = 0x55;
+ *(bios + 0x5555) = 0xA0;
+ *dst++ = *buf++;
+
+ /* wait for Toggle bit ready */
+ toggle_ready_jedec(dst);
+
+ if ((i & 0xfff) == 0)
+ printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
+ }
+#endif
+ printf("\n");
+
+ return (0);
+}
diff --git a/util/flashrom/mx29f002.h b/util/flashrom/mx29f002.h
new file mode 100644
index 0000000000..7d3cf20ce1
--- /dev/null
+++ b/util/flashrom/mx29f002.h
@@ -0,0 +1,8 @@
+#ifndef __MX29F002_H__
+#define __MX29F002_H__ 1
+
+extern int probe_29f002(struct flashchip *flash);
+extern int erase_29f002(struct flashchip *flash);
+extern int write_29f002(struct flashchip *flash, unsigned char *buf);
+
+#endif /* !__MX29F002_H__ */
diff --git a/util/flashrom/pm49fl004.c b/util/flashrom/pm49fl004.c
new file mode 100644
index 0000000000..afcd55a063
--- /dev/null
+++ b/util/flashrom/pm49fl004.c
@@ -0,0 +1,57 @@
+/*
+ * pm49fl004.c: driver for Pm49FL004 flash models.
+ *
+ *
+ * Copyright 2004 Tyan Corporation
+ * yhlu yhlu@tyan.com add exclude range
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ */
+
+#include <stdio.h>
+#include "flash.h"
+#include "jedec.h"
+#include "pm49fl004.h"
+
+extern int exclude_start_page, exclude_end_page;
+
+int write_49fl004(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile char *bios = flash->virt_addr;
+
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ if( (i>=exclude_start_page) && (i<exclude_end_page))
+ continue;
+
+ /* erase the page before programming */
+ erase_block_jedec(bios, i * page_size);
+
+ /* write to the sector */
+ printf("%04d at address: 0x%08x", i, i * page_size);
+ write_sector_jedec(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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");
+ fflush(stdout);
+ }
+ printf("\n");
+
+ return (0);
+}
diff --git a/util/flashrom/pm49fl004.h b/util/flashrom/pm49fl004.h
new file mode 100644
index 0000000000..21c880b0bf
--- /dev/null
+++ b/util/flashrom/pm49fl004.h
@@ -0,0 +1,8 @@
+#ifndef __PM49FL004_H__
+#define __PM49FL004_H__ 1
+
+extern int probe_49fl004(struct flashchip *flash);
+extern int erase_49fl004(struct flashchip *flash);
+extern int write_49fl004(struct flashchip *flash, unsigned char *buf);
+
+#endif
diff --git a/util/flashrom/sst28sf040.c b/util/flashrom/sst28sf040.c
new file mode 100644
index 0000000000..1853f156b0
--- /dev/null
+++ b/util/flashrom/sst28sf040.c
@@ -0,0 +1,173 @@
+/*
+ * sst28sf040.c: driver for SST28SF040C flash models.
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ * 4 MEgabit (512K x 8) SuperFlash EEPROM, SST28SF040 data sheet
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include "flash.h"
+#include "jedec.h"
+
+#define AUTO_PG_ERASE1 0x20
+#define AUTO_PG_ERASE2 0xD0
+#define AUTO_PGRM 0x10
+#define CHIP_ERASE 0x30
+#define RESET 0xFF
+#define READ_ID 0x90
+
+static __inline__ void protect_28sf040(volatile char *bios)
+{
+ /* ask compiler not to optimize this */
+ volatile unsigned char tmp;
+
+ tmp = *(volatile unsigned char *) (bios + 0x1823);
+ tmp = *(volatile unsigned char *) (bios + 0x1820);
+ tmp = *(volatile unsigned char *) (bios + 0x1822);
+ tmp = *(volatile unsigned char *) (bios + 0x0418);
+ tmp = *(volatile unsigned char *) (bios + 0x041B);
+ tmp = *(volatile unsigned char *) (bios + 0x0419);
+ tmp = *(volatile unsigned char *) (bios + 0x040A);
+}
+
+static __inline__ void unprotect_28sf040(volatile char *bios)
+{
+ /* ask compiler not to optimize this */
+ volatile unsigned char tmp;
+
+ tmp = *(volatile unsigned char *) (bios + 0x1823);
+ tmp = *(volatile unsigned char *) (bios + 0x1820);
+ tmp = *(volatile unsigned char *) (bios + 0x1822);
+ tmp = *(volatile unsigned char *) (bios + 0x0418);
+ tmp = *(volatile unsigned char *) (bios + 0x041B);
+ tmp = *(volatile unsigned char *) (bios + 0x0419);
+ tmp = *(volatile unsigned char *) (bios + 0x041A);
+}
+
+static __inline__ int erase_sector_28sf040(volatile char *bios,
+ unsigned long address)
+{
+ *bios = AUTO_PG_ERASE1;
+ *(bios + address) = AUTO_PG_ERASE2;
+
+ /* wait for Toggle bit ready */
+ toggle_ready_jedec(bios);
+
+ return (0);
+}
+
+static __inline__ int write_sector_28sf040(volatile char *bios,
+ unsigned char *src,
+ volatile unsigned char *dst,
+ unsigned int page_size)
+{
+ int i;
+
+ for (i = 0; i < page_size; i++) {
+ /* transfer data from source to destination */
+ if (*src == 0xFF) {
+ dst++, src++;
+ /* If the data is 0xFF, don't program it */
+ continue;
+ }
+ /*issue AUTO PROGRAM command */
+ *dst = AUTO_PGRM;
+ *dst++ = *src++;
+
+ /* wait for Toggle bit ready */
+ toggle_ready_jedec(bios);
+ }
+
+ return (0);
+}
+
+int probe_28sf040(struct flashchip *flash)
+{
+ volatile char *bios = flash->virt_addr;
+ unsigned char id1, id2, tmp;
+
+ /* save the value at the beginning of the Flash */
+ tmp = *bios;
+
+ *bios = RESET;
+ myusec_delay(10);
+
+ *bios = READ_ID;
+ myusec_delay(10);
+ id1 = *(volatile unsigned char *) bios;
+ myusec_delay(10);
+ id2 = *(volatile unsigned char *) (bios + 0x01);
+
+ *bios = RESET;
+ myusec_delay(10);
+
+ printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
+ if (id1 == flash->manufacture_id && id2 == flash->model_id)
+ return 1;
+
+ /* if there is no SST28SF040, restore the original value */
+ *bios = tmp;
+ return 0;
+}
+
+int erase_28sf040(struct flashchip *flash)
+{
+ volatile char *bios = flash->virt_addr;
+
+ unprotect_28sf040(bios);
+ *bios = CHIP_ERASE;
+ *bios = CHIP_ERASE;
+ protect_28sf040(bios);
+
+ myusec_delay(10);
+ toggle_ready_jedec(bios);
+
+ return (0);
+}
+
+int write_28sf040(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile char *bios = flash->virt_addr;
+
+ unprotect_28sf040(bios);
+
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ /* erase the page before programming */
+ erase_sector_28sf040(bios, i * page_size);
+
+ /* write to the sector */
+ printf("%04d at address: 0x%08x", i, i * page_size);
+ write_sector_28sf040(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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("\n");
+
+ protect_28sf040(bios);
+
+ return (0);
+}
diff --git a/util/flashrom/sst28sf040.h b/util/flashrom/sst28sf040.h
new file mode 100644
index 0000000000..ca57eff1ec
--- /dev/null
+++ b/util/flashrom/sst28sf040.h
@@ -0,0 +1,8 @@
+#ifndef __SST28SF040_H__
+#define __SST28SF040_H__
+
+extern int probe_28sf040(struct flashchip *flash);
+extern int erase_28sf040(struct flashchip *flash);
+extern int write_28sf040(struct flashchip *flash, unsigned char *buf);
+
+#endif /* !__SST28SF040_H__ */
diff --git a/util/flashrom/sst39sf020.c b/util/flashrom/sst39sf020.c
new file mode 100644
index 0000000000..97e87a1c56
--- /dev/null
+++ b/util/flashrom/sst39sf020.c
@@ -0,0 +1,71 @@
+/*
+ * sst39sf020.c: driver for SST28SF040C flash models.
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ * 4 MEgabit (512K x 8) SuperFlash EEPROM, SST28SF040 data sheet
+ *
+ * ToDo: Consilidated to standard JEDEC code.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include "flash.h"
+#include "jedec.h"
+#include "sst39sf020.h"
+
+#define AUTO_PG_ERASE1 0x20
+#define AUTO_PG_ERASE2 0xD0
+
+static __inline__ int erase_sector_39sf020(volatile char *bios,
+ unsigned long address)
+{
+ *bios = AUTO_PG_ERASE1;
+ *(bios + address) = AUTO_PG_ERASE2;
+
+ /* wait for Toggle bit ready */
+ toggle_ready_jedec(bios);
+
+ return (0);
+}
+
+int write_39sf020(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile char *bios = flash->virt_addr;
+
+ erase_chip_jedec(flash);
+
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ /* write to the sector */
+ printf("%04d at address: 0x%08x", i, i * page_size);
+ write_sector_jedec(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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");
+ fflush(stdout);
+ }
+ printf("\n");
+
+ return (0);
+}
diff --git a/util/flashrom/sst39sf020.h b/util/flashrom/sst39sf020.h
new file mode 100644
index 0000000000..698814c3e7
--- /dev/null
+++ b/util/flashrom/sst39sf020.h
@@ -0,0 +1,7 @@
+#ifndef __SST39SF020_H__
+#define __SST39SF020_H__ 1
+
+extern int probe_39sf020(struct flashchip *flash);
+extern int write_39sf020(struct flashchip *flash, unsigned char *buf);
+
+#endif /* !__SST39SF020_H__ */
diff --git a/util/flashrom/sst49lf040.c b/util/flashrom/sst49lf040.c
new file mode 100644
index 0000000000..f19b91e1c2
--- /dev/null
+++ b/util/flashrom/sst49lf040.c
@@ -0,0 +1,72 @@
+/* sst40lf020.c: driver for SST40LF040 flash models.
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ * 4 MEgabit (512K x 8) SuperFlash EEPROM, SST49lF040 data sheet
+ *
+ * ToDo: Consilidated to standard JEDEC code.
+ *
+ * $Id$
+ */
+#include <stdio.h>
+#include "flash.h"
+#include "jedec.h"
+#include "sst49lf040.h"
+
+int erase_49lf040(struct flashchip *flash)
+{
+ int i;
+ int total_size = flash->total_size * 1024;
+ int page_size = flash->page_size;
+ volatile char *bios = flash->virt_addr;
+
+ for (i = 0; i < total_size / page_size; i++) {
+ /* Chip erase only works in parallel programming mode
+ * for the 49lf040. Use sector-erase instead */
+ erase_sector_jedec(bios, i * page_size);
+ }
+ return 0;
+}
+
+int write_49lf040(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024;
+ int page_size = flash->page_size;
+ volatile char *bios = flash->virt_addr;
+
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ /* erase the page before programming
+ * Chip erase only works in parallel programming mode
+ * for the 49lf040. Use sector-erase instead */
+ erase_sector_jedec(bios, i * page_size);
+
+ /* write to the sector */
+ printf("%04d at address: 0x%08x ", i, i * page_size);
+ write_sector_jedec(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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\b");
+ fflush(stdout);
+ }
+ printf("\n");
+
+ return (0);
+}
diff --git a/util/flashrom/sst49lf040.h b/util/flashrom/sst49lf040.h
new file mode 100644
index 0000000000..79dfec99f2
--- /dev/null
+++ b/util/flashrom/sst49lf040.h
@@ -0,0 +1,7 @@
+#ifndef __SST49LF040_H__
+#define __SST49LF040_H__ 1
+
+extern int erase_49lf040(struct flashchip *flash);
+extern int write_49lf040(struct flashchip *flash, unsigned char *buf);
+
+#endif /* !__SST49LF040_H__ */
diff --git a/util/flashrom/sst_fwhub.c b/util/flashrom/sst_fwhub.c
new file mode 100644
index 0000000000..c064ed661b
--- /dev/null
+++ b/util/flashrom/sst_fwhub.c
@@ -0,0 +1,114 @@
+/*
+ * adapted from the Intel FW hub stuff for 82802ax parts.
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Id$
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/io.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "flash.h"
+#include "jedec.h"
+#include "sst_fwhub.h"
+
+// I need that Berkeley bit-map printer
+void print_sst_fwhub_status(unsigned char status)
+{
+ printf("%s", status & 0x80 ? "Ready:" : "Busy:");
+ printf("%s", status & 0x40 ? "BE SUSPEND:" : "BE RUN/FINISH:");
+ printf("%s", status & 0x20 ? "BE ERROR:" : "BE OK:");
+ printf("%s", status & 0x10 ? "PROG ERR:" : "PROG OK:");
+ printf("%s", status & 0x8 ? "VP ERR:" : "VPP OK:");
+ printf("%s", status & 0x4 ? "PROG SUSPEND:" : "PROG RUN/FINISH:");
+ printf("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
+}
+
+/* probe_jedec works fine for probing */
+int probe_sst_fwhub(struct flashchip *flash)
+{
+ volatile unsigned char *bios;
+ size_t size = flash->total_size * 1024;
+
+ if (probe_jedec(flash) == 0)
+ return 0;
+
+ bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
+ flash->fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
+ if (bios == MAP_FAILED) {
+ // it's this part but we can't map it ...
+ perror("Error MMAP /dev/mem");
+ exit(1);
+ }
+
+ flash->virt_addr_2 = bios;
+ return 1;
+}
+
+int erase_sst_fwhub_block(struct flashchip *flash, int offset)
+{
+ volatile unsigned char *wrprotect = flash->virt_addr_2 + offset + 2;
+
+ // clear write protect
+ *(wrprotect) = 0;
+
+ erase_block_jedec(flash->virt_addr, offset);
+ toggle_ready_jedec(flash->virt_addr);
+
+ return (0);
+}
+
+int erase_sst_fwhub(struct flashchip *flash)
+{
+ int i;
+ unsigned int total_size = flash->total_size * 1024;
+
+ for (i = 0; i < total_size; i += flash->page_size)
+ erase_sst_fwhub_block(flash, i);
+ return (0);
+}
+
+int write_sst_fwhub(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile unsigned char *bios = flash->virt_addr;
+
+ erase_sst_fwhub(flash);
+ if (*bios != 0xff) {
+ printf("ERASE FAILED\n");
+ return -1;
+ }
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ printf("%04d at address: 0x%08x", i, i * page_size);
+ write_sector_jedec(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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("\n");
+ return (0);
+}
diff --git a/util/flashrom/sst_fwhub.h b/util/flashrom/sst_fwhub.h
new file mode 100644
index 0000000000..eb2b364e62
--- /dev/null
+++ b/util/flashrom/sst_fwhub.h
@@ -0,0 +1,8 @@
+#ifndef __SST_FWHUB_H__
+#define __SST_FWHUB_H__ 1
+
+extern int probe_sst_fwhub(struct flashchip *flash);
+extern int erase_sst_fwhub(struct flashchip *flash);
+extern int write_sst_fwhub(struct flashchip *flash, unsigned char *buf);
+
+#endif /* !__SST_FWHUB_H__ */
diff --git a/util/flashrom/udelay.c b/util/flashrom/udelay.c
new file mode 100644
index 0000000000..30b8dde261
--- /dev/null
+++ b/util/flashrom/udelay.c
@@ -0,0 +1,37 @@
+#include <sys/time.h>
+#include <stdio.h>
+
+// count to a billion. Time it. If it's < 1 sec, count to 10B, etc.
+unsigned long micro = 1;
+
+void myusec_delay(int time)
+{
+ volatile unsigned long i;
+ for (i = 0; i < time * micro; i++);
+}
+
+void myusec_calibrate_delay()
+{
+ int count = 1000;
+ unsigned long timeusec;
+ struct timeval start, end;
+ int ok = 0;
+
+ printf("Setting up microsecond timing loop\n");
+ while (!ok) {
+ gettimeofday(&start, 0);
+ myusec_delay(count);
+ gettimeofday(&end, 0);
+ timeusec = 1000000 * (end.tv_sec - start.tv_sec) +
+ (end.tv_usec - start.tv_usec);
+ count *= 2;
+ if (timeusec < 1000000 / 4)
+ continue;
+ ok = 1;
+ }
+
+ // compute one microsecond. That will be count / time
+ micro = count / timeusec;
+
+ fprintf(stderr, "%ldM loops per second\n", (unsigned long) micro);
+}
diff --git a/util/flashrom/w49f002u.c b/util/flashrom/w49f002u.c
new file mode 100644
index 0000000000..02667cf1a0
--- /dev/null
+++ b/util/flashrom/w49f002u.c
@@ -0,0 +1,56 @@
+/*
+ * w49f002u.c: driver for Winbond 49F002U flash models
+ *
+ *
+ * Copyright 2000 Silicon Integrated System Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * Reference:
+ * W49F002U data sheet
+ *
+ * ToDo: Consilidated to standard JEDEC code.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include "flash.h"
+#include "jedec.h"
+#include "w49f002u.h"
+
+int write_49f002(struct flashchip *flash, unsigned char *buf)
+{
+ int i;
+ int total_size = flash->total_size * 1024, page_size =
+ flash->page_size;
+ volatile char *bios = flash->virt_addr;
+
+ erase_chip_jedec(flash);
+
+ printf("Programming Page: ");
+ for (i = 0; i < total_size / page_size; i++) {
+ /* write to the sector */
+ printf("%04d at address: 0x%08x ", i, i * page_size);
+ write_sector_jedec(bios, buf + i * page_size,
+ bios + i * page_size, page_size);
+ 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\b");
+ fflush(stdout);
+ }
+ printf("\n");
+
+ return (0);
+}
diff --git a/util/flashrom/w49f002u.h b/util/flashrom/w49f002u.h
new file mode 100644
index 0000000000..29320b7cef
--- /dev/null
+++ b/util/flashrom/w49f002u.h
@@ -0,0 +1,6 @@
+#ifndef __W49F002U_H__
+#define __W49F002U_H__ 1
+
+extern int write_49f002(struct flashchip *flash, unsigned char *buf);
+
+#endif /* !__W49F002U_H__ */