diff options
| author | Ronald G. Minnich <rminnich@gmail.com> | 2002-01-29 20:18:02 +0000 | 
|---|---|---|
| committer | Ronald G. Minnich <rminnich@gmail.com> | 2002-01-29 20:18:02 +0000 | 
| commit | ef5779d1ddee6b83dfe04ff343e4b7d290fd24d7 (patch) | |
| tree | 4e9514f6bc1d73b14490747d1d18ab1ef9e7b6fa | |
| parent | f4cf2baec9ba699c7e7387de7fd528fca06b25d6 (diff) | |
| download | flashrom-ef5779d1ddee6b83dfe04ff343e4b7d290fd24d7.tar.gz flashrom-ef5779d1ddee6b83dfe04ff343e4b7d290fd24d7.tar.bz2 flashrom-ef5779d1ddee6b83dfe04ff343e4b7d290fd24d7.zip | |
Fixes
 - switch to volatile everywhere
 - use myusec_delay instead of usleep
Corresponding to coreboot v1 svn r492.
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | am29f040b.c | 17 | ||||
| -rw-r--r-- | flash.h | 2 | ||||
| -rw-r--r-- | flash_rom.c | 61 | ||||
| -rw-r--r-- | jedec.c | 41 | ||||
| -rw-r--r-- | jedec.h | 20 | ||||
| -rw-r--r-- | mx29f002.c | 19 | ||||
| -rw-r--r-- | sst28sf040.c | 59 | 
8 files changed, 137 insertions, 88 deletions
| @@ -3,9 +3,7 @@ CC = gcc -O2  all: ${OBJS}  	${CC} -o flash_rom flash_rom.c ${OBJS} -	${CC} -o flash_on flash_on.c -	${CC} -o acpi_reset acpi_reset.c -	${CC} -o acpi_shutdown acpi_shutdown.c +#	${CC} -o flash_on flash_on.c  clean: -	rm -f flash_rom flash_on acpi_reset acpi_shutdown *.o *~
\ No newline at end of file +	rm -f flash_rom flash_on *.o *~ diff --git a/am29f040b.c b/am29f040b.c index 121297fc..ceba046f 100644 --- a/am29f040b.c +++ b/am29f040b.c @@ -27,7 +27,7 @@  #include "flash.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 +   0x2AA) = 0x55; @@ -42,8 +42,8 @@ static __inline__ erase_sector_29f040b (char * bios, unsigned long address)  	toggle_ready_jedec(bios + address);  } -static __inline__ write_sector_29f040b(char * bios, unsigned char * src, -				       unsigned char * dst, unsigned int page_size) +static __inline__ write_sector_29f040b(volatile char * bios, unsigned char * src, +				       volatile unsigned char * dst, unsigned int page_size)  {  	int i; @@ -64,7 +64,7 @@ static __inline__ write_sector_29f040b(char * bios, unsigned char * src,  int probe_29f040b (struct flashchip * flash)  { -	char * bios = flash->virt_addr; +	volatile char * bios = flash->virt_addr;  	unsigned char id1, id2;  	*(bios + 0x555) = 0xAA; @@ -76,8 +76,9 @@ int probe_29f040b (struct flashchip * flash)  	*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)  		return 1; @@ -86,7 +87,7 @@ int probe_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 + 0x2AA) = 0x55; @@ -95,7 +96,7 @@ int erase_29f040b (struct flashchip * flash)  	*(bios + 0x2AA) = 0x55;  	*(bios + 0x555) = 0x10; -	usleep(10); +	myusec_delay(10);  	toggle_ready_jedec(bios);  } @@ -103,7 +104,7 @@ int write_29f040b (struct flashchip * flash, char * buf)  {  	int i;  	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: ");  	for (i = 0; i < total_size/page_size; i++) { @@ -6,7 +6,7 @@ struct flashchip {  	int manufacture_id;  	int model_id; -	char * virt_addr; +	volatile char * virt_addr;  	int total_size;  	int page_size; diff --git a/flash_rom.c b/flash_rom.c index 12aa2733..0b7b768f 100644 --- a/flash_rom.c +++ b/flash_rom.c @@ -109,7 +109,7 @@ int enable_flash_sis630 (void)  struct flashchip * probe_flash(struct flashchip * flash)  {      int fd_mem; -    char * bios; +    volatile char * bios;      unsigned long size;      if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) { @@ -118,6 +118,7 @@ struct flashchip * probe_flash(struct flashchip * flash)      }      while (flash->name != NULL) { +	printf("Trying %s, %d KB\n", flash->name, flash->total_size);  	size = flash->total_size * 1024;  	bios = mmap (0, size, PROT_WRITE | PROT_READ, MAP_SHARED,  		     fd_mem, (off_t) (0 - size)); @@ -132,7 +133,7 @@ struct flashchip * probe_flash(struct flashchip * flash)  		    flash->name, (0 - size), bios);  	    return flash;  	} -	munmap (bios, size); +	munmap ((void *) bios, size);  	flash++;      }      return NULL; @@ -142,7 +143,7 @@ int verify_flash (struct flashchip * flash, char * buf)  {      int i = 0;      int total_size = flash->total_size *1024; -    char * bios = flash->virt_addr; +    volatile char * bios = flash->virt_addr;      printf("Verifying address: ");      while (i++ < total_size) { @@ -156,6 +157,52 @@ int verify_flash (struct flashchip * flash, char * buf)      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[])  {      char * buf; @@ -163,20 +210,20 @@ main (int argc, char * argv[])      FILE * image;      struct flashchip * flash; +    myusec_calibrate_delay(); +      if (argc > 2){  	printf("usage: %s [romimage]\n", argv[0]);  	printf(" If no romimage is specified, then all that happens\n"); -	printf(" is that flash writes are enabled (useful for DoC)\n"); -	exit(1); +	printf(" is that flash info is dumped\n");      } -    enable_flash_sis630 (); -      if ((flash = probe_flash (flashchips)) == NULL) {  	printf("EEPROM not found\n");  	exit(1);      } +    printf("Part is %s\n", flash->name);      if (argc < 2){  	printf("OK, only ENABLING flash write, but NOT FLASHING\n");          exit(0); @@ -29,24 +29,25 @@  int probe_jedec (struct flashchip * flash)  { -	char * bios = flash->virt_addr; +	volatile char * bios = flash->virt_addr;  	unsigned char  id1, id2; -	*(char *) (bios + 0x5555) = 0xAA; -	*(char *) (bios + 0x2AAA) = 0x55; -	*(char *) (bios + 0x5555) = 0x90; +	*(volatile char *) (bios + 0x5555) = 0xAA; +	*(volatile char *) (bios + 0x2AAA) = 0x55; +	*(volatile char *) (bios + 0x5555) = 0x90; -	usleep(10); +	myusec_delay(10); -	id1 = *(unsigned char *) bios; -	id2 = *(unsigned char *) (bios + 0x01); +	id1 = *(volatile unsigned char *) bios; +	id2 = *(volatile unsigned char *) (bios + 0x01); -	*(char *) (bios + 0x5555) = 0xAA; -	*(char *) (bios + 0x2AAA) = 0x55; -	*(char *) (bios + 0x5555) = 0xF0; +	*(volatile char *) (bios + 0x5555) = 0xAA; +	*(volatile char *) (bios + 0x2AAA) = 0x55; +	*(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)  		return 1; @@ -55,17 +56,17 @@ int probe_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; -	*(char *) (bios + 0x2AAA) = 0x55; -	*(char *) (bios + 0x5555) = 0x80; +	*(volatile char *) (bios + 0x5555) = 0xAA; +	*(volatile char *) (bios + 0x2AAA) = 0x55; +	*(volatile char *) (bios + 0x5555) = 0x80; -	*(char *) (bios + 0x5555) = 0xAA; -	*(char *) (bios + 0x2AAA) = 0x55; -	*(char *) (bios + 0x5555) = 0x10; +	*(volatile char *) (bios + 0x5555) = 0xAA; +	*(volatile char *) (bios + 0x2AAA) = 0x55; +	*(volatile char *) (bios + 0x5555) = 0x10; -	usleep(10); +	myusec_delay(10);  	toggle_ready_jedec(bios);  } @@ -73,7 +74,7 @@ int write_jedec (struct flashchip * flash, char * buf)  {  	int i;  	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);  	printf ("Programming Page: "); @@ -2,7 +2,7 @@ extern int probe_jedec (struct flashchip * flash);  extern int erase_jedec (struct flashchip * flash);  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;  	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;  	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; -	*(char *) (bios + 0x2AAA) = 0x55; -	*(char *) (bios + 0x5555) = 0xA0; +	*(volatile char *) (bios + 0x5555) = 0xAA; +	*(volatile char *) (bios + 0x2AAA) = 0x55; +	*(volatile char *) (bios + 0x5555) = 0xA0;  	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 i; -	*(char *) (bios + 0x5555) = 0xAA; -	*(char *) (bios + 0x2AAA) = 0x55; -	*(char *) (bios + 0x5555) = 0xA0; +	*(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 */ @@ -30,20 +30,21 @@  int probe_29f002 (struct flashchip * flash)  { -	char * bios = flash->virt_addr; +	volatile char * bios = flash->virt_addr;  	unsigned char id1, id2, id3;  	*(bios + 0x5555) = 0xAA;  	*(bios + 0x2AAA) = 0x55;  	*(bios + 0x5555) = 0x90; -	id1 = *(unsigned char *) bios; -	id2 = *(unsigned char *) (bios + 0x01); +	id1 = *(volatile unsigned char *) bios; +	id2 = *(volatile unsigned char *) (bios + 0x01);  	*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)  		return 1; @@ -52,7 +53,7 @@ int probe_29f002 (struct flashchip * flash)  int erase_29f002 (struct flashchip * flash)  { -	char * bios = flash->virt_addr; +	volatile char * bios = flash->virt_addr;   again:  	*(bios + 0x555) = 0xF0; @@ -63,7 +64,7 @@ int erase_29f002 (struct flashchip * flash)  	*(bios + 0x2AA) = 0x55;  	*(bios + 0x555) = 0x10; -	usleep(100); +	myusec_delay(100);  	toggle_ready_jedec(bios);  	//   while ((*bios & 0x40) != 0x40) @@ -85,11 +86,11 @@ int write_29f002 (struct flashchip * flash, char * buf)  {      int i;      int total_size = flash->total_size * 1024, page_size = flash->page_size; -    char * bios = flash->virt_addr; -    char * dst = bios, * src = buf; +    volatile char * bios = flash->virt_addr; +    volatile char * dst = bios, * src = buf;      *bios = 0xF0; -    usleep(10); +    myusec_delay(10);      erase_29f002(flash);      //*bios = 0xF0;  #if 1 diff --git a/sst28sf040.c b/sst28sf040.c index e0e5ea32..4042e8bf 100644 --- a/sst28sf040.c +++ b/sst28sf040.c @@ -35,35 +35,35 @@  #define RESET			0xFF  #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 */  	volatile unsigned char tmp; -	tmp = *(unsigned char *) (bios + 0x1823); -	tmp = *(unsigned char *) (bios + 0x1820); -	tmp = *(unsigned char *) (bios + 0x1822); -	tmp = *(unsigned char *) (bios + 0x0418); -	tmp = *(unsigned char *) (bios + 0x041B); -	tmp = *(unsigned char *) (bios + 0x0419); -	tmp = *(unsigned char *) (bios + 0x040A); +	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 (char * bios) +static __inline__ void unprotect_28sf040 (volatile char * bios)  {  	/* ask compiler not to optimize this */  	volatile unsigned char tmp; -	tmp = *(unsigned char *) (bios + 0x1823); -	tmp = *(unsigned char *) (bios + 0x1820); -	tmp = *(unsigned char *) (bios + 0x1822); -	tmp = *(unsigned char *) (bios + 0x0418); -	tmp = *(unsigned char *) (bios + 0x041B); -	tmp = *(unsigned char *) (bios + 0x0419); -	tmp = *(unsigned char *) (bios + 0x041A); +	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__ erase_sector_28sf040 (char * bios, unsigned long address) +static __inline__ erase_sector_28sf040 (volatile char * bios, unsigned long address)  {  	*bios = AUTO_PG_ERASE1;  	*(bios + address) = AUTO_PG_ERASE2; @@ -72,8 +72,8 @@ static __inline__ erase_sector_28sf040 (char * bios, unsigned long address)  	toggle_ready_jedec(bios);  } -static __inline__ write_sector_28sf040(char * bios, unsigned char * src, -				       unsigned char * dst, unsigned int page_size) +static __inline__ write_sector_28sf040(volatile char * bios, unsigned char * src, +				       volatile unsigned char * dst, unsigned int page_size)  {  	int i; @@ -95,24 +95,25 @@ static __inline__ write_sector_28sf040(char * bios, unsigned char * src,  int probe_28sf040 (struct flashchip * flash)  { -	char * bios = flash->virt_addr; +	volatile char * bios = flash->virt_addr;  	unsigned char  id1, id2, tmp;  	/* save the value at the beginning of the Flash */  	tmp = *bios;  	*bios = RESET; -	usleep(10); +	myusec_delay(10);  	*bios = READ_ID; -	usleep(10); -	id1 = *(unsigned char *) bios; -	usleep(10); -	id2 = *(unsigned char *) (bios + 0x01); +	myusec_delay(10); +	id1 = *(volatile unsigned char *) bios; +	myusec_delay(10); +	id2 = *(volatile unsigned char *) (bios + 0x01);  	*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)  		return 1; @@ -123,14 +124,14 @@ int probe_28sf040 (struct flashchip * flash)  int erase_28sf040 (struct flashchip * flash)  { -	char * bios = flash->virt_addr; +	volatile char * bios = flash->virt_addr;  	unprotect_28sf040 (bios);  	*bios = CHIP_ERASE;  	*bios = CHIP_ERASE;  	protect_28sf040 (bios); -	usleep(10); +	myusec_delay(10);  	toggle_ready_jedec(bios);  } @@ -138,7 +139,7 @@ int write_28sf040 (struct flashchip * flash, char * buf)  {  	int i;  	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); | 
