summaryrefslogtreecommitdiff
path: root/common/system.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2017-07-20 09:48:50 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-07-28 17:45:13 -0700
commit1b25735b732e7766aceb3f060e4ca205aba6d358 (patch)
tree4ac67bc0f1e1449177698490b49be94f54cf2c59 /common/system.c
parent734ebcbbb4e1e6f816225c59acef08ebd1094a2c (diff)
downloadchrome-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 'common/system.c')
-rw-r--r--common/system.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/common/system.c b/common/system.c
index 1f9a2062c1..dae29d159c 100644
--- a/common/system.c
+++ b/common/system.c
@@ -17,6 +17,7 @@
#include "host_command.h"
#include "i2c.h"
#include "lpc.h"
+#include "otp.h"
#include "rwsig.h"
#include "spi_flash.h"
#ifdef CONFIG_MPU
@@ -1321,3 +1322,34 @@ int system_can_boot_ap(void)
return power_good;
}
+
+#ifdef CONFIG_SERIALNO_LEN
+/* By default, read serial number from flash, can be overridden. */
+#if defined(CONFIG_FLASH_PSTATE) && defined(CONFIG_FLASH_PSTATE_BANK)
+__attribute__((weak))
+const char *board_read_serial(void)
+{
+ return flash_read_pstate_serial();
+}
+#elif defined(CONFIG_OTP)
+__attribute__((weak))
+const char *board_read_serial(void)
+{
+ return otp_read_serial();
+}
+#endif
+
+#if defined(CONFIG_FLASH_PSTATE) && defined(CONFIG_FLASH_PSTATE_BANK)
+__attribute__((weak))
+int board_write_serial(const char *serialno)
+{
+ return flash_write_pstate_serial(serialno);
+}
+#elif defined(CONFIG_OTP)
+__attribute__((weak))
+int board_write_serial(const char *serialno)
+{
+ return otp_write_serial(serialno);
+}
+#endif
+#endif /* CONFIG_SERIALNO_LEN */