How to obtain length of binary COMPONENT_EMBED_FILES

papaluna
Posts: 50
Joined: Tue Jan 30, 2018 11:27 am

How to obtain length of binary COMPONENT_EMBED_FILES

Postby papaluna » Tue Feb 26, 2019 8:04 am

What is the simplest way to obtain the length in bytes of an embedded binary file when using https://docs.espressif.com/projects/esp ... inary-data?

Is an attribute available which returns the length or do I have to compute it myself?

This is the way I do it right now:

Code: Select all

COMPONENT_EMBED_FILES := kafka_status_ok.message

Code: Select all

extern const uint8_t kafka_status_ok_message_start[] asm("_binary_kafka_status_ok_message_start");
extern const uint8_t kafka_status_ok_message_end[] asm("_binary_kafka_status_ok_message_end");

int len_buffer = sizeof(uint8_t) * (kafka_status_ok_message_end - kafka_status_ok_message_start);
--
Paul.

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: How to obtain length of binary COMPONENT_EMBED_FILES

Postby ESP_igrr » Tue Feb 26, 2019 10:05 am

The way you are doing this now seems to be the correct one. I don't think there is any better option when using just COMPONENT_EMBED_FILES without any extra logic.

(extra logic would be: determine size of the file at Make run time, store it as a variable, add -DMY_FILE_LEN=$(length_var) to CPPFLAGS...)

papaluna
Posts: 50
Joined: Tue Jan 30, 2018 11:27 am

Re: How to obtain length of binary COMPONENT_EMBED_FILES

Postby papaluna » Tue Feb 26, 2019 10:12 am

Thanks.
--
Paul.

FiwiDev
Posts: 22
Joined: Wed Jan 22, 2020 12:32 am

Re: How to obtain length of binary COMPONENT_EMBED_FILES

Postby FiwiDev » Thu Jan 04, 2024 10:43 pm

ESP_igrr wrote:
Tue Feb 26, 2019 10:05 am
The way you are doing this now seems to be the correct one. I don't think there is any better option when using just COMPONENT_EMBED_FILES without any extra logic.

(extra logic would be: determine size of the file at Make run time, store it as a variable, add -DMY_FILE_LEN=$(length_var) to CPPFLAGS...)
I was digging through a compiled MAP output (trying to find the actual handles the compiler used for the embedded files), and noticed that there appears to be a "size" attribute also provided. See below...

Code: Select all

_binary_web_index_htm_end                         .pio/build/esp32dev/index.htm.txt.o
                                                  .pio/build/esp32dev/src/wifi.cpp.o
_binary_web_index_htm_size                        .pio/build/esp32dev/index.htm.txt.o
_binary_web_index_htm_start                       .pio/build/esp32dev/index.htm.txt.o
                                                  .pio/build/esp32dev/src/wifi.cpp.o
_binary_web_script_js_end                         .pio/build/esp32dev/script.js.txt.o
                                                  .pio/build/esp32dev/src/wifi.cpp.o
_binary_web_script_js_size                        .pio/build/esp32dev/script.js.txt.o
_binary_web_script_js_start                       .pio/build/esp32dev/script.js.txt.o
                                                  .pio/build/esp32dev/src/wifi.cpp.o
_binary_web_style_css_end                         .pio/build/esp32dev/style.css.txt.o
                                                  .pio/build/esp32dev/src/wifi.cpp.o
_binary_web_style_css_size                        .pio/build/esp32dev/style.css.txt.o
_binary_web_style_css_start                       .pio/build/esp32dev/style.css.txt.o
                                                  .pio/build/esp32dev/src/wifi.cpp.o
I'm not well versed in the binutils, i.e. trying to figure out if that symbol is actually mapped to a memory address, what size the symbol is (assuming 32-bit?), and what value it is. Tried defining an "asm("")" to reference the corresponding "*_size" entry to a size_t, but it just crashes the ESP32 every time I try to access it.

I mean, doing "end - start" is one way to get the length--but heck, if there's a better way...what's the trick?

Who is online

Users browsing this forum: No registered users and 82 guests