Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
src/blfwk/ELF.h
1 /*
2  * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #if !defined(_ELF_h_)
31 #define _ELF_h_
32 
35 
36 typedef uint32_t Elf32_Addr;
37 typedef uint16_t Elf32_Half;
38 typedef /*off_t*/ uint32_t Elf32_Off;
39 typedef int32_t Elf32_Sword;
40 typedef uint32_t Elf32_Word;
42 
43 // All ELF structures are byte aligned. Any alignment padding is explicit.
44 #pragma pack(1)
45 
47 
48 
52 enum
53 {
54  EI_MAG0 = 0,
55  EI_MAG1,
56  EI_MAG2,
57  EI_MAG3,
58  EI_CLASS,
59  EI_DATA,
60  EI_VERSION,
61  EI_PAD,
62  EI_NIDENT = 16,
63 
64  // Magic number.
65  ELFMAG0 = 0x7f,
66  ELFMAG1 = 'E',
67  ELFMAG2 = 'L',
68  ELFMAG3 = 'F',
69 
70  // EI_CLASS
71  ELFCLASSNONE = 0,
72  ELFCLASS32 = 1,
73  ELFCLASS64 = 2,
74 
75  // EI_DATA
76  ELFDATANONE = 0,
77  ELFDATA2LSB = 1,
78  ELFDATA2MSB = 2
79 };
80 
84 struct Elf32_Ehdr
85 {
86  unsigned char e_ident[EI_NIDENT];
87  Elf32_Half e_type;
88  Elf32_Half e_machine;
89  Elf32_Word e_version;
90  Elf32_Addr e_entry;
91  Elf32_Off e_phoff;
92  Elf32_Off e_shoff;
93  Elf32_Word e_flags;
94  Elf32_Half e_ehsize;
95  Elf32_Half e_phentsize;
96  Elf32_Half e_phnum;
97  Elf32_Half e_shentsize;
98  Elf32_Half e_shnum;
99  Elf32_Half e_shstrndx;
100 };
101 
105 enum
106 {
107  ET_NONE,
108  ET_REL,
109  ET_EXEC,
110  ET_DYN,
111  ET_CORE,
112  ET_LOPROC,
113  ET_HIPROC
114 };
115 
119 enum
120 {
121  EF_ARM_HASENTRY = 0x02,
122  EF_ARM_SYMSARESORTED = 0x04,
123  EF_ARM_DYNSYMSUSESEGIDX = 0x08,
124  EF_ARM_MAPSYMSFIRST = 0x10,
126  EF_ARM_EABIMASK = 0xff000000,
127 
129  ARM_EABI_VERSION = 0x02000000
130 };
131 
133 
135 
136 
158 struct Elf32_Shdr
159 {
160  Elf32_Word sh_name;
161  Elf32_Word sh_type;
162  Elf32_Word sh_flags;
163  Elf32_Addr sh_addr;
164  Elf32_Off sh_offset;
165  Elf32_Word sh_size;
166  Elf32_Word sh_link;
167  Elf32_Word sh_info;
168  Elf32_Word sh_addralign;
169  Elf32_Word sh_entsize;
170 };
171 
175 enum
176 {
177  SHN_UNDEF = 0,
178  SHN_LORESERVE = 0xff00,
179  SHN_LOPROC = 0xff00,
180  SHN_HIPROC = 0xff1f,
181  SHN_ABS = 0xfff1,
182  SHN_COMMON = 0xfff2,
183  SHN_HIRESERVE = 0xffff
184 };
185 
189 enum
190 {
191  SHT_NULL = 0,
192  SHT_PROGBITS = 1,
193  SHT_SYMTAB = 2,
194  SHT_STRTAB = 3,
195  SHT_RELA = 4,
196  SHT_HASH = 5,
197  SHT_DYNAMIC = 6,
198  SHT_NOTE = 7,
199  SHT_NOBITS = 8,
200  SHT_REL = 9,
201  SHT_SHLIB = 10,
202  SHT_DYNSYM = 11
203 };
204 
208 enum
209 {
210  SHF_WRITE = 0x1,
211  SHF_ALLOC = 0x2,
212  SHF_EXECINSTR = 0x4
213 };
214 
218 enum
219 {
220  SHF_ENTRYSECT = 0x10000000,
221  SHF_COMDEF = 0x80000000
222 };
223 
224 #define BSS_SECTION_NAME ".bss"
225 #define DATA_SECTION_NAME ".data"
226 #define TEXT_SECTION_NAME ".text"
227 #define SHSTRTAB_SECTION_NAME ".shstrtab"
228 #define STRTAB_SECTION_NAME ".strtab"
229 #define SYMTAB_SECTION_NAME ".symtab"
230 
232 
234 
235 
246 struct Elf32_Phdr
247 {
248  Elf32_Word p_type;
249  Elf32_Off p_offset;
250  Elf32_Addr p_vaddr;
251  Elf32_Addr p_paddr;
252  Elf32_Word p_filesz;
253  Elf32_Word p_memsz;
254  Elf32_Word p_flags;
255  Elf32_Word p_align;
256 };
257 
261 enum
262 {
263  PT_NULL = 0,
264  PT_LOAD = 1,
265  PT_DYNAMIC = 2,
266  PT_INTERP = 3,
267  PT_NOTE = 4,
268  PT_SHLIB = 5,
269  PT_PHDR = 6
270 };
271 
275 enum
276 {
277  PF_X = 0x1,
278  PF_W = 0x2,
279  PF_R = 0x4
280 };
281 
283 
285 
286 
287 enum
288 {
289  STN_UNDEF = 0
290 };
291 
300 struct Elf32_Sym
301 {
302  Elf32_Word st_name;
303  Elf32_Addr st_value;
304  Elf32_Word st_size;
305  unsigned char st_info;
306  unsigned char st_other;
307  Elf32_Half st_shndx;
308 };
309 
312 
313 #define ELF32_ST_BIND(i) ((i) >> 4)
314 #define ELF32_ST_TYPE(i) ((i)&0x0f)
315 #define ELF32_ST_INFO(b, t) \
316  (((b) << 4) + ((t)&0x0f))
317 
318 
319 
324 enum
325 {
326  STB_LOCAL = 0,
327  STB_GLOBAL = 1,
328  STB_WEAK = 2,
329 
330  // Processor-specific semantics.
331  STB_LOPROC = 13,
332  STB_HIPROC = 15
333 };
334 
338 enum
339 {
340  STT_NOTYPE = 0,
341  STT_OBJECT = 1,
342  STT_FUNC = 2,
343  STT_SECTION = 3,
344  STT_FILE = 4,
345 
347  STT_LOPROC = 13,
348  STT_HIPROC = 15
349 };
350 
354 enum
355 {
356  STO_THUMB = 1
357 };
358 
359 #define ARM_SEQUENCE_MAPSYM "$a"
360 #define DATA_SEQUENCE_MAPSYM "$d"
361 #define THUMB_SEQUENCE_MAPSYM "$t"
362 
363 #define THUMB_BL_TAGSYM "$b"
364 #define FN_PTR_CONST_TAGSYM "$f"
365 #define INDIRECT_FN_CALL_TAGSYM "$p"
366 #define MAPPING_SYMBOL_COUNT_TAGSYM "$m"
367 
369 
370 #pragma pack()
371 
372 #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_Half e_ehsize
The ELF header&#39;s size in bytes.
Definition: apps/elftosb/common/ELF.h:71
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_Word e_flags
Processor-specific flags associated with the file.
Definition: apps/elftosb/common/ELF.h:70
ELF symbol table entry.
Definition: apps/elftosb/common/ELF.h:277
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_Half e_shentsize
Size in bytes of an entry in the section header table.
Definition: apps/elftosb/common/ELF.h:74
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
ELF file header.
Definition: apps/elftosb/common/ELF.h:61
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_Half e_phnum
Number of entries in the program header table.
Definition: apps/elftosb/common/ELF.h:73
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