esp-iot-solution
esp-iot-solution copied to clipboard
elf loader doesn't resolve libc symbols (AEGHB-1047)
Answers checklist.
- [x] I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
- [x] I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- [x] I have searched the issue tracker for a similar issue and not found a similar issue.
IDF version.
v5.4
Espressif SoC revision.
esp32-c6-devkitc-1 v1.2
Operating System used.
Linux
How did you build your project?
Command line with idf.py
If you are using Windows, please specify command line type.
None
Development Kit.
esp32-c6-devkitc-1 v1.2
Power Supply used.
USB
What is the expected behavior?
I modify the build_elf_file_example to use ESP_LOGW following the docs, here's my diff in the iot git repo
diff --git a/examples/elf_loader/build_elf_file_example/CMakeLists.txt b/examples/elf_loader/build_elf_file_example/CMakeLists.txt
index a82da18e..6f598ce6 100644
--- a/examples/elf_loader/build_elf_file_example/CMakeLists.txt
+++ b/examples/elf_loader/build_elf_file_example/CMakeLists.txt
@@ -8,7 +8,7 @@ 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")
+set(ELF_COMPONENTS "log") # "esp_wifi")
include(elf_loader)
project_elf(hello_world)
diff --git a/examples/elf_loader/build_elf_file_example/main/main.c b/examples/elf_loader/build_elf_file_example/main/main.c
index a6620b23..ac75a515 100644
--- a/examples/elf_loader/build_elf_file_example/main/main.c
+++ b/examples/elf_loader/build_elf_file_example/main/main.c
@@ -6,14 +6,18 @@
#include <stdio.h>
#include <unistd.h>
+#include <esp_log.h>
static int s_cnt;
+static const char TAG[] = "houp";
+
int try_test(void)
{
for (int i = 0; i < 10; i++) {
- printf(buffer, s_cnt++);
+ // printf(buffer, s_cnt++);
+ ESP_LOGW(TAG, "holy moly %d", s_cnt++);
sleep(1);
}
diff --git a/examples/elf_loader/elf_loader_example/main/test_riscv.elf b/examples/elf_loader/elf_loader_example/main/test_riscv.elf
index aa2798d2..ef0fb282 100755
Binary files a/examples/elf_loader/elf_loader_example/main/test_riscv.elf and b/examples/elf_loader/elf_loader_example/main/test_riscv.elf differ
and the example should still work.
I didn't understand how to link the libc here.
What is the actual behavior?
It builds but then when it runs, the loader doesn't find vprintf
(259) main_task: Started on CPU0
I (259) main_task: Calling app_main()
I (259) elf_loader: Start to relocate ELF file
I (269) ELF: ELF loader version: 1.0.0
I (269) ELF: Too much padding before segment[2], padding: 4240
I (269) ELF: elf->entry=0x40812196
E (279) ELF: Can't find common vprintf
E (279) elf_loader: Failed to relocate ELF file errno=-88
I (289) main_task: Returned from app_main()
Steps to reproduce.
- apply diff above to iot elf loader example
- build elf, cp to loader
- build loader, flash and monitor
Debug Logs.
More Information.
I am motivated to get this working and understand elf loading better, and writing up my experience here https://wdmn.fr/elf-loading-on-esp32/ with more details. The docs are not very clear to a esp32 beginner like me.