Skip to content

cortex-m-rt: Allow custom memory region names #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

kpfleming
Copy link

Adds support for environment variables which allow the user to use their own memory region names in memory.x, instead of FLASH and/or RAM.

Adds support for environment variables which allow the user to use
their own memory region names in memory.x, instead of FLASH and/or
RAM.
@kpfleming
Copy link
Author

I don't understand why far had to be added to both dev-dependencies and build-dependencies in Cargo.toml, but I couldn't get a successful build without it.

@jonathanpallant
Copy link
Contributor

Two thoughts:

  1. What does far do that replace does not?
  2. What's the motivation for wanting to be able to have different region names in the linker script, and can people just use region aliases to achieve the same outcome?

@kpfleming
Copy link
Author

kpfleming commented Jun 11, 2025

Good questions, thanks.

  1. Using a templating system just provides a bit more structure, although in this case it's unlikely that the number of replacable strings in the linker script is going to grow beyond two, so using replace will probably be sufficient.

  2. I wasn't previously aware of region aliases, so I did a bit of reading. It can be used to solve the problem I'm trying to solve here, but with a bit more complexity, so I'll explain with an example:

My project has two binary crates, a bootloader and an application. They will both be stored in flash memory, in separate regions. The region addresses must be fixed, so the bootloader knows how to find/start the application (this is all basic stuff, apologies if that annoys you, I just want to have the details clear).

At the moment, each crate must have its own memory.x file with the FLASH region defined to start at the proper address and of the proper size. This creates a maintenance risk, as a developer may change one of them without changing the other one, and the results will not spark joy.

Instead I'd prefer to have a memory.x file with no FLASH region at all, but with a BOOT region and an APP region, set to the proper addresses and with the proper sizes. Both crates would this file, and each would use the environment variable to tell the linker which region their .text section should land in.

Using aliases would require three linker script files: the memory.x file that is common between the crates, plus two crate-specific files which aliased FLASH to either BOOT or APP (and which used INCLUDE to bring in the common file). This would not be terrible, certainly. It's just slightly more difficult to setup and document, so I'd prefer to avoid the three-file solution, but I'd be satisfied with that solution for my own project if the team decides that editing the main linker script during the build isn't worth the trouble :-)

@kpfleming
Copy link
Author

Closing this PR, as region aliases are an easy solution. I'll contribute an example to the embassy-boot docs :-)

@kpfleming kpfleming closed this Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants