Skip to content

Commit

Permalink
lpc55-rot-startup: Get DICE mfg flash region from HUBRIS_FLASH_OUTPUTs.
Browse files Browse the repository at this point in the history
HUBRIS_DICE_MFG is no longer needed.
  • Loading branch information
flihp committed Aug 25, 2023
1 parent cc131b7 commit b2b4861
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 58 deletions.
14 changes: 0 additions & 14 deletions build/xtask/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ pub struct Config {
/// Fully expanded manifest file, with all patches applied
pub app_config: String,
pub auxflash: Option<AuxFlashData>,
pub dice_mfg: Option<Output>,
pub caboose: Option<CabooseConfig>,
}

Expand Down Expand Up @@ -163,11 +162,6 @@ impl Config {
None => None,
};

let dice_mfg = match outputs.get("flash") {
Some(f) => f.iter().find(|&o| o.name == "dice-mfg").cloned(),
None => None,
};

Ok(Config {
name: toml.name,
target: toml.target,
Expand All @@ -189,7 +183,6 @@ impl Config {
buildhash,
app_toml_path: cfg.to_owned(),
app_config: cfg_contents,
dice_mfg,
caboose: toml.caboose,
})
}
Expand Down Expand Up @@ -283,13 +276,6 @@ impl Config {
env.insert("HUBRIS_APP_CONFIG".to_string(), app_config);
}

if let Some(output) = &self.dice_mfg {
env.insert(
"HUBRIS_DICE_MFG".to_string(),
toml::to_string(&output).unwrap(),
);
}

let out_path = Path::new("")
.join(&self.target)
.join("release")
Expand Down
36 changes: 2 additions & 34 deletions lib/lpc55-rot-startup/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,18 @@ use serde::Deserialize;
use std::fs::File;
use std::io::Write;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let out = build_util::out_dir();
gen_image_flash_range(&out)?;

#[cfg(feature = "dice-mfg")]
{
gen_memory_range(&out)?;
}

Ok(())
}

#[derive(Deserialize, Debug)]
struct Region {
pub name: String,
pub address: u32,
pub size: u32,
}

#[cfg(feature = "dice-mfg")]
fn gen_memory_range(
out_dir: &std::path::PathBuf,
) -> Result<(), Box<dyn std::error::Error>> {
let toml = build_util::env_var("HUBRIS_DICE_MFG")?;
let region: Region = toml::from_str(&toml)?;
let mut dice_mfg = File::create(out_dir.join("dice-mfg.rs")).unwrap();

writeln!(
dice_mfg,
"use core::ops::Range;\n\n\
pub const DICE_FLASH: Range<usize> = {:#x}..{:#x};",
region.address,
region.address + region.size
)?;

Ok(())
}

fn gen_image_flash_range(
out_dir: &std::path::PathBuf,
) -> Result<(), Box<dyn std::error::Error>> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
let outputs = build_util::env_var("HUBRIS_FLASH_OUTPUTS")?;
let outputs: Vec<Region> = ron::de::from_str(&outputs)?;

let out_dir = build_util::out_dir();
let mut cfg = File::create(out_dir.join("config.rs")).unwrap();

writeln!(cfg, "use core::ops::Range;\n")?;
Expand Down
24 changes: 14 additions & 10 deletions lib/lpc55-rot-startup/src/dice_mfg_usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ macro_rules! flash_page_align {
};
}

// ensure DiceState object will fit in DICE_FLASH range
// ensure DiceState object will fit in FLASH_DICE_MFG range
sa::const_assert!(
(DICE_FLASH.end - DICE_FLASH.start)
(FLASH_DICE_MFG.end - FLASH_DICE_MFG.start) as usize
>= flash_page_align!(DiceState::MAX_SIZE)
);

// ensure DICE_FLASH start and end are alligned
sa::const_assert!(DICE_FLASH.end % lpc55_romapi::FLASH_PAGE_SIZE == 0);
sa::const_assert!(DICE_FLASH.start % lpc55_romapi::FLASH_PAGE_SIZE == 0);
// ensure FLASH_DICE_MFG start and end are alligned
sa::const_assert!(
FLASH_DICE_MFG.end as usize % lpc55_romapi::FLASH_PAGE_SIZE == 0
);
sa::const_assert!(
FLASH_DICE_MFG.start as usize % lpc55_romapi::FLASH_PAGE_SIZE == 0
);

const VERSION: u32 = 0;
const MAGIC: [u8; 12] = [
Expand Down Expand Up @@ -84,7 +88,7 @@ impl DiceState {
// conditional evaluated before executing this unsafe code.
let src = unsafe {
core::slice::from_raw_parts(
DICE_FLASH.start as *const u8,
FLASH_DICE_MFG.start as *const u8,
Self::ALIGNED_MAX_SIZE,
)
};
Expand Down Expand Up @@ -121,12 +125,12 @@ impl DiceState {
// TODO: error handling
unsafe {
lpc55_romapi::flash_erase(
DICE_FLASH.start as *const u32 as u32,
FLASH_DICE_MFG.start as *const u32 as u32,
Self::ALIGNED_MAX_SIZE as u32,
)
.expect("flash_erase");
lpc55_romapi::flash_write(
DICE_FLASH.start as *const u32 as u32,
FLASH_DICE_MFG.start as *const u32 as u32,
&mut buf as *mut u8,
Self::ALIGNED_MAX_SIZE as u32,
)
Expand All @@ -138,7 +142,7 @@ impl DiceState {

pub fn is_programmed() -> bool {
lpc55_romapi::validate_programmed(
DICE_FLASH.start as u32,
FLASH_DICE_MFG.start,
flash_page_align!(Header::MAX_SIZE + Self::MAX_SIZE) as u32,
)
}
Expand Down Expand Up @@ -300,4 +304,4 @@ fn flexcomm0_setup(
syscon.fcclksel0().modify(|_, w| w.sel().enum_0x2());
}

include!(concat!(env!("OUT_DIR"), "/dice-mfg.rs"));
include!(concat!(env!("OUT_DIR"), "/config.rs"));

0 comments on commit b2b4861

Please sign in to comment.