Skip to content

Commit

Permalink
[silicon_creator] Make the nonce.h header available separately
Browse files Browse the repository at this point in the history
The `nonce.c` file has some requirements that pull a lot of code.
On the other hand, some headers only require the definition of
a nonce and not the implementation that goes with it. This commit
refactors the dependencies so that it is possible to depend on
the nonce and boot data definition without depending on the
flash_ctrl driver.

Signed-off-by: Amaury Pouly <[email protected]>
  • Loading branch information
pamaury committed Jan 8, 2025
1 parent 1dc0bad commit 1de7173
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
25 changes: 20 additions & 5 deletions sw/device/silicon_creator/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ load(

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

cc_library(
name = "boot_data_header",
hdrs = ["boot_data.h"],
deps = [
"//sw/device/silicon_creator/lib/drivers:lifecycle",
],
)

dual_cc_library(
name = "boot_data",
srcs = dual_inputs(
Expand All @@ -27,7 +35,6 @@ dual_cc_library(
),
hdrs = dual_inputs(
host = ["mock_boot_data.h"],
shared = ["boot_data.h"],
),
deps = dual_inputs(
device = [
Expand All @@ -43,6 +50,7 @@ dual_cc_library(
"@googletest//:gtest",
],
shared = [
":boot_data_header",
":error",
":nonce",
"//sw/device/lib/base:macros",
Expand Down Expand Up @@ -94,8 +102,8 @@ cc_library(
srcs = ["boot_log.c"],
hdrs = ["boot_log.h"],
deps = [
":boot_data",
":nonce",
":boot_data_header",
":nonce_header",
"//sw/device/lib/base:macros",
"//sw/device/silicon_creator/lib:chip_info",
"//sw/device/silicon_creator/lib:error",
Expand Down Expand Up @@ -451,11 +459,18 @@ cc_library(
hdrs = ["attestation.h"],
)

cc_library(
name = "nonce_header",
hdrs = ["nonce.h"],
)

cc_library(
name = "nonce",
srcs = ["nonce.c"],
hdrs = ["nonce.h"],
deps = ["//sw/device/silicon_creator/lib/drivers:rnd"],
deps = [
":nonce_header",
"//sw/device/silicon_creator/lib/drivers:rnd",
],
)

cc_library(
Expand Down
3 changes: 3 additions & 0 deletions sw/device/silicon_creator/lib/boot_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
#include "otp_ctrl_regs.h"

static_assert(kBootDataValidEntry ==
((uint64_t)kFlashCtrlErasedWord << 32 | kFlashCtrlErasedWord),
"kBootDataValidEntry words must be kFlashCtrlErasedWord");
static_assert(kBootDataEntriesPerPage ==
FLASH_CTRL_PARAM_BYTES_PER_PAGE / sizeof(boot_data_t),
"Number of boot data entries per page is incorrect");
Expand Down
4 changes: 0 additions & 4 deletions sw/device/silicon_creator/lib/boot_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define OPENTITAN_SW_DEVICE_SILICON_CREATOR_LIB_BOOT_DATA_H_

#include "sw/device/lib/base/macros.h"
#include "sw/device/silicon_creator/lib/drivers/flash_ctrl.h"
#include "sw/device/silicon_creator/lib/drivers/hmac.h"
#include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
#include "sw/device/silicon_creator/lib/error.h"
Expand Down Expand Up @@ -158,9 +157,6 @@ enum {
};
static_assert(kBootDataInvalidEntry != kBootDataValidEntry,
"Invalidation values cannot be equal.");
static_assert(kBootDataValidEntry ==
((uint64_t)kFlashCtrlErasedWord << 32 | kFlashCtrlErasedWord),
"kBootDataValidEntry words must be kFlashCtrlErasedWord");

/**
* Constants referring to EFLASH slots A and B.
Expand Down
4 changes: 2 additions & 2 deletions sw/device/silicon_creator/lib/boot_svc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ cc_library(
"//sw/device/lib/base:macros",
"//sw/device/lib/base:memory",
"//sw/device/silicon_creator/lib:error",
"//sw/device/silicon_creator/lib:nonce",
"//sw/device/silicon_creator/lib:nonce_header",
"//sw/device/silicon_creator/lib/base:chip",
"//sw/device/silicon_creator/lib/ownership:datatypes",
],
Expand All @@ -157,7 +157,7 @@ cc_library(
"//sw/device/lib/base:macros",
"//sw/device/lib/base:memory",
"//sw/device/silicon_creator/lib:error",
"//sw/device/silicon_creator/lib:nonce",
"//sw/device/silicon_creator/lib:nonce_header",
"//sw/device/silicon_creator/lib/base:chip",
"//sw/device/silicon_creator/lib/ownership:datatypes",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
#include "sw/device/silicon_creator/lib/boot_data.h"
#include "sw/device/silicon_creator/lib/drivers/flash_ctrl.h"
#include "sw/device/silicon_creator/lib/drivers/lifecycle.h"
#include "sw/device/silicon_creator/lib/drivers/rstmgr.h"
#include "sw/device/silicon_creator/lib/manifest_def.h"
Expand Down

0 comments on commit 1de7173

Please sign in to comment.