Static flash/RAM footprint analysis for ARM Cortex-M binaries (M0/M4/M7/M33)
Project description
cortex-memory-budget
Static flash/RAM footprint analysis for ARM Cortex-M binaries — CI-friendly, framework-agnostic, zero runtime dependencies.
cortex-memory-budget analyzes an ELF binary (via arm-none-eabi-objdump,
nm, and addr2line) and reports how much flash and RAM your
firmware consumes, broken down by memory region, section, symbol, and
source file. Pre-allocated stack and heap are detected via linker
symbols with section-based fallback.
It supports Cortex-M0, Cortex-M4, Cortex-M7, and Cortex-M33 and is designed for resource-constrained MCUs where every kilobyte of flash and every byte of RAM matters.
✨ Features
| Feature | Status |
|---|---|
| Cortex-M0 / M4 / M7 / M33 supported | ✅ |
Linker-script MEMORY {} auto-detect (with config override) |
✅ |
| Region utilisation report with ASCII bar charts | ✅ |
.data double-counted (flash LMA + RAM VMA) |
✅ |
| Per-section breakdown | ✅ |
| Top-N symbol table (per region) | ✅ |
Per-source-file aggregation via DWARF (addr2line) |
✅ |
| Pre-allocated stack & heap detection (symbol + section) | ✅ |
| Diff mode against a baseline ELF | ✅ |
| Multi-mode analyzer (multiple configs in one run) | ✅ |
| GitHub composite action + reusable workflow | ✅ |
| PR comment with stable marker (idempotent update) | ✅ |
--fail-over-flash-pct / --fail-over-ram-pct CI gates |
✅ |
| Machine-readable JSON metrics | ✅ |
🚀 Quickstart
1. Install
pip install cortex-memory-budget
Runtime dependencies: none (Python ≥ 3.11 stdlib only). At analysis time
you need arm-none-eabi-objdump, arm-none-eabi-nm, and
arm-none-eabi-addr2line on PATH, or pass --objdump/--nm/--addr2line.
2. Write a config (memory-analysis.json)
{
"top_n_symbols": 20,
"top_n_source_files": 15,
"regions": [
{"name": "FLASH", "length_kb": 1024},
{"name": "SRAM", "length_kb": 192}
]
}
regions is optional — if omitted (or for regions not listed), values are
taken from the linker script passed via --linker-script. See
docs/config-schema.md for the full schema.
3. Run
cortex-memory-budget memory-analysis.json \
--elf build/firmware.elf \
--target nucleo-h743zi \
--build-config Release \
--cortex m7 \
--linker-script firmware.ld \
--output-dir reports
Outputs in reports/:
| File | Purpose |
|---|---|
memory_report.md |
Full Markdown report (regions / sections / symbols / src) |
pr_comment.md |
Compact PR comment (with idempotent marker) |
memory_metrics.json |
Machine-readable summary for downstream tooling |
memory_diff.md |
(When --baseline-elf given) per-symbol/section delta |
4. Use in GitHub Actions
- uses: embedded-pro/cortex-memory-budget@v0
with:
config-path: memory-analysis.json
elf-path: build/firmware.elf
baseline-elf-path: baseline/firmware.elf # optional, enables diff
target: nucleo-h743zi
build-config: Release
cortex: m7
linker-script-path: firmware.ld
fail-over-flash-pct: 85
fail-over-ram-pct: 80
The action posts an idempotent PR comment, appends a step summary, and uploads all reports as an artifact. See docs/usage.md for the full input/output reference.
📚 Documentation
| Document | What it covers |
|---|---|
| docs/usage.md | CLI flags, action inputs/outputs, examples |
| docs/config-schema.md | Full JSON config schema + reference |
| docs/memory-model.md | What counts where (.data, COMMON, debug) |
| docs/linker-script-detection.md | Linker-script parser scope & limits |
| docs/cortex-variants.md | M0 / M4 / M7 / M33 notes for memory layout |
| docs/architecture.md | Internal module layout & data flow |
| docs/troubleshooting.md | Common errors & their fixes |
| CONTRIBUTING.md | Dev setup, testing, release process |
| CHANGELOG.md | Version history |
🧪 Examples
Five runnable examples ship in examples/:
| Example | Highlights |
|---|---|
| examples/minimal | Single-region M4 firmware with explicit budgets |
| examples/cortex-m7 | Multi-region layout incl. AXI SRAM |
| examples/cortex-m33 | Single binary spanning two RAM regions |
| examples/multi-mode | One ELF analysed against two budget profiles |
| examples/diff-mode | baseline.elf vs. current.elf growth report |
⚠️ Scope & limitations
This tool gives static post-link footprint analysis. It does not model:
- Worst-case dynamic stack depth (use
-fstack-usage+ a call-graph walker for that). We report only the pre-allocated stack reservation. - Runtime heap fragmentation. We report only the configured heap budget.
- Cache line / row paddings inserted at runtime.
- Externally loaded / overlay / XIP-from-PSRAM code that isn't part of the ELF.
Estimates are intended as a CI guardrail for the static link image.
📄 License
Apache-2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cortex_memory_budget-0.1.0.tar.gz.
File metadata
- Download URL: cortex_memory_budget-0.1.0.tar.gz
- Upload date:
- Size: 31.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36a5f4e24919dd6337c81181e44bac042fec712b6ffb7572af0a8b545e1f7cee
|
|
| MD5 |
39f5fe77e90dd8f1c553822786a2d4a6
|
|
| BLAKE2b-256 |
19e4b92fbdf76af353a7c653c1335faa0ff37fdd7e8ef024ec1d57277900cdb9
|
Provenance
The following attestation bundles were made for cortex_memory_budget-0.1.0.tar.gz:
Publisher:
release.yml on embedded-pro/cortex-memory-budget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cortex_memory_budget-0.1.0.tar.gz -
Subject digest:
36a5f4e24919dd6337c81181e44bac042fec712b6ffb7572af0a8b545e1f7cee - Sigstore transparency entry: 1615905128
- Sigstore integration time:
-
Permalink:
embedded-pro/cortex-memory-budget@82b74bfa88b2d584eb6efa480113a73f61e53586 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/embedded-pro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@82b74bfa88b2d584eb6efa480113a73f61e53586 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cortex_memory_budget-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cortex_memory_budget-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f485afc257569b97e12028bd20ca47cc90320ab0c2a1d48fbe5b70ae172d2fd6
|
|
| MD5 |
69c60bf559722a4ecdcd046544520539
|
|
| BLAKE2b-256 |
6de57999214115ec5fa31fe4ea23fc49fe09445241e372ea77b74641d712b0a5
|
Provenance
The following attestation bundles were made for cortex_memory_budget-0.1.0-py3-none-any.whl:
Publisher:
release.yml on embedded-pro/cortex-memory-budget
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cortex_memory_budget-0.1.0-py3-none-any.whl -
Subject digest:
f485afc257569b97e12028bd20ca47cc90320ab0c2a1d48fbe5b70ae172d2fd6 - Sigstore transparency entry: 1615905165
- Sigstore integration time:
-
Permalink:
embedded-pro/cortex-memory-budget@82b74bfa88b2d584eb6efa480113a73f61e53586 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/embedded-pro
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@82b74bfa88b2d584eb6efa480113a73f61e53586 -
Trigger Event:
push
-
Statement type: