Hello,
I have a proprietary binary that contains executable code which I need to include in the final firmware built with ESP-IDF. Here are my specific requirements:
The binary must be included in the final firmware binary.
The binary needs to be aligned on a page boundary.
I need variables for the start and end addresses of the binary in memory.
I am using ESP-IDF version 5.2.1.
I have tried the method described in the following link to embed binary data:
ESP-IDF: https://docs.espressif.com/projects/esp ... inary-data
However, it turns out that the binary is not aligned as required.
Could someone please provide guidance or an example on how to correctly include and align the binary on a page boundary while having the start and end address variables available in the code?
Thank you!
How to Include and Align a Proprietary Binary in ESP-IDF Firmware
-
- Posts: 9727
- Joined: Thu Nov 26, 2015 4:08 am
-
- Posts: 52
- Joined: Fri Aug 11, 2023 4:56 am
Re: How to Include and Align a Proprietary Binary in ESP-IDF Firmware
This is indeed a very unusual requirement on parts like this. When you have only a few hundred K - and nothing like a general purpose MMU that imposes such requirements - burning up to 4095 bytes of address space just to get it on an alignment of 4096 is not to be taken lightly.
But if you're insistent upon doing so (and doing it well) you're going to need to cozy up to the linker scripts on sections and force alignment and symbol addition there. There are dozens of examples in the existting scrips where certain data is forced into specific sections with _start and _end symbols bookending them.
There's tons of doc on GNU ld, but you can find snippets without much context at https://ftp.gnu.org/old-gnu/Manuals/ld- ... ld_21.html
I haven't used it, but https://docs.espressif.com/projects/esp ... ation.html looks like it tries to smear a coat of usability over the raw GNU ld interface. Having 30+ years experience with GNU ld myself, I'm not sure it succeeds, but I'm probably not the target audience. Still, it's an option for you. You might find inspiration (though you need associated understanding) with examples like:
In doing this, you can also end up accidentally "hiding" requirements of the code outside the obvious parts of the code and create a nightmare for your successor (which might be a future you) that has to port this to a new part. Tread lightly and document well.
But if you're insistent upon doing so (and doing it well) you're going to need to cozy up to the linker scripts on sections and force alignment and symbol addition there. There are dozens of examples in the existting scrips where certain data is forced into specific sections with _start and _end symbols bookending them.
There's tons of doc on GNU ld, but you can find snippets without much context at https://ftp.gnu.org/old-gnu/Manuals/ld- ... ld_21.html
I haven't used it, but https://docs.espressif.com/projects/esp ... ation.html looks like it tries to smear a coat of usability over the raw GNU ld interface. Having 30+ years experience with GNU ld myself, I'm not sure it succeeds, but I'm probably not the target audience. Still, it's an option for you. You might find inspiration (though you need associated understanding) with examples like:
Code: Select all
.iram0.text :
{
/* Code marked as runnning out of IRAM */
_iram_text_start = ABSOLUTE(.);
/* Placement rules generated from the processed fragments, placed where the marker was in the template */
*(.iram1 .iram1.*)
*libfreertos.a:(.literal .text .literal.* .text.*)
_iram_text_end = ABSOLUTE(.);
} > iram0_0_seg
-
- Posts: 1704
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: How to Include and Align a Proprietary Binary in ESP-IDF Firmware
The quick brute method would be to add PAGE_SIZE-1 bytes of 0xff before and after the binary's 'payload' data. This ensures that the actual payload doesn't share any page with other data/sections and can thus be erased/updated independently from the application, as long as its size stays the same.
Or, you can convert the binary into a C array initialization during the build and have that array aligned through C means.
Or, you can convert the binary into a C array initialization during the build and have that array aligned through C means.
Who is online
Users browsing this forum: Bing [Bot] and 101 guests