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

Buid.link error: bad value #9

Open
henriterhofte opened this issue Jan 6, 2023 · 7 comments
Open

Buid.link error: bad value #9

henriterhofte opened this issue Jan 6, 2023 · 7 comments

Comments

@henriterhofte
Copy link

henriterhofte commented Jan 6, 2023

I got a bad value error while during linking firmware.elf after cloning this repo yesterday, doing a 'clean all' and building this repo using Visual Studio Code (v1.74.2), PlatformIO (Core: 6.1.5; Home 3.4.3) and Windoes 11 Education (v21H2). I also get the same error when I change the platform line in platromio.ini to espressif32. Similarly, I also get the same error when compiling the source code in the v2.0.0 release. More details below.

What could be the problem here?

CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.3.1+sha.33ff413) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 0.0.0+sha.caef400
 - tool-esptoolpy @ 1.30200.211025 (3.2.0)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r1
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft

...

Linking .pio\build\release\firmware.elf
c:/users/henrgi/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: final link failed: bad value
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\release\firmware.elf] Error 1

I also tried the solution mentioned in SmartEVSE-3/issues/36, but that did not help either:

CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.3.1+sha.33ff413) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 0.0.0+sha.caef400 
 - tool-esptoolpy @ 1.30200.211025 (3.2.0) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r1
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft

...

Linking .pio\build\release\firmware.elf
c:/users/henrgi/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: final link failed: bad value
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\release\firmware.elf] Error 1

I also get the same error when compiling the source code in the v2.0.0 release:

CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.3.1+sha.33ff413) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 0.0.0+sha.caef400
 - tool-esptoolpy @ 1.30200.211025 (3.2.0)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r1
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft

...

Linking .pio\build\release\firmware.elf
c:/users/henrgi/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: final link failed: bad value
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\release\firmware.elf] Error 1
@mstegen
Copy link
Member

mstegen commented Jan 6, 2023

This does not look correct:
framework-arduinoespressif32 @ 0.0.0+sha.caef400

when i update the platformio.ini file to the latest arduino version, this is the output:

 - framework-arduinoespressif32 @ 3.20006.221224 (2.0.6)
 - tool-esptoolpy @ 1.40400.0 (4.4.0)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 43 compatible libraries
Scanning dependencies...
Dependency Graph
|-- AsyncTCP-esphome @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.0.0
|   |-- AsyncTCP-esphome @ 2.0.0
|   |-- FS @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- ESPAsync_WiFiManager @ 1.9.8
|   |-- ESP Async WebServer @ 1.2.3
|   |   |-- FS @ 2.0.0
|   |   |-- AsyncTCP-esphome @ 2.0.0
|   |   |-- WiFi @ 2.0.0
|   |-- ESP_DoubleResetDetector @ 1.2.1
|   |-- DNSServer @ 2.0.0
|   |   |-- WiFi @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- eModbus @ 1.6.0
|   |-- AsyncTCP-esphome @ 2.0.0
|-- ESP Async WebServer @ 1.2.3
|   |-- FS @ 2.0.0
|   |-- AsyncTCP-esphome @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- Preferences @ 2.0.0
|-- SPIFFS @ 2.0.0
|   |-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
Building in release mode

Try deleting the files in the .pio folder, this will let platformio re-download packages

here is my current platformio.ini file for this project:

description = Sensorbox 2 with web interface
default_envs = release


[env]
platform = espressif32
board = esp32dev
framework = arduino
upload_port = COM5
monitor_port = COM5
monitor_speed = 115200
upload_speed = 2000000
board_build.f_flash = 80000000L
board_build.flash_mode = dio
lib_ignore = 
	AsyncTCP
	LittleFS_esp32
	Hash
	ESP8266WiFi
lib_deps =  
	esphome/AsyncTCP-esphome @ 2.0.0
	esphome/ESPAsyncWebServer-esphome @ 3.0.0
	khoih-prog/[email protected]
	miq19/eModbus @ 1.6.0
	
monitor_filters = esp32_exception_decoder
board_build.partitions = partitions_custom.csv

[env:release]
build_flags = 
	-DLOG_LEVEL=5

@henriterhofte
Copy link
Author

henriterhofte commented Jan 8, 2023

Short:
Your platformio.ini file (with [platformio] added as a first line) resolves the framework-arduinoespressif32 @ 0.0.0+sha.caef400 error, but now I'm stuck with the missing bootloader error, which was also reported in issue 36.
I even uninstalled and re-installed PlatformIO and Visual Studio Code and updated esptool.py to version 4.4.0, but I got the same result.

In more detail.
Deleting the files in the .pio folder seems to have the same effect as usung the 'Clean All' option in the left PlatformIO menu in VSCode:

 *  Executing task: C:\Users\henrgi\.platformio\penv\Scripts\platformio.exe run --target cleanall --environment release 

Processing release (platform: espressif32; board: esp32dev; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------
Removing .pio\build\release
Removing .pio\libdeps\release
Done cleaning
======================================================== [SUCCESS] Took 0.76 seconds ========================================================
 *  Terminal will be reused by tasks, press any key to close it. 

After changing the platformio.ini file to this content:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
description = Sensorbox 2 with web interface
default_envs = release


[env]
platform = espressif32
board = esp32dev
framework = arduino
upload_port = COM5
monitor_port = COM5
monitor_speed = 115200
upload_speed = 2000000
board_build.f_flash = 80000000L
board_build.flash_mode = dio
lib_ignore = 
	AsyncTCP
	LittleFS_esp32
	Hash
	ESP8266WiFi
lib_deps =  
	esphome/AsyncTCP-esphome @ 2.0.0
	esphome/ESPAsyncWebServer-esphome @ 3.0.0
	khoih-prog/[email protected]
	miq19/eModbus @ 1.6.0
	
monitor_filters = esp32_exception_decoder
board_build.partitions = partitions_custom.csv

[env:release]
build_flags = 
	-DLOG_LEVEL=5

The proper arduino framework seems to be used, i.e. framework-arduinoespressif32 @ 2.0.6+sha.57b27cd...

However, I get the error *** [.pio\build\release\bootloader.bin] Source C:\Users\henrgi.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader__80m.elf' not found, needed by target .pio\build\release\bootloader.bin'.

More details:

 *  Executing task: C:\Users\henrgi\.platformio\penv\Scripts\platformio.exe run --environment release 

Processing release (platform: espressif32; board: esp32dev; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------
Library Manager: Installing esphome/AsyncTCP-esphome @ 2.0.0
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Library Manager: Installing esphome/ESPAsyncWebServer-esphome @ 3.0.0
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing khoih-prog/ESPAsync_WiFiManager @ 1.9.8
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing me-no-dev/AsyncTCP @ >=1.1.1
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Library Manager: Installing me-no-dev/ESP Async WebServer @ >=1.2.3
Unpacking  [####################################]  100%
Library Manager: ESP Async [email protected] has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing khoih-prog/ESP_DoubleResetDetector @ >=1.2.1
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Library Manager: Installing lorol/LittleFS_esp32 @ >=1.0.6
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Library Manager: Installing miq19/eModbus @ 1.6.0
Unpacking  [####################################]  100%
Library Manager: [email protected] has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing git+https://github.com/maxgerhardt/Ethernet.git
git version 2.36.1.windows.1
Cloning into 'C:\Users\henrgi\.platformio\.cache\tmp\pkg-installing-71oiexs7'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 47 (delta 4), reused 19 (delta 0), pack-reused 0
Receiving objects: 100% (47/47), 52.74 KiB | 7.53 MiB/s, done.
Resolving deltas: 100% (4/4), done.
Library Manager: [email protected]+sha.c9399a9 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.3.1+sha.33ff413) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 2.0.6+sha.57b27cd
 - tool-esptoolpy @ 1.30100.210531 (3.1.0)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r1
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 40 compatible libraries
Scanning dependencies...
Dependency Graph
|-- AsyncTCP-esphome @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.0.0
|   |-- AsyncTCP-esphome @ 2.0.0
|   |-- FS @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- ESPAsync_WiFiManager @ 1.9.8
|   |-- ESP Async WebServer @ 1.2.3
|   |   |-- FS @ 2.0.0
|   |   |-- AsyncTCP-esphome @ 2.0.0
|   |   |-- WiFi @ 2.0.0
|   |-- ESP_DoubleResetDetector @ 1.3.2
|   |-- DNSServer @ 2.0.0
|   |   |-- WiFi @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- eModbus @ 1.6.0
|   |-- AsyncTCP-esphome @ 2.0.0
|-- ESP Async WebServer @ 1.2.3
|   |-- FS @ 2.0.0
|   |-- AsyncTCP-esphome @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- Preferences @ 2.0.0
|-- SPIFFS @ 2.0.0
|   |-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
Building in release mode
Compiling .pio\build\release\src\main.cpp.o
Compiling .pio\build\release\src\prg_pic.cpp.o
Compiling .pio\build\release\src\radix.cpp.o
*** [.pio\build\release\bootloader.bin] Source `C:\Users\henrgi\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader__80m.elf' not found, needed by target `.pio\build\release\bootloader.bin'.
======================================================== [FAILED] Took 33.12 seconds ========================================================


 *  The terminal process "C:\Users\henrgi\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'release'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

I also tested with esptool.py upgraded to version 4.4.0by including the line directly below in platformio.ini, but the error did not go away:
platform_packages = tool-esptoolpy@~1.40400.0

@henriterhofte
Copy link
Author

After running the build command with the --verbose option added, i.e.
C:\Users\henrgi\.platformio\penv\Scripts\platformio.exe run --verbose --environment release
it becoms clear that the FLASH mode option is not used in the toolchain, i.e. the board_build.flash_mode = dio in the file platformio.ini is not used by the toolchain when looking for the proper elf file.
The toolchain seems to depend on python; I am running
Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21)

More details:
The linker is looking for C:\Users\henrgi\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader__80m.elf, which is not available in the folder.
The files that ARE available are:

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          8-1-2023     19:27         721460 bootloader_dio_40m.elf
-a----          8-1-2023     19:27         721488 bootloader_dio_80m.elf
-a----          8-1-2023     19:27         721460 bootloader_dout_40m.elf
-a----          8-1-2023     19:27         721488 bootloader_dout_80m.elf
-a----          8-1-2023     19:27         737204 bootloader_qio_40m.elf
-a----          8-1-2023     19:27         737232 bootloader_qio_80m.elf
-a----          8-1-2023     19:27         737204 bootloader_qout_40m.elf
-a----          8-1-2023     19:27         737232 bootloader_qout_80m.elf

These files seem to have been copied from https://github.com/espressif/arduino-esp32/tree/master/tools/sdk/esp32/bin,

Just issuing the 'Build' command results in:

 *  Executing task: C:\Users\henrgi\.platformio\penv\Scripts\platformio.exe run --environment release 

Processing release (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.3.1+sha.33ff413) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-arduinoespressif32 @ 2.0.6+sha.57b27cd 
 - tool-esptoolpy @ 1.40400.0 (4.4.0) 
 - toolchain-xtensa-esp32 @ 8.4.0+2021r1
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 40 compatible libraries
Scanning dependencies...
Dependency Graph
|-- AsyncTCP-esphome @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.0.0
|   |-- AsyncTCP-esphome @ 2.0.0
|   |-- FS @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- ESPAsync_WiFiManager @ 1.9.8
|   |-- ESP Async WebServer @ 1.2.3
|   |   |-- FS @ 2.0.0
|   |   |-- AsyncTCP-esphome @ 2.0.0
|   |   |-- WiFi @ 2.0.0
|   |-- ESP_DoubleResetDetector @ 1.3.2
|   |-- DNSServer @ 2.0.0
|   |   |-- WiFi @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- eModbus @ 1.6.0
|   |-- AsyncTCP-esphome @ 2.0.0
|-- ESP Async WebServer @ 1.2.3
|   |-- FS @ 2.0.0
|   |-- AsyncTCP-esphome @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- Preferences @ 2.0.0
|-- SPIFFS @ 2.0.0
|   |-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
Building in release mode
Compiling .pio\build\release\src\main.cpp.o
Compiling .pio\build\release\src\prg_pic.cpp.o
Compiling .pio\build\release\src\radix.cpp.o
Building .pio\build\release\bootloader.bin
Generating partitions .pio\build\release\partitions.bin
usage: esptool elf2image [-h] [--output OUTPUT] [--version {1,2,3}]
                         [--min-rev-full {0, ... 65535}]
                         [--max-rev-full {0, ... 65535}] [--secure-pad]
                         [--secure-pad-v2]
                         [--elf-sha256-offset ELF_SHA256_OFFSET]
                         [--dont-append-digest] [--use_segments]
                         [--flash-mmu-page-size {64KB,32KB,16KB,8KB}]
                         [--flash_freq {80m,60m,48m,40m,30m,26m,24m,20m,16m,15m,12m}]
                         [--flash_mode {qio,qout,dio,dout}]
                         [--flash_size {256KB,512KB,1MB,2MB,2MB-c1,4MB,4MB-c1,8MB,16MB,32MB,64MB,128MB}]
                         [--spi-connection SPI_CONNECTION]
                         input
esptool elf2image: error: argument --flash_mode/-fm: expected one argument
Compiling .pio\build\release\libc95\AsyncTCP-esphome\AsyncTCP.cpp.o
Compiling .pio\build\release\libefe\FS\FS.cpp.o
Compiling .pio\build\release\libefe\FS\vfs_api.cpp.o
*** [.pio\build\release\bootloader.bin] Error 2
============================================================ [FAILED] Took 8.82 seconds ============================================================

 *  The terminal process "C:\Users\henrgi\.platformio\penv\Scripts\platformio.exe 'run', '--environment', 'release'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

and indeed, after copying bootloader_dio_80m.elf to bootloader__80m.elf the error changes to an error in the arguments used for esptool elf2image in the toolchain. Using the --verbose option, I can see that the following the `` -- flash_modeis not followed bydio`, which seems to cause the error

The crucial line is:

Building in release mode
"C:\Users\henrgi\.platformio\penv\Scripts\python.exe" "C:\Users\henrgi\.platformio\packages\tool-esptoolpy\esptool.py" --chip esp32 elf2image --flash_mode --flash_freq 80m --flash_size 4MB -o .pio\build\release\bootloader.bin C:\Users\henrgi\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader__80m.elf
``` 


@henriterhofte
Copy link
Author

The error may be related to this change, committed 2 days ago:
platformio/platform-espressif32@d0835e9

@henriterhofte
Copy link
Author

And indeed, changing the line that specifies the platform in platformio.ini to the line below finally allowed me to sucesfully complile and upload the Sensorbox-2 firmware!

platform = https://github.com/platformio/platform-espressif32.git#develop

So, it seems commit specified in platformio/platform-espressif32@d0835e9 that is currently in the develop branch is needed to compile the firmware properly!?

@henriterhofte
Copy link
Author

henriterhofte commented Jan 22, 2023

The fix is incorporatedin release v6.0.0 of the espressif32 platform

So, after pulling v6.0.0 from GitHub, in platform.ini for the platfrm line, you can now simply use the line
platform = espressif32

and then the issue is gone.

@mstegen
Copy link
Member

mstegen commented Jan 23, 2023

Thanks for debugging this issue.
Just tried a fresh installation of Ubuntu + VScode + PlatformIO, and i ran into the same issue where the bootloader could not be found.

platform = espressif32 did not work for me.
Somehow it did not install the latest version, but instead installed framework-arduinoespressif32 @ 2.0.6 weird...

platform = espressif32 @ 6.0.0

did install the correct platform, framework and esptool

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

2 participants