Skip to contentSkip to conversation

imx: kontron: Add support for HW UIDs in OTPs

PATCH Applied Frieder Schrempf 2 participants 6 messages Nov 4, 2025

lore
Share & tools
lore
#0 lore raw

cover imx: kontron: Add support for HW UIDs in OTPs

From: Frieder Schrempf <[email protected]>

SoMs and boards that are manufactured at Kontron Electronics Germany (KED) get UIDs programmed to the OTP fuses. This adds support for extracting them from the fuses and exporting them to the serial console and Linux.

Frieder Schrempf (4):
imx: kontron-sl-mx6ul: Enable CONFIG_BOARD_LATE_INIT to fix auto
fastboot
imx: kontron: Add common function to get HW UIDs from OTPs
imx: kontron-sl-mx6ul: Add support for reading HW UIDs
imx: kontron-sl-mx8mm: Add support for reading HW UIDs

 board/kontron/common/Kconfig       | 14 ++++++
 board/kontron/common/Makefile      |  1 +
 board/kontron/common/hw-uid.c      | 75 ++++++++++++++++++++++++++++++
 board/kontron/common/hw-uid.h      | 26 +++++++++++
 board/kontron/sl-mx6ul/Kconfig     |  2 +
 board/kontron/sl-mx6ul/sl-mx6ul.c  | 32 +++++++++++++
 board/kontron/sl-mx8mm/Kconfig     |  2 +
 board/kontron/sl-mx8mm/sl-mx8mm.c  | 32 +++++++++++++
 configs/kontron-sl-mx6ul_defconfig |  2 +
 configs/kontron-sl-mx8mm_defconfig |  1 +
 10 files changed, 187 insertions(+)
 create mode 100644 board/kontron/common/Kconfig
 create mode 100644 board/kontron/common/Makefile
 create mode 100644 board/kontron/common/hw-uid.c
 create mode 100644 board/kontron/common/hw-uid.h
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/4 imx: kontron-sl-mx6ul: Enable CONFIG_BOARD_LATE_INIT to fix auto fastboot

From: Frieder Schrempf <[email protected]>

Recently code was added in board_late_init() to autostart fastboot in case of booting from USB OTG. This change was ineffective as enabling CONFIG_BOARD_LATE_INIT got lost during upstreaming.

Fixes 410d9ccc0388 ("imx: kontron-sl-mx6ul: Autostart fastboot if booted from USB")
---
 configs/kontron-sl-mx6ul_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/kontron-sl-mx6ul_defconfig +1 -0
index 8e35d894dae..9f7003bf54c 100644
@@ -34,6 +34,7 @@ CONFIG_SYS_PBSIZE=532
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 CONFIG_BOARD_TYPES=y
 CONFIG_BOARD_EARLY_INIT_F=y
+CONFIG_BOARD_LATE_INIT=y
 CONFIG_SPL_RAW_IMAGE_SUPPORT=y
 CONFIG_SPL_LEGACY_IMAGE_FORMAT=y
 CONFIG_SPL_LEGACY_IMAGE_CRC_CHECK=y
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/4 imx: kontron: Add common function to get HW UIDs from OTPs

In reply to Frieder Schrempf

From: Frieder Schrempf <[email protected]>

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.

Provide a common function to load UIDs from arbitrary OTP registers and generate a serial number string that is saved in the "serial#" env variable.

---
 board/kontron/common/Kconfig  | 14 +++++++
 board/kontron/common/Makefile |  1 +
 board/kontron/common/hw-uid.c | 75 +++++++++++++++++++++++++++++++++++
 board/kontron/common/hw-uid.h | 26 ++++++++++++
 4 files changed, 116 insertions(+)
 create mode 100644 board/kontron/common/Kconfig
 create mode 100644 board/kontron/common/Makefile
 create mode 100644 board/kontron/common/hw-uid.c
 create mode 100644 board/kontron/common/hw-uid.h
board/kontron/common/Kconfig new file +14 -0
new file mode 100644
index 00000000000..d581006c203
@@ -0,0 +1,14 @@
+menuconfig KONTRON_HW_UID
+	bool "Enable reading Kontron HW UID from OTP fuses"
+	help
+	  Enable support for reading Kontron hardware UIDs from OTP fuse registers.
+	  The UIDs are factory-programmed for SoMs and boards and are printed to the
+	  console and used as serial numbers if this option is enabled.
+
+menuconfig KONTRON_HW_UID_USE_SOC_FALLBACK
+	bool "Use the unique ID of the SoC as fallback serial number"
+	depends on KONTRON_HW_UID
+	default n
+	help
+	  Enable the fallback to the UID of the SoC programmed by the SoC
+	  manufacturer if no Kontron UID is found in the OTP fuses.
board/kontron/common/Makefile new file +1 -0
new file mode 100644
index 00000000000..634744dc542
@@ -0,0 +1 @@
+obj-$(CONFIG_KONTRON_HW_UID) += hw-uid.o
board/kontron/common/hw-uid.c new file +75 -0

75 lines not on this page · raw message

board/kontron/common/hw-uid.h new file +26 -0
new file mode 100644
index 00000000000..7eaf2cc9b6c
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2024 Kontron Electronics GmbH
+ */
+
+#ifndef _KONTRON_HW_UID_H
+#define _KONTRON_HW_UID_H
+
+#include <compiler.h>
+#include <stddef.h>
+
+enum {
+	UID_OTP_FORMAT_DEC = 0,
+	UID_OTP_FORMAT_HEX,
+};
+
+struct uid_otp_loc {
+	u32 *addr;
+	size_t len;
+	unsigned int format;
+	char *desc;
+};
+
+void get_serial_number(struct uid_otp_loc *locs, unsigned int num);
+
+#endif /* _KONTRON_HW_UID_H */
Signature · 1 line
2.51.0
#3 lore raw

PATCH 3/4 imx: kontron-sl-mx6ul: Add support for reading HW UIDs

In reply to Frieder Schrempf

From: Frieder Schrempf <[email protected]>

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)

---
 board/kontron/sl-mx6ul/Kconfig     |  2 ++
 board/kontron/sl-mx6ul/sl-mx6ul.c  | 32 ++++++++++++++++++++++++++++++
 configs/kontron-sl-mx6ul_defconfig |  1 +
 3 files changed, 35 insertions(+)
board/kontron/sl-mx6ul/Kconfig +2 -0
index 7a4ffbed289..a6d3fa49778 100644
@@ -9,4 +9,6 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
 	default "kontron-sl-mx6ul"
 
+source "board/kontron/common/Kconfig"
+
 endif
board/kontron/sl-mx6ul/sl-mx6ul.c +32 -0
index 65f9b75c1a0..9dda8822ef9 100644
@@ -14,8 +14,37 @@
 
 #include "sl-mx6ul-common.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 + 0x670),
+		.len = 1,
+		.format = UID_OTP_FORMAT_DEC,
+		.desc = "BOARD"
+	},
+	{
+		.addr = (u32 *)(OCOTP_BASE_ADDR + 0x660),
+		.len = 1,
+		.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 */
+
 int dram_init(void)
 {
 	gd->ram_size = imx_ddr_size();
@@ -91,6 +120,9 @@ int board_init(void)
 
 int board_late_init(void)
 {
+	if (IS_ENABLED(CONFIG_KONTRON_HW_UID))
+		get_serial_number(uid_otp_locations, ARRAY_SIZE(uid_otp_locations));
+
 	if (is_boot_from_usb()) {
 		env_set("bootdelay", "0");
 		env_set("bootcmd", "fastboot 0");
configs/kontron-sl-mx6ul_defconfig +1 -0
index 9f7003bf54c..c6d450419cc 100644
@@ -13,6 +13,7 @@ CONFIG_ENV_SECT_SIZE=0x4000
 CONFIG_MX6UL=y
 CONFIG_TARGET_KONTRON_MX6UL=y
 CONFIG_DM_GPIO=y
+CONFIG_KONTRON_HW_UID=y
 CONFIG_DEFAULT_DEVICE_TREE="nxp/imx/imx6ul-kontron-bl"
 CONFIG_SPL_MMC=y
 CONFIG_SPL_SERIAL=y
Signature · 1 line
2.51.0
#4 lore raw

PATCH 4/4 imx: kontron-sl-mx8mm: Add support for reading HW UIDs

In reply to Frieder Schrempf

From: Frieder Schrempf <[email protected]>

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)

---
 board/kontron/sl-mx8mm/Kconfig     |  2 ++
 board/kontron/sl-mx8mm/sl-mx8mm.c  | 32 ++++++++++++++++++++++++++++++
 configs/kontron-sl-mx8mm_defconfig |  1 +
 3 files changed, 35 insertions(+)
board/kontron/sl-mx8mm/Kconfig +2 -0
index 1597bcf894d..0a5123d2979 100644
@@ -9,4 +9,6 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
 	default "kontron-sl-mx8mm"
 
+source "board/kontron/common/Kconfig"
+
 endif
board/kontron/sl-mx8mm/sl-mx8mm.c +32 -0
index df92765cb2d..d24d5286e45 100644
@@ -18,8 +18,37 @@
 #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");
configs/kontron-sl-mx8mm_defconfig +1 -0
index 42346a305f9..ed60d3b9ce4 100644
@@ -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
Signature · 1 line
2.51.0
#5 lore raw
In reply to Frieder Schrempf
Quoted 8 lines · Frieder Schrempf

From: Frieder Schrempf <[email protected]>

SoMs and boards that are manufactured at Kontron Electronics Germany (KED) get UIDs programmed to the OTP fuses. This adds support for extracting them from the fuses and exporting them to the serial console and Linux.

Quoted 6 lines

Frieder Schrempf (4):
imx: kontron-sl-mx6ul: Enable CONFIG_BOARD_LATE_INIT to fix auto
fastboot
imx: kontron: Add common function to get HW UIDs from OTPs
imx: kontron-sl-mx6ul: Add support for reading HW UIDs
imx: kontron-sl-mx8mm: Add support for reading HW UIDs

Applied the series, thanks.