Michael Schaffner | 41fdc8d | 2021-01-28 17:03:15 -0800 | [diff] [blame] | 1 | # Design-related Tooling Scripts |
| 2 | |
| 3 | ## Life Cycle and OTP Tools |
| 4 | |
| 5 | ### OTP Memory Map Translation Script |
| 6 | |
| 7 | The `gen-otp-mmap.py` script is used to translate the OTP memory map definition Hjson file into documentation and SV package collateral. |
| 8 | The memory map definition file for top_earlgrey is currently located at `hw/ip/otp_ctrl/data/otp_ctrl_mmap.hjson`. |
| 9 | |
| 10 | The script can either be invoked via the makefile |
| 11 | ```console |
| 12 | $ cd ${PROJ_ROOT} |
| 13 | $ make -C hw otp-mmap |
| 14 | |
| 15 | ``` |
| 16 | |
| 17 | or directly using the command |
| 18 | |
| 19 | ```console |
| 20 | $ cd ${PROJ_ROOT} |
| 21 | $ ./util/design/gen-otp-mmap.py |
| 22 | ``` |
| 23 | |
| 24 | The seed value used for generating OTP-related random netlist constants can optionally be overridden with the `--seed` switch when calling the script directly. |
| 25 | Otherwise 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 | |
| 29 | The `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. |
| 30 | The life cycle definition file for top_earlgrey is currently located at `hw/ip/lc_ctrl/data/lc_ctrl_state.hjson`. |
| 31 | |
| 32 | The script can either be invoked via the makefile |
| 33 | ```console |
| 34 | $ cd ${PROJ_ROOT} |
| 35 | $ make -C hw lc-state-enc |
| 36 | |
| 37 | ``` |
| 38 | |
| 39 | or directly using the command |
| 40 | |
| 41 | ```console |
| 42 | $ cd ${PROJ_ROOT} |
| 43 | $ ./util/design/gen-lc-state-enc.py |
| 44 | ``` |
| 45 | |
| 46 | The 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. |
| 47 | Otherwise 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 | |
| 51 | The 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. |
| 52 | The generated hexfile is compatible with the Verilog `$readmemh` command. |
| 53 | |
| 54 | The 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. |
| 55 | Further, since the life cycle state is stored in OTP, the image generator script also supports generating the correct life cycle state encodings. |
| 56 | To 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 | |
| 58 | The 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 | |
| 102 | Common 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 | |
| 104 | Note 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 | |
| 106 | The 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 | |
| 113 | Additional configuration files can be added using the `--add-cfg` switch. |
| 114 | The switch can be specified multiple times, and the configuration files are processed in the order they are specified. |
| 115 | This allows to incrementally "patch in" additional data, if needed. |
| 116 | |
| 117 | For 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 | |
| 152 | The 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 | |
| 162 | TODO |
| 163 | |
| 164 | ## LFSR Coefficient Generator Tool |
| 165 | |
| 166 | TODO |
| 167 | |
| 168 | ## LFSR Seed Generator Tool |
| 169 | |
| 170 | TODO |
| 171 | |
| 172 | ## Sparse FSM State Encoding Tool |
| 173 | |
| 174 | TODO |
| 175 | |
| 176 | ## KECCAK Coefficient Generation Tool |
| 177 | |
| 178 | TODO |
| 179 | |