Memory Mapping Linked Code for ESP32 Builds

Hello All,

I have successfully utilized PlatformIO on VSCode as the development environment for a prototype product idea based on the ESP32 device. After gaining familiarity with the device and the esp-idf (using both BLE and WiFi connectivity), I am ready to take steps to utilize this device on other products of ours to replace more costly communications radios. In order to do so, I have to manage some limitations in our current OTA firmware update architecture.

Our existing products utilize a serial flash device to store downloaded OTA images before they are validated, unencrypted and flashed into our host controller or radio. The current serial flash size limits these images to 512KB each. The code running on the ESP32 exceeds this footprint, so I was considering the thought of memory mapping the esp-idf components and my application components in separate areas which could then be updated independently.

An analysis of the mapping file for my existing ESP32 prototype project shows the linker randomly places pieces of my application code and the esp-idf content all over the memory map. The linker is apparently using a default linker script, a copy of which gets placed into the build directory during the build process.

Is it possible to utilize a custom linker script file under PlatformIO to accomplish the memory mapping I desire?

If so, are there any examples in existence that I can reference?

Thanks in advance!
Mark

Per code and docs, use

board_build.ldscript = /path/to/ldscript.ld

in the platformio.ini to overwrite the build script.

ESP-IDF is a bit complicated in regards to the linker script, as you can see in the linked code there’s actually a generation logic to generate a final <esp chip type>_out.ld file from a base ld file, e.g. this one, using GCC. This also involves other files in that directory.

If you only want to change that template file and not the final x_out.ld file, use board_build.esp-idf.ldscript = /path/to/ldscript.ld to change that, as the code allows it.

For details what content to modify of the linkerscript to get your desired memory map, I’d suggest opening an issue in ESP-IDF.

Thanks for the explanation… and the links to documentation! :grinning:

I have definitely noticed the complexity of the ESP-IDF suite, so this prototype project was a very good exercise to gain some familiarity. The use of PlatformIO has been a huge step forward from the command line tool suite offered by Espressif.

It is good to hear I have a few options with the linker script modification. I will check out the links you provided and attempt to make the necessary changes to support our mapping requirements.

Best Regards,
Mark