fn update(&self, spi: &dyn Target, payload: &[u8]) -> Result<()> {
        let frames = Frame::from_payload(payload);

        for (i, frame) in frames.iter().enumerate() {
            let want_hash = frames[i.saturating_sub(1)].frame_hash();
            // Repeatedly transmit the frame, until receiving expected response.
            loop {
                // TODO: Introduce a progress callback, to allow common code to show progress bar.
                eprint!("{}.", i);

                // Important? Comment in spiflash.cc indicates that it seems to corrupt without a
                // 1ms delay.
                std::thread::sleep(self.inter_frame_delay);

                // Write the frame and read back the hash of the previous frame.
                let mut response = [0u8; std::mem::size_of::<Frame>()];
                spi.run_transaction(&mut [Transfer::Both(frame.as_bytes(), &mut response)])?;

                if response.iter().all(|&x| x == response[0]) {
                    // A response consisteing of all identical bytes is a status code.
                    match LegacyBootstrapError::from(response[0]) {
                        LegacyBootstrapError::NotReady => continue, // Retry sending same frame.
                        error => return Err(error.into()),
                    }
                }

                // Compare response with checksum of last block sent.
                if response[..Frame::HASH_LEN] == want_hash {
                    // Successful response, move on to the next frame.
                    break;
                }
                log::error!(
                    "Frame hash mismatch device:{:x?} != frame:{:x?}.",
                    &response[..Frame::HASH_LEN],
                    want_hash
                );
                // Retry sending same frame.
            }
        }
        eprintln!("success");
        Ok(())
    }
/// Performs the update protocol using the `transport` with the firmware `payload`.
Performs the update protocol using the `transport` with the firmware `payload`.
Performs the update protocol using the ` transport ` with the firmware ` payload ` .
fn update(&self, spi: &dyn Target, payload: &[u8]) -> Result<()> {
        let frames = Frame::from_payload(payload);
        for (i, frame) in frames.iter().enumerate() {
            let want_hash = frames[i.saturating_sub(1)].frame_hash();
            // Repeatedly transmit the frame, until receiving expected response.
            loop {
                // TODO: Introduce a progress callback, to allow common code to show progress bar.
                eprint!("{}.", i);
                // Important? Comment in spiflash.cc indicates that it seems to corrupt without a
                // 1ms delay.
                std::thread::sleep(self.inter_frame_delay);
                // Write the frame and read back the hash of the previous frame.
                let mut response = [0u8; std::mem::size_of::<Frame>()];
                spi.run_transaction(&mut [Transfer::Both(frame.as_bytes(), &mut response)])?;
                if response.iter().all(|&x| x == response[0]) {
                    // A response consisteing of all identical bytes is a status code.
                    match LegacyBootstrapError::from(response[0]) {
                        LegacyBootstrapError::NotReady => continue, // Retry sending same frame.
                        error => return Err(error.into()),
                    }
                }
                // Compare response with checksum of last block sent.
                if response[..Frame::HASH_LEN] == want_hash {
                    // Successful response, move on to the next frame.
                    break;
                }
                log::error!(
                    "Frame hash mismatch device:{:x?} != frame:{:x?}.",
                    &response[..Frame::HASH_LEN],
                    want_hash
                );
                // Retry sending same frame.
            }
        }
        eprintln!("success");
        Ok(())
    }
fn update ( & self , spi : & dyn Target , payload : & [ u8 ] ) -> Result < ( ) > { let frames = Frame :: from_payload ( payload ) ; for ( i , frame ) in frames . iter ( ) . enumerate ( ) { let want_hash = frames [ i . saturating_sub ( 1 ) ] . frame_hash ( ) ; // Repeatedly transmit the frame, until receiving expected response. loop { // TODO: Introduce a progress callback, to allow common code to show progress bar. eprint ! ( " " i ) ; // Important? Comment in spiflash.cc indicates that it seems to corrupt without a // 1ms delay. std :: thread :: sleep ( self . inter_frame_delay ) ; // Write the frame and read back the hash of the previous frame. let mut response = [ 0u8 ; std :: mem :: size_of :: < Frame > ( ) ] ; spi . run_transaction ( & mut [ Transfer :: Both ( frame . as_bytes ( ) , & mut response ) ] ) ? ; if response . iter ( ) . all ( | & x | x == response [ 0 ] ) { // A response consisteing of all identical bytes is a status code. match LegacyBootstrapError :: from ( response [ 0 ] ) { LegacyBootstrapError :: NotReady => continue , // Retry sending same frame. error => return Err ( error . into ( ) ) , } } // Compare response with checksum of last block sent. if response [ .. Frame :: HASH_LEN ] == want_hash { // Successful response, move on to the next frame. break ; } log :: error ! ( " " response [ Frame HASH_LEN ] want_hash ) ; // Retry sending same frame. } } eprintln ! ( " " ) ; Ok ( ( ) ) }
Performs the update protocol using the `transport` with the firmware `payload`.
Performs the update protocol using the ` transport ` with the firmware ` payload ` .
&self
spi
&dyn Target
payload
&[u8]