diff options
author | ntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-05-27 21:23:47 +0000 |
---|---|---|
committer | ntfreak <ntfreak@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2008-05-27 21:23:47 +0000 |
commit | 938e01d0c3ff4fedf1629cc1c1928af1c90882e9 (patch) | |
tree | c496c2db7f863657643ff3bfb6db3a0bf7659310 /src/flash | |
parent | 506ca886c4d89aabcffab2dfa6736dfcfc1396c5 (diff) | |
download | riscv-openocd-938e01d0c3ff4fedf1629cc1c1928af1c90882e9.zip riscv-openocd-938e01d0c3ff4fedf1629cc1c1928af1c90882e9.tar.gz riscv-openocd-938e01d0c3ff4fedf1629cc1c1928af1c90882e9.tar.bz2 |
- moved flash erase_check target code to target.c
git-svn-id: svn://svn.berlios.de/openocd/trunk@694 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/flash')
-rw-r--r-- | src/flash/flash.c | 258 | ||||
-rw-r--r-- | src/flash/flash.h | 3 | ||||
-rw-r--r-- | src/flash/stellaris.c | 2 | ||||
-rw-r--r-- | src/flash/stm32x.c | 2 |
4 files changed, 56 insertions, 209 deletions
diff --git a/src/flash/flash.c b/src/flash/flash.c index 1e4edd6..91a94db 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -1090,11 +1090,11 @@ int flash_write(target_t *target, image_t *image, u32 *written, int erase) return retval; } -int default_flash_blank_check(struct flash_bank_s *bank) +int default_flash_mem_blank_check(struct flash_bank_s *bank) { target_t *target = bank->target; u8 buffer[1024]; - int buffer_size=sizeof(buffer); + int buffer_size = sizeof(buffer); int i; int nBytes; @@ -1103,227 +1103,73 @@ int default_flash_blank_check(struct flash_bank_s *bank) return ERROR_TARGET_NOT_HALTED; } - int retval; - int fast_check=0; - working_area_t *erase_check_algorithm; -#if 0 - /* FIX! doesn't work yet... */ - /* - char test(char *a, int len, char t) + for (i = 0; i < bank->num_sectors; i++) { - int i=0; - - for (i=0; i<len; i++) + int j; + bank->sectors[i].is_erased = 1; + + for (j = 0; j < bank->sectors[i].size; j += buffer_size) { - t&=a[i]; - + 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 + j, 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; + } + } } } - $ arm-elf-gcc -c -mthumb -O3 test.c - - $ arm-elf-objdump --disassemble test.o - - test.o: file format elf32-littlearm - - Disassembly of section .text: - - 00000000 <test>: - 0: b510 push {r4, lr} - 2: 0612 lsl r2, r2, #24 - 4: 1c04 mov r4, r0 (add r4, r0, #0) - 6: 0e10 lsr r0, r2, #24 - 8: 2200 mov r2, #0 - a: 2900 cmp r1, #0 - c: dd04 ble 18 <test+0x18> - e: 5ca3 ldrb r3, [r4, r2] - 10: 3201 add r2, #1 - 12: 4018 and r0, r3 - 14: 428a cmp r2, r1 - 16: dbfa blt e <test+0xe> - 18: bd10 pop {r4, pc} - 1a: 46c0 nop (mov r8, r8) - - - */ - u16 erase_check_code[] = - { - 0x0612,// lsl r2, r2, #24 - 0x1c04,// mov r4, r0 (add r4, r0, #0) - 0x0e10,// lsr r0, r2, #24 - 0x2200,// mov r2, #0 - 0x2900,// cmp r1, #0 - 0xdd04,// ble 18 <test+0x18> - 0x5ca3,// ldrb r3, [r4, r2] - 0x3201,// add r2, #1 - 0x4018,// and r0, r3 - 0x428a,// cmp r2, r1 - 0xdbfa,// blt e <test+0xe> - 0x46c0,// nop (mov r8, r8) - - }; - + return ERROR_OK; +} +int default_flash_blank_check(struct flash_bank_s *bank) +{ + target_t *target = bank->target; + int i; + int retval; + int fast_check = 0; + int blank; - /* make sure we have a working area */ - if (target_alloc_working_area(target, ((sizeof(erase_check_code)+3)/4)*4, &erase_check_algorithm) != ERROR_OK) + if (bank->target->state != TARGET_HALTED) { - erase_check_algorithm = NULL; + return ERROR_TARGET_NOT_HALTED; } - - if (erase_check_algorithm) - { - u8 erase_check_code_buf[((sizeof(erase_check_code)+3)/4)*4]; - LOG_DEBUG("Running fast flash erase check"); - for (i = 0; i < sizeof(erase_check_code)/sizeof(*erase_check_code); i++) - target_buffer_set_u16(target, erase_check_code_buf + (i*2), erase_check_code[i]); - - /* write algorithm code to working area */ - if ((retval=target->type->write_memory(target, erase_check_algorithm->address, 2, sizeof(erase_check_code)/sizeof(*erase_check_code), erase_check_code_buf))==ERROR_OK) - { - for (i = 0; i < bank->num_sectors; i++) - { - u32 address = bank->base + bank->sectors[i].offset; - u32 size = bank->sectors[i].size; - - reg_param_t reg_params[3]; - armv7m_algorithm_t arm_info; - - arm_info.common_magic = ARMV7M_COMMON_MAGIC; - arm_info.core_mode = ARMV7M_MODE_ANY; - arm_info.core_state = ARMV7M_STATE_THUMB; - - init_reg_param(®_params[0], "r0", 32, PARAM_OUT); - buf_set_u32(reg_params[0].value, 0, 32, address); - - init_reg_param(®_params[1], "r1", 32, PARAM_OUT); - buf_set_u32(reg_params[1].value, 0, 32, size); - - init_reg_param(®_params[2], "r2", 32, PARAM_IN_OUT); - buf_set_u32(reg_params[2].value, 0, 32, 0xff); - - if ((retval = target->type->run_algorithm(target, 0, NULL, 3, reg_params, erase_check_algorithm->address, - erase_check_algorithm->address + sizeof(erase_check_code) - 2, 10000, &arm_info)) != ERROR_OK) - break; - - if (buf_get_u32(reg_params[2].value, 0, 32) == 0xff) - bank->sectors[i].is_erased = 1; - else - bank->sectors[i].is_erased = 0; - - destroy_reg_param(®_params[0]); - destroy_reg_param(®_params[1]); - destroy_reg_param(®_params[2]); - } - if (i == bank->num_sectors) - { - fast_check = 1; - } - } - target_free_working_area(target, erase_check_algorithm); - } -#endif - if (!fast_check) + for (i = 0; i < bank->num_sectors; i++) { - /* try ARM7 instead */ - - u32 erase_check_code[] = - { - 0xe4d03001, /* ldrb r3, [r0], #1 */ - 0xe0022003, /* and r2, r2, r3 */ - 0xe2511001, /* subs r1, r1, #1 */ - 0x1afffffb, /* b -4 */ - 0xeafffffe /* b 0 */ - }; - - /* make sure we have a working area */ - if (target_alloc_working_area(target, 20, &erase_check_algorithm) == ERROR_OK) + u32 address = bank->base + bank->sectors[i].offset; + u32 size = bank->sectors[i].size; + + if ((retval = target_blank_check_memory(target, address, size, &blank)) != ERROR_OK) { - u8 erase_check_code_buf[5 * 4]; - - for (i = 0; i < 5; i++) - target_buffer_set_u32(target, erase_check_code_buf + (i*4), erase_check_code[i]); - - /* write algorithm code to working area */ - if ((retval=target->type->write_memory(target, erase_check_algorithm->address, 4, 5, erase_check_code_buf))==ERROR_OK) - { - for (i = 0; i < bank->num_sectors; i++) - { - u32 address = bank->base + bank->sectors[i].offset; - u32 size = bank->sectors[i].size; - - reg_param_t reg_params[3]; - armv4_5_algorithm_t armv4_5_info; - - armv4_5_info.common_magic = ARMV4_5_COMMON_MAGIC; - armv4_5_info.core_mode = ARMV4_5_MODE_SVC; - armv4_5_info.core_state = ARMV4_5_STATE_ARM; - - init_reg_param(®_params[0], "r0", 32, PARAM_OUT); - buf_set_u32(reg_params[0].value, 0, 32, address); - - init_reg_param(®_params[1], "r1", 32, PARAM_OUT); - buf_set_u32(reg_params[1].value, 0, 32, size); - - init_reg_param(®_params[2], "r2", 32, PARAM_IN_OUT); - buf_set_u32(reg_params[2].value, 0, 32, 0xff); - - if ((retval = target->type->run_algorithm(target, 0, NULL, 3, reg_params, - erase_check_algorithm->address, erase_check_algorithm->address + 0x10, 10000, &armv4_5_info)) != ERROR_OK) - break; - - if (buf_get_u32(reg_params[2].value, 0, 32) == 0xff) - bank->sectors[i].is_erased = 1; - else - bank->sectors[i].is_erased = 0; - - destroy_reg_param(®_params[0]); - destroy_reg_param(®_params[1]); - destroy_reg_param(®_params[2]); - } - if (i == bank->num_sectors) - { - fast_check = 1; - } - } - target_free_working_area(target, erase_check_algorithm); + fast_check = 0; + break; } + if (blank == 0xFF) + bank->sectors[i].is_erased = 1; + else + bank->sectors[i].is_erased = 0; + fast_check = 1; } - - + if (!fast_check) { LOG_USER("Running slow fallback erase check - add working memory"); - 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 + j, 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 default_flash_mem_blank_check(bank); } return ERROR_OK; diff --git a/src/flash/flash.h b/src/flash/flash.h index e2f7885..e7a79f8 100644 --- a/src/flash/flash.h +++ b/src/flash/flash.h @@ -78,7 +78,8 @@ 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 int default_flash_blank_check(struct flash_bank_s *bank); +extern int default_flash_mem_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/stellaris.c b/src/flash/stellaris.c index e8c0a1c..57049fa 100644 --- a/src/flash/stellaris.c +++ b/src/flash/stellaris.c @@ -70,7 +70,7 @@ flash_driver_t stellaris_flash = .write = stellaris_write, .probe = stellaris_probe, .auto_probe = stellaris_auto_probe, - .erase_check = default_flash_blank_check, + .erase_check = default_flash_mem_blank_check, .protect_check = stellaris_protect_check, .info = stellaris_info }; diff --git a/src/flash/stm32x.c b/src/flash/stm32x.c index 9ce16f7..dcd59d2 100644 --- a/src/flash/stm32x.c +++ b/src/flash/stm32x.c @@ -61,7 +61,7 @@ flash_driver_t stm32x_flash = .write = stm32x_write, .probe = stm32x_probe, .auto_probe = stm32x_auto_probe, - .erase_check = default_flash_blank_check, + .erase_check = default_flash_mem_blank_check, .protect_check = stm32x_protect_check, .info = stm32x_info }; |