Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
apps/elftosb/common/ELF.h
1 /*
2  * File: ELF.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_ELF_h_)
8 #define _ELF_h_
9 
12 
13 typedef uint32_t Elf32_Addr;
14 typedef uint16_t Elf32_Half;
15 typedef /*off_t*/ uint32_t Elf32_Off;
16 typedef int32_t Elf32_Sword;
17 typedef uint32_t Elf32_Word;
19 
20 // All ELF structures are byte aligned. Any alignment padding is explicit.
21 #pragma pack(1)
22 
24 
25 
29 enum
30 {
31  EI_MAG0 = 0,
32  EI_MAG1,
33  EI_MAG2,
34  EI_MAG3,
35  EI_CLASS,
36  EI_DATA,
37  EI_VERSION,
38  EI_PAD,
39  EI_NIDENT = 16,
40 
41  // Magic number.
42  ELFMAG0 = 0x7f,
43  ELFMAG1 = 'E',
44  ELFMAG2 = 'L',
45  ELFMAG3 = 'F',
46 
47  // EI_CLASS
48  ELFCLASSNONE = 0,
49  ELFCLASS32 = 1,
50  ELFCLASS64 = 2,
51 
52  // EI_DATA
53  ELFDATANONE = 0,
54  ELFDATA2LSB = 1,
55  ELFDATA2MSB = 2
56 };
57 
61 struct Elf32_Ehdr
62 {
63  unsigned char e_ident[EI_NIDENT];
64  Elf32_Half e_type;
65  Elf32_Half e_machine;
66  Elf32_Word e_version;
67  Elf32_Addr e_entry;
68  Elf32_Off e_phoff;
69  Elf32_Off e_shoff;
70  Elf32_Word e_flags;
71  Elf32_Half e_ehsize;
72  Elf32_Half e_phentsize;
73  Elf32_Half e_phnum;
74  Elf32_Half e_shentsize;
75  Elf32_Half e_shnum;
76  Elf32_Half e_shstrndx;
77 };
78 
82 enum
83 {
84  ET_NONE,
85  ET_REL,
86  ET_EXEC,
87  ET_DYN,
88  ET_CORE,
89  ET_LOPROC,
90  ET_HIPROC
91 };
92 
96 enum
97 {
98  EF_ARM_HASENTRY = 0x02,
99  EF_ARM_SYMSARESORTED = 0x04,
100  EF_ARM_DYNSYMSUSESEGIDX = 0x08,
101  EF_ARM_MAPSYMSFIRST = 0x10,
103  EF_ARM_EABIMASK = 0xff000000,
104 
106  ARM_EABI_VERSION = 0x02000000
107 };
108 
110 
112 
113 
136 {
137  Elf32_Word sh_name;
138  Elf32_Word sh_type;
139  Elf32_Word sh_flags;
140  Elf32_Addr sh_addr;
141  Elf32_Off sh_offset;
142  Elf32_Word sh_size;
143  Elf32_Word sh_link;
144  Elf32_Word sh_info;
145  Elf32_Word sh_addralign;
146  Elf32_Word sh_entsize;
147 };
148 
152 enum
153 {
154  SHN_UNDEF = 0,
155  SHN_LORESERVE = 0xff00,
156  SHN_LOPROC = 0xff00,
157  SHN_HIPROC = 0xff1f,
158  SHN_ABS = 0xfff1,
159  SHN_COMMON = 0xfff2,
160  SHN_HIRESERVE = 0xffff
161 };
162 
166 enum
167 {
168  SHT_NULL = 0,
169  SHT_PROGBITS = 1,
170  SHT_SYMTAB = 2,
171  SHT_STRTAB = 3,
172  SHT_RELA = 4,
173  SHT_HASH = 5,
174  SHT_DYNAMIC = 6,
175  SHT_NOTE = 7,
176  SHT_NOBITS = 8,
177  SHT_REL = 9,
178  SHT_SHLIB = 10,
179  SHT_DYNSYM = 11
180 };
181 
185 enum
186 {
187  SHF_WRITE = 0x1,
188  SHF_ALLOC = 0x2,
189  SHF_EXECINSTR = 0x4
190 };
191 
195 enum
196 {
197  SHF_ENTRYSECT = 0x10000000,
198  SHF_COMDEF = 0x80000000
199 };
200 
201 #define BSS_SECTION_NAME ".bss"
202 #define DATA_SECTION_NAME ".data"
203 #define TEXT_SECTION_NAME ".text"
204 #define SHSTRTAB_SECTION_NAME ".shstrtab"
205 #define STRTAB_SECTION_NAME ".strtab"
206 #define SYMTAB_SECTION_NAME ".symtab"
207 
209 
211 
212 
224 {
225  Elf32_Word p_type;
226  Elf32_Off p_offset;
227  Elf32_Addr p_vaddr;
228  Elf32_Addr p_paddr;
229  Elf32_Word p_filesz;
230  Elf32_Word p_memsz;
231  Elf32_Word p_flags;
232  Elf32_Word p_align;
233 };
234 
238 enum
239 {
240  PT_NULL = 0,
241  PT_LOAD = 1,
242  PT_DYNAMIC = 2,
243  PT_INTERP = 3,
244  PT_NOTE = 4,
245  PT_SHLIB = 5,
246  PT_PHDR = 6
247 };
248 
252 enum
253 {
254  PF_X = 0x1,
255  PF_W = 0x2,
256  PF_R = 0x4
257 };
258 
260 
262 
263 
264 enum
265 {
266  STN_UNDEF = 0
267 };
268 
277 struct Elf32_Sym
278 {
279  Elf32_Word st_name;
280  Elf32_Addr st_value;
281  Elf32_Word st_size;
282  unsigned char st_info;
283  unsigned char st_other;
284  Elf32_Half st_shndx;
285 };
286 
289 
290 #define ELF32_ST_BIND(i) ((i) >> 4)
291 #define ELF32_ST_TYPE(i) ((i)&0x0f)
292 #define ELF32_ST_INFO(b, t) \
293  (((b) << 4) + ((t)&0x0f))
294 
295 
296 
301 enum
302 {
303  STB_LOCAL = 0,
304  STB_GLOBAL = 1,
305  STB_WEAK = 2,
306 
307  // Processor-specific semantics.
308  STB_LOPROC = 13,
309  STB_HIPROC = 15
310 };
311 
315 enum
316 {
317  STT_NOTYPE = 0,
318  STT_OBJECT = 1,
319  STT_FUNC = 2,
320  STT_SECTION = 3,
321  STT_FILE = 4,
322 
324  STT_LOPROC = 13,
325  STT_HIPROC = 15
326 };
327 
331 enum
332 {
333  STO_THUMB = 1
334 };
335 
336 #define ARM_SEQUENCE_MAPSYM "$a"
337 #define DATA_SEQUENCE_MAPSYM "$d"
338 #define THUMB_SEQUENCE_MAPSYM "$t"
339 
340 #define THUMB_BL_TAGSYM "$b"
341 #define FN_PTR_CONST_TAGSYM "$f"
342 #define INDIRECT_FN_CALL_TAGSYM "$p"
343 #define MAPPING_SYMBOL_COUNT_TAGSYM "$m"
344 
346 
347 #pragma pack()
348 
349 #endif // _ELF_h_
Elf32_Half e_phentsize
Size in bytes of one entry in the program header table.
Definition: apps/elftosb/common/ELF.h:72
ELF section header.
Definition: apps/elftosb/common/ELF.h:135
Elf32_Word sh_link
Section header table link index. Interpretation depends on section type.
Definition: apps/elftosb/common/ELF.h:143
Elf32_Off p_offset
Offset in bytes from start of file to the first byte of the segment.
Definition: apps/elftosb/common/ELF.h:226
Elf32_Half e_ehsize
The ELF header&#39;s size in bytes.
Definition: apps/elftosb/common/ELF.h:71
Elf32_Word st_size
Size associated with symbol. 0 if the symbol has no size or an unknown size.
Definition: apps/elftosb/common/ELF.h:281
Elf32_Word p_memsz
Size in bytes of the segment in memory. May be zero.
Definition: apps/elftosb/common/ELF.h:230
Elf32_Half st_shndx
Section header table index for this symbol.
Definition: apps/elftosb/common/ELF.h:284
Elf32_Word p_filesz
Number of bytes of file data the segment consumes. May be zero.
Definition: apps/elftosb/common/ELF.h:229
Elf32_Addr p_paddr
Physical address, for systems where this is relevant.
Definition: apps/elftosb/common/ELF.h:228
Elf32_Word sh_name
The section&#39;s name. Index into the section header string table section.
Definition: apps/elftosb/common/ELF.h:137
Elf32_Word sh_type
Section type, describing the contents and semantics.
Definition: apps/elftosb/common/ELF.h:138
Elf32_Word p_align
Alignment constraint for segment addresses. Possible values are 0 and positive powers of 2...
Definition: apps/elftosb/common/ELF.h:232
Elf32_Word p_flags
Flags relevant to the segment.
Definition: apps/elftosb/common/ELF.h:231
ELF program header.
Definition: apps/elftosb/common/ELF.h:223
Elf32_Half e_shstrndx
Section header table index of the section name string table.
Definition: apps/elftosb/common/ELF.h:76
unsigned char e_ident[EI_NIDENT]
Magic number identifying the file format.
Definition: apps/elftosb/common/ELF.h:63
Elf32_Addr sh_addr
The address at which the section will appear in the memory image, or 0.
Definition: apps/elftosb/common/ELF.h:140
Elf32_Word e_flags
Processor-specific flags associated with the file.
Definition: apps/elftosb/common/ELF.h:70
unsigned char st_info
Specified the symbol&#39;s type and binding attributes.
Definition: apps/elftosb/common/ELF.h:282
ELF symbol table entry.
Definition: apps/elftosb/common/ELF.h:277
Elf32_Addr p_vaddr
Virtual address at which the segment will reside in memory.
Definition: apps/elftosb/common/ELF.h:227
Elf32_Off e_phoff
Program header table offset in bytes, or 0 if no program header table.
Definition: apps/elftosb/common/ELF.h:68
Elf32_Word st_name
Index into file&#39;s string table.
Definition: apps/elftosb/common/ELF.h:279
Elf32_Word sh_size
The section&#39;s size in bytes.
Definition: apps/elftosb/common/ELF.h:142
Elf32_Half e_shentsize
Size in bytes of an entry in the section header table.
Definition: apps/elftosb/common/ELF.h:74
Elf32_Word sh_addralign
Address alignment constraint. Values are 0 and positive powers of 2.
Definition: apps/elftosb/common/ELF.h:145
Elf32_Half e_type
Identifies the object file format.
Definition: apps/elftosb/common/ELF.h:64
Elf32_Half e_shnum
Number of entries in the section header table.
Definition: apps/elftosb/common/ELF.h:75
Elf32_Word sh_flags
Section flags describing various attributes.
Definition: apps/elftosb/common/ELF.h:139
ELF file header.
Definition: apps/elftosb/common/ELF.h:61
unsigned char st_other
Currently 0 (reserved).
Definition: apps/elftosb/common/ELF.h:283
Elf32_Word e_version
Object file version.
Definition: apps/elftosb/common/ELF.h:66
Elf32_Half e_machine
Specified the architecture for the object file.
Definition: apps/elftosb/common/ELF.h:65
Elf32_Word sh_entsize
Size in bytes of section entries, or 0 if the section does not have fixed-size entries.
Definition: apps/elftosb/common/ELF.h:146
Elf32_Off sh_offset
Offset from beginning of the file to the first byte in the section.
Definition: apps/elftosb/common/ELF.h:141
Elf32_Addr st_value
Value associated with the symbol. Depends on context.
Definition: apps/elftosb/common/ELF.h:280
Elf32_Half e_phnum
Number of entries in the program header table.
Definition: apps/elftosb/common/ELF.h:73
Elf32_Word p_type
What type of segment this header describes.
Definition: apps/elftosb/common/ELF.h:225
Elf32_Word sh_info
Extra information about the section. Depends on section type.
Definition: apps/elftosb/common/ELF.h:144
Elf32_Off e_shoff
Section header table offset in bytes, or 0 if no section header table.
Definition: apps/elftosb/common/ELF.h:69
Elf32_Addr e_entry
Virtual address of the entry point, or 0.
Definition: apps/elftosb/common/ELF.h:67