From 28b64005022ad2a72647e2f72716cf6c73f96dc7 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Fri, 5 Jul 2024 20:30:23 +0200 Subject: [PATCH] drivers: hwinfo: Add support for generating device id from device addr In some ICs (including nRF54H20) the DEVICEID register is not part of FICR, and thus it is not accessible to applications. Use instead the device address, along with a couple of bytes from ER and IR, to generated a unique device id. At the same time update the pointer to the hal_nordic repo to pull in https://github.com/zephyrproject-rtos/hal_nordic/pull/196. (cherry picked from commit ebd31d3916abf87791ba69e6831ea187e6b20e8f) Original-Signed-off-by: Carles Cufi GitOrigin-RevId: ebd31d3916abf87791ba69e6831ea187e6b20e8f Cr-Build-Id: 8740696253239544497 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8740696253239544497 Change-Id: I017bd5007759b76a970cb9bd3751297321adaabd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5760303 Reviewed-by: Fabio Baltieri Commit-Queue: Fabio Baltieri Tested-by: Fabio Baltieri Tested-by: ChromeOS Prod (Robot) --- drivers/hwinfo/Kconfig | 2 +- drivers/hwinfo/hwinfo_nrf.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig index f49d0393fb9..9e251e9a265 100644 --- a/drivers/hwinfo/Kconfig +++ b/drivers/hwinfo/Kconfig @@ -67,7 +67,7 @@ config HWINFO_NRF bool "NRF device ID" default y depends on SOC_FAMILY_NORDIC_NRF - depends on NRF_SOC_SECURE_SUPPORTED + depends on SOC_SERIES_NRF54HX || NRF_SOC_SECURE_SUPPORTED help Enable Nordic NRF hwinfo driver. diff --git a/drivers/hwinfo/hwinfo_nrf.c b/drivers/hwinfo/hwinfo_nrf.c index 8b644f2f60e..d1fca5350a6 100644 --- a/drivers/hwinfo/hwinfo_nrf.c +++ b/drivers/hwinfo/hwinfo_nrf.c @@ -8,7 +8,7 @@ #include #include #include -#ifndef CONFIG_BOARD_QEMU_CORTEX_M0 +#if !defined(CONFIG_SOC_SERIES_NRF54HX) && !defined(CONFIG_BOARD_QEMU_CORTEX_M0) #include #endif @@ -25,17 +25,34 @@ struct nrf_uid { ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length) { struct nrf_uid dev_id; - uint32_t deviceid[2]; + uint32_t buf[2]; +#if NRF_FICR_HAS_DEVICE_ID || NRF_FICR_HAS_INFO_DEVICE_ID + /* DEVICEID is accessible, use this */ #if defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) && defined(NRF_FICR_S) - soc_secure_read_deviceid(deviceid); + soc_secure_read_deviceid(buf); #else - deviceid[0] = nrf_ficr_deviceid_get(NRF_FICR, 0); - deviceid[1] = nrf_ficr_deviceid_get(NRF_FICR, 1); + buf[0] = nrf_ficr_deviceid_get(NRF_FICR, 0); + buf[1] = nrf_ficr_deviceid_get(NRF_FICR, 1); +#endif +#elif NRF_FICR_HAS_DEVICE_ADDR || NRF_FICR_HAS_BLE_ADDR + /* DEVICEID is not accessible, use device/ble address instead. + * Assume that it is always accessible from the non-secure image. + */ + buf[0] = nrf_ficr_deviceaddr_get(NRF_FICR, 0); + buf[1] = nrf_ficr_deviceaddr_get(NRF_FICR, 1); + + /* Assume that ER and IR are available whenever deviceaddr is. + * Use the LSBytes from ER and IR to complete the device id. + */ + buf[1] |= (nrf_ficr_er_get(NRF_FICR, 0) & 0xFF) << 16; + buf[1] |= (nrf_ficr_ir_get(NRF_FICR, 0) & 0xFF) << 24; +#else +#error "No suitable source for hwinfo device_id generation" #endif - dev_id.id[0] = sys_cpu_to_be32(deviceid[1]); - dev_id.id[1] = sys_cpu_to_be32(deviceid[0]); + dev_id.id[0] = sys_cpu_to_be32(buf[1]); + dev_id.id[1] = sys_cpu_to_be32(buf[0]); if (length > sizeof(dev_id.id)) { length = sizeof(dev_id.id); @@ -46,7 +63,7 @@ ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length) return length; } -#ifndef CONFIG_BOARD_QEMU_CORTEX_M0 +#if !defined(CONFIG_SOC_SERIES_NRF54HX) && !defined(CONFIG_BOARD_QEMU_CORTEX_M0) int z_impl_hwinfo_get_reset_cause(uint32_t *cause) { uint32_t flags = 0;