rust-embedded / rust-embedded/cortex-m

Convenience function to get all read-only linker sections located in Flash

Open
#412 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1k
Forks
202
Avg merge
6d 2h
Merged PRs (30d)
2

Description

If you would like to perform a checksum validation of all Flash memory you would need to know where all used Flash memory starts and ends.
Today, this can (partially) be done using the _stext, __etext, etc. symbols + slice::from_raw_parts but these symbols are not part of the public, stable ABI (iirc) and this approach requires writing unsafe code.

We could add a function that returns an iterator (or slice) over the read-only linker sections .

// the elements of the returned slices are the sectinos `.vector_table`, `.text`, `.rodata`, etc.
pub fn read_only_flash_sections() -> &[&u8] { /* .. */ }

I think this should be sound because these sections are read only so it should be OK to return a shared reference to the entire linker section.
On the other hand, a section dedicated to writeable Flash should not be returned from this function.

The slice should also contain the chunk of memory that corresponds to the initial values of mutable static variables (corresponds to LOADADDR(.data) in the linker script), see below.

static X: AtomicU32 = AtomicU32::new(42);
//                                   ^^ this value is stored in Flash but it's not in .rodata

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the linker script sections and the existing _stext, __etext, and LOADADDR(.data) symbols mentioned in the issue. Determine the public API and soundness requirements before implementing anything; done means a stable read-only Flash view includes the initial mutable-static values while excluding writable Flash sections.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.