-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add APOB messages to host_sp_comms #2006
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -134,6 +134,11 @@ enum Trace { | |||||
#[count(children)] | ||||||
message: SpToHost, | ||||||
}, | ||||||
APOBWriteError { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly, i think this would be
Suggested change
|
||||||
offset: u64, | ||||||
#[count(children)] | ||||||
err: APOBError, | ||||||
Comment on lines
+138
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth leaving a comment here indicating that the Or, perhaps we should call the |
||||||
}, | ||||||
} | ||||||
|
||||||
counted_ringbuf!(Trace, 20, Trace::None); | ||||||
|
@@ -160,6 +165,31 @@ enum Timers { | |||||
TxPeriodicZeroByte, | ||||||
} | ||||||
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, counters::Count)] | ||||||
enum APOBError { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aaaaand my stupid capitalization thing again:
Suggested change
|
||||||
OffsetOverflow { | ||||||
offset: u64, | ||||||
}, | ||||||
NotErased { | ||||||
offset: u32, | ||||||
}, | ||||||
EraseFailed { | ||||||
offset: u32, | ||||||
#[count(children)] | ||||||
err: drv_hf_api::HfError, | ||||||
}, | ||||||
WriteFailed { | ||||||
offset: u32, | ||||||
#[count(children)] | ||||||
err: drv_hf_api::HfError, | ||||||
}, | ||||||
ReadFailed { | ||||||
offset: u32, | ||||||
#[count(children)] | ||||||
err: drv_hf_api::HfError, | ||||||
}, | ||||||
} | ||||||
|
||||||
#[export_name = "main"] | ||||||
fn main() -> ! { | ||||||
let mut server = ServerImpl::claim_static_resources(); | ||||||
|
@@ -967,6 +997,15 @@ impl ServerImpl { | |||||
}), | ||||||
} | ||||||
} | ||||||
HostToSp::APOB { offset } => { | ||||||
Some(match Self::apob_write(&self.hf, offset, data) { | ||||||
Ok(()) => SpToHost::APOBResult(0), | ||||||
Err(err) => { | ||||||
ringbuf_entry!(Trace::APOBWriteError { offset, err }); | ||||||
SpToHost::APOBResult(1) | ||||||
} | ||||||
}) | ||||||
} | ||||||
}; | ||||||
|
||||||
if let Some(response) = response { | ||||||
|
@@ -995,6 +1034,51 @@ impl ServerImpl { | |||||
Ok(()) | ||||||
} | ||||||
|
||||||
/// Write data to the bonus region of flash | ||||||
/// | ||||||
/// This does not take `&self` because we need to force a split borrow | ||||||
fn apob_write( | ||||||
hf: &HostFlash, | ||||||
mut offset: u64, | ||||||
data: &[u8], | ||||||
) -> Result<(), APOBError> { | ||||||
for chunk in data.chunks(drv_hf_api::PAGE_SIZE_BYTES) { | ||||||
Self::apob_write_page( | ||||||
hf, | ||||||
offset | ||||||
.try_into() | ||||||
.map_err(|_| APOBError::OffsetOverflow { offset })?, | ||||||
chunk, | ||||||
)?; | ||||||
offset += chunk.len() as u64; | ||||||
} | ||||||
Ok(()) | ||||||
} | ||||||
|
||||||
/// Write a single page of data to the bonus region of flash | ||||||
/// | ||||||
/// This does not take `&self` because we need to force a split borrow | ||||||
fn apob_write_page( | ||||||
hf: &HostFlash, | ||||||
offset: u32, | ||||||
data: &[u8], | ||||||
) -> Result<(), APOBError> { | ||||||
if offset as usize % drv_hf_api::SECTOR_SIZE_BYTES == 0 { | ||||||
hf.bonus_sector_erase(offset) | ||||||
.map_err(|err| APOBError::EraseFailed { offset, err })?; | ||||||
} else { | ||||||
// Read back the page and confirm that it's all empty | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this fail if there's a blip in the IPCC path and the host resends an |
||||||
let mut scratch = [0u8; drv_hf_api::PAGE_SIZE_BYTES]; | ||||||
hf.bonus_read(offset, &mut scratch[..data.len()]) | ||||||
.map_err(|err| APOBError::ReadFailed { offset, err })?; | ||||||
if !scratch[..data.len()].iter().all(|b| *b == 0xFF) { | ||||||
return Err(APOBError::NotErased { offset }); | ||||||
} | ||||||
} | ||||||
hf.bonus_page_program(offset, data) | ||||||
.map_err(|err| APOBError::WriteFailed { offset, err }) | ||||||
} | ||||||
|
||||||
fn handle_sprot( | ||||||
&mut self, | ||||||
sequence: u64, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suuuper nitpicky, feel free to disregard me: I think the recommended Rust naming conventions for casing is that acronyms should be treated as a "word" in camel-case, and only the first letter should be uppercased, so this would be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that other variants of this enum follow this convention (e.g.
GetMacIdentity
rather thanGetMACIdentity
;RotRequest
rather thanROTRequest
, and so on).