All Projects → martinribelotta → elfloader

martinribelotta / elfloader

Licence: other
ARMv7M ELF loader

Programming Languages

c
50402 projects - #5 most used programming language
assembly
5116 projects

Projects that are alternatives of or similar to elfloader

CML
Fast, safe and easy to use Cortex-M HAL Library, written in C++ 17
Stars: ✭ 17 (-76.06%)
Mutual labels:  arm, cortex, bare-metal
drone-stm32-map
STM32 peripheral mappings for Drone, an Embedded Operating System.
Stars: ✭ 16 (-77.46%)
Mutual labels:  arm, cortex, bare-metal
drone-cortexm
ARM® Cortex®-M platform crate for Drone, an Embedded Operating System.
Stars: ✭ 31 (-56.34%)
Mutual labels:  arm, cortex, bare-metal
V60Mini-firmhack
A project to disassemble the KBParadise V60 Mini keyboard firmware.
Stars: ✭ 23 (-67.61%)
Mutual labels:  arm, armv7, thumb2
Shecc
A self-hosting and educational C compiler
Stars: ✭ 286 (+302.82%)
Mutual labels:  arm, armv7, elf
Atmel Software Package
Atmel Software Package
Stars: ✭ 81 (+14.08%)
Mutual labels:  arm, bare-metal
Docker Jdownloader
JDownloader 2 Docker Image (Multiarch) - Passed 40M Downloads
Stars: ✭ 85 (+19.72%)
Mutual labels:  arm, armv7
Gitlab
GitLab CE (Docker image) for ARM devices, this is a mirror repository of
Stars: ✭ 121 (+70.42%)
Mutual labels:  arm, armv7
Arm Assembly Cheat
MOVED TO: https://github.com/cirosantilli/linux-kernel-module-cheat#userland-assembly SEE README. ARMv7 and ARMv8 assembly userland minimal examples tutorial. Runnable asserts on x86 hosts with QEMU user mode or natively on ARM targets. Nice GDB step debug setup. Tested on Ubuntu 18.04 host and Raspberry Pi 2 and 3 targets.
Stars: ✭ 159 (+123.94%)
Mutual labels:  arm, armv7
Cortex M Rtic
Real-Time Interrupt-driven Concurrency (RTIC) framework for ARM Cortex-M microcontrollers
Stars: ✭ 623 (+777.46%)
Mutual labels:  arm, bare-metal
Aros
Main AROS repository for active development. Contains the main Operating System components and Build System.
Stars: ✭ 146 (+105.63%)
Mutual labels:  arm, bare-metal
Computelibrary
The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
Stars: ✭ 2,123 (+2890.14%)
Mutual labels:  arm, armv7
Reverse Engineering
This repository contains some of the executables that I've cracked.
Stars: ✭ 29 (-59.15%)
Mutual labels:  arm, armv7
Ferret
Ferret is a free software lisp implementation for real time embedded control systems.
Stars: ✭ 878 (+1136.62%)
Mutual labels:  arm, bare-metal
Nwjs rpi
[NW.js port for Raspberry Pi] binary compiled for the ARMv6 used in Raspberry Pi (compatible with RPi 2 and RPi 3)
Stars: ✭ 91 (+28.17%)
Mutual labels:  arm, armv7
Element Web
element.io docker image generator
Stars: ✭ 21 (-70.42%)
Mutual labels:  arm, armv7
Synestiaos
The Synestia Operating System
Stars: ✭ 159 (+123.94%)
Mutual labels:  arm, armv7
Gnu Eprog
Embedded Programming with the GNU Toolchain
Stars: ✭ 230 (+223.94%)
Mutual labels:  arm, bare-metal
Baremetal Arm
An ebook about bare-metal programming for ARM
Stars: ✭ 222 (+212.68%)
Mutual labels:  arm, bare-metal
discolix
distroless arm docker images
Stars: ✭ 22 (-69.01%)
Mutual labels:  arm, armv7

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:

  • No common section is allowed. All non-init data is in bss (CC -fno-common)
  • Only word relocation is allowed. (CC -mword-relocation) This is not realy true, some compilers produce R_ARM_THB_CALL/JMP relocation and ignore word-relocation flags, therefore, the loader handling only two relocation:
    • R_ARM_ABS32 Emmited on every data access and some jmp (weak/extern)
    • R_ARM_THB_JMP/CALL Emmited on some short jumps (CC -mlong-call flag not fix it)
  • Relocatable ELF is required (LD -r option)
  • No start library (LD -nostartfiles)

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;
  • exported: Array of symbols to resolve in executable. ELFSymbol_t is a struct contains const char *name for C-String symbol name and void *ptr pointer to memory related to symbol (entry point of function, variable address, etc)
  • size: Size of exported symbol array in elements number

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
  • LOADER_FD_T File descriptor type
  • LOADER_OPEN_FOR_RD(path) Function to open file for read
  • LOADER_FD_VALID(fd) Validity evaluation of file descriptor
  • LOADER_READ(fd, buffer, size) Function to read buffer from fd
  • LOADER_CLOSE(fd) Function to close file descriptor
  • LOADER_SEEK_FROM_START(fd, off) Seek function over fd
  • LOADER_TELL(fd) Tell position of fd cursor
Memory manager/access
  • LOADER_ALIGN_ALLOC(size, align, perm) Aligned malloc function macro
  • LOADER_ALIGN_ALLOC_SDRAM(size, align, perm) Aligned malloc function macro (for .sdram_* sections)
  • LOADER_FREE(ptr) Free memory function
  • LOADER_CLEAR(ptr, size) Memory clearance (to 0) function
  • LOADER_STREQ(s1, s2) String compare function (return !=0 if s1==s2)
Code execution
  • LOADER_JUMP_TO(entry) Macro for jump to "entry" pointer (entry_t)
Debug/message
  • DBG(...) printf style macro for debug
  • ERR(msg) puts style macro used on severe error
  • MSG(msg) puts style macro used on info/warning
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].