2010-12-01 16:17:11 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* API
|
|
|
|
*/
|
|
|
|
enum elf_section_type_t
|
|
|
|
{
|
|
|
|
EST_LOAD,
|
|
|
|
EST_FILL
|
|
|
|
};
|
|
|
|
|
|
|
|
struct elf_section_t
|
|
|
|
{
|
|
|
|
uint32_t addr;
|
|
|
|
uint32_t size;
|
|
|
|
enum elf_section_type_t type;
|
|
|
|
/* <union> */
|
|
|
|
void *section;
|
|
|
|
uint32_t pattern;
|
|
|
|
/* </union> */
|
|
|
|
struct elf_section_t *next;
|
2011-04-17 15:49:58 +00:00
|
|
|
/* Internal to elf_write_file */
|
2010-12-01 16:17:11 +00:00
|
|
|
uint32_t offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct elf_params_t
|
|
|
|
{
|
|
|
|
bool has_start_addr;
|
|
|
|
uint32_t start_addr;
|
|
|
|
struct elf_section_t *first_section;
|
|
|
|
struct elf_section_t *last_section;
|
|
|
|
};
|
|
|
|
|
2011-04-17 15:49:58 +00:00
|
|
|
typedef bool (*elf_read_fn_t)(void *user, uint32_t addr, void *buf, size_t count);
|
|
|
|
/* write function manages it's own error state */
|
2010-12-01 16:17:11 +00:00
|
|
|
typedef void (*elf_write_fn_t)(void *user, uint32_t addr, const void *buf, size_t count);
|
2011-04-17 15:49:58 +00:00
|
|
|
typedef void (*elf_printf_fn_t)(void *user, bool error, const char *fmt, ...);
|
2010-12-01 16:17:11 +00:00
|
|
|
|
|
|
|
void elf_init(struct elf_params_t *params);
|
|
|
|
void elf_add_load_section(struct elf_params_t *params,
|
|
|
|
uint32_t load_addr, uint32_t size, const void *section);
|
|
|
|
void elf_add_fill_section(struct elf_params_t *params,
|
|
|
|
uint32_t fill_addr, uint32_t size, uint32_t pattern);
|
2011-04-17 15:49:58 +00:00
|
|
|
void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, void *user);
|
|
|
|
bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, elf_printf_fn_t printf,
|
|
|
|
void *user);
|
2010-12-01 16:17:11 +00:00
|
|
|
bool elf_is_empty(struct elf_params_t *params);
|
|
|
|
void elf_set_start_addr(struct elf_params_t *params, uint32_t addr);
|
2011-04-17 15:49:58 +00:00
|
|
|
bool elf_get_start_addr(struct elf_params_t *params, uint32_t *addr);
|
|
|
|
int elf_get_nr_sections(struct elf_params_t *params);
|
2010-12-01 16:17:11 +00:00
|
|
|
void elf_release(struct elf_params_t *params);
|