Skip to content

Commit 8082056

Browse files
committed
[rescue] Format the serial number correctly
Format the USB-DFU rescue's `iSerial` serial number as a 64-bit hex integer. This is the same representation as the device identification number in `//sw/host/opentitanlib/src/chip/device_id.rs`. Signed-off-by: Chris Frantz <cfrantz@google.com>
1 parent 366cc8d commit 8082056

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sw/device/silicon_creator/lib/rescue/rescue_usb.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ static const char lang_id[] = {
7878
// clang-format off
7979
static const char str_vendor[] = { USB_STRING_DSCR('G','o','o','g','l','e'), };
8080
static const char str_opentitan[] = { USB_STRING_DSCR('O','p','e','n','T','i','t','a','n'), };
81-
static const char str_resq[] = { USB_STRING_DSCR('R','e','s','c','u','e') };
81+
static const char str_resq[] = { USB_STRING_DSCR('R','e','s','c','u','e',' ','S','l','o','t','A')};
8282
static const char str_resb[] = { USB_STRING_DSCR('R','e','s','c','u','e',' ','S','l','o','t','B')};
8383
static const char str_otid[] = { USB_STRING_DSCR('D','e','v','i','c','e','I','D') };
8484
static const char str_blog[] = { USB_STRING_DSCR('B','o','o','t','L','o','g') };
8585
static const char str_bsvc[] = { USB_STRING_DSCR('B','o','o','t','S','e','r','v','i','c','e','s') };
8686
static const char str_ownr[] = { USB_STRING_DSCR('O','w','n','e','r','s','h','i','p') };
8787

8888
// Located in RAM so we can fill in the OpenTitan device ID.
89-
static char str_serialnumber[2 + 32];
89+
static char str_serialnumber[2 + 4 + 32];
9090

9191
static const char *string_desc[] = {
9292
lang_id,
@@ -110,9 +110,17 @@ static void set_serialnumber(void) {
110110
const char hex[] = "0123456789ABCDEF";
111111

112112
char *sn = str_serialnumber;
113-
*sn++ = 2 + 32;
113+
// Length: descriptor header (2) + 2 * (len("0x") + len(64-bit integer)).
114+
*sn++ = 2 + 4 + 32;
115+
// Descriptor type: 3 (string descriptor).
114116
*sn++ = 3;
115-
for (size_t w = 1; w < 3; ++w) {
117+
// Leading "0x".
118+
*sn++ = '0';
119+
*sn++ = 0;
120+
*sn++ = 'x';
121+
*sn++ = 0;
122+
// The device identification number, printed in hex as a uint64_t.
123+
for (size_t w = 2; w > 0; --w) {
116124
uint8_t byte = (uint8_t)(dev.device_id[w] >> 24);
117125
*sn++ = hex[byte >> 4];
118126
*sn++ = 0;

0 commit comments

Comments
 (0)