From b2f009b4ba36b9712dee25129e1ac2538f7c624a Mon Sep 17 00:00:00 2001 From: Balaji Selvanathan Date: Wed, 22 Apr 2026 09:32:48 +0530 Subject: [PATCH] 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/20260106122134.2047864-3-aswin.murugan@oss.qualcomm.com/ Signed-off-by: Balaji Selvanathan --- arch/arm/mach-snapdragon/board.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c index 829a0109ac78..a9df92f5e5d8 100644 --- a/arch/arm/mach-snapdragon/board.c +++ b/arch/arm/mach-snapdragon/board.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #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. + */ +static 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");