Skip to content

Commit

Permalink
Make caliptra-coverage optional for the emulated hw-model.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zhalvorsen authored and jhand2 committed Jun 18, 2024
1 parent 15361ef commit 65b914d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions hw-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
15 changes: 11 additions & 4 deletions hw-model/src/model_emulated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -58,10 +60,14 @@ pub struct ModelEmulated {
cpu_enabled: Rc<Cell<bool>>,
trace_path: Option<PathBuf>,

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<u64>,
trng_mode: TrngMode,
}

#[cfg(feature = "coverage")]
impl Drop for ModelEmulated {
fn drop(&mut self) {
let cov_path =
Expand All @@ -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,
);

Expand All @@ -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()
Expand Down Expand Up @@ -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,
};
Expand Down

0 comments on commit 65b914d

Please sign in to comment.