diff options
author | Nicolas Boichat <drinkcat@google.com> | 2017-06-02 22:46:29 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-06-13 21:23:56 -0700 |
commit | d5bb8390a8f7b27d55d96b14dcaa928dfff4c59d (patch) | |
tree | 5473df6a7a00cf7244dbadfd3c03debcad6c2afa | |
parent | d132e5ecbd93fa598fc495ec90718ea853962ef7 (diff) | |
download | chrome-ec-d5bb8390a8f7b27d55d96b14dcaa928dfff4c59d.tar.gz |
hammer: Use unique board ID to generate USB serial number
BRANCH=none
BUG=b:62280271
TEST=Flash hammer
lsusb -d 18d1:5022 -v -v | grep iSerial
shows different chip IDs on different boards.
Change-Id: I249967df133a8aa8a2b5c570fb940dd03fae4169
Reviewed-on: https://chromium-review.googlesource.com/523046
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/hammer/board.c | 24 | ||||
-rw-r--r-- | board/hammer/board.h | 7 |
2 files changed, 26 insertions, 5 deletions
diff --git a/board/hammer/board.c b/board/hammer/board.c index b9f21acf1d..f3d32f468c 100644 --- a/board/hammer/board.c +++ b/board/hammer/board.c @@ -13,10 +13,12 @@ #include "i2c.h" #include "keyboard_raw.h" #include "keyboard_scan.h" +#include "printf.h" #include "pwm.h" #include "pwm_chip.h" #include "registers.h" #include "rollback.h" +#include "system.h" #include "task.h" #include "timer.h" #include "update_fw.h" @@ -164,3 +166,25 @@ int board_get_entropy(void *buffer, int len) return 1; } + +/* + * Generate a USB serial number from unique chip ID. + */ +const char *board_read_serial(void) +{ + static char str[USB_STRING_LEN]; + + if (str[0] == '\0') { + uint8_t *id; + int pos = 0; + int idlen = system_get_chip_unique_id(&id); + int i; + + for (i = 0; i < idlen && pos < sizeof(str); i++, pos += 2) { + snprintf(&str[pos], sizeof(str)-pos, + "%02x", id[i]); + } + } + + return str; +} diff --git a/board/hammer/board.h b/board/hammer/board.h index a003bcb6c5..ac87d9b2a2 100644 --- a/board/hammer/board.h +++ b/board/hammer/board.h @@ -94,11 +94,8 @@ #define CONFIG_USB_SUSPEND #define CONFIG_USB_SERIALNO -/* TODO(drinkcat): Replace this by proper serial number. Note that according to - * USB standard, we must either unset this (iSerialNumber = 0), or have a unique - * serial number per device. - */ -#define DEFAULT_SERIALNO "Uninitialized" +/* Replaced at runtime (board_read_serial) by chip unique-id-based number. */ +#define DEFAULT_SERIALNO "" /* USB interface indexes (use define rather than enum to expand them) */ #ifdef SECTION_IS_RW |