Skip to content

Commit 1871921

Browse files
committed
[sw,rom_ext] Add boot log events field to track boot data redundancy fix
This change adds an `events` field to the `boot_log_t` structure to track specific events during the boot process. Specifically, it introduces a `kBootLogEventRedundancy` flag that indicates if the boot data redundancy was fixed by the ROM_EXT. The `events` field is populated in `rom_ext_start` based on the `boot_data_validity` check. A new end-to-end test is added to verify that the redundancy fix is correctly signaled on the first boot after a bitstream load and not on subsequent resets. Change-Id: I2a3417d4e588f916bdb1ca4127a2bf0e4917d8a1 Signed-off-by: Yi-Hsuan Deng <yhdeng@google.com>
1 parent d087285 commit 1871921

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

sw/device/silicon_creator/lib/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ cc_library(
9797
deps = [
9898
":boot_data",
9999
":nonce",
100+
"//sw/device/lib/base:bitfield",
100101
"//sw/device/lib/base:macros",
101102
"//sw/device/silicon_creator/lib:build_info",
102103
"//sw/device/silicon_creator/lib:error",

sw/device/silicon_creator/lib/boot_log.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <stdint.h>
99

10+
#include "sw/device/lib/base/bitfield.h"
1011
#include "sw/device/lib/base/macros.h"
1112
#include "sw/device/silicon_creator/lib/boot_data.h"
1213
#include "sw/device/silicon_creator/lib/build_info.h"
@@ -53,8 +54,10 @@ typedef struct boot_log {
5354
uint32_t primary_bl0_slot;
5455
/** Whether the RET-RAM was initialized on this boot (hardened_bool_t). */
5556
uint32_t retention_ram_initialized;
57+
/** Signals of events during boot. */
58+
uint32_t events;
5659
/** Pad to 128 bytes. */
57-
uint32_t reserved[8];
60+
uint32_t reserved[7];
5861
} boot_log_t;
5962

6063
OT_ASSERT_MEMBER_OFFSET(boot_log_t, digest, 0);
@@ -72,7 +75,8 @@ OT_ASSERT_MEMBER_OFFSET(boot_log_t, rom_ext_min_sec_ver, 80);
7275
OT_ASSERT_MEMBER_OFFSET(boot_log_t, bl0_min_sec_ver, 84);
7376
OT_ASSERT_MEMBER_OFFSET(boot_log_t, primary_bl0_slot, 88);
7477
OT_ASSERT_MEMBER_OFFSET(boot_log_t, retention_ram_initialized, 92);
75-
OT_ASSERT_MEMBER_OFFSET(boot_log_t, reserved, 96);
78+
OT_ASSERT_MEMBER_OFFSET(boot_log_t, events, 96);
79+
OT_ASSERT_MEMBER_OFFSET(boot_log_t, reserved, 100);
7680

7781
enum {
7882
/**
@@ -81,6 +85,14 @@ enum {
8185
kBootLogIdentifier = 0x474f4c42,
8286
};
8387

88+
/**
89+
* Boot log event (bit 0): Boot data redundancy fixed.
90+
*
91+
* This bit will be set to 1 if the boot data was corrupted and has been
92+
* repaired by the ROM_EXT during this boot.
93+
*/
94+
#define BOOT_LOG_EVENT_REDUNDANCY 0
95+
8496
/**
8597
* Updates the digest of the boot_log.
8698
*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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(
6+
"//rules/opentitan:defs.bzl",
7+
"fpga_params",
8+
"opentitan_test",
9+
)
10+
11+
package(default_visibility = ["//visibility:public"])
12+
13+
opentitan_test(
14+
name = "redundancy_fix_test",
15+
srcs = ["redundancy_fix_test.c"],
16+
exec_env = {
17+
"//hw/top_earlgrey:fpga_cw310_rom_ext": None,
18+
"//hw/top_earlgrey:fpga_cw340_rom_ext": None,
19+
},
20+
fpga = fpga_params(
21+
# Clear the FPGA so the boot data is empty which needs redundancy fix.
22+
test_cmd = """
23+
--exec="transport init"
24+
--exec="fpga clear-bitstream"
25+
--exec="fpga load-bitstream {bitstream}"
26+
--exec="bootstrap --clear-uart=true {firmware}"
27+
--exec="console --non-interactive --exit-success='{exit_success}' --exit-failure='{exit_failure}'"
28+
no-op
29+
""",
30+
),
31+
deps = [
32+
"//sw/device/lib/base:bitfield",
33+
"//sw/device/lib/base:status",
34+
"//sw/device/lib/runtime:log",
35+
"//sw/device/lib/testing/test_framework:check",
36+
"//sw/device/lib/testing/test_framework:ottf_main",
37+
"//sw/device/silicon_creator/lib/drivers:retention_sram",
38+
"//sw/device/silicon_creator/lib/drivers:rstmgr",
39+
],
40+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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/bitfield.h"
6+
#include "sw/device/lib/base/status.h"
7+
#include "sw/device/lib/runtime/log.h"
8+
#include "sw/device/lib/testing/test_framework/check.h"
9+
#include "sw/device/lib/testing/test_framework/ottf_main.h"
10+
#include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
11+
#include "sw/device/silicon_creator/lib/drivers/rstmgr.h"
12+
13+
OTTF_DEFINE_TEST_CONFIG();
14+
15+
bool test_main(void) {
16+
retention_sram_t *retram = retention_sram_get();
17+
18+
bool redundancy_fixed = bitfield_bit32_read(retram->creator.boot_log.events,
19+
BOOT_LOG_EVENT_REDUNDANCY);
20+
LOG_INFO("Redundancy fix event: %d", redundancy_fixed);
21+
22+
if (bitfield_bit32_read(retram->creator.reset_reasons,
23+
kRstmgrReasonPowerOn)) {
24+
CHECK(redundancy_fixed, "ROM_EXT should fix redundancy on first boot");
25+
rstmgr_reset();
26+
return false;
27+
} else {
28+
CHECK(!redundancy_fixed, "It should already be fixed on the second boot");
29+
return true;
30+
}
31+
}

sw/device/silicon_creator/rom_ext/rom_ext.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ static rom_error_t rom_ext_start(boot_data_t *boot_data, boot_log_t *boot_log) {
548548
// it here so the "SetNextBl0" can do a one-time override of the RAM copy
549549
// of `boot_data`.
550550
boot_log->primary_bl0_slot = boot_data->primary_bl0_slot;
551+
boot_log->events =
552+
bitfield_bit32_write(boot_log->events, BOOT_LOG_EVENT_REDUNDANCY,
553+
boot_data_validity != kErrorOk);
551554

552555
// Protect the flash pages where the ROM_EXT is located.
553556
rom_ext_flash_protect_self(boot_log->rom_ext_slot);

0 commit comments

Comments
 (0)