7 #define PRINTF(...) printf(__VA_ARGS__)
9 #define PRINTF(...) do {} while (0)
12 #define ELF32_R_TYPE(info) ((unsigned char)(info))
17 #define R_ARM_THM_CALL 10
21 static uint32_t datamemory_aligned[(ELFLOADER_DATAMEMORY_SIZE+3)/4];
22 static uint8_t* datamemory = (uint8_t *)datamemory_aligned;
23 VAR_AT_SEGMENT (
static const uint16_t textmemory[ELFLOADER_TEXTMEMORY_SIZE/2],
".elf_text") = {0};
28 if(size >
sizeof(datamemory_aligned)){
29 PRINTF(
"RESERVED RAM TOO SMALL\n");
37 if(size >
sizeof(textmemory)){
38 PRINTF(
"RESERVED FLASH TOO SMALL\n");
40 return (
void *)textmemory;
43 #define READSIZE sizeof(datamemory_aligned)
53 for(ptr = 0; ptr < size; ptr += READSIZE) {
56 nbytes = cfs_read(fd, (
unsigned char *)datamemory, READSIZE);
59 stm32w_flash_write((int32u)mem, datamemory, nbytes);
66 unsigned int sectionoffset,
68 struct elf32_rela *rela,
char *addr)
72 type = ELF32_R_TYPE(rela->r_info);
82 cfs_read(fd, (
char*)&addend, 4);
85 cfs_write(fd,&addr,4);
87 PRINTF(
"%p: addr: %p\n", sectionaddr +rela->r_offset,
96 cfs_read(fd, (
char*)instr, 4);
101 base = sectionaddr + (rela->r_offset + 4);
103 if (((instr[1]) & 0xe800) == 0xe800) {
105 if (((uint32_t)addr) & 0x1) {
109 #if defined(__ARM_ARCH_4T__)
119 if ((instr[1] & 0x1800) == 0x0800) {
120 addr = (
char*)((((uint32_t)addr) & 0xfffffffd)
121 | (((uint32_t)base) & 0x00000002));
123 offset = addr - (sectionaddr + (rela->r_offset + 4));
124 PRINTF(
"elfloader-arm.c: offset %d\n", (
int)offset);
125 if (offset < -(1<<22) || offset >= (1<<22)) {
126 PRINTF(
"elfloader-arm.c: offset %d too large for relative call\n",
130 instr[0] = (instr[0] & 0xf800) | ((offset>>12)&0x07ff);
131 instr[1] = (instr[1] & 0xf800) | ((offset>>1)&0x07ff);
132 cfs_write(fd,&instr,4);
139 PRINTF(
"elfloader-arm.c: unsupported relocation type %d\n", type);