| 53 | */ |
| 54 | |
| 55 | static int esp_elf_load_section(esp_elf_t *elf, const uint8_t *pbuf) |
| 56 | { |
| 57 | uint32_t entry; |
| 58 | uint32_t size; |
| 59 | |
| 60 | const elf32_hdr_t *ehdr = (const elf32_hdr_t *)pbuf; |
| 61 | const elf32_shdr_t *shdr = (const elf32_shdr_t *)(pbuf + ehdr->shoff); |
| 62 | const char *shstrab = (const char *)pbuf + shdr[ehdr->shstrndx].offset; |
| 63 | |
| 64 | /* Calculate ELF image size */ |
| 65 | |
| 66 | for (uint32_t i = 0; i < ehdr->shnum; i++) { |
| 67 | const char *name = shstrab + shdr[i].name; |
| 68 | |
| 69 | if (stype(&shdr[i], SHT_PROGBITS) && sflags(&shdr[i], SHF_ALLOC)) { |
| 70 | if (sflags(&shdr[i], SHF_EXECINSTR) && !strcmp(ELF_TEXT, name)) { |
| 71 | ESP_LOGD(TAG, ".text sec addr=0x%08x size=0x%08x offset=0x%08x", |
| 72 | shdr[i].addr, shdr[i].size, shdr[i].offset); |
| 73 | |
| 74 | elf->sec[ELF_SEC_TEXT].v_addr = shdr[i].addr; |
| 75 | elf->sec[ELF_SEC_TEXT].size = ELF_ALIGN(shdr[i].size, 4); |
| 76 | elf->sec[ELF_SEC_TEXT].offset = shdr[i].offset; |
| 77 | |
| 78 | ESP_LOGD(TAG, ".text offset is 0x%lx size is 0x%x", |
| 79 | elf->sec[ELF_SEC_TEXT].offset, |
| 80 | elf->sec[ELF_SEC_TEXT].size); |
| 81 | } else if (sflags(&shdr[i], SHF_WRITE) && !strcmp(ELF_DATA, name)) { |
| 82 | ESP_LOGD(TAG, ".data sec addr=0x%08x size=0x%08x offset=0x%08x", |
| 83 | shdr[i].addr, shdr[i].size, shdr[i].offset); |
| 84 | |
| 85 | elf->sec[ELF_SEC_DATA].v_addr = shdr[i].addr; |
| 86 | elf->sec[ELF_SEC_DATA].size = shdr[i].size; |
| 87 | elf->sec[ELF_SEC_DATA].offset = shdr[i].offset; |
| 88 | |
| 89 | ESP_LOGD(TAG, ".data offset is 0x%lx size is 0x%x", |
| 90 | elf->sec[ELF_SEC_DATA].offset, |
| 91 | elf->sec[ELF_SEC_DATA].size); |
| 92 | } else if (!strcmp(ELF_RODATA, name)) { |
| 93 | ESP_LOGD(TAG, ".rodata sec addr=0x%08x size=0x%08x offset=0x%08x", |
| 94 | shdr[i].addr, shdr[i].size, shdr[i].offset); |
| 95 | |
| 96 | elf->sec[ELF_SEC_RODATA].v_addr = shdr[i].addr; |
| 97 | elf->sec[ELF_SEC_RODATA].size = shdr[i].size; |
| 98 | elf->sec[ELF_SEC_RODATA].offset = shdr[i].offset; |
| 99 | |
| 100 | ESP_LOGD(TAG, ".rodata offset is 0x%lx size is 0x%x", |
| 101 | elf->sec[ELF_SEC_RODATA].offset, |
| 102 | elf->sec[ELF_SEC_RODATA].size); |
| 103 | } else if (!strcmp(ELF_DATA_REL_RO, name)) { |
| 104 | ESP_LOGD(TAG, ".data.rel.ro sec addr=0x%08x size=0x%08x offset=0x%08x", |
| 105 | shdr[i].addr, shdr[i].size, shdr[i].offset); |
| 106 | |
| 107 | elf->sec[ELF_SEC_DRLRO].v_addr = shdr[i].addr; |
| 108 | elf->sec[ELF_SEC_DRLRO].size = shdr[i].size; |
| 109 | elf->sec[ELF_SEC_DRLRO].offset = shdr[i].offset; |
| 110 | |
| 111 | ESP_LOGD(TAG, ".data.rel.ro offset is 0x%lx size is 0x%x", |
| 112 | elf->sec[ELF_SEC_DRLRO].offset, |
no test coverage detected