diff --git a/jtag/libbrux/flash/amd_flash.c b/jtag/libbrux/flash/amd_flash.c index 5a26a277..96e68b1b 100644 --- a/jtag/libbrux/flash/amd_flash.c +++ b/jtag/libbrux/flash/amd_flash.c @@ -70,7 +70,7 @@ forced_detection_t var_forced_detection; -int amd_detect(bus_t *bus, cfi_array_t **cfi_array ); +int amd_detect(bus_t *bus, uint32_t adr, cfi_array_t **cfi_array ); static int amd_29xx040_autodetect( cfi_array_t *cfi_array ); static int amd_29xx040_status( bus_t *bus, uint32_t adr, unsigned short data ); static void amd_29xx040_print_info( cfi_array_t *cfi_array ); @@ -79,20 +79,20 @@ static int amd_29xx040_erase_block( cfi_array_t *cfi_array, uint32_t adr ); static int amd_29xx040_program( cfi_array_t *cfi_array, uint32_t adr, uint32_t data ); static int amd_29xx040_unlock_block( cfi_array_t *cfi_array, uint32_t adr ); -int amd_detect(bus_t *bus, cfi_array_t **cfi_array ) +int amd_detect(bus_t *bus, uint32_t adr, cfi_array_t **cfi_array ) { int mid; int did; bus_area_t area; cfi_query_structure_t *cfi ; - bus_write( bus, 0x0, 0xf0 ); - bus_write( bus, 0x555, 0xaa ); - bus_write( bus, 0x2AA, 0x55 ); - bus_write( bus, 0x555, 0x90 ); - mid = bus_read( bus, 0x0); - did = bus_read( bus, 0x1); - bus_write( bus, 0x0, 0xf0 ); + bus_write( bus, adr+0x0, 0xf0 ); + bus_write( bus, adr+0x555, 0xaa ); + bus_write( bus, adr+0x2AA, 0x55 ); + bus_write( bus, adr+0x555, 0x90 ); + mid = bus_read( bus, adr+0x0); + did = bus_read( bus, adr+0x1); + bus_write( bus, adr+0x0, 0xf0 ); printf( "%s: mid %x, did %x\n", __FUNCTION__, mid, did ); if (mid != 0x01) @@ -117,7 +117,7 @@ int amd_detect(bus_t *bus, cfi_array_t **cfi_array ) (*cfi_array)->bus = bus; (*cfi_array)->address = 0; - if (bus_area( bus, 0, &area ) != 0) + if (bus_area( bus, adr+0, &area ) != 0) return -8; /* bus width detection failed */ unsigned int bw = area.width; int ba,i; @@ -204,14 +204,14 @@ static void amd_29xx040_print_info( cfi_array_t *cfi_array ) bus_t *bus = cfi_array->bus; - bus_write( bus, 0x0, 0xf0 ); - bus_write( bus, 0x555, 0xaa ); - bus_write( bus, 0x2AA, 0x55 ); - bus_write( bus, 0x555, 0x90 ); - mid = bus_read( bus, 0x0); - did = bus_read( bus, 0x1); - prot = bus_read( bus, 0x2); - bus_write( bus, 0x0, 0xf0 ); + bus_write( bus, cfi_array->address + 0x0, 0xf0 ); + bus_write( bus, cfi_array->address + 0x555, 0xaa ); + bus_write( bus, cfi_array->address + 0x2AA, 0x55 ); + bus_write( bus, cfi_array->address + 0x555, 0x90 ); + mid = bus_read( bus, cfi_array->address + 0x0); + did = bus_read( bus, cfi_array->address + 0x1); + prot = bus_read( bus, cfi_array->address + 0x2); + bus_write( bus, cfi_array->address + 0x0, 0xf0 ); printf( "%s: mid %x, did %x\n", __FUNCTION__, mid, did ); // amd_29xx040_read_array( cfi_array ); /* AMD reset */ @@ -247,12 +247,12 @@ static void amd_29xx040_read_array( cfi_array_t *cfi_array ) /* Read Array */ if(var_forced_detection.unlock_bypass == AMD_BYPASS_UNLOCK_MODE) { - bus_write( bus, 0x555, 0x90 ); - bus_write( bus, 0x2AA, 0x00 ); + bus_write( bus, cfi_array->address + 0x555, 0x90 ); + bus_write( bus, cfi_array->address + 0x2AA, 0x00 ); usleep(100); var_forced_detection.unlock_bypass = AMD_STANDARD_MODE; } - bus_write( cfi_array->bus, 0x0, 0x0F0 ); /* AMD reset */ + bus_write( cfi_array->bus, cfi_array->address + 0x0, 0x0F0 ); /* AMD reset */ } @@ -267,19 +267,19 @@ static int amd_29xx040_erase_block( cfi_array_t *cfi_array, uint32_t adr ) if(var_forced_detection.unlock_bypass == AMD_BYPASS_UNLOCK_MODE) { - bus_write( bus, 0x555, 0x90 ); - bus_write( bus, 0x2AA, 0x00 ); + bus_write( bus, cfi_array->address + 0x555, 0x90 ); + bus_write( bus, cfi_array->address + 0x2AA, 0x00 ); usleep(100); var_forced_detection.unlock_bypass = AMD_STANDARD_MODE; } - bus_write( bus, 0x0, 0xf0 ); - bus_write( bus, 0x555, 0xaa ); - bus_write( bus, 0x2AA, 0x55 ); - bus_write( bus, 0x555, 0x80 ); - bus_write( bus, 0x555, 0xaa ); - bus_write( bus, 0x2AA, 0x55 ); -// bus_write( bus, 0x555, 0x10 ); //Chip Erase + bus_write( bus, cfi_array->address + 0x0, 0xf0 ); + bus_write( bus, cfi_array->address + 0x555, 0xaa ); + bus_write( bus, cfi_array->address + 0x2AA, 0x55 ); + bus_write( bus, cfi_array->address + 0x555, 0x80 ); + bus_write( bus, cfi_array->address + 0x555, 0xaa ); + bus_write( bus, cfi_array->address + 0x2AA, 0x55 ); +// bus_write( bus, cfi_array->address + 0x555, 0x10 ); //Chip Erase bus_write( bus, adr, 0x30 ); //Sector erase @@ -306,20 +306,20 @@ static int amd_29xx040_program( cfi_array_t *cfi_array, uint32_t adr, uint32_t d { if(var_forced_detection.unlock_bypass != AMD_BYPASS_UNLOCK_MODE) { - bus_write( bus, 0x555, 0xaa ); - bus_write( bus, 0x2AA, 0x55 ); - bus_write( bus, 0x555, 0x20 ); + bus_write( bus, cfi_array->address + 0x555, 0xaa ); + bus_write( bus, cfi_array->address + 0x2AA, 0x55 ); + bus_write( bus, cfi_array->address + 0x555, 0x20 ); usleep(1000); var_forced_detection.unlock_bypass = AMD_BYPASS_UNLOCK_MODE; } } else { - bus_write( bus, 0x555, 0xaa ); - bus_write( bus, 0x2AA, 0x55 ); + bus_write( bus, cfi_array->address + 0x555, 0xaa ); + bus_write( bus, cfi_array->address + 0x2AA, 0x55 ); } - bus_write( bus, 0x555, 0xA0 ); + bus_write( bus, cfi_array->address + 0x555, 0xA0 ); bus_write( bus, adr, data ); status = amd_29xx040_status( bus, adr, data ); /* amd_29xx040_read_array(cfi_array); */ diff --git a/jtag/libbrux/flash/detectflash.c b/jtag/libbrux/flash/detectflash.c index e8276315..62345347 100644 --- a/jtag/libbrux/flash/detectflash.c +++ b/jtag/libbrux/flash/detectflash.c @@ -42,9 +42,9 @@ cfi_array_t *cfi_array = NULL; -int jedec_detect( bus_t *bus, uint32_t adr, cfi_array_t **cfi_array ); +extern int jedec_detect( bus_t *bus, uint32_t adr, cfi_array_t **cfi_array ); -extern int amd_detect(bus_t *bus, cfi_array_t **cfi_array ); //Ajith +extern int amd_detect(bus_t *bus, uint32_t adr, cfi_array_t **cfi_array ); //Ajith void detectflash( bus_t *bus, uint32_t adr ) @@ -67,7 +67,7 @@ detectflash( bus_t *bus, uint32_t adr ) cfi_array = NULL; if (jedec_detect( bus, adr, &cfi_array ) != 0) { cfi_array_free( cfi_array ); - if(amd_detect(bus, &cfi_array ) != 0) + if(amd_detect(bus, adr, &cfi_array ) != 0) { cfi_array_free( cfi_array ); cfi_array->bus_width = 1;