Skip to content

Commit 4fbccfe

Browse files
[hw] Integrate KMAC and enabled ROM scrambling
Integrate KMAC hardware block for use with the ROM checker only. No other KMAC interfaces are connected. Modify the SW build system to generate a scrambled boot-ROM image. Attempting to run an un-scrambled image will be blocked by the in-hardware ROM checker. Add minimal HJSON files required for ROM image scrambling script. These use the OT testing secrets for now.
1 parent 67746ee commit 4fbccfe

14 files changed

Lines changed: 260 additions & 67 deletions

doc/ref/dev_guide.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ cmake --build build/sw -j $(nproc)
116116

117117
Outputs with the suffix "_sram" exist only for UVM-based tests, as they presently lack a DRAM backdoor-load mechanism.
118118

119+
The boot-ROM output with the "_scrambled" suffix is the only binary run through the ROM image scrambling script.
120+
Attempting to run any unscrambled binary from the scrambled ROM will be blocked by the in-hardware ROM checker.
121+
119122
### Code Quality
120123

121124
For software written in C, `clang-format` and `clang-tidy` are used to format and lint the code.
@@ -138,7 +141,7 @@ To build and run a Verilator simulation of Mocha, run:
138141
# Build simulator.
139142
fusesoc --cores-root=. run --target=sim --tool=verilator --setup --build lowrisc:mocha:top_chip_verilator --verilator_options="-j 4 --threads 2 --trace-threads 2" --make_options="-j 4"
140143
# Run simulator.
141-
build/lowrisc_mocha_top_chip_verilator_0/sim-verilator/Vtop_chip_verilator -E build/sw/device/bootrom/bootrom -E build/sw/device/examples/hello_world
144+
build/lowrisc_mocha_top_chip_verilator_0/sim-verilator/Vtop_chip_verilator -r build/sw/device/bootrom/bootrom_scrambled.vmem -E build/sw/device/examples/hello_world
142145
```
143146

144147
Note that the `-j 4` arguments speed up simulator building, while the `--threads 2 --trace-threads 2` arguments speed up simulator running.
@@ -173,7 +176,7 @@ usermod -a -G plugdev $USER
173176

174177
To build a bitstream with the boot-ROM, make sure that Vivado is on your path, then run:
175178
```sh
176-
fusesoc --cores-root=. run --target=synth --setup --build lowrisc:mocha:chip_mocha_genesys2 --RomInitFile=$PWD/build/sw/device/bootrom/bootrom.vmem
179+
fusesoc --cores-root=. run --target=synth --setup --build lowrisc:mocha:chip_mocha_genesys2 --RomInitFile=$PWD/build/sw/device/bootrom/bootrom_scrambled.vmem
177180
# Nix alternative: `nix run .#bitstream-build`
178181
```
179182

hw/data/secrets.testing.hjson

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright lowRISC contributors (COSMIC Project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Minimal hand-crafted secrets config HJSON file for scrambled ROM generation.
6+
//
7+
// CRITICAL: CHANGE THE SECRET VALUES BELOW BEFORE ANY REAL-WORLD DEPLOYMENT!
8+
//
9+
{
10+
module:
11+
[
12+
{
13+
name: rom_ctrl
14+
type: rom_ctrl
15+
base_addrs:
16+
{
17+
rom:
18+
{
19+
hart: 0x00080000
20+
}
21+
}
22+
memory:
23+
{
24+
rom:
25+
{
26+
size: 0x8000
27+
}
28+
}
29+
param_list:
30+
[
31+
{
32+
name: RndCnstScrNonce
33+
desc: Fixed nonce used for address / data scrambling
34+
type: bit [63:0]
35+
randcount: 64
36+
randtype: data
37+
name_top: RndCnstRomCtrlScrNonce
38+
default: 0xd35500e5a51bba34
39+
randwidth: 64
40+
}
41+
{
42+
name: RndCnstScrKey
43+
desc: Randomised constant used as a scrambling key for ROM data
44+
type: bit [127:0]
45+
randcount: 128
46+
randtype: data
47+
name_top: RndCnstRomCtrlScrKey
48+
default: 0xa71d81e9eb876b6f1996b2be4b58dfcf
49+
randwidth: 128
50+
}
51+
]
52+
}
53+
]
54+
}

hw/data/top.hjson

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright lowRISC contributors (COSMIC Project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Minimal hand-crafted top config HJSON file for scrambled ROM generation.
6+
//
7+
{
8+
name: mocha
9+
type: top
10+
module:
11+
[
12+
{
13+
name: rom_ctrl
14+
type: rom_ctrl
15+
param_decl:
16+
{
17+
SecDisableScrambling: 1'b0
18+
}
19+
param_list:
20+
[
21+
{
22+
name: SecDisableScrambling
23+
type: bit
24+
}
25+
]
26+
}
27+
]
28+
}

hw/top_chip/dv/tb/chip_hier_macros.svh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
`define CPU_HIER `SYSTEM_HIER.i_cva6
88
`define SRAM_MEM_HIER `SYSTEM_HIER.u_axi_sram.u_ram.mem
99
`define TAG_MEM_HIER `SYSTEM_HIER.u_axi_sram.u_tag_ram.mem
10-
`define ROM_MEM_HIER `SYSTEM_HIER.u_rom_ctrl.gen_rom_scramble_disabled.u_rom.u_prim_rom.mem
10+
`define ROM_MEM_HIER `SYSTEM_HIER.u_rom_ctrl.gen_rom_scramble_enabled.u_rom.u_rom.u_prim_rom.mem
1111

1212
// Testbench related
1313
`define SIM_SRAM_IF u_sim_sram.u_sim_sram_if

0 commit comments

Comments
 (0)