Skip to content

Make flash --ram usable with the monitor and the stub - #1149

Open
SergioGasquez wants to merge 2 commits into
esp-rs:mainfrom
SergioGasquez:fix/flash-ram
Open

SergioGasquez wants to merge 2 commits into
esp-rs:mainfrom
SergioGasquez:fix/flash-ram

Conversation

@SergioGasquez

Copy link
Copy Markdown
Member

Description

Fixes #1134.

Three changes to flash --ram (espflash and cargo-espflash):

  1. --monitor no longer resets the RAM application away. The monitor's reset booted the application in flash instead. After loading to RAM, the monitor now starts without a reset, like esptool's load-ram, which doesn't reset afterwards either. MonitorConfigArgs::no_reset is now public so that both binaries can set it.
  2. Segments that overlap the running flash stub are rejected before anything is written. With the stub, such a segment overwrote it, and espflash failed with Timeout while running MemEnd command. Flasher::load_elf_to_ram now checks every RAM segment against the stub's BSS and data (bss_start..data_start + data.len()) and its text, the same ranges esptool checks in mem_begin. It fails with the new Error::RamSegmentOverlapsStub:
    Error: espflash::ram_segment_overlaps_stub
    
      × The flash stub is resident at 0x40800000..0x408018f0, so the image can't
      │ be loaded at the overlapping address range 0x40800000..0x40800046
      help: Link the image at addresses the stub does not use, or use the `--no-
            stub` option to load it with the ROM loader
    
    FlashStub now reads bss_start from the stub TOML files, and the stub selection (by chip and ESP32-P4 revision) moved from load_stub to Flasher::stub so that the check uses the same stub.
  3. The ESP-IDF app descriptor is no longer required with --ram. A RAM image doesn't go through the second-stage bootloader, so --ignore-app-descriptor isn't needed anymore.

As in esptool, the overlap check compares addresses only. On chips where IRAM and DRAM alias the same memory at different addresses (ESP32, ESP32-S2, ESP32-S3), a segment linked at the other alias of the stub's memory isn't detected.

The app descriptor check still runs after connecting; moving it before connect is #1133.

An AI tool generated a significant part of this change. It is tested on the HIL rig, see Testing.

Testing

ESP32-C6 (revision v0.2) on the HIL rig, with two minimal bare-metal programs that print RAMOK to UART0 and USB-Serial-JTAG in a loop: one linked at 0x40820000, clear of the stub (text 0x40800000..0x408018f0, BSS and data 0x40840000..0x40852e54), and one at 0x40800000, overlapping the stub's text.

Command main This PR
flash --ram <clear> App descriptor error Loads and runs
flash --ram --ignore-app-descriptor -M --non-interactive <clear>, USB-Serial-JTAG 4 RAMOK lines, then rst:0x15 (USB_UART_HPSYS) 391 RAMOK lines in 20 s, no reset
Same over UART 478 RAMOK lines in 25 s, no reset
flash --ram --ignore-app-descriptor <overlap> Timeout while running MemEnd command espflash::ram_segment_overlaps_stub before writing
flash --ram --no-stub -M --non-interactive <overlap> Loads and runs, 392 RAMOK lines
  • check_stub_encodings now also checks that every stub's BSS precedes its data, so that one range covers both.
  • cargo +nightly fmt --check, cargo clippy --all-targets -- -D warnings, cargo clippy -p espflash --no-default-features [--features cli|serialport] -- -D warnings and cargo test -p espflash --lib.
  • Not tested: cargo espflash flash --ram on hardware (the same change as in espflash), Xtensa chips, the interactive monitor (which doesn't reset before monitoring anyway), and the ESP32-P4 stub selection, which moved but is unchanged.

Suggested HIL: /hil quick. The HIL tests don't cover --ram, but the stub loading code they exercise moved.

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.

flash --ram: the monitor resets the RAM application, no check for overlap with the flash stub, app descriptor required

1 participant