summaryrefslogtreecommitdiff
path: root/src/target/target.c
diff options
context:
space:
mode:
authordrath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2007-05-30 15:47:18 +0000
committerdrath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2007-05-30 15:47:18 +0000
commitf94d66d7c5f3c018ba72593b720746e4c5be1a16 (patch)
treed4d7d3e2ac6d3fd940c1026417eb738decd8055f /src/target/target.c
parentcf013d2e135373438815315f48ce86e4b558c58b (diff)
downloadopenocd_libswd-f94d66d7c5f3c018ba72593b720746e4c5be1a16.tar.gz
openocd_libswd-f94d66d7c5f3c018ba72593b720746e4c5be1a16.tar.bz2
openocd_libswd-f94d66d7c5f3c018ba72593b720746e4c5be1a16.tar.xz
openocd_libswd-f94d66d7c5f3c018ba72593b720746e4c5be1a16.zip
- 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
Diffstat (limited to 'src/target/target.c')
-rw-r--r--src/target/target.c32
1 files changed, 19 insertions, 13 deletions
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);