Software APIs
boot_test.c
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 #include "sw/device/lib/base/status.h"
8 #include "sw/device/silicon_creator/lib/boot_log.h"
9 #include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
10 
11 #ifdef WITH_OWNERSHIP_INFO
12 #include "sw/device/silicon_creator/lib/drivers/flash_ctrl.h"
13 #include "sw/device/silicon_creator/lib/ownership/datatypes.h"
14 
15 status_t ownership_print(void) {
16  owner_block_t config;
17  TRY(flash_ctrl_info_read(&kFlashCtrlInfoPageOwnerSlot0, 0,
18  sizeof(config) / sizeof(uint32_t), &config));
19 
20  LOG_INFO("owner_page0 tag = %C", config.header.tag);
21  LOG_INFO("owner_page0 ownership_key_alg = %C", config.ownership_key_alg);
22  LOG_INFO("owner_page0 config_version = %d", config.config_version);
23  LOG_INFO("owner_page0 min_security_version_bl0 = %08x",
25  LOG_INFO("owner_page0 update_mode = %C", config.update_mode);
26  LOG_INFO("owner_page0 owner_key = %08x", config.owner_key.raw[0]);
27  return OK_STATUS();
28 }
29 #else
30 status_t ownership_print(void) { return OK_STATUS(); }
31 #endif
32 
33 #ifdef WITH_KEYMGR
35 
37 
38 const char *keymgr_state(dif_keymgr_state_t s) {
39  switch (s) {
41  return "Reset";
43  return "Initialized";
45  return "CreatorRootKey";
47  return "OwnerIntermediateKey";
49  return "OwnerRootKey";
51  return "Disabled";
53  return "Invalid";
54  default:
55  return "Unknown";
56  }
57 }
58 
59 status_t keymgr_print(void) {
60  dif_keymgr_t km;
62  &km));
63 
64  dif_keymgr_state_t state;
65  TRY(dif_keymgr_get_state(&km, &state));
66  LOG_INFO("keymgr state = %s", keymgr_state(state));
67 
69  TRY(dif_keymgr_read_binding(&km, &bind));
70  LOG_INFO("keymgr bind_sealing = %08x%08x%08x%08x%08x%08x%08x%08x",
71  bind.sealing[0], bind.sealing[1], bind.sealing[2], bind.sealing[3],
72  bind.sealing[4], bind.sealing[5], bind.sealing[6], bind.sealing[7]);
73  LOG_INFO("keymgr bind_attest = %08x%08x%08x%08x%08x%08x%08x%08x",
74  bind.attestation[0], bind.attestation[1], bind.attestation[2],
75  bind.attestation[3], bind.attestation[4], bind.attestation[5],
76  bind.attestation[6], bind.attestation[7]);
77 
80 
82  TRY(dif_keymgr_read_output(&km, &out));
83  LOG_INFO("keymgr sw_key = %08x%08x%08x%08x%08x%08x%08x%08x",
84  out.value[0][0] ^ out.value[1][0], out.value[0][1] ^ out.value[1][1],
85  out.value[0][2] ^ out.value[1][2], out.value[0][3] ^ out.value[1][3],
86  out.value[0][4] ^ out.value[1][4], out.value[0][5] ^ out.value[1][5],
87  out.value[0][6] ^ out.value[1][6],
88  out.value[0][7] ^ out.value[1][7]);
89 
90  return OK_STATUS();
91 }
92 #else
93 status_t keymgr_print(void) { return OK_STATUS(); }
94 #endif
95 
96 OTTF_DEFINE_TEST_CONFIG();
97 
98 status_t boot_log_print(boot_log_t *boot_log) {
99  TRY(boot_log_check(boot_log));
100  LOG_INFO("boot_log identifier = %C", boot_log->identifier);
101  LOG_INFO("boot_log chip_version = %08x%08x",
104 
105  LOG_INFO("boot_log rom_ext_slot = %C", boot_log->rom_ext_slot);
106  LOG_INFO("boot_log rom_ext_version = %d.%d", boot_log->rom_ext_major,
108  LOG_INFO("boot_log rom_ext_size = 0x%08x", boot_log->rom_ext_size);
109  LOG_INFO("boot_log rom_ext_nonce = %08x%08x",
110  boot_log->rom_ext_nonce.value[1], boot_log->rom_ext_nonce.value[0]);
111  LOG_INFO("boot_log bl0_slot = %C", boot_log->bl0_slot);
112  LOG_INFO("boot_log ownership_state = %C", boot_log->ownership_state);
113  LOG_INFO("boot_log ownership_transfers = %u", boot_log->ownership_transfers);
114  LOG_INFO("boot_log rom_ext_min_sec_ver = %u", boot_log->rom_ext_min_sec_ver);
115  LOG_INFO("boot_log bl0_min_sec_ver = %u", boot_log->bl0_min_sec_ver);
116  LOG_INFO("boot_log primary_bl0_slot = %C", boot_log->primary_bl0_slot);
117  TRY(ownership_print());
118  TRY(keymgr_print());
119  return OK_STATUS();
120 }
121 
122 bool test_main(void) {
123  status_t sts = boot_log_print(&retention_sram_get()->creator.boot_log);
124  if (status_err(sts)) {
125  LOG_ERROR("boot_log_print: %r", sts);
126  }
127  return status_ok(sts);
128 }