Skip to content

Commit

Permalink
[perso] Initialize ownership during perso
Browse files Browse the repository at this point in the history
1. Initialize the ownership sealing key during the UDS stage of keymgr
   setup.
2. Call the `sku_creator_owner_init` function to initialize the
   ownership INFO page.
3. Link in the per-sku `<sku>_owner` implementations of
   `sku_creator_owner_init`.

Signed-off-by: Chris Frantz <[email protected]>
  • Loading branch information
cfrantz committed Nov 20, 2024
1 parent 86f0f5b commit 2aab772
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sw/device/silicon_creator/manuf/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ manifest(d = {
"//sw/device/lib/testing/test_framework:status",
"//sw/device/lib/testing/test_framework:ujson_ottf",
"//sw/device/silicon_creator/lib:attestation",
"//sw/device/silicon_creator/lib:boot_data",
"//sw/device/silicon_creator/lib:otbn_boot_services",
"//sw/device/silicon_creator/lib/base:chip",
"//sw/device/silicon_creator/lib/base:util",
Expand All @@ -332,10 +333,12 @@ manifest(d = {
"//sw/device/silicon_creator/lib/drivers:hmac",
"//sw/device/silicon_creator/lib/drivers:keymgr",
"//sw/device/silicon_creator/lib/drivers:kmac",
"//sw/device/silicon_creator/lib/ownership:owner_block",
"//sw/device/silicon_creator/lib/ownership:ownership_key",
"//sw/device/silicon_creator/manuf/lib:flash_info_fields",
"//sw/device/silicon_creator/manuf/lib:individualize_sw_cfg_{}".format(config["otp"]),
"//sw/device/silicon_creator/manuf/lib:personalize",
] + config["dice_libs"] + config["device_ext_libs"],
] + config["dice_libs"] + config["device_ext_libs"] + config.get("ownership_libs", []),
)
for sku, config in EARLGREY_SKUS.items()
]
Expand Down
50 changes: 50 additions & 0 deletions sw/device/silicon_creator/manuf/base/ft_personalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "sw/device/silicon_creator/lib/base/boot_measurements.h"
#include "sw/device/silicon_creator/lib/base/chip.h"
#include "sw/device/silicon_creator/lib/base/util.h"
#include "sw/device/silicon_creator/lib/boot_data.h"
#include "sw/device/silicon_creator/lib/cert/cdi_0.h" // Generated.
#include "sw/device/silicon_creator/lib/cert/cdi_1.h" // Generated.
#include "sw/device/silicon_creator/lib/cert/cert.h"
Expand All @@ -35,6 +36,8 @@
#include "sw/device/silicon_creator/lib/error.h"
#include "sw/device/silicon_creator/lib/manifest.h"
#include "sw/device/silicon_creator/lib/otbn_boot_services.h"
#include "sw/device/silicon_creator/lib/ownership/owner_block.h"
#include "sw/device/silicon_creator/lib/ownership/ownership_key.h"
#include "sw/device/silicon_creator/manuf/base/perso_tlv_data.h"
#include "sw/device/silicon_creator/manuf/base/personalize_ext.h"
#include "sw/device/silicon_creator/manuf/lib/flash_info_fields.h"
Expand Down Expand Up @@ -152,6 +155,16 @@ static cert_flash_info_layout_t cert_flash_layout[] = {
},
};

/**
* Ownership initialization function.
*/
OT_WEAK rom_error_t
sku_creator_owner_init(boot_data_t *bootdata, owner_config_t *config,
owner_application_keyring_t *keyring) {
LOG_ERROR("No ownership initialization");
return kErrorOk;
}

static void log_self_hash(void) {
// clang-format off
LOG_INFO("Personalization Firmware Hash: 0x%08x%08x%08x%08x%08x%08x%08x%08x",
Expand Down Expand Up @@ -499,6 +512,9 @@ static status_t personalize_gen_dice_certificates(ujson_t *uj) {
kDiceCertFormat, all_certs, curr_cert_size, &perso_blob_to_host));
LOG_INFO("Generated UDS certificate.");

ownership_seal_init();
LOG_INFO("Initialized ownership sealing in UDS state.");

// Generate CDI_0 keys and cert.
curr_cert_size = kCdi0MaxCertSizeBytes;
compute_keymgr_owner_int_binding(&certgen_inputs);
Expand Down Expand Up @@ -543,6 +559,39 @@ static status_t personalize_gen_dice_certificates(ujson_t *uj) {
return OK_STATUS();
}

static status_t install_owner(void) {
// Get the boot_data; installing the owner will write it back with the
// ownership_state set to LockedOwner.
boot_data_t boot_data;
TRY(boot_data_read(kLcStateProd, &boot_data));

// Initialize the ownership-related flash pages.
flash_ctrl_perms_t perm = {
.read = kMultiBitBool4True,
.write = kMultiBitBool4True,
.erase = kMultiBitBool4True,
};
flash_ctrl_cfg_t cfg = {
.scrambling = kMultiBitBool4True,
.ecc = kMultiBitBool4True,
.he = kMultiBitBool4False,
};
flash_ctrl_info_perms_set(&kFlashCtrlInfoPageOwnerSlot0, perm);
flash_ctrl_info_cfg_set(&kFlashCtrlInfoPageOwnerSlot0, cfg);
flash_ctrl_info_perms_set(&kFlashCtrlInfoPageOwnerSlot1, perm);
flash_ctrl_info_cfg_set(&kFlashCtrlInfoPageOwnerSlot1, cfg);

// Initialize ownership. This will write the owner block into OwnerSlot0 and
// set the ownership_state to LockedOwner. The first boot of the ROM_EXT
// will create a redundanty copy in OwnerSlot1.
owner_config_t config;
owner_config_default(&config);
owner_application_keyring_t keyring = {0};
TRY(sku_creator_owner_init(&boot_data, &config, &keyring));

return OK_STATUS();
}

// Returns how much data is left in the perso blob receive buffer (i.e., `body`
// field). Useful when scanning the receive buffer containing perso LTV objects.
static size_t max_available(void) {
Expand Down Expand Up @@ -814,6 +863,7 @@ bool test_main(void) {
CHECK_STATUS_OK(lc_ctrl_testutils_operational_state_check(&lc_ctrl));
CHECK_STATUS_OK(personalize_otp_and_flash_secrets(&uj));
CHECK_STATUS_OK(personalize_gen_dice_certificates(&uj));
CHECK_STATUS_OK(install_owner());

personalize_extension_pre_endorse_t pre_endorse = {
.uj = &uj,
Expand Down
2 changes: 2 additions & 0 deletions sw/device/silicon_creator/manuf/base/provisioning_inputs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ EARLGREY_SKUS = {
"dice_libs": ["//sw/device/silicon_creator/lib/cert:dice"],
"host_ext_libs": ["@provisioning_exts//:default_ft_ext_lib"],
"device_ext_libs": ["@provisioning_exts//:default_perso_fw_ext"],
"ownership_libs": ["//sw/device/silicon_creator/lib/ownership:test_owner"],
"rom_ext": "//sw/device/silicon_creator/rom_ext:rom_ext_slot_b",
"owner_fw": "//sw/device/silicon_owner/bare_metal:bare_metal_slot_b",
},
Expand All @@ -48,6 +49,7 @@ EARLGREY_SKUS = {
"//sw/device/silicon_creator/lib/cert:tpm_ek_template_library",
"//sw/device/silicon_creator/manuf/base:tpm_perso_fw_ext",
],
"ownership_libs": ["//sw/device/silicon_creator/lib/ownership:test_owner"],
"rom_ext": "//sw/device/silicon_creator/rom_ext:rom_ext_slot_b",
"owner_fw": "//sw/device/silicon_owner/bare_metal:bare_metal_slot_b",
},
Expand Down

0 comments on commit 2aab772

Please sign in to comment.