Is there any way to set the app version when using PlatformIO with an ESP32 chip?
I am developing a project that uses OTA firmware upgrades. When pulling a firmware.bin file from an upgrade server, I want to check the app version which is included in the header of the .bin file.
According to Espressif’s documentation for the ESP32 chip here, there are a few ways to do it using Espressif’s ESP-IDF toolchain:
create a PROJECT_VER variable in the project makefile and assign the version to it
use ESP-IDF’s project configurator (MenuConfig) to set the version
create a file called version.txt in the project’s root directory and put the version in it
put the project in a git repo and pull the version using ‘git describe’
However, I can’t find any way to do this using PlatformIO. The user doesn’t typically interact with a makefile or ESP-IDF’s MenuConfig when using PlatformIO. I tried creating a version.txt file in the project’s root, but the string that I put in this file didn’t end up in the .bin file. Instead, the app version seems to be getting set to a git commit hash (6b2a602-dirty), but this hash doesn’t even exist in my repo. I think it’s getting this from the esp32-arduino-lib-builder repo.
Here are some details about the environment that I’m using:
IDE: Visual Studio Code with PlatformIO plugin
Board: Espressif ESP32 Dev Module
Framework: Arduino
Thanks Jens. Unfortunately when I switch to the upstream version, I encounter 2 new problems. Note that I was previously using the #feature/stage branch, which seems to no longer exist. I’ve included the Platformio.ini settings at the bottom of the post.
Problem #1
After switching to the upstream version, the compiler can no longer find the following items that my project depends on:
esp_app_desc_t
esp_ota_get_partition_description
It looks like these existed in the version of the espressif arduino framework that was used by the feature/stage branch of the espressif32 platform, but not in the upstream version. To work around this, I added the following to force Platformio to use the latest version of the arduino framework: platform_packages = framework-arduinoespressif32 @ GitHub - espressif/arduino-esp32: Arduino core for the ESP32
Problem #2
After adding the platform_packages statement shown above, the compiler can now find the items that were missing before. However, now the linker starts throwing the following error several hundred or thousand times: dangerous relocation: windowed longcall crosses 1GB boundary; return may fail
To confirm that it’s not a problem with my project, I created a brand new project from the PlatformIO Home tab, and entered the PlatformIO.ini settings shown at the very bottom of this post (Problem #2 settings). The linker error still occurs with a completely blank project.
Does anybody know what could be causing this linker error? I haven’t seen it before and am having trouble figuring out what I’m doing wrong even after a lot of searching the web.
My solution has landed as promised, it uses an extra_script to patch x4 fields (app-name/version, build-date/time) into the image, after it has been compiled, and recalculates checksum & sha256.