Skip to content

Commit b92d174

Browse files
committed
[SW]: add ZOIX fault simulation environment and scripts
1 parent 62a2f3a commit b92d174

5 files changed

Lines changed: 266 additions & 0 deletions

File tree

target/zoix/elaborate_rtl.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# #!/usr/bin/env bash
2+
# Copyright 2022 ETH Zurich and University of Bologna.
3+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Cyril Koenig <cykoenig@iis.ee.ethz.ch>
7+
8+
TESTBENCH=tb_cheshire_soc
9+
DUT_PATH="${TESTBENCH}.fix.dut.i_core_cva6.gen_cva6_core[0].i_cva6"
10+
11+
VCS_BIN="vcs"
12+
13+
# Set full path to c++ compiler.
14+
if [ -z "${CXX_PATH}" ]; then
15+
if [ -z "${CXX}" ]; then
16+
CXX="g++"
17+
fi
18+
CXX_PATH=`which ${CXX}`
19+
fi
20+
21+
# Set default VCS binary
22+
#[[ -z "${VERDI_VERSION}" ]] && VERDI_VERSION=""
23+
flags="+warn=noRT-NCMUCS +warn=noRT-MTOCMUCS "
24+
#Set VCS compile args
25+
flags+="-O2 "
26+
flags+="-kdb -lca -sverilog -full64 -j8 -override_timescale=1ns/10ps "
27+
flags+="+lint=TFIPC-L +lint=PCWM +warn=noCWUC +warn=noUII-L -l compile.log "
28+
flags+="+vcs+fsdbon -debug_access+all "
29+
#Set ZOIX compile args
30+
flags+="+notimingchecks "
31+
flags+="-debug_access+class -debug_access+pp -xlrm nettype_array -debug_region=lib+cell -force_list -debug_access+cbkd -debug_access+fwn "
32+
flags+="-fsim "
33+
#flags+="-fsim=dut:${TESTBENCH}.fix.dut.i_core_cva6 "
34+
flags+="-fsim=dut:${DUT_PATH} "
35+
flags+="-fsim=portfaults -fsim=class "
36+
37+
flags+="-cpp ${CXX_PATH} "
38+
[[ -n "${SELCFG}" ]] && flags+="-pvalue+SelectedCfg=${SELCFG} "
39+
40+
${VCS_BIN} ${flags} ../elfloader.cpp ${TESTBENCH}

target/zoix/fault.sff

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2025 ETH Zurich and University of Bologna.
2+
# Proprietary, not for release
3+
4+
FaultGenerate
5+
{
6+
# Set timing for frequency of transient fault insertion
7+
Timing("cycle1", CycleTime 5ns, Offset 1ns)
8+
UseTiming("cycle1")
9+
10+
# Create transient faults on all gate level flip-flops
11+
12+
#faults
13+
}

target/zoix/fcm.tcl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2025 ETH Zurich and University of Bologna.
2+
# Proprietary, not for release
3+
4+
set faultsim_tb $::env(FAULTSIM_TB)
5+
set num_fault_sim $::env(NUM_FAULT_SIM)
6+
set bootmode $::env(BOOTMODE)
7+
set prelmode $::env(PRELMODE)
8+
set binary $::env(BINARY)
9+
10+
11+
# Configure grid -> To figure out with IT...
12+
set_config -global_max_jobs 12
13+
# set_submit_cmd -grid_type TODO
14+
# set_config -max_faults_per_fsim_task 50
15+
16+
# Create fault campaign (Build fault universe through VC FCC)
17+
create_campaign -localhost -args "-full64 -daidir simv.daidir -dut ${faultsim_tb}.fix.dut.i_core_cva6 -sff states.sff -sff ${faultsim_tb}.sff -campaign fc1 -sample num:${num_fault_sim} -overwrite"
18+
#create_campaign -localhost -args "-full64 -daidir $simv.daidir -sff states.sff -sff ${faultsim_tb}.sff -campaign fc1 -sample num:${num_fault_sim} -overwrite"
19+
# Create testcases
20+
create_testcases -name {test1} -exec simv -daidir simv.daidir -campaign fc1 -args "-no_save +BOOTMODE=\"$bootmode\" +PRELMODE=\"$prelmode\" +BINARY=\"$binary\""
21+
22+
# dump -fids {1} -tc test1 -mode gmfm -fsdb gmfmdump.fsdb -args "+fsdb+all=on"
23+
# dump -fids {1} -tc test1 -mode fm -fsdb fmdump.fsdb -args "+fsdb+all=on"
24+
25+
set_config -fsdb_outdated_behavior 0
26+
27+
#fcm::show_faults
28+
29+
# Run fault simulation campaign
30+
fsim -fsim_args "-no_save" -localhost -selected_status {NA}
31+
32+
set output [string trim [show_fault_results -status {"HA"}]]
33+
34+
if {$output ne "No fault results found."} {
35+
set_config -fsim_mode serial
36+
fsim -fsim_args "-no_save" -localhost -selected_status {HA}
37+
}
38+
39+
# Reporting after fault simulation
40+
report -campaign fc1
41+
42+
# Dump waves for all failing testcases
43+
set failing_cases {}
44+
#lappend failing_cases [show_fault_results -status {FE}]
45+
46+
# Initialize list of FIDs
47+
set fid_list {}
48+
49+
# Process output line by line
50+
foreach state $failing_cases {
51+
foreach line [split $state "\n"] {
52+
# Trim leading/trailing spaces
53+
set line [string trim $line]
54+
55+
# Skip header or empty lines
56+
if {[regexp {^#} $line] || $line eq "" || [regexp {^\-} $line]} {
57+
continue
58+
}
59+
60+
# Check if the line starts with a number (FID)
61+
if {[regexp {^([0-9]+)} $line match fid]} {
62+
# Save the FID
63+
lappend fid_list $fid
64+
}
65+
}
66+
}
67+
68+
#dump -fids $fid_list -tc test1 -mode gmfm -fsdb gmfmdump_all.fsdb -args "+fsdb+all=on"
69+
#dump -fids $fid_list -tc test1 -mode fm -fsdb fmdump_all.fsdb -args "+fsdb+all=on"

target/zoix/states.sff

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2025 ETH Zurich and University of Bologna.
2+
# Proprietary, not for release
3+
4+
5+
# Set the Status Definitions that will be used and reported from fault simulation
6+
StatusDefinitions
7+
{
8+
# Redefinition of some built-in status definitions
9+
10+
# Creation of new functional safety definitions
11+
OK "Masked";
12+
FE "Faulty Exception";
13+
FT "Faulty Timeout";
14+
FR "Faulty Return";
15+
CM "Catch HMR Main";
16+
CA "Catch HMR AMO";
17+
CF "Catch HMR Flush";
18+
CD "Catch HMR Data Cache Request";
19+
CI "Catch HMR Instruction Cache Request";
20+
CE "Catch HMR Faulty Exception";
21+
LS "Latent Error Scoreboard";
22+
LF "Latent Error Float Regfile";
23+
LR "Latent Error Integer Regfile";
24+
LI "Latent Error Instruction Cache";
25+
LD "Latent Error Data Cache";
26+
LC "Latent Error CSR";
27+
LM "Latent Error MMU";
28+
LB "Latent Error Branch Predictor";
29+
30+
# Any fault created and not set by a system task will have this status
31+
DefaultStatus (OK)
32+
33+
# Any fault of this status will be chosen by the simulation for injection
34+
Selected (NA)
35+
36+
# Define the merging of faults when multiple tests are run
37+
PromotionTable
38+
{
39+
StatusLabels (OK,FE,FT,FR ,CM, CA, CF, CD, CI , CE, LS, LF, LR, LI, LD, LC, LM, LB)
40+
# OK FE FT FR CM CA CF CD CI CE LS LF LR LI LD LC LM LB
41+
[ - | | | | | | | | | | | | | | | | | ; # OK
42+
- - | | | | | | | | | | | | | | | | ; # FE
43+
- - - | | | | | | | | | | | | | | | ; # FT
44+
- - - - | | | | | | | | | | | | | | ; # FR
45+
- - - - - | | | | | | | | | | | | | ; # CM
46+
- - - - - - | | | | | | | | | | | | ; # CA
47+
- - - - - - - | | | | | | | | | | | ; # CF
48+
- - - - - - - - | | | | | | | | | | ; # CD
49+
- - - - - - - - - | | | | | | | | | ; # CI
50+
- - - - - - - - - - | | | | | | | | ; # CE
51+
- - - - - - - - - - - | | | | | | | ; # LS
52+
- - - - - - - - - - - - | | | | | | ; # LF
53+
- - - - - - - - - - - - - | | | | | ; # LR
54+
- - - - - - - - - - - - - - | | | | ; # LI
55+
- - - - - - - - - - - - - - - | | | ; # LD
56+
- - - - - - - - - - - - - - - - | | ; # LC
57+
- - - - - - - - - - - - - - - - - | ; # LM
58+
- - - - - - - - - - - - - - - - - - ; # LB
59+
]
60+
}
61+
62+
StatusGroups
63+
{
64+
MA "Masked" (NO, OK, NI);
65+
PE "Program error" (FE, FT, FR);
66+
LE "Dangerous Unobserved" (LS, LF, LR, LI, LD, LC, LM, LB);
67+
CH "Error detected" (CM, CA, CF, CD, CI, CE);
68+
}
69+
}

target/zoix/zoix.mk

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
################################
2+
# ZOIX fault simulation #
3+
################################
4+
5+
BENDER ?= bender
6+
7+
VCS := vcs
8+
VLOGAN_ZOIX := vlogan
9+
VERDI := verdi
10+
FCM := vc_fcm
11+
12+
VERDI_PATH := $(shell dirname $(shell dirname $(shell which $(VERDI))))
13+
14+
ROOT_DIR := target/zoix
15+
BUILD_DIR := target/zoix/build
16+
NUM_FAULT_SIM := 100000
17+
FAULT_START_CYCLE := 453500
18+
FAULT_END_CYCLE := 1280000
19+
20+
FAULTSIM_TB := tb_cheshire_soc
21+
22+
ZOIX_BINARY=../../sw/tests/helloworld.spm.elf
23+
ZOIX_BOOTMODE=0
24+
ZOIX_PRELMODE=1
25+
#ZOIX_SELCFG=7
26+
27+
BENDER_ARGS += $(CHS_BENDER_RTL_FLAGS)
28+
BENDER_ARGS += -t vcs -t sim -t test -D SYNTHESIS -D SIMULATION -D SYNTHESIS -D SIMULATION -D VCS -t ZOIX -D VC_Z01X
29+
#BENDER_ARGS += -DREL_CORE
30+
VCS_SCRIPT_ARGS := -assert svaext +v2k -kdb -override_timescale=1ns/10ps -debug_access+all
31+
32+
ZOIX_SCRIPT_ARGS := -work work -nc -xlrm nettype_array -debug_access+class -debug_access+pp -debug_region=lib+cell -debug_access+fwn -debug_access+cbkd +incdir+$(CURDIR) +incdir+$(CURDIR)/target/zoix +incdir+$(CURDIR)/target/sim/src +incdir+$(CURDIR)/hw
33+
34+
$(BUILD_DIR)/compile_rtl.sh: $(CHS_ROOT)/Bender.lock $(CHS_ROOT)/Bender.yml
35+
mkdir -p $(BUILD_DIR)
36+
$(BENDER) script vcs $(BENDER_ARGS) --vlog-arg="$(VCS_SCRIPT_ARGS) $(ZOIX_SCRIPT_ARGS)" --vlogan-bin="$(VLOGAN_ZOIX)" > $@
37+
chmod +x $@
38+
39+
.PHONY: build-zoix
40+
build-zoix: $(BUILD_DIR)/simv
41+
$(BUILD_DIR)/simv: $(BUILD_DIR)/compile_rtl.sh
42+
cd $(BUILD_DIR); \
43+
export SELCFG=$(ZOIX_SELCFG); \
44+
export VERDI_HOME=$(VERDI_PATH); \
45+
./compile_rtl.sh; \
46+
../elaborate_rtl.sh;
47+
48+
.PHONY: simulate
49+
simulate: $(BUILD_DIR)/simv
50+
cd $(BUILD_DIR); \
51+
./simv +fsdb+all=on +BOOTMODE=${ZOIX_BOOTMODE} +PRELMODE=${ZOIX_PRELMODE} +BINARY=${ZOIX_BINARY} -l simulate.log
52+
53+
.PHONY: simulate-gui
54+
simulate-gui: $(BUILD_DIR)/simv
55+
cd $(BUILD_DIR); \
56+
./simv +fsdb+all=on +BOOTMODE=${ZOIX_BOOTMODE} +PRELMODE=${ZOIX_PRELMODE} +BINARY=${ZOIX_BINARY} -gui -l simulate.log
57+
58+
.PHONY: faultsim
59+
faultsim: $(BUILD_DIR)/fcm.dir
60+
$(BUILD_DIR)/fcm.dir: $(BUILD_DIR)/simv $(ROOT_DIR)/fcm.tcl $(ROOT_DIR)/states.sff tb_cheshire_soc.sff
61+
cp -f $(ROOT_DIR)/fcm.tcl $(BUILD_DIR)/
62+
cp -f $(ROOT_DIR)/states.sff $(BUILD_DIR)/
63+
cp -f $(ROOT_DIR)/tb_cheshire_soc.sff $(BUILD_DIR)/
64+
cd $(BUILD_DIR); export FAULTSIM_TB=$(FAULTSIM_TB); export NUM_FAULT_SIM=$(NUM_FAULT_SIM); export BINARY=$(ZOIX_BINARY); export BOOTMODE=$(ZOIX_BOOTMODE); export PRELMODE=$(ZOIX_PRELMODE); $(FCM) -connect -tcl_script fcm.tcl
65+
66+
.PHONY: clean-zoix
67+
clean-zoix:
68+
rm -rf $(BUILD_DIR)
69+
70+
tb_cheshire_soc.sff: $(ROOT_DIR)/tb_cheshire_soc.sff
71+
$(ROOT_DIR)/tb_cheshire_soc.sff: $(ROOT_DIR)/fault.sff $(ROOT_DIR)/zoix.mk
72+
@cp -f $< $@
73+
sed -i "s|#faults|NA ~ (\"cycle1\" $(FAULT_START_CYCLE):$(FAULT_END_CYCLE)) { FLOP \"tb_cheshire_soc.fix.dut.i_core_cva6.gen_cva6_core[0].**\" }\n #faults|" $@
74+
75+
# sed -i "s|#faults|NA ~ (\"cycle1\" $(FAULT_START_CYCLE):$(FAULT_END_CYCLE)) { FLOP \"tb_cheshire_soc.fix.dut.i_core_wrap.**\" }\n #faults|" $@

0 commit comments

Comments
 (0)