-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates an image bundle with FMC and Runtime populated with zeros. 0 is an ilegal opcode in risc-v, so the image will immediately NMI. This is useful for testing production signing infrastructure. A production key can be used to sign this image before an official release is ready. The prod-signed zeros binary is benign but can be used to ensure that the prod key was loaded into fuses correctly.
- Loading branch information
Showing
11 changed files
with
233 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ members = [ | |
"test", | ||
"test-harness", | ||
"test-harness/types", | ||
"zero_bin", | ||
] | ||
|
||
[workspace.dependencies] | ||
|
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 | ||
|
||
[package] | ||
name = "caliptra-zeros" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[build-dependencies] | ||
caliptra_common = { workspace = true, default-features = false } | ||
caliptra-gen-linker-scripts.workspace = true | ||
cfg-if.workspace = true | ||
|
||
[dev-dependencies] | ||
caliptra-api.workspace = true | ||
caliptra-builder.workspace = true | ||
caliptra-error.workspace = true | ||
caliptra-hw-model.workspace = true | ||
|
||
[features] | ||
default = ["std"] | ||
std = ["caliptra_common/std"] | ||
riscv = [] | ||
fmc = [] |
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,37 @@ | ||
fn main() { | ||
cfg_if::cfg_if! { | ||
if #[cfg(not(feature = "std"))] { | ||
use std::env; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
use caliptra_gen_linker_scripts::gen_memory_x; | ||
|
||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
|
||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "fmc")] { | ||
fs::write(out_dir.join("memory.x"),gen_memory_x(caliptra_common::FMC_ORG, caliptra_common::FMC_SIZE) | ||
.as_bytes()) | ||
.expect("Unable to generate memory.x"); | ||
} else { | ||
fs::write(out_dir.join("memory.x"),gen_memory_x(caliptra_common::RUNTIME_ORG, caliptra_common::RUNTIME_SIZE) | ||
.as_bytes()) | ||
.expect("Unable to generate memory.x"); | ||
} | ||
} | ||
|
||
fs::write(out_dir.join("link.x"), include_bytes!("src/link.x")).unwrap(); | ||
|
||
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
|
||
println!("cargo:rustc-link-search={}", out_dir.display()); | ||
|
||
println!("cargo:rerun-if-changed=memory.x"); | ||
println!("cargo:rustc-link-arg=-Tmemory.x"); | ||
|
||
println!("cargo:rerun-if-changed=link.x"); | ||
println!("cargo:rustc-link-arg=-Tlink.x"); | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
} | ||
} | ||
} |
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,14 @@ | ||
SECTIONS | ||
{ | ||
.text : ALIGN(4) | ||
{ | ||
_stext = .; | ||
|
||
KEEP(*(.init .init.*)); | ||
*(.text .text.*); | ||
KEEP(*(.vectors)) | ||
|
||
. = ALIGN(4); | ||
_etext = .; | ||
} > REGION_TEXT | ||
} |
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,15 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
#![cfg_attr(not(feature = "std"), no_main)] | ||
|
||
#[cfg(target_arch = "riscv32")] | ||
core::arch::global_asm!(include_str!("zeros.S")); | ||
|
||
#[cfg(feature = "std")] | ||
pub fn main() {} | ||
|
||
// Should not be linked | ||
#[cfg(not(feature = "std"))] | ||
#[panic_handler] | ||
fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
loop {} | ||
} |
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,19 @@ | ||
.section .init.text, "ax" | ||
.global _start | ||
_start: | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 | ||
.word 0 |
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,38 @@ | ||
// Licensed under the Apache-2.0 license | ||
|
||
use caliptra_api::soc_mgr::SocManager; | ||
use caliptra_builder::{ | ||
firmware::{APP_ZEROS, FMC_ZEROS}, | ||
ImageOptions, | ||
}; | ||
use caliptra_error::CaliptraError; | ||
use caliptra_hw_model::{BootParams, HwModel, InitParams}; | ||
|
||
#[test] | ||
fn test_zeros() { | ||
let rom = caliptra_builder::rom_for_fw_integration_tests().unwrap(); | ||
let init_params = InitParams { | ||
rom: &rom, | ||
..Default::default() | ||
}; | ||
|
||
let image = | ||
caliptra_builder::build_and_sign_image(&FMC_ZEROS, &APP_ZEROS, ImageOptions::default()) | ||
.unwrap(); | ||
|
||
let mut model = caliptra_hw_model::new( | ||
init_params, | ||
BootParams { | ||
fw_image: Some(&image.to_bytes().unwrap()), | ||
..Default::default() | ||
}, | ||
) | ||
.unwrap(); | ||
|
||
// 0 is an ilegal instruction in risc-v. Image should immediately NMI. | ||
model.step_until(|m| m.soc_ifc().cptra_fw_error_fatal().read() != 0); | ||
assert_eq!( | ||
model.soc_ifc().cptra_fw_error_fatal().read(), | ||
u32::from(CaliptraError::ROM_GLOBAL_EXCEPTION) | ||
); | ||
} |