@@ -19,7 +19,6 @@ use crate::{
1919} ;
2020use abi:: { ImageHeader , CABOOSE_MAGIC , HEADER_MAGIC } ;
2121use core:: ops:: Range ;
22- use drv_lpc55_flash:: BYTES_PER_FLASH_PAGE ;
2322use drv_lpc55_update_api:: { RawCabooseError , RotComponent , SlotId } ;
2423use drv_update_api:: UpdateError ;
2524use zerocopy:: { AsBytes , FromBytes } ;
@@ -91,7 +90,7 @@ pub fn flash_range(component: RotComponent, slot: SlotId) -> FlashRange {
9190}
9291
9392/// Does (component, slot) refer to the currently running Hubris image?
94- pub fn same_image ( component : RotComponent , slot : SlotId ) -> bool {
93+ pub fn is_current_hubris_image ( component : RotComponent , slot : SlotId ) -> bool {
9594 // Safety: We are trusting the linker.
9695 flash_range ( component, slot) . store . start
9796 == unsafe { & __this_image } as * const _ as u32
@@ -293,7 +292,7 @@ pub fn caboose_slice(
293292 }
294293}
295294
296- // Accessor keeps the implementation details of ImageAccess private
295+ /// Accessor keeps the implementation details of ImageAccess private
297296enum Accessor < ' a > {
298297 // Flash driver, flash device range
299298 Flash {
@@ -372,8 +371,6 @@ impl ImageAccess<'_> {
372371 component : RotComponent ,
373372 slot : SlotId ,
374373 ) -> ImageAccess < ' a > {
375- assert ! ( ( buffer. len( ) % BYTES_PER_FLASH_PAGE ) == 0 ) ;
376- assert ! ( ( ( buffer. as_ptr( ) as u32 ) % U32_SIZE ) == 0 ) ;
377374 let span = flash_range ( component, slot) ;
378375 ImageAccess {
379376 accessor : Accessor :: _Hybrid {
@@ -459,9 +456,8 @@ impl ImageAccess<'_> {
459456 let len = buffer. len ( ) as u32 ;
460457 match & self . accessor {
461458 Accessor :: Flash { flash, span } => {
462- let start = offset. saturating_add ( span. store . start ) ;
463- let end =
464- offset. saturating_add ( span. store . start ) . saturating_add ( len) ;
459+ let start = span. store . start . saturating_add ( offset) ;
460+ let end = start. saturating_add ( len) ;
465461 if span. store . contains ( & start)
466462 && ( span. store . start ..=span. store . end ) . contains ( & end)
467463 {
@@ -503,14 +499,12 @@ impl ImageAccess<'_> {
503499 }
504500 // Transfer data from the flash-backed portion of the image.
505501 if remainder > 0 {
506- let start =
507- offset. saturating_add ( span. store . start as usize ) ;
508- let end = start. saturating_add ( remainder) ;
509- if span. store . contains ( & ( start as u32 ) )
510- && ( span. store . start ..=span. store . end )
511- . contains ( & ( end as u32 ) )
502+ let start = span. store . start . saturating_add ( offset as u32 ) ;
503+ let end = start. saturating_add ( remainder as u32 ) ;
504+ if span. store . contains ( & start)
505+ && ( span. store . start ..=span. store . end ) . contains ( & end)
512506 {
513- indirect_flash_read ( flash, start as u32 , buffer) ?;
507+ indirect_flash_read ( flash, start, buffer) ?;
514508 } else {
515509 return Err ( UpdateError :: OutOfBounds ) ;
516510 }
0 commit comments