|
| 1 | +# Copyright lowRISC contributors (OpenTitan project). |
| 2 | +# Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +load("//rules:const.bzl", "CONST", "hex", "hex_digits") |
| 6 | +load("//rules:cross_platform.bzl", "dual_cc_library", "dual_inputs") |
| 7 | +load("//rules:linker.bzl", "ld_library") |
| 8 | +load("//rules:manifest.bzl", "manifest") |
| 9 | +load("//rules/opentitan:defs.bzl", "fpga_params", "opentitan_binary", "opentitan_test") |
| 10 | +load( |
| 11 | + "//sw/device/silicon_creator/rom_ext:defs.bzl", |
| 12 | + "ROM_EXT_VARIATIONS", |
| 13 | + "ROM_EXT_VERSION", |
| 14 | + "SLOTS", |
| 15 | +) |
| 16 | + |
| 17 | +package(default_visibility = ["//visibility:public"]) |
| 18 | + |
| 19 | +manifest(d = { |
| 20 | + "name": "manifest0", |
| 21 | + "identifier": hex(CONST.ROM_EXT), |
| 22 | + "visibility": ["//visibility:public"], |
| 23 | + "version_major": "0", |
| 24 | + "version_minor": "0", |
| 25 | + "security_version": "0", |
| 26 | + "secver_write": "false", |
| 27 | +}) |
| 28 | + |
| 29 | +manifest(d = { |
| 30 | + "name": "manifest1", |
| 31 | + "identifier": hex(CONST.ROM_EXT), |
| 32 | + "visibility": ["//visibility:public"], |
| 33 | + "version_major": "0", |
| 34 | + "version_minor": "1", |
| 35 | + "security_version": "1", |
| 36 | + "secver_write": "true", |
| 37 | +}) |
| 38 | + |
| 39 | +manifest(d = { |
| 40 | + "name": "manifest2", |
| 41 | + "identifier": hex(CONST.ROM_EXT), |
| 42 | + "visibility": ["//visibility:public"], |
| 43 | + "version_major": "0", |
| 44 | + "version_minor": "2", |
| 45 | + "security_version": "2", |
| 46 | + "secver_write": "false", |
| 47 | +}) |
| 48 | + |
| 49 | +manifest(d = { |
| 50 | + "name": "manifest3", |
| 51 | + "identifier": hex(CONST.ROM_EXT), |
| 52 | + "visibility": ["//visibility:public"], |
| 53 | + "version_major": "0", |
| 54 | + "version_minor": "3", |
| 55 | + "security_version": "3", |
| 56 | + "secver_write": "true", |
| 57 | +}) |
| 58 | + |
| 59 | +_TEST_ROM_EXTS = { |
| 60 | + "0": { |
| 61 | + "manifest": ":manifest0", |
| 62 | + }, |
| 63 | + "1": { |
| 64 | + "manifest": ":manifest1", |
| 65 | + }, |
| 66 | + "2": { |
| 67 | + "manifest": ":manifest2", |
| 68 | + }, |
| 69 | + "3": { |
| 70 | + "manifest": ":manifest3", |
| 71 | + }, |
| 72 | +} |
| 73 | + |
| 74 | +[ |
| 75 | + opentitan_binary( |
| 76 | + name = "rom_ext_{}".format(name), |
| 77 | + testonly = True, |
| 78 | + ecdsa_key = {"//sw/device/silicon_creator/rom/keys/fake/ecdsa:prod_key_0_ecdsa_p256": "prod_key_0"}, |
| 79 | + exec_env = [ |
| 80 | + "//hw/top_earlgrey:fpga_cw310", |
| 81 | + "//hw/top_earlgrey:fpga_cw340", |
| 82 | + ], |
| 83 | + linker_script = "//sw/device/silicon_creator/rom_ext:ld_slot_virtual", |
| 84 | + manifest = param["manifest"], |
| 85 | + spx_key = {"//sw/device/silicon_creator/rom/keys/fake/spx:prod_key_0_spx": "prod_key_0"}, |
| 86 | + transitive_features = [ |
| 87 | + "minsize", |
| 88 | + "use_lld", |
| 89 | + ], |
| 90 | + deps = [ |
| 91 | + "//sw/device/lib/crt", |
| 92 | + "//sw/device/silicon_creator/lib:manifest_def", |
| 93 | + "//sw/device/silicon_creator/lib/ownership:test_owner", |
| 94 | + "//sw/device/silicon_creator/lib/ownership/keys/fake", |
| 95 | + "//sw/device/silicon_creator/lib/rescue:rescue_xmodem", |
| 96 | + "//sw/device/silicon_creator/rom_ext:rom_ext_dice_x509", |
| 97 | + "//sw/device/silicon_creator/rom_ext/imm_section:main_section_dice_x509_slot_virtual", |
| 98 | + ], |
| 99 | + ) |
| 100 | + for name, param in _TEST_ROM_EXTS.items() |
| 101 | +] |
| 102 | + |
| 103 | +opentitan_test( |
| 104 | + name = "secver_write_test", |
| 105 | + exec_env = { |
| 106 | + "//hw/top_earlgrey:fpga_cw310_rom_ext": None, |
| 107 | + "//hw/top_earlgrey:fpga_cw340_rom_ext": None, |
| 108 | + }, |
| 109 | + fpga = fpga_params( |
| 110 | + assemble = "{rom_ext}@0 {boot_test}@0x10000", |
| 111 | + binaries = { |
| 112 | + ":boot_test": "boot_test", |
| 113 | + ":rom_ext_1": "rom_ext1", |
| 114 | + ":rom_ext_2": "rom_ext2", |
| 115 | + ":rom_ext_3": "rom_ext3", |
| 116 | + }, |
| 117 | + changes_otp = True, |
| 118 | + exit_success = "BFV:{}".format(hex_digits(CONST.BFV.BOOT_POLICY.ROLLBACK)), |
| 119 | + rom_ext = ":rom_ext_0", |
| 120 | + test_cmd = """ |
| 121 | + # First, assemble the additional images we'll need for this test. |
| 122 | + --exec="image assemble -s 131072 --mirror=false -o fw1.bin {rom_ext1}@0 {boot_test}@0x10000" |
| 123 | + --exec="image assemble -s 131072 --mirror=false -o fw2.bin {rom_ext2}@0 {boot_test}@0x10000" |
| 124 | + --exec="image assemble -s 131072 --mirror=false -o fw3.bin {rom_ext3}@0 {boot_test}@0x10000" |
| 125 | + --exec="transport init" |
| 126 | + --exec="fpga clear-bitstream" |
| 127 | + --exec="fpga load-bitstream {bitstream}" |
| 128 | +
|
| 129 | + # Bootstrap the initial version 0 into SlotA |
| 130 | + --exec="bootstrap --clear-uart=true {firmware}" |
| 131 | + --exec="console --non-interactive --exit-success='rom_ext_min_sec_ver = 0'" |
| 132 | +
|
| 133 | + # Rescue and update to SlotB. We expect to update the secver. |
| 134 | + --exec="rescue firmware --raw --slot=SlotB fw1.bin" |
| 135 | + --exec="console --non-interactive --exit-success='rom_ext_min_sec_ver = 1'" |
| 136 | +
|
| 137 | + # Rescue and update to SlotA. We expect NOT to update the secver. |
| 138 | + --exec="rescue firmware --raw --slot=SlotA fw2.bin" |
| 139 | + --exec="console --non-interactive --exit-success='rom_ext_min_sec_ver = 1'" |
| 140 | +
|
| 141 | + # Rescue and update to SlotB. We expect to update the secver. |
| 142 | + --exec="rescue firmware --raw --slot=SlotB fw3.bin" |
| 143 | + --exec="console --non-interactive --exit-success='rom_ext_min_sec_ver = 3'" |
| 144 | +
|
| 145 | + # Finally, bootstrap back to version 0, which we expect NOT to work. |
| 146 | + --exec="bootstrap --clear-uart=true {firmware}" |
| 147 | + --exec="console --non-interactive --exit-success='{exit_success}' --timeout=10s" |
| 148 | + no-op |
| 149 | + """, |
| 150 | + ), |
| 151 | +) |
| 152 | + |
| 153 | +opentitan_binary( |
| 154 | + name = "boot_test", |
| 155 | + testonly = True, |
| 156 | + srcs = ["//sw/device/silicon_creator/rom_ext/e2e/verified_boot:boot_test"], |
| 157 | + exec_env = { |
| 158 | + "//hw/top_earlgrey:fpga_cw310_rom_ext": None, |
| 159 | + "//hw/top_earlgrey:fpga_cw340_rom_ext": None, |
| 160 | + }, |
| 161 | + deps = [ |
| 162 | + "//sw/device/lib/base:status", |
| 163 | + "//sw/device/lib/testing/test_framework:ottf_main", |
| 164 | + "//sw/device/silicon_creator/lib:boot_log", |
| 165 | + "//sw/device/silicon_creator/lib/drivers:retention_sram", |
| 166 | + ], |
| 167 | +) |
0 commit comments