elf_loader refactored and added more symbols (#347)
This commit is contained in:
committed by
GitHub
parent
9cc58099b4
commit
dcf28d0868
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "private/elf_symbol.h"
|
||||
|
||||
/* Extern declarations from ELF symbol table */
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/* Available ELF symbols table: g_customer_elfsyms */
|
||||
|
||||
const struct esp_elfsym g_customer_elfsyms[] = {
|
||||
ESP_ELFSYM_END
|
||||
};
|
||||
@@ -19,12 +19,27 @@
|
||||
|
||||
#include "private/elf_symbol.h"
|
||||
#include "private/elf_platform.h"
|
||||
#include "esp_elf.h"
|
||||
|
||||
#define stype(_s, _t) ((_s)->type == (_t))
|
||||
#define sflags(_s, _f) (((_s)->flags & (_f)) == (_f))
|
||||
#define ADDR_OFFSET (0x400)
|
||||
|
||||
uintptr_t elf_find_sym_default(const char *sym_name);
|
||||
|
||||
static const char *TAG = "ELF";
|
||||
static symbol_resolver current_resolver = elf_find_sym_default;
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
return current_resolver(sym_name);
|
||||
}
|
||||
|
||||
#if CONFIG_ELF_LOADER_BUS_ADDRESS_MIRROR
|
||||
|
||||
@@ -306,6 +321,18 @@ static int esp_elf_load_segment(esp_elf_t *elf, const uint8_t *pbuf)
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Override the internal symbol resolver.
|
||||
* The default resolver is based on static lists that are determined by KConfig.
|
||||
* This override allows for an arbitrary implementation.
|
||||
*
|
||||
* @param resolver the resolver function
|
||||
*/
|
||||
void elf_set_symbol_resolver(symbol_resolver resolver) {
|
||||
current_resolver = resolver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Map symbol's address of ELF to physic space.
|
||||
*
|
||||
|
||||
@@ -27,13 +27,6 @@ extern int __gtdf2(double a, double b);
|
||||
extern double __floatunsidf(unsigned int i);
|
||||
extern double __divdf3(double a, double b);
|
||||
|
||||
// Tactility custom -->
|
||||
static const struct esp_elfsym* custom_symbols = NULL;
|
||||
void elf_set_custom_symbols(const struct esp_elfsym* symbols) {
|
||||
custom_symbols = symbols;
|
||||
}
|
||||
// <-- Tactility custom
|
||||
|
||||
/** @brief Libc public functions symbols look-up table */
|
||||
|
||||
static const struct esp_elfsym g_esp_libc_elfsyms[] = {
|
||||
@@ -163,7 +156,7 @@ static const struct esp_elfsym g_esp_espidf_elfsyms[] = {
|
||||
*
|
||||
* @return Symbol address if success or 0 if failed.
|
||||
*/
|
||||
uintptr_t elf_find_sym(const char *sym_name)
|
||||
uintptr_t elf_find_sym_default(const char *sym_name)
|
||||
{
|
||||
const struct esp_elfsym *syms;
|
||||
|
||||
@@ -208,16 +201,5 @@ uintptr_t elf_find_sym(const char *sym_name)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Tactility custom -->
|
||||
syms = custom_symbols;
|
||||
while (syms->name) {
|
||||
if (!strcmp(syms->name, sym_name)) {
|
||||
return (uintptr_t)syms->sym;
|
||||
}
|
||||
|
||||
syms++;
|
||||
}
|
||||
// <-- Tactility custom
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user