Skip to content
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

Lack of uninit section causes linking defmt to fail #175

Closed
9names opened this issue Aug 30, 2022 · 4 comments · Fixed by #179
Closed

Lack of uninit section causes linking defmt to fail #175

9names opened this issue Aug 30, 2022 · 4 comments · Fixed by #179

Comments

@9names
Copy link
Contributor

9names commented Aug 30, 2022

defmt puts it's uninitialised data in the uninit section, found here in the cortex-m-rt linker script:
https://github.com/rust-embedded/cortex-m/blob/0e530549de322684c50e858c6bb985afb5479dbe/cortex-m-rt/link.x.in#L170

this is absent from the linker scripts here, so we get this linker error:

note: rust-lld: warning: address (0x42000008) of section .text is not a multiple of alignment (256)
          rust-lld: error: section .uninit.defmt-rtt.BUFFER load address range overlaps with .rwtext
          >>> .uninit.defmt-rtt.BUFFER range is [0x2D4E4, 0x2D8E3]
          >>> .rwtext range is [0x2D4EC, 0x2DDFB]

This issue has already been reported with defmt.
knurling-rs/defmt#693

I've tested adding this uninit section to the esp32c3 db-riscv-link.x after BSS, and it seems to work!

  /* ### .uninit */
  .uninit (NOLOAD) : ALIGN(4)
  {
    . = ALIGN(4);
    __suninit = .;
    *(.uninit .uninit.*);
    . = ALIGN(4);
    __euninit = .;
  } > REGION_BSS

Also seems to trigger some issues flashing on cargo embed, but I think those are likely to be probe-rs bugs.
probe-rs-cli does not trigger this, maybe my cargo-embed is not up to date. Recording it here just in case:

Error failed to flash blinky
Caused by:
                 0: Error while flashing
                 1: No flash memory contains the entire requested memory range 0x00000000..       0x8.

I'll make a PR for this in a few days if no-one else picks this up

@TheButlah
Copy link
Contributor

Anything else that needs to be done in this PR?

@9names
Copy link
Contributor Author

9names commented Sep 4, 2022

No, that should be all that is necessary.
I only tested it on the direct-boot linker script, you should probably test against the regular linker script too.
I assume if it works for esp32c3 it should be safe to put in all the other chip variants as well.

@TheButlah
Copy link
Contributor

TheButlah commented Sep 4, 2022

I did not have any issues flashing with cargo embed. However, my rtt console looks like this:
Screen Shot 2022-09-04 at 1 36 38 PM

Code is here

I tried to use your linker script patch like this:
db-riscv-link.x:

/* ... */

  .bss (NOLOAD) :
  {
    _sbss = .;
    *(.sbss .sbss.* .bss .bss.*);
    . = ALIGN(4);
    _ebss = .;
  } > REGION_BSS

   /* ### .uninit */
  .uninit (NOLOAD) : ALIGN(4)
  {
    . = ALIGN(4);
    __suninit = .;
    *(.uninit .uninit.*);
    . = ALIGN(4);
    __euninit = .;
  } > REGION_BSS

  /* fictitious region that represents the memory available for the heap */
  .heap (NOLOAD) :
  {
    _sheap = .;
    . += _heap_size;
    . = ALIGN(4);
    _eheap = .;
  } > REGION_HEAP

/* ... */

Hardware is an esp32c3, connected directly over onboard serial peripheral.

@TheButlah
Copy link
Contributor

TheButlah commented Sep 4, 2022

My apologies, this was user error. I forgot that defmt sends compressed data, so merely printing it without decoding it will look like spaghetti. I needed to configure my Embed.toml to tell cargo embed to decode it as defmt.

I have successfully tested the direct-boot approach, will test the regular boot one soon.

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 a pull request may close this issue.

2 participants