43 #define PRINTF(...) printf(__VA_ARGS__)
45 #define PRINTF(...) do {} while (0)
48 #define ELF32_R_TYPE(info) ((unsigned char)(info))
52 #define R_ARM_THM_CALL 10
56 static uint32_t datamemory_aligned[(ELFLOADER_DATAMEMORY_SIZE + 3) / 4];
57 static uint8_t *datamemory = (uint8_t *) datamemory_aligned;
61 textmemory[ELFLOADER_TEXTMEMORY_SIZE / 2],
".elf_text") = {0};
66 if(size >
sizeof(datamemory_aligned)) {
67 PRINTF(
"RESERVED RAM TOO SMALL\n");
75 if(size >
sizeof(textmemory)) {
76 PRINTF(
"RESERVED FLASH TOO SMALL\n");
78 return (
void *)textmemory;
81 #define READSIZE sizeof(datamemory_aligned)
91 for(ptr = 0; ptr < size; ptr += READSIZE) {
93 nbytes = cfs_read(fd, (
unsigned char *)datamemory, READSIZE);
95 stm32w_flash_write((uint32_t) mem, datamemory, nbytes);
101 unsigned int sectionoffset,
103 struct elf32_rela *rela,
char *addr)
106 type = ELF32_R_TYPE(rela->r_info);
114 cfs_read(fd, (
char *)&addend, 4);
117 cfs_write(fd, &addr, 4);
119 PRINTF(
"%p: addr: %p\n", sectionaddr + rela->r_offset, addr);
127 cfs_read(fd, (
char *)instr, 4);
135 base = sectionaddr + (rela->r_offset + 4);
136 if(((instr[1]) & 0xe800) == 0xe800) {
138 if(((uint32_t) addr) & 0x1) {
142 #if defined(__ARM_ARCH_4T__)
153 if((instr[1] & 0x1800) == 0x0800) {
154 addr = (
char *)((((uint32_t) addr) & 0xfffffffd) |
155 (((uint32_t) base) & 0x00000002));
157 offset = addr - (sectionaddr + (rela->r_offset + 4));
158 PRINTF(
"elfloader-arm.c: offset %d\n", (
int)offset);
159 if(offset < -(1 << 22) || offset >= (1 << 22)) {
160 PRINTF(
"elfloader-arm.c: offset %d too large for relative call\n",
164 instr[0] = (instr[0] & 0xf800) | ((offset >> 12) & 0x07ff);
165 instr[1] = (instr[1] & 0xf800) | ((offset >> 1) & 0x07ff);
166 cfs_write(fd, &instr, 4);
173 PRINTF(
"elfloader-arm.c: unsupported relocation type %d\n", type);
void elfloader_arch_relocate(int fd, unsigned int sectionoffset, char *sectionaddr, struct elf32_rela *rela, char *addr)
Perform a relocation.
cfs_offset_t cfs_seek(int fd, cfs_offset_t offset, int whence)
Seek to a specified position in an open file.
#define CFS_SEEK_CUR
Specify that cfs_seek() should compute the offset from the current position of the file pointer...
Header file for the architecture specific parts of the Contiki ELF loader.
#define VAR_AT_SEGMENT(__variableDeclaration, __segmentName)
Provide a portable way to specify the segment where a variable lives.
void * elfloader_arch_allocate_ram(int size)
Allocate RAM for a new module.
#define ELFLOADER_UNHANDLED_RELOC
Return value from elfloader_load() indicating that the ELF file contained a relocation type that the ...
Coffee architecture-dependent header for the STM32W108-based mb851 platform.
void * elfloader_arch_allocate_rom(int size)
Allocate program memory for a new module.
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file. ...
void elfloader_arch_write_rom(int fd, unsigned short textoff, unsigned int size, char *mem)
Write to read-only memory (for example the text segment).