Skip to content

Commit

Permalink
Merge branch 'feature/support_link_other_components_to_elf' into 'mas…
Browse files Browse the repository at this point in the history
…ter'

feat(elf_loader): Add support for linking other components to ELF file

Closes AEG-1898

See merge request ae_group/esp-iot-solution!1095
  • Loading branch information
wujiangang committed Dec 19, 2024
2 parents b2cd32d + b3f3002 commit 7fdbb77
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 13 deletions.
6 changes: 6 additions & 0 deletions components/elf_loader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## v1.0.0 - 2024-12-09

* Added support for the following RISC-V chips: ESP32-P4 and ESP32-C6
* Added support for linking other components to ELF file
* Fixed the issue of getting wrong symbol type

## v0.1.0 - 2023-08-14

* Add basic ELF loader component
2 changes: 1 addition & 1 deletion components/elf_loader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Add a dependency on this component in your component or project's idf_component.

```yml
dependencies:
espressif/elf_loader: "0.*"
espressif/elf_loader: "1.*"
```

Enable ELF loader in the menuconfig:
Expand Down
4 changes: 2 additions & 2 deletions components/elf_loader/elf_loader.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ macro(project_elf project_name)
endif()

# Link input list of libraries to ELF
list(APPEND ELF_COMPONENTS "main")
list(PREPEND ELF_COMPONENTS "main")
if(ELF_COMPONENTS)
foreach(c "${ELF_COMPONENTS}")
foreach(c ${ELF_COMPONENTS})
list(APPEND elf_libs "esp-idf/${c}/lib${c}.a")
list(APPEND elf_dependeces "idf::${c}")
endforeach()
Expand Down
2 changes: 1 addition & 1 deletion components/elf_loader/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.1.0"
version: "1.0.0"
description: Espressif ELF(Executable and Linkable Format) Loader
url: https://github.com/espressif/esp-iot-solution/tree/master/components/elf_loader
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion components/elf_loader/include/private/elf_symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "private/elf_types.h"
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 2 additions & 2 deletions components/elf_loader/src/arch/esp_elf_riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ int esp_elf_arch_relocate(esp_elf_t *elf, const elf32_rela_t *rela,
assert(elf && rela);

where = (uint32_t *)((uint8_t *)elf->psegment + rela->offset + elf->svaddr);
ESP_LOGD(TAG, "where=%p addr=0x%x offset=0x%x",
where, (int)elf->psegment, (int)rela->offset);
ESP_LOGD(TAG, "type: %d, where=%p addr=0x%x offset=0x%x",
ELF_R_TYPE(rela->info), where, (int)elf->psegment, (int)rela->offset);

/* Do relocation based on relocation type */

Expand Down
4 changes: 2 additions & 2 deletions components/elf_loader/src/arch/esp_elf_xtensa.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ int esp_elf_arch_relocate(esp_elf_t *elf, const elf32_rela_t *rela,

where = (uint32_t *)esp_elf_map_sym(elf, rela->offset);

ESP_LOGD(TAG, "where=%p addr=0x%x offset=0x%x\n",
where, (int)addr, (int)rela->offset);
ESP_LOGD(TAG, "type: %d, where=%p addr=0x%x offset=0x%x\n",
ELF_R_TYPE(rela->info), where, (int)addr, (int)rela->offset);

switch (ELF_R_TYPE(rela->info)) {
case R_XTENSA_RELATIVE:
Expand Down
8 changes: 6 additions & 2 deletions components/elf_loader/src/esp_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ int esp_elf_relocate(esp_elf_t *elf, const uint8_t *pbuf)

const elf32_sym_t *sym = &symtab[ELF_R_SYM(rela_buf.info)];

type = ELF_R_TYPE(rela->info);
if (type == STT_COMMON || type == STT_OBJECT) {
type = ELF_R_TYPE(rela_buf.info);
if (type == STT_COMMON || type == STT_OBJECT || type == STT_SECTION) {
const char *comm_name = strtab + sym->name;

if (comm_name[0]) {
Expand Down Expand Up @@ -477,6 +477,10 @@ int esp_elf_relocate(esp_elf_t *elf, const uint8_t *pbuf)
*/
int esp_elf_request(esp_elf_t *elf, int opt, int argc, char *argv[])
{
if (!elf || !(elf->entry)) {
return -EINVAL;
}

elf->entry(argc, argv);

return 0;
Expand Down
3 changes: 3 additions & 0 deletions examples/elf_loader/build_elf_file_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(hello_world)

# Set other components to link to the ELF file
# e.g: set(ELF_COMPONENTS "log" "esp_wifi")

include(elf_loader)
project_elf(hello_world)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dependencies:
elf_loader:
version: "0.*"
version: "1.*"
override_path: "../../../../components/elf_loader"
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ targets:
- esp32p4
dependencies:
elf_loader:
version: "0.*"
version: "1.*"
override_path: "../../../../components/elf_loader"

0 comments on commit 7fdbb77

Please sign in to comment.