diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2017-07-20 09:48:50 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-07-28 17:45:13 -0700 |
commit | 1b25735b732e7766aceb3f060e4ca205aba6d358 (patch) | |
tree | 4ac67bc0f1e1449177698490b49be94f54cf2c59 /chip/stm32 | |
parent | 734ebcbbb4e1e6f816225c59acef08ebd1094a2c (diff) | |
download | chrome-ec-1b25735b732e7766aceb3f060e4ca205aba6d358.tar.gz |
Add OTP support
One Time Programmable memory can be used to store permanent data like
serial numbers.
Reorganize the code to support writing serial number to OTP, in
addition to pstate (if using its own memory bank) or autogenerate from
unique id (hammer).
+ Add CONFIG_OTP to enable OTP code
+ Add CONFIG_SERIALNO_LEN to indicate the size of the serial number
string. Currently set to 28, when USB serial number is needed.
+ Expose flash_read|write_pstate_serial and add otp_read|write_serail,
remove more generic flash_read|write_serial.
+ Make board_read|write_serial generic, declared outside of USB subsystem.
Priority order to read|write serial string:
- board definition (like hammer)
- pstate location, if stored in its private memory bank
- otp area
If none of these methods are available, a compilation error is raised.
BUG=chromium:746471
BRANCH=none
TEST=compile
Change-Id: I3d16125a6c0f424fb30e38123e63cf074b3cb2d3
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/580289
Reviewed-by: Nick Sanders <nsanders@chromium.org>
Diffstat (limited to 'chip/stm32')
-rw-r--r-- | chip/stm32/usb.c | 17 | ||||
-rw-r--r-- | chip/stm32/usb_dwc.c | 19 |
2 files changed, 10 insertions, 26 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c index 5788873df0..fa292d7aca 100644 --- a/chip/stm32/usb.c +++ b/chip/stm32/usb.c @@ -645,7 +645,7 @@ static int usb_set_serial(const char *serialno) return EC_ERROR_INVAL; /* Convert into unicode usb string desc. */ - for (i = 0; i < USB_STRING_LEN; i++) { + for (i = 0; i < CONFIG_SERIALNO_LEN; i++) { sd->_data[i] = serialno[i]; if (serialno[i] == 0) break; @@ -657,13 +657,6 @@ 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) { @@ -687,7 +680,7 @@ static int usb_save_serial(const char *serialno) return EC_ERROR_INVAL; /* Save this new serial number to flash. */ - rv = flash_write_serial(serialno); + rv = board_write_serial(serialno); if (rv) return rv; @@ -699,7 +692,7 @@ static int usb_save_serial(const char *serialno) static int command_serialno(int argc, char **argv) { struct usb_string_desc *sd = usb_serialno_desc; - char buf[USB_STRING_LEN]; + char buf[CONFIG_SERIALNO_LEN]; int rv = EC_SUCCESS; int i; @@ -716,7 +709,7 @@ static int command_serialno(int argc, char **argv) return EC_ERROR_INVAL; } - for (i = 0; i < USB_STRING_LEN; i++) + for (i = 0; i < CONFIG_SERIALNO_LEN; i++) buf[i] = sd->_data[i]; ccprintf("Serial number: %s\n", buf); return rv; @@ -725,4 +718,4 @@ static int command_serialno(int argc, char **argv) DECLARE_CONSOLE_COMMAND(serialno, command_serialno, "load/set [value]", "Read and write USB serial number"); -#endif +#endif /* CONFIG_USB_SERIALNO */ diff --git a/chip/stm32/usb_dwc.c b/chip/stm32/usb_dwc.c index fa5797079a..4d5a1db506 100644 --- a/chip/stm32/usb_dwc.c +++ b/chip/stm32/usb_dwc.c @@ -1359,7 +1359,7 @@ static int usb_set_serial(const char *serialno) return EC_ERROR_INVAL; /* Convert into unicode usb string desc. */ - for (i = 0; i < USB_STRING_LEN; i++) { + for (i = 0; i < CONFIG_SERIALNO_LEN; i++) { sd->_data[i] = serialno[i]; if (serialno[i] == 0) break; @@ -1371,13 +1371,6 @@ 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) { @@ -1392,7 +1385,6 @@ static int usb_load_serial(void) return rv; } - /* Save serial number into pstate region. */ static int usb_save_serial(const char *serialno) { @@ -1402,7 +1394,7 @@ static int usb_save_serial(const char *serialno) return EC_ERROR_INVAL; /* Save this new serial number to flash. */ - rv = flash_write_serial(serialno); + rv = board_write_serial(serialno); if (rv) return rv; @@ -1414,7 +1406,7 @@ static int usb_save_serial(const char *serialno) static int command_serialno(int argc, char **argv) { struct usb_string_desc *sd = usb_serialno_desc; - char buf[USB_STRING_LEN]; + char buf[CONFIG_SERIALNO_LEN]; int rv = EC_SUCCESS; int i; @@ -1431,7 +1423,7 @@ static int command_serialno(int argc, char **argv) return EC_ERROR_INVAL; } - for (i = 0; i < USB_STRING_LEN; i++) + for (i = 0; i < CONFIG_SERIALNO_LEN; i++) buf[i] = sd->_data[i]; ccprintf("Serial number: %s\n", buf); return rv; @@ -1440,5 +1432,4 @@ static int command_serialno(int argc, char **argv) DECLARE_CONSOLE_COMMAND(serialno, command_serialno, "load/set [value]", "Read and write USB serial number"); -#endif - +#endif /* CONFIG_USB_SERIALNO */ |