summaryrefslogtreecommitdiff
path: root/utils/sbtools/elf.h
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2011-04-17 15:49:58 +0000
committerAmaury Pouly <pamaury@rockbox.org>2011-04-17 15:49:58 +0000
commitc4cb4cca47091978be0c557bcc0b2fbdca7c3b61 (patch)
tree8442635026d4c2d38b22c630be96a415c95d3dd6 /utils/sbtools/elf.h
parent204a2e920acd94090e5be12b009fc71ddee8fabc (diff)
downloadrockbox-c4cb4cca47091978be0c557bcc0b2fbdca7c3b61.tar.gz
rockbox-c4cb4cca47091978be0c557bcc0b2fbdca7c3b61.zip
sbtools: move internal elf definition to elf.c, implement elf reading
sbtoelf: generate a correct section name for undef and string table sections elftosb: static'ify functions, add cmd file to sb file conversion git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29738 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/sbtools/elf.h')
-rw-r--r--utils/sbtools/elf.h141
1 files changed, 9 insertions, 132 deletions
diff --git a/utils/sbtools/elf.h b/utils/sbtools/elf.h
index d2bf210c5c..b145bfffc5 100644
--- a/utils/sbtools/elf.h
+++ b/utils/sbtools/elf.h
@@ -6,136 +6,6 @@
6#include <unistd.h> 6#include <unistd.h>
7 7
8/** 8/**
9 * Definitions
10 * taken from elf.h linux header
11 * based on ELF specification
12 * based on ARM ELF specification
13 */
14typedef uint16_t Elf32_Half;
15
16typedef uint32_t Elf32_Word;
17typedef int32_t Elf32_Sword;
18typedef uint32_t Elf32_Addr;
19typedef uint32_t Elf32_Off;
20typedef uint16_t Elf32_Section;
21
22#define EI_NIDENT 16
23
24typedef struct
25{
26 unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
27 Elf32_Half e_type; /* Object file type */
28 Elf32_Half e_machine; /* Architecture */
29 Elf32_Word e_version; /* Object file version */
30 Elf32_Addr e_entry; /* Entry point virtual address */
31 Elf32_Off e_phoff; /* Program header table file offset */
32 Elf32_Off e_shoff; /* Section header table file offset */
33 Elf32_Word e_flags; /* Processor-specific flags */
34 Elf32_Half e_ehsize; /* ELF header size in bytes */
35 Elf32_Half e_phentsize; /* Program header table entry size */
36 Elf32_Half e_phnum; /* Program header table entry count */
37 Elf32_Half e_shentsize; /* Section header table entry size */
38 Elf32_Half e_shnum; /* Section header table entry count */
39 Elf32_Half e_shstrndx; /* Section header string table index */
40}Elf32_Ehdr;
41
42#define EI_MAG0 0 /* File identification byte 0 index */
43#define ELFMAG0 0x7f /* Magic number byte 0 */
44
45#define EI_MAG1 1 /* File identification byte 1 index */
46#define ELFMAG1 'E' /* Magic number byte 1 */
47
48#define EI_MAG2 2 /* File identification byte 2 index */
49#define ELFMAG2 'L' /* Magic number byte 2 */
50
51#define EI_MAG3 3 /* File identification byte 3 index */
52#define ELFMAG3 'F' /* Magic number byte 3 */
53
54#define EI_CLASS 4 /* File class byte index */
55#define ELFCLASS32 1 /* 32-bit objects */
56
57#define EI_DATA 5 /* Data encoding byte index */
58#define ELFDATA2LSB 1 /* 2's complement, little endian */
59
60#define EI_VERSION 6 /* File version byte index, Value must be EV_CURRENT */
61
62#define EI_OSABI 7 /* OS ABI identification */
63#define ELFOSABI_NONE 0 /* UNIX System V ABI */
64#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */
65#define ELFOSABI_ARM 97 /* ARM */
66
67#define EI_ABIVERSION 8 /* ABI version */
68
69#define EI_PAD 9 /* Byte index of padding bytes */
70
71#define ET_EXEC 2 /* Executable file */
72
73#define EM_ARM 40 /* ARM */
74
75#define EV_CURRENT 1 /* Current version */
76
77#define EF_ARM_HASENTRY 0x00000002
78
79#define SHN_UNDEF 0 /* Undefined section */
80
81typedef struct
82{
83 Elf32_Word sh_name; /* Section name (string tbl index) */
84 Elf32_Word sh_type; /* Section type */
85 Elf32_Word sh_flags; /* Section flags */
86 Elf32_Addr sh_addr; /* Section virtual addr at execution */
87 Elf32_Off sh_offset; /* Section file offset */
88 Elf32_Word sh_size; /* Section size in bytes */
89 Elf32_Word sh_link; /* Link to another section */
90 Elf32_Word sh_info; /* Additional section information */
91 Elf32_Word sh_addralign; /* Section alignment */
92 Elf32_Word sh_entsize; /* Entry size if section holds table */
93}Elf32_Shdr;
94
95#define SHT_NULL 0 /* Section header table entry unused */
96#define SHT_PROGBITS 1 /* Program data */
97#define SHT_SYMTAB 2 /* Symbol table */
98#define SHT_STRTAB 3 /* String table */
99#define SHT_RELA 4 /* Relocation entries with addends */
100#define SHT_HASH 5 /* Symbol hash table */
101#define SHT_DYNAMIC 6 /* Dynamic linking information */
102#define SHT_NOTE 7 /* Notes */
103#define SHT_NOBITS 8 /* Program space with no data (bss) */
104#define SHT_REL 9 /* Relocation entries, no addends */
105#define SHT_SHLIB 10 /* Reserved */
106#define SHT_DYNSYM 11 /* Dynamic linker symbol table */
107#define SHT_INIT_ARRAY 14 /* Array of constructors */
108#define SHT_FINI_ARRAY 15 /* Array of destructors */
109#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
110#define SHT_GROUP 17 /* Section group */
111#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
112#define SHT_NUM 19 /* Number of defined types. */
113
114#define SHF_WRITE (1 << 0) /* Writable */
115#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */
116#define SHF_EXECINSTR (1 << 2) /* Executable */
117#define SHF_MERGE (1 << 4) /* Might be merged */
118#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */
119
120typedef struct
121{
122 Elf32_Word p_type; /* Segment type */
123 Elf32_Off p_offset; /* Segment file offset */
124 Elf32_Addr p_vaddr; /* Segment virtual address */
125 Elf32_Addr p_paddr; /* Segment physical address */
126 Elf32_Word p_filesz; /* Segment size in file */
127 Elf32_Word p_memsz; /* Segment size in memory */
128 Elf32_Word p_flags; /* Segment flags */
129 Elf32_Word p_align; /* Segment alignment */
130}Elf32_Phdr;
131
132#define PT_LOAD 1 /* Loadable program segment */
133
134#define PF_X (1 << 0) /* Segment is executable */
135#define PF_W (1 << 1) /* Segment is writable */
136#define PF_R (1 << 2) /* Segment is readable */
137
138/**
139 * API 9 * API
140 */ 10 */
141enum elf_section_type_t 11enum elf_section_type_t
@@ -154,7 +24,7 @@ struct elf_section_t
154 uint32_t pattern; 24 uint32_t pattern;
155 /* </union> */ 25 /* </union> */
156 struct elf_section_t *next; 26 struct elf_section_t *next;
157 /* Internal to elf_output */ 27 /* Internal to elf_write_file */
158 uint32_t offset; 28 uint32_t offset;
159}; 29};
160 30
@@ -166,14 +36,21 @@ struct elf_params_t
166 struct elf_section_t *last_section; 36 struct elf_section_t *last_section;
167}; 37};
168 38
39typedef bool (*elf_read_fn_t)(void *user, uint32_t addr, void *buf, size_t count);
40/* write function manages it's own error state */
169typedef void (*elf_write_fn_t)(void *user, uint32_t addr, const void *buf, size_t count); 41typedef void (*elf_write_fn_t)(void *user, uint32_t addr, const void *buf, size_t count);
42typedef void (*elf_printf_fn_t)(void *user, bool error, const char *fmt, ...);
170 43
171void elf_init(struct elf_params_t *params); 44void elf_init(struct elf_params_t *params);
172void elf_add_load_section(struct elf_params_t *params, 45void elf_add_load_section(struct elf_params_t *params,
173 uint32_t load_addr, uint32_t size, const void *section); 46 uint32_t load_addr, uint32_t size, const void *section);
174void elf_add_fill_section(struct elf_params_t *params, 47void elf_add_fill_section(struct elf_params_t *params,
175 uint32_t fill_addr, uint32_t size, uint32_t pattern); 48 uint32_t fill_addr, uint32_t size, uint32_t pattern);
176void elf_output(struct elf_params_t *params, elf_write_fn_t write, void *user); 49void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *user);
50bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf,
51 void *user);
177bool elf_is_empty(struct elf_params_t *params); 52bool elf_is_empty(struct elf_params_t *params);
178void elf_set_start_addr(struct elf_params_t *params, uint32_t addr); 53void elf_set_start_addr(struct elf_params_t *params, uint32_t addr);
54bool elf_get_start_addr(struct elf_params_t *params, uint32_t *addr);
55int elf_get_nr_sections(struct elf_params_t *params);
179void elf_release(struct elf_params_t *params); 56void elf_release(struct elf_params_t *params);