-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently reports just a single bit representing functionality present in v1.0 of ROM.
- Loading branch information
1 parent
98f9a0d
commit c76b3ed
Showing
7 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*++ | ||
Licensed under the Apache-2.0 license. | ||
File Name: | ||
capabilities.rs | ||
Abstract: | ||
Capability bits | ||
--*/ | ||
|
||
bitflags::bitflags! { | ||
#[derive(Default, Copy, Clone, Debug)] | ||
pub struct Capabilities : u128 { | ||
// Represents base capabilities present in Caliptra ROM v1.0 | ||
const ROM_BASE = 0b0001; | ||
} | ||
} | ||
|
||
impl Capabilities { | ||
pub fn to_bytes(&self) -> [u8; 16] { | ||
self.bits().to_be_bytes() | ||
} | ||
} | ||
|
||
impl TryFrom<&[u8]> for Capabilities { | ||
type Error = (); | ||
fn try_from(value: &[u8]) -> Result<Self, Self::Error> { | ||
if value.len() != 16 { | ||
Err(()) | ||
} else { | ||
let capabilities = u128::from_be_bytes(value.try_into().unwrap()); | ||
let caps = Capabilities::from_bits(capabilities); | ||
caps.ok_or(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Licensed under the Apache-2.0 license | ||
|
||
use caliptra_builder::ImageOptions; | ||
use caliptra_common::{capabilities::Capabilities, mailbox_api::CommandId}; | ||
use caliptra_hw_model::{Fuses, HwModel}; | ||
use zerocopy::AsBytes; | ||
|
||
pub mod helpers; | ||
|
||
#[test] | ||
fn test_capabilities() { | ||
let (mut hw, _image_bundle) = | ||
helpers::build_hw_model_and_image_bundle(Fuses::default(), ImageOptions::default()); | ||
|
||
let response = hw | ||
.mailbox_execute(CommandId::CAPABILITIES.into(), &[]) | ||
.unwrap() | ||
.unwrap(); | ||
|
||
let caps = Capabilities::try_from(response.as_bytes()).unwrap(); | ||
|
||
assert!(caps.contains(Capabilities::ROM_BASE)); | ||
} |