[PATCH 3/9] board: samsung: e850-96: Setup serial# env var
Sam Protsenko
semen.protsenko at linaro.org
Thu Jul 10 00:29:20 CEST 2025
Setup "serial#" environment variable from the chip ID. The chip ID is
read from Exynos850 SoC OTP (One Time Programmable) memory, which acts
like an EEPROM and contains unique SoC ID. This "serial#" variable is
further used for "fastboot devices" serial number, etc.
Signed-off-by: Sam Protsenko <semen.protsenko at linaro.org>
---
board/samsung/e850-96/e850-96.c | 37 +++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/board/samsung/e850-96/e850-96.c b/board/samsung/e850-96/e850-96.c
index 3bbd95201b5f..addfe0460973 100644
--- a/board/samsung/e850-96/e850-96.c
+++ b/board/samsung/e850-96/e850-96.c
@@ -4,9 +4,17 @@
* Author: Sam Protsenko <semen.protsenko at linaro.org>
*/
+#include <env.h>
#include <init.h>
+#include <mapmem.h>
+#include <asm/io.h>
#include "fw.h"
+/* OTP Controller base address and register offsets */
+#define EXYNOS850_OTP_BASE 0x10000000
+#define OTP_CHIPID0 0x4
+#define OTP_CHIPID1 0x8
+
int dram_init(void)
{
return fdtdec_setup_mem_size_base();
@@ -17,6 +25,33 @@ int dram_init_banksize(void)
return fdtdec_setup_memory_banksize();
}
+/* Read the unique SoC ID from OTP registers */
+static u64 get_chip_id(void)
+{
+ void __iomem *otp_base;
+ u64 val;
+
+ otp_base = map_sysmem(EXYNOS850_OTP_BASE, 12);
+ val = readl(otp_base + OTP_CHIPID0);
+ val |= (u64)readl(otp_base + OTP_CHIPID1) << 32UL;
+ unmap_sysmem(otp_base);
+
+ return val;
+}
+
+static void setup_serial(void)
+{
+ char serial_str[17] = { 0 };
+ u64 serial_num;
+
+ if (env_get("serial#"))
+ return;
+
+ serial_num = get_chip_id();
+ snprintf(serial_str, sizeof(serial_str), "%016llx", serial_num);
+ env_set("serial#", serial_str);
+}
+
int board_init(void)
{
return 0;
@@ -26,6 +61,8 @@ int board_late_init(void)
{
int err;
+ setup_serial();
+
/*
* Do this in board_late_init() to make sure MMC is not probed before
* efi_init_early().
--
2.39.5
More information about the U-Boot
mailing list