Skip to content
Draft
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
10 changes: 5 additions & 5 deletions rules/autogen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ autogen_chip_info_src = rule(
} | stamp_attr(-1, "//rules:stamp_flag"),
)

def autogen_chip_info(name):
def autogen_chip_info(name, deps = []):
"""Generates a cc_library named `name` that defines chip info."""

# Generate a C source file that defines the chip info struct. This is an
Expand All @@ -198,10 +198,10 @@ def autogen_chip_info(name):
native.cc_library(
name = name,
srcs = [chip_info_src_target],
hdrs = ["//sw/device/silicon_creator/lib:chip_info.h"],
deps = [
"//sw/device/lib/base:macros",
],
deps = deps,
# Make sure to participate in linking so that the symbol is not discarded
# (since it is not meant to be directly used).
alwayslink = True,
)

def _cryptotest_hjson_external(ctx):
Expand Down
3 changes: 2 additions & 1 deletion sw/device/lib/testing/test_rom/test_rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ bool rom_test_main(void) {
}

// Print the chip version information
LOG_INFO("kChipInfo: scm_revision=%x", kChipInfo.scm_revision);
chip_info_t *chip_info = (chip_info_t *)&_chip_info_start;
LOG_INFO("kChipInfo: scm_revision=%x", chip_info->scm_revision);

// Skip sram_init for test_rom
dif_rstmgr_reset_info_bitfield_t reset_reasons;
Expand Down
13 changes: 12 additions & 1 deletion sw/device/silicon_creator/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,18 @@ filegroup(
],
)

autogen_chip_info(name = "chip_info")
cc_library(
name = "chip_info",
hdrs = ["chip_info.h"],
)

autogen_chip_info(
name = "chip_info_data",
deps = [
":chip_info",
"//sw/device/lib/base:macros",
],
)

dual_cc_library(
name = "shutdown",
Expand Down
7 changes: 3 additions & 4 deletions sw/device/silicon_creator/lib/chip_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ enum {
};

/**
* Extern declaration for the `kChipInfo` instance placed at the end of ROM.
*
* The actual definition is in an auto-generated file.
* The chip information is placed at the end of ROM and is accessible using
* the following symbol.
*/
extern const chip_info_t kChipInfo;
extern const char _chip_info_start[];

#endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_CHIP_INFO_H_
3 changes: 2 additions & 1 deletion sw/device/silicon_creator/lib/shutdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,11 @@ SHUTDOWN_FUNC(NO_MODIFIERS, shutdown_report_error(rom_error_t reason)) {

// Print the error message and the raw life cycle state as reported by the
// hardware.
const chip_info_t *rom_chip_info = (const chip_info_t *)_chip_info_start;
shutdown_print(kShutdownLogPrefixBootFault, redacted_error);
shutdown_print(kShutdownLogPrefixLifecycle, raw_state);
shutdown_print(kShutdownLogPrefixVersion,
kChipInfo.scm_revision.scm_revision_high);
rom_chip_info->scm_revision.scm_revision_high);
}

SHUTDOWN_FUNC(NO_MODIFIERS, shutdown_software_escalate(void)) {
Expand Down
2 changes: 2 additions & 0 deletions sw/device/silicon_creator/rom/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ cc_library(
"//sw/device/lib/base:hardened",
"//sw/device/lib/base:multibits",
"//sw/device/silicon_creator/lib/base:chip",
# This embeds the chip info into the binary.
"//sw/device/silicon_creator/lib:chip_info_data",
],
alwayslink = True,
)
Expand Down
13 changes: 13 additions & 0 deletions sw/device/silicon_creator/rom/e2e/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,16 @@ opentitan_test(
"//sw/device/silicon_creator/lib/drivers:rstmgr",
],
)

opentitan_test(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add an entry to the tesplan?

name = "rom_e2e_chip_info",
srcs = ["chip_info_test.c"],
exec_env = {
"//hw/top_earlgrey:fpga_cw310_rom_with_fake_keys": None,
"//hw/top_earlgrey:fpga_cw340_rom_with_fake_keys": None,
},
deps = [
"//sw/device/lib/testing/test_framework:ottf_main",
"//sw/device/silicon_creator/lib:chip_info",
],
)
21 changes: 21 additions & 0 deletions sw/device/silicon_creator/rom/e2e/chip_info_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright lowRISC contributors (OpenTitan project).
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "sw/device/silicon_creator/lib/chip_info.h"

#include <stdbool.h>

#include "sw/device/lib/testing/test_framework/ottf_main.h"

OTTF_DEFINE_TEST_CONFIG();

bool test_main(void) {
chip_info_t *chip_info = (chip_info_t *)&_chip_info_start;
LOG_INFO("Chip Info");
LOG_INFO(" Version: %x", chip_info->version);
LOG_INFO(" SCM lo: %x", chip_info->scm_revision.scm_revision_low);
LOG_INFO(" SCM hi: %x", chip_info->scm_revision.scm_revision_high);

return chip_info->version == kChipInfoVersion1;
}
3 changes: 2 additions & 1 deletion sw/device/silicon_creator/rom/rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ static rom_error_t rom_init(void) {

// Initialize boot_log
boot_log_t *boot_log = &retention_sram_get()->creator.boot_log;
const chip_info_t *rom_chip_info = (const chip_info_t *)_chip_info_start;
memset(boot_log, 0, sizeof(*boot_log));
boot_log->identifier = kBootLogIdentifier;
boot_log->chip_version = kChipInfo.scm_revision;
boot_log->chip_version = rom_chip_info->scm_revision;
boot_log->retention_ram_initialized =
reset_reasons & reset_mask ? kHardenedBoolTrue : kHardenedBoolFalse;

Expand Down
1 change: 1 addition & 0 deletions util/rom_chip_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def generate_chip_info_c_source(scm_revision: int) -> str:

#include "sw/device/lib/base/macros.h"

OT_USED
OT_SECTION(".chip_info")
const chip_info_t kChipInfo = {{
.scm_revision = (chip_info_scm_revision_t){{
Expand Down
Loading