@@ -19,6 +19,7 @@ use nusb::{Device, DeviceInfo, Interface};
1919
2020pub use crate :: bmp_matcher:: BmpMatcher ;
2121use crate :: error:: ErrorKind ;
22+ use crate :: firmware_file:: FirmwareFile ;
2223// XXX: Ideally this shouldn't be pub here, but that's a breaking change.
2324pub use crate :: firmware_type:: FirmwareType ;
2425use 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 }
0 commit comments