Skip to content

Commit

Permalink
Changes from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
lzrd committed Aug 1, 2024
1 parent 39d2fbe commit 23e8186
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
24 changes: 9 additions & 15 deletions drv/lpc55-update-server/src/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{
};
use abi::{ImageHeader, CABOOSE_MAGIC, HEADER_MAGIC};
use core::ops::Range;
use drv_lpc55_flash::BYTES_PER_FLASH_PAGE;
use drv_lpc55_update_api::{RawCabooseError, RotComponent, SlotId};
use drv_update_api::UpdateError;
use zerocopy::{AsBytes, FromBytes};
Expand Down Expand Up @@ -91,7 +90,7 @@ pub fn flash_range(component: RotComponent, slot: SlotId) -> FlashRange {
}

/// Does (component, slot) refer to the currently running Hubris image?
pub fn same_image(component: RotComponent, slot: SlotId) -> bool {
pub fn is_current_hubris_image(component: RotComponent, slot: SlotId) -> bool {
// Safety: We are trusting the linker.
flash_range(component, slot).store.start
== unsafe { &__this_image } as *const _ as u32
Expand Down Expand Up @@ -293,7 +292,7 @@ pub fn caboose_slice(
}
}

// Accessor keeps the implementation details of ImageAccess private
/// Accessor keeps the implementation details of ImageAccess private
enum Accessor<'a> {
// Flash driver, flash device range
Flash {
Expand Down Expand Up @@ -372,8 +371,6 @@ impl ImageAccess<'_> {
component: RotComponent,
slot: SlotId,
) -> ImageAccess<'a> {
assert!((buffer.len() % BYTES_PER_FLASH_PAGE) == 0);
assert!(((buffer.as_ptr() as u32) % U32_SIZE) == 0);
let span = flash_range(component, slot);
ImageAccess {
accessor: Accessor::_Hybrid {
Expand Down Expand Up @@ -459,9 +456,8 @@ impl ImageAccess<'_> {
let len = buffer.len() as u32;
match &self.accessor {
Accessor::Flash { flash, span } => {
let start = offset.saturating_add(span.store.start);
let end =
offset.saturating_add(span.store.start).saturating_add(len);
let start = span.store.start.saturating_add(offset);
let end = start.saturating_add(len);
if span.store.contains(&start)
&& (span.store.start..=span.store.end).contains(&end)
{
Expand Down Expand Up @@ -503,14 +499,12 @@ impl ImageAccess<'_> {
}
// Transfer data from the flash-backed portion of the image.
if remainder > 0 {
let start =
offset.saturating_add(span.store.start as usize);
let end = start.saturating_add(remainder);
if span.store.contains(&(start as u32))
&& (span.store.start..=span.store.end)
.contains(&(end as u32))
let start = span.store.start.saturating_add(offset as u32);
let end = start.saturating_add(remainder as u32);
if span.store.contains(&start)
&& (span.store.start..=span.store.end).contains(&end)
{
indirect_flash_read(flash, start as u32, buffer)?;
indirect_flash_read(flash, start, buffer)?;
} else {
return Err(UpdateError::OutOfBounds);
}
Expand Down
5 changes: 3 additions & 2 deletions drv/lpc55-update-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ use zerocopy::AsBytes;

mod images;
use crate::images::{
caboose_slice, flash_range, same_image, ImageAccess, HEADER_BLOCK,
caboose_slice, flash_range, is_current_hubris_image, ImageAccess,
HEADER_BLOCK,
};

const PAGE_SIZE: u32 = BYTES_PER_FLASH_PAGE as u32;
Expand Down Expand Up @@ -1143,7 +1144,7 @@ fn do_block_write(
let page_num = block_num as u32;

// Can only update opposite image
if same_image(component, slot) {
if is_current_hubris_image(component, slot) {
return Err(UpdateError::RunningImage);
}

Expand Down

0 comments on commit 23e8186

Please sign in to comment.