Skip to content

Commit b127e59

Browse files
committed
Improve key rotation error reporting in htool.
PiperOrigin-RevId: 808344093
1 parent 69661d3 commit b127e59

30 files changed

Lines changed: 1169 additions & 86 deletions

BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
2+
13
package(default_visibility = ["//visibility:public"])
24

35
cc_library(

examples/BUILD

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
2+
load("@rules_cc//cc:cc_library.bzl", "cc_library")
3+
14
package(default_visibility = ["//visibility:public"])
25

36
cc_library(
@@ -57,6 +60,8 @@ cc_binary(
5760
"htool_raw_host_command.h",
5861
"htool_rot_usb.c",
5962
"htool_rot_usb.h",
63+
"htool_secure_boot.c",
64+
"htool_secure_boot.h",
6065
"htool_spi.c",
6166
"htool_statistics.c",
6267
"htool_statistics.h",
@@ -85,6 +90,7 @@ cc_binary(
8590
"//protocol:progress",
8691
"//protocol:reboot",
8792
"//protocol:rot_firmware_version",
93+
"//protocol:secure_boot",
8894
"//protocol:spi_proxy",
8995
"//protocol:statistics",
9096
"//transports:libhoth_device",

examples/htool.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "htool_payload_update.h"
4141
#include "htool_raw_host_command.h"
4242
#include "htool_rot_usb.h"
43+
#include "htool_secure_boot.h"
4344
#include "htool_srtm.h"
4445
#include "htool_statistics.h"
4546
#include "htool_target_control.h"
@@ -1161,6 +1162,12 @@ static const struct htool_cmd CMDS[] = {
11611162
"device in chain",
11621163
.params =
11631164
(const struct htool_param[]){
1165+
{.type = HTOOL_FLAG_VALUE,
1166+
.ch = 'i',
1167+
.name = "jtag_interface_id",
1168+
.default_value = "0",
1169+
.desc = "JTAG interface ID (0/1) to send the host command "
1170+
"to."},
11641171
{.type = HTOOL_FLAG_VALUE,
11651172
.ch = 'd',
11661173
.name = "clk_idiv",
@@ -1177,6 +1184,12 @@ static const struct htool_cmd CMDS[] = {
11771184
"Assumes only a single device in chain",
11781185
.params =
11791186
(const struct htool_param[]){
1187+
{.type = HTOOL_FLAG_VALUE,
1188+
.ch = 'i',
1189+
.name = "jtag_interface_id",
1190+
.default_value = "0",
1191+
.desc = "JTAG interface ID (0/1) to send the host command "
1192+
"to."},
11801193
{.type = HTOOL_FLAG_VALUE,
11811194
.ch = 'd',
11821195
.name = "clk_idiv",
@@ -1211,6 +1224,12 @@ static const struct htool_cmd CMDS[] = {
12111224
"device in chain",
12121225
.params =
12131226
(const struct htool_param[]){
1227+
{.type = HTOOL_FLAG_VALUE,
1228+
.ch = 'i',
1229+
.name = "jtag_interface_id",
1230+
.default_value = "0",
1231+
.desc = "JTAG interface ID (0/1) to send the host command "
1232+
"to."},
12141233
{.type = HTOOL_FLAG_VALUE,
12151234
.ch = 'o',
12161235
.name = "offset",
@@ -1224,6 +1243,12 @@ static const struct htool_cmd CMDS[] = {
12241243
.desc = "Verify a PLD over JTAG. Assumes only a single device in chain",
12251244
.params =
12261245
(const struct htool_param[]){
1246+
{.type = HTOOL_FLAG_VALUE,
1247+
.ch = 'i',
1248+
.name = "jtag_interface_id",
1249+
.default_value = "0",
1250+
.desc = "JTAG interface ID (0/1) to send the host command "
1251+
"to."},
12271252
{.type = HTOOL_FLAG_VALUE,
12281253
.ch = 'o',
12291254
.name = "offset",
@@ -1393,6 +1418,39 @@ static const struct htool_cmd CMDS[] = {
13931418
{}},
13941419
.func = htool_key_rotation_chunk_type_count,
13951420
},
1421+
{
1422+
.verbs = (const char*[]){"key_rotation", "erase", "record", NULL},
1423+
.desc = "Erase the key rotation record from both halves of the flash "
1424+
"if the mauv allows",
1425+
.params = (const struct htool_param[]){{}},
1426+
.func = htool_key_rotation_erase_record,
1427+
},
1428+
{
1429+
.verbs = (const char*[]){"key_rotation", "set", "mauv", NULL},
1430+
.desc = "Set Key Rotation Record MAUV",
1431+
.params =
1432+
(const struct htool_param[]){
1433+
{HTOOL_FLAG_VALUE, 'm', "mauv", .desc = "MAUV to set"}, {}},
1434+
.func = htool_key_rotation_set_mauv,
1435+
},
1436+
{
1437+
.verbs = (const char*[]){"key_rotation", "get", "mauv", NULL},
1438+
.desc = "Get Key Rotation Record MAUV",
1439+
.params = (const struct htool_param[]){{}},
1440+
.func = htool_key_rotation_get_mauv,
1441+
},
1442+
{
1443+
.verbs = (const char*[]){"secure_boot", "get_enforcement", NULL},
1444+
.desc = "Get the current state of target secure boot enforcement.",
1445+
.params = (const struct htool_param[]){{}},
1446+
.func = htool_secure_boot_get_enforcement,
1447+
},
1448+
{
1449+
.verbs = (const char*[]){"secure_boot", "enable_enforcement", NULL},
1450+
.desc = "Enable secure boot enforcement.",
1451+
.params = (const struct htool_param[]){{}},
1452+
.func = htool_secure_boot_enable_enforcement,
1453+
},
13961454
{},
13971455
};
13981456

examples/htool_jtag.c

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
#include "protocol/host_cmd.h"
2626
#include "protocol/jtag.h"
2727

28-
// Used if no data is provided for data to send over TDI
29-
static char *JTAG_TEST_BYPASS_PATTERN_DEFAULT_VALUE =
28+
// Used if no data is provided for data to send over TDI. This needs to be
29+
// modifiable for use with `strtok_r` later
30+
static char JTAG_TEST_BYPASS_PATTERN_DEFAULT_VALUE[] =
3031
// PRBS9 with '0' bit added at the beginning to make it exactly 64 bytes
3132
"0x42 0x30 0x9c 0xab 0xd 0xe9 0xb9 0x14 0x2b 0x4f 0xd9 0x25 0xbf 0x26 0xa6 "
3233
"0x60 0x31 0x94 0x69 0x7f 0x45 0x8e 0xb2 0xcf 0x1f 0x74 0x1a 0xdb 0xb0 "
@@ -37,19 +38,27 @@ static char *JTAG_TEST_BYPASS_PATTERN_DEFAULT_VALUE =
3738
static int jtag_read_idcode(struct libhoth_device *dev,
3839
const struct htool_invocation *inv) {
3940
uint32_t clk_idiv;
41+
uint32_t interface_id;
4042

4143
if (htool_get_param_u32(inv, "clk_idiv", &clk_idiv)) {
4244
return -1;
4345
}
44-
4546
if (clk_idiv > UINT16_MAX) {
4647
fprintf(stderr, "Clock divisor value too large. Expected <= %u\n",
4748
UINT16_MAX);
4849
return -1;
4950
}
5051

52+
if (htool_get_param_u32(inv, "jtag_interface_id", &interface_id)) {
53+
return -1;
54+
}
55+
if (interface_id > UINT8_MAX) {
56+
fprintf(stderr, "Jtag ID value too large. Expected <= %u\n", UINT8_MAX);
57+
return -1;
58+
}
59+
5160
uint32_t idcode = 0;
52-
int ret = libhoth_jtag_read_idcode(dev, clk_idiv, &idcode);
61+
int ret = libhoth_jtag_read_idcode(dev, interface_id, clk_idiv, &idcode);
5362
if (ret != 0) {
5463
return ret;
5564
}
@@ -100,6 +109,7 @@ static int jtag_test_bypass(struct libhoth_device *dev,
100109
const struct htool_invocation *inv) {
101110
char *tdi_bytes_str = NULL;
102111
uint32_t clk_idiv;
112+
uint32_t interface_id;
103113

104114
if (htool_get_param_u32(inv, "clk_idiv", &clk_idiv) ||
105115
htool_get_param_string(inv, "tdi_bytes", (const char **)&tdi_bytes_str)) {
@@ -118,6 +128,14 @@ static int jtag_test_bypass(struct libhoth_device *dev,
118128
return -1;
119129
}
120130

131+
if (htool_get_param_u32(inv, "jtag_interface_id", &interface_id)) {
132+
return -1;
133+
}
134+
if (interface_id > UINT8_MAX) {
135+
fprintf(stderr, "Jtag ID value too large. Expected <= %u\n", UINT8_MAX);
136+
return -1;
137+
}
138+
121139
uint8_t tdi_bytes[HOTH_JTAG_TEST_BYPASS_PATTERN_LEN];
122140
int ret = parse_string_param_into_byte_sequence(
123141
tdi_bytes_str, tdi_bytes, HOTH_JTAG_TEST_BYPASS_PATTERN_LEN);
@@ -132,7 +150,8 @@ static int jtag_test_bypass(struct libhoth_device *dev,
132150
printf("\n");
133151

134152
uint8_t tdo_bytes[HOTH_JTAG_TEST_BYPASS_PATTERN_LEN] = {0};
135-
ret = libhoth_jtag_test_bypass(dev, clk_idiv, tdi_bytes, tdo_bytes);
153+
ret = libhoth_jtag_test_bypass(dev, interface_id, clk_idiv, tdi_bytes,
154+
tdo_bytes);
136155
if (ret != 0) {
137156
return ret;
138157
}
@@ -155,23 +174,41 @@ static int jtag_test_bypass(struct libhoth_device *dev,
155174
static int jtag_program_and_verify_pld(struct libhoth_device *dev,
156175
const struct htool_invocation *inv) {
157176
uint32_t offset;
177+
uint32_t interface_id;
158178

159179
if (htool_get_param_u32(inv, "offset", &offset)) {
160180
return -1;
161181
}
162182

163-
return libhoth_jtag_program_and_verify_pld(dev, offset);
183+
if (htool_get_param_u32(inv, "jtag_interface_id", &interface_id)) {
184+
return -1;
185+
}
186+
if (interface_id > UINT8_MAX) {
187+
fprintf(stderr, "Jtag ID value too large. Expected <= %u\n", UINT8_MAX);
188+
return -1;
189+
}
190+
191+
return libhoth_jtag_program_and_verify_pld(dev, interface_id, offset);
164192
}
165193

166194
static int jtag_verify_pld(struct libhoth_device *dev,
167195
const struct htool_invocation *inv) {
168196
uint32_t offset;
197+
uint32_t interface_id;
169198

170199
if (htool_get_param_u32(inv, "offset", &offset)) {
171200
return -1;
172201
}
173202

174-
return libhoth_jtag_verify_pld(dev, offset);
203+
if (htool_get_param_u32(inv, "jtag_interface_id", &interface_id)) {
204+
return -1;
205+
}
206+
if (interface_id > UINT8_MAX) {
207+
fprintf(stderr, "Jtag ID value too large. Expected <= %u\n", UINT8_MAX);
208+
return -1;
209+
}
210+
211+
return libhoth_jtag_verify_pld(dev, interface_id, offset);
175212
}
176213

177214
int htool_jtag_run(const struct htool_invocation *inv) {

0 commit comments

Comments
 (0)