Skip to content

Cannot use mbedtls in esp-idf from main firmware #957

Open
@maxgerhardt

Description

@maxgerhardt

Reproduction:

  1. Create a new blank ESP-IDF project for ESP32 Dev Module
  2. Modify the source code src/main.c to
#include "mbedtls/aes.h"

void app_main() {
   mbedtls_aes_context ctx;
   mbedtls_aes_init(&ctx);
}

3, Hit compile:

Linking .pio/build/esp32dev/firmware.elf
/home/max/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32dev/src/main.o:(.literal.app_main+0x0): undefined reference to `mbedtls_aes_init'
/home/max/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32dev/src/main.o: in function `app_main':
/home/max/temp/espidf_mbedtls_bug/src/main.c:6: undefined reference to `mbedtls_aes_init'
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32dev/firmware.elf] Error 1
  1. Realize when looking at the verbose compile log, that when the mbedtls library is compiled, it does so with the flag
-DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" 
  1. Realize that this flag is not in the compiler invocation for the firmware files in src/.
  2. Set source code to
#define MBEDTLS_CONFIG_FILE "mbedtls/esp_config.h"
#include "mbedtls/aes.h"

void app_main() {
   mbedtls_aes_context ctx;
   mbedtls_aes_init(&ctx);
}

--> it compiles thanks to the config file being correctly selected

Linking .pio/build/esp32dev/firmware.elf
Retrieving maximum program size .pio/build/esp32dev/firmware.elf
Checking size .pio/build/esp32dev/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   3.5% (used 11312 bytes from 327680 bytes)
Flash: [==        ]  16.1% (used 169253 bytes from 1048576 bytes)
Building .pio/build/esp32dev/firmware.bin
esptool.py v4.2.1
Creating esp32 image...
Merged 2 ELF sections
Successfully created esp32 image.
============[SUCCESS] Took 7.62 seconds =============

Conclusion: "Something" is preventing the src/ files in the main PlatformIO projects from getting the critical macro for the mbedtls config file. This causes problems when calling some mbedtls functions which the actual config redefined to have other names.

See discussion in community topic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions