Skip to content

Commit 7fdbb77

Browse files
committed
Merge branch 'feature/support_link_other_components_to_elf' into 'master'
feat(elf_loader): Add support for linking other components to ELF file Closes AEG-1898 See merge request ae_group/esp-iot-solution!1095
2 parents b2cd32d + b3f3002 commit 7fdbb77

File tree

11 files changed

+26
-13
lines changed

11 files changed

+26
-13
lines changed

components/elf_loader/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog
22

3+
## v1.0.0 - 2024-12-09
4+
5+
* Added support for the following RISC-V chips: ESP32-P4 and ESP32-C6
6+
* Added support for linking other components to ELF file
7+
* Fixed the issue of getting wrong symbol type
8+
39
## v0.1.0 - 2023-08-14
410

511
* Add basic ELF loader component

components/elf_loader/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Add a dependency on this component in your component or project's idf_component.
2222

2323
```yml
2424
dependencies:
25-
espressif/elf_loader: "0.*"
25+
espressif/elf_loader: "1.*"
2626
```
2727

2828
Enable ELF loader in the menuconfig:

components/elf_loader/elf_loader.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ macro(project_elf project_name)
4848
endif()
4949

5050
# Link input list of libraries to ELF
51-
list(APPEND ELF_COMPONENTS "main")
51+
list(PREPEND ELF_COMPONENTS "main")
5252
if(ELF_COMPONENTS)
53-
foreach(c "${ELF_COMPONENTS}")
53+
foreach(c ${ELF_COMPONENTS})
5454
list(APPEND elf_libs "esp-idf/${c}/lib${c}.a")
5555
list(APPEND elf_dependeces "idf::${c}")
5656
endforeach()

components/elf_loader/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "0.1.0"
1+
version: "1.0.0"
22
description: Espressif ELF(Executable and Linkable Format) Loader
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/elf_loader
44
dependencies:

components/elf_loader/include/private/elf_symbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include "private/elf_types.h"
9+
#include <stdint.h>
1010

1111
#ifdef __cplusplus
1212
extern "C" {

components/elf_loader/src/arch/esp_elf_riscv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ int esp_elf_arch_relocate(esp_elf_t *elf, const elf32_rela_t *rela,
8686
assert(elf && rela);
8787

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

9292
/* Do relocation based on relocation type */
9393

components/elf_loader/src/arch/esp_elf_xtensa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ int esp_elf_arch_relocate(esp_elf_t *elf, const elf32_rela_t *rela,
8282

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

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

8888
switch (ELF_R_TYPE(rela->info)) {
8989
case R_XTENSA_RELATIVE:

components/elf_loader/src/esp_elf.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ int esp_elf_relocate(esp_elf_t *elf, const uint8_t *pbuf)
410410

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

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

417417
if (comm_name[0]) {
@@ -477,6 +477,10 @@ int esp_elf_relocate(esp_elf_t *elf, const uint8_t *pbuf)
477477
*/
478478
int esp_elf_request(esp_elf_t *elf, int opt, int argc, char *argv[])
479479
{
480+
if (!elf || !(elf->entry)) {
481+
return -EINVAL;
482+
}
483+
480484
elf->entry(argc, argv);
481485

482486
return 0;

examples/elf_loader/build_elf_file_example/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ cmake_minimum_required(VERSION 3.5)
77
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
88
project(hello_world)
99

10+
# Set other components to link to the ELF file
11+
# e.g: set(ELF_COMPONENTS "log" "esp_wifi")
12+
1013
include(elf_loader)
1114
project_elf(hello_world)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dependencies:
22
elf_loader:
3-
version: "0.*"
3+
version: "1.*"
44
override_path: "../../../../components/elf_loader"

0 commit comments

Comments
 (0)