Re: how to add unique_id for Raspberry Pi Pico?
What is the use case for needing the ID to match pico-sdk's implementation? With the PRNG approach we get some useful properties: 1. Firmware updates can change CONFIG_BOARDCTL_UNIQUEID_SIZE without affecting the most significant bytes of the board ID. If I'm using 6 bytes for a MAC address (for instance), and later need an 8 or 16 byte ID for some reason, the first 6 bytes don't change. 2. A user / application can extract any number of bytes from any portion of the board ID and have a reasonable expectation of uniqueness. The application doesn't have to care about how the ID was generated or which set of bytes it should use. I'm not completely opposed to this idea, but I don't think I understand the need. If there is a need for this, I would prefer the separate configuration option. -- Adam On 2024-04-02 01:03, Anders wrote: Thank you Alan, that is even better. Another option is to introduce a separate configuration option, e.g. CONFIG_BOARDCTL_RP2040_HARDWAREID. If that is set, code would be compiled to return a unique id based directly on hardware values, independent of the relative sizes of the CONFIG_BOARDCTL_UNIQUEID_SIZE and RP2040_FLASH_ID_SIZE. If it is not set, Adam's code would be compiled and kick in. If the flash hardware id is copied and not hashed, one thing to consider is where the bytes should go in the NuttX unique id. If a subset of the 8 bytes will be used in a shorter unique id variable, I suggest the least significant bytes of the hardware id are used (as returned by the Pico SDK). But if the 8 byte hardware id will be put in a unique id variable that is larger than 8 bytes, will they be in the least significant bytes or in the most significant? Also here I would suggest the least significant ones. In any case, after feedback on the list, I can draft a proposal and prepare a merge request. Cheers, Anders On Monday, 1 April 2024 at 23:18, Alan C. Assis wrote: Should it be: #if CONFIG_BOARDCTL_UNIQUEID_SIZE <= RP2040_FLASH_ID_SIZE ? BR, Alan On Mon, Apr 1, 2024 at 5:45 PM Anders andyl...@proton.me.invalid wrote: Hi, The unique id solution for the Raspberry Pi by Adam and his team works very well. However, I suggest a slight modification of the code. In short, if the number of bytes of the NuttX unique id is configured equal to the actual number of bytes of the id in the Pico flash hardware system (8 bytes), the hardware id is just copied and not used as a PRNG seed. If the configured size of the NuttX unique id is larger than the flash hardware, the PRNG code is used to return a unique id with more (non-zero) bytes. The advantage of having the function returning the actual hardware id, is that this is easily compared to the id returned by the Pico SDK function. Remember that the number of bytes (bits) in the flash hardware id sets a limit on how many unique ids there are, even if those are embedded (distributed) in a larger number of bytes (bits), as is the result of the PRNG function. The suggested code (from the boards/arm/rp2040/common/src/rp2040_uniqueid.c): void rp2040_uniqueid_initialize(void) { uint8_t txbuf[RP2040_FLASH_ID_BUFFER_SIZE]; uint8_t rxbuf[RP2040_FLASH_ID_BUFFER_SIZE]; memset(g_uniqueid, 0xac, CONFIG_BOARDCTL_UNIQUEID_SIZE); memset(txbuf, 0, RP2040_FLASH_ID_BUFFER_SIZE); memset(rxbuf, 0, RP2040_FLASH_ID_BUFFER_SIZE); txbuf[0] = RP2040_FLASH_RUID_CMD; rp2040_flash_cmd(txbuf, rxbuf, RP2040_FLASH_ID_BUFFER_SIZE); #if CONFIG_BOARDCTL_UNIQUEID_SIZE == RP2040_FLASH_ID_SIZE for (int i = 0; i < CONFIG_BOARDCTL_UNIQUEID_SIZE; i++) { g_uniqueid[i] = rxbuf[i + RP2040_FLASH_ID_BUFFER_OFFSET]; } #else /* xorshift PRNG: */ uint64_t x; x = *(uint64_t *)(rxbuf + RP2040_FLASH_ID_BUFFER_OFFSET); for (int i = 0; i < CONFIG_BOARDCTL_UNIQUEID_SIZE; i++) { x ^= x >> 12; x ^= x << 25; x ^= x >> 27; g_uniqueid[i] = (uint8_t)((x * 0x2545f4914f6cdd1dull) >> 32); } #endif } Any comments? Anders On Monday, 18 March 2024 at 06:51, Anders andyl...@proton.me.INVALID wrote: Hello Adam Excellent! Precisely what I was looking for. I'll check it out. Thanks, Anders On Sunday, 17 March 2024 at 12:54, Adam Comley a...@novators.net wrote: Hi Anders, I recently had a need for this feature as well, and put together a PR based on the pico-sdk implementation. See: https://github.com/apache/nuttx/pull/11927 Hope this helps. -- Adam
Re: how to add unique_id for Raspberry Pi Pico?
Thank you Alan, that is even better. Another option is to introduce a separate configuration option, e.g. CONFIG_BOARDCTL_RP2040_HARDWAREID. If that is set, code would be compiled to return a unique id based directly on hardware values, independent of the relative sizes of the CONFIG_BOARDCTL_UNIQUEID_SIZE and RP2040_FLASH_ID_SIZE. If it is not set, Adam's code would be compiled and kick in. If the flash hardware id is copied and not hashed, one thing to consider is where the bytes should go in the NuttX unique id. If a subset of the 8 bytes will be used in a shorter unique id variable, I suggest the least significant bytes of the hardware id are used (as returned by the Pico SDK). But if the 8 byte hardware id will be put in a unique id variable that is larger than 8 bytes, will they be in the least significant bytes or in the most significant? Also here I would suggest the least significant ones. In any case, after feedback on the list, I can draft a proposal and prepare a merge request. Cheers, Anders On Monday, 1 April 2024 at 23:18, Alan C. Assis wrote: > Should it be: > > #if CONFIG_BOARDCTL_UNIQUEID_SIZE <= RP2040_FLASH_ID_SIZE ? > > BR, > > Alan > > On Mon, Apr 1, 2024 at 5:45 PM Anders andyl...@proton.me.invalid wrote: > > > Hi, > > > > The unique id solution for the Raspberry Pi by Adam and his team works > > very well. However, I suggest a slight modification of the code. In short, > > if the number of bytes of the NuttX unique id is configured equal to the > > actual number of bytes of the id in the Pico flash hardware system (8 > > bytes), the hardware id is just copied and not used as a PRNG seed. If the > > configured size of the NuttX unique id is larger than the flash hardware, > > the PRNG code is used to return a unique id with more (non-zero) bytes. The > > advantage of having the function returning the actual hardware id, is that > > this is easily compared to the id returned by the Pico SDK function. > > Remember that the number of bytes (bits) in the flash hardware id sets a > > limit on how many unique ids there are, even if those are embedded > > (distributed) in a larger number of bytes (bits), as is the result of the > > PRNG function. > > > > The suggested code (from the > > boards/arm/rp2040/common/src/rp2040_uniqueid.c): > > > > void rp2040_uniqueid_initialize(void) > > { > > uint8_t txbuf[RP2040_FLASH_ID_BUFFER_SIZE]; > > uint8_t rxbuf[RP2040_FLASH_ID_BUFFER_SIZE]; > > > > memset(g_uniqueid, 0xac, CONFIG_BOARDCTL_UNIQUEID_SIZE); > > memset(txbuf, 0, RP2040_FLASH_ID_BUFFER_SIZE); > > memset(rxbuf, 0, RP2040_FLASH_ID_BUFFER_SIZE); > > txbuf[0] = RP2040_FLASH_RUID_CMD; > > > > rp2040_flash_cmd(txbuf, rxbuf, RP2040_FLASH_ID_BUFFER_SIZE); > > > > #if CONFIG_BOARDCTL_UNIQUEID_SIZE == RP2040_FLASH_ID_SIZE > > for (int i = 0; i < CONFIG_BOARDCTL_UNIQUEID_SIZE; i++) > > { > > g_uniqueid[i] = rxbuf[i + RP2040_FLASH_ID_BUFFER_OFFSET]; > > } > > #else > > /* xorshift PRNG: */ > > uint64_t x; > > x = *(uint64_t *)(rxbuf + RP2040_FLASH_ID_BUFFER_OFFSET); > > for (int i = 0; i < CONFIG_BOARDCTL_UNIQUEID_SIZE; i++) > > { > > x ^= x >> 12; > > x ^= x << 25; > > x ^= x >> 27; > > g_uniqueid[i] = (uint8_t)((x * 0x2545f4914f6cdd1dull) >> 32); > > } > > #endif > > } > > > > Any comments? > > > > Anders > > > > On Monday, 18 March 2024 at 06:51, Anders andyl...@proton.me.INVALID > > wrote: > > > > > Hello Adam > > > > > > Excellent! Precisely what I was looking for. I'll check it out. > > > > > > Thanks, > > > Anders > > > > > > On Sunday, 17 March 2024 at 12:54, Adam Comley a...@novators.net wrote: > > > > > > > Hi Anders, > > > > > > > > I recently had a need for this feature as well, and put together a PR > > > > based on the pico-sdk implementation. See: > > > > > > > > https://github.com/apache/nuttx/pull/11927 > > > > > > > > Hope this helps. > > > > > > > > -- Adam
Re: how to add unique_id for Raspberry Pi Pico?
Should it be: #if CONFIG_BOARDCTL_UNIQUEID_SIZE <= RP2040_FLASH_ID_SIZE ? BR, Alan On Mon, Apr 1, 2024 at 5:45 PM Anders wrote: > Hi, > > The unique id solution for the Raspberry Pi by Adam and his team works > very well. However, I suggest a slight modification of the code. In short, > if the number of bytes of the NuttX unique id is configured equal to the > actual number of bytes of the id in the Pico flash hardware system (8 > bytes), the hardware id is just copied and not used as a PRNG seed. If the > configured size of the NuttX unique id is larger than the flash hardware, > the PRNG code is used to return a unique id with more (non-zero) bytes. The > advantage of having the function returning the actual hardware id, is that > this is easily compared to the id returned by the Pico SDK function. > Remember that the number of bytes (bits) in the flash hardware id sets a > limit on how many unique ids there are, even if those are embedded > (distributed) in a larger number of bytes (bits), as is the result of the > PRNG function. > > The suggested code (from the > boards/arm/rp2040/common/src/rp2040_uniqueid.c): > > void rp2040_uniqueid_initialize(void) > { > uint8_t txbuf[RP2040_FLASH_ID_BUFFER_SIZE]; > uint8_t rxbuf[RP2040_FLASH_ID_BUFFER_SIZE]; > > memset(g_uniqueid, 0xac, CONFIG_BOARDCTL_UNIQUEID_SIZE); > memset(txbuf, 0, RP2040_FLASH_ID_BUFFER_SIZE); > memset(rxbuf, 0, RP2040_FLASH_ID_BUFFER_SIZE); > txbuf[0] = RP2040_FLASH_RUID_CMD; > > rp2040_flash_cmd(txbuf, rxbuf, RP2040_FLASH_ID_BUFFER_SIZE); > > #if CONFIG_BOARDCTL_UNIQUEID_SIZE == RP2040_FLASH_ID_SIZE > for (int i = 0; i < CONFIG_BOARDCTL_UNIQUEID_SIZE; i++) > { > g_uniqueid[i] = rxbuf[i + RP2040_FLASH_ID_BUFFER_OFFSET]; > } > #else > /* xorshift PRNG: */ > uint64_t x; > x = *(uint64_t *)(rxbuf + RP2040_FLASH_ID_BUFFER_OFFSET); > for (int i = 0; i < CONFIG_BOARDCTL_UNIQUEID_SIZE; i++) > { > x ^= x >> 12; > x ^= x << 25; > x ^= x >> 27; > g_uniqueid[i] = (uint8_t)((x * 0x2545f4914f6cdd1dull) >> 32); > } > #endif > } > > Any comments? > > Anders > > > > > On Monday, 18 March 2024 at 06:51, Anders > wrote: > > > Hello Adam > > > > Excellent! Precisely what I was looking for. I'll check it out. > > > > Thanks, > > Anders > > > > On Sunday, 17 March 2024 at 12:54, Adam Comley a...@novators.net wrote: > > > > > Hi Anders, > > > > > > I recently had a need for this feature as well, and put together a PR > > > based on the pico-sdk implementation. See: > > > > > > https://github.com/apache/nuttx/pull/11927 > > > > > > Hope this helps. > > > > > > -- Adam >
Re: how to add unique_id for Raspberry Pi Pico?
Hi, The unique id solution for the Raspberry Pi by Adam and his team works very well. However, I suggest a slight modification of the code. In short, if the number of bytes of the NuttX unique id is configured equal to the actual number of bytes of the id in the Pico flash hardware system (8 bytes), the hardware id is just copied and not used as a PRNG seed. If the configured size of the NuttX unique id is larger than the flash hardware, the PRNG code is used to return a unique id with more (non-zero) bytes. The advantage of having the function returning the actual hardware id, is that this is easily compared to the id returned by the Pico SDK function. Remember that the number of bytes (bits) in the flash hardware id sets a limit on how many unique ids there are, even if those are embedded (distributed) in a larger number of bytes (bits), as is the result of the PRNG function. The suggested code (from the boards/arm/rp2040/common/src/rp2040_uniqueid.c): void rp2040_uniqueid_initialize(void) { uint8_t txbuf[RP2040_FLASH_ID_BUFFER_SIZE]; uint8_t rxbuf[RP2040_FLASH_ID_BUFFER_SIZE]; memset(g_uniqueid, 0xac, CONFIG_BOARDCTL_UNIQUEID_SIZE); memset(txbuf, 0, RP2040_FLASH_ID_BUFFER_SIZE); memset(rxbuf, 0, RP2040_FLASH_ID_BUFFER_SIZE); txbuf[0] = RP2040_FLASH_RUID_CMD; rp2040_flash_cmd(txbuf, rxbuf, RP2040_FLASH_ID_BUFFER_SIZE); #if CONFIG_BOARDCTL_UNIQUEID_SIZE == RP2040_FLASH_ID_SIZE for (int i = 0; i < CONFIG_BOARDCTL_UNIQUEID_SIZE; i++) { g_uniqueid[i] = rxbuf[i + RP2040_FLASH_ID_BUFFER_OFFSET]; } #else /* xorshift PRNG: */ uint64_t x; x = *(uint64_t *)(rxbuf + RP2040_FLASH_ID_BUFFER_OFFSET); for (int i = 0; i < CONFIG_BOARDCTL_UNIQUEID_SIZE; i++) { x ^= x >> 12; x ^= x << 25; x ^= x >> 27; g_uniqueid[i] = (uint8_t)((x * 0x2545f4914f6cdd1dull) >> 32); } #endif } Any comments? Anders On Monday, 18 March 2024 at 06:51, Anders wrote: > Hello Adam > > Excellent! Precisely what I was looking for. I'll check it out. > > Thanks, > Anders > > On Sunday, 17 March 2024 at 12:54, Adam Comley a...@novators.net wrote: > > > Hi Anders, > > > > I recently had a need for this feature as well, and put together a PR > > based on the pico-sdk implementation. See: > > > > https://github.com/apache/nuttx/pull/11927 > > > > Hope this helps. > > > > -- Adam
Re: how to add unique_id for Raspberry Pi Pico?
Hello Adam Excellent! Precisely what I was looking for. I'll check it out. Thanks, Anders On Sunday, 17 March 2024 at 12:54, Adam Comley wrote: > Hi Anders, > > I recently had a need for this feature as well, and put together a PR > based on the pico-sdk implementation. See: > > https://github.com/apache/nuttx/pull/11927 > > Hope this helps. > > -- Adam
Re: how to add unique_id for Raspberry Pi Pico?
Hi Anders, I recently had a need for this feature as well, and put together a PR based on the pico-sdk implementation. See: https://github.com/apache/nuttx/pull/11927 Hope this helps. -- Adam
Re: how to add unique_id for Raspberry Pi Pico?
Yes I know how it is done with the Pico-SDK, the NuttX is sort of different :-) The fact that the ID is stored in the flash circuits and not in the processor seems to make it a bit tricky. In the file pico-sdk/src/rp2_common/hardware_flash/include/hardware/flash.h it is recommended to extract flash metadata during startup, to avoid potential problems, for example with interrupts or the second core simultaneously trying to execute code on the flash memory. Therefore one solution here may be to read out the flash id during boot and keep it in memory for later access from a user application. All of course if the configuration to have a unique id is enabled. Such a solution can be implemented in either nuttx/boards/arm/rp2040/raspberrypi-pico/src/rp2040_initialize.c or rp2040_bringup.c. Possibly in the common versions of these if the flash id solution is equal across all boards with the RP2040 processor. In addition to this, some access function would be needed in a new file rp2040_uid.c or so. But what is the procedure in NuttX to store some global variable in memory? Preferably as read-only after initialization. Anders On Thursday, 14 March 2024 at 14:39, Alan C. Assis wrote: > Hi Anders, > > As I said the RP2040 doesn't have a unique id like others MCUs, then the > solution they found was read from its SPI Flash, more info: > > https://github.com/raspberrypi/pico-sdk/pull/12 > > You need to look how they did it and use it in NuttX. > > BR, > > Alan > > On Thu, Mar 14, 2024 at 4:09 AM Anders andyl...@proton.me.invalid wrote: > > > Hello Alan and thanks for the warm welcome. > > > > Yes, the id is in the flash part of the board and the code for extracting > > the unique id is in the Pico bootrom. But how to acces and run bootrom code > > from a Nuttx application? > > The code for other boards seem to access an id in a processor register. > > And while access to flash fs on the Pico supposedly could give some hints, > > a solution still eludes me. > > > > Anders > > > > Originalmeddelande > > Den 25 feb. 2024 20:17, Alan C. Assis skrev: > > > > > Hi Anders, Welcome to NuttX !!! Yes, you are right, the rp2040 port > > > doesn't yet have support for uniqueid. If you want to add it, please enter > > > inside nuttx/arch/arm/src/ and "git grep uniqueid" for a reference how it > > > is done in other chips. Example in cxd56xx arch: > > > arch/arm/src/cxd56xx/cxd56_uid.c And cxd56xx common boards: > > > boards/arm/cxd56xx/common/src/cxd56_uid.c Notice that rp2040 doesn't have > > > unique id like other chips, but you have use the flash serial number as > > > unique id, more info: > > > https://forums.raspberrypi.com/viewtopic.php?t=331910 BR, Alan On Sun, > > > Feb 25, 2024 at 9:58 AM Anders wrote: > Having just started to play with > > > nuttx running on Raspberry Pi Pico, I > discovered that configuring > > > support > > > for the unique id functions results in > a build of nuttx that fails. My > > > understanding is that support for this is > not currently added. One can > > > find code for this for other boards in the > corresponding directory tree > > > of nuttx. > > Reading in the archives of this list, it is not recommended > > > to use > functions from the Pico-sdk. So new driver code should be added. > > > > > > > What is the recommended way of adding this functionality? Adding the > > > > interface in a separate file of boards/arm/rp2040/raspberry-pi-pico/src/ > > > > and Make.defs seems easy. But where would the code for actually > > > interfacing > > > with the flash best go? > > Anders
Re: how to add unique_id for Raspberry Pi Pico?
Hi Anders, As I said the RP2040 doesn't have a unique id like others MCUs, then the solution they found was read from its SPI Flash, more info: https://github.com/raspberrypi/pico-sdk/pull/12 You need to look how they did it and use it in NuttX. BR, Alan On Thu, Mar 14, 2024 at 4:09 AM Anders wrote: > Hello Alan and thanks for the warm welcome. > > Yes, the id is in the flash part of the board and the code for extracting > the unique id is in the Pico bootrom. But how to acces and run bootrom code > from a Nuttx application? > The code for other boards seem to access an id in a processor register. > And while access to flash fs on the Pico supposedly could give some hints, > a solution still eludes me. > > Anders > > Originalmeddelande > Den 25 feb. 2024 20:17, Alan C. Assis skrev: > > > Hi Anders, Welcome to NuttX !!! Yes, you are right, the rp2040 port > doesn't yet have support for uniqueid. If you want to add it, please enter > inside nuttx/arch/arm/src/ and "git grep uniqueid" for a reference how it > is done in other chips. Example in cxd56xx arch: > arch/arm/src/cxd56xx/cxd56_uid.c And cxd56xx common boards: > boards/arm/cxd56xx/common/src/cxd56_uid.c Notice that rp2040 doesn't have > unique id like other chips, but you have use the flash serial number as > unique id, more info: > https://forums.raspberrypi.com/viewtopic.php?t=331910 BR, Alan On Sun, > Feb 25, 2024 at 9:58 AM Anders wrote: > Having just started to play with > nuttx running on Raspberry Pi Pico, I > discovered that configuring support > for the unique id functions results in > a build of nuttx that fails. My > understanding is that support for this is > not currently added. One can > find code for this for other boards in the > corresponding directory tree > of nuttx. > > Reading in the archives of this list, it is not recommended > to use > functions from the Pico-sdk. So new driver code should be added. > > > What is the recommended way of adding this functionality? Adding the > > interface in a separate file of boards/arm/rp2040/raspberry-pi-pico/src/ > > and Make.defs seems easy. But where would the code for actually interfacing > > with the flash best go? > > Anders
Re: how to add unique_id for Raspberry Pi Pico?
Hello Alan and thanks for the warm welcome. Yes, the id is in the flash part of the board and the code for extracting the unique id is in the Pico bootrom. But how to acces and run bootrom code from a Nuttx application? The code for other boards seem to access an id in a processor register. And while access to flash fs on the Pico supposedly could give some hints, a solution still eludes me. Anders Originalmeddelande Den 25 feb. 2024 20:17, Alan C. Assis skrev: > Hi Anders, Welcome to NuttX !!! Yes, you are right, the rp2040 port doesn't > yet have support for uniqueid. If you want to add it, please enter inside > nuttx/arch/arm/src/ and "git grep uniqueid" for a reference how it is done in > other chips. Example in cxd56xx arch: arch/arm/src/cxd56xx/cxd56_uid.c And > cxd56xx common boards: boards/arm/cxd56xx/common/src/cxd56_uid.c Notice that > rp2040 doesn't have unique id like other chips, but you have use the flash > serial number as unique id, more info: > https://forums.raspberrypi.com/viewtopic.php?t=331910 BR, Alan On Sun, Feb > 25, 2024 at 9:58 AM Anders wrote: > Having just started to play with nuttx > running on Raspberry Pi Pico, I > discovered that configuring support for the > unique id functions results in > a build of nuttx that fails. My > understanding is that support for this is > not currently added. One can find > code for this for other boards in the > corresponding directory tree of > nuttx. > > Reading in the archives of this list, it is not recommended to use > > functions from the Pico-sdk. So new driver code should be added. > > What > is the recommended way of adding this functionality? Adding the > interface > in a separate file of boards/arm/rp2040/raspberry-pi-pico/src/ > and > Make.defs seems easy. But where would the code for actually interfacing > > with the flash best go? > > Anders
Re: how to add unique_id for Raspberry Pi Pico?
Hi Anders, Welcome to NuttX !!! Yes, you are right, the rp2040 port doesn't yet have support for uniqueid. If you want to add it, please enter inside nuttx/arch/arm/src/ and "git grep uniqueid" for a reference how it is done in other chips. Example in cxd56xx arch: arch/arm/src/cxd56xx/cxd56_uid.c And cxd56xx common boards: boards/arm/cxd56xx/common/src/cxd56_uid.c Notice that rp2040 doesn't have unique id like other chips, but you have use the flash serial number as unique id, more info: https://forums.raspberrypi.com/viewtopic.php?t=331910 BR, Alan On Sun, Feb 25, 2024 at 9:58 AM Anders wrote: > Having just started to play with nuttx running on Raspberry Pi Pico, I > discovered that configuring support for the unique id functions results in > a build of nuttx that fails. My understanding is that support for this is > not currently added. One can find code for this for other boards in the > corresponding directory tree of nuttx. > > Reading in the archives of this list, it is not recommended to use > functions from the Pico-sdk. So new driver code should be added. > > What is the recommended way of adding this functionality? Adding the > interface in a separate file of boards/arm/rp2040/raspberry-pi-pico/src/ > and Make.defs seems easy. But where would the code for actually interfacing > with the flash best go? > > Anders
how to add unique_id for Raspberry Pi Pico?
Having just started to play with nuttx running on Raspberry Pi Pico, I discovered that configuring support for the unique id functions results in a build of nuttx that fails. My understanding is that support for this is not currently added. One can find code for this for other boards in the corresponding directory tree of nuttx. Reading in the archives of this list, it is not recommended to use functions from the Pico-sdk. So new driver code should be added. What is the recommended way of adding this functionality? Adding the interface in a separate file of boards/arm/rp2040/raspberry-pi-pico/src/ and Make.defs seems easy. But where would the code for actually interfacing with the flash best go? Anders