diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2010-12-21 11:42:50 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2010-12-21 11:42:50 +0100 |
commit | bb8e7336e4248b21517ed18a75b4d0343a3a0d53 (patch) | |
tree | 3f0c841ee1298a846f2d2a05202a219f6c6ef4b2 /srec.c | |
parent | 5da40cbf6daae35ad4948476bac7827f81ee7904 (diff) |
Diffstat (limited to 'srec.c')
-rw-r--r-- | srec.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -55,10 +55,11 @@ err_out: } static int srec_load_S3(char *buf, size_t data_count, - off_t offset, uint8_t *mem_base, size_t mem_size) + uint32_t load_addr, struct memory *mem) { size_t i; - uint32_t *base = (uint32_t *) mem_base; + size_t mem_size = mem->size; + uint32_t *base = mem->base; for (i = 0; i < data_count; i += 4) { uint32_t tmp; @@ -70,19 +71,19 @@ static int srec_load_S3(char *buf, size_t data_count, /* SREC is Big Endian, NiosII is Little Endian */ tmp = bswap_32(tmp); - if (offset + i >= mem_size) { + if (load_addr + i >= mem_size) { err("Image file too large for allocated memory of %zu bytes\n", mem_size); return -1; } /* Store in memory */ - base[offset / 4 + i] = tmp; + base[(load_addr + i) / 4] = tmp; } return 0; } -static int srec_handle_line(char *buf, size_t len, uint8_t *mem_base, size_t mem_size) +static int srec_handle_line(char *buf, size_t len, struct memory *mem) { unsigned int data_count = 0; unsigned int start_addr; @@ -114,7 +115,10 @@ static int srec_handle_line(char *buf, size_t len, uint8_t *mem_base, size_t mem return -1; } - if (srec_load_S3(buf + 12, data_count - 4, start_addr, mem_base, mem_size) != 0) + if (mem->image_base == IMAGE_BASE_UNINITIALIZED) + mem->image_base = start_addr; + + if (srec_load_S3(buf + 12, data_count - 4, start_addr, mem) != 0) return -1; break; case '4': @@ -143,7 +147,7 @@ static int srec_handle_line(char *buf, size_t len, uint8_t *mem_base, size_t mem return 0; } -int srec_load(FILE *fp, const char *name __unused, uint8_t *mem_base, size_t mem_size) +int srec_load(FILE *fp, const char *name __unused, struct memory *mem) { ssize_t len; int ret = 0; @@ -158,7 +162,7 @@ int srec_load(FILE *fp, const char *name __unused, uint8_t *mem_base, size_t mem ret = 0; break; } else { - ret = srec_handle_line(data_buf, len, mem_base, mem_size); + ret = srec_handle_line(data_buf, len, mem); if (ret < 0) break; } |