Skip to content

Commit

Permalink
Add a structure for CMPA/CFPA config
Browse files Browse the repository at this point in the history
Makes it nicer for checking in config files places
  • Loading branch information
labbott committed Feb 2, 2024
1 parent 96f064e commit aad08eb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lpc55_areas/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lpc55_areas"
version = "0.2.4"
version = "0.2.5"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion lpc55_areas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl DefaultIsp {
}
}

#[derive(PrimitiveEnum, Copy, Clone, Debug)]
#[derive(PrimitiveEnum, Copy, Clone, Debug, Deserialize)]
pub enum BootSpeed {
Nmpa = 0b00,
Fro48mhz = 0b10,
Expand Down
2 changes: 1 addition & 1 deletion lpc55_sign/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lpc55_sign"
version = "0.3.3"
version = "0.3.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
62 changes: 62 additions & 0 deletions lpc55_sign/src/signed_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,68 @@ use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use x509_cert::Certificate;

/// Combined structure definine both CMPA/CFPA
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct MfgCfg {
pub cfpa: CfpaCfg,
pub cmpa: CmpaCfg,
}


/// Structure defining a CFPA configuration
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct CfpaCfg {
rkth0: ROTKeyStatus,
rkth1: ROTKeyStatus,
rkth2: ROTKeyStatus,
rkth3: ROTKeyStatus,
debug: DebugSettings,
image_key_revoke: u16,
}

impl CfpaCfg {
pub fn generate(&self) -> Result<CFPAPage, Error> {
generate_cfpa(
self.debug,
[self.rkth0, self.rkth1, self.rkth2, self.rkth3],
self.image_key_revoke,
)
}
}

/// Structure defining a CMPA configuration
/// note the ROTKH and lock fields are purposely omitted
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct CmpaCfg {
secure_boot: bool,
dice: DiceArgs,
default_isp: DefaultIsp,
boot_speed: BootSpeed,
boot_err_pin: u8,
boot_err_port: u8,
debug: DebugSettings,
only_rsa_4096: bool,
}

impl CmpaCfg {
pub fn generate(&self, lock: bool, rotkh: [u8; 32]) -> Result<CMPAPage, Error> {
generate_cmpa(
self.dice,
self.secure_boot,
self.debug,
self.default_isp,
self.boot_speed,
BootErrorPin::new(self.boot_err_port, self.boot_err_pin).unwrap(),
rotkh,
lock,
self.only_rsa_4096,
)
}
}

/// Struct defining the TOML format for `--cert-cfg`, which bundles up flags
/// that would otherwise need to appear on the command line.
#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down

0 comments on commit aad08eb

Please sign in to comment.