From 425e40b8b66391cffab75cb12829954b6e85f426 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Fri, 5 Jul 2024 20:30:23 +0200 Subject: [PATCH] [nrf fromtree] 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. Signed-off-by: Carles Cufi (cherry picked from commit ebd31d3916abf87791ba69e6831ea187e6b20e8f) --- 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 0d3f6b991f9..f8e80872c6f 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;