feat(platforms/common): GUIDs of boards that override the UUID

Boards that override their UUID, such as SITL and the Linux boards, only had the functions that format the GUID, while DroneCAN and Cyphal send the GUID itself to the other nodes, so these drivers couldn't be linked for them. board_get_mfguid() and board_get_px4_guid() now give the bytes that the formatting functions print.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
This commit is contained in:
Benjamin Cabé authored and Ramon Roche committed 2026-10-12 12:45:09 +02:00
1 parent 32d8646181
commit 3fc3b141d7
2 files changed
+49

No files matched your search

+25
View File
@@ -103,4 +103,29 @@ int board_get_px4_guid_formated(char *format_buffer, int size)
size -= offset;
return board_get_mfguid_formated(&format_buffer[offset], size);
}
/* The bytes of each 32-bit word with the most significant first, as board_get_mfguid_formated() prints them */
int board_get_mfguid(mfguid_t mfgid)
{
uuid_uint32_t uuid;
board_get_uuid32(uuid);
for (unsigned int i = 0; i < PX4_CPU_UUID_WORD32_LENGTH; i++) {
mfgid[4 * i] = (uuid[i] >> 24) & 0xff;
mfgid[4 * i + 1] = (uuid[i] >> 16) & 0xff;
mfgid[4 * i + 2] = (uuid[i] >> 8) & 0xff;
mfgid[4 * i + 3] = uuid[i] & 0xff;
}
return PX4_CPU_MFGUID_BYTE_LENGTH;
}
int board_get_px4_guid(px4_guid_t px4_guid)
{
px4_guid[0] = (soc_arch_id >> 8) & 0xff;
px4_guid[1] = soc_arch_id & 0xff;
memset(&px4_guid[2], 0, PX4_GUID_BYTE_LENGTH - 2 - PX4_CPU_MFGUID_BYTE_LENGTH);
board_get_mfguid(&px4_guid[PX4_GUID_BYTE_LENGTH - PX4_CPU_MFGUID_BYTE_LENGTH]);
return PX4_GUID_BYTE_LENGTH;
}
#endif
+24
View File
@@ -160,3 +160,27 @@ TEST(BoardIdentityTest, PX4GUIDBufferOverflow)
board_get_px4_guid_formated(buf_40, sizeof(buf_40));
EXPECT_EQ(0, strncmp(groundtruth_px4_guid, buf_40, sizeof(buf_40) - 1));
}
/**
* @brief Test that `board_get_px4_guid` and `board_get_mfguid` give the bytes of the formatted GUID
*/
TEST(BoardIdentityTest, PX4GUIDBytes)
{
char formatted[PX4_GUID_FORMAT_SIZE];
board_get_px4_guid_formated(formatted, sizeof(formatted));
px4_guid_t px4_guid;
EXPECT_EQ(PX4_GUID_BYTE_LENGTH, board_get_px4_guid(px4_guid));
char bytes[PX4_GUID_FORMAT_SIZE] {};
for (int i = 0; i < PX4_GUID_BYTE_LENGTH; i++) {
snprintf(&bytes[2 * i], sizeof(bytes) - 2 * i, "%02x", px4_guid[i]);
}
EXPECT_STREQ(formatted, bytes);
mfguid_t mfguid;
EXPECT_EQ(PX4_CPU_MFGUID_BYTE_LENGTH, board_get_mfguid(mfguid));
EXPECT_EQ(0, memcmp(&px4_guid[PX4_GUID_BYTE_LENGTH - PX4_CPU_MFGUID_BYTE_LENGTH], mfguid, sizeof(mfguid)));
}