Skip to content

Commit 4044e0e

Browse files
dssengalexanderwachter
authored andcommitted
drivers: hwinfo: rpi_pico: use bootrom method on RP2350
RP2350 provides a function to get OTP-backed chip ID. Prefer using this on supported platforms for these reasons: - a secure internal identifier, same as read by picotool - works on flashless boards - does not conflict with code running in XIP mode (e.g. when the other core tries to access device ID) - when used with USB HWID serial number will match one BootROM has Signed-off-by: Dmitrii Sharshakov <[email protected]> Co-authored-by: Alexander Wachter <[email protected]>
1 parent f9eeefa commit 4044e0e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

drivers/hwinfo/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ config HWINFO_RPI_PICO
152152
help
153153
Enable Raspberry Pi Pico hwinfo driver.
154154

155+
config HWINFO_RPI_PICO_CHIP_ID
156+
bool "Use chip ID as device ID for RP2350"
157+
default n
158+
depends on SOC_SERIES_RP2350
159+
depends on HWINFO_RPI_PICO
160+
help
161+
Use the chip ID as device ID for RP2350 instead of the default
162+
flash RUID. This is useful for RP2350 boards that do not have a
163+
flash, or when OTP ID is preferred over flash RUID.
164+
This option is recommended for new RP2350 designs, but defaults to n
165+
to prevent existing devices from changing their serial numbers.
166+
155167
config HWINFO_SAM_RSTC
156168
bool "Atmel SAM reset cause"
157169
default y

drivers/hwinfo/hwinfo_rpi_pico.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#if defined(CONFIG_SOC_SERIES_RP2040)
1212
#include <hardware/structs/vreg_and_chip_reset.h>
1313
#else
14+
#include <zephyr/sys/byteorder.h>
15+
#include <pico/bootrom.h>
1416
#include <hardware/structs/powman.h>
1517
#endif
1618

@@ -29,6 +31,20 @@
2931
ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
3032
{
3133
uint8_t id[FLASH_RUID_DATA_BYTES];
34+
35+
#if CONFIG_HWINFO_RPI_PICO_CHIP_ID
36+
rom_get_sys_info_fn get_sys_info = (rom_get_sys_info_fn)
37+
rom_func_lookup_inline(ROM_FUNC_GET_SYS_INFO);
38+
/* Words: CHIP_INFO, PACKAGE_SEL, DEVICE_ID, WAFER_ID */
39+
uint32_t words[4];
40+
41+
int n = get_sys_info(words, ARRAY_SIZE(words), SYS_INFO_CHIP_INFO);
42+
/* CHIP_INFO returns 4 words */
43+
__ASSERT(n == ARRAY_SIZE(words), "Failed to get chip info");
44+
45+
/* Use DEVICE_ID + WAFER_ID, like BootROM uses for its USB ID */
46+
sys_put_be(id, &words[2], 2 * sizeof(uint32_t));
47+
#else
3248
uint32_t key;
3349

3450
/*
@@ -40,6 +56,7 @@ ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
4056
key = irq_lock();
4157
flash_get_unique_id(id);
4258
irq_unlock(key);
59+
#endif /* defined(CONFIG_SOC_SERIES_RP2350) */
4360

4461
if (length > sizeof(id)) {
4562
length = sizeof(id);

0 commit comments

Comments
 (0)