diff options
Diffstat (limited to 'src/target')
-rw-r--r-- | src/target/arm720t.c | 1 | ||||
-rw-r--r-- | src/target/arm7_9_common.c | 63 | ||||
-rw-r--r-- | src/target/arm7_9_common.h | 1 | ||||
-rw-r--r-- | src/target/arm7tdmi.c | 1 | ||||
-rw-r--r-- | src/target/arm920t.c | 1 | ||||
-rw-r--r-- | src/target/arm926ejs.c | 1 | ||||
-rw-r--r-- | src/target/arm966e.c | 1 | ||||
-rw-r--r-- | src/target/arm9tdmi.c | 1 | ||||
-rw-r--r-- | src/target/armv7m.c | 60 | ||||
-rw-r--r-- | src/target/armv7m.h | 1 | ||||
-rw-r--r-- | src/target/cortex_m3.c | 1 | ||||
-rw-r--r-- | src/target/feroceon.c | 1 | ||||
-rw-r--r-- | src/target/target.c | 17 | ||||
-rw-r--r-- | src/target/target.h | 2 | ||||
-rw-r--r-- | src/target/xscale.c | 3 |
15 files changed, 154 insertions, 1 deletions
diff --git a/src/target/arm720t.c b/src/target/arm720t.c index 9645db85..cc45c9e6 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -70,6 +70,7 @@ target_type_t arm720t_target = .write_memory = arm720t_write_memory, .bulk_write_memory = arm7_9_bulk_write_memory, .checksum_memory = arm7_9_checksum_memory, + .blank_check_memory = arm7_9_blank_check_memory, .run_algorithm = armv4_5_run_algorithm, diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 517badfd..b4ab4ef9 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2305,6 +2305,69 @@ int arm7_9_checksum_memory(struct target_s *target, u32 address, u32 count, u32* return ERROR_OK; } +int arm7_9_blank_check_memory(struct target_s *target, u32 address, u32 count, u32* blank) +{ + working_area_t *erase_check_algorithm; + reg_param_t reg_params[3]; + armv4_5_algorithm_t armv4_5_info; + int retval; + int i; + + u32 erase_check_code[] = + { + /* loop: */ + 0xe4d03001, /* ldrb r3, [r0], #1 */ + 0xe0022003, /* and r2, r2, r3 */ + 0xe2511001, /* subs r1, r1, #1 */ + 0x1afffffb, /* bne loop */ + /* end: */ + 0xeafffffe /* b end */ + }; + + /* make sure we have a working area */ + if (target_alloc_working_area(target, sizeof(erase_check_code), &erase_check_algorithm) != ERROR_OK) + { + return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; + } + + /* convert flash writing code into a buffer in target endianness */ + for (i = 0; i < (sizeof(erase_check_code)/sizeof(u32)); i++) + target_write_u32(target, erase_check_algorithm->address + i*sizeof(u32), erase_check_code[i]); + + 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, count); + + 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) - 4), 10000, &armv4_5_info)) != ERROR_OK) + { + destroy_reg_param(®_params[0]); + destroy_reg_param(®_params[1]); + destroy_reg_param(®_params[2]); + target_free_working_area(target, erase_check_algorithm); + return 0; + } + + *blank = buf_get_u32(reg_params[2].value, 0, 32); + + destroy_reg_param(®_params[0]); + destroy_reg_param(®_params[1]); + destroy_reg_param(®_params[2]); + + target_free_working_area(target, erase_check_algorithm); + + return ERROR_OK; +} + int arm7_9_register_commands(struct command_context_s *cmd_ctx) { command_t *arm7_9_cmd; diff --git a/src/target/arm7_9_common.h b/src/target/arm7_9_common.h index 21992faf..d6052f85 100644 --- a/src/target/arm7_9_common.h +++ b/src/target/arm7_9_common.h @@ -123,6 +123,7 @@ int arm7_9_read_memory(struct target_s *target, u32 address, u32 size, u32 count int arm7_9_write_memory(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer); int arm7_9_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buffer); int arm7_9_checksum_memory(struct target_s *target, u32 address, u32 count, u32* checksum); +int arm7_9_blank_check_memory(struct target_s *target, u32 address, u32 count, u32* blank); int arm7_9_run_algorithm(struct target_s *target, int num_mem_params, mem_param_t *mem_params, int num_reg_prams, reg_param_t *reg_param, u32 entry_point, void *arch_info); diff --git a/src/target/arm7tdmi.c b/src/target/arm7tdmi.c index 549f6a67..16d1b136 100644 --- a/src/target/arm7tdmi.c +++ b/src/target/arm7tdmi.c @@ -75,6 +75,7 @@ target_type_t arm7tdmi_target = .write_memory = arm7_9_write_memory, .bulk_write_memory = arm7_9_bulk_write_memory, .checksum_memory = arm7_9_checksum_memory, + .blank_check_memory = arm7_9_blank_check_memory, .run_algorithm = armv4_5_run_algorithm, diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 9e9bf1a5..3a3c2f1f 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -79,6 +79,7 @@ target_type_t arm920t_target = .write_memory = arm920t_write_memory, .bulk_write_memory = arm7_9_bulk_write_memory, .checksum_memory = arm7_9_checksum_memory, + .blank_check_memory = arm7_9_blank_check_memory, .run_algorithm = armv4_5_run_algorithm, diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index f46760e5..ffa2b0d6 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -79,6 +79,7 @@ target_type_t arm926ejs_target = .write_memory = arm926ejs_write_memory, .bulk_write_memory = arm7_9_bulk_write_memory, .checksum_memory = arm7_9_checksum_memory, + .blank_check_memory = arm7_9_blank_check_memory, .run_algorithm = armv4_5_run_algorithm, diff --git a/src/target/arm966e.c b/src/target/arm966e.c index 3112e0fc..af699cfa 100644 --- a/src/target/arm966e.c +++ b/src/target/arm966e.c @@ -70,6 +70,7 @@ target_type_t arm966e_target = .write_memory = arm7_9_write_memory, .bulk_write_memory = arm7_9_bulk_write_memory, .checksum_memory = arm7_9_checksum_memory, + .blank_check_memory = arm7_9_blank_check_memory, .run_algorithm = armv4_5_run_algorithm, diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index 24f3b2eb..90fb45aa 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -73,6 +73,7 @@ target_type_t arm9tdmi_target = .write_memory = arm7_9_write_memory, .bulk_write_memory = arm7_9_bulk_write_memory, .checksum_memory = arm7_9_checksum_memory, + .blank_check_memory = arm7_9_blank_check_memory, .run_algorithm = armv4_5_run_algorithm, diff --git a/src/target/armv7m.c b/src/target/armv7m.c index 950c5cda..b862cf38 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -596,4 +596,64 @@ int armv7m_checksum_memory(struct target_s *target, u32 address, u32 count, u32* return ERROR_OK; } +int armv7m_blank_check_memory(struct target_s *target, u32 address, u32 count, u32* blank) +{ + working_area_t *erase_check_algorithm; + reg_param_t reg_params[3]; + armv7m_algorithm_t armv7m_info; + int retval; + int i; + + u16 erase_check_code[] = + { + /* loop: */ + 0xF810, 0x3B01, /* ldrb r3, [r0], #1 */ + 0xEA02, 0x0203, /* and r2, r2, r3 */ + 0x3901, /* subs r1, r1, #1 */ + 0xD1F9, /* bne loop */ + /* end: */ + 0xE7FE, /* b end */ + }; + + /* make sure we have a working area */ + if (target_alloc_working_area(target, sizeof(erase_check_code), &erase_check_algorithm) != ERROR_OK) + { + return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; + } + + /* convert flash writing code into a buffer in target endianness */ + for (i = 0; i < (sizeof(erase_check_code)/sizeof(u16)); i++) + target_write_u16(target, erase_check_algorithm->address + i*sizeof(u16), erase_check_code[i]); + + armv7m_info.common_magic = ARMV7M_COMMON_MAGIC; + armv7m_info.core_mode = ARMV7M_MODE_ANY; + + 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, count); + + 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, &armv7m_info)) != ERROR_OK) + { + destroy_reg_param(®_params[0]); + destroy_reg_param(®_params[1]); + destroy_reg_param(®_params[2]); + target_free_working_area(target, erase_check_algorithm); + return 0; + } + + *blank = buf_get_u32(reg_params[2].value, 0, 32); + + destroy_reg_param(®_params[0]); + destroy_reg_param(®_params[1]); + destroy_reg_param(®_params[2]); + + target_free_working_area(target, erase_check_algorithm); + + return ERROR_OK; +} diff --git a/src/target/armv7m.h b/src/target/armv7m.h index ebbf437f..d7d24adb 100644 --- a/src/target/armv7m.h +++ b/src/target/armv7m.h @@ -129,6 +129,7 @@ extern int armv7m_invalidate_core_regs(target_t *target); extern int armv7m_restore_context(target_t *target); extern int armv7m_checksum_memory(struct target_s *target, u32 address, u32 count, u32* checksum); +extern int armv7m_blank_check_memory(struct target_s *target, u32 address, u32 count, u32* blank); /* Thumb mode instructions */ diff --git a/src/target/cortex_m3.c b/src/target/cortex_m3.c index 58b620b5..845cca5f 100644 --- a/src/target/cortex_m3.c +++ b/src/target/cortex_m3.c @@ -81,6 +81,7 @@ target_type_t cortexm3_target = .write_memory = cortex_m3_write_memory, .bulk_write_memory = cortex_m3_bulk_write_memory, .checksum_memory = armv7m_checksum_memory, + .blank_check_memory = armv7m_blank_check_memory, .run_algorithm = armv7m_run_algorithm, diff --git a/src/target/feroceon.c b/src/target/feroceon.c index dc216292..a912dbd3 100644 --- a/src/target/feroceon.c +++ b/src/target/feroceon.c @@ -83,6 +83,7 @@ target_type_t feroceon_target = .write_memory = arm926ejs_write_memory, .bulk_write_memory = feroceon_bulk_write_memory, .checksum_memory = arm7_9_checksum_memory, + .blank_check_memory = arm7_9_blank_check_memory, .run_algorithm = armv4_5_run_algorithm, diff --git a/src/target/target.c b/src/target/target.c index 8c479189..0a44e7b3 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1136,6 +1136,23 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32* return retval; } +int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u32* blank) +{ + int retval; + if (!target->type->examined) + { + LOG_ERROR("Target not examined yet"); + return ERROR_FAIL; + } + + if (target->type->blank_check_memory == 0) + return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; + + retval = target->type->blank_check_memory(target, address, size, blank); + + return retval; +} + int target_read_u32(struct target_s *target, u32 address, u32 *value) { u8 value_buf[4]; diff --git a/src/target/target.h b/src/target/target.h index dd70170d..17ac94a5 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -159,6 +159,7 @@ typedef struct target_type_s int (*bulk_write_memory)(struct target_s *target, u32 address, u32 count, u8 *buffer); int (*checksum_memory)(struct target_s *target, u32 address, u32 count, u32* checksum); + int (*blank_check_memory)(struct target_s *target, u32 address, u32 count, u32* blank); /* target break-/watchpoint control * rw: 0 = write, 1 = read, 2 = access @@ -283,6 +284,7 @@ extern target_t* get_target_by_num(int num); extern int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer); extern int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffer); extern int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32* crc); +extern int target_blank_check_memory(struct target_s *target, u32 address, u32 size, u32* blank); /* DANGER!!!!! * diff --git a/src/target/xscale.c b/src/target/xscale.c index 48233243..a83ab70d 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -111,7 +111,8 @@ target_type_t xscale_target = .write_memory = xscale_write_memory, .bulk_write_memory = xscale_bulk_write_memory, .checksum_memory = xscale_checksum_memory, - + .blank_check_memory = NULL, + .run_algorithm = armv4_5_run_algorithm, .add_breakpoint = xscale_add_breakpoint, |