Skip to content

Commit 23e8186

Browse files
committed
Changes from PR review
1 parent 39d2fbe commit 23e8186

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

drv/lpc55-update-server/src/images.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::{
1919
};
2020
use abi::{ImageHeader, CABOOSE_MAGIC, HEADER_MAGIC};
2121
use core::ops::Range;
22-
use drv_lpc55_flash::BYTES_PER_FLASH_PAGE;
2322
use drv_lpc55_update_api::{RawCabooseError, RotComponent, SlotId};
2423
use drv_update_api::UpdateError;
2524
use 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
297296
enum 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
}

drv/lpc55-update-server/src/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ use zerocopy::AsBytes;
3333

3434
mod images;
3535
use crate::images::{
36-
caboose_slice, flash_range, same_image, ImageAccess, HEADER_BLOCK,
36+
caboose_slice, flash_range, is_current_hubris_image, ImageAccess,
37+
HEADER_BLOCK,
3738
};
3839

3940
const PAGE_SIZE: u32 = BYTES_PER_FLASH_PAGE as u32;
@@ -1143,7 +1144,7 @@ fn do_block_write(
11431144
let page_num = block_num as u32;
11441145

11451146
// Can only update opposite image
1146-
if same_image(component, slot) {
1147+
if is_current_hubris_image(component, slot) {
11471148
return Err(UpdateError::RunningImage);
11481149
}
11491150

0 commit comments

Comments
 (0)