From 65b914d22b24ca2039efb59f7bcd8595862f3396 Mon Sep 17 00:00:00 2001 From: Zach Halvorsen Date: Fri, 14 Jun 2024 23:13:48 +0000 Subject: [PATCH] Make caliptra-coverage optional for the emulated hw-model. This adds a new default feature flag for the hw-model. caliptra-coverage depends on caliptra-builder which uses cargo directly. This can make using the hw-model easier for build environments that may not have cargo accessible. --- hw-model/Cargo.toml | 5 +++-- hw-model/src/model_emulated.rs | 15 +++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hw-model/Cargo.toml b/hw-model/Cargo.toml index 9af494aae8..2a0f2df48d 100644 --- a/hw-model/Cargo.toml +++ b/hw-model/Cargo.toml @@ -8,10 +8,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = [] +default = ["coverage"] verilator = ["dep:caliptra-verilated"] fpga_realtime = ["dep:uio"] itrng = ["caliptra-verilated?/itrng"] +coverage = ["dep:caliptra-coverage"] [dependencies] bitfield.workspace = true @@ -31,7 +32,7 @@ ureg.workspace = true zerocopy.workspace = true nix.workspace = true libc.workspace = true -caliptra-coverage.workspace = true +caliptra-coverage = { workspace = true, optional = true } caliptra-image-types.workspace = true [dev-dependencies] diff --git a/hw-model/src/model_emulated.rs b/hw-model/src/model_emulated.rs index 762116f745..3f535a46cc 100644 --- a/hw-model/src/model_emulated.rs +++ b/hw-model/src/model_emulated.rs @@ -9,7 +9,9 @@ use std::path::PathBuf; use std::rc::Rc; use caliptra_emu_bus::Clock; -use caliptra_emu_cpu::{CoverageBitmaps, Cpu, InstrTracer}; +#[cfg(feature = "coverage")] +use caliptra_emu_cpu::CoverageBitmaps; +use caliptra_emu_cpu::{Cpu, InstrTracer}; use caliptra_emu_periph::ActionCb; use caliptra_emu_periph::ReadyForFwCb; use caliptra_emu_periph::{CaliptraRootBus, CaliptraRootBusArgs, SocToCaliptraBus, TbServicesCb}; @@ -58,10 +60,14 @@ pub struct ModelEmulated { cpu_enabled: Rc>, trace_path: Option, - rom_image_tag: u64, + // Keep this even when not including the coverage feature to keep the + // interface consistent + _rom_image_tag: u64, iccm_image_tag: Option, trng_mode: TrngMode, } + +#[cfg(feature = "coverage")] impl Drop for ModelEmulated { fn drop(&mut self) { let cov_path = @@ -73,7 +79,7 @@ impl Drop for ModelEmulated { let CoverageBitmaps { rom, iccm } = self.code_coverage_bitmap(); let _ = caliptra_coverage::dump_emu_coverage_to_file( cov_path.as_str(), - self.rom_image_tag, + self._rom_image_tag, rom, ); @@ -87,6 +93,7 @@ impl Drop for ModelEmulated { } } +#[cfg(feature = "coverage")] impl ModelEmulated { pub fn code_coverage_bitmap(&self) -> CoverageBitmaps { self.cpu.code_coverage.code_coverage_bitmap() @@ -173,7 +180,7 @@ impl crate::HwModel for ModelEmulated { ready_for_fw, cpu_enabled, trace_path: trace_path_or_env(params.trace_path), - rom_image_tag: image_tag, + _rom_image_tag: image_tag, iccm_image_tag: None, trng_mode, };