From f94d66d7c5f3c018ba72593b720746e4c5be1a16 Mon Sep 17 00:00:00 2001 From: drath Date: Wed, 30 May 2007 15:47:18 +0000 Subject: - reworked image handling to support multiple sections (tested with ihex file containing gaps) This checkin is still experimental, not recommended for general use git-svn-id: svn://svn.berlios.de/openocd/trunk@159 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/target/target.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/target/target.c') diff --git a/src/target/target.c b/src/target/target.c index e980ae4a..b7f842e7 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1658,6 +1658,8 @@ int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char u8 *buffer; u32 buf_cnt; u32 image_size; + int i; + int retval; image_t image; @@ -1678,8 +1680,6 @@ int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char image.base_address = strtoul(args[1], NULL, 0); image.start_address_set = 0; - - buffer = malloc(128 * 1024); duration_start_measure(&duration); @@ -1689,21 +1689,27 @@ int handle_load_image_command(struct command_context_s *cmd_ctx, char *cmd, char return ERROR_OK; } - image_size = image.size; - address = image.base_address; - - while ((image_size > 0) && - (image_read(&image, 128 * 1024, buffer, &buf_cnt) == ERROR_OK)) + image_size = 0x0; + for (i = 0; i < image.num_sections; i++) { - target_write_buffer(target, address, buf_cnt, buffer); - address += buf_cnt; - image_size -= buf_cnt; + buffer = malloc(image.sections[i].size); + if ((retval = image_read_section(&image, i, 0x0, image.sections[i].size, buffer, &buf_cnt)) != ERROR_OK) + { + ERROR("image_read_section failed with error code: %i", retval); + command_print(cmd_ctx, "image reading failed, download aborted"); + free(buffer); + image_close(&image); + return ERROR_OK; + } + target_write_buffer(target, image.sections[i].base_address, buf_cnt, buffer); + image_size += buf_cnt; + command_print(cmd_ctx, "%u byte written at address 0x%8.8x", buf_cnt, image.sections[i].base_address); + + free(buffer); } - free(buffer); - duration_stop_measure(&duration, &duration_text); - command_print(cmd_ctx, "downloaded %u byte in %s", image.size, duration_text); + command_print(cmd_ctx, "downloaded %u byte in %s", image_size, duration_text); free(duration_text); image_close(&image); -- cgit v1.2.3