Files
firmware/extra_scripts
Ben Meadors 2fb9b2fa8c tools: attribute flash to source files through LTO inlining
We had no way to answer "where is our flash actually going" on the LTO'd
nRF52 builds. bin/analyze_map.py reads the linker map, which tells you which
object file contributed a section - a question whole-image LTO stops
answering usefully once it inlines across translation units. `nm --size-sort`
has the same problem from the other end: the biggest symbol in an nRF52 image
is `setup` at ~8.9 KB, which is really dozens of inlined module initialisers
from all over src/.

bin/flash_attribution.py walks the disassembly instead, asks addr2line for
the inline stack at every instruction, and charges each instruction's bytes
to the innermost frame. Output is a per-subsystem rollup plus the heaviest
source files. Only needs objdump/addr2line from the toolchain.

Sample rak4631 run (.text 767,036 B): src/mesh 8.7%, src/modules 7.4%,
src/graphics/draw 5.9%, framework 5.3%, Telemetry 4.9%, newlib/libstdc++
4.4%. Heaviest files NodeDB.cpp 14,890 - AdminModule.cpp 12,508 -
MenuHandler.cpp 12,310 - XEdDSA.cpp 12,030 - GPS.cpp 11,818. It also finds
costs that have no symbol to sort by at all, e.g. ~14 KB of C++ template
instantiation charged to stl_vector.h / std_function.h / stl_tree.h.

extra_scripts/debug_info.py turns the required DWARF on behind
MESHTASTIC_DEBUG_INFO=1. Two non-obvious reasons it needs to be a script
rather than a build flag:

  - nrf52.ini's build_unflags strips -g, -g0..-g3 and -ggdb2/3, so the usual
    spellings get removed again. -gdwarf-4 is not in that list.
  - under -flto the code is generated by lto1 at LINK time, so -g is needed
    on the link line too. Compile-only leaves ~96% of an nRF52 image
    unresolvable; adding LINKFLAGS takes it to ~30%, the rest being vendor
    blobs with no source (newlib, CryptoCell, BSEC) and rodata in .text.

Debug info goes to non-allocated sections, so this does not change image
size: rak4631 links at 0xE46D8 either way. Verified the script is inert
without the variable - the resulting ELF has no .debug_* sections at all -
and that it loads cleanly on esp32 as well as nrf52.
2026-07-27 10:29:09 -05:00
..
2026-07-01 19:01:27 -05:00
2026-07-01 19:01:27 -05:00
2026-07-01 19:01:27 -05:00

extra_scripts

This directory contains special scripts that are used to modify the platformio environment in rare cases.