Skip to content

Load ELF data directly using probe_rs#690

Open
mkeeter wants to merge 1 commit into
masterfrom
mkeeter/probe-that-elf
Open

Load ELF data directly using probe_rs#690
mkeeter wants to merge 1 commit into
masterfrom
mkeeter/probe-that-elf

Conversation

@mkeeter
Copy link
Copy Markdown
Contributor

@mkeeter mkeeter commented Jun 3, 2026

(staged on #689)

Now that we are using probe-rs for everything, we don't need to convert to IHEX / SREC. This lets us remove a bunch of dependencies. I also switched ProbeCore::load to return a strong error type, while I was poking at it.

This is a building block for a humility flash library.

Bidding a fond farewell to the best docstring in the codebase, describing elf_chunks:

While it may sound like the impetus for an OSHA investigation at the North Pole...

@mkeeter mkeeter requested review from hawkw, jamesmunns and labbott June 3, 2026 14:25
@mkeeter
Copy link
Copy Markdown
Contributor Author

mkeeter commented Jun 3, 2026

I flashed both the SP and RoT on Grapefruit, and everything looks fine.

Comment thread cmd/rebootleby/Cargo.toml
humility-cli = { workspace = true }
clap = { workspace = true }
anyhow = { workspace = true }
parse_int = { workspace = true }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were unused dependencies that I happened to notice while pruning.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the flashing workflow to load ELF data directly via probe-rs instead of converting ELF to IHEX/SREC first, reducing dependencies and simplifying the flash pipeline. It also introduces a dedicated LoadError type for ProbeCore::load.

Changes:

  • Switch ProbeCore::load to accept in-memory ELF bytes and program flash via probe-rs’s ELF loader/flash loader APIs.
  • Remove IHEX/SREC/tempfile-related conversion code and associated dependencies from the flash and rebootleby commands.
  • Prune workspace dependencies (ihex, srec, tempfile, path-slash, etc.) and update lockfile accordingly.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
humility-probes-core/src/probe_rs.rs Introduces LoadError and changes ProbeCore::load to program ELF bytes directly via probe-rs.
cmd/flash/src/lib.rs Updates flash command to pass ELF bytes directly to core.load.
cmd/flash/Cargo.toml Removes now-unneeded dependencies related to ELF→IHEX/SREC conversion.
cmd/rebootleby/Cargo.toml Removes dependencies no longer used by the command.
Cargo.toml Removes workspace-level dependencies that are no longer required.
Cargo.lock Reflects dependency graph changes after removing IHEX/SREC/tempfile/etc.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +246 to +248
/// Loading is not allowed when `can_flash = false`
#[error("ProbeCore was constructed with can_flash = false")]
NotAllowed,
Comment on lines 287 to +292
let erase_style = ProgressStyle::default_bar()
.template("humility: erasing [{bar:30}] {bytes}/{total_bytes}")?;
.template("humility: erasing [{bar:30}] {bytes}/{total_bytes}")
.unwrap();
let flash_style = ProgressStyle::default_bar()
.template("humility: flashing [{bar:30}] {bytes}/{total_bytes}")?;
.template("humility: flashing [{bar:30}] {bytes}/{total_bytes}")
.unwrap();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deliberate; the progress bar can only fail if it's given an invalid template string, and we won't do that (or will catch it quickly, because it's a loud failure mode).

@mkeeter mkeeter force-pushed the mkeeter/only-load-with-a-probe branch from b2d785b to dd14be6 Compare June 3, 2026 20:31
@mkeeter mkeeter force-pushed the mkeeter/probe-that-elf branch 2 times, most recently from 869db6f to fe3045b Compare June 3, 2026 20:35
@mkeeter mkeeter force-pushed the mkeeter/only-load-with-a-probe branch from dd14be6 to e4e0918 Compare June 3, 2026 20:35
@mkeeter mkeeter force-pushed the mkeeter/probe-that-elf branch from fe3045b to f65a517 Compare June 4, 2026 15:25
@mkeeter mkeeter force-pushed the mkeeter/only-load-with-a-probe branch from e4e0918 to 5d2a983 Compare June 4, 2026 15:25
Copy link
Copy Markdown
Contributor

@labbott labbott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me a little nervous but I think we're probably okay because our elf is very simple

$ arm-none-eabi-readelf --segments img/final.elf

Elf file type is REL (Relocatable file)
Entry point 0x10181
There is 1 program header, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000054 0x00010000 0x00010000 0x339e8 0x339e8 R   0x20

 Section to Segment mapping:
  Segment Sections...
   00     .sec1 
$ arm-none-eabi-readelf --segments img/final.elf
 
Elf file type is REL (Relocatable file)
Entry point 0x80002e9
There is 1 program header, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000054 0x08000000 0x08000000 0x88100 0x88100 R   0x20

 Section to Segment mapping:
  Segment Sections...
   00     .sec1 

I guess my biggest concern would be if there's any rounding changes. We may also want to take a closer look at the updated DownloadOptions in new probe-rs https://docs.rs/probe-rs/latest/probe_rs/flashing/struct.DownloadOptions.html to make sure we're getting the behavior we want.

Comment on lines +339 to +341
let mut loader = self.session.target().flash_loader();
loader.load_elf_data(&mut std::io::Cursor::new(elf_data))?;
loader.commit(&mut self.session, options)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to change ever so slightly when we do the probe-rs upgrade https://docs.rs/probe-rs/latest/probe_rs/flashing/struct.FlashLoader.html#method.load_image I think it should still match up okay and we can just use the default ElfOptions https://docs.rs/probe-rs/latest/probe_rs/flashing/struct.ElfOptions.html

@mkeeter mkeeter force-pushed the mkeeter/probe-that-elf branch from f65a517 to c95ebee Compare June 4, 2026 20:27
Base automatically changed from mkeeter/only-load-with-a-probe to master June 4, 2026 20:56
@mkeeter
Copy link
Copy Markdown
Contributor Author

mkeeter commented Jun 5, 2026

@labbott Can you say more about what rounding changes would look like, e.g. are you worried about a different erase / write granularity?

@labbott
Copy link
Copy Markdown
Contributor

labbott commented Jun 5, 2026

@labbott Can you say more about what rounding changes would look like, e.g. are you worried about a different erase / write granularity?

Currently, we're explicitly breaking up the ELF into 32 byte chunks and using that to generate the ihex. I'm concerned if there could be different behavior for the last unaligned block. e.g we had an image of 512+1 bytes in length, that gets converted to (512/32) + 1 chunks in ihex. Block write size is 512. I would expect that that last byte would get handled the same way for both images and that last block should look the same in all cases but I'd want to be sure.

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.

3 participants