Skip to content

Conversation

@dragonmux
Copy link
Member

In this PR we address the dual issues of the ELF container the firmware is read from being thrown away too quickly, and the guessed load address being wrong on parts that have the firmware start at someplace other than 0x08002000.

To address this we introduce a new FirmwareFile type and FirmwareStorage trait that allows bmputil to transparently hold firmware backed by an arbitrary file type and which knows how to determine, when available, the load address a file is intended for. This is then promulgated through to BmpDevice::download() to allow it to more smartly determine load address.

The introduced ELFFirmwareFile type that implemented the FirmwareStorage trait holds onto significantly more information about the ELF that was read in w/o discarding it, thus allowing the actual load address of the firmware to propagate properly. This type also implements proper loading of segments in a manner more conducive to correctly loading the firmware into Flash on the target even in the face of arbitrary section names appearing. It fills gaps between segments with the erased byte to create a contiguous firmware image.

There are still a bunch of assumptions being made that need addressing, however this unblocks us enough on hardware bringup and allows bmputil to be successfully used with other platforms such as Blackpill which also use a different firmware load address.

NB: This change may break ABI, however it does so on functionality that should never have been exposed to the world. Hopefully the new visibilities for the new functionality is set correctly in relation to that.

@dragonmux dragonmux added this to the v1.1 release milestone Dec 17, 2025
@dragonmux dragonmux requested a review from esden December 17, 2025 09:14
@dragonmux dragonmux added bug Something isn't working enhancement New feature or request labels Dec 17, 2025
@semanticdiff-com
Copy link

semanticdiff-com bot commented Dec 17, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  src/flasher.rs  10% smaller
  src/bmp.rs  3% smaller
  src/elf.rs  0% smaller
  src/firmware_file/elf.rs  0% smaller
  src/firmware_file/ihex.rs  0% smaller
  src/firmware_file/mod.rs  0% smaller
  src/firmware_file/raw.rs  0% smaller
  src/firmware_type.rs  0% smaller
  src/lib.rs  0% smaller

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 0% with 201 lines in your changes missing coverage. Please review.
✅ Project coverage is 6.11%. Comparing base (2f500df) to head (a952aba).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
src/firmware_file/elf.rs 0.00% 66 Missing ⚠️
src/firmware_type.rs 0.00% 61 Missing ⚠️
src/firmware_file/mod.rs 0.00% 25 Missing ⚠️
src/firmware_file/raw.rs 0.00% 18 Missing ⚠️
src/firmware_file/ihex.rs 0.00% 12 Missing ⚠️
src/flasher.rs 0.00% 12 Missing ⚠️
src/bmp.rs 0.00% 7 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main     #69      +/-   ##
========================================
- Coverage   6.21%   6.11%   -0.10%     
========================================
  Files         25      29       +4     
  Lines       3187    3237      +50     
  Branches    3187    3237      +50     
========================================
  Hits         198     198              
- Misses      2969    3019      +50     
  Partials      20      20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@esden esden left a comment

Choose a reason for hiding this comment

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

Great progress on this. Nice to have this abstracted nicely. Only a few comments on what could potentially be an improved? Curious what you think.

@dragonmux dragonmux force-pushed the fix/firwmare-start-address-assumptions branch from a4cf39f to a952aba Compare December 17, 2025 22:58
@esden esden self-requested a review December 17, 2025 23:43
Copy link
Member

@esden esden left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the hard work. Let's keep moving! :D

@esden esden merged commit a952aba into main Dec 17, 2025
8 of 11 checks passed
@dragonmux dragonmux deleted the fix/firwmare-start-address-assumptions branch December 18, 2025 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants