Page 1 of 1

esp_app_desc huge flash usage

Posted: Wed May 22, 2024 8:56 pm
by msn444
Using IDF 5.3.0 (esp32), I'm trying to reduce my binary size and have found that the esp_app_desc object is a huge factor.

Code: Select all

                                                                         Per-file contributions to ELF file                                                                         
┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┓
┃ Object File          ┃ Total Size ┃ DRAM ┃ .bss ┃ .data ┃ IRAM ┃ .text ┃ .vectors ┃ Flash Code ┃ .fini ┃ .text ┃ Flash Data ┃ .rodata ┃ .appdesc ┃ RTC SLOW ┃ .rtc_slow_reserved ┃
┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━╇━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━┩
│ esp_app_desc.c.obj   │     101024 │   17 │   17 │     0 │    0 │     0 │        0 │        446 │     0 │   446 │     100561 │  100305 │      256 │        0 │                  0 │
│ ed25519_ref10.c.obj  │      40890 │    0 │    0 │     0 │    0 │     0 │        0 │      10170 │     0 │ 10170 │      30720 │   30720 │        0 │        0 │                  0 │
│ ecp_curves.c.obj     │      35219 │    0 │    0 │     0 │    0 │     0 │        0 │       5679 │     0 │  5679 │      29540 │   29540 │        0 │        0 │                  0 │
│ phy_chip_v7.o        │      21219 │ 2558 │  533 │  2025 │ 2190 │  2190 │        0 │      16471 │     0 │ 16471 │          0 │       0 │        0 │        0 │                  0 │
│ wl_cnx.o             │      19496 │ 3891 │ 3889 │     2 │  277 │   277 │        0 │      13997 │     0 │ 13997 │       1331 │    1331 │        0 │        0 │                  0 │
│ x509_crt_bundle.S.ob │      16826 │    0 │    0 │     0 │    0 │     0 │        0 │          0 │     0 │     0 │      16826 │   16826 │        0 │        0 │                  0 │
│ j                    │            │      │      │       │      │       │          │            │       │       │            │         │          │          │                    │
It's even worse when targeting C3/C6. Previous builds on IDF 4.4.7 had esp_app_desc weighing in at around 500 bytes. Is this expected, and does anyone know how to get it back to reasonable levels? What on earth is all that .rodata?

Re: esp_app_desc huge flash usage

Posted: Thu May 23, 2024 2:21 am
by ESP_Sprite
That's a known issue and it's already fixed in the latest master. Lemme check if I can find the commit, maybe you can cherrypick it.

Re: esp_app_desc huge flash usage

Posted: Thu May 23, 2024 3:33 am
by ESP_Sprite
Ah, turns out it's something related but different. It's likely a red herring. According to my co-devs, we enabled a function that merges string constants over the entire project (ironically, this *saves* flash memory), but it ends up dumping all those string constants into one library when the project is linked. Seems esp_app_desc is that library in your build. You can check by simply looking at the object itself: for me, ./build/esp-idf/esp_app_format/CMakeFiles/__idf_esp_app_format.dir/esp_app_desc.c.obj is only 21K (and that includes debug symbols etc) while esp-idf size-files says it contains 25K of rodata.

Re: esp_app_desc huge flash usage

Posted: Thu May 23, 2024 4:10 am
by msn444
Thanks, yes, I did notice that and was puzzled by it. That raises a couple of questions:

  • Upon switching to IDF 5.3 from IDF 4.4.7, I'm finding the binary size to have gone from 1210kb to 1348kb (with same optimization settings). Is this to be expected, and can it be mitigated?
  • Can the string constants that you mentioned are being dumped into esp_app_format be reduced?