Hey,
I have a problem with embedding and using a certificate in my ESP32 application (ESP-IDF framework, not Arduino). I am using PlatformIO 4.3.1 and the Espressif32 framework 1.12 (ESP-IDF 4.0).
Within platformio.ini I specified my .pem file to be included into my binary. This seems to work as I do not get an error message. Within my source code (main.c) I am using
extern const uint8_t server_cert_pem_start[] asm("_binary_src_cert_pem_start");
to reference the certificate. The linker, however, tells me that it cannot find _binary_src_cert_pem_start
Here is the full error message:
/Users/Mr_Blonde/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/pico32/esp-idf/src/main.c.o:(.literal.simple_ota_example_task+0xc): undefined reference to `_binary_src_cert_pem_start'
collect2: error: ld returned 1 exit status
*** [.pio/build/pico32/firmware.elf] Error 1
For me it seems that the linker reference / symbol name is not properly created by the build environment. I tried to use:
board_build.embed_txtfiles =
src/cert.pem
as well as
build_flags = -DCOMPONENT_EMBED_TXTFILES=src/cert.pem
within platformio.ini. But neither worked. I also modified the reference in the source code to exclude the _src (as mentioned in the PlatformIO documentation) with, again, no success. My question is: What am I doing wrong? Do I have to add/modify something else besides platformio.ini and my source code? Do I need to add something to CMakeLists.txt (or other files)? I have seen modifications within CMakeLists.txt but my understanding is that this is only required for using the ESP-IDF natively (without platformio).
Thanks in advance!
my platformio.ini:
[env:pico32]
platform = espressif32
board = pico32
framework = espidf
board_build.partitions = partition_ota.csv
monitor_speed = 115200
monitor_port = /dev/cu.usbserial-14201
upload_port = /dev/cu.usbserial-14201
board_build.embed_txtfiles =
src/cert.pem
;build_flags = -DCOMPONENT_EMBED_TXTFILES=src/cert.pem
Directory structure:
[project-folder]
- src/
- - main.c
- - cert.pem
- platformio.ini
Source snippet:
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_http_client.h"
#include "esp_https_ota.h"
#include "string.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "esp_wifi.h"
extern const uint8_t server_cert_pem_start[] asm("_binary_src_cert_pem_start");
extern const uint8_t server_cert_pem_end[] asm("_binary_src_cert_pem_end");
void simple_ota_example_task(void *pvParameter) {
ESP_LOGI(TAG, "Starting OTA example");
esp_http_client_config_t config = {
.url = FIRMWARE_UPGRADE_URL,
.cert_pem = (char *)server_cert_pem_start, // that's the line the linker has its issue with
.event_handler = _http_event_handler,
};
// More code to follow
}
void app_main(void) {
// DO STUFF HERE
}