1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2011 Amaury Pouly
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
34 enum elf_section_type_t
42 uint32_t addr
; /* virtual address */
43 uint32_t size
; /* virtual size */
44 enum elf_section_type_t type
;
46 void *section
; /* data */
47 uint32_t pattern
; /* fill pattern */
49 struct elf_section_t
*next
;
50 /* Internal to elf_write_file */
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
;
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
;
73 typedef bool (*elf_read_fn_t
)(void *user
, uint32_t addr
, void *buf
, size_t count
);
74 /* write function manages it's own error state */
75 typedef void (*elf_write_fn_t
)(void *user
, uint32_t addr
, const void *buf
, size_t count
);
76 typedef void (*elf_printf_fn_t
)(void *user
, bool error
, const char *fmt
, ...);
78 void elf_init(struct elf_params_t
*params
);
79 void elf_add_load_section(struct elf_params_t
*params
,
80 uint32_t load_addr
, uint32_t size
, const void *section
);
81 void elf_add_fill_section(struct elf_params_t
*params
,
82 uint32_t fill_addr
, uint32_t size
, uint32_t pattern
);
83 uint32_t elf_translate_virtual_address(struct elf_params_t
*params
, uint32_t addr
);
84 void elf_translate_addresses(struct elf_params_t
*params
);
85 void elf_simplify(struct elf_params_t
*params
);
86 void elf_sort_by_address(struct elf_params_t
*params
);
87 void elf_write_file(struct elf_params_t
*params
, elf_write_fn_t write
, elf_printf_fn_t printf
, void *user
);
88 bool elf_read_file(struct elf_params_t
*params
, elf_read_fn_t read
, elf_printf_fn_t printf
,
90 bool elf_is_empty(struct elf_params_t
*params
);
91 void elf_set_start_addr(struct elf_params_t
*params
, uint32_t addr
);
92 bool elf_get_start_addr(struct elf_params_t
*params
, uint32_t *addr
);
93 int elf_get_nr_sections(struct elf_params_t
*params
);
94 void elf_release(struct elf_params_t
*params
);
96 #endif /* __ELF_H__ */