summaryrefslogtreecommitdiff
path: root/utils/imxtools/elf.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/imxtools/elf.h')
-rw-r--r--utils/imxtools/elf.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/utils/imxtools/elf.h b/utils/imxtools/elf.h
new file mode 100644
index 0000000000..2166833276
--- /dev/null
+++ b/utils/imxtools/elf.h
@@ -0,0 +1,94 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2011 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __ELF_H__
22#define __ELF_H__
23
24#include <stdio.h>
25#include <stdint.h>
26#include <string.h>
27#include <stdbool.h>
28#include <stdlib.h>
29#include <unistd.h>
30
31/**
32 * API
33 */
34enum elf_section_type_t
35{
36 EST_LOAD,
37 EST_FILL
38};
39
40struct elf_section_t
41{
42 uint32_t addr; /* virtual address */
43 uint32_t size; /* virtual size */
44 enum elf_section_type_t type;
45 /* <union> */
46 void *section; /* data */
47 uint32_t pattern; /* fill pattern */
48 /* </union> */
49 struct elf_section_t *next;
50 /* Internal to elf_write_file */
51 uint32_t offset;
52};
53
54struct elf_segment_t
55{
56 uint32_t vaddr; /* virtual address */
57 uint32_t paddr; /* physical address */
58 uint32_t vsize; /* virtual size */
59 uint32_t psize; /* physical size */
60 struct elf_segment_t *next;
61};
62
63struct elf_params_t
64{
65 bool has_start_addr;
66 uint32_t start_addr;
67 struct elf_section_t *first_section;
68 struct elf_section_t *last_section;
69 struct elf_segment_t *first_segment;
70 struct elf_segment_t *last_segment;
71};
72
73typedef bool (*elf_read_fn_t)(void *user, uint32_t addr, void *buf, size_t count);
74/* write function manages it's own error state */
75typedef void (*elf_write_fn_t)(void *user, uint32_t addr, const void *buf, size_t count);
76typedef void (*elf_printf_fn_t)(void *user, bool error, const char *fmt, ...);
77
78void elf_init(struct elf_params_t *params);
79void elf_add_load_section(struct elf_params_t *params,
80 uint32_t load_addr, uint32_t size, const void *section);
81void elf_add_fill_section(struct elf_params_t *params,
82 uint32_t fill_addr, uint32_t size, uint32_t pattern);
83uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr);
84void elf_translate_addresses(struct elf_params_t *params);
85void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, elf_printf_fn_t printf, void *user);
86bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf,
87 void *user);
88bool elf_is_empty(struct elf_params_t *params);
89void elf_set_start_addr(struct elf_params_t *params, uint32_t addr);
90bool elf_get_start_addr(struct elf_params_t *params, uint32_t *addr);
91int elf_get_nr_sections(struct elf_params_t *params);
92void elf_release(struct elf_params_t *params);
93
94#endif /* __ELF_H__ */