I want to set my application version into the app description block (right at the beginning of the firmware.bin) so that I can stop my customers from downgrading the application with OTA. How can I achieve this with platformio?
Is this a framework = espidf
project? Then, regular ESP-IDF docs apply.
Framework is arduino. I wasn’t aware that this is important.
I don’t think this is (easily) possible for Arduino-ESP32 v2.x, because it links with libapp_update.a
which has a hardcoded, non-weak definition of the “esp_app_desc” structure that holds this project info. And that always has a version field of “esp-idf: v4.4.7-dirty” and a “project name” of “arduino-lib-builder”, with time and date of Mar 5, 2024, 12:36:24.
It only got changed to being a weak
, overridable definition in Arduino-ESP32 v3.x (and the accompanying ESP-IDF update).
Of course, one could overwrite that info but then the verification hashes and checksums afterwards would not be correct anymore.
Are you compiling your firmware against Arduino-ESP32 2.x using the official espressif32 platform or are you using https://github.com/pioarduino/platform-espressif32 to compile against Arduino-ESP32 3.x?
Mh, after some experimenting, it overwriting the app description block does work in Arduino-ESP32 3.x.
Just creating a new source file ver.c
(it really has to be a .c file) and writing (similiar to this)
#include <assert.h>
#include <sys/param.h>
#include <string.h>
#include "esp_app_desc.h"
#include "sdkconfig.h"
#include "esp_log.h"
#if defined(__APPLE__) && CONFIG_IDF_TARGET_LINUX
const __attribute__((weak)) __attribute__((section("__RODATA_DESC,.rodata_desc"))) esp_app_desc_t esp_app_desc = {
#else
const __attribute__((weak)) __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
#endif
ESP_APP_DESC_MAGIC_WORD,
0,
{0,0},
"3.2.12",
"My awesome project",
__TIME__,
__DATE__,
IDF_VER
};
will make the resultant firmware.bin
show those strings at the app description block (offset +0x10).
Without that file: