2011-09-15 16:10:31 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Amaury Pouly
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __ELF_H__
|
|
|
|
#define __ELF_H__
|
|
|
|
|
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>
|
2013-08-21 20:20:53 +00:00
|
|
|
#include "misc.h"
|
2010-12-01 16:17:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* API
|
|
|
|
*/
|
|
|
|
enum elf_section_type_t
|
|
|
|
{
|
|
|
|
EST_LOAD,
|
|
|
|
EST_FILL
|
|
|
|
};
|
|
|
|
|
|
|
|
struct elf_section_t
|
|
|
|
{
|
2013-07-30 15:12:56 +00:00
|
|
|
char *name;
|
2011-09-15 14:36:58 +00:00
|
|
|
uint32_t addr; /* virtual address */
|
|
|
|
uint32_t size; /* virtual size */
|
2010-12-01 16:17:11 +00:00
|
|
|
enum elf_section_type_t type;
|
|
|
|
/* <union> */
|
2011-09-15 14:36:58 +00:00
|
|
|
void *section; /* data */
|
|
|
|
uint32_t pattern; /* fill pattern */
|
2010-12-01 16:17:11 +00:00
|
|
|
/* </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;
|
|
|
|
};
|
|
|
|
|
2011-09-15 14:36:58 +00:00
|
|
|
struct elf_segment_t
|
|
|
|
{
|
|
|
|
uint32_t vaddr; /* virtual address */
|
|
|
|
uint32_t paddr; /* physical address */
|
|
|
|
uint32_t vsize; /* virtual size */
|
|
|
|
uint32_t psize; /* physical size */
|
|
|
|
struct elf_segment_t *next;
|
|
|
|
};
|
|
|
|
|
2013-08-04 13:04:06 +00:00
|
|
|
enum elf_symbol_type_t
|
|
|
|
{
|
|
|
|
ESYT_NOTYPE,
|
|
|
|
ESYT_OBJECT,
|
|
|
|
ESYT_FUNC,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct elf_symbol_t
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
uint32_t addr;
|
|
|
|
uint32_t size;
|
|
|
|
enum elf_symbol_type_t type;
|
|
|
|
char *section;
|
|
|
|
struct elf_symbol_t *next;
|
|
|
|
};
|
|
|
|
|
2010-12-01 16:17:11 +00:00
|
|
|
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-09-15 14:36:58 +00:00
|
|
|
struct elf_segment_t *first_segment;
|
|
|
|
struct elf_segment_t *last_segment;
|
2013-08-04 13:04:06 +00:00
|
|
|
struct elf_symbol_t *first_symbol;
|
|
|
|
struct elf_symbol_t *last_symbol;
|
2010-12-01 16:17:11 +00:00
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
void elf_init(struct elf_params_t *params);
|
|
|
|
void elf_add_load_section(struct elf_params_t *params,
|
2013-07-30 15:12:56 +00:00
|
|
|
uint32_t load_addr, uint32_t size, const void *section, const char *name);
|
2010-12-01 16:17:11 +00:00
|
|
|
void elf_add_fill_section(struct elf_params_t *params,
|
2013-07-30 15:12:56 +00:00
|
|
|
uint32_t fill_addr, uint32_t size, uint32_t pattern, const char *name);
|
2011-09-15 14:36:58 +00:00
|
|
|
uint32_t elf_translate_virtual_address(struct elf_params_t *params, uint32_t addr);
|
2012-11-27 21:38:48 +00:00
|
|
|
void elf_simplify(struct elf_params_t *params);
|
2012-12-16 20:06:38 +00:00
|
|
|
void elf_sort_by_address(struct elf_params_t *params);
|
2013-08-21 20:20:53 +00:00
|
|
|
void elf_write_file(struct elf_params_t *params, elf_write_fn_t write, generic_printf_t printf, void *user);
|
|
|
|
bool elf_read_file(struct elf_params_t *params, elf_read_fn_t read, generic_printf_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);
|
2011-09-15 16:10:31 +00:00
|
|
|
|
2013-08-04 13:03:29 +00:00
|
|
|
bool elf_guess(elf_read_fn_t read, void *user);
|
|
|
|
|
2013-07-17 22:27:12 +00:00
|
|
|
/* standard implementation of read/write/printf functions
|
|
|
|
* with user being a FILE* pointer */
|
|
|
|
void elf_std_write(void *user, uint32_t addr, const void *buf, size_t count);
|
|
|
|
bool elf_std_read(void *user, uint32_t addr, void *buf, size_t count);
|
|
|
|
|
2011-09-15 16:10:31 +00:00
|
|
|
#endif /* __ELF_H__ */
|