stm32/usb: Add support for board-specific serial number

By default, read USB serial number from flash, but provide a way
for boards to override the function (e.g., to read serial number
from unique chip id).

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: I0917752bb8e04c1eff4dffc0b3714f63dcd942b0
Reviewed-on: https://chromium-review.googlesource.com/523045
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Nicolas Boichat
2017-06-03 12:06:37 +08:00
committed by chrome-bot
parent 8ba7c1762c
commit d132e5ecbd
3 changed files with 22 additions and 2 deletions

View File

@@ -657,13 +657,20 @@ static int usb_set_serial(const char *serialno)
return EC_SUCCESS;
}
/* By default, read serial number from flash, can be overridden. */
__attribute__((weak))
const char *board_read_serial(void)
{
return flash_read_serial();
}
/* Retrieve serial number from pstate flash. */
static int usb_load_serial(void)
{
const char *serialno;
int rv;
serialno = flash_read_serial();
serialno = board_read_serial();
if (!serialno)
return EC_ERROR_ACCESS_DENIED;

View File

@@ -1371,13 +1371,20 @@ static int usb_set_serial(const char *serialno)
return EC_SUCCESS;
}
/* By default, read serial number from flash, can be overridden. */
__attribute__((weak))
const char *board_read_serial(void)
{
return flash_read_serial();
}
/* Retrieve serial number from pstate flash. */
static int usb_load_serial(void)
{
const char *serialno;
int rv;
serialno = flash_read_serial();
serialno = board_read_serial();
if (!serialno)
return EC_ERROR_ACCESS_DENIED;

View File

@@ -285,6 +285,12 @@ const char *system_get_chip_revision(void);
*/
int system_get_chip_unique_id(uint8_t **id);
/**
* Optional board-level callback functions to read a unique serial number per
* chip. Default implementation reads from flash (flash_read_serial).
*/
const char *board_read_serial(void) __attribute__((weak));
/*
* Common bbram entries. Chips don't necessarily need to implement
* all of these, error will be returned from system_get/set_bbram if