diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/flash/at91sam7.c | 2 | ||||
-rw-r--r-- | src/flash/cfi.c | 18 | ||||
-rw-r--r-- | src/flash/flash.c | 2 | ||||
-rw-r--r-- | src/flash/lpc3180_nand_controller.c | 4 | ||||
-rw-r--r-- | src/flash/mflash.c | 6 | ||||
-rw-r--r-- | src/target/arm7_9_common.c | 8 | ||||
-rw-r--r-- | src/target/cortex_m3.c | 2 | ||||
-rw-r--r-- | src/target/mips_m4k.c | 8 | ||||
-rw-r--r-- | src/target/target.c | 30 | ||||
-rw-r--r-- | src/target/target.h | 13 | ||||
-rw-r--r-- | src/target/xscale.c | 4 |
11 files changed, 58 insertions, 39 deletions
diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c index fb87aa3..186aa06 100644 --- a/src/flash/at91sam7.c +++ b/src/flash/at91sam7.c @@ -665,7 +665,7 @@ static int at91sam7_erase_check(struct flash_bank_s *bank) for (nSector=0; nSector<bank->num_sectors; nSector++) { bank->sectors[nSector].is_erased = 1; - retval = target->type->read_memory(target, bank->base+bank->sectors[nSector].offset, 4, + retval = target_read_memory(target, bank->base+bank->sectors[nSector].offset, 4, bank->sectors[nSector].size/4, buffer); if (retval != ERROR_OK) return retval; diff --git a/src/flash/cfi.c b/src/flash/cfi.c index 6e8b96e..999b0a7 100644 --- a/src/flash/cfi.c +++ b/src/flash/cfi.c @@ -166,7 +166,7 @@ static u8 cfi_query_u8(flash_bank_t *bank, int sector, u32 offset) target_t *target = bank->target; u8 data[CFI_MAX_BUS_WIDTH]; - target->type->read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 1, data); + target_read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 1, data); if (bank->target->endianness == TARGET_LITTLE_ENDIAN) return data[0]; @@ -184,7 +184,7 @@ static u8 cfi_get_u8(flash_bank_t *bank, int sector, u32 offset) u8 data[CFI_MAX_BUS_WIDTH]; int i; - target->type->read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 1, data); + target_read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 1, data); if (bank->target->endianness == TARGET_LITTLE_ENDIAN) { @@ -213,11 +213,11 @@ static u16 cfi_query_u16(flash_bank_t *bank, int sector, u32 offset) { u8 i; for(i=0;i<2;i++) - target->type->read_memory(target, flash_address(bank, sector, offset+i), bank->bus_width, 1, + target_read_memory(target, flash_address(bank, sector, offset+i), bank->bus_width, 1, &data[i*bank->bus_width] ); } else - target->type->read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 2, data); + target_read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 2, data); if (bank->target->endianness == TARGET_LITTLE_ENDIAN) return data[0] | data[bank->bus_width] << 8; @@ -235,11 +235,11 @@ static u32 cfi_query_u32(flash_bank_t *bank, int sector, u32 offset) { u8 i; for(i=0;i<4;i++) - target->type->read_memory(target, flash_address(bank, sector, offset+i), bank->bus_width, 1, + target_read_memory(target, flash_address(bank, sector, offset+i), bank->bus_width, 1, &data[i*bank->bus_width] ); } else - target->type->read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 4, data); + target_read_memory(target, flash_address(bank, sector, offset), bank->bus_width, 4, data); if (bank->target->endianness == TARGET_LITTLE_ENDIAN) return data[0] | data[bank->bus_width] << 8 | data[bank->bus_width * 2] << 16 | data[bank->bus_width * 3] << 24; @@ -1889,7 +1889,7 @@ int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) for (i = 0; i < align; ++i, ++copy_p) { u8 byte; - if((retval = target->type->read_memory(target, copy_p, 1, 1, &byte)) != ERROR_OK) + if((retval = target_read_memory(target, copy_p, 1, 1, &byte)) != ERROR_OK) { return retval; } @@ -1908,7 +1908,7 @@ int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) for (; (count == 0) && (i < bank->bus_width); ++i, ++copy_p) { u8 byte; - if((retval = target->type->read_memory(target, copy_p, 1, 1, &byte)) != ERROR_OK) + if((retval = target_read_memory(target, copy_p, 1, 1, &byte)) != ERROR_OK) { return retval; } @@ -2039,7 +2039,7 @@ int cfi_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) for (; i < bank->bus_width; ++i, ++copy_p) { u8 byte; - if((retval = target->type->read_memory(target, copy_p, 1, 1, &byte)) != ERROR_OK) + if((retval = target_read_memory(target, copy_p, 1, 1, &byte)) != ERROR_OK) { return retval; } diff --git a/src/flash/flash.c b/src/flash/flash.c index 9beec5a..ce92005 100644 --- a/src/flash/flash.c +++ b/src/flash/flash.c @@ -1157,7 +1157,7 @@ int default_flash_mem_blank_check(struct flash_bank_s *bank) chunk = (j - bank->sectors[i].size); } - retval = target->type->read_memory(target, bank->base + bank->sectors[i].offset + j, 4, chunk/4, buffer); + retval = target_read_memory(target, bank->base + bank->sectors[i].offset + j, 4, chunk/4, buffer); if (retval != ERROR_OK) return retval; diff --git a/src/flash/lpc3180_nand_controller.c b/src/flash/lpc3180_nand_controller.c index 1cbd920..a074acc 100644 --- a/src/flash/lpc3180_nand_controller.c +++ b/src/flash/lpc3180_nand_controller.c @@ -759,12 +759,12 @@ static int lpc3180_read_page(struct nand_device_s *device, u32 page, u8 *data, u if (data) { - target->type->read_memory(target, 0x200a8000, 4, 128, page_buffer + page_bytes_done); + target_read_memory(target, 0x200a8000, 4, 128, page_buffer + page_bytes_done); } if (oob) { - target->type->read_memory(target, 0x200a8000, 4, 4, oob_buffer + oob_bytes_done); + target_read_memory(target, 0x200a8000, 4, 4, oob_buffer + oob_bytes_done); } page_bytes_done += 512; diff --git a/src/flash/mflash.c b/src/flash/mflash.c index 47c7338..cc1d1ee 100644 --- a/src/flash/mflash.c +++ b/src/flash/mflash.c @@ -345,7 +345,7 @@ static int mg_dsk_drv_info(void) if (! mflash_bank->drv_info) mflash_bank->drv_info = malloc(sizeof(mg_drv_info_t)); - target->type->read_memory(target, mg_buff, 2, sizeof(mg_io_type_drv_info) >> 1, + target_read_memory(target, mg_buff, 2, sizeof(mg_io_type_drv_info) >> 1, (u8 *)&mflash_bank->drv_info->drv_id); mflash_bank->drv_info->tot_sects = (u32)(mflash_bank->drv_info->drv_id.total_user_addressable_sectors_hi << 16) @@ -428,7 +428,7 @@ static int mg_mflash_do_read_sects(void *buff, u32 sect_num, u32 sect_cnt) for (i = 0; i < sect_cnt; i++) { mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL); - target->type->read_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr); + target_read_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr); buff_ptr += MG_MFLASH_SECTOR_SIZE; target_write_u8(target, mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, mg_io_cmd_confirm_read); @@ -932,7 +932,7 @@ static int mg_verify_interface(void) memset(buff, 0xff, MG_MFLASH_SECTOR_SIZE); - target->type->read_memory(target, address, 2, + target_read_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, (u8 *)buff); for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++) { diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 12ee62f..48263ef 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -274,7 +274,7 @@ int arm7_9_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint) { u32 verify = 0xffffffff; /* keep the original instruction in target endianness */ - if ((retval = target->type->read_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK) + if ((retval = target_read_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK) { return retval; } @@ -298,7 +298,7 @@ int arm7_9_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint) { u16 verify = 0xffff; /* keep the original instruction in target endianness */ - if ((retval = target->type->read_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK) + if ((retval = target_read_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK) { return retval; } @@ -373,7 +373,7 @@ int arm7_9_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint) { u32 current_instr; /* check that user program as not modified breakpoint instruction */ - if ((retval = target->type->read_memory(target, breakpoint->address, 4, 1, (u8*)¤t_instr)) != ERROR_OK) + if ((retval = target_read_memory(target, breakpoint->address, 4, 1, (u8*)¤t_instr)) != ERROR_OK) { return retval; } @@ -387,7 +387,7 @@ int arm7_9_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint) { u16 current_instr; /* check that user program as not modified breakpoint instruction */ - if ((retval = target->type->read_memory(target, breakpoint->address, 2, 1, (u8*)¤t_instr)) != ERROR_OK) + if ((retval = target_read_memory(target, breakpoint->address, 2, 1, (u8*)¤t_instr)) != ERROR_OK) { return retval; } diff --git a/src/target/cortex_m3.c b/src/target/cortex_m3.c index 4a032ee..6f51d91 100644 --- a/src/target/cortex_m3.c +++ b/src/target/cortex_m3.c @@ -930,7 +930,7 @@ int cortex_m3_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint) { u8 code[4]; buf_set_u32(code, 0, 32, ARMV7M_T_BKPT(0x11)); - if((retval = target->type->read_memory(target, breakpoint->address & 0xFFFFFFFE, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK) + if((retval = target_read_memory(target, breakpoint->address & 0xFFFFFFFE, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK) { return retval; } diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c index 6d331d4..a16590c 100644 --- a/src/target/mips_m4k.c +++ b/src/target/mips_m4k.c @@ -529,7 +529,7 @@ int mips_m4k_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint) { u32 verify = 0xffffffff; - if((retval = target->type->read_memory(target, breakpoint->address, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK) + if((retval = target_read_memory(target, breakpoint->address, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK) { return retval; } @@ -552,7 +552,7 @@ int mips_m4k_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint) { u16 verify = 0xffff; - if((retval = target->type->read_memory(target, breakpoint->address, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK) + if((retval = target_read_memory(target, breakpoint->address, breakpoint->length, 1, breakpoint->orig_instr)) != ERROR_OK) { return retval; } @@ -611,7 +611,7 @@ int mips_m4k_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint) u32 current_instr; /* check that user program has not modified breakpoint instruction */ - if ((retval = target->type->read_memory(target, breakpoint->address, 4, 1, (u8*)¤t_instr)) != ERROR_OK) + if ((retval = target_read_memory(target, breakpoint->address, 4, 1, (u8*)¤t_instr)) != ERROR_OK) { return retval; } @@ -628,7 +628,7 @@ int mips_m4k_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint) u16 current_instr; /* check that user program has not modified breakpoint instruction */ - if ((retval = target->type->read_memory(target, breakpoint->address, 2, 1, (u8*)¤t_instr)) != ERROR_OK) + if ((retval = target_read_memory(target, breakpoint->address, 2, 1, (u8*)¤t_instr)) != ERROR_OK) { return retval; } diff --git a/src/target/target.c b/src/target/target.c index d56f5e3..5b75c34 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -525,6 +525,12 @@ static int target_run_algorithm_imp(struct target_s *target, int num_mem_params, return target->type->run_algorithm_imp(target, num_mem_params, mem_params, num_reg_params, reg_param, entry_point, exit_point, timeout_ms, arch_info); } +int target_read_memory(struct target_s *target, + u32 address, u32 size, u32 count, u8 *buffer) +{ + return target->type->read_memory(target, address, size, count, buffer); +} + int target_init(struct command_context_s *cmd_ctx) { target_t *target = all_targets; @@ -858,7 +864,7 @@ int target_alloc_working_area(struct target_s *target, u32 size, working_area_t { int retval; new_wa->backup = malloc(new_wa->size); - if((retval = target->type->read_memory(target, new_wa->address, 4, new_wa->size / 4, new_wa->backup)) != ERROR_OK) + if((retval = target_read_memory(target, new_wa->address, 4, new_wa->size / 4, new_wa->backup)) != ERROR_OK) { free(new_wa->backup); free(new_wa); @@ -1077,7 +1083,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe if (((address % 2) == 0) && (size == 2)) { - return target->type->read_memory(target, address, 2, 1, buffer); + return target_read_memory(target, address, 2, 1, buffer); } /* handle unaligned head bytes */ @@ -1088,7 +1094,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe if (unaligned > size) unaligned = size; - if ((retval = target->type->read_memory(target, address, 1, unaligned, buffer)) != ERROR_OK) + if ((retval = target_read_memory(target, address, 1, unaligned, buffer)) != ERROR_OK) return retval; buffer += unaligned; @@ -1101,7 +1107,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe { int aligned = size - (size % 4); - if ((retval = target->type->read_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK) + if ((retval = target_read_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK) return retval; buffer += aligned; @@ -1112,7 +1118,7 @@ int target_read_buffer(struct target_s *target, u32 address, u32 size, u8 *buffe /* handle tail writes of less than 4 bytes */ if (size > 0) { - if ((retval = target->type->read_memory(target, address, 1, size, buffer)) != ERROR_OK) + if ((retval = target_read_memory(target, address, 1, size, buffer)) != ERROR_OK) return retval; } @@ -1190,7 +1196,7 @@ int target_read_u32(struct target_s *target, u32 address, u32 *value) return ERROR_FAIL; } - int retval = target->type->read_memory(target, address, 4, 1, value_buf); + int retval = target_read_memory(target, address, 4, 1, value_buf); if (retval == ERROR_OK) { @@ -1215,7 +1221,7 @@ int target_read_u16(struct target_s *target, u32 address, u16 *value) return ERROR_FAIL; } - int retval = target->type->read_memory(target, address, 2, 1, value_buf); + int retval = target_read_memory(target, address, 2, 1, value_buf); if (retval == ERROR_OK) { @@ -1233,7 +1239,7 @@ int target_read_u16(struct target_s *target, u32 address, u16 *value) int target_read_u8(struct target_s *target, u32 address, u8 *value) { - int retval = target->type->read_memory(target, address, 1, 1, value); + int retval = target_read_memory(target, address, 1, 1, value); if (!target->type->examined) { LOG_ERROR("Target not examined yet"); @@ -1914,7 +1920,7 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char u8 *buffer = calloc(count, size); target_t *target = get_current_target(cmd_ctx); - int retval = target->type->read_memory(target, + int retval = target_read_memory(target, address, size, count, buffer); if (ERROR_OK == retval) handle_md_output(cmd_ctx, target, address, size, count, buffer); @@ -2256,7 +2262,7 @@ static int handle_verify_image_command_internal(struct command_context_s *cmd_ct size *= 4; count /= 4; } - retval = target->type->read_memory(target, image.sections[i].base_address, size, count, data); + retval = target_read_memory(target, image.sections[i].base_address, size, count, data); if (retval == ERROR_OK) { u32 t; @@ -2829,7 +2835,7 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_ count = (sizeof(buffer)/width); } - retval = target->type->read_memory( target, addr, width, count, buffer ); + retval = target_read_memory( target, addr, width, count, buffer ); if (retval != ERROR_OK) { /* BOO !*/ LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", addr, width, count); @@ -3575,7 +3581,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv ) if( y > 16 ){ y = 16; } - e = target->type->read_memory( target, a, b, y / b, target_buf ); + e = target_read_memory( target, a, b, y / b, target_buf ); if( e != ERROR_OK ){ Jim_SetResult_sprintf( interp, "error reading target @ 0x%08lx", (int)(a) ); return JIM_ERR; diff --git a/src/target/target.h b/src/target/target.h index 09f8e9c..b11e2b6 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -161,6 +161,10 @@ typedef struct target_type_s * count: number of items of <size> */ int (*read_memory_imp)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer); + /** + * Target memory read callback. Do @b not call this function + * directly, use target_read_memory() instead. + */ int (*read_memory)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer); int (*write_memory_imp)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer); int (*write_memory)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer); @@ -371,6 +375,15 @@ extern target_t* get_current_target(struct command_context_s *cmd_ctx); extern int get_num_by_target(target_t *query_target); extern target_t *get_target(const char *id); +/** + * Read @count items of @a size bytes from the memory of @a target at + * the @a address given. + * + * This routine is a wrapper for target->type->read_memory. + */ +extern int target_read_memory(struct target_s *target, + u32 address, u32 size, u32 count, u8 *buffer); + 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); diff --git a/src/target/xscale.c b/src/target/xscale.c index 3947da0..f200e8c 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -2187,7 +2187,7 @@ int xscale_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint) if (breakpoint->length == 4) { /* keep the original instruction in target endianness */ - if((retval = target->type->read_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK) + if((retval = target_read_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK) { return retval; } @@ -2200,7 +2200,7 @@ int xscale_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint) else { /* keep the original instruction in target endianness */ - if((retval = target->type->read_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK) + if((retval = target_read_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK) { return retval; } |