summaryrefslogtreecommitdiff
path: root/srec.c
diff options
context:
space:
mode:
Diffstat (limited to 'srec.c')
-rw-r--r--srec.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/srec.c b/srec.c
index 7c3aaf4..9179317 100644
--- a/srec.c
+++ b/srec.c
@@ -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;
}