Add Python script to generate flash_map C code from devicetree#4
Closed
Add Python script to generate flash_map C code from devicetree#4
Conversation
Co-authored-by: de-nordic <56024351+de-nordic@users.noreply.github.com>
Co-authored-by: de-nordic <56024351+de-nordic@users.noreply.github.com>
Co-authored-by: de-nordic <56024351+de-nordic@users.noreply.github.com>
Co-authored-by: de-nordic <56024351+de-nordic@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add Python script to generate C code for Flash Map subsystem
Add Python script to generate flash_map C code from devicetree
Feb 6, 2026
de-nordic
pushed a commit
that referenced
this pull request
Mar 20, 2026
1. Mostly complete. Supports MPU, userspace, PSPLIM-based stack guards, and FPU/DSP features. ARMv8-M secure mode "should" work but I don't know how to test it. 2. Designed with an eye to uncompromising/best-in-industry cooperative context switch performance. No PendSV exception nor hardware stacking/unstacking, just a traditional "musical chairs" switch. Context gets saved on process stacks only instead of split between there and the thread struct. No branches in the core integer switch code (and just one in the FPU bits that can't be avoided). 3. Minimal assembly use; arch_switch() itself is ALWAYS_INLINE, there is an assembly stub for exception exit, and that's it beyond one/two instruction inlines elsewhere. 4. Selectable at build time, interoperable with existing code. Just use the pre-existing CONFIG_USE_SWITCH=y flag to enable it. Or turn it off to evade regressions as this stabilizes. 5. Exception/interrupt returns in the common case need only a single C function to be called at the tail, and then return naturally. Effectively "all interrupts are direct now". This isn't a benefit currently because the existing stubs haven't been removed (see #4), but in the long term we can look at exploiting this. The boilerplate previously required is now (mostly) empty. 6. No support for ARMv6 (Cortex M0 et. al.) thumb code. The expanded instruction encodings in ARMv7 are a big (big) win, so the older cores really need a separate port to avoid impacting newer hardware. Thankfully there isn't that much code to port (see #3), so this should be doable. Signed-off-by: Andy Ross <andyross@google.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Flash Map subsystem currently generates partition map and flash_area objects using complex nested DT foreach macros. This PR replaces macro-based generation with a Python script that generates explicit C code at compile time.
Changes
New script:
scripts/dts/gen_flash_map.pydefault_flash_map[]array and individual partition objects (global_fixed_partition_ORD_<N>){ .fa_id = DT_FIXED_PARTITION_ID(DT_N_...), .fa_off = FIXED_PARTITION_NODE_OFFSET(DT_N_...), .fa_size = DT_REG_SIZE(DT_N_...), .fa_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_N_...)), }--labelsflagBuild integration:
subsys/storage/flash_map/CMakeLists.txtflash_map_generated.cflash_map_default.cwith generated file (unless CONFIG_FLASH_MAP_CUSTOM)Compatibility
All FIXED_PARTITION_* macros in flash_map.h continue to work unchanged. Generated structures are identical to the macro-based version:
Benefits
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.