Add lifecycle controller OT peripheral tests

- Generation of a supporting OTP image is done at test time
- Added otp_ctrl_img_smoketest.hjson for OTP image generation

Change-Id: Ifadba36b1c9b84bff0faf06a97ef4513c2fd75af
diff --git a/opentitan_peripherals_test.robot b/opentitan_peripherals_test.robot
index f52e22d..ba37edc 100644
--- a/opentitan_peripherals_test.robot
+++ b/opentitan_peripherals_test.robot
@@ -7,7 +7,8 @@
 
 *** Variables ***
 ${UART}                         sysbus.uart0
-${ROOTDIR}                      @${CURDIR}/../..
+${SHODAN_DIR}                   ${CURDIR}/../..
+${ROOTDIR}                      @${SHODAN_DIR}
 ${AES_BIN}                      ${ROOTDIR}/out/opentitan/sw/build-out/sw/device/tests/aes_smoketest_fpga_nexysvideo.elf
 ${UART_BIN}                     ${ROOTDIR}/out/opentitan/sw/build-out/sw/device/tests/uart_smoketest_fpga_nexysvideo.elf
 ${HMAC_BIN}                     ${ROOTDIR}/out/opentitan/sw/build-out/sw/device/tests/hmac_smoketest_fpga_nexysvideo.elf
@@ -21,6 +22,12 @@
 ${RESET_BIN}                    ${ROOTDIR}/out/opentitan/sw/build-out/sw/device/tests/rstmgr_smoketest_fpga_nexysvideo.elf
 ${SW_RESET_BIN}                 ${ROOTDIR}/out/opentitan/sw/build-out/sw/device/tests/rstmgr_sw_req_test_fpga_nexysvideo.elf
 ${HELLO_WORLD_BIN}              ${ROOTDIR}/out/opentitan/sw/build-out/sw/device/examples/hello_world/hello_world_fpga_nexysvideo.elf
+${OTP_VMEM}                     ${SHODAN_DIR}/out/tmp/otp_img_smoketest.vmem
+${LC_TRANSITION}                ${ROOTDIR}/out/opentitan/sw/build-out/sw/device/tests/lc_ctrl_transition_test_fpga_nexysvideo.elf
+${LC_OTP_CFG}                   ${ROOTDIR}/out/opentitan/sw/build-out/sw/device/tests/lc_ctrl_otp_hw_cfg_test_fpga_nexysvideo.elf
+
+${OTP_IMG_SCRIPT}               ${SHODAN_DIR}/hw/opentitan-upstream/util/design/gen-otp-img.py
+${OTP_IMG_CFG}                  ${SHODAN_DIR}/sim/tests/otp_ctrl_img_smoketest.hjson
 
 ${LEDS}=    SEPARATOR=
 ...  """                                     ${\n}
@@ -52,6 +59,9 @@
     Execute Command             machine LoadPlatformDescriptionFromString ${LEDS}
     Execute Command             sysbus LoadELF ${BOOT_ROM_BIN}
     Execute Command             sysbus LoadELF ${HELLO_WORLD_BIN}
+    Run Process                 mkdir   -p      ${SHODAN_DIR}/out/tmp
+    Run Process                 python3     ${OTP_IMG_SCRIPT}  --img-cfg   ${OTP_IMG_CFG}  --out   ${OTP_VMEM}
+    Execute Command             sysbus.otp_ctrl LoadVMem @${OTP_VMEM}
     Execute Command             sysbus.cpu0 PC 0x00008084
 
     Create Terminal Tester      ${UART}
@@ -173,6 +183,12 @@
 Should Pass Software Reset Test
     Run Smoketest               ${SW_RESET_BIN}
 
+Should Pass Life Cycle Transition Test
+    Run Smoketest               ${LC_TRANSITION}
+
+Should Pass Life Cycle Otp Config Test
+    Run Smoketest               ${LC_OTP_CFG}
+
 Should Pass AES Smoketest With Scrambled Boot ROM Vmem
     Run Smoketest With Scrambled Boot ROM Vmem      ${AES_BIN}
 
diff --git a/otp_ctrl_img_smoketest.hjson b/otp_ctrl_img_smoketest.hjson
new file mode 100644
index 0000000..60c44ec
--- /dev/null
+++ b/otp_ctrl_img_smoketest.hjson
@@ -0,0 +1,129 @@
+// Copyright lowRISC contributors.
+// Licensed under the Apache License, Version 2.0, see LICENSE for details.
+// SPDX-License-Identifier: Apache-2.0
+//
+// Use the gen-otp-img.py script to convert this configuration into
+// a hex file for preloading the OTP in FPGA synthesis or simulation.
+//
+
+{
+    // Seed to be used for generation of partition randomized values.
+    // Can be overridden on the command line with the --seed switch.
+    seed: 01931961561863975174
+
+    // The partition and item names must correspond with the OTP memory map.
+    partitions: [
+        {
+            name:  "CREATOR_SW_CFG",
+            items: [
+                {
+                    name:  "CREATOR_SW_CFG_DIGEST",
+                    value: "0x0",
+                },
+                {
+                    name: "CREATOR_SW_CFG_USE_SW_RSA_VERIFY",
+                    // Use software mod_exp implementation for signature
+                    // verification. See the definition of `hardened_bool_t` in
+                    // sw/device/lib/base/hardened.h.
+                    value: "0x739",
+                },
+                {
+                    name: "CREATOR_SW_CFG_KEY_IS_VALID",
+                    // Mark the first two keys as valid and remaining as
+                    // invalid since we have currently only two keys. See the
+                    // definition of `hardened_byte_bool_t` in
+                    // sw/device/lib/base/hardened.h.
+                    value: "0x4b4b4b4b4b4ba5a5",
+                }
+            ],
+        }
+        {
+            name:  "OWNER_SW_CFG",
+            items: [
+                {
+                    name:  "OWNER_SW_CFG_DIGEST",
+                    value: "0x0",
+                }
+            ],
+        }
+        {
+            name:  "HW_CFG",
+            // If set to true, this computes the HW digest value
+            // and locks the partition.
+            lock:  "True",
+            items: [
+                {
+                    name:  "DEVICE_ID",
+                    value: "0xBF5EA92044DAC540CFD1A00105568DFA97D9C35EA0407D71320B5E0434DB637F",
+                },
+                {
+                    name:  "EN_CSRNG_SW_APP_READ",
+                    value: "0xA5",
+                },
+                {
+                    name:  "EN_ENTROPY_SRC_FW_READ",
+                    value: "0xA5",
+                },
+            ],
+        }
+        {
+            name:  "SECRET0",
+            lock:  "True",
+            items: [
+                {
+                    name:  "TEST_UNLOCK_TOKEN",
+                    value: "0x79DEF38F41A9B895F6BDF341BEADA9B6",
+                }
+                {
+                    name:  "TEST_EXIT_TOKEN",
+                    value: "0x000102030405060708090A0B0C0D0E0F",
+                }
+            ],
+        }
+        {
+            name:  "SECRET1",
+            lock:  "True",
+            items: [
+                {
+                    name:  "FLASH_ADDR_KEY_SEED",
+                    value: "<random>",
+                }
+                {
+                    name:  "FLASH_DATA_KEY_SEED",
+                    value: "<random>",
+                }
+                {
+                    name:  "SRAM_DATA_KEY_SEED",
+                    value: "<random>",
+                }
+            ],
+        }
+        {
+            name:  "SECRET2",
+            lock:  "False",
+            items: [
+                {
+                    name:  "RMA_TOKEN",
+                    value: "0x4D89B62D287CB957C2500042306DFD57",
+                }
+                {
+                    name:  "CREATOR_ROOT_KEY_SHARE0",
+                    value: "<random>",
+                }
+                {
+                    name:  "CREATOR_ROOT_KEY_SHARE1",
+                    value: "<random>",
+                }
+            ],
+        }
+        {
+            name:  "LIFE_CYCLE",
+            // Can be one of the following strings:
+            // RAW, TEST_UNLOCKED0-3, TEST_LOCKED0-2, DEV, PROD, PROD_END, RMA, SCRAP
+            state: "TEST_UNLOCKED2",
+            // Can range from 0 to 16.
+            // Note that a value of 0 is only permissible in RAW state.
+            count: "7"
+        }
+    ]
+}