Skip to content

Commit 71a1fc6

Browse files
committed
[syn] Add keep_hierarchy constraints to prim_generic
Some FI countermeasures in Ibex use redundancy to detect fault attacks (e.g., the onehot encoding & checker in the RF). As synthesis tools are great in detecting redundant logic and reducing it, this commit puts a keep_hierarchy synthesis constraint on prim_generic* modules. This is exactely the purpose of the prim_generic_buf, prim_generic_flop, and prim_generic_and2 modules - having synthesis barriers to avoid optimizations. Signed-off-by: Pascal Nasahl <nasahlpa@lowrisc.org>
1 parent a92221a commit 71a1fc6

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

syn/tcl/yosys_run_synth.tcl

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,23 @@ if { $lr_synth_ibex_writeback_stage } {
2424
yosys "chparam -set WritebackStage 1 $lr_synth_top_module"
2525
}
2626

27-
if { $lr_synth_ibex_secure_ibex } {
28-
yosys "chparam -set SecureIbex 1 $lr_synth_top_module"
29-
}
30-
3127
yosys "chparam -set RV32B $lr_synth_ibex_bitmanip $lr_synth_top_module"
3228

3329
yosys "chparam -set RV32M $lr_synth_ibex_multiplier $lr_synth_top_module"
3430

3531
yosys "chparam -set RegFile $lr_synth_ibex_regfile $lr_synth_top_module"
3632

33+
if { $lr_synth_ibex_secure_ibex } {
34+
yosys "chparam -set SecureIbex 1 $lr_synth_top_module"
35+
# Place keep_hierarchy contraints on relevant modules to prevent aggressive
36+
# synthesis optimzations across the boundaries of these modules.
37+
yosys "hierarchy -check -top $lr_synth_top_module"
38+
yosys "setattr -mod -set keep_hierarchy 1 *prim_generic_and2*"
39+
yosys "setattr -mod -set keep_hierarchy 1 *prim_generic_buf*"
40+
yosys "setattr -mod -set keep_hierarchy 1 *prim_generic_clock_mux2*"
41+
yosys "setattr -mod -set keep_hierarchy 1 *prim_generic_flop*"
42+
}
43+
3744
yosys "synth $flatten_opt -top $lr_synth_top_module"
3845
yosys "opt -purge"
3946

@@ -53,6 +60,20 @@ if { $lr_synth_timing_run } {
5360
yosys "abc -liberty $lr_synth_cell_library_path"
5461
}
5562

63+
if { $lr_synth_ibex_secure_ibex } {
64+
# Remove keep_hierarchy constraints before the final flattening step.
65+
# We're done optimizing.
66+
yosys "setattr -mod -set keep_hierarchy 0 *prim_generic_and2*"
67+
yosys "setattr -mod -set keep_hierarchy 0 *prim_generic_buf*"
68+
yosys "setattr -mod -set keep_hierarchy 0 *prim_generic_clock_mux2*"
69+
yosys "setattr -mod -set keep_hierarchy 0 *prim_generic_flop*"
70+
}
71+
72+
# Final flattening.
73+
if { $lr_synth_flatten } {
74+
yosys "flatten"
75+
}
76+
5677
yosys "clean"
5778
yosys "write_verilog $lr_synth_netlist_out"
5879

0 commit comments

Comments
 (0)