Obtain the board serial number from OTP. Make it visible in the
'serial#' environment variable, and also in DFU/fastboot/UMS mode.

This helps to distinguish multiple boards connected to the same LAVA
controller.

Signed-off-by: Ralph Siemsen <[email protected]>
---
 board/schneider/rzn1-snarc/rzn1.c | 25 +++++++++++++++++++++++++
 include/configs/rzn1-snarc.h      |  5 +++++
 2 files changed, 30 insertions(+)

diff --git a/board/schneider/rzn1-snarc/rzn1.c 
b/board/schneider/rzn1-snarc/rzn1.c
index e1d5b5b0497..38aa2ed9d4e 100644
--- a/board/schneider/rzn1-snarc/rzn1.c
+++ b/board/schneider/rzn1-snarc/rzn1.c
@@ -1,11 +1,21 @@
 // SPDX-License-Identifier: GPL-2.0+
 
+#include <asm/io.h>
+#include <configs/rzn1-snarc.h>
 #include <dm.h>
+#include <env.h>
+#include <g_dnl.h>
 #include <ram.h>
 #include <asm/global_data.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
+static inline uint32_t hosted_readl(uint32_t addr)
+{
+       /* No hypervisor yet, just do a direct read */
+       return readl(addr);
+}
+
 int board_init(void)
 {
        gd->bd->bi_boot_params = gd->ram_base + 0x100;
@@ -13,6 +23,21 @@ int board_init(void)
        return 0;
 }
 
+int board_late_init(void)
+{
+       char serial_string[32];
+
+       /* Obtain serial number from OTP */
+       snprintf(serial_string, sizeof(serial_string),
+                "LCES2-0x%08x%08x",
+                hosted_readl(RZN1_SERIAL_LOW),
+                hosted_readl(RZN1_SERIAL_HIGH));
+       env_set("serial#", serial_string);
+       g_dnl_set_serialnumber((char *)serial_string);
+
+       return 0;
+}
+
 int dram_init(void)
 {
        struct udevice *dev;
diff --git a/include/configs/rzn1-snarc.h b/include/configs/rzn1-snarc.h
index 9fee2ece54a..75fada671af 100644
--- a/include/configs/rzn1-snarc.h
+++ b/include/configs/rzn1-snarc.h
@@ -10,4 +10,9 @@
 #define CFG_SYS_INIT_RAM_ADDR  0x20000000
 #define CFG_SYS_INIT_RAM_SIZE  (1 * 1024 * 1024)
 
+/* One-time programmable OTP */
+#define RZN1_OTP_BASE          0x40007000
+#define   RZN1_SERIAL_LOW      (RZN1_OTP_BASE + 0x08)
+#define   RZN1_SERIAL_HIGH     (RZN1_OTP_BASE + 0x0c)
+
 #endif /* __RZN1_SNARC_H */

-- 
2.55.0

Reply via email to