Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp32-led-strip-sdk unable to build in VS Code using PlatformIO #17

Open
oleksandr-kosylov opened this issue Jun 16, 2024 · 17 comments
Open

Comments

@oleksandr-kosylov
Copy link

oleksandr-kosylov commented Jun 16, 2024

I'm configuring CMakeLists same as described in Example, it successfully works from Terminal using idf.py build BUT doesn't work from in VSCode using PlatformIO (idf 5.2.1)

Looks like custom command/custom target never gets called, so _swiftcode.o never generated and build fails due to undefined symbols for app_main function which is implemented in Main.swift.

I see command and target configuration in build.ninja but they are not called, I've tried to replace swiftc command with custom test command but it's not getting executed.

I've either filed an issue in PlatformIO repo: platformio/platform-espressif32#1401

Please advice.

@avkghost
Copy link

avkghost commented Jun 17, 2024

I have a similar problem.
As far as I understand in my case, the problem is the incorrect path for a Swift compiler.
When I changed the path (exportSWIFTC, or replaced the actual path) with a real path to the toolchain (Swift 6, nightly build) I almost compiled the project without the final binary because of errors, see below.

[home]/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/13.2.0/../../../../riscv32-esp-elf/bin/ld: The gap between .flash.appdesc and .flash.rodata must not exist to produce the final bin image. [home]/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/13.2.0/../../../../riscv32-esp-elf/bin/ld: The gap between .flash.rodata and .eh_frame_hdr must not exist to produce the final bin image. collect2: error: ld returned 1 exit status

@kubamracek Could you please help us to solve the issue?
Thanks for the beautiful presentation at WWDC 2024z.

@kubamracek
Copy link
Collaborator

I think these might be separate problems. If you can, post full logs and also details about your OS, configuration, environment, etc.

If swiftc is not getting called at all, my best guess would be that CMake is too old. The Swift support in CMake is only available in CMake 3.29+ and it's conceivable that in a terminal your PATH is pointing to a different CMake than from VSCode. Full build logs, maybe even screenshots, would be helpful. Also, what is your declared minimum CMake version in your CMakeListst.txt?

As far as I understand in my case, the problem is the incorrect path for a Swift compiler.

Right, this is probably a common issue. You can force a Swift compiler path with -DCMAKE_Swift_COMPILER=<path>.

[home]/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/13.2.0/../../../../riscv32-esp-elf/bin/ld: The gap between .flash.appdesc and .flash.rodata must not exist to produce the final bin image. [home]/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/13.2.0/../../../../riscv32-esp-elf/bin/ld: The gap between .flash.rodata and .eh_frame_hdr must not exist to produce the final bin image. collect2: error: ld returned 1 exit status

What's your ESP IDF version? And are you getting this error just by building the esp32-led-strip-sdk example code unmodified?

@avkghost
Copy link

avkghost commented Jun 17, 2024

@kubamracek

The system is Ubuntu 24.04.

If swiftc is not getting called at all, my best guess would be that CMake is too old. The Swift support in CMake is only available in CMake 3.29+

Looks like the problem belongs to my version of Cmake (3.28.3-1build7)

What's your ESP IDF version?

ESP-IDF v5.4-dev-826-g8760e6d2a7-dirty. However, I'm going to compile the example with the latest stable SDK (5.2.2).

And are you getting this error just by building the esp32-led-strip-sdk example code unmodified?

Yes.

@avkghost
Copy link

avkghost commented Jun 17, 2024

SDKs, tools, languages...

  • ESP-IDF 5.2.2.

  • Cmake 3.29.5

  • Swift - swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-13-a-ubuntu22.04.tar.gz

I've successfully built the example, but a new problem has arrived. See below.

The example calls abort on random number generation.
generic specialization <Swift.SystemRandomNumberGenerator, Swift.UInt8> of (extension in Swift):Swift.RandomNumberGenerator.next<A where A1: Swift.FixedWidthInteger, A1: Swift.UnsignedInteger>(upperBound: A1) -> A1

The exception itself.
`I (331) main_task: Started on CPU0
I (331) main_task: Calling app_main()
Hello from Swift on ESP32-C6!

abort() was called at PC 0x420069b7 on core 0
0x420069b7: syscall_not_implemented_aborts at /home/andy/Projects/MCU/ESP/esp-idf/components/newlib/syscalls.c:27

Stack dump detected
Core 0 register dump:
MEPC : 0x408004ec RA : 0x40805906 SP : 0x408118d0 GP : 0x4080c570
0x408004ec: panic_abort at /home/andy/Projects/MCU/ESP/esp-idf/components/esp_system/panic.c:466
0x40805906: __ubsan_include at /home/andy/Projects/MCU/ESP/esp-idf/components/esp_system/ubsan.c:313

TP : 0x408071f8 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130
0x408071f8: prvAddCurrentTaskToDelayedList at /home/andy/Projects/MCU/ESP/esp-idf/components/freertos/FreeRTOS-Kernel/tasks.c:6337

S0/FP : 0x00000004 S1 : 0x40811934 A0 : 0x408118fc A1 : 0x40811932
A2 : 0x00000000 A3 : 0x40811929 A4 : 0x00000001 A5 : 0x4080e000
A6 : 0x00000000 A7 : 0x76757473 S2 : 0x40812914 S3 : 0x408119d8
S4 : 0x4080e000 S5 : 0x00000000 S6 : 0x00000000 S7 : 0x00000000
S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938
MSTATUS : 0x00001881 MTVEC : 0x40800001 MCAUSE : 0x00000007 MTVAL : 0x00000000
0x40800001: _vector_table at ??:?

MHARTID : 0x00000000

Backtrace:

panic_abort (details=details@entry=0x408118fc "abort() was called at PC 0x420069b7 on core 0") at /home/andy/Projects/MCU/ESP/esp-idf/components/esp_system/panic.c:466
466 *((volatile int *) 0) = 0; // NOLINT(clang-analyzer-core.NullDereference) should be an invalid operation on targets
#0 panic_abort (details=details@entry=0x408118fc "abort() was called at PC 0x420069b7 on core 0") at /home/andy/Projects/MCU/ESP/esp-idf/components/esp_system/panic.c:466
#1 0x40805906 in esp_system_abort (details=details@entry=0x408118fc "abort() was called at PC 0x420069b7 on core 0") at /home/andy/Projects/MCU/ESP/esp-idf/components/esp_system/port/esp_system_chip.c:93
#2 0x4080abde in abort () at /home/andy/Projects/MCU/ESP/esp-idf/components/newlib/abort.c:38
#3 0x420069ba in syscall_not_implemented_aborts () at /home/andy/Projects/MCU/ESP/esp-idf/components/newlib/syscalls.c:27
#4 0x42012936 in _getentropy_fail () at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdlib/arc4random.h:69
#5 _rs_stir () at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdlib/arc4random.c:102
#6 _rs_stir_if_needed (len=len@entry=8) at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdlib/arc4random.c:125
#7 0x42012a68 in _rs_random_buf (n=8, _buf=0x408119d8) at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdlib/arc4random.c:162
#8 arc4random_buf (buf=0x408119d8, n=8) at /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/newlib/newlib/libc/stdlib/arc4random.c:214
#9 0x42000468 in $sSGsE4next10upperBoundqd__qd___ts17FixedWidthIntegerRd__SURd__lFs27SystemRandomNumberGeneratorV_s5UInt8VTg5 ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
ELF file SHA256: b8ab6f760

Rebooting...
ESP-ROM:esp32c6-20220919
`

@Akeyzerr
Copy link

I'm reproducing
.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/13.2.0/../../../../riscv32-esp-elf/bin/ld: The gap between .flash.rodata and .eh_frame_hdr must not exist to produce the final bin image.
ninja failed with exit code 1, output of the command is in the .../build/log/idf_py_stderr_output_62229 and .../build/log/idf_py_stdout_output_62229
on a MacMini M1 w/latest Sonoma, IDF v5.4-dev-826-g8760e6d2a7 and Apple Swift version 6.0-dev (LLVM 57177aa1b91540b, Swift 8be62863326595c)
Target: arm64-apple-macosx14.0

@erhankur
Copy link
Contributor

@avkghost You can apply the attached patch to fix newlib getentropy error.
0001-newlib-getentropy-implementation.patch

@avkghost
Copy link

@erhankur Thanks. It's help.

Maybe you could help with the problem with ESP-IDF v5.4-dev-826-g8760e6d2a7-dirty

.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/13.2.0/../../../../riscv32-esp-elf/bin/ld: The gap between .flash.rodata and .eh_frame_hdr must not exist to produce the final bin image. collect2: error: ld returned 1 exit status

@erhankur
Copy link
Contributor

As a temporary solution you can comment out 2 assertions from components/esp_system/ld/esp32c6/sections.ld.in

-  ASSERT_SECTIONS_GAP(.flash.appdesc, .flash.rodata)
+  /* ASSERT_SECTIONS_GAP(.flash.appdesc, .flash.rodata) */

- ASSERT_SECTIONS_GAP(.flash.rodata, .eh_frame_hdr)
+  /* ASSERT_SECTIONS_GAP(.flash.rodata, .eh_frame_hdr) */

@avkghost
Copy link

@erhankur Thank you so much.

@erhankur
Copy link
Contributor

The current locations of .swift_modhash , .got and .got.plt sections cause the assert errors.

  [13] .flash.text       PROGBITS        42000020 010020 016768 00  AX  0   0  2
  [14] .flash_rodat[...] NOBITS          42000020 027020 018000 00  WA  0   0  1
  [15] .flash.appdesc    PROGBITS        42018020 03f020 000100 00   A  0   0 16
  [16] .swift_modhash    PROGBITS        42018120 03f120 000010 00  Ao  0   0  1
  [17] .flash.rodata     PROGBITS        42018130 03f130 00abdc 00  WA  0   0 16
  [18] .got              PROGBITS        42022d0c 049d0c 000008 04  WA  0   0  4
  [19] .got.plt          PROGBITS        42022d14 049d14 000008 04  WA  0   0  4
  [20] .eh_frame_hdr     PROGBITS        42022d1c 049d1c 000000 00   W  0   0  1
  [21] .eh_frame         PROGBITS        42022d1c 049d1c 000000 00   W  0   0  1
  [22] .flash.tdata      PROGBITS        42022d1c 049d1c 000000 00   W  0   0  1

This patch also fixes that errors.

0001-move-swift-sections-to-proper-memory-regions.patch

@georgik
Copy link

georgik commented Jun 18, 2024

The solution works for C6.
The similar correction would be required also for C3 and P4.
It's possible to test the build process simply by changing target:

idf.py set-target esp32c3
idf.py build

@PaulSolt
Copy link

PaulSolt commented Sep 4, 2024

@erhankur

  1. Where am I applying the patch?

  2. I couldn't seem to find the assertions in components/esp_system/ld/esp32c6/sections.ld.in

  3. I'm new to embedded programming, what does this mean?

The current locations of .swift_modhash , .got and .got.plt sections cause the assert errors.

@PaulSolt
Copy link

@erhankur Is this an issue that will be fixed in https://github.com/espressif/esp-idf ?

@erhankur
Copy link
Contributor

@PaulSolt try using the idf master branch. You shouldn't need to apply a patch.

@PaulSolt
Copy link

@erhankur What release will have the fixes from master?

The previous patches didn't work for me, so I had to manually apply the changes. Attached are the patches based on your patches that worked for me.

  1. Download the patch you need to fix random numbers
    1. esp32c6_random_crash_fix_5.2.2.patch
    2. esp32c6_random_crash_fix_5.3.1.patch
  2. Navigate to your ESP build folder
    cd ~/esp/esp-idf/
  3. Apply the patch (5.2.2 or 5.3.1)
    git apply ~/Dowloads/esp32c6_random_crash_fix_5.2.2.patch
  4. Navigate back to your project and build. It should pick up the changes and fix your problem.
    idf.py build

@erhankur
Copy link
Contributor

erhankur commented Sep 13, 2024

@PaulSolt Please stay in the master (v5.4) branch. Don't checkout to the release v5.2 or v5.3

As a summary;

@PaulSolt
Copy link

Thank you @erhankur for the details. I'll switch to the master (v5.4) branch and recommend others do the same. I appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants