size

A command that reads a Keil compiler .map file, a build report describing where firmware uses memory. It reports Flash, RAM, stack, and heap allocation and compares usage with warning limits.

In plain words
What is it for?
Use it with Keil MDK projects to scan a map file, calculate memory usage, and show normal, warning, or over-limit status. It can also output JSON.
Why use it?
It makes it easier to spot firmware that is approaching the chip's memory limits before the problem causes a build or runtime failure.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/jzl-maker/ea-skill/size
Clone the repo
git clone --depth 1 https://github.com/jzl-maker/EA-SKILL
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,336 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01336
Opus 5 $0.00000 $0.00668
Sonnet 5 $0.00000 $0.00267
Haiku 4.5 $0.00000 $0.00134

Measured 2d ago against content hash a81fcbfeb600, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

size scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/size.md · 78 lines

How it starts

The opening of the file, as written. The whole thing — 78 lines — stays where its author put it; the contents beside it link to each section on GitHub.

命令: /ea size (固件资源分析)

功能

解析 Keil 编译生成的 .map 文件,统计固件 Flash / RAM / 栈 / 堆 使用情况,并支持超限预警(使用率 ≥ warn 警告,≥ err 超限)。

能力 数据来源 说明
Flash 用量 Total ROM Size(Code + RO Data + RW Data) 对比 Flash 容量出使用率
RAM 用量 Total RW Size(RW Data + ZI Data) 对比 RAM 容量出使用率
栈/堆 Global Symbols 里 STACK / HEAP Section ⚠️ startup 定义的分配量,非运行期峰值
超限预警 使用率 vs --warn/--err 阈值 ✅ 正常 / ⚠️ 偏高 / ❌ 超限
容量来源 Execution Region 的 Max(链接脚本区域上限) --flash-kb/--ram-kb 可覆盖

适用:Keil MDK 工程(armcc v5 / armclang v6 的 .map 格式)。GCC/其他工具链暂不支持。

调用方式

py ~/.claude/skills/ea-skill/tools/resource/scripts/size_tool.py --project <工程目录>
# 自动扫描工程下最新 .map → 输出 Flash/RAM 使用率 + 栈/堆 + 预警

# 显式指定 .map(编译产物在 Listings/ 或 build/ 下)
py .../size_tool.py --map build/xxx.map

# 覆盖容量 + 收紧阈值(芯片实际容量与链接脚本不一致时)
py .../size_tool.py --map build/xxx.map --flash-kb 512 --ram-kb 144 --warn 85 --err 92

# AI 解析用 JSON
py .../size_tool.py --map build/xxx.map --json

参数表

参数 必须 说明
--map <file> 是(动作) 显式指定 .map 文件
--project <dir> 是(动作) 工程目录,扫描最新 .map
--flash-kb N Flash 容量 KB(缺省用链接脚本 region Max)
--ram-kb N RAM 容量 KB(缺省用链接脚本 region Max)
--warn 预警阈值 %(默认 90)
--err 超限阈值 %(默认 95)
--json 结构化 JSON 输出
--dry-run 只打印流程不解析

工作流程(AI 执行闭环)

1. 定位 .map     --project 扫描,或 --map 显式指定(通常 Listings/ 或 build/ 下)
2. 容量确定      缺省 region Max;芯片手册容量与链接脚本不符时 --flash-kb/--ram-kb 覆盖
3. 读取总量      Flash = Total ROM,RAM = Total RW
4. 计算使用率    used/capacity × 100 → ✅/⚠️/❌
5. 栈/堆         STACK/HEAP 分配量(startup 定义)
6. 预警判断      任一 ≥ warn 提示,≥ err 标超限 → 结论(是否逼近容量上限)

示例闭环:/ea size --project . --flash-kb 512 --ram-kb 144 → Flash 21.8% ✅、RAM 50.4% ✅、栈 32KB → 判断固件内存余量充足。

注意事项

  1. 栈/堆是分配量:STACK/HEAP 是启动文件里定义的大小(本工具读 .map 符号值),不是运行期实际峰值。实际峰值栈用 /ea debug 读 SP(__initial_sp - SP)测量。
  2. 容量缺省取链接脚本 region Max.sctLOAD_REGION/RW_IRAM1 的 Max 就是芯片可用量;若链接脚本人为缩小区域(如给 BootLoader 预留),Max 会小于芯片容量,此时用 --flash-kb/--ram-kb 覆盖成芯片真实值。
  3. ZI-data 计入 RAM:Total RW = RW Data + ZI Data(含 bss 未初始化段)。
  4. GBK 编码兼容:工程路径含中文时 .map 可能是 GBK 编码,解析器自动回退。

Read the full file on GitHub · 78 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 78 lines · 0 tokens per session scan A a81fcbfeb600

Subscribe to this mod's changes

size is a command published in the GitHub repository jzl-maker/EA-SKILL (6 stars, last pushed 5d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,336 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.