Updated elf_loader library to latest from GitHub (#234)

This commit is contained in:
Ken Van Hoeylandt
2025-02-22 23:57:45 +01:00
committed by GitHub
parent 6d1d08944b
commit bd2786b122
45 changed files with 641 additions and 483 deletions
@@ -12,19 +12,17 @@
extern "C" {
#endif
#ifndef ELF_ALIGN_SIZE
#define ELF_ALIGN_SIZE 4
#endif
/* Notes: align_size needs to be a power of 2 */
#define ELF_ALIGN(_a) (((_a) + (ELF_ALIGN_SIZE - 1)) & \
(~(ELF_ALIGN_SIZE - 1)))
#define ELF_ALIGN(_a, align_size) (((_a) + (align_size - 1)) & \
~(align_size - 1))
/**
* @brief Allocate block of memory.
*
* @param n - Memory size in byte
* @param exec - True: memory can run executable code; False: memory can R/W data
*
*
* @return Memory pointer if success or NULL if failed.
*/
void *esp_elf_malloc(uint32_t n, bool exec);
@@ -33,7 +31,7 @@ void *esp_elf_malloc(uint32_t n, bool exec);
* @brief Free block of memory.
*
* @param ptr - memory block pointer allocated by "esp_elf_malloc"
*
*
* @return None
*/
void esp_elf_free(void *ptr);
@@ -45,18 +43,18 @@ void esp_elf_free(void *ptr);
* @param rela - Relocated symbol data
* @param sym - ELF symbol table
* @param addr - Jumping target address
*
* @return ESP_OK if sucess or other if failed.
*
* @return ESP_OK if success or other if failed.
*/
int esp_elf_arch_relocate(esp_elf_t *elf, const elf32_rela_t *rela,
const elf32_sym_t *sym, uint32_t addr);
/**
* @brief Remap symbol from ".data" to ".text" section.
* @brief Remap symbol from ".data" to ".text" section.
*
* @param elf - ELF object pointer
* @param sym - ELF symbol table
*
*
* @return Remapped symbol value
*/
#ifdef CONFIG_ELF_LOADER_CACHE_OFFSET
@@ -67,7 +65,7 @@ uintptr_t elf_remap_text(esp_elf_t *elf, uintptr_t sym);
* @brief Flush data from cache to external RAM.
*
* @param None
*
*
* @return None
*/
#ifdef CONFIG_ELF_LOADER_LOAD_PSRAM
@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// Tactility custom -->
#define ESP_ELFSYM_EXPORT(_sym) { #_sym, (const void*)&_sym }
// <-- Tactility custom
#define ESP_ELFSYM_END { NULL, NULL }
/** @brief Function symbol description */
struct esp_elfsym {
const char *name; /*!< Function name */
const void *sym; /*!< Function pointer */
};
/**
* @brief Find symbol address by name.
*
* @param sym_name - Symbol name
*
* @return Symbol address if success or 0 if failed.
*/
uintptr_t elf_find_sym(const char *sym_name);
// Tactility custom -->
void elf_set_custom_symbols(const struct esp_elfsym* symbols);
// <-- Tactility custom
#ifdef __cplusplus
}
#endif
@@ -18,6 +18,29 @@ extern "C" {
#define EI_NIDENT 16 /*!< Magic number and other information length */
/** @brief Type of segment */
#define PT_NULL 0 /*!< Program header table entry unused */
#define PT_LOAD 1 /*!< Loadable program segment */
#define PT_DYNAMIC 2 /*!< Dynamic linking information */
#define PT_INTERP 3 /*!< Program interpreter */
#define PT_NOTE 4 /*!< Auxiliary information */
#define PT_SHLIB 5 /*!< Reserved */
#define PT_PHDR 6 /*!< Entry for header table itself */
#define PT_TLS 7 /*!< Thread-local storage segment */
#define PT_NUM 8 /*!< Number of defined types */
#define PT_LOOS 0x60000000 /*!< Start of OS-specific */
#define PT_GNU_EH_FRAME 0x6474e550 /*!< GCC .eh_frame_hdr segment */
#define PT_GNU_STACK 0x6474e551 /*!< Indicates stack executability */
#define PT_GNU_RELRO 0x6474e552 /*!< Read-only after relocation */
#define PT_LOSUNW 0x6ffffffa
#define PT_SUNWBSS 0x6ffffffa /*!< Sun Specific segment */
#define PT_SUNWSTACK 0x6ffffffb /*!< Stack segment */
#define PT_HISUNW 0x6fffffff
#define PT_HIOS 0x6fffffff /*!< End of OS-specific */
#define PT_LOPROC 0x70000000 /*!< Start of processor-specific */
#define PT_HIPROC 0x7fffffff /*!< End of processor-specific */
/** @brief Section Type */
#define SHT_NULL 0 /*!< invalid section header */
@@ -82,6 +105,8 @@ extern "C" {
#define ELF_SYMTAB ".symtab" /*!< symbol table */
#define ELF_TEXT ".text" /*!< code */
#define ELF_DATA_REL_RO ".data.rel.ro" /*!< dynamic read-only data */
#define ELF_PLT ".plt" /*!< procedure linkage table. */
#define ELF_GOT_PLT ".got.plt" /*!< a table where resolved addresses from external functions are stored */
/** @brief ELF section and symbol operation */
@@ -130,6 +155,19 @@ typedef struct elf32_hdr {
Elf32_Half shstrndx; /*!< section header table's "section header string table" entry offset */
} elf32_hdr_t;
/** @brief Program Header */
typedef struct elf32_phdr {
Elf32_Word type; /* segment type */
Elf32_Off offset; /* segment offset */
Elf32_Addr vaddr; /* virtual address of segment */
Elf32_Addr paddr; /* physical address - ignored? */
Elf32_Word filesz; /* number of bytes in file for seg. */
Elf32_Word memsz; /* number of bytes in mem. for seg. */
Elf32_Word flags; /* flags */
Elf32_Word align; /* memory alignment */
} elf32_phdr_t;
/** @brief Section Header */
typedef struct elf32_shdr {
@@ -184,16 +222,20 @@ typedef struct esp_elf_sec {
/** @brief ELF object */
typedef struct esp_elf {
unsigned char *psegment; /*!< segment buffer pointer */
uint32_t svaddr; /*!< start virtual address of segment */
unsigned char *ptext; /*!< instruction buffer pointer */
unsigned char *pdata; /*!< data buffer pointer */
esp_elf_sec_t sec[ELF_SECS]; /*!< ".bss", "data", "rodata", ".text" */
int (*entry)(int argc, char *argv[]); /*!< Entry pointer of ELF */
int (*entry)(int argc, char *argv[]); /*!< Entry pointer of ELF */
#ifdef CONFIG_ELF_LOADER_SET_MMU
uint32_t text_off; /* .text symbol offset */
uint32_t text_off; /* .text symbol offset */
uint32_t mmu_off; /* MMU unit offset */
uint32_t mmu_num; /* MMU unit total number */