consolidate more jedec standard code

git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1457 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Li-Ta Lo 2004-03-20 16:46:10 +00:00
parent 6a1a1102ea
commit fbf43ac5a6
27 changed files with 762 additions and 695 deletions

View File

@ -102,8 +102,7 @@ unsigned char wait_82802ab(volatile unsigned char * bios)
*bios = 0x70;
if ((*bios & 0x80) == 0) { // it's busy
while ((*bios & 0x80) == 0)
;
while ((*bios & 0x80) == 0);
}
status = *bios;
@ -126,7 +125,8 @@ unsigned char wait_82802ab(volatile unsigned char * bios)
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;
volatile unsigned char *wrprotect =
flash->virt_addr_2 + offset + 2;
unsigned char status;
// clear status register
@ -178,7 +178,8 @@ void write_page_82802ab (volatile char * bios, char * src, volatile char * dst,
int write_82802ab(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size *1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile unsigned char *bios = flash->virt_addr;
erase_82802ab(flash);
@ -189,9 +190,10 @@ int write_82802ab (struct flashchip * flash, unsigned char * buf)
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");
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);

View File

@ -28,7 +28,8 @@
#include "flash.h"
#include "jedec.h"
static __inline__ int erase_sector_29f040b (volatile char * bios, unsigned long address)
static __inline__ int erase_sector_29f040b(volatile char *bios,
unsigned long address)
{
*(bios + 0x555) = 0xAA;
*(bios + 0x2AA) = 0x55;
@ -45,13 +46,16 @@ static __inline__ int erase_sector_29f040b (volatile char * bios, unsigned long
return (0);
}
static __inline__ int write_sector_29f040b(volatile char * bios, unsigned char * src,
volatile unsigned char * dst, unsigned int page_size)
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);
printf("0x%08lx",
(unsigned long) dst - (unsigned long) bios);
*(bios + 0x555) = 0xAA;
*(bios + 0x2AA) = 0x55;
@ -110,7 +114,8 @@ int erase_29f040b (struct flashchip * flash)
int write_29f040b(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size * 1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile char *bios = flash->virt_addr;
printf("Programming Page: ");
@ -120,8 +125,8 @@ int write_29f040b (struct flashchip * flash, unsigned char * buf)
/* write to the sector */
printf("%04d at address: ", i);
write_sector_29f040b(bios, buf + i * page_size, bios + i * page_size,
page_size);
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");

View File

@ -75,7 +75,8 @@ static int enable_flash_e7500(struct pci_dev *dev, char *name)
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",
printf
("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
0x4e, new, name);
return -1;
}
@ -103,12 +104,15 @@ static int enable_flash_vt8235(struct pci_dev *dev, char *name)
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",
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);
base =
((pci_read_byte(dev, 0x88) & 0x80) | pci_read_byte(dev, 0x89)
<< 8);
val = inb(base + 0x4d);
val |= 0x80;
outb(val, base + 0x4d);
@ -129,7 +133,8 @@ static int enable_flash_vt8231(struct pci_dev *dev, char *name)
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",
printf
("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
0x40, val, name);
return -1;
}
@ -145,7 +150,8 @@ static int enable_flash_cs5530(struct pci_dev *dev, char *name)
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",
printf
("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
0x52, new, name);
return -1;
}
@ -161,7 +167,8 @@ static int enable_flash_sc1100(struct pci_dev *dev, char *name)
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",
printf
("tried to set register 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
0x52, new, name);
return -1;
}
@ -183,7 +190,8 @@ static int enable_flash_sis5595(struct pci_dev *dev, char *name)
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",
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;
@ -191,7 +199,8 @@ static int enable_flash_sis5595(struct pci_dev *dev, char *name)
return 0;
}
static int enable_flash_amd8111(struct pci_dev *dev, char *name) {
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
@ -205,7 +214,8 @@ static int enable_flash_amd8111(struct pci_dev *dev, char *name) {
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",
printf
("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
0x43, new, name);
}
}
@ -217,7 +227,8 @@ static int enable_flash_amd8111(struct pci_dev *dev, char *name) {
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",
printf
("tried to set 0x%x to 0x%x on %s failed (WARNING ONLY)\n",
0x40, new, name);
return -1;
}
@ -254,7 +265,8 @@ int enable_flash_write()
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++) {
for (i = 0; i < sizeof(enables) / sizeof(enables[0]) && (!dev);
i++) {
struct pci_filter f;
struct pci_dev *z;
/* the first param is unused. */

View File

@ -51,39 +51,40 @@ 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_jedec, write_jedec, NULL},
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_jedec, write_jedec, NULL},
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_jedec, write_39sf020, NULL},
probe_jedec, erase_chip_jedec, write_39sf020, NULL},
{"SST39VF020", SST_ID, SST_39VF020, NULL, 256, 4096,
probe_jedec, erase_jedec, write_39sf020, NULL},
probe_jedec, erase_chip_jedec, write_39sf020, NULL},
{"SST49LF040", SST_ID, SST_49LF040, NULL, 512, 4096,
probe_jedec, erase_jedec, write_49lf040, NULL},
probe_jedec, erase_chip_jedec, write_49lf040, NULL},
{"SST49LF080A", SST_ID, SST_49LF080A, NULL, 1024, 4096,
probe_jedec, erase_jedec, write_49lf040, NULL},
probe_jedec, erase_chip_jedec, write_49lf040, NULL},
{"SST49LF002A", SST_ID, SST_49LF002A, NULL, 256, 4096,
probe_jedec, erase_jedec, write_49lf040, NULL},
probe_jedec, erase_chip_jedec, write_49lf040, NULL},
{"SST49LF003A", SST_ID, SST_49LF003A, NULL, 384, 4096,
probe_jedec, erase_jedec, write_49lf040, NULL},
probe_jedec, erase_chip_jedec, write_49lf040, NULL},
{"SST49LF004A", SST_ID, SST_49LF004A, NULL, 512, 4096,
probe_jedec, erase_jedec, write_49lf040, NULL},
probe_jedec, erase_chip_jedec, write_49lf040, NULL},
{"SST49LF008A", SST_ID, SST_49LF008A, NULL, 1024, 4096,
probe_jedec, erase_jedec, write_49lf040, NULL},
probe_jedec, erase_chip_jedec, write_49lf040, NULL},
{"Pm49FL004", PMC_ID, PMC_49FL004, NULL, 512, 64 * 1024,
probe_jedec, erase_jedec, write_49fl004, NULL},
probe_jedec, erase_chip_jedec, write_49fl004, NULL},
{"W29C011", WINBOND_ID, W_29C011, NULL, 128, 128,
probe_jedec, erase_jedec, write_jedec, NULL},
probe_jedec, erase_chip_jedec, write_jedec, NULL},
{"W29C020C", WINBOND_ID, W_29C020C, NULL, 256, 128,
probe_jedec, erase_jedec, write_jedec, NULL},
probe_jedec, erase_chip_jedec, write_jedec, NULL},
{"W49F002U", WINBOND_ID, W_49F002U, NULL, 256, 128,
probe_jedec, erase_jedec, write_49f002, NULL},
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},
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,
@ -109,18 +110,21 @@ struct flashchip * probe_flash(struct flashchip * flash)
}
while (flash->name != NULL) {
if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0) {
if (chip_to_probe
&& strcmp(flash->name, chip_to_probe) != 0) {
flash++;
continue;
}
printf("Trying %s, %d KB\n", flash->name, flash->total_size);
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);
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));
@ -222,7 +226,8 @@ int main (int argc, char * argv[])
if (optind < argc)
filename = argv[optind++];
printf("Calibrating timer since microsleep sucks ... takes a second\n");
printf
("Calibrating timer since microsleep sucks ... takes a second\n");
myusec_calibrate_delay();
printf("OK, calibrated, now do the deed\n");
@ -238,7 +243,8 @@ int main (int argc, char * argv[])
printf("Part is %s\n", flash->name);
if (!filename) {
printf("OK, only ENABLING flash write, but NOT FLASHING\n");
printf
("OK, only ENABLING flash write, but NOT FLASHING\n");
return 0;
}
size = flash->total_size * 1024;

View File

@ -33,6 +33,7 @@ int probe_jedec (struct flashchip * flash)
volatile 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;
@ -40,9 +41,11 @@ int probe_jedec (struct flashchip * flash)
*(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;
@ -59,28 +62,27 @@ int probe_jedec (struct flashchip * flash)
int erase_sector_jedec(volatile char *bios, unsigned int page)
{
/* Chip erase function does not exist for LPC mode on 49lf040.
* Erase sector-by-sector instead. */
volatile unsigned char *Temp;
/* Issue the Sector Erase command to 40LF040 */
Temp = bios + 0x5555; /* set up address to be C000:5555h */
/* Issue the Sector Erase command */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be C000:5555h */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0x80; /* write data 0x80 to the address */
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be C000:5555h */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
myusec_delay(10);
Temp = bios + page; /* set up address to be the current sector */
*Temp = 0x30; /* write data 0x30 to the address */
myusec_delay(10);
/* wait for Toggle bit ready */
toggle_ready_jedec(bios);
@ -88,29 +90,29 @@ int erase_sector_jedec (volatile char * bios, unsigned int page)
return (0);
}
int erase_jedec (struct flashchip * flash)
int erase_chip_jedec(struct flashchip *flash)
{
volatile unsigned char *bios = flash->virt_addr;
volatile unsigned char *Temp;
/* Issue the Sector Erase command to 39SF020 */
Temp = bios + 0x5555; /* set up address to be C000:5555h */
/* Issue the JEDEC Chip Erase command */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be C000:5555h */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0x80; /* write data 0x80 to the address */
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be C000:5555h */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be C000:5555h */
*Temp = 0x10; /* write data 0x55 to the address */
Temp = bios + 0x5555; /* set up address to be BASEy:5555h */
*Temp = 0x10; /* write data 0x10 to the address */
myusec_delay(10);
toggle_ready_jedec(bios);
@ -118,13 +120,70 @@ int erase_jedec (struct flashchip * flash)
return (0);
}
void write_page_jedec(volatile char *bios, char *src, volatile char *dst,
int page_size)
{
int i;
/* Issue JEDEC Data Unprotect comand */
*(volatile char *) (bios + 0x5555) = 0xAA;
*(volatile char *) (bios + 0x2AAA) = 0x55;
*(volatile char *) (bios + 0x5555) = 0xA0;
for (i = 0; i < page_size; i++) {
/* transfer data from source to destination */
*dst++ = *src++;
}
usleep(100);
toggle_ready_jedec(dst - 1);
}
int write_sector_jedec(volatile char *bios,
unsigned char *src,
volatile unsigned char *dst, unsigned int page_size)
{
int i;
volatile char *Temp;
for (i = 0; i < page_size; i++) {
if (*dst != 0xff) {
printf("FATAL: dst %p not erased (val 0x%x\n", dst,
*dst);
return (-1);
}
/* transfer data from source to destination */
if (*src == 0xFF) {
dst++, src++;
/* If the data is 0xFF, don't program it */
continue;
}
/* Issue JEDEC Byte Program command */
Temp = bios + 0x5555;
*Temp = 0xAA;
Temp = bios + 0x2AAA;
*Temp = 0x55;
Temp = bios + 0x5555;
*Temp = 0xA0;
*dst = *src;
toggle_ready_jedec(bios);
if (*dst != *src)
printf("BAD! dst 0x%lx val 0x%x src 0x%x\n",
(unsigned long) dst, *dst, *src);
dst++, src++;
}
return (0);
}
int write_jedec(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size *1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile unsigned char *bios = flash->virt_addr;
erase_jedec (flash);
erase_chip_jedec(flash);
if (*bios != (unsigned char) 0xff) {
printf("ERASE FAILED\n");
return -1;
@ -132,9 +191,10 @@ int write_jedec (struct flashchip * flash, unsigned char * buf)
printf("Programming Page: ");
for (i = 0; i < total_size / page_size; i++) {
printf("%04d at address: 0x%08x", i, i * page_size);
write_page_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");
write_page_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);

View File

@ -2,8 +2,13 @@
#define __JEDEC_H__ 1
extern int probe_jedec(struct flashchip *flash);
extern int erase_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 char *bios, unsigned int page);
extern int write_sector_jedec(volatile char *bios,
unsigned char *src,
volatile unsigned char *dst,
unsigned int page_size);
extern __inline__ void toggle_ready_jedec(volatile char *dst)
{
@ -36,6 +41,18 @@ extern __inline__ void data_polling_jedec (volatile char * dst, char data)
}
}
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;
@ -45,60 +62,5 @@ extern __inline__ void protect_jedec (volatile char * bios)
usleep(200);
}
extern int erase_sector_jedec (volatile char * bios, unsigned int page);
extern __inline__ void write_page_jedec (volatile char * bios, char * src, volatile char * dst,
int page_size)
{
int i;
*(volatile char *) (bios + 0x5555) = 0xAA;
*(volatile char *) (bios + 0x2AAA) = 0x55;
*(volatile char *) (bios + 0x5555) = 0xA0;
for (i = 0; i < page_size; i++) {
/* transfer data from source to destination */
*dst++ = *src++;
}
usleep(100);
toggle_ready_jedec(dst-1);
}
static __inline__ int write_sector_jedec(volatile char * bios,
unsigned char * src,
volatile unsigned char * dst,
unsigned int page_size)
{
int i;
volatile char *Temp;
for (i = 0; i < page_size; i++) {
if (*dst != 0xff) {
printf("FATAL: dst %p not erased (val 0x%x\n", dst, *dst);
return(-1);
}
/* transfer data from source to destination */
if (*src == 0xFF) {
dst++, src++;
/* If the data is 0xFF, don't program it */
continue;
}
Temp = (bios + 0x5555);
*Temp = 0xAA;
Temp = bios + 0x2AAA;
*Temp = 0x55;
Temp = bios + 0x5555;
*Temp = 0xA0;
*dst = *src;
toggle_ready_jedec(bios);
if (*dst != *src)
printf("BAD! dst 0x%lx val 0x%x src 0x%x\n",
(unsigned long)dst, *dst, *src);
dst++, src++;
}
return(0);
}
#endif /* !__JEDEC_H__ */

View File

@ -95,7 +95,8 @@ int block_erase_m29f400bt (volatile char * bios ,volatile char * dst)
int write_m29f400bt(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size *1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile char *bios = flash->virt_addr;
//erase_m29f400bt (flash);
@ -119,26 +120,31 @@ int write_m29f400bt (struct flashchip * flash, unsigned char * buf)
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");
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);
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);
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);
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);
write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000,
16 * 1024);
printf("\n");
//protect_m29f400bt (bios);
@ -168,19 +174,23 @@ int write_linuxbios_m29f400bt (struct flashchip * flash, unsigned char * buf)
*********************************/
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);
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);
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);
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);
write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000,
64 * 1024);
printf("\n");
//protect_m29f400bt (bios);

View File

@ -7,7 +7,8 @@ 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 int write_linuxbios_m29f400bt(struct flashchip *flash,
unsigned char *buf);
extern __inline__ void toggle_ready_m29f400bt(volatile char *dst)
{
@ -25,7 +26,8 @@ extern __inline__ void toggle_ready_m29f400bt (volatile char * dst)
}
}
extern __inline__ void data_polling_m29f400bt (volatile char * dst, unsigned char data)
extern __inline__ void data_polling_m29f400bt(volatile char *dst,
unsigned char data)
{
unsigned int i = 0;
char tmp;
@ -49,7 +51,8 @@ extern __inline__ void protect_m29f400bt (volatile char * bios)
usleep(200);
}
extern __inline__ void write_page_m29f400bt (volatile char * bios, char * src, volatile char * dst,
extern __inline__ void write_page_m29f400bt(volatile char *bios, char *src,
volatile char *dst,
int page_size)
{
int i;
@ -64,7 +67,9 @@ extern __inline__ void write_page_m29f400bt (volatile char * bios, char * src, v
//*(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);
printf
("Value in the flash at address %p = %#x, want %#x\n",
(char *) (dst - bios), *dst, *src);
dst++;
src++;
}

View File

@ -40,8 +40,7 @@ static void doc_write_cdsncontrol(volatile char *bios, unsigned char data);
int
probe_md2802(struct flashchip * flash)
int probe_md2802(struct flashchip *flash)
{
volatile char *bios = flash->virt_addr;
unsigned char chipid;
@ -73,7 +72,8 @@ probe_md2802(struct flashchip * flash)
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: switching off write protection ... done\n",
__FUNCTION__);
printf("%s:\n", __FUNCTION__);
@ -127,8 +127,7 @@ probe_md2802(struct flashchip * flash)
printf("%s: checking ECCConfiguration toggle bit\n", __FUNCTION__);
printf("%s:", __FUNCTION__);
toggle_a = toggle_b = 0;
for(i=0; i<10; i++)
{
for (i = 0; i < 10; i++) {
unsigned char toggle = doc_toggle(bios);
printf(" 0x%02x", toggle);
@ -138,15 +137,16 @@ probe_md2802(struct flashchip * flash)
else
toggle_b += toggle;
} /* for(i=0; i<10; i++) */
printf("\n%s: toggle result: %d/%d\n", __FUNCTION__, toggle_a, toggle_b);
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))
&& ((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);
}
@ -155,8 +155,7 @@ probe_md2802(struct flashchip * flash)
int
read_md2802(struct flashchip *flash, unsigned char *buf)
int read_md2802(struct flashchip *flash, unsigned char *buf)
{
return (0);
@ -164,8 +163,7 @@ read_md2802(struct flashchip *flash, unsigned char *buf)
int
erase_md2802(struct flashchip *flash)
int erase_md2802(struct flashchip *flash)
{
volatile char *bios = flash->virt_addr;
@ -181,11 +179,11 @@ erase_md2802(struct flashchip *flash)
int
write_md2802(struct flashchip *flash, unsigned char *buf)
int write_md2802(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size *1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile unsigned char *bios = flash->virt_addr;
return (1);
@ -198,7 +196,8 @@ write_md2802(struct flashchip *flash, unsigned char *buf)
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
("\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);
@ -216,23 +215,20 @@ write_md2802(struct flashchip *flash, unsigned char *buf)
0: ready
-1: timeout expired
*/
static int
doc_wait(volatile char *bios, int timeout)
static int doc_wait(volatile char *bios, int timeout)
{
int i = 20;
doc_read_4nop(bios);
while(_doc_busy(bios) && (i != 0))
{
while (_doc_busy(bios) && (i != 0)) {
usleep(timeout * 1000 / 20);
i--;
}
doc_read_2nop(bios);
if(_doc_busy(bios))
{
if (_doc_busy(bios)) {
doc_read_2nop(bios);
return (-1);
}
@ -242,8 +238,7 @@ doc_wait(volatile char *bios, int timeout)
static unsigned char
doc_read_docstatus(volatile char *bios)
static unsigned char doc_read_docstatus(volatile char *bios)
{
doc_read(bios, CDSNSlowIO);
doc_read_2nop(bios);
@ -253,8 +248,7 @@ doc_read_docstatus(volatile char *bios)
static unsigned char
doc_read_chipid(volatile char *bios)
static unsigned char doc_read_chipid(volatile char *bios)
{
doc_read(bios, CDSNSlowIO);
doc_read_2nop(bios);
@ -264,8 +258,7 @@ doc_read_chipid(volatile char *bios)
static unsigned char
doc_read_cdsncontrol(volatile char *bios)
static unsigned char doc_read_cdsncontrol(volatile char *bios)
{
unsigned char value;
@ -281,8 +274,7 @@ doc_read_cdsncontrol(volatile char *bios)
static void
doc_write_cdsncontrol(volatile char *bios, unsigned char data)
static void doc_write_cdsncontrol(volatile char *bios, unsigned char data)
{
doc_write(data, bios, _CDSNControl);
doc_read_4nop(bios);

View File

@ -31,7 +31,8 @@
#define RESET 0xFF
#define READ_ID 0x90
static __inline__ int erase_block_49fl004 ( volatile unsigned char * bios ,unsigned long address)
static __inline__ int erase_block_49fl004(volatile unsigned char *bios,
unsigned long address)
{
volatile unsigned char *Temp;
@ -69,7 +70,8 @@ static __inline__ int write_block_49fl004(volatile char * bios,
for (i = 0; i < page_size; i++) {
if (*dst != 0xff) {
printf("FATAL: dst %p not erased (val 0x%x\n", dst, *dst);
printf("FATAL: dst %p not erased (val 0x%x\n", dst,
*dst);
return (-1);
}
/* transfer data from source to destination */
@ -98,7 +100,8 @@ static __inline__ int write_block_49fl004(volatile char * bios,
int write_49fl004(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size * 1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile char *bios = flash->virt_addr;
printf("Programming Page: ");
@ -108,9 +111,10 @@ int write_49fl004 (struct flashchip * flash, unsigned char * buf)
/* write to the sector */
printf("%04d at address: 0x%08x", i, i * page_size);
write_block_49fl004(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");
write_block_49fl004(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");

View File

@ -64,7 +64,8 @@ static __inline__ void unprotect_28sf040 (volatile char * bios)
tmp = *(volatile unsigned char *) (bios + 0x041A);
}
static __inline__ int erase_sector_28sf040 (volatile char * bios, unsigned long address)
static __inline__ int erase_sector_28sf040(volatile char *bios,
unsigned long address)
{
*bios = AUTO_PG_ERASE1;
*(bios + address) = AUTO_PG_ERASE2;
@ -75,8 +76,10 @@ static __inline__ int erase_sector_28sf040 (volatile char * bios, unsigned long
return (0);
}
static __inline__ int write_sector_28sf040(volatile char * bios, unsigned char * src,
volatile unsigned char * dst, unsigned int page_size)
static __inline__ int write_sector_28sf040(volatile char *bios,
unsigned char *src,
volatile unsigned char *dst,
unsigned int page_size)
{
int i;
@ -145,7 +148,8 @@ int erase_28sf040 (struct flashchip * flash)
int write_28sf040(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size * 1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile char *bios = flash->virt_addr;
unprotect_28sf040(bios);
@ -157,9 +161,10 @@ int write_28sf040 (struct flashchip * flash, unsigned char * buf)
/* 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");
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");

View File

@ -39,7 +39,8 @@
#define RESET 0xFF
#define READ_ID 0x90
static __inline__ int erase_sector_39sf020 (volatile char * bios, unsigned long address)
static __inline__ int erase_sector_39sf020(volatile char *bios,
unsigned long address)
{
*bios = AUTO_PG_ERASE1;
*(bios + address) = AUTO_PG_ERASE2;
@ -53,10 +54,11 @@ static __inline__ int erase_sector_39sf020 (volatile char * bios, unsigned long
int write_39sf020(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size * 1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile char *bios = flash->virt_addr;
erase_jedec(flash);
erase_chip_jedec(flash);
printf("Programming Page: ");
for (i = 0; i < total_size / page_size; i++) {
@ -65,9 +67,10 @@ int write_39sf020 (struct flashchip * flash, unsigned char * buf)
/* 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");
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");

View File

@ -41,7 +41,8 @@
int write_49lf040(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size * 1024, page_size = flash->page_size;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile char *bios = flash->virt_addr;
printf("Programming Page: ");
@ -53,9 +54,10 @@ int write_49lf040 (struct flashchip * flash, unsigned char * buf)
/* 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");
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");

View File

@ -7,8 +7,7 @@ unsigned long micro = 1;
void myusec_delay(int time)
{
volatile unsigned long i;
for (i = 0; i < time * micro; i++)
;
for (i = 0; i < time * micro; i++);
}
void myusec_calibrate_delay()

View File

@ -39,7 +39,7 @@ int write_49f002 (struct flashchip * flash, unsigned char * buf)
volatile char *bios = flash->virt_addr;
volatile char *dst = bios;
erase_jedec(flash);
erase_chip_jedec(flash);
printf("Programming Page: ");
for (i = 0; i < total_size; i++) {