Home

Awesome

elfloader

For contributing list see CONTRIBUTORS.md

ARMv7M ELF loader

The goal of this project is provide a loader for ELF file format for ARMv7-M (thumb-2) architecture (Aka Cortex-M, Cortex-R in Thumb2 mode) over bare-metal or RTOS enviroment.

This loader not required MMU or special OS support (only aligned memory alloc) and run with minimun memory overhead (only required parts of files is loaded in memory).

This is developed using gcc arm embedded compiler from GCC arm embedded (arm-none-eabi) but is successful tested with linaro arm-linux-gnueabihf in freestangin mode.

ELF creation

For correct handling, The code must be compiled with certain characteristics:

Additionally, following memory sections are recognized: .sdram_data, .sdram_rodata, .sdram_bss.

An example of application is found in the app folder

Usage

The API is simple, first call to #load_elf to obtain an execution context.

    extern int load_elf(const char *path, const ELFEnv_t *env, ELFExec_t **exec);

This function take a path to a file, and ELFEnv_t is a struct containing:

	typedef struct {
	  const ELFSymbol_t *exported;
	  size_t exported_size;
	} ELFEnv_t;

Then, #jumpTo and #get_func calls can be made:

    extern int jumpTo(ELFExec_t *exec);

to execute code at the entry point of the ELF.

Use

    extern void * get_func(ELFExec_t *exec, const char *func_name);

to obtain a function pointer corresponding to a (mangled) symbol name.

And

    extern void * get_obj(ELFExec_t *exec, const char *obj_name);

to obtain a pointer corresponding to a global variable.

Finally, the execution context can be cleaned up:

    extern int unload_elf(ELFExec_t *exec);

Loader config

File handling macros
Memory manager/access
Code execution
Debug/message