Skip to contentSkip to conversation

arch: snapdragon: Improve serial number detection using SMEM interface

PATCH New Balaji Selvanathan 1 participant 1 message Apr 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arch: snapdragon: Improve serial number detection using SMEM interface

Enhance serial number detection by prioritizing SMEM-based retrieval over bootargs parsing for better reliability and consistency across Qualcomm Snapdragon platforms.

Add board_serial_num() function to retrieve serial number directly from SMEM using the socinfo interface. This provides access to the hardware-stored serial number in shared memory, eliminating the dependency on kernel command line parsing.

This patch depends on the following patch [1], which adds the socinfo header file.

[1] https://lore.kernel.org/all/[email protected]/

---
 arch/arm/mach-snapdragon/board.c     | 31 +++++++++++++++++++++++++++++++
 arch/arm/mach-snapdragon/qcom-priv.h |  2 ++
 2 files changed, 33 insertions(+)
arch/arm/mach-snapdragon/board.c +31 -0
index 5fb3240acc5..2f058038b25 100644
@@ -32,6 +32,8 @@
 #include <usb.h>
 #include <sort.h>
 #include <time.h>
+#include <smem.h>
+#include <soc/qcom/socinfo.h>
 
 #include "qcom-priv.h"
 
@@ -363,10 +365,39 @@ static const char *get_cmdline(void)
 	return cmdline;
 }
 
+/**
+ * board_serial_num() - Retrieves the board serial number from SMEM
+ * @serial_num_ptr: Pointer to store the serial number
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int board_serial_num(u32 *serial_num_ptr)
+{
+	struct socinfo *soc_info_ptr;
+	struct udevice *dev_ptr;
+	size_t total_size;
+
+	if (uclass_get_device(UCLASS_SMEM, 0, &dev_ptr) != 0)
+		return -ENODEV;
+
+	soc_info_ptr = smem_get(dev_ptr, 0, SMEM_HW_SW_BUILD_ID, &total_size);
+	if (!soc_info_ptr)
+		return -ENODATA;
+
+	*serial_num_ptr = soc_info_ptr->serial_num;
+	return 0;
+}
+
 void qcom_set_serialno(void)
 {
 	const char *cmdline = get_cmdline();
 	char serial[32];
+	u32 serial_num;
+
+	if (board_serial_num(&serial_num) == 0) {
+		env_set_hex("serial#", serial_num);
+		return;
+	}
 
 	if (!cmdline) {
 		log_debug("Failed to get bootargs\n");
arch/arm/mach-snapdragon/qcom-priv.h +2 -0
index b8bf574e8bb..3da841b8cda 100644
@@ -17,6 +17,8 @@ enum qcom_boot_source {
 
 extern enum qcom_boot_source qcom_boot_source;
 
+int board_serial_num(u32 *serial_num_ptr);
+
 #if IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)
 void qcom_configure_capsule_updates(void);
 #else

---
base-commit: 052988aa29bfd506d7ce207fbb3f5374a5dbecbb
change-id: 20260422-serial-93231b32b7b1

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>