MapScope
嵌入式 MAP 文件分析器 —— 一个 VSCode 扩展,在一个界面里直观地展示固件的 内存占用 与 地址空间分布,帮助嵌入式工程师快速回答:"Flash 还够不够、RAM 用剩多少、哪个模块/文件吃得最多"。
Embedded MAP file analyzer — a VSCode extension that visualizes firmware memory usage and address-space layout in one place, answering "Is Flash running low? How much RAM is left? Which module/file eats the most?"
MapScope 仅做分析,不修改任何工程代码,读完即走,无侵入、无副作用。
MapScope only analyzes and never modifies your project code — it is non-invasive and side-effect free.
只需提供 .map 文件即可,MapScope 会自动识别工具链并解析,无需额外配置。
Just point MapScope at a .map file — it auto-detects the toolchain and parses, with no extra configuration.
| 工具链 / Toolchain |
解析内容 / What is parsed |
| IAR EWARM / IAR ELF Linker |
完整布局(含 PLACEMENT 段)、符号、模块汇总 / Full layout (incl. PLACEMENT), symbols, module summary |
| GNU ld(GCC / arm-none-eabi / S32DS) |
Link map、运行区、符号 / Link map, execution regions, symbols |
| Greenhills (MULTI) Load Map |
Image 段、ROM()/ZI 模型、镜像段去重 / Image segments, ROM()/ZI model, mirror-dedup |
| Keil AC5 / AC6(含 EIDE 变体) |
Execution / Load Region |
| HighTec(英飞凌 AURIX) |
工具链专用 map / Toolchain-specific map |
| TASKING TriCore |
工具链专用 map / Toolchain-specific map |
主要功能 / Key Features
1. 多视图总览 / Multiple Overview Views
打开 map 后,顶部立即给出 ROM / RAM 占用率(进度条 + 百分比),并提供多个 Tab 重点不同地看同一份数据。
On opening a map, the top immediately shows ROM/RAM utilization (gauge + percent) and several tabs that view the same data from different angles:
- Overview(概览):地址空间带状图 + 物理分段明细表 + 各存储类型占用柱。/ Address-space strip + physical-segment table + per-memory-type bars.
- Treemap(矩形树图):整个固件按模块渲染成色块,面积 ∝ 占用,一眼找出大户。/ Whole firmware as colored blocks; area ∝ usage to spot the big eaters.
- Bar(柱状图):按模块/分组维度的 ROM/RAM 对比。/ ROM/RAM comparison by module/group.
- Pie(饼图):各类存储(Code / RO Data / RW Data / ZI)占比环。/ Share ring of each storage kind.
- Top N(排行榜):占用最大的若干模块/文件排行。/ Ranking of the largest modules / files.
- Table(明细表):逐条的 section / 模块明细列表。/ Itemized section / module list.
视图提供 Region / Module 两种切换,均可向下钻取到目标文件(.o)。
Views support switching between Region / Module, and drilling down to object files (.o).
2. 地址空间分布(Memory Map)/ Address-Space Layout
以横向带状图展示芯片的物理地址空间——ROM、RAM、空洞、未映射区按真实地址比例排布,悬停查看段内内容。
A horizontal strip shows the chip's physical address space — ROM, RAM, holes and unmapped areas laid out to scale; hover to inspect what lives at an address.
3. Physical Segments(物理分段明细表)/ Physical Segments Table
按芯片**物理存储块(Bank)**列出每段的起止地址、跨度和 占用率(Used / Fill)。识别芯片后:
Lists each of the chip's physical storage banks with its start/end, span and fill rate (Used / Fill). Once the chip is recognized:
- 每个 Bank 都会列出,即使 0% 占用也显示,让你看清"这块留着没动"。/ Every bank is shown, even at 0% usage, so free banks are visible.
- 多 Bank、双核 ITCM/DTCM 镜像等结构会逐一如实呈现。/ Multi-bank and dual-core ITCM/DTCM mirror layouts are rendered faithfully.
4. MCU 芯片库与自动识别 / MCU Library & Auto-Detect
内置常用 MCU 地址库(覆盖主流车规 / 工业 / 通用厂商),并能:
Ships with a library of common MCUs (automotive / industrial / general-purpose) and can:
- 自动识别:从内存地址自动猜出芯片,随后用"芯片物理容量"作 ROM/RAM 总量基准。/ Auto-detect the chip from addresses, then use its physical capacity as the ROM/RAM base.
- 手动选择:自动识别不准时下拉手动选;一键 清除 回到自动识别。/ Pick manually if detection is off; one-click clear to return to auto-detect.
5. 报告导出 / Report Export
一键导出为 HTML 报告(离线存档 / 分享)或 CSV(便于 Excel 二次统计)。
Export as an HTML report (for archiving / sharing) or CSV (for further Excel analysis) with one click.
6. 阈值告警 / Threshold Alerts
内置 ROM/RAM 警告阈值(默认 80% 警告、95% 报错)。分析视图打开期间,VSCode 状态栏(左下角) 会显示 ROM/RAM 占用百分比,并在超限时变为**黄色(警告)/ 红色(报错)**并加上 ⚠ ROM!/RAM! 标记,便于交付前快速确认 Flash / RAM 余量。
Built-in ROM/RAM thresholds (default warn 80%, error 95%). While the analysis view is open, the VSCode status bar (bottom-left) shows ROM/RAM percentages and turns yellow (warn) / red (error) with a ⚠ ROM!/RAM! tag when a limit is crossed — handy for a quick pre-release Flash/RAM budget check.
安装 / Installation
- 在 VSCode 打开 Extensions 视图(
Ctrl+Shift+X)。
Open the Extensions view in VSCode (Ctrl+Shift+X).
- 搜索 MapScope。
Search for MapScope.
- 点击 Install 安装。
Click Install to install.
- 完成后重启(或执行 Reload Window)。
Reload the window (or restart VSCode).
使用方法 / Usage
打开分析视图(两种方式/ Open the analysis view (either way)
- 右键 资源管理器中任意
.map 文件 → MapScope: 分析 MAP 文件(Analyze MAP File);
Right-click any .map file in the Explorer → MapScope: Analyze MAP File;
- 按下
Ctrl+Shift+P 打开命令面板,运行 MapScope: 分析当前文件(Analyze Current File)。
Press Ctrl+Shift+P to open the command palette, then run MapScope: Analyze Current File.
面板打开期间,左下角状态栏会同步显示 ROM/RAM 占用与阈值告警(见"阈值告警")。
While the panel is open, the bottom status bar shows ROM/RAM usage and threshold alerts (see "Threshold Alerts").
界面元素 / UI elements
- 顶部条形区 / Top bar:ROM / RAM 占用率进度条与百分比;ROM/RAM utilization gauges.
- Tab 栏 / Tabs:Overview / Treemap / Bar / Pie / Top N / Table。
- 芯片选择框 / Chip selector:当前 MCU 型号与数据来源(内置库 / 自定义 / 按地址聚类);current MCU and its source (library / custom / address clustering).
常见操作 / Common actions
| 我想…… / I want to… |
怎么做 / What to do |
| 换一种看法 / See it differently |
顶部点击不同 Tab / Click a tab |
| 某模块占多少 / See a module's usage |
Treemap 点色块,或 Bar 看柱高 / Click a block in Treemap, or read the Bar column |
| 深挖到单文件 / Drill into a file |
视图内向下钻取,返回回上层 / Drill down, then back up |
| 看精确地址 / Inspect an address |
Overview 的地址空间带状图悬停定位 / Hover the strip in Overview |
| 手动指定芯片 / Pick a chip |
顶部芯片选择框输入型号后选 / Type in the chip selector |
| 用自定义芯片 JSON / Use a custom chip JSON |
点 MCU JSON 按钮选择一个 .json 芯片文件(选后面板立即更新显示芯片信息;文件无效会提示错误)/ Click MCU JSON to pick a .json chip file (panel updates instantly; an invalid file shows an error) |
| 修改已选的 json / Edit a chosen json |
改完后用 MCU JSON 按钮重新选择该文件(在当前面板即时生效,无需重开面板);json 缺少 ROM/RAM 地址、或 map 用了 RAM 而 json 无 RAM 字段,都会弹提示 / Edit then re-pick it via the MCU JSON button (takes effect in the current panel immediately); missing addresses or a json with no RAM while the map uses RAM triggers a warning |
| 取消自定义 / Cancel custom JSON |
点芯片框旁清除,或在下拉里选内置型号 / Auto detect 即可放弃自定义文件并回退 / Click clear, or pick a built-in part / Auto detect to drop the custom file |
| 回到自动识别 / Re-auto-detect |
点芯片框旁清除 / Click clear beside the selector |
| 改告警阈值 / Adjust thresholds |
设置 mapscope.thresholds / Change mapscope.thresholds |
| 导出结果 / Export |
运行 导出 HTML 报告 / 导出 CSV 报告(Export HTML / CSV Report) |
界面支持中英文,自动跟随 VSCode 语言。
UI is Chinese/English, following the VSCode language.
设置项 / Settings
在 VSCode 设置(Ctrl+,)中搜索 mapscope。
Search mapscope in VSCode settings (Ctrl+,).
| 配置 / Setting |
说明 / Description |
mapscope.memoryConfig |
为特定 map 手动指定 ROM/RAM 总量(KB)覆盖推断 / Per-map ROM/RAM total (KB) to override inference |
mapscope.thresholds |
ROM/RAM 警告/错误阈值(默认 80 / 95)/ ROM/RAM warn/error thresholds (default 80 / 95) |
mapscope.mcuInfoPath |
自定义 MCU JSON 芯片文件(内置库之外补充自己的芯片,也兼容目录)/ Custom MCU JSON chip file to add your own chips (a directory is accepted too) |
mapscope.mcuPart |
按文件锁定使用的芯片型号 / Lock the chip used per file |
数据来源说明 / Data-source notes
- ROM/RAM 已用量:优先采用工具链链接器总账(权威口径),如 IAR 的
N bytes of readonly code/data memory。/ Used: prefer the linker grand total (authoritative), e.g. IAR's N bytes of readonly code/data memory.
- ROM/RAM 总量:优先取所选芯片物理容量(识别到芯片时),否则回退 map 内 Load Region / 内存区推断。/ Total: prefer the chip's physical capacity (when recognized), else fall back to Load Region / memory-region inference.
- Physical Segments 分段行与合计行:分段按芯片物理 Bank 累加段字节;合计用链接器总账,两者正常基本一致(差异仅少量元数据 / 对齐填充)。/ Segment vs total rows: segments sum bytes per physical bank; the total uses the linker grand total; they normally agree within a small amount (metadata / alignment).
若某芯片不在内置库又希望被自动识别,可用 mapscope.mcuInfoPath 添加自己的芯片信息。
If a chip is missing from the library, add your own via mapscope.mcuInfoPath.
通过 MCU JSON 按钮(或 mapscope.mcuInfoPath)选择的 .json 芯片文件,用 ROM/RAM 地址范围来描述一颗芯片。支持两种等价写法:
A .json chip file picked via the MCU JSON button (or mapscope.mcuInfoPath) describes a chip by its ROM/RAM address ranges. Two equivalent layouts are supported.
顶层列表(推荐)/ Top-level lists (recommended)
{
"Product": { "PartNumber": "R7F7015473AFP-C" },
"CodeFlash": [
{ "StartAddr": "0x00000000", "EndAddr": "0x001FFFFF" },
{ "StartAddr": "0x01000000", "EndAddr": "0x01007FFF" }
],
"RAM": [
{ "StartAddr": "0xFEBF0000", "EndAddr": "0xFEBFFFFF" },
{ "StartAddr": "0xFEBF8000", "EndAddr": "0xFEBFFFFF" }
],
"DataFlash": [
{ "StartAddr": "0xFF200000", "EndAddr": "0xFF20FFFF" }
]
}
CodeFlash / ProgramFlash → ROM(Flash);RAM → RAM(变量内存);DataFlash → 独立数据存储区(可选)。
CodeFlash/ProgramFlash → ROM (Flash); RAM → RAM (variable memory); DataFlash → a separate data-storage area (optional).
- 每键都是数组;ROM 或 RAM 有多个不连续段时,用逗号分隔多个
{StartAddr,EndAddr} 项(如上例 CodeFlash 两块、RAM 两块)。
Each key is an array; for multiple non-contiguous ROM/RAM ranges, add more {StartAddr,EndAddr} entries separated by commas (e.g. two CodeFlash and two RAM blocks above).
- 每项
{ "StartAddr": "…", "EndAddr": "…" },地址用十六进制,支持 0x 前缀或 FF20_0000 下划线分隔。所有值都是闭区间(EndAddr 涵盖最后一个字节)。
Each entry { "StartAddr": "…", "EndAddr": "…" } uses hex addresses, either 0x-prefixed or _-separated (FF20_0000). Both ends are inclusive.
Product 里只需 PartNumber(型号名,用于搜索与自动匹配);其它字段(如 Manufacturer、Series)会被忽略,省略。
Only Product.PartNumber (the part name, used for search & auto-match) is read; other fields such as Manufacturer/Series are ignored and may be omitted.
内存镜像 / Mirrored memory(可选)
同一物理存储若有主/别名两个窗口,用 primary + alias 描述;两者容量必须一致,别名窗口不计入总容量:
If the same physical memory has primary/alias windows, use primary + alias; both sizes must match and the alias is not counted twice:
"RAM": [
{ "primary": { "StartAddr": "0xFEBF0000", "EndAddr": "0xFEBFFFFF" },
"alias": { "StartAddr": "0xFEFF0000", "EndAddr": "0xFEFFFFFF" } }
]
Memory_Map 字典风格 / Memory_Map dict style(如 S32K)
也支持 Memory_Map 对象,键名按内容识别为 ROM/RAM(含 flash / sram / dtcm 等关键词),值同样是 {StartAddr,EndAddr}:
Also accepts a Memory_Map object whose keys are classified by name (flash / sram / dtcm etc.); values use the same {StartAddr,EndAddr} shape:
{
"Product": { "PartNumber": "S32K344" },
"Memory_Map": {
"Flash": { "StartAddr": "0x00400000", "EndAddr": "0x007FFFFF" },
"SRAM_L": { "StartAddr": "0x20000000", "EndAddr": "0x2002FFFF" },
"Segments": {
"Data_Flash": { "StartAddr": "0x10000000", "EndAddr": "0x1003FFFF" }
}
}
}
字段要求 / Field requirements
Product.PartNumber:型号名(可选),用于下拉搜索与自动匹配;缺失时用文件名代替。
Product.PartNumber: part name (optional), used for search & auto-match; falls back to the file name.
- 至少应提供一个有效 ROM 或 RAM 地址段;两者都缺会被拒绝并提示。
At least one valid ROM or RAM range is required; a file with neither is rejected with a warning.
- 若 map 使用了 RAM 而 JSON 完全没有 RAM 字段,会提示"缺少 RAM 字段"。
If the current map uses RAM but the JSON has no RAM at all, a "missing RAM field" warning is shown.
已知限制 / Known limitations
- 分析依赖
.map 文件详尽程度:若某工具链只输出摘要而无逐项段地址,部分视图(如 Treemap 精细展开)受限,但顶部 ROM/RAM 总览以链接器总账为准,仍然可靠。
Analysis depends on map detail: if a toolchain only emits a summary without per-section addresses, some views (e.g. fine Treemap expansion) are limited, but the top ROM/RAM overview uses the linker total and stays reliable.
- 个别型号的 RAM 地址在源数据中可能缺失(源数据本身限制,非解析缺陷),此时按地址聚类回退。
Some parts may lack RAM addresses in the source data (a source-data limit, not a parser bug); address clustering is used as fallback.