]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
board: samsung: e850-96: Setup serial# env var
authorSam Protsenko <semen.protsenko@linaro.org>
Wed, 9 Jul 2025 22:29:20 +0000 (17:29 -0500)
committerMinkyu Kang <mk7.kang@samsung.com>
Fri, 25 Jul 2025 01:17:21 +0000 (10:17 +0900)
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@linaro.org>
Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
board/samsung/e850-96/e850-96.c

index 3bbd95201b5fc3a4bc7ad8b5fcbda921a46bebb5..addfe0460973efd70ac564a68f967efd6fc6b85f 100644 (file)
@@ -4,9 +4,17 @@
  * Author: Sam Protsenko <semen.protsenko@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().