Skip to content

Commit

Permalink
Just include it in the binding maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
swenson committed Feb 22, 2025
1 parent 1260622 commit 96825fa
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion hw-model/c-binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
caliptra-cfi-lib.workspace = true
caliptra-emu-bus.workspace = true
caliptra-emu-types.workspace = true
caliptra-hw-model.workspace = true
Expand All @@ -19,4 +20,4 @@ itrng = ["caliptra-hw-model/itrng"]
verilator = ["caliptra-hw-model/verilator"]

[build-dependencies]
cbindgen.workspace = true
cbindgen.workspace = true
2 changes: 1 addition & 1 deletion hw-model/c-binding/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TARGET = $(OUT)/smoke_test
RTL_SOC_IFC_INCLUDE_PATH = ../../../hw/latest/rtl/src/soc_ifc/rtl
BUILDER_PATH = ../../../builder
CALIPTRA_MODEL_PATH = ../out
CFLAGS += -flto -I$(RTL_SOC_IFC_INCLUDE_PATH) -I$(CALIPTRA_MODEL_PATH)
CFLAGS += -I$(RTL_SOC_IFC_INCLUDE_PATH) -I$(CALIPTRA_MODEL_PATH)

SOURCE += api/caliptra_api.c
SOURCE += smoke_test.c
Expand Down
13 changes: 0 additions & 13 deletions hw-model/c-binding/examples/smoke_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@

static const uint32_t RT_READY_FOR_COMMANDS = 0x600;

// These are needed if CFI is enabled.
void cfi_panic_handler(void)
{
exit(-ENOENT);
}

uint8_t CFI_STATE_ORG[256] = {0}; // leave some extra room

static struct caliptra_buffer read_file_or_die(const char *path)
{
// Open File in Read Only Mode
Expand Down Expand Up @@ -60,11 +52,6 @@ static void display_usage(void)

int main(int argc, char *argv[])
{
for (int i = 0; i < 256; i++)
{
CFI_STATE_ORG[i] = 0;
}

// Process Input Arguments
int opt;
const char *rom_path = NULL;
Expand Down
12 changes: 12 additions & 0 deletions hw-model/c-binding/src/caliptra_model.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
// Licensed under the Apache-2.0 license

use caliptra_api::soc_mgr::SocManager;
use caliptra_cfi_lib::CfiState;
use caliptra_emu_bus::Bus;
use caliptra_hw_model::{DefaultHwModel, HwModel, InitParams, SecurityState};
use std::ffi::*;
use std::slice;

use caliptra_emu_types::RvSize;

// These are needed if CFI is enabled.
#[no_mangle]
pub extern "C" fn cfi_panic_handler(code: u32) -> ! {
std::process::exit(code as i32);
}

#[allow(unused)]
#[no_mangle]
static mut CFI_STATE_ORG: [u8; std::mem::size_of::<CfiState>()] =
[0; std::mem::size_of::<CfiState>()];

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct caliptra_model {
Expand Down
5 changes: 0 additions & 5 deletions libcaliptra/examples/hwmodel/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ struct caliptra_model *model = NULL;

static struct caliptra_model_init_params init_params;

// These are needed if CFI is enabled.
void cfi_panic_handler(void) {}

uint8_t CFI_STATE_ORG[256] = {0}; // leave some extra room

// ONLY for testing. Not part of actual libcaliptra interface
void testbench_reinit(void)
{
Expand Down
9 changes: 0 additions & 9 deletions test/dpe_verification/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ static int set_fuses()
}
return status;
}
// This is needed if CFI is enabled.
__attribute__((aligned(4))) uint8_t CFI_STATE_ORG[256] = {0}; // leave some extra room
*/
import "C"

Expand All @@ -68,12 +65,6 @@ type CptraModel struct {
// APIs need to be callable from C
var CALIPTRA_C_MODEL *C.struct_caliptra_model

// This is needed if CFI is enabled.
//export cfi_panic_handler
func cfi_panic_handler() {
os.Exit(-1)
}

//export caliptra_write_u32
func caliptra_write_u32(address C.uint32_t, data C.uint32_t) C.int {
result := C.caliptra_model_apb_write_u32(CALIPTRA_C_MODEL, address, data)
Expand Down

0 comments on commit 96825fa

Please sign in to comment.