mcpField
R
resource-optimization-lowend

resource-optimization-lowend

github.com/mohitmishra786Development269296 installsUpdated 18w ago
Repository

About resource-optimization-lowend

resource-optimization-lowend guides agents in reducing flash and RAM use on constrained devices, including bare-metal and small RTOS firmware. It covers image-size analysis, linker maps, stack measurement, and size-versus-speed tradeoffs.

Key features

  1. 01Analyze ELF and linker map files
  2. 02Find large symbols
  3. 03Apply compiler and linker size flags
  4. 04Measure static and runtime stack use
  5. 05Balance code size and execution speed

Use cases

  1. 01Investigate firmware exceeding its flash budget
  2. 02Find unexpected .rodata or .bss growth
  3. 03Diagnose stack overflows in production
  4. 04Choose -Os or -O2 for an MCU

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill resource-optimization-lowend

After installing, type/resource-optimization-lowendin Claude Code to confirm it loaded.

Details

From the project README

Resource Optimization (Low-End Systems)

Purpose

Guide agents through flash and RAM optimization on constrained devices: compiler size flags, linker map analysis, stack usage measurement, dead code elimination, and size-vs-speed tradeoffs — for bare-metal and small RTOS images.

When to Use

  • Firmware exceeds flash budget
  • Stack overflow in production only
  • Choosing -Os vs -O2 on MCU
  • Finding unexpected .rodata or .bss growth

Workflow

1. Size measurement toolchain
arm-none-eabi-size -A firmware.elf
arm-none-eabi-objdump -h firmware.elf
nm --size-sort -S firmware.elf | tail -20
2. Linker map file
/* linker.ld */
OUTPUT_FORMAT("elf32-littlearm")
ENTRY(Reset_Handler)

SECTIONS
{
  /* ... */
}

/* Generate map */
/* gcc ... -Wl,-Map=firmware.map */
grep -E '\.text|\.rodata|\.data|\.bss' firmware.map | head

Identify largest symbols and unexpected library pull-in.

3. Compiler flags
FlagEffect
-OsSize-first optimization
-ffunction-sections -fdata-sectionsPer-symbol sections
-Wl,--gc-sectionsDrop unused sections
-fltoCross-TU dead code elimination
-specs=nano.specsSmaller newlib (GCC ARM)
CFLAGS += -Os -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections -Wl,--print-memory-usage
4. Stack analysis
# Static (if built with -fstack-usage)
find . -name '*.su' -exec cat {} \;

# Linker stack symbol
grep _estack firmware.map

Runtime: fill stack with pattern (0xDEADBEEF), run tests, scan high-water mark. FreeRTOS: uxTaskGetStackHighWaterMark.

5. RAM categories
SectionTactic
.bssShrink buffers; pool allocators
.dataMove const to flash (const → .rodata)
HeapAvoid malloc; fixed pools
StackReduce nesting; smaller ISR stacks
6. Size vs speed decision
Hot path in ISR or 1 kHz loop?
├── Yes → -O2 for that file (#pragma GCC optimize)
└── No  → -Os globally
7. Agent usage
/resource-optimization-lowend Find top 10 flash consumers in firmware.map and suggest -gc-sections fixes

Common Problems

SymptomCauseFix
printf pulls 20+ KBFull newlib printf_write retarget; tiny printf
--gc-sections broke IRQSection collectedKEEP() in linker script
Stack overflow lateDeep call + IRQ nestMeasure HW stack; increase _estack
RAM zero but big ELF.data not loadedCheck VMA/LMA
LTO link failMixed compiler versionsSame GCC for all objects

Related Skills

  • skills/embedded/linker-scripts — MEMORY/Sections layout
  • skills/baremetal/baremetal-startup — stack symbol
  • skills/baremetal/low-power-embedded — RAM retention
  • skills/compilers/gcc — optimization flags
  • skills/rust/rust-no-std — embedded Rust size patterns

Comments

Markdown supported