]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
imx: kontron-sl-mx8mm: Add support for reading HW UIDs
authorFrieder Schrempf <frieder.schrempf@kontron.de>
Tue, 4 Nov 2025 12:54:28 +0000 (13:54 +0100)
committerFabio Estevam <festevam@nabladev.com>
Tue, 4 Nov 2025 15:46:11 +0000 (12:46 -0300)
The factory provides a CPU UID in the OTPs and the SoM module
and the carrier board might provide additional UIDs in the GP
registers of the OTPs. Load these values in the following order
and create a serial number string:

* Board UID (GP2)
* SoM UID (GP1)
* CPU UID (UNIQUE_ID)

The string is stored in the "serial#" env variable and
exported to Linux. Further this prints the used UID to the
console which looks like this

  ID:    0042152331 (Board)

or:

  ID:    0030124840 (SoM)

or:

  ID:    4696668CD9516886 (CPU)

Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
board/kontron/sl-mx8mm/Kconfig
board/kontron/sl-mx8mm/sl-mx8mm.c
configs/kontron-sl-mx8mm_defconfig

index 1597bcf894df4edc78e4ab3c416e4acb7ce953f2..0a5123d297906aeae62de194cd035aed348f9fe9 100644 (file)
@@ -9,4 +9,6 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
        default "kontron-sl-mx8mm"
 
+source "board/kontron/common/Kconfig"
+
 endif
index df92765cb2db7bc90652ab12583e77f81d2f1dd4..d24d5286e457a8344ba10b1d125ae7d46dde7645 100644 (file)
 #include <mmc.h>
 #include <net.h>
 
+#include "../common/hw-uid.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
+#if IS_ENABLED(CONFIG_KONTRON_HW_UID)
+
+struct uid_otp_loc uid_otp_locations[] = {
+       {
+               .addr = (u32 *)(OCOTP_BASE_ADDR + 0x7A0),
+               .len = 2,
+               .format = UID_OTP_FORMAT_DEC,
+               .desc = "BOARD"
+       },
+       {
+               .addr = (u32 *)(OCOTP_BASE_ADDR + 0x780),
+               .len = 2,
+               .format = UID_OTP_FORMAT_DEC,
+               .desc = "SOM"
+       },
+#if IS_ENABLED(CONFIG_KONTRON_HW_UID_USE_SOC_FALLBACK)
+       {
+               .addr = (u32 *)(OCOTP_BASE_ADDR + 0x410),
+               .len = 2,
+               .format = UID_OTP_FORMAT_HEX,
+               .desc = "SOC"
+       }
+#endif
+};
+
+#endif /* CONFIG_KONTRON_HW_UID */
+
 #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
 struct efi_fw_image fw_images[] = {
        {
@@ -167,6 +196,9 @@ int board_late_init(void)
                env_set("touch_rst_gpio", "87");
        }
 
+       if (IS_ENABLED(CONFIG_KONTRON_HW_UID))
+               get_serial_number(uid_otp_locations, ARRAY_SIZE(uid_otp_locations));
+
        if (is_usb_boot()) {
                env_set("bootcmd", "fastboot 0");
                env_set("bootdelay", "0");
index 42346a305f929c5dfca181bd29d26a1262dca55f..ed60d3b9ce40df656ee5628f44abc0193a11f9f7 100644 (file)
@@ -11,6 +11,7 @@ CONFIG_ENV_OFFSET=0x1E0000
 CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_IMX_CONFIG="board/kontron/sl-mx8mm/imximage.cfg"
 CONFIG_DM_GPIO=y
+CONFIG_KONTRON_HW_UID=y
 CONFIG_SPL_DM_SPI=y
 CONFIG_DEFAULT_DEVICE_TREE="freescale/imx8mm-kontron-bl"
 CONFIG_TARGET_KONTRON_MX8MM=y