Load ELF data directly using probe_rs#690
Conversation
|
I flashed both the SP and RoT on Grapefruit, and everything looks fine. |
| humility-cli = { workspace = true } | ||
| clap = { workspace = true } | ||
| anyhow = { workspace = true } | ||
| parse_int = { workspace = true } |
There was a problem hiding this comment.
These were unused dependencies that I happened to notice while pruning.
There was a problem hiding this comment.
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::loadto accept in-memory ELF bytes and program flash viaprobe-rs’s ELF loader/flash loader APIs. - Remove IHEX/SREC/tempfile-related conversion code and associated dependencies from the
flashandrebootlebycommands. - 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.
| /// Loading is not allowed when `can_flash = false` | ||
| #[error("ProbeCore was constructed with can_flash = false")] | ||
| NotAllowed, |
| 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(); |
There was a problem hiding this comment.
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).
b2d785b to
dd14be6
Compare
869db6f to
fe3045b
Compare
dd14be6 to
e4e0918
Compare
fe3045b to
f65a517
Compare
e4e0918 to
5d2a983
Compare
labbott
left a comment
There was a problem hiding this comment.
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.
| 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)?; |
There was a problem hiding this comment.
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
f65a517 to
c95ebee
Compare
|
@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 |
(staged on #689)
Now that we are using
probe-rsfor everything, we don't need to convert to IHEX / SREC. This lets us remove a bunch of dependencies. I also switchedProbeCore::loadto return a strong error type, while I was poking at it.This is a building block for a
humility flashlibrary.Bidding a fond farewell to the best docstring in the codebase, describing
elf_chunks: