Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

Commit a4cf39f

Browse files
committed
bmp: Made BmpDevice::download() take a FirmwareFile and fixed the load address problem
1 parent d368ce9 commit a4cf39f

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/bmp.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use nusb::{Device, DeviceInfo, Interface};
1919

2020
pub use crate::bmp_matcher::BmpMatcher;
2121
use crate::error::ErrorKind;
22+
use crate::firmware_file::FirmwareFile;
2223
// XXX: Ideally this shouldn't be pub here, but that's a breaking change.
2324
pub use crate::firmware_type::FirmwareType;
2425
use crate::probe_identity::ProbeIdentity;
@@ -496,9 +497,9 @@ impl BmpDevice
496497
///
497498
/// `progress` is a callback of the form `fn(just_written: usize)`, for callers to keep track of
498499
/// the flashing process.
499-
pub fn download<'r, P>(
500+
pub fn download<P>(
500501
&mut self,
501-
firmware: &'r [u8],
502+
firmware_file: &FirmwareFile,
502503
firmware_type: FirmwareType,
503504
progress: P,
504505
) -> Result<DfuSync>
@@ -509,8 +510,11 @@ impl BmpDevice
509510
self.detach_and_enumerate().wrap_err("detaching device for download")?;
510511
}
511512

512-
let length = firmware.len() as u32;
513-
let load_address = self.platform.load_address(firmware_type);
513+
// Extract the file's load address, and if that isn't a thing, fall back on
514+
// more crude methods based on the platform we're downloading to
515+
let load_address = firmware_file
516+
.load_address()
517+
.unwrap_or_else(|| self.platform.load_address(firmware_type));
514518

515519
let dfu_dev = DfuNusb::open(
516520
self.device.take().expect("Must have a valid device handle"),
@@ -531,7 +535,7 @@ impl BmpDevice
531535

532536
debug!("Load address: 0x{:08x}", load_address);
533537

534-
match self.try_download(firmware, length, &mut dfu_iface) {
538+
match self.try_download(firmware_file.data(), firmware_file.len(), &mut dfu_iface) {
535539
Err(error) => {
536540
if let Some(DfuNusbError::Dfu(DfuCoreError::StateError(DfuState::DfuError))) =
537541
error.downcast_ref::<DfuNusbError>()
@@ -555,7 +559,7 @@ impl BmpDevice
555559
.unwrap()
556560
.control_out_blocking(request, &[], Duration::from_secs(2))?;
557561

558-
self.try_download(firmware, length, &mut dfu_iface)
562+
self.try_download(firmware_file.data(), firmware_file.len(), &mut dfu_iface)
559563
} else {
560564
Err(error)
561565
}

src/flasher.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ impl Firmware
8989
{
9090
// Extract the firmware type as a value so it can be captured and moved (copied) by the progress lambda
9191
let firmware_type = self.firmware_type;
92-
// Pull out the data to program
93-
let firmware_data = self.firmware_file.data();
9492
// Pull out the length of the firmware image and make it a u64
9593
let firmware_length = self.firmware_file.len() as u64;
9694

@@ -106,7 +104,7 @@ impl Firmware
106104
let progress_bar = Rc::new(progress_bar);
107105
let enclosed = Rc::clone(&progress_bar);
108106

109-
let result = device.download(firmware_data, firmware_type, move |flash_pos_delta| {
107+
let result = device.download(&self.firmware_file, firmware_type, move |flash_pos_delta| {
110108
// Don't actually print flashing until the erasing has finished.
111109
if enclosed.position() == 0 {
112110
if firmware_type == FirmwareType::Application {

0 commit comments

Comments
 (0)