- c.cmd = CMD_FINISH_WRITE;
- c.arg[0] = (ExpectedAddr-1) & (~255);
- if(translate) {
- c.arg[0] -= PHYSICAL_FLASH_START;
- }
- printf("c.arg[0] = %08x\r", c.arg[0]);
- memcpy(c.d.asBytes, QueuedToSend+240, 16);
- SendCommand(&c);
- WaitForAck();
+ fprintf(stderr, "Loading usable ELF segments:\n");
+ for (int i = 0; i < num_phdrs; i++) {
+ if (le32(phdr->p_type) != PT_LOAD) {
+ phdr++;
+ continue;
+ }
+ uint32_t vaddr = le32(phdr->p_vaddr);
+ uint32_t paddr = le32(phdr->p_paddr);
+ uint32_t filesz = le32(phdr->p_filesz);
+ uint32_t memsz = le32(phdr->p_memsz);
+ uint32_t offset = le32(phdr->p_offset);
+ uint32_t flags = le32(phdr->p_flags);
+ if (!filesz) {
+ phdr++;
+ continue;
+ }
+ fprintf(stderr, "%d: V 0x%08x P 0x%08x (0x%08x->0x%08x) [%c%c%c] @0x%x\n",
+ i, vaddr, paddr, filesz, memsz,
+ flags & PF_R ? 'R' : ' ',
+ flags & PF_W ? 'W' : ' ',
+ flags & PF_X ? 'X' : ' ',
+ offset);
+ if (filesz != memsz) {
+ fprintf(stderr, "Error: PHDR file size does not equal memory size\n"
+ "(DATA+BSS PHDRs do not make sense on ROM platforms!)\n");
+ return -1;
+ }
+ if (paddr < last_end) {
+ fprintf(stderr, "Error: PHDRs not sorted or overlap\n");
+ return -1;
+ }
+ if (paddr < FLASH_START || (paddr+filesz) > FLASH_END) {
+ fprintf(stderr, "Error: PHDR is not contained in Flash\n");
+ return -1;
+ }
+ if (vaddr >= FLASH_START && vaddr < FLASH_END && (flags & PF_W)) {
+ fprintf(stderr, "Error: Flash VMA segment is writable\n");
+ return -1;
+ }