1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00
- switch to volatile everywhere
 - use myusec_delay instead of usleep

Corresponding to coreboot v1 svn r492.
This commit is contained in:
Ronald G. Minnich 2002-01-29 20:18:02 +00:00
parent f4cf2baec9
commit ef5779d1dd
8 changed files with 137 additions and 88 deletions

View File

@ -3,9 +3,7 @@ CC = gcc -O2
all: ${OBJS} all: ${OBJS}
${CC} -o flash_rom flash_rom.c ${OBJS} ${CC} -o flash_rom flash_rom.c ${OBJS}
${CC} -o flash_on flash_on.c # ${CC} -o flash_on flash_on.c
${CC} -o acpi_reset acpi_reset.c
${CC} -o acpi_shutdown acpi_shutdown.c
clean: clean:
rm -f flash_rom flash_on acpi_reset acpi_shutdown *.o *~ rm -f flash_rom flash_on *.o *~

View File

@ -27,7 +27,7 @@
#include "flash.h" #include "flash.h"
#include "jedec.h" #include "jedec.h"
static __inline__ erase_sector_29f040b (char * bios, unsigned long address) static __inline__ erase_sector_29f040b (volatile char * bios, unsigned long address)
{ {
*(bios + 0x555) = 0xAA; *(bios + 0x555) = 0xAA;
*(bios + 0x2AA) = 0x55; *(bios + 0x2AA) = 0x55;
@ -42,8 +42,8 @@ static __inline__ erase_sector_29f040b (char * bios, unsigned long address)
toggle_ready_jedec(bios + address); toggle_ready_jedec(bios + address);
} }
static __inline__ write_sector_29f040b(char * bios, unsigned char * src, static __inline__ write_sector_29f040b(volatile char * bios, unsigned char * src,
unsigned char * dst, unsigned int page_size) volatile unsigned char * dst, unsigned int page_size)
{ {
int i; int i;
@ -64,7 +64,7 @@ static __inline__ write_sector_29f040b(char * bios, unsigned char * src,
int probe_29f040b (struct flashchip * flash) int probe_29f040b (struct flashchip * flash)
{ {
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
unsigned char id1, id2; unsigned char id1, id2;
*(bios + 0x555) = 0xAA; *(bios + 0x555) = 0xAA;
@ -76,8 +76,9 @@ int probe_29f040b (struct flashchip * flash)
*bios = 0xF0; *bios = 0xF0;
usleep(10); myusec_delay(10);
printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2);
if (id1 == flash->manufacture_id && id2 == flash->model_id) if (id1 == flash->manufacture_id && id2 == flash->model_id)
return 1; return 1;
@ -86,7 +87,7 @@ int probe_29f040b (struct flashchip * flash)
int erase_29f040b (struct flashchip * flash) int erase_29f040b (struct flashchip * flash)
{ {
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
*(bios + 0x555) = 0xAA; *(bios + 0x555) = 0xAA;
*(bios + 0x2AA) = 0x55; *(bios + 0x2AA) = 0x55;
@ -95,7 +96,7 @@ int erase_29f040b (struct flashchip * flash)
*(bios + 0x2AA) = 0x55; *(bios + 0x2AA) = 0x55;
*(bios + 0x555) = 0x10; *(bios + 0x555) = 0x10;
usleep(10); myusec_delay(10);
toggle_ready_jedec(bios); toggle_ready_jedec(bios);
} }
@ -103,7 +104,7 @@ int write_29f040b (struct flashchip * flash, char * buf)
{ {
int i; 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;
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
printf ("Programming Page: "); printf ("Programming Page: ");
for (i = 0; i < total_size/page_size; i++) { for (i = 0; i < total_size/page_size; i++) {

View File

@ -6,7 +6,7 @@ struct flashchip {
int manufacture_id; int manufacture_id;
int model_id; int model_id;
char * virt_addr; volatile char * virt_addr;
int total_size; int total_size;
int page_size; int page_size;

View File

@ -109,7 +109,7 @@ int enable_flash_sis630 (void)
struct flashchip * probe_flash(struct flashchip * flash) struct flashchip * probe_flash(struct flashchip * flash)
{ {
int fd_mem; int fd_mem;
char * bios; volatile char * bios;
unsigned long size; unsigned long size;
if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) { if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) {
@ -118,6 +118,7 @@ struct flashchip * probe_flash(struct flashchip * flash)
} }
while (flash->name != NULL) { while (flash->name != NULL) {
printf("Trying %s, %d KB\n", flash->name, flash->total_size);
size = flash->total_size * 1024; size = flash->total_size * 1024;
bios = mmap (0, size, PROT_WRITE | PROT_READ, MAP_SHARED, bios = mmap (0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
fd_mem, (off_t) (0 - size)); fd_mem, (off_t) (0 - size));
@ -132,7 +133,7 @@ struct flashchip * probe_flash(struct flashchip * flash)
flash->name, (0 - size), bios); flash->name, (0 - size), bios);
return flash; return flash;
} }
munmap (bios, size); munmap ((void *) bios, size);
flash++; flash++;
} }
return NULL; return NULL;
@ -142,7 +143,7 @@ int verify_flash (struct flashchip * flash, char * buf)
{ {
int i = 0; int i = 0;
int total_size = flash->total_size *1024; int total_size = flash->total_size *1024;
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
printf("Verifying address: "); printf("Verifying address: ");
while (i++ < total_size) { while (i++ < total_size) {
@ -156,6 +157,52 @@ int verify_flash (struct flashchip * flash, char * buf)
return 1; return 1;
} }
// count to a billion. Time it. If it's < 1 sec, count to 10B, etc.
unsigned long micro = 0;
void
myusec_calibrate_delay()
{
unsigned long count = 2 * 1024 * 1024;
volatile unsigned long i;
unsigned long timeusec;
struct timeval start, end;
int ok = 0;
fprintf(stderr, "Setting up microsecond timing loop\n");
while (! ok) {
fprintf(stderr, "Try %d\n", count);
gettimeofday(&start, 0);
for( i = count; i; i--)
;
gettimeofday(&end, 0);
timeusec = 1000000 * (end.tv_sec - start.tv_sec ) +
(end.tv_usec - start.tv_usec);
fprintf(stderr, "timeusec is %d\n", timeusec);
count *= 10;
if (timeusec < 1000000)
continue;
ok = 1;
}
// compute one microsecond. That will be count / time
micro = count / timeusec;
fprintf(stderr, "one us is %d count\n", micro);
}
void
myusec_delay(time)
{
volatile unsigned long i;
for(i = 0; i < time * micro; i++)
;
}
main (int argc, char * argv[]) main (int argc, char * argv[])
{ {
char * buf; char * buf;
@ -163,20 +210,20 @@ main (int argc, char * argv[])
FILE * image; FILE * image;
struct flashchip * flash; struct flashchip * flash;
myusec_calibrate_delay();
if (argc > 2){ if (argc > 2){
printf("usage: %s [romimage]\n", argv[0]); printf("usage: %s [romimage]\n", argv[0]);
printf(" If no romimage is specified, then all that happens\n"); printf(" If no romimage is specified, then all that happens\n");
printf(" is that flash writes are enabled (useful for DoC)\n"); printf(" is that flash info is dumped\n");
exit(1);
} }
enable_flash_sis630 ();
if ((flash = probe_flash (flashchips)) == NULL) { if ((flash = probe_flash (flashchips)) == NULL) {
printf("EEPROM not found\n"); printf("EEPROM not found\n");
exit(1); exit(1);
} }
printf("Part is %s\n", flash->name);
if (argc < 2){ if (argc < 2){
printf("OK, only ENABLING flash write, but NOT FLASHING\n"); printf("OK, only ENABLING flash write, but NOT FLASHING\n");
exit(0); exit(0);

41
jedec.c
View File

@ -29,24 +29,25 @@
int probe_jedec (struct flashchip * flash) int probe_jedec (struct flashchip * flash)
{ {
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
unsigned char id1, id2; unsigned char id1, id2;
*(char *) (bios + 0x5555) = 0xAA; *(volatile char *) (bios + 0x5555) = 0xAA;
*(char *) (bios + 0x2AAA) = 0x55; *(volatile char *) (bios + 0x2AAA) = 0x55;
*(char *) (bios + 0x5555) = 0x90; *(volatile char *) (bios + 0x5555) = 0x90;
usleep(10); myusec_delay(10);
id1 = *(unsigned char *) bios; id1 = *(volatile unsigned char *) bios;
id2 = *(unsigned char *) (bios + 0x01); id2 = *(volatile unsigned char *) (bios + 0x01);
*(char *) (bios + 0x5555) = 0xAA; *(volatile char *) (bios + 0x5555) = 0xAA;
*(char *) (bios + 0x2AAA) = 0x55; *(volatile char *) (bios + 0x2AAA) = 0x55;
*(char *) (bios + 0x5555) = 0xF0; *(volatile char *) (bios + 0x5555) = 0xF0;
usleep(10); myusec_delay(10);
printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2);
if (id1 == flash->manufacture_id && id2 == flash->model_id) if (id1 == flash->manufacture_id && id2 == flash->model_id)
return 1; return 1;
@ -55,17 +56,17 @@ int probe_jedec (struct flashchip * flash)
int erase_jedec (struct flashchip * flash) int erase_jedec (struct flashchip * flash)
{ {
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
*(char *) (bios + 0x5555) = 0xAA; *(volatile char *) (bios + 0x5555) = 0xAA;
*(char *) (bios + 0x2AAA) = 0x55; *(volatile char *) (bios + 0x2AAA) = 0x55;
*(char *) (bios + 0x5555) = 0x80; *(volatile char *) (bios + 0x5555) = 0x80;
*(char *) (bios + 0x5555) = 0xAA; *(volatile char *) (bios + 0x5555) = 0xAA;
*(char *) (bios + 0x2AAA) = 0x55; *(volatile char *) (bios + 0x2AAA) = 0x55;
*(char *) (bios + 0x5555) = 0x10; *(volatile char *) (bios + 0x5555) = 0x10;
usleep(10); myusec_delay(10);
toggle_ready_jedec(bios); toggle_ready_jedec(bios);
} }
@ -73,7 +74,7 @@ int write_jedec (struct flashchip * flash, char * buf)
{ {
int i; 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;
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
erase_jedec (flash); erase_jedec (flash);
printf ("Programming Page: "); printf ("Programming Page: ");

20
jedec.h
View File

@ -2,7 +2,7 @@ extern int probe_jedec (struct flashchip * flash);
extern int erase_jedec (struct flashchip * flash); extern int erase_jedec (struct flashchip * flash);
extern int write_jedec (struct flashchip * flash, char * buf); extern int write_jedec (struct flashchip * flash, char * buf);
extern __inline__ void toggle_ready_jedec (char * dst) extern __inline__ void toggle_ready_jedec (volatile char * dst)
{ {
unsigned int i = 0; unsigned int i = 0;
char tmp1, tmp2; char tmp1, tmp2;
@ -18,7 +18,7 @@ extern __inline__ void toggle_ready_jedec (char * dst)
} }
} }
extern __inline__ void data_polling_jedec (char * dst, char data) extern __inline__ void data_polling_jedec (volatile char * dst, char data)
{ {
unsigned int i = 0; unsigned int i = 0;
char tmp; char tmp;
@ -33,23 +33,23 @@ extern __inline__ void data_polling_jedec (char * dst, char data)
} }
} }
extern __inline__ void protect_jedec (char * bios) extern __inline__ void protect_jedec (volatile char * bios)
{ {
*(char *) (bios + 0x5555) = 0xAA; *(volatile char *) (bios + 0x5555) = 0xAA;
*(char *) (bios + 0x2AAA) = 0x55; *(volatile char *) (bios + 0x2AAA) = 0x55;
*(char *) (bios + 0x5555) = 0xA0; *(volatile char *) (bios + 0x5555) = 0xA0;
usleep(200); usleep(200);
} }
extern __inline__ void write_page_jedec (char * bios, char * src, char * dst, extern __inline__ void write_page_jedec (volatile char * bios, char * src, volatile char * dst,
int page_size) int page_size)
{ {
int i; int i;
*(char *) (bios + 0x5555) = 0xAA; *(volatile char *) (bios + 0x5555) = 0xAA;
*(char *) (bios + 0x2AAA) = 0x55; *(volatile char *) (bios + 0x2AAA) = 0x55;
*(char *) (bios + 0x5555) = 0xA0; *(volatile char *) (bios + 0x5555) = 0xA0;
for (i = 0; i < page_size; i++) { for (i = 0; i < page_size; i++) {
/* transfer data from source to destination */ /* transfer data from source to destination */

View File

@ -30,20 +30,21 @@
int probe_29f002 (struct flashchip * flash) int probe_29f002 (struct flashchip * flash)
{ {
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
unsigned char id1, id2, id3; unsigned char id1, id2, id3;
*(bios + 0x5555) = 0xAA; *(bios + 0x5555) = 0xAA;
*(bios + 0x2AAA) = 0x55; *(bios + 0x2AAA) = 0x55;
*(bios + 0x5555) = 0x90; *(bios + 0x5555) = 0x90;
id1 = *(unsigned char *) bios; id1 = *(volatile unsigned char *) bios;
id2 = *(unsigned char *) (bios + 0x01); id2 = *(volatile unsigned char *) (bios + 0x01);
*bios = 0xF0; *bios = 0xF0;
usleep(10); myusec_delay(10);
printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2);
if (id1 == flash->manufacture_id && id2 == flash->model_id) if (id1 == flash->manufacture_id && id2 == flash->model_id)
return 1; return 1;
@ -52,7 +53,7 @@ int probe_29f002 (struct flashchip * flash)
int erase_29f002 (struct flashchip * flash) int erase_29f002 (struct flashchip * flash)
{ {
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
again: again:
*(bios + 0x555) = 0xF0; *(bios + 0x555) = 0xF0;
@ -63,7 +64,7 @@ int erase_29f002 (struct flashchip * flash)
*(bios + 0x2AA) = 0x55; *(bios + 0x2AA) = 0x55;
*(bios + 0x555) = 0x10; *(bios + 0x555) = 0x10;
usleep(100); myusec_delay(100);
toggle_ready_jedec(bios); toggle_ready_jedec(bios);
// while ((*bios & 0x40) != 0x40) // while ((*bios & 0x40) != 0x40)
@ -85,11 +86,11 @@ int write_29f002 (struct flashchip * flash, char * buf)
{ {
int i; 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;
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
char * dst = bios, * src = buf; volatile char * dst = bios, * src = buf;
*bios = 0xF0; *bios = 0xF0;
usleep(10); myusec_delay(10);
erase_29f002(flash); erase_29f002(flash);
//*bios = 0xF0; //*bios = 0xF0;
#if 1 #if 1

View File

@ -35,35 +35,35 @@
#define RESET 0xFF #define RESET 0xFF
#define READ_ID 0x90 #define READ_ID 0x90
static __inline__ void protect_28sf040 (char * bios) static __inline__ void protect_28sf040 (volatile char * bios)
{ {
/* ask compiler not to optimize this */ /* ask compiler not to optimize this */
volatile unsigned char tmp; volatile unsigned char tmp;
tmp = *(unsigned char *) (bios + 0x1823); tmp = *(volatile unsigned char *) (bios + 0x1823);
tmp = *(unsigned char *) (bios + 0x1820); tmp = *(volatile unsigned char *) (bios + 0x1820);
tmp = *(unsigned char *) (bios + 0x1822); tmp = *(volatile unsigned char *) (bios + 0x1822);
tmp = *(unsigned char *) (bios + 0x0418); tmp = *(volatile unsigned char *) (bios + 0x0418);
tmp = *(unsigned char *) (bios + 0x041B); tmp = *(volatile unsigned char *) (bios + 0x041B);
tmp = *(unsigned char *) (bios + 0x0419); tmp = *(volatile unsigned char *) (bios + 0x0419);
tmp = *(unsigned char *) (bios + 0x040A); tmp = *(volatile unsigned char *) (bios + 0x040A);
} }
static __inline__ void unprotect_28sf040 (char * bios) static __inline__ void unprotect_28sf040 (volatile char * bios)
{ {
/* ask compiler not to optimize this */ /* ask compiler not to optimize this */
volatile unsigned char tmp; volatile unsigned char tmp;
tmp = *(unsigned char *) (bios + 0x1823); tmp = *(volatile unsigned char *) (bios + 0x1823);
tmp = *(unsigned char *) (bios + 0x1820); tmp = *(volatile unsigned char *) (bios + 0x1820);
tmp = *(unsigned char *) (bios + 0x1822); tmp = *(volatile unsigned char *) (bios + 0x1822);
tmp = *(unsigned char *) (bios + 0x0418); tmp = *(volatile unsigned char *) (bios + 0x0418);
tmp = *(unsigned char *) (bios + 0x041B); tmp = *(volatile unsigned char *) (bios + 0x041B);
tmp = *(unsigned char *) (bios + 0x0419); tmp = *(volatile unsigned char *) (bios + 0x0419);
tmp = *(unsigned char *) (bios + 0x041A); tmp = *(volatile unsigned char *) (bios + 0x041A);
} }
static __inline__ erase_sector_28sf040 (char * bios, unsigned long address) static __inline__ erase_sector_28sf040 (volatile char * bios, unsigned long address)
{ {
*bios = AUTO_PG_ERASE1; *bios = AUTO_PG_ERASE1;
*(bios + address) = AUTO_PG_ERASE2; *(bios + address) = AUTO_PG_ERASE2;
@ -72,8 +72,8 @@ static __inline__ erase_sector_28sf040 (char * bios, unsigned long address)
toggle_ready_jedec(bios); toggle_ready_jedec(bios);
} }
static __inline__ write_sector_28sf040(char * bios, unsigned char * src, static __inline__ write_sector_28sf040(volatile char * bios, unsigned char * src,
unsigned char * dst, unsigned int page_size) volatile unsigned char * dst, unsigned int page_size)
{ {
int i; int i;
@ -95,24 +95,25 @@ static __inline__ write_sector_28sf040(char * bios, unsigned char * src,
int probe_28sf040 (struct flashchip * flash) int probe_28sf040 (struct flashchip * flash)
{ {
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
unsigned char id1, id2, tmp; unsigned char id1, id2, tmp;
/* save the value at the beginning of the Flash */ /* save the value at the beginning of the Flash */
tmp = *bios; tmp = *bios;
*bios = RESET; *bios = RESET;
usleep(10); myusec_delay(10);
*bios = READ_ID; *bios = READ_ID;
usleep(10); myusec_delay(10);
id1 = *(unsigned char *) bios; id1 = *(volatile unsigned char *) bios;
usleep(10); myusec_delay(10);
id2 = *(unsigned char *) (bios + 0x01); id2 = *(volatile unsigned char *) (bios + 0x01);
*bios = RESET; *bios = RESET;
usleep(10); myusec_delay(10);
printf(__FUNCTION__ "id1 %d, id2 %d\n", id1, id2);
if (id1 == flash->manufacture_id && id2 == flash->model_id) if (id1 == flash->manufacture_id && id2 == flash->model_id)
return 1; return 1;
@ -123,14 +124,14 @@ int probe_28sf040 (struct flashchip * flash)
int erase_28sf040 (struct flashchip * flash) int erase_28sf040 (struct flashchip * flash)
{ {
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
unprotect_28sf040 (bios); unprotect_28sf040 (bios);
*bios = CHIP_ERASE; *bios = CHIP_ERASE;
*bios = CHIP_ERASE; *bios = CHIP_ERASE;
protect_28sf040 (bios); protect_28sf040 (bios);
usleep(10); myusec_delay(10);
toggle_ready_jedec(bios); toggle_ready_jedec(bios);
} }
@ -138,7 +139,7 @@ int write_28sf040 (struct flashchip * flash, char * buf)
{ {
int i; 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;
char * bios = flash->virt_addr; volatile char * bios = flash->virt_addr;
unprotect_28sf040 (bios); unprotect_28sf040 (bios);