Browse Source

ls2k verify flash by spi_cmp_area.

Change-Id: I9e2854e342993e300206207d0e914383e6c5c85d
Signed-off-by: Chong Qiao <qiaochong@loongson.cn>
master
Chong Qiao 4 years ago
parent
commit
31a2709ce9
  1. 40
      Targets/LS2K/dev/spi_w.c

40
Targets/LS2K/dev/spi_w.c

@ -600,15 +600,17 @@ int spi_write_area(int flashaddr,char *buffer,int size)
}
SET_SPI(SOFTCS,0x11|0xee);
wait_sr();
delay(10);
return 0;
}
#endif
int spi_read_area(int flashaddr,char *buffer,int size)
int spi_read_or_cmp_area(int flashaddr,char *buffer,int size, int cmp)
{
int i;
char data;
spi_initw();
SET_SPI(SOFTCS,0x01|0xee);
@ -635,12 +637,27 @@ int spi_read_area(int flashaddr,char *buffer,int size)
{
SET_SPI(TXFIFO,0);
while((GET_SPI(SPSR))&RFEMPTY);
buffer[i] = GET_SPI(RXFIFO);
data = GET_SPI(RXFIFO);
if (cmp) {
if (buffer[i] != data)
break;
} else
buffer[i] = data;
}
SET_SPI(SOFTCS,0x11|0xee);
delay(10);
return 0;
return i;
}
int spi_read_area(int flashaddr,char *buffer,int size)
{
return spi_read_or_cmp_area( flashaddr, buffer, size, 0);
}
int spi_cmp_area(int flashaddr,char *buffer,int size)
{
return spi_read_or_cmp_area( flashaddr, buffer, size, 1);
}
struct fl_device myflash = {
@ -684,25 +701,22 @@ fl_verify_device(void *fl_base, void *data_base, int data_size, int verbose)
{
struct fl_map *map;
int off;
char *p;
int ok;
int pos;
map = fl_find_map(fl_base);
off = (int)(fl_base - map->fl_map_base) + map->fl_map_offset;
if(verbose) {
printf("Verifying FLASH. ");
}
p = malloc(data_size);
spi_read_area(off,p,data_size);
ok = memcmp(data_base, p, data_size) == 0;
free(p);
pos = spi_cmp_area(off, data_base, data_size);
if(verbose) {
if (ok)
if (pos != data_size)
printf("verfiy error at %d\n", pos);
else
printf("\b No Errors found.\n");
else
printf("\b error, Program failed.\n");
}
spi_initr();
return ok;
return pos != data_size;
}
//---------------------------------------

Loading…
Cancel
Save