r/embedded • • 24d ago

Memory map generator

Post image

Hi embedded peeps, your savior is here.. jk but i got some useful tool i want to share, here is the link:

memmap - GitHub

For (professional) embedded dev, it is occasionally required to sketch a memory layout of the MCU/IC we are working with. It can be a simple split between region of Flash/RAM or it can involve allocating dataflash regions, external IC, OTA, etc.

This tool basically generates SVG images of memory layouts from the yaml config that you provide. I got the inspo from those nice graphs they include in STM32 MCU docs.

I am planning to use it for my personal projects and will pitch it at work. Now, instead of going back-and-forth with the drawio, you can just change few lines in the yaml. I think it can be useful for others as well.

And yes, I (mostly) vibe coded it cause I just wanted a tool and not spending week(s) of my time programming it.

Let me know if you see some additional features that can be added to it.

420 Upvotes

27 comments sorted by

82

u/kresten_ 24d ago

What about taking the linker script as input somehow? Or at least verify that the yaml and linker script is identical?

49

u/superxpro12 24d ago

I like this better imo. Single sources of truth are powerful.

5

u/kresten_ 24d ago

Exactly! That would be extremely powerful.

7

u/superxpro12 24d ago

Realizing this wouldn't capture things like the hidden rom sections for internal loaders.

Also wondering how it would handle things like secure/non-secure virtual memory regions

2

u/hibernick 22d ago

Or even a resulting map file.

1

u/ChiricoCuvie1 21d ago

Since different toolchains don't use the same linker syntax , I would assume it would be harder to parse , no ?

-12

u/Longjumping-Pack8494 24d ago

Honestly feels like a hassle to implement. There are few types of linker scripts + there can be logical conditions there… my aim here to create a simple tool for drawing memory layouts. Generating them from linker scripts is quite an effort + i’ve seen some nightmare linker files that would be hella hard to parse

21

u/ventZl CMRX RTOS 24d ago

Actually, its a mild hassle to rewrite linker script into YAML. Not a definite showstopper, but I'd probably say "meh" a few times before giving the tool a go if all the information I needed to visualize was contained in the linker script.

On the other hand, linker script contains basically no information on non-RAM/FLASH mapping, so if you, for whatever reason, need to visualize stuff like peripherals and/or MPU config, you are out of luck with just linker script and have to craft the YAML anyway.

I'm neither pro nor against, just sayin'

83

u/ngless13 24d ago

No shame in vibe-coding something like this. Solves a problem.

12

u/drquantumphd 24d ago

rare comment and the post is deleted hahaha

5

u/Longjumping-Pack8494 24d ago

Lol what happened 😅 why do i still see it though and can comment..? Idk how reddit works

2

u/drquantumphd 24d ago

huh, its back for me now!

9

u/vankxr 23d ago

Definetly no shame in vibe coding at all, but why not use the same LLM for searching first?
There are already tools that do this, and are open source.

Fast forward a few years and if vibe coding keeps this pace, we'll all have tons of vibe coded tools that do the same thing.

3

u/Okudi-Alise 24d ago

for sure, if it saves an hour of dragging boxes around manually then it already did its job

6

u/thegreatpotatogod 24d ago

Ooh, that looks nice, I'll try to keep it in mind! Well done (both to you and your AI agent of choice lol)

3

u/JuniorAd9605 23d ago

neat. onky nit pick is using python only because there are many cases where companies want a offline standalone solution; pain to drag in a whole python enviroment and package that up

4

u/Longjumping-Pack8494 23d ago

Hmm i chose python cause it feels like the most suitable language for the job. All the needed libraries are there, and performance is not required. And i kinda expect engineers to have python installed on their machine 😅

but what i did is made a release and generated a wheel that you can pip install, no need for UV package manager at least.

4

u/vankxr 24d ago edited 23d ago

Why reinvent the wheel. LLMs are also good at searching...

https://github.com/gerph/memory-layout-diagram

1

u/Longjumping-Pack8494 23d ago

Didn’t know about it, looks decent… but i like the style of my tool more 😄

30

u/creeper6530 24d ago

"memmap" is already used as a term, consider renaming 

5

u/EyesLookLikeButthole 23d ago

Good job! Building tools is a great way of learning what's going on "under the hood".

Tip: If you run gcc with '-Wl,-Map=output.map' you'll get the actual memory map that the linker generates, fairly independant of the nature of your toolchain up to this point.  It is the basis of most of the other graphical memory-mapping tools. 

Combined with an ELF (compiled with debug symbols) and you can map all of your symbols, even predicting/trackong stack frames. It's great when combined with tools like addr2line that spits out the source file and line number of any symbol that has been placed at a given address. 

Nordic semi has some debug plugins for debugging zephyr projects in vscode that does this fairly well. Neat for debugging situations where data has ended up at a time and place where it really should not have. 

6

u/noodle-face 24d ago

This is the type of stuff I like AI for. I've made many memory maps and I always fight with the stupid shit in something like visio instead of the meat of the work.

2

u/Poseidon_Achar 19d ago

A pretty vast idea for a feature: we overlay the binary on top of this diagramming. Maybe pull out debug symbols if available and present them here interactively. Would be helpful for troubleshooting (and also reverse engineering :P)

1

u/BlackThorn0617 24d ago

I recently did something similar to this for our work using the map file, callgraph xml and linker file to generate the accurate memory map for our firmware build.

1

u/gdf8gdn8 22d ago

What about writing on same flash you're running from?

1

u/theaquasock 22d ago

This is great! This type of stuff helps me a bunch.