Commit 95e13054 authored by zwelch's avatar zwelch
Browse files

Add target_write_memory wrapper:

- replaces all calls to target->type->write_memory.
- add documentation in target_s to warn not to invoke callback directly.


git-svn-id: svn://svn.berlios.de/openocd/trunk@1960 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent b6db182c
......@@ -1027,7 +1027,7 @@ static int at91sam7_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32
/* Write one block to the PageWriteBuffer */
buffer_pos = (pagen-first_page)*dst_min_alignment;
wcount = CEIL(count,4);
if((retval = target->type->write_memory(target, bank->base+pagen*dst_min_alignment, 4, wcount, buffer+buffer_pos)) != ERROR_OK)
if((retval = target_write_memory(target, bank->base+pagen*dst_min_alignment, 4, wcount, buffer+buffer_pos)) != ERROR_OK)
{
return retval;
}
......
This diff is collapsed.
......@@ -258,7 +258,7 @@ static int lpc2000_iap_call(flash_bank_t *bank, int code, u32 param_table[5], u3
/* write IAP code to working area */
target_buffer_set_u32(target, jump_gate, ARMV4_5_BX(12));
target_buffer_set_u32(target, jump_gate + 4, ARMV4_5_B(0xfffffe, 0));
if((retval = target->type->write_memory(target, lpc2000_info->iap_working_area->address, 4, 2, jump_gate)) != ERROR_OK)
if((retval = target_write_memory(target, lpc2000_info->iap_working_area->address, 4, 2, jump_gate)) != ERROR_OK)
{
return retval;
}
......
......@@ -406,7 +406,7 @@ static int lpc288x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32
* it seems not to be a LOT slower....
* bulk_write_memory() is no quicker :(*/
#if 1
if (target->type->write_memory(target, offset + dest_offset, 4, 128, page_buffer) != ERROR_OK)
if (target_write_memory(target, offset + dest_offset, 4, 128, page_buffer) != ERROR_OK)
{
LOG_ERROR("Write failed s %x p %x", sector, page);
return ERROR_FLASH_OPERATION_FAILED;
......
......@@ -602,8 +602,8 @@ static int lpc3180_write_page(struct nand_device_s *device, u32 page, u8 *data,
/* write MLC_ECC_ENC_REG to start encode cycle */
target_write_u32(target, 0x200b8008, 0x0);
target->type->write_memory(target, 0x200a8000, 4, 128, page_buffer + (quarter * 512));
target->type->write_memory(target, 0x200a8000, 1, 6, oob_buffer + (quarter * 6));
target_write_memory(target, 0x200a8000, 4, 128, page_buffer + (quarter * 512));
target_write_memory(target, 0x200a8000, 1, 6, oob_buffer + (quarter * 6));
/* write MLC_ECC_AUTO_ENC_REG to start auto encode */
target_write_u32(target, 0x200b8010, 0x0);
......
......@@ -494,7 +494,7 @@ static int mg_mflash_do_write_sects(void *buff, u32 sect_num, u32 sect_cnt,
if (ret != ERROR_OK)
LOG_ERROR("mg_io_wait_drq time out");
ret = target->type->write_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr);
ret = target_write_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr);
if (ret != ERROR_OK)
LOG_ERROR("mem write error");
buff_ptr += MG_MFLASH_SECTOR_SIZE;
......@@ -927,7 +927,7 @@ static int mg_verify_interface(void)
for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++)
buff[i] = i;
target->type->write_memory(target, address, 2,
target_write_memory(target, address, 2,
MG_MFLASH_SECTOR_SIZE / 2, (u8 *)buff);
memset(buff, 0xff, MG_MFLASH_SECTOR_SIZE);
......
......@@ -131,7 +131,7 @@ static int orion_nand_fast_block_write(struct nand_device_s *device, u8 *data, i
target_buffer_set_u32(target, code_buf + i*4, code[i]);
/* write code to working area */
retval = target->type->write_memory(target,
retval = target_write_memory(target,
hw->copy_area->address,
4, code_size/4, code_buf);
if (retval != ERROR_OK)
......@@ -143,7 +143,7 @@ static int orion_nand_fast_block_write(struct nand_device_s *device, u8 *data, i
retval = target->type->bulk_write_memory(target, target_buf,
size/4, data);
if (retval == ERROR_OK && size & 3) {
retval = target->type->write_memory(target,
retval = target_write_memory(target,
target_buf + (size & ~3),
1, size & 3, data + (size & ~3));
}
......
......@@ -546,11 +546,11 @@ static int str7x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 co
target_write_u32(target, str7x_get_flash_adr(bank, FLASH_AR), address);
/* data word 1 */
target->type->write_memory(target, str7x_get_flash_adr(bank, FLASH_DR0), 4, 1, buffer + bytes_written);
target_write_memory(target, str7x_get_flash_adr(bank, FLASH_DR0), 4, 1, buffer + bytes_written);
bytes_written += 4;
/* data word 2 */
target->type->write_memory(target, str7x_get_flash_adr(bank, FLASH_DR1), 4, 1, buffer + bytes_written);
target_write_memory(target, str7x_get_flash_adr(bank, FLASH_DR1), 4, 1, buffer + bytes_written);
bytes_written += 4;
/* start programming cycle */
......@@ -593,11 +593,11 @@ static int str7x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 co
target_write_u32(target, str7x_get_flash_adr(bank, FLASH_AR), address);
/* data word 1 */
target->type->write_memory(target, str7x_get_flash_adr(bank, FLASH_DR0), 4, 1, last_dword);
target_write_memory(target, str7x_get_flash_adr(bank, FLASH_DR0), 4, 1, last_dword);
bytes_written += 4;
/* data word 2 */
target->type->write_memory(target, str7x_get_flash_adr(bank, FLASH_DR1), 4, 1, last_dword + 4);
target_write_memory(target, str7x_get_flash_adr(bank, FLASH_DR1), 4, 1, last_dword + 4);
bytes_written += 4;
/* start programming cycle */
......
......@@ -569,7 +569,7 @@ static int str9x_write(struct flash_bank_s *bank,
/* write data command */
target_write_u16(target, bank_adr, 0x40);
target->type->write_memory(target, address, 2, 1, buffer + bytes_written);
target_write_memory(target, address, 2, 1, buffer + bytes_written);
/* get status command */
target_write_u16(target, bank_adr, 0x70);
......@@ -618,7 +618,7 @@ static int str9x_write(struct flash_bank_s *bank,
/* write data comamnd */
target_write_u16(target, bank_adr, 0x40);
target->type->write_memory(target, address, 2, 1, last_halfword);
target_write_memory(target, address, 2, 1, last_halfword);
/* query status command */
target_write_u16(target, bank_adr, 0x70);
......
......@@ -378,7 +378,7 @@ int arm7_9_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
return retval;
}
if (current_instr==arm7_9->arm_bkpt)
if ((retval = target->type->write_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
if ((retval = target_write_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
......@@ -392,7 +392,7 @@ int arm7_9_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
return retval;
}
if (current_instr==arm7_9->thumb_bkpt)
if ((retval = target->type->write_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
if ((retval = target_write_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
......@@ -2628,7 +2628,7 @@ int arm7_9_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buffe
int i;
if (!arm7_9->dcc_downloads)
return target->type->write_memory(target, address, 4, count, buffer);
return target_write_memory(target, address, 4, count, buffer);
/* regrab previously allocated working_area, or allocate a new one */
if (!arm7_9->dcc_working_area)
......@@ -2639,7 +2639,7 @@ int arm7_9_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buffe
if (target_alloc_working_area(target, 24, &arm7_9->dcc_working_area) != ERROR_OK)
{
LOG_INFO("no working area available, falling back to memory writes");
return target->type->write_memory(target, address, 4, count, buffer);
return target_write_memory(target, address, 4, count, buffer);
}
/* copy target instructions to target endianness */
......@@ -2649,7 +2649,7 @@ int arm7_9_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buffe
}
/* write DCC code to working area */
if ((retval = target->type->write_memory(target, arm7_9->dcc_working_area->address, 4, 6, dcc_code_buf)) != ERROR_OK)
if ((retval = target_write_memory(target, arm7_9->dcc_working_area->address, 4, 6, dcc_code_buf)) != ERROR_OK)
{
return retval;
}
......
......@@ -934,7 +934,7 @@ int cortex_m3_set_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
{
return retval;
}
if((retval = target->type->write_memory(target, breakpoint->address & 0xFFFFFFFE, breakpoint->length, 1, code)) != ERROR_OK)
if((retval = target_write_memory(target, breakpoint->address & 0xFFFFFFFE, breakpoint->length, 1, code)) != ERROR_OK)
{
return retval;
}
......@@ -975,14 +975,14 @@ int cortex_m3_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint
/* restore original instruction (kept in target endianness) */
if (breakpoint->length == 4)
{
if((retval = target->type->write_memory(target, breakpoint->address & 0xFFFFFFFE, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
if((retval = target_write_memory(target, breakpoint->address & 0xFFFFFFFE, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
}
else
{
if((retval = target->type->write_memory(target, breakpoint->address & 0xFFFFFFFE, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
if((retval = target_write_memory(target, breakpoint->address & 0xFFFFFFFE, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
......
......@@ -546,7 +546,7 @@ int feroceon_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buf
u32 dcc_size = sizeof(dcc_code);
if (!arm7_9->dcc_downloads)
return target->type->write_memory(target, address, 4, count, buffer);
return target_write_memory(target, address, 4, count, buffer);
/* regrab previously allocated working_area, or allocate a new one */
if (!arm7_9->dcc_working_area)
......@@ -557,7 +557,7 @@ int feroceon_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buf
if (target_alloc_working_area(target, dcc_size, &arm7_9->dcc_working_area) != ERROR_OK)
{
LOG_INFO("no working area available, falling back to memory writes");
return target->type->write_memory(target, address, 4, count, buffer);
return target_write_memory(target, address, 4, count, buffer);
}
/* copy target instructions to target endianness */
......@@ -565,7 +565,7 @@ int feroceon_bulk_write_memory(target_t *target, u32 address, u32 count, u8 *buf
target_buffer_set_u32(target, dcc_code_buf + i*4, dcc_code[i]);
/* write DCC code to working area */
if((retval = target->type->write_memory(target, arm7_9->dcc_working_area->address, 4, dcc_size/4, dcc_code_buf)) != ERROR_OK)
if((retval = target_write_memory(target, arm7_9->dcc_working_area->address, 4, dcc_size/4, dcc_code_buf)) != ERROR_OK)
{
return retval;
}
......
......@@ -617,7 +617,7 @@ int mips_m4k_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
}
if (current_instr == MIPS32_SDBBP)
{
if((retval = target->type->write_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
if((retval = target_write_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
......@@ -635,7 +635,7 @@ int mips_m4k_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
if (current_instr == MIPS16_SDBBP)
{
if((retval = target->type->write_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
if((retval = target_write_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
......
......@@ -531,6 +531,13 @@ int target_read_memory(struct target_s *target,
return target->type->read_memory(target, address, size, count, buffer);
}
int target_write_memory(struct target_s *target,
u32 address, u32 size, u32 count, u8 *buffer)
{
return target->type->write_memory(target, address, size, count, buffer);
}
int target_init(struct command_context_s *cmd_ctx)
{
target_t *target = all_targets;
......@@ -898,7 +905,7 @@ int target_free_working_area_restore(struct target_s *target, working_area_t *ar
if (restore&&target->backup_working_area)
{
int retval;
if((retval = target->type->write_memory(target, area->address, 4, area->size / 4, area->backup)) != ERROR_OK)
if((retval = target_write_memory(target, area->address, 4, area->size / 4, area->backup)) != ERROR_OK)
return retval;
}
......@@ -1004,7 +1011,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
if (((address % 2) == 0) && (size == 2))
{
return target->type->write_memory(target, address, 2, 1, buffer);
return target_write_memory(target, address, 2, 1, buffer);
}
/* handle unaligned head bytes */
......@@ -1015,7 +1022,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
if (unaligned > size)
unaligned = size;
if ((retval = target->type->write_memory(target, address, 1, unaligned, buffer)) != ERROR_OK)
if ((retval = target_write_memory(target, address, 1, unaligned, buffer)) != ERROR_OK)
return retval;
buffer += unaligned;
......@@ -1036,7 +1043,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
}
else
{
if ((retval = target->type->write_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK)
if ((retval = target_write_memory(target, address, 4, aligned / 4, buffer)) != ERROR_OK)
return retval;
}
......@@ -1048,7 +1055,7 @@ int target_write_buffer(struct target_s *target, u32 address, u32 size, u8 *buff
/* handle tail writes of less than 4 bytes */
if (size > 0)
{
if ((retval = target->type->write_memory(target, address, 1, size, buffer)) != ERROR_OK)
if ((retval = target_write_memory(target, address, 1, size, buffer)) != ERROR_OK)
return retval;
}
......@@ -1272,7 +1279,7 @@ int target_write_u32(struct target_s *target, u32 address, u32 value)
LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, value);
target_buffer_set_u32(target, value_buf, value);
if ((retval = target->type->write_memory(target, address, 4, 1, value_buf)) != ERROR_OK)
if ((retval = target_write_memory(target, address, 4, 1, value_buf)) != ERROR_OK)
{
LOG_DEBUG("failed: %i", retval);
}
......@@ -1293,7 +1300,7 @@ int target_write_u16(struct target_s *target, u32 address, u16 value)
LOG_DEBUG("address: 0x%8.8x, value: 0x%8.8x", address, value);
target_buffer_set_u16(target, value_buf, value);
if ((retval = target->type->write_memory(target, address, 2, 1, value_buf)) != ERROR_OK)
if ((retval = target_write_memory(target, address, 2, 1, value_buf)) != ERROR_OK)
{
LOG_DEBUG("failed: %i", retval);
}
......@@ -1312,7 +1319,7 @@ int target_write_u8(struct target_s *target, u32 address, u8 value)
LOG_DEBUG("address: 0x%8.8x, value: 0x%2.2x", address, value);
if ((retval = target->type->write_memory(target, address, 1, 1, &value)) != ERROR_OK)
if ((retval = target_write_memory(target, address, 1, 1, &value)) != ERROR_OK)
{
LOG_DEBUG("failed: %i", retval);
}
......@@ -1967,7 +1974,7 @@ static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char
}
for (i=0; i<count; i++)
{
int retval = target->type->write_memory(target,
int retval = target_write_memory(target,
address + i * wordsize, wordsize, 1, value_buf);
if (ERROR_OK != retval)
return retval;
......@@ -3034,7 +3041,7 @@ static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_
}
len -= count;
retval = target->type->write_memory(target, addr, width, count, buffer);
retval = target_write_memory(target, addr, width, count, buffer);
if (retval != ERROR_OK) {
/* BOO !*/
LOG_ERROR("array2mem: Write @ 0x%08x, w=%d, cnt=%d, failed", addr, width, count);
......@@ -3525,7 +3532,7 @@ static int tcl_target_func( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
break;
}
for( x = 0 ; x < c ; x++ ){
e = target->type->write_memory( target, a, b, 1, target_buf );
e = target_write_memory( target, a, b, 1, target_buf );
if( e != ERROR_OK ){
Jim_SetResult_sprintf( interp, "Error writing @ 0x%08x: %d\n", (int)(a), e );
return JIM_ERR;
......
......@@ -167,6 +167,10 @@ typedef struct target_type_s
*/
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);
/**
* Target memory write callback. Do @b not call this function
* directly, use target_write_memory() instead.
*/
int (*write_memory)(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer);
/* write target memory in multiples of 4 byte, optimized for writing large quantities of data */
......@@ -383,6 +387,14 @@ extern target_t *get_target(const char *id);
*/
extern int target_read_memory(struct target_s *target,
u32 address, u32 size, u32 count, u8 *buffer);
/**
* Write @count items of @a size bytes to the memory of @a target at
* the @a address given.
*
* This routine is wrapper for target->type->write_memory.
*/
extern int target_write_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);
......
......@@ -2284,14 +2284,14 @@ int xscale_unset_breakpoint(struct target_s *target, breakpoint_t *breakpoint)
/* restore original instruction (kept in target endianness) */
if (breakpoint->length == 4)
{
if((retval = target->type->write_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
if((retval = target_write_memory(target, breakpoint->address, 4, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
}
else
{
if((retval = target->type->write_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
if((retval = target_write_memory(target, breakpoint->address, 2, 1, breakpoint->orig_instr)) != ERROR_OK)
{
return retval;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment