Yes because I thought unflags would be applied first and then build_flags applied on top of that. That should avoid double-definition of the macro and spamming warnings.
But that actually doesn’t work. I had it compile successfully because in blufi_security.c
, above #include "mbedtls/aes.h"
I added
#include "mbedtls/esp_config.h"
1 Like
niels
November 9, 2022, 12:35pm
22
Okay that makes more sense to me.
I did the same as you with #include "mbedtls/esp_config.h"
and it compile successfully!
Can we conclude that this update to the example is needed because of the “porting” of esp-idf to platformio?
1 Like
No something is wrong on the PlatformIO side because the mbedtls config macro isn’t there (when compiling sources in the src/
of the project).
I’ve raised the issue
opened 12:32PM - 09 Nov 22 UTC
bug
ESP-IDF
Reproduction:
1. Create a new blank ESP-IDF project for ESP32 Dev Module
2. Mo… dify the source code `src/main.c` to
```cpp
#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
```
4. 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\"
```
5. Realize that this flag is not in the compiler invocation for the firmware files in `src/`.
6. Set source code to
```cpp
#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](https://github.com/espressif/mbedtls/blob/89da85968417ce4a163b7275cb22f159995c271d/include/mbedtls/aes.h#L43-L48)
```
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](https://github.com/espressif/esp-idf/blob/1cb31e50943bb757966ca91ed7f4852692a5b0ed/components/mbedtls/port/include/aes_alt.h#L30-L39).
See discussion in [community topic](https://community.platformio.org/t/linking-problem-with-the-blufi-example/30365/6?u=maxgerhardt).
niels
November 9, 2022, 12:41pm
24
Okay, thanks again for the exquisite support!
I will go back and see if I can remember what I really wanted to tryout with this example.
Thank you so much for posting the solution, I experienced the same in esphome, solved mine like this.
esphome:
includes:
- include.h
esp32:
board: esp32doit-devkit-v1
framework:
type: esp-idf
Then the include file
#include "mbedtls/esp_config.h"
#include "mbedtls/aes.h"