summaryrefslogtreecommitdiff
path: root/src/target
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-13 14:44:53 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-16 15:47:09 -0800
commit51862bb98c26e9b3f03d46ae0f8ceb434f0743d0 (patch)
tree78cb65e732581369d51937ca7ba1de670313f016 /src/target
parent69df712d1d06b2c698bed3de086b9f734de73b7e (diff)
downloadopenocd_libswd-51862bb98c26e9b3f03d46ae0f8ceb434f0743d0.tar.gz
openocd_libswd-51862bb98c26e9b3f03d46ae0f8ceb434f0743d0.tar.bz2
openocd_libswd-51862bb98c26e9b3f03d46ae0f8ceb434f0743d0.tar.xz
openocd_libswd-51862bb98c26e9b3f03d46ae0f8ceb434f0743d0.zip
fileio: improve API types
Use size_t instead of uint32_t when specifying file sizes. Update all consumers up through the layers to use size_t when required. These changes should be safe, but the higher-levels will need to be updated further to receive the intended benefits (i.e. large file support). Add error checking for fileio_read and file_write. Previously, all errors were being silently ignored, so this change might cause some problems for some people in some cases. However, it gives us the chance to handle any errors that do occur at higher-levels, rather than burying our heads in the sand.
Diffstat (limited to 'src/target')
-rw-r--r--src/target/etm.c2
-rw-r--r--src/target/image.c14
-rw-r--r--src/target/image.h2
-rw-r--r--src/target/target.c10
-rw-r--r--src/target/xscale.c2
5 files changed, 15 insertions, 15 deletions
diff --git a/src/target/etm.c b/src/target/etm.c
index 5a0ffed5..fa7a71b2 100644
--- a/src/target/etm.c
+++ b/src/target/etm.c
@@ -640,7 +640,7 @@ static int etm_read_instruction(struct etm_context *ctx, struct arm_instruction
{
int i;
int section = -1;
- uint32_t size_read;
+ size_t size_read;
uint32_t opcode;
int retval;
diff --git a/src/target/image.c b/src/target/image.c
index bba4675f..8774c251 100644
--- a/src/target/image.c
+++ b/src/target/image.c
@@ -48,7 +48,7 @@ static int autodetect_image_type(struct image *image, const char *url)
{
int retval;
struct fileio fileio;
- uint32_t read_bytes;
+ size_t read_bytes;
uint8_t buffer[9];
/* read the first 4 bytes of image */
@@ -175,7 +175,7 @@ static int image_ihex_buffer_complete(struct image *image)
uint32_t record_type;
uint32_t checksum;
uint8_t cal_checksum = 0;
- uint32_t bytes_read = 0;
+ size_t bytes_read = 0;
if (sscanf(&lpszLine[bytes_read], ":%2" SCNx32 "%4" SCNx32 "%2" SCNx32 , &count, &address, &record_type) != 3)
{
@@ -360,7 +360,7 @@ static int image_ihex_buffer_complete(struct image *image)
static int image_elf_read_headers(struct image *image)
{
struct image_elf *elf = image->type_private;
- uint32_t read_bytes;
+ size_t read_bytes;
uint32_t i,j;
int retval;
@@ -458,11 +458,11 @@ static int image_elf_read_headers(struct image *image)
return ERROR_OK;
}
-static int image_elf_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, uint32_t *size_read)
+static int image_elf_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
{
struct image_elf *elf = image->type_private;
Elf32_Phdr *segment = (Elf32_Phdr *)image->sections[section].private;
- uint32_t read_size,really_read;
+ size_t read_size,really_read;
int retval;
*size_read = 0;
@@ -474,7 +474,7 @@ static int image_elf_read_section(struct image *image, int section, uint32_t off
{
/* maximal size present in file for the current segment */
read_size = MIN(size, field32(elf,segment->p_filesz)-offset);
- LOG_DEBUG("read elf: size = 0x%" PRIx32 " at 0x%" PRIx32 "",read_size,
+ LOG_DEBUG("read elf: size = 0x%zu at 0x%" PRIx32 "", read_size,
field32(elf,segment->p_offset) + offset);
/* read initialized area of the segment */
if ((retval = fileio_seek(&elf->fileio, field32(elf,segment->p_offset) + offset)) != ERROR_OK)
@@ -797,7 +797,7 @@ int image_open(struct image *image, const char *url, const char *type_string)
return retval;
};
-int image_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, uint32_t *size_read)
+int image_read_section(struct image *image, int section, uint32_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
{
int retval;
diff --git a/src/target/image.h b/src/target/image.h
index 06d47bf8..0dac5bae 100644
--- a/src/target/image.h
+++ b/src/target/image.h
@@ -102,7 +102,7 @@ struct image_mot
int image_open(struct image *image, const char *url, const char *type_string);
int image_read_section(struct image *image, int section, uint32_t offset,
- uint32_t size, uint8_t *buffer, uint32_t *size_read);
+ uint32_t size, uint8_t *buffer, size_t *size_read);
void image_close(struct image *image);
int image_add_section(struct image *image, uint32_t base, uint32_t size,
diff --git a/src/target/target.c b/src/target/target.c
index f141e933..c00c2ed9 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -2399,7 +2399,7 @@ static COMMAND_HELPER(parse_load_image_command_args, struct image *image,
COMMAND_HANDLER(handle_load_image_command)
{
uint8_t *buffer;
- uint32_t buf_cnt;
+ size_t buf_cnt;
uint32_t image_size;
uint32_t min_address = 0;
uint32_t max_address = 0xffffffff;
@@ -2519,7 +2519,7 @@ COMMAND_HANDLER(handle_dump_image_command)
int retval = ERROR_OK;
while (size > 0)
{
- uint32_t size_written;
+ size_t size_written;
uint32_t this_run_size = (size > 560) ? 560 : size;
retval = target_read_buffer(target, address, this_run_size, buffer);
if (retval != ERROR_OK)
@@ -2553,7 +2553,7 @@ COMMAND_HANDLER(handle_dump_image_command)
static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
{
uint8_t *buffer;
- uint32_t buf_cnt;
+ size_t buf_cnt;
uint32_t image_size;
int i;
int retval;
@@ -2674,7 +2674,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, int verify)
}
} else
{
- command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08" PRIx32 "",
+ command_print(cmd_ctx, "address 0x%08" PRIx32 " length 0x%08zx",
image.sections[i].base_address,
buf_cnt);
}
@@ -4537,7 +4537,7 @@ static void free_fastload(void)
COMMAND_HANDLER(handle_fast_load_image_command)
{
uint8_t *buffer;
- uint32_t buf_cnt;
+ size_t buf_cnt;
uint32_t image_size;
uint32_t min_address = 0;
uint32_t max_address = 0xffffffff;
diff --git a/src/target/xscale.c b/src/target/xscale.c
index 30ca3bf3..9e93c020 100644
--- a/src/target/xscale.c
+++ b/src/target/xscale.c
@@ -2557,7 +2557,7 @@ static int xscale_read_instruction(struct target *target,
struct xscale_common *xscale = target_to_xscale(target);
int i;
int section = -1;
- uint32_t size_read;
+ size_t size_read;
uint32_t opcode;
int retval;