blob: 2f77e0603829e3249a2b2ceef9e6e82fd6bb5c61 [file] [log] [blame] [view]
Michael Schaffner41fdc8d2021-01-28 17:03:15 -08001# Design-related Tooling Scripts
2
3## Life Cycle and OTP Tools
4
5### OTP Memory Map Translation Script
6
7The `gen-otp-mmap.py` script is used to translate the OTP memory map definition Hjson file into documentation and SV package collateral.
8The memory map definition file for top_earlgrey is currently located at `hw/ip/otp_ctrl/data/otp_ctrl_mmap.hjson`.
9
10The script can either be invoked via the makefile
11```console
12$ cd ${PROJ_ROOT}
13$ make -C hw otp-mmap
14
15```
16
17or directly using the command
18
19```console
20$ cd ${PROJ_ROOT}
21$ ./util/design/gen-otp-mmap.py
22```
23
24The seed value used for generating OTP-related random netlist constants can optionally be overridden with the `--seed` switch when calling the script directly.
25Otherwise that seed value is taken from the Hjson file, or generated on-the-fly if the Hjson file does not contain a seed.
26
27### Life Cycle State Encoding Generator
28
29The `gen-lc-state-enc.py` script is used to generate the redundant life cycle state encoding and print the constants and type definitions into the life cycle state package.
30The life cycle definition file for top_earlgrey is currently located at `hw/ip/lc_ctrl/data/lc_ctrl_state.hjson`.
31
32The script can either be invoked via the makefile
33```console
34$ cd ${PROJ_ROOT}
35$ make -C hw lc-state-enc
36
37```
38
39or directly using the command
40
41```console
42$ cd ${PROJ_ROOT}
43$ ./util/design/gen-lc-state-enc.py
44```
45
46The seed value used for generating life-cycle-state-related random netlist constants can optionally be overridden with the `--seed` switch when calling the script directly.
47Otherwise that seed value is taken from the Hjson file, or generated on-the-fly if the Hjson file does not contain a seed.
48
49### OTP Preload Image Generator
50
51The OTP preload image generation tool builds on top of the memory map and life cycle state generation Python classes in order to transform a memory image configuration into a memory hexfile that can be used for OTP preloading in simulation and FPGA emulation runs.
52The generated hexfile is compatible with the Verilog `$readmemh` command.
53
54The OTP memory image configuration file is basically an Hjson file that lists the names and corresponding values of items defined in the OTP memory map definition.
55Further, since the life cycle state is stored in OTP, the image generator script also supports generating the correct life cycle state encodings.
56To that end, the desired life cycle state name can be declared in the image configuration file, and the generator script looks up and assigns the correct netlist constants.
57
58The following snippet shows a memory image configuration that puts the device into the `DEV` life cycle state, and that defines the SECRET2 partition items and locks down the partition:
59```
60{
61 // Seed to be used for generation of partition randomized values.
62 // Can be overridden on the command line.
63 seed: 01931961561863975174
64
65 // The partition and item names must correspond with the OTP memory map.
66 partitions: [
67 {
68 name: "SECRET2",
69 // If True, a digest will be calculated for this partition.
70 // Note that this only applies to partitions with a hardware digest.
71 lock: "True",
72 items: [
73 {
74 name: "RMA_TOKEN",
75 // This item is assigned is a fixed Hex value
76 value: "0x9cfbd7383959a62a4438bc468d76eed6 ",
77 }
78 {
79 name: "CREATOR_ROOT_KEY_SHARE0",
80 // This item will be assigned a random value, based on the seed above.
81 value: "<random>",
82 }
83 {
84 name: "CREATOR_ROOT_KEY_SHARE1",
85 // This item will be assigned a random value, based on the seed above.
86 value: "<random>",
87 }
88 ],
89 }
90 {
91 name: "LIFE_CYCLE",
92 // Can be one of the following strings:
93 // RAW, TEST_UNLOCKED0-3, TEST_LOCKED0-2, DEV, PROD, PROD_END, RMA, SCRAP
94 state: "DEV",
95 // Can be either "RAW", or any number from 1 to 16.
96 count: "5"
97 }
98 ]
99}
100```
101
102Common example configuration files that can be used for simulation and emulation are checked in under `hw/ip/otp_ctrl/data`, e.g. `hw/ip/otp_ctrl/data/otp_ctrl_img_dev.hjson` which provisions all buffered partitions and puts the device into the `DEV` life cycle.
103
104Note that the preload image generator script automatically scrambles secret partitions, computes digests of locked partitions using the PRESENT cipher, and computes the OTP ECC bits.
105
106The OTP preload image generator expects at least one main image configuration file to be specified with the `--img-cfg` switch, for example:
107```console
108$ cd ${PROJ_ROOT}
109$ ./util/design/gen-otp-img.py --img-cfg hw/ip/otp_ctrl/data/otp_ctrl_img_dev.hjson \
110 --out otp-img.mem
111```
112
113Additional configuration files can be added using the `--add-cfg` switch.
114The switch can be specified multiple times, and the configuration files are processed in the order they are specified.
115This allows to incrementally "patch in" additional data, if needed.
116
117For example, this can be used to patch in additional software configuration data, specified in an additional file `otp_ctrl_img_sw_cfg.hjson` that looks as follows (it is also possible to split the individual items into their own files):
118```
119{
120 // The partition and item names must correspond with the OTP memory map.
121 partitions: [
122 {
123 name: "CREATOR_SW_CFG",
124 items: [
125 {
126 name: "CREATOR_SW_CFG_CONTENT",
127 value: "0x0", // data to be put into this partition
128 }
129 {
130 name: "CREATOR_SW_CFG_DIGEST",
131 value: "0x0", // 64bit digest to be written to this partition
132 }
133 ],
134 },
135 {
136 name: "OWNER_SW_CFG",
137 items: [
138 {
139 name: "OWNER_SW_CFG_CONTENT",
140 value: "0x0", // data to be put into this partition
141 }
142 {
143 name: "OWNER_SW_CFG_DIGEST",
144 value: "0x0", // 64bit digest to be written to this partition
145 }
146 ],
147 }
148 ]
149}
150```
151
152The generator script call would then look as follows:
153```console
154$ cd ${PROJ_ROOT}
155$ ./util/design/gen-otp-img.py --img-cfg hw/ip/otp_ctrl/data/otp_ctrl_img_dev.hjson \
156 --add-cfg otp_ctrl_img_sw_cfg.hjson \
157 --out otp-img.mem
158```
159
160## ECC Generator Tool
161
162TODO
163
164## LFSR Coefficient Generator Tool
165
166TODO
167
168## LFSR Seed Generator Tool
169
170TODO
171
172## Sparse FSM State Encoding Tool
173
174TODO
175
176## KECCAK Coefficient Generation Tool
177
178TODO
179