mem_end = mend;
}
+ if (data_start < *location) {
+ data_start = *location;
+ }
+
+ if (data_end <= data_start) {
+ fprintf(stderr, "E: data ends before it starts. Make sure the ELF file is correct and resides in ROM space.\n");
+ exit(1);
+ }
+
/* allocate an intermediate buffer for the data */
buffer = calloc(data_end - data_start, 1);
/* Copy the file data into the buffer */
for (i = 0; i < headers; i++) {
+ unsigned int l_start, l_offset = 0;
if (elf32_to_native(phdr[i].p_type) != PT_LOAD)
continue;
if (elf32_to_native(phdr[i].p_memsz) == 0)
continue;
- memcpy(buffer + (elf32_to_native(phdr[i].p_paddr) - data_start),
- &header[elf32_to_native(phdr[i].p_offset)],
- elf32_to_native(phdr[i].p_filesz));
+ l_start = elf32_to_native(phdr[i].p_paddr);
+ if (l_start < *location) {
+ l_offset = *location - l_start;
+ l_start = *location;
+ }
+
+ memcpy(buffer + (l_start - data_start),
+ &header[elf32_to_native(phdr[i].p_offset)+l_offset],
+ elf32_to_native(phdr[i].p_filesz)-l_offset);
}
/* Now make the output buffer */