Skip to content

Commit

Permalink
Merge #683
Browse files Browse the repository at this point in the history
683: Make sure the whole RTT structure is in RAM r=jonas-schievink a=jannic

Currently, the name field of the RTT channel will be placed in
flash (rodata). That causes the debug probe to read from flash while
parsing the RTT header.

Usually this doesn't matter, but if the firmware disables flash access
before the debug probe scanned the header, it will break.

The situation where I stumbled over this was writing a firmware which
writes to flash on an RP2040. While writing to the (external) flash
chip, no concurrent flash accesses must happen.

This patch forces the name to the `.data` section, so the whole RTT
header can be read from RAM.

Co-authored-by: Jan Niehusmann <jan@gondor.com>
Co-authored-by: Johann Hemmann <johann.hemmann@code.berlin>
  • Loading branch information
3 people authored Jul 14, 2022
2 parents 37a699c + b92510c commit 00b1813
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- [#686]: `CI`: Temporarily disable `qemu-snapshot (nightly)`
- [#684]: Fix `syn` dependency version in `defmt-macros`.
- [#683]: defmt-rtt: Make sure the whole RTT structure is in RAM
- [#682]: defmt-print: exit when stdin is closed
- [#681]: Make use of i/o locking being static since rust `1.61`.
- [#679]: Add changelog enforcer
- [#678]: Satisfy clippy

[#686]: https://github.com/knurling-rs/defmt/pull/686
[#684]: https://github.com/knurling-rs/defmt/pull/684
[#683]: https://github.com/knurling-rs/defmt/pull/683
[#682]: https://github.com/knurling-rs/defmt/pull/682
[#681]: https://github.com/knurling-rs/defmt/pull/681
[#679]: https://github.com/knurling-rs/defmt/pull/679
Expand Down
7 changes: 5 additions & 2 deletions firmware/defmt-rtt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ unsafe fn handle() -> &'static Channel {
max_up_channels: 1,
max_down_channels: 0,
up_channel: Channel {
name: NAME as *const _ as *const u8,
name: &NAME as *const _ as *const u8,
buffer: unsafe { &mut BUFFER as *mut _ as *mut u8 },
size: BUF_SIZE,
write: AtomicUsize::new(0),
Expand All @@ -124,7 +124,10 @@ unsafe fn handle() -> &'static Channel {
#[cfg_attr(not(target_os = "macos"), link_section = ".uninit.defmt-rtt.BUFFER")]
static mut BUFFER: [u8; BUF_SIZE] = [0; BUF_SIZE];

static NAME: &[u8] = b"defmt\0";
// Place NAME in data section, so the whole RTT header can be read from RAM.
// This is useful if flash access gets disabled by the firmware at runtime.
#[link_section = ".data"]
static NAME: [u8; 6] = *b"defmt\0";

&_SEGGER_RTT.up_channel
}

0 comments on commit 00b1813

Please sign in to comment.