@@ -19,7 +19,6 @@ use crate::{
19
19
} ;
20
20
use abi:: { ImageHeader , CABOOSE_MAGIC , HEADER_MAGIC } ;
21
21
use core:: ops:: Range ;
22
- use drv_lpc55_flash:: BYTES_PER_FLASH_PAGE ;
23
22
use drv_lpc55_update_api:: { RawCabooseError , RotComponent , SlotId } ;
24
23
use drv_update_api:: UpdateError ;
25
24
use zerocopy:: { AsBytes , FromBytes } ;
@@ -91,7 +90,7 @@ pub fn flash_range(component: RotComponent, slot: SlotId) -> FlashRange {
91
90
}
92
91
93
92
/// 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 {
95
94
// Safety: We are trusting the linker.
96
95
flash_range ( component, slot) . store . start
97
96
== unsafe { & __this_image } as * const _ as u32
@@ -293,7 +292,7 @@ pub fn caboose_slice(
293
292
}
294
293
}
295
294
296
- // Accessor keeps the implementation details of ImageAccess private
295
+ /// Accessor keeps the implementation details of ImageAccess private
297
296
enum Accessor < ' a > {
298
297
// Flash driver, flash device range
299
298
Flash {
@@ -372,8 +371,6 @@ impl ImageAccess<'_> {
372
371
component : RotComponent ,
373
372
slot : SlotId ,
374
373
) -> ImageAccess < ' a > {
375
- assert ! ( ( buffer. len( ) % BYTES_PER_FLASH_PAGE ) == 0 ) ;
376
- assert ! ( ( ( buffer. as_ptr( ) as u32 ) % U32_SIZE ) == 0 ) ;
377
374
let span = flash_range ( component, slot) ;
378
375
ImageAccess {
379
376
accessor : Accessor :: _Hybrid {
@@ -459,9 +456,8 @@ impl ImageAccess<'_> {
459
456
let len = buffer. len ( ) as u32 ;
460
457
match & self . accessor {
461
458
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) ;
465
461
if span. store . contains ( & start)
466
462
&& ( span. store . start ..=span. store . end ) . contains ( & end)
467
463
{
@@ -503,14 +499,12 @@ impl ImageAccess<'_> {
503
499
}
504
500
// Transfer data from the flash-backed portion of the image.
505
501
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)
512
506
{
513
- indirect_flash_read ( flash, start as u32 , buffer) ?;
507
+ indirect_flash_read ( flash, start, buffer) ?;
514
508
} else {
515
509
return Err ( UpdateError :: OutOfBounds ) ;
516
510
}
0 commit comments