diff --git a/quality/BUILD.bazel b/quality/BUILD.bazel index ced3e05c7b1e0..21688a9bceb3f 100644 --- a/quality/BUILD.bazel +++ b/quality/BUILD.bazel @@ -173,19 +173,21 @@ RUST_TARGETS = [ "//sw/host/hsmtool:hsmlib", "//sw/host/hsmtool:hsmlib_test", "//sw/host/hsmtool/acorn:acorn", - "//sw/host/ot_certs:ot_certs", - "//sw/host/ot_certs:ot_certs_test", "//sw/host/opentitanlib:opentitanlib", "//sw/host/opentitanlib:opentitanlib_test", "//sw/host/opentitansession:opentitansession", "//sw/host/opentitantool:opentitantool", + "//sw/host/ot_certs:ot_certs", + "//sw/host/ot_certs:ot_certs_test", "//sw/host/tests/chip/gpio:gpio", "//sw/host/tests/chip/power_virus:power_virus", + "//sw/host/tests/chip/spi_device:spi_passthru", + "//sw/host/tests/ownership:transfer_lib", + "//sw/host/tests/ownership:transfer_test", "//sw/host/tests/rom/e2e_bootstrap_disabled:e2e_bootstrap_disabled", "//sw/host/tests/rom/e2e_bootstrap_entry:e2e_bootstrap_entry", "//sw/host/tests/rom/e2e_chip_specific_startup:e2e_chip_specific_startup", "//sw/host/tests/rom/sw_strap_value:sw_strap_value", - "//sw/host/tests/chip/spi_device:spi_passthru", "//sw/host/tests/xmodem:lrzsz_test", "//sw/host/tests/xmodem:xmodem", "//sw/host/sphincsplus:sphincsplus", diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/BUILD b/sw/device/silicon_creator/lib/ownership/keys/dummy/BUILD new file mode 100644 index 0000000000000..c143892271503 --- /dev/null +++ b/sw/device/silicon_creator/lib/ownership/keys/dummy/BUILD @@ -0,0 +1,30 @@ +# Copyright lowRISC contributors (OpenTitan project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "owner_key", + srcs = ["owner_ecdsa_p256.der"], +) + +filegroup( + name = "activate_key", + srcs = ["activate_ecdsa_p256.der"], +) + +filegroup( + name = "unlock_key", + srcs = ["unlock_ecdsa_p256.der"], +) + +filegroup( + name = "app_prod", + srcs = ["app_prod_rsa_3072_exp_f4.der"], +) + +filegroup( + name = "app_prod_pub", + srcs = ["app_prod_rsa_3072_exp_f4.pub.der"], +) diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/activate_ecdsa_p256.der b/sw/device/silicon_creator/lib/ownership/keys/dummy/activate_ecdsa_p256.der new file mode 100644 index 0000000000000..c0b4b4bd7472f Binary files /dev/null and b/sw/device/silicon_creator/lib/ownership/keys/dummy/activate_ecdsa_p256.der differ diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/activate_ecdsa_p256.pub.der b/sw/device/silicon_creator/lib/ownership/keys/dummy/activate_ecdsa_p256.pub.der new file mode 100644 index 0000000000000..02b30b3a5fa1e Binary files /dev/null and b/sw/device/silicon_creator/lib/ownership/keys/dummy/activate_ecdsa_p256.pub.der differ diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/app_prod_rsa_3072_exp_f4.der b/sw/device/silicon_creator/lib/ownership/keys/dummy/app_prod_rsa_3072_exp_f4.der new file mode 100644 index 0000000000000..a41d54d309f0f Binary files /dev/null and b/sw/device/silicon_creator/lib/ownership/keys/dummy/app_prod_rsa_3072_exp_f4.der differ diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/app_prod_rsa_3072_exp_f4.pub.der b/sw/device/silicon_creator/lib/ownership/keys/dummy/app_prod_rsa_3072_exp_f4.pub.der new file mode 100644 index 0000000000000..cfea71681c78e Binary files /dev/null and b/sw/device/silicon_creator/lib/ownership/keys/dummy/app_prod_rsa_3072_exp_f4.pub.der differ diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/owner_ecdsa_p256.der b/sw/device/silicon_creator/lib/ownership/keys/dummy/owner_ecdsa_p256.der new file mode 100644 index 0000000000000..8134d7740a927 Binary files /dev/null and b/sw/device/silicon_creator/lib/ownership/keys/dummy/owner_ecdsa_p256.der differ diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/owner_ecdsa_p256.pub.der b/sw/device/silicon_creator/lib/ownership/keys/dummy/owner_ecdsa_p256.pub.der new file mode 100644 index 0000000000000..a199a167415e8 Binary files /dev/null and b/sw/device/silicon_creator/lib/ownership/keys/dummy/owner_ecdsa_p256.pub.der differ diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/unlock_ecdsa_p256.der b/sw/device/silicon_creator/lib/ownership/keys/dummy/unlock_ecdsa_p256.der new file mode 100644 index 0000000000000..a52254cb97137 Binary files /dev/null and b/sw/device/silicon_creator/lib/ownership/keys/dummy/unlock_ecdsa_p256.der differ diff --git a/sw/device/silicon_creator/lib/ownership/keys/dummy/unlock_ecdsa_p256.pub.der b/sw/device/silicon_creator/lib/ownership/keys/dummy/unlock_ecdsa_p256.pub.der new file mode 100644 index 0000000000000..ad32bd0f6f790 Binary files /dev/null and b/sw/device/silicon_creator/lib/ownership/keys/dummy/unlock_ecdsa_p256.pub.der differ diff --git a/sw/device/silicon_creator/rom_ext/e2e/ownership/BUILD b/sw/device/silicon_creator/rom_ext/e2e/ownership/BUILD new file mode 100644 index 0000000000000..700054bac1a84 --- /dev/null +++ b/sw/device/silicon_creator/rom_ext/e2e/ownership/BUILD @@ -0,0 +1,51 @@ +# Copyright lowRISC contributors (OpenTitan project). +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +load( + "//rules/opentitan:defs.bzl", + "fpga_params", + "opentitan_test", +) + +package(default_visibility = ["//visibility:public"]) + +opentitan_test( + name = "ownership_transfer_test", + srcs = ["//sw/device/silicon_creator/rom_ext/e2e/verified_boot:boot_test"], + exec_env = { + "//hw/top_earlgrey:fpga_hyper310_rom_ext": None, + }, + fpga = fpga_params( + # This test doesn't change OTP, but it modifies the ownership INFO + # pages, so we need to clear the bitstream after the test, which is + # what the `changes_otp` parameter actually does. + changes_otp = True, + data = [ + "//sw/device/silicon_creator/lib/ownership/keys/dummy:activate_key", + "//sw/device/silicon_creator/lib/ownership/keys/dummy:app_prod_pub", + "//sw/device/silicon_creator/lib/ownership/keys/dummy:owner_key", + "//sw/device/silicon_creator/lib/ownership/keys/dummy:unlock_key", + "//sw/device/silicon_creator/lib/ownership/keys/fake:unlock_key", + ], + test_cmd = """ + --clear-bitstream + --bootstrap={firmware} + --unlock-key=$(location //sw/device/silicon_creator/lib/ownership/keys/fake:unlock_key) + --next-owner-key=$(location //sw/device/silicon_creator/lib/ownership/keys/dummy:owner_key) + --next-unlock-key=$(location //sw/device/silicon_creator/lib/ownership/keys/dummy:unlock_key) + --next-activate-key=$(location //sw/device/silicon_creator/lib/ownership/keys/dummy:activate_key) + --next-application-key=$(location //sw/device/silicon_creator/lib/ownership/keys/dummy:app_prod_pub) + """, + test_harness = "//sw/host/tests/ownership:transfer_test", + ), + rsa_key = { + "//sw/device/silicon_creator/lib/ownership/keys/dummy:app_prod": "app_prod", + }, + deps = [ + "//sw/device/lib/base:status", + "//sw/device/lib/testing/test_framework:ottf_main", + "//sw/device/silicon_creator/lib:boot_log", + "//sw/device/silicon_creator/lib/drivers:retention_sram", + ], +) diff --git a/sw/device/silicon_creator/rom_ext/e2e/rescue/BUILD b/sw/device/silicon_creator/rom_ext/e2e/rescue/BUILD index fb6e242cd7327..f254a8885a9c7 100644 --- a/sw/device/silicon_creator/rom_ext/e2e/rescue/BUILD +++ b/sw/device/silicon_creator/rom_ext/e2e/rescue/BUILD @@ -95,7 +95,7 @@ opentitan_test( --exec="fpga load-bitstream {bitstream}" --exec="bootstrap --clear-uart=true {firmware}" # Set next slot via the rescue protocol - --exec="rescue boot-svc set-next-bl0-slot --next=SlotB" + --exec="rescue boot-svc set-next-bl0-slot --next=SlotB --get-response=false" # Check for firmware execution in slot B --exec="console --non-interactive --exit-success='bl0_slot = __BB\r\n' --exit-failure='{exit_failure}'" # Reset and observe return to slot A. diff --git a/sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD b/sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD index 0616c75df464a..2a091cf71abb3 100644 --- a/sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD +++ b/sw/device/silicon_creator/rom_ext/e2e/verified_boot/BUILD @@ -1,6 +1,7 @@ # Copyright lowRISC contributors (OpenTitan project). # Licensed under the Apache License, Version 2.0, see LICENSE for details. # SPDX-License-Identifier: Apache-2.0 + load( "//rules/opentitan:defs.bzl", "DEFAULT_TEST_FAILURE_MSG", diff --git a/sw/host/opentitanlib/BUILD b/sw/host/opentitanlib/BUILD index 847fa1f34bcbc..8583e428df238 100644 --- a/sw/host/opentitanlib/BUILD +++ b/sw/host/opentitanlib/BUILD @@ -83,6 +83,7 @@ rust_library( "src/chip/boot_svc.rs", "src/chip/helper.rs", "src/chip/mod.rs", + "src/chip/rom_error.rs", "src/console/mod.rs", "src/console/spi.rs", "src/crypto/ecdsa.rs", @@ -259,6 +260,7 @@ rust_library( "//third_party/openocd:jtag_cmsis_dap_adapter_cfg", "//util/openocd/target:lowrisc-earlgrey.cfg", "//util/openocd/target:lowrisc-earlgrey-lc.cfg", + "//sw/host/opentitanlib/bindgen:rom_error_enum", ], crate_features = [ "include_hyperdebug_firmware", @@ -275,6 +277,7 @@ rust_library( "i2c_target": "$(location :i2c_target)", "mem": "$(location :mem)", "pinmux_config": "$(location :pinmux_config)", + "rom_error_enum": "$(location //sw/host/opentitanlib/bindgen:rom_error_enum)", "spi_passthru": "$(location :spi_passthru)", "ottf": "$(location :ottf)", "hyperdebug_firmware": "$(location @hyperdebug_firmware//:hyperdebug/ec.bin)", diff --git a/sw/host/opentitanlib/bindgen/BUILD b/sw/host/opentitanlib/bindgen/BUILD index 199074cfc12a9..dab3e013f2bf5 100644 --- a/sw/host/opentitanlib/bindgen/BUILD +++ b/sw/host/opentitanlib/bindgen/BUILD @@ -2,8 +2,8 @@ # Licensed under the Apache License, Version 2.0, see LICENSE for details. # SPDX-License-Identifier: Apache-2.0 -load("@rules_rust//bindgen:defs.bzl", "rust_bindgen_library") -load("@rules_rust//rust:defs.bzl", "rust_library") +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") +load("@rules_rust//bindgen:defs.bzl", "rust_bindgen", "rust_bindgen_library") package(default_visibility = ["//visibility:public"]) @@ -187,6 +187,43 @@ rust_bindgen_library( ], ) +# We generate the bindgen source for rom_error_t so we can post-process it +# with the :rom_error_enum rule and build a full enum from all known +# rom_error_t values. +rust_bindgen( + name = "rom_error", + bindgen_flags = [ + "--allowlist-type=rom_error_t", + ], + cc_lib = "//sw/device/silicon_creator/lib:error", + header = "//sw/device/silicon_creator/lib:error.h", +) + +# Generate a rust source file that contains the enum definition. This +# will get textual-included into opentitanlib's `chip::rom_error` module. +genrule( + name = "rom_error_enum", + srcs = [":rom_error"], + outs = ["rom_error_enum.rs"], + cmd = """ +cat >$@ <
>$@ + +cat >>$@ <