Skip to content

Commit 65d370d

Browse files
[bazel] bump OT repo version
This bumps the lowrisc_opentitan bazel repo version, and subsequently the OpenTitan provisioning firmware and bitstream dependencies. Additionally, this adds a CRC computation to the RMA unlock token message as the latest version of the personalization firmware now requires the host to send a valid CRC with the RMA unlock token JSON message. Signed-off-by: Tim Trippel <ttrippel@google.com>
1 parent 24f56e8 commit 65d370d

File tree

9 files changed

+66
-12
lines changed

9 files changed

+66
-12
lines changed

src/ate/ate_api.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,11 @@ DLLEXPORT int DeviceIdFromJson(const dut_spi_frame_t* frame,
630630
*
631631
* @param rma_token The RMA token.
632632
* @param[out] result The generated JSON command.
633+
* @param skip_crc Whether or not to skip attaching of the CRC.
633634
* @return The result of the operation.
634635
*/
635-
DLLEXPORT int RmaTokenToJson(const token_t* rma_token, dut_spi_frame_t* result);
636+
DLLEXPORT int RmaTokenToJson(const token_t* rma_token, dut_spi_frame_t* result,
637+
bool skip_crc);
636638

637639
/**
638640
* Parse JSON command to extract the RMA token from the SPI frame.

src/ate/ate_api_json_commands.cc

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <algorithm>
88

99
#include "absl/log/log.h"
10+
#include "absl/strings/str_format.h"
1011
#include "src/ate/ate_api.h"
1112
#include "src/ate/proto/dut_commands.pb.h"
1213

@@ -48,6 +49,51 @@ inline uint64_t ByteSwap64(uint64_t value) {
4849
((value & 0x00000000000000FFULL) << 56);
4950
}
5051

52+
/**
53+
* Table to store the pre-computed CRC values for each possible 8-bit byte.
54+
*/
55+
static uint32_t crc32_table[256];
56+
57+
/**
58+
* Flag to ensure the table is initialized only once.
59+
*/
60+
static bool crc32_table_initialized = false;
61+
62+
// Function to initialize the CRC32 lookup table
63+
void InitCrc32Table(void) {
64+
if (crc32_table_initialized) {
65+
// Table already initialized.
66+
return;
67+
}
68+
constexpr uint32_t kCrc32Polynomial =
69+
0xEDB88320; // CRC-32 reversed polynomial.
70+
71+
for (size_t i = 0; i < 256; ++i) {
72+
uint32_t c = (uint32_t)i;
73+
for (size_t j = 0; j < 8; ++j) {
74+
if (c & 1) {
75+
c = kCrc32Polynomial ^ (c >> 1);
76+
} else {
77+
c = c >> 1;
78+
}
79+
}
80+
crc32_table[i] = c;
81+
}
82+
crc32_table_initialized = true;
83+
}
84+
85+
uint32_t CalculateCrc32(const char *data, size_t length) {
86+
// Ensure the CRC32 table is initialized before calculation.
87+
if (!crc32_table_initialized) {
88+
InitCrc32Table();
89+
}
90+
uint32_t crc = 0xFFFFFFFF;
91+
for (size_t i = 0; i < length; i++) {
92+
crc = crc32_table[(crc ^ data[i]) & 0xFF] ^ (crc >> 8);
93+
}
94+
return crc ^ 0xFFFFFFFF;
95+
}
96+
5197
} // namespace
5298

5399
DLLEXPORT int TokensToJson(const token_t *wafer_auth_secret,
@@ -138,8 +184,8 @@ DLLEXPORT int DeviceIdFromJson(const dut_spi_frame_t *frame,
138184
return 0;
139185
}
140186

141-
DLLEXPORT int RmaTokenToJson(const token_t *rma_token,
142-
dut_spi_frame_t *result) {
187+
DLLEXPORT int RmaTokenToJson(const token_t *rma_token, dut_spi_frame_t *result,
188+
bool skip_crc) {
143189
if (result == nullptr) {
144190
LOG(ERROR) << "Invalid result buffer";
145191
return -1;
@@ -164,6 +210,11 @@ DLLEXPORT int RmaTokenToJson(const token_t *rma_token,
164210
google::protobuf::util::Status status =
165211
google::protobuf::util::MessageToJsonString(rma_hash_cmd, &command,
166212
options);
213+
if (!skip_crc) {
214+
// The personalization firmware expects a CRC on this JSON payload.
215+
uint32_t crc = CalculateCrc32(command.data(), command.length());
216+
command += absl::StrFormat("{\"crc\": %d}", crc);
217+
}
167218
if (!status.ok()) {
168219
LOG(ERROR) << "Failed to convert token hash command to JSON: "
169220
<< status.ToString();

src/ate/ate_api_json_commands_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ TEST_F(AteJsonTest, RmaToken) {
104104
rma_token.data[1] = 0x22;
105105

106106
dut_spi_frame_t frame;
107-
EXPECT_EQ(RmaTokenToJson(&rma_token, &frame), 0);
107+
EXPECT_EQ(RmaTokenToJson(&rma_token, &frame, /*skip_crc=*/true), 0);
108108

109109
std::string json_string =
110110
std::string(reinterpret_cast<char*>(frame.payload), frame.cursor);

src/ate/test_programs/ft.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ int main(int argc, char **argv) {
233233
return -1;
234234
}
235235
dut_spi_frame_t rma_token_spi_frame;
236-
if (RmaTokenToJson(&rma_token, &rma_token_spi_frame) != 0) {
236+
if (RmaTokenToJson(&rma_token, &rma_token_spi_frame, /*skip_crc=*/false) !=
237+
0) {
237238
LOG(ERROR) << "RmaTokenToJson failed.";
238239
return -1;
239240
}

third_party/lowrisc/ot_bitstreams/build-ot-bitstreams.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fi
1919

2020
OT_REPO_TOP=$1
2121

22-
_OT_REPO_BRANCH="Earlgrey-A2-Orchestrator-RC1"
22+
_OT_REPO_BRANCH="Earlgrey-A2-Orchestrator-RC2"
2323
_PROVISIONING_REPO_TOP=$(pwd)
2424
_FPGAS=("hyper310" "cw340")
2525
_CP_SKUS=("emulation")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:744cf7e2562ac5a430cdb1f4b96d9cfb4b133a8b590f5b5981bc94b808f15157
2+
oid sha256:28d334cd26a2db68ba5187545b208e3a578534303dba54a7f343572288b69da0
33
size 15878032
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:7fc14b448d75f893935cefa8b0cab5648806cf9b282792fafc8ea775304ead15
2+
oid sha256:cf919e400708298d4e895bc6dc1cdc12ebde1a9ac986446097135010a8400e2a
33
size 35843488
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:f5420d905311b189449f00b6a14fdc787aa72a8dfd08186a22451a91f19e4aa2
3-
size 112425426
2+
oid sha256:5098ee556ecd5067cc03dd8a2da84d51caa1e460edf49bce63212040d2da6774
3+
size 112565360

third_party/lowrisc/repos.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _BAZEL_SKYLIB_VERSION = "1.7.1"
1212
# When updating the lowrisc_opentitan repo, be sure to rebuild the builtstream
1313
# files too by following the instructions in
1414
# `third_party/lowrisc/README.md`.
15-
_OPENTITAN_VERSION = "Earlgrey-A2-Orchestrator-RC1"
15+
_OPENTITAN_VERSION = "Earlgrey-A2-Orchestrator-RC2"
1616

1717
def lowrisc_repos(misc_linters = None, bazel_release = None, bazel_skylib = None, opentitan = None):
1818
maybe(
@@ -45,7 +45,7 @@ def lowrisc_repos(misc_linters = None, bazel_release = None, bazel_skylib = None
4545
http_archive_or_local,
4646
local = opentitan,
4747
name = "lowrisc_opentitan",
48-
sha256 = "7ea956946e7898cd85baadcf6ebb7263fb2ac82b65b3b6555a0bc3a1fdc311f4",
48+
sha256 = "f5d67e2c057ebdc5f42fab286076f8b69fba7e21d1ff105a2ddb3a61f415e11e",
4949
strip_prefix = "opentitan-{}".format(_OPENTITAN_VERSION),
5050
url = "https://github.com/lowRISC/opentitan/archive/refs/tags/{}.tar.gz".format(_OPENTITAN_VERSION),
5151
)

0 commit comments

Comments
 (0)