added -E option for chip erase, remove duplicated code

git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1815 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Li-Ta Lo 2004-12-08 20:10:01 +00:00
parent 19b6945a40
commit 257a58b60d
6 changed files with 49 additions and 147 deletions

View File

@ -194,7 +194,8 @@ int main(int argc, char *argv[])
FILE *image;
struct flashchip *flash;
int opt;
int read_it = 0, write_it = 0, verify_it = 0, verbose = 0;
int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0,
verbose = 0;
char *filename = NULL;
@ -211,7 +212,7 @@ int main(int argc, char *argv[])
setbuf(stdout, NULL);
while ((opt = getopt(argc, argv, "rwvVc:s:e:")) != EOF) {
while ((opt = getopt(argc, argv, "rwvVEc:s:e:")) != EOF) {
switch (opt) {
case 'r':
read_it = 1;
@ -228,6 +229,9 @@ int main(int argc, char *argv[])
case 'V':
verbose = 1;
break;
case 'E':
erase_it = 1;
break;
case 's':
tempstr = strdup(optarg);
sscanf(tempstr,"%x",&exclude_start_position);
@ -266,14 +270,18 @@ int main(int argc, char *argv[])
}
printf("Part is %s\n", flash->name);
if (!filename) {
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 (read_it) {
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);

View File

@ -62,26 +62,19 @@ int probe_jedec(struct flashchip *flash)
int erase_sector_jedec(volatile unsigned char *bios, unsigned int page)
{
volatile unsigned char *Temp;
/* Issue the Sector Erase command */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
*(volatile char *) (bios + 0x5555) = 0xAA;
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
*(volatile char *) (bios + 0x2AAA) = 0x55;
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0x80; /* write data 0x80 to the address */
*(volatile char *) (bios + 0x5555) = 0x80;
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
*(volatile char *) (bios + 0x5555) = 0xAA;
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
*(volatile char *) (bios + 0x2AAA) = 0x55;
myusec_delay(10);
Temp = bios + page; /* set up address to be the current sector */
*Temp = 0x30; /* write data 0x30 to the address */
*(volatile char *) (bios + page) = 0x30;
myusec_delay(10);
/* wait for Toggle bit ready */
@ -92,26 +85,19 @@ int erase_sector_jedec(volatile unsigned char *bios, unsigned int page)
int erase_block_jedec(volatile unsigned char *bios, unsigned int block)
{
volatile unsigned char *Temp;
/* Issue the Sector Erase command */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
*(volatile char *) (bios + 0x5555) = 0xAA;
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
*(volatile char *) (bios + 0x2AAA) = 0x55;
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0x80; /* write data 0x80 to the address */
*(volatile char *) (bios + 0x5555) = 0x80;
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
*(volatile char *) (bios + 0x5555) = 0xAA;
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
*(volatile char *) (bios + 0x2AAA) = 0x55;
myusec_delay(10);
Temp = bios + block; /* set up address to be the current sector */
*Temp = 0x50; /* write data 0x30 to the address */
*(volatile char *) (bios + block) = 0x50;
myusec_delay(10);
/* wait for Toggle bit ready */
@ -123,26 +109,20 @@ int erase_block_jedec(volatile unsigned char *bios, unsigned int block)
int erase_chip_jedec(struct flashchip *flash)
{
volatile unsigned char *bios = flash->virt_addr;
volatile unsigned char *Temp;
/* Issue the JEDEC Chip Erase command */
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
*(volatile char *) (bios + 0x5555) = 0xAA;
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
*(volatile char *) (bios + 0x2AAA) = 0x55;
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0x80; /* write data 0x80 to the address */
*(volatile char *) (bios + 0x5555) = 0x80;
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be BASE:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
*(volatile char *) (bios + 0x5555) = 0xAA;
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be BASE:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
*(volatile char *) (bios + 0x2AAA) = 0x55;
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be BASEy:5555h */
*Temp = 0x10; /* write data 0x10 to the address */
*(volatile char *) (bios + 0x5555) = 0x10;
myusec_delay(10);
toggle_ready_jedec(bios);

View File

@ -27,36 +27,6 @@
#include "jedec.h"
#include "pm49fl004.h"
static __inline__ int erase_block_49fl004(volatile unsigned char *bios,
unsigned long address)
{
volatile unsigned char *Temp;
Temp = bios + 0x5555; /* set up address to be C000:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be C000:5555h */
*Temp = 0x80; /* write data 0x80 to the address */
myusec_delay(10);
Temp = bios + 0x5555; /* set up address to be C000:5555h */
*Temp = 0xAA; /* write data 0xAA to the address */
myusec_delay(10);
Temp = bios + 0x2AAA; /* set up address to be C000:2AAAh */
*Temp = 0x55; /* write data 0x55 to the address */
myusec_delay(10);
Temp = bios + address; /* set up address to be C000:5555h */
*Temp = 0x50; /* write data 0x50 to the address */
/* wait for Toggle bit ready */
toggle_ready_jedec(bios);
return (0);
}
extern int exclude_start_page, exclude_end_page;
int write_49fl004(struct flashchip *flash, unsigned char *buf)
@ -72,7 +42,7 @@ int write_49fl004(struct flashchip *flash, unsigned char *buf)
continue;
/* erase the page before programming */
erase_block_49fl004(bios, i * page_size);
erase_block_jedec(bios, i * page_size);
/* write to the sector */
printf("%04d at address: 0x%08x", i, i * page_size);

View File

@ -58,15 +58,11 @@ int write_39sf020(struct flashchip *flash, unsigned char *buf)
printf("Programming Page: ");
for (i = 0; i < total_size / page_size; i++) {
/* erase the page before programming */
//erase_sector_39sf020(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");
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

@ -47,38 +47,14 @@ void print_sst_fwhub_status(unsigned char status)
}
/* probe_jedec works fine for probing */
int probe_sst_fwhub(struct flashchip *flash)
{
volatile unsigned char *bios = flash->virt_addr;
unsigned char id1, id2;
volatile unsigned char *bios;
size_t size = flash->total_size * 1024;
/* 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)
if (probe_jedec(flash) == 0)
return 0;
myusec_delay(10);
bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
flash->fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
if (bios == MAP_FAILED) {
@ -91,23 +67,15 @@ int probe_sst_fwhub(struct flashchip *flash)
return 1;
}
unsigned char wait_sst_fwhub(volatile unsigned char *bios)
{
toggle_ready_jedec(bios);
return 0;
}
int erase_sst_fwhub_block(struct flashchip *flash, int offset)
{
volatile unsigned char *wrprotect = flash->virt_addr_2 + offset + 2;
unsigned char status;
//printf("Erase at %p\n", bios);
// clear write protect
*(wrprotect) = 0;
erase_block_jedec(flash->virt_addr, offset);
status = wait_sst_fwhub(flash->virt_addr);
toggle_ready_jedec(flash->virt_addr);
return (0);
}
@ -122,19 +90,6 @@ int erase_sst_fwhub(struct flashchip *flash)
return (0);
}
void write_page_sst_fwhub(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 */
write_byte_program_jedec(bios, src, dst);
src++;
dst++;
}
}
int write_sst_fwhub(struct flashchip *flash, unsigned char *buf)
{
int i;
@ -150,7 +105,7 @@ int write_sst_fwhub(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_sst_fwhub(bios, buf + 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");
}

View File

@ -35,27 +35,20 @@
int write_49f002(struct flashchip *flash, unsigned char *buf)
{
int i;
int total_size = flash->total_size * 1024;
int total_size = flash->total_size * 1024, page_size =
flash->page_size;
volatile char *bios = flash->virt_addr;
volatile char *dst = bios;
erase_chip_jedec(flash);
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");
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");