Skip to content

Commit

Permalink
drivers: hwinfo: Add support for generating device id from device addr
Browse files Browse the repository at this point in the history
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
zephyrproject-rtos/hal_nordic#196.

(cherry picked from commit ebd31d3)

Original-Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
GitOrigin-RevId: ebd31d3
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 <fabiobaltieri@google.com>
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
  • Loading branch information
carlescufi authored and Chromeos LUCI committed Aug 2, 2024
1 parent 2095bb5 commit 28b6400
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion drivers/hwinfo/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
33 changes: 25 additions & 8 deletions drivers/hwinfo/hwinfo_nrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <zephyr/drivers/hwinfo.h>
#include <string.h>
#include <zephyr/sys/byteorder.h>
#ifndef CONFIG_BOARD_QEMU_CORTEX_M0
#if !defined(CONFIG_SOC_SERIES_NRF54HX) && !defined(CONFIG_BOARD_QEMU_CORTEX_M0)
#include <helpers/nrfx_reset_reason.h>
#endif

Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 28b6400

Please sign in to comment.