diff options
-rw-r--r-- | src/flash/ecos.c | 8 | ||||
-rw-r--r-- | src/flash/flash.c | 54 | ||||
-rw-r--r-- | src/flash/flash.h | 1 | ||||
-rw-r--r-- | src/flash/str7x.c | 45 | ||||
-rw-r--r-- | src/flash/str9x.c | 46 |
5 files changed, 57 insertions, 97 deletions
diff --git a/src/flash/ecos.c b/src/flash/ecos.c index 55e54e05..f467b74d 100644 --- a/src/flash/ecos.c +++ b/src/flash/ecos.c @@ -45,7 +45,6 @@ int ecosflash_erase(struct flash_bank_s *bank, int first, int last); int ecosflash_protect(struct flash_bank_s *bank, int set, int first, int last); int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count); int ecosflash_probe(struct flash_bank_s *bank); -int ecosflash_erase_check(struct flash_bank_s *bank); int ecosflash_protect_check(struct flash_bank_s *bank); int ecosflash_info(struct flash_bank_s *bank, char *buf, int buf_size); @@ -64,7 +63,7 @@ flash_driver_t ecosflash_flash = .write = ecosflash_write, .probe = ecosflash_probe, .auto_probe = ecosflash_probe, - .erase_check = ecosflash_erase_check, + .erase_check = default_flash_blank_check, .protect_check = ecosflash_protect_check, .info = ecosflash_info }; @@ -444,11 +443,6 @@ int ecosflash_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count } -int ecosflash_erase_check(struct flash_bank_s *bank) -{ - return ERROR_OK; -} - int ecosflash_protect_check(struct flash_bank_s *bank) { return ERROR_OK; diff --git a/src/flash/flash.c b/src/flash/flash.c index a0c89841..d5159b97 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -334,7 +334,11 @@ int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char char buf[1024]; /* attempt auto probe */ - p->driver->auto_probe(p); + if ((retval = p->driver->auto_probe(p)) != ERROR_OK) + return retval; + + if ((retval = p->driver->erase_check(p)) != ERROR_OK) + return retval; command_print(cmd_ctx, "#%i: %s at 0x%8.8x, size 0x%8.8x, buswidth %i, chipwidth %i", i, p->driver->name, p->base, p->size, p->bus_width, p->chip_width); @@ -1049,3 +1053,51 @@ int handle_flash_auto_erase_command(struct command_context_s *cmd_ctx, char *cmd return ERROR_OK; } + + +int default_flash_blank_check(struct flash_bank_s *bank) +{ + target_t *target = bank->target; + u8 buffer[1024]; + int buffer_size=sizeof(buffer); + int i; + int nBytes; + + if (bank->target->state != TARGET_HALTED) + { + return ERROR_TARGET_NOT_HALTED; + } + + + for (i = 0; i < bank->num_sectors; i++) + { + int j; + bank->sectors[i].is_erased = 1; + + for (j=0; j<bank->sectors[i].size; j+=buffer_size) + { + int chunk; + int retval; + chunk=buffer_size; + if (chunk>(j-bank->sectors[i].size)) + { + chunk=(j-bank->sectors[i].size); + } + + retval=target->type->read_memory(target, bank->base + bank->sectors[i].offset, 4, chunk/4, buffer); + if (retval!=ERROR_OK) + return retval; + + for (nBytes = 0; nBytes < chunk; nBytes++) + { + if (buffer[nBytes] != 0xFF) + { + bank->sectors[i].is_erased = 0; + break; + } + } + } + } + + return ERROR_OK; +} diff --git a/src/flash/flash.h b/src/flash/flash.h index 846ddc4b..e2f78855 100644 --- a/src/flash/flash.h +++ b/src/flash/flash.h @@ -78,6 +78,7 @@ extern int flash_erase_address_range(target_t *target, u32 addr, u32 length); extern int flash_write(target_t *target, image_t *image, u32 *written, int erase); extern void flash_set_dirty(void); extern int flash_get_bank_count(); +int default_flash_blank_check(struct flash_bank_s *bank); extern flash_bank_t *get_flash_bank_by_num(int num); extern flash_bank_t *get_flash_bank_by_num_noprobe(int num); diff --git a/src/flash/str7x.c b/src/flash/str7x.c index c7a486e2..70f312d3 100644 --- a/src/flash/str7x.c +++ b/src/flash/str7x.c @@ -56,7 +56,6 @@ int str7x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count); int str7x_probe(struct flash_bank_s *bank); int str7x_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int str7x_protect_check(struct flash_bank_s *bank); -int str7x_erase_check(struct flash_bank_s *bank); int str7x_info(struct flash_bank_s *bank, char *buf, int buf_size); int str7x_handle_disable_jtag_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); @@ -71,7 +70,7 @@ flash_driver_t str7x_flash = .write = str7x_write, .probe = str7x_probe, .auto_probe = str7x_probe, - .erase_check = str7x_erase_check, + .erase_check = default_flash_blank_check, .protect_check = str7x_protect_check, .info = str7x_info }; @@ -240,43 +239,6 @@ u32 str7x_result(struct flash_bank_s *bank) return retval; } -int str7x_blank_check(struct flash_bank_s *bank, int first, int last) -{ - target_t *target = bank->target; - u8 *buffer; - int i; - int nBytes; - - if ((first < 0) || (last > bank->num_sectors)) - return ERROR_FLASH_SECTOR_INVALID; - - if (bank->target->state != TARGET_HALTED) - { - return ERROR_TARGET_NOT_HALTED; - } - - buffer = malloc(256); - - for (i = first; i <= last; i++) - { - bank->sectors[i].is_erased = 1; - - target->type->read_memory(target, bank->base + bank->sectors[i].offset, 4, 256/4, buffer); - - for (nBytes = 0; nBytes < 256; nBytes++) - { - if (buffer[nBytes] != 0xFF) - { - bank->sectors[i].is_erased = 0; - break; - } - } - } - - free(buffer); - - return ERROR_OK; -} int str7x_protect_check(struct flash_bank_s *bank) { @@ -729,11 +691,6 @@ int str7x_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, c return ERROR_OK; } -int str7x_erase_check(struct flash_bank_s *bank) -{ - return str7x_blank_check(bank, 0, bank->num_sectors - 1); -} - int str7x_info(struct flash_bank_s *bank, char *buf, int buf_size) { snprintf(buf, buf_size, "str7x flash driver info" ); diff --git a/src/flash/str9x.c b/src/flash/str9x.c index bd823820..68fefc1b 100644 --- a/src/flash/str9x.c +++ b/src/flash/str9x.c @@ -64,7 +64,6 @@ int str9x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count); int str9x_probe(struct flash_bank_s *bank); int str9x_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); int str9x_protect_check(struct flash_bank_s *bank); -int str9x_erase_check(struct flash_bank_s *bank); int str9x_info(struct flash_bank_s *bank, char *buf, int buf_size); int str9x_handle_flash_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); @@ -79,7 +78,7 @@ flash_driver_t str9x_flash = .write = str9x_write, .probe = str9x_probe, .auto_probe = str9x_probe, - .erase_check = str9x_erase_check, + .erase_check = default_flash_blank_check, .protect_check = str9x_protect_check, .info = str9x_info }; @@ -170,44 +169,6 @@ int str9x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char return ERROR_OK; } -int str9x_blank_check(struct flash_bank_s *bank, int first, int last) -{ - target_t *target = bank->target; - u8 *buffer; - int i; - int nBytes; - - if ((first < 0) || (last > bank->num_sectors)) - return ERROR_FLASH_SECTOR_INVALID; - - if (bank->target->state != TARGET_HALTED) - { - return ERROR_TARGET_NOT_HALTED; - } - - buffer = malloc(256); - - for (i = first; i <= last; i++) - { - bank->sectors[i].is_erased = 1; - - target->type->read_memory(target, bank->base + bank->sectors[i].offset, 4, 256/4, buffer); - - for (nBytes = 0; nBytes < 256; nBytes++) - { - if (buffer[nBytes] != 0xFF) - { - bank->sectors[i].is_erased = 0; - break; - } - } - } - - free(buffer); - - return ERROR_OK; -} - int str9x_protect_check(struct flash_bank_s *bank) { str9x_flash_bank_t *str9x_info = bank->driver_priv; @@ -581,11 +542,6 @@ int str9x_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, c return ERROR_OK; } -int str9x_erase_check(struct flash_bank_s *bank) -{ - return str9x_blank_check(bank, 0, bank->num_sectors - 1); -} - int str9x_info(struct flash_bank_s *bank, char *buf, int buf_size) { snprintf(buf, buf_size, "str9x flash driver info" ); |