/odin-native:resource-optimization-lowendfrom ODIN Native
Reduces flash and RAM usage on constrained MCUs by analyzing linker map files, measuring stack depth, and tuning -Os size-versus-speed tradeoffs for bare-metal and small RTOS firmware.
Ships in ODIN Native. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
| Field | Bound contract |
|---|---|
| Trigger | Firmware exceeds its flash or RAM budget, a stack overflows in production, a linker map needs reading, or -Os versus -O2 needs deciding per file. |
| Authority | Read-only. Emits analysis and commands for the operator to run; no file writes, no rollback needed. No remote mutation. |
| Side effect | Measurement commands and a size verdict in chat. Nothing is written. |
| Done | The largest flash or RAM consumers are named from the map file, and each has a stated reduction tactic. |
-Wl,-Map= output.binutils matching the target, for example arm-none-eabi-*.Measure the image.
arm-none-eabi-size -A firmware.elf
arm-none-eabi-objdump -h firmware.elf
nm --size-sort -S firmware.elf | tail -20
Done when: section totals and the largest symbols are known.
Read the linker map. Generate it at link time and grep the sections.
gcc ... -Wl,-Map=firmware.map
grep -E '\.text|\.rodata|\.data|\.bss' firmware.map | head
Look for the largest symbols and for library code pulled in unexpectedly, such as full printf. Done when: the top consumers are named with their sizes.
Apply the size flags.
| Flag | Effect |
|---|---|
-Os | Optimize for size |
-ffunction-sections -fdata-sections | One section per symbol |
-Wl,--gc-sections | Drop unreferenced sections |
-flto | Cross-TU dead code elimination |
-specs=nano.specs | Smaller newlib on ARM GCC |
-Wl,--print-memory-usage | Print region usage at link time |
CFLAGS += -Os -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections -Wl,--print-memory-usage
--gc-sections can collect interrupt vectors and other unreferenced entry points; pin them with KEEP() in the linker script. Done when: the flags are on and the image still boots.
Measure the stack.
# Static per-function usage, from -fstack-usage builds
find . -name '*.su' -exec cat {} \;
# Stack bound symbol from the linker script
grep _estack firmware.map
At runtime, fill the stack with a pattern such as 0xDEADBEEF, run the worst-case path, and scan for the high-water mark. Under FreeRTOS use uxTaskGetStackHighWaterMark. Done when: worst-case stack depth is measured, not guessed.
Cut RAM by section.
| Section | Tactic |
|---|---|
.bss | Shrink buffers; use pool allocators |
.data | Move constants to flash with const, landing them in .rodata |
| Heap | Avoid malloc; use fixed pools |
| Stack | Reduce call depth; size ISR stacks separately |
Done when: each RAM section has a named reduction.
Decide size versus speed per file.
Hot path in an ISR or a fast control loop?
|-- yes -> -O2 for that file (#pragma GCC optimize or per-file flags)
+-- no -> -Os globally
Done when: hot files carry -O2 and the rest stay at -Os.
| Symptom | Cause | Fix |
|---|---|---|
printf is the largest pull-in | Full newlib implementation | Retarget _write; use a tiny printf |
--gc-sections broke an IRQ | Vector or handler collected | KEEP() it in the linker script |
| Stack overflow appears late | Deep call plus IRQ nesting | Measure the high-water mark; raise the stack bound |
| RAM is free but the ELF is large | .data not loaded from flash | Check VMA versus LMA in the linker script |
| LTO link fails | Mixed compiler versions | Build every object with the same GCC |
A size report naming the top flash and RAM consumers from the map file, the flags applied, the measured stack bound, and the per-file optimization split.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
firmware-optimization, linker-map, stack-analysis, embedded, mcu
npx claudepluginhub outlinedriven/odin-claude-plugin --plugin odin-native138 skills in this plugin
/abi-and-calling-conventionsUse when explaining System V AMD64, ARM AAPCS, RISC-V psABI, stack frames, variadic calls, or FFI register rules. Not for the Rust FFI binding layer: use rust-ffi./adc-dac-baremetalUse when configuring ADC sampling time, DMA-driven ADC, calibration, or DAC channel setup on bare-metal MCUs. Not for the DMA stream itself: use dma-baremetal./af-xdpUse when creating AF_XDP sockets, configuring UMEM and XSK rings, writing an XDP redirect program, or choosing copy versus zero-copy mode. Not for full kernel bypass: use dpdk.Other plugins' skills for the same job