Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[opentitanlib] add DFT disabling strap config and workaround #20683

Merged
merged 7 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sw/device/silicon_creator/manuf/lib/ast_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ status_t ast_program_config(bool verbose) {
(kFlashInfoFieldAstCalibrationData.page * device_info.bytes_per_page) +
kFlashInfoFieldAstCalibrationData.byte_offset;
uint32_t ast_data[kFlashInfoAstCalibrationDataSizeIn32BitWords];
TRY(flash_ctrl_testutils_wait_for_init(&flash_state));
TRY(flash_ctrl_testutils_read(&flash_state, byte_address,
kFlashInfoFieldAstCalibrationData.partition,
ast_data, kDifFlashCtrlPartitionTypeInfo,
Expand Down
3 changes: 0 additions & 3 deletions sw/device/silicon_creator/manuf/lib/individualize.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ status_t manuf_individualize_device_hw_cfg_check(
status_t manuf_individualize_device_secret0(
const dif_lc_ctrl_t *lc_ctrl, const dif_otp_ctrl_t *otp_ctrl,
const manuf_cp_provisioning_data_t *provisioning_data) {
// Check life cycle in TEST_UNLOCKED0.
TRY(lc_ctrl_testutils_check_lc_state(lc_ctrl, kDifLcCtrlStateTestUnlocked0));

bool is_locked;
TRY(dif_otp_ctrl_is_digest_computed(otp_ctrl, kDifOtpCtrlPartitionSecret0,
&is_locked));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//rules:const.bzl", "CONST")
load(
"//rules:opentitan.bzl",
"RSA_ONLY_KEY_STRUCTS",
)
load("//rules:signing.bzl", "offline_presigning_artifacts", "offline_signature_attach")
load(
"//rules/opentitan:defs.bzl",
"cw310_jtag_params",
Expand All @@ -23,8 +25,6 @@ load(
"FT_PERSONALIZE_SIGNING_KEYS",
"FT_PROVISIONING_INPUTS",
)
load("//rules:signing.bzl", "offline_presigning_artifacts", "offline_signature_attach")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -173,20 +173,21 @@ opentitan_test(
"//sw/device/lib/arch:device",
"//sw/device/lib/base:macros",
"//sw/device/lib/dif:flash_ctrl",
"//sw/device/lib/dif:lc_ctrl",
"//sw/device/lib/dif:otp_ctrl",
"//sw/device/lib/dif:pinmux",
"//sw/device/lib/runtime:hart",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing:lc_ctrl_testutils",
"//sw/device/lib/testing:flash_ctrl_testutils",
"//sw/device/lib/testing:otp_ctrl_testutils",
"//sw/device/lib/testing:pinmux_testutils",
"//sw/device/lib/testing/test_framework:check",
"//sw/device/lib/testing/test_framework:ottf_console",
"//sw/device/lib/testing/test_framework:ottf_test_config",
"//sw/device/lib/testing/test_framework:status",
"//sw/device/lib/testing/test_framework:ujson_ottf",
"//sw/device/silicon_creator/manuf/lib:flash_info_fields",
"//sw/device/silicon_creator/manuf/lib:individualize",
"//sw/device/silicon_creator/manuf/lib:otp_fields",
"//sw/device/silicon_creator/manuf/lib:sram_start",
"//sw/device/silicon_creator/manuf/lib:individualize_sw_cfg_earlgrey_a0_sku_{}".format(otp_sw_cfgs),
],
Expand Down Expand Up @@ -241,9 +242,7 @@ opentitan_binary(
"//sw/device/lib/dif:flash_ctrl",
"//sw/device/lib/dif:lc_ctrl",
"//sw/device/lib/dif:otp_ctrl",
"//sw/device/lib/dif:rstmgr",
"//sw/device/lib/runtime:log",
"//sw/device/lib/testing:rstmgr_testutils",
"//sw/device/lib/testing/json:provisioning_data",
"//sw/device/lib/testing/test_framework:check",
"//sw/device/lib/testing/test_framework:ottf_main",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
#include "sw/device/lib/dif/dif_flash_ctrl.h"
#include "sw/device/lib/dif/dif_lc_ctrl.h"
#include "sw/device/lib/dif/dif_otp_ctrl.h"
#include "sw/device/lib/dif/dif_rstmgr.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/json/provisioning_data.h"
#include "sw/device/lib/testing/rstmgr_testutils.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
Expand All @@ -23,7 +21,6 @@ OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);
static dif_flash_ctrl_state_t flash_ctrl_state;
static dif_lc_ctrl_t lc_ctrl;
static dif_otp_ctrl_t otp_ctrl;
static dif_rstmgr_t rstmgr;

static manuf_rma_token_perso_data_in_t in_data;
static manuf_rma_token_perso_data_out_t out_data;
Expand All @@ -39,20 +36,9 @@ static status_t peripheral_handles_init(void) {
&lc_ctrl));
TRY(dif_otp_ctrl_init(
mmio_region_from_addr(TOP_EARLGREY_OTP_CTRL_CORE_BASE_ADDR), &otp_ctrl));
TRY(dif_rstmgr_init(mmio_region_from_addr(TOP_EARLGREY_RSTMGR_AON_BASE_ADDR),
&rstmgr));
return OK_STATUS();
}

/**
* Perform software reset.
*/
static void sw_reset(void) {
rstmgr_testutils_reason_clear();
CHECK_DIF_OK(dif_rstmgr_software_device_reset(&rstmgr));
wait_for_interrupt();
}

/**
* Provision OTP Secret2 partition and keymgr flash info pages (1, 2, and 4).
*/
Expand All @@ -64,12 +50,8 @@ static status_t personalize(ujson_t *uj) {
&in_data, &out_data));
LOG_INFO("Exporting FT provisioning data ...");
RESP_OK(ujson_serialize_manuf_rma_token_perso_data_out_t, uj, &out_data);
// We need to reset the chip here to activate the keymgr seeds.
sw_reset();
}

// TODO(#19455): crank keymgr and generate certificates.

return OK_STATUS();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ bool sram_main(void) {
ujson_t uj = ujson_ottf_console();
LOG_INFO("AST manually configured.");

// Check we are in in TEST_UNLOCKED0 and perform CP provisioning operations.
CHECK_STATUS_OK(
lc_ctrl_testutils_check_lc_state(&lc_ctrl, kDifLcCtrlStateTestUnlocked0));
// Perform CP provisioning operations.
CHECK_STATUS_OK(provision(&uj));

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@

#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/dif/dif_flash_ctrl.h"
#include "sw/device/lib/dif/dif_lc_ctrl.h"
#include "sw/device/lib/dif/dif_otp_ctrl.h"
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/runtime/print.h"
#include "sw/device/lib/testing/lc_ctrl_testutils.h"
#include "sw/device/lib/testing/flash_ctrl_testutils.h"
#include "sw/device/lib/testing/otp_ctrl_testutils.h"
#include "sw/device/lib/testing/pinmux_testutils.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_console.h"
#include "sw/device/lib/testing/test_framework/ottf_test_config.h"
#include "sw/device/lib/testing/test_framework/ujson_ottf.h"
#include "sw/device/silicon_creator/manuf/lib/flash_info_fields.h"
#include "sw/device/silicon_creator/manuf/lib/individualize.h"
#include "sw/device/silicon_creator/manuf/lib/individualize_sw_cfg.h"
#include "sw/device/silicon_creator/manuf/lib/otp_fields.h"
#include "sw/device/silicon_creator/manuf/skus/earlgrey_a0/sival_bringup/flash_info_permissions.h"

#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"

OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);

static dif_flash_ctrl_state_t flash_ctrl_state;
static dif_lc_ctrl_t lc_ctrl;
static dif_otp_ctrl_t otp_ctrl;
static dif_pinmux_t pinmux;

static manuf_ft_individualize_data_t in_data;
static uint32_t device_id[kHwCfgDeviceIdSizeIn32BitWords];
static uint32_t ast_cfg_data[kHwCfgDeviceIdSizeIn32BitWords];

/**
* Initializes all DIF handles used in this SRAM program.
Expand All @@ -40,15 +42,42 @@ static status_t peripheral_handles_init(void) {
TRY(dif_flash_ctrl_init_state(
&flash_ctrl_state,
mmio_region_from_addr(TOP_EARLGREY_FLASH_CTRL_CORE_BASE_ADDR)));
TRY(dif_lc_ctrl_init(mmio_region_from_addr(TOP_EARLGREY_LC_CTRL_BASE_ADDR),
&lc_ctrl));
TRY(dif_otp_ctrl_init(
mmio_region_from_addr(TOP_EARLGREY_OTP_CTRL_CORE_BASE_ADDR), &otp_ctrl));
TRY(dif_pinmux_init(mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR),
&pinmux));
return OK_STATUS();
}

/**
* Print data stored in flash info page 0 to console for manual verification
* purposes during silicon bring-up.
*/
static status_t print_flash_info_0_data_to_console(void) {
uint32_t byte_address = 0;
TRY(flash_ctrl_testutils_info_region_setup_properties(
&flash_ctrl_state, kFlashInfoFieldDeviceId.page,
kFlashInfoFieldDeviceId.bank, kFlashInfoFieldDeviceId.partition,
kFlashInfoPage0Permissions, &byte_address));

LOG_INFO("Device ID:");
TRY(manuf_flash_info_field_read(&flash_ctrl_state, kFlashInfoFieldDeviceId,
device_id, kHwCfgDeviceIdSizeIn32BitWords));
for (size_t i = 0; i < kHwCfgDeviceIdSizeIn32BitWords; ++i) {
LOG_INFO("0x%x", device_id[i]);
}

LOG_INFO("AST Calibration Values:");
TRY(manuf_flash_info_field_read(
&flash_ctrl_state, kFlashInfoFieldAstCalibrationData, ast_cfg_data,
kFlashInfoAstCalibrationDataSizeIn32BitWords));
for (size_t i = 0; i < kFlashInfoAstCalibrationDataSizeIn32BitWords; ++i) {
LOG_INFO("0x%x", ast_cfg_data[i]);
}

return OK_STATUS();
}

/**
* Provision OTP {CreatorSw,OwnerSw,Hw}Cfg partitions.
*
Expand All @@ -74,10 +103,9 @@ bool sram_main(void) {
ottf_console_init();
ujson_t uj = ujson_ottf_console();

// Check we are in in TEST_UNLOCKED1.
CHECK_STATUS_OK(
lc_ctrl_testutils_check_lc_state(&lc_ctrl, kDifLcCtrlStateTestUnlocked1));

// Print flash data to console (for manual verification purposes) and perform
// provisioning operations.
CHECK_STATUS_OK(print_flash_info_0_data_to_console());
CHECK_STATUS_OK(provision(&uj));

// Halt the CPU here to enable JTAG to perform an LC transition to mission
Expand Down
15 changes: 8 additions & 7 deletions sw/host/opentitanlib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ rust_library(
"src/bootstrap/primitive.rs",
"src/bootstrap/rescue.rs",
"src/chip/alert.rs",
"src/chip/autogen/mod.rs",
"src/chip/boolean.rs",
"src/chip/mod.rs",
"src/chip/autogen/mod.rs",
"src/console/mod.rs",
"src/console/spi.rs",
"src/crypto/mod.rs",
Expand All @@ -83,10 +83,10 @@ rust_library(
"src/dif/aon_timer.rs",
"src/dif/clkmgr.rs",
"src/dif/lc_ctrl.rs",
"src/dif/mod.rs",
"src/dif/otp_ctrl.rs",
"src/dif/rstmgr.rs",
"src/dif/uart.rs",
"src/dif/mod.rs",
"src/image/image.rs",
"src/image/manifest.rs",
"src/image/manifest_def.rs",
Expand All @@ -109,10 +109,10 @@ rust_library(
"src/otp/lc_state.rs",
"src/otp/mod.rs",
"src/otp/otp_img.rs",
"src/proxy/nonblocking_uart.rs",
"src/proxy/errors.rs",
"src/proxy/handler.rs",
"src/proxy/mod.rs",
"src/proxy/nonblocking_uart.rs",
"src/proxy/protocol.rs",
"src/proxy/socket_server.rs",
"src/spiflash/flash.rs",
Expand All @@ -126,6 +126,7 @@ rust_library(
"src/test_utils/gpio.rs",
"src/test_utils/i2c_target.rs",
"src/test_utils/init.rs",
"src/test_utils/lc.rs",
"src/test_utils/lc_transition.rs",
"src/test_utils/load_bitstream.rs",
"src/test_utils/load_sram_program.rs",
Expand All @@ -142,14 +143,14 @@ rust_library(
"src/tpm/driver.rs",
"src/tpm/mod.rs",
"src/tpm/status.rs",
"src/transport/common/mod.rs",
"src/transport/common/fpga.rs",
"src/transport/common/uart.rs",
"src/transport/chip_whisperer/board.rs",
"src/transport/chip_whisperer/gpio.rs",
"src/transport/chip_whisperer/mod.rs",
"src/transport/chip_whisperer/spi.rs",
"src/transport/chip_whisperer/usb.rs",
"src/transport/common/fpga.rs",
"src/transport/common/mod.rs",
"src/transport/common/uart.rs",
"src/transport/dediprog/gpio.rs",
"src/transport/dediprog/mod.rs",
"src/transport/dediprog/spi.rs",
Expand Down Expand Up @@ -182,8 +183,8 @@ rust_library(
"src/transport/ultradebug/mpsse.rs",
"src/transport/ultradebug/spi.rs",
"src/transport/ultradebug/uart.rs",
"src/transport/verilator/mod.rs",
"src/transport/verilator/gpio.rs",
"src/transport/verilator/mod.rs",
"src/transport/verilator/subprocess.rs",
"src/transport/verilator/transport.rs",
"src/transport/verilator/uart.rs",
Expand Down
27 changes: 27 additions & 0 deletions sw/host/opentitanlib/src/app/config/hyperdebug_chipwhisperer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
"pull_mode": "PullUp",
"alias_of": "CN10_29"
},
{
"name": "DFT_STRAP0",
"mode": "Alternate",
"alias_of": "IOC3"
},
{
"name": "DFT_STRAP1",
"mode": "Alternate",
"alias_of": "IOC4"
},
timothytrippel marked this conversation as resolved.
Show resolved Hide resolved
{
"name": "IOA0",
"alias_of": "CN8_6"
Expand Down Expand Up @@ -237,5 +247,22 @@
"name": "console",
"alias_of": "UART2"
}
],
"strappings": [
{
"name": "PRERESET_DFT_DISABLE",
"pins": [
{
"name": "DFT_STRAP0",
"mode": "PushPull",
"level": false
},
{
"name": "DFT_STRAP1",
"mode": "PushPull",
"level": false
}
]
}
timothytrippel marked this conversation as resolved.
Show resolved Hide resolved
]
}
Loading
Loading