From 859ceb4fd9e449ffa157222533613e895ac139db Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 2 Dec 2024 10:51:58 +0100 Subject: [PATCH 1/5] Bpid: allow build on all boards --- src/bpid/bpid.cpp | 5 +++-- src/bpid/bpid.h | 6 +++--- src/bpid/csn.cpp | 4 ++-- src/bpid/csn.h | 15 ++++++++++----- src/bpid/mac.cpp | 26 +++++++++++++++----------- src/bpid/mac.h | 4 +--- src/bpid/ucid.cpp | 24 ++++++++++++++---------- src/bpid/ucid.h | 10 +++++----- 8 files changed, 53 insertions(+), 41 deletions(-) diff --git a/src/bpid/bpid.cpp b/src/bpid/bpid.cpp index 74c5705..60fb003 100644 --- a/src/bpid/bpid.cpp +++ b/src/bpid/bpid.cpp @@ -22,11 +22,11 @@ namespace arduino { namespace bpid { if (!arduino::ucid::get(&in[offset], size)) { return false; } - offset += arduino::ucid::UC_UID_SIZE; + offset += UC_UID_SIZE; if (!arduino::mac::get(&in[offset], size - offset)) { return false; } - offset += arduino::mac::IFACE_MAC_SIZE; + offset += IFACE_MAC_ADDR_LENGTH; if (!arduino::csn::get(&in[offset], size - offset)) { return false; } @@ -41,6 +41,7 @@ namespace arduino { namespace bpid { uint8_t out[SHA256::HASH_SIZE]; arduino::sha256::oneshot(data, sizeof(data), out); return arduino::hex::encode(out, sizeof(out)); + return String(""); } }} // arduino::bpid diff --git a/src/bpid/bpid.h b/src/bpid/bpid.h index 2f6c085..780bf8a 100644 --- a/src/bpid/bpid.h +++ b/src/bpid/bpid.h @@ -20,9 +20,9 @@ namespace arduino { namespace bpid { * This library contains the methods to get board provisioning id */ - constexpr int BOARD_PROVISIONING_ID_SIZE = arduino::ucid::UC_UID_SIZE + - arduino::mac::IFACE_MAC_SIZE + - arduino::csn::CRYPTO_SN_SIZE; + constexpr int BOARD_PROVISIONING_ID_SIZE = UC_UID_SIZE + + IFACE_MAC_ADDR_LENGTH + + CRYPTO_SN_SIZE; bool get(uint8_t* in, uint32_t size); String get(); diff --git a/src/bpid/csn.cpp b/src/bpid/csn.cpp index ea967e2..31c7ae0 100644 --- a/src/bpid/csn.cpp +++ b/src/bpid/csn.cpp @@ -13,8 +13,8 @@ namespace arduino { namespace csn { bool get(uint8_t *in, uint32_t size) { -#if defined ARDUINO_UNOR4_WIFI - return false; +#if CRYPTO_SN_SIZE == 0 + return false; #else if (size < CRYPTO_SN_SIZE) { return false; diff --git a/src/bpid/csn.h b/src/bpid/csn.h index 87d61a0..2106749 100644 --- a/src/bpid/csn.h +++ b/src/bpid/csn.h @@ -19,19 +19,24 @@ namespace arduino { namespace csn { */ #if defined(ARDUINO_NANO_RP2040_CONNECT) || \ - defined(ARDUINO_SAMD_MKRWIFI1010) || \ defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_SAMD_MKRWIFI1010) || \ + defined(ARDUINO_SAMD_MKRGSM1400) || \ + defined(ARDUINO_SAMD_MKRWAN1300) || \ + defined(ARDUINO_SAMD_MKRWAN1310) || \ + defined(ARDUINO_SAMD_MKRNB1500) || \ + defined(ARDUINO_SAMD_MKR1000) || \ defined(ARDUINO_PORTENTA_H7_M7) || \ defined(ARDUINO_OPTA) || \ defined(ARDUINO_GIGA) - constexpr int CRYPTO_SN_SIZE = 9; + #define CRYPTO_SN_SIZE 9 #elif defined(ARDUINO_PORTENTA_C33) || \ defined(ARDUINO_NICLA_VISION) - constexpr int CRYPTO_SN_SIZE = SE05X_SN_LENGTH; + #define CRYPTO_SN_SIZE SE05X_SN_LENGTH #elif defined(ARDUINO_UNOR4_WIFI) - constexpr int CRYPTO_SN_SIZE = 6; + #define CRYPTO_SN_SIZE 6 #else - #error "Unknown board" + #define CRYPTO_SN_SIZE 0 #endif bool get(uint8_t *in, uint32_t size); diff --git a/src/bpid/mac.cpp b/src/bpid/mac.cpp index 348326c..8594bb7 100644 --- a/src/bpid/mac.cpp +++ b/src/bpid/mac.cpp @@ -13,25 +13,29 @@ namespace arduino { namespace mac { bool get(uint8_t *in, uint32_t size) { - if (size < IFACE_MAC_SIZE) { +#if IFACE_MAC_ADDR_LENGTH == 0 + return false; +#else + if (size < IFACE_MAC_ADDR_LENGTH) { return false; } -#if defined(ARDUINO_SAMD_MKRWIFI1010) || \ - defined(ARDUINO_SAMD_NANO_33_IOT) + #if defined(ARDUINO_SAMD_MKRWIFI1010) || \ + defined(ARDUINO_SAMD_NANO_33_IOT) WiFi.macAddress(in); -#elif defined(ARDUINO_PORTENTA_H7_M7) || \ - defined(ARDUINO_NICLA_VISION) || \ - defined(ARDUINO_GIGA) + #elif defined(ARDUINO_PORTENTA_H7_M7) || \ + defined(ARDUINO_NICLA_VISION) || \ + defined(ARDUINO_GIGA) WiFi.macAddress(in); -#elif defined(ARDUINO_PORTENTA_C33) || \ - defined(ARDUINO_UNOR4_WIFI) + #elif defined(ARDUINO_PORTENTA_C33) || \ + defined(ARDUINO_UNOR4_WIFI) WiFi.macAddress(in); -#elif defined(ARDUINO_NANO_RP2040_CONNECT) + #elif defined(ARDUINO_NANO_RP2040_CONNECT) WiFi.macAddress(in); -#elif defined(ARDUINO_OPTA) + #elif defined(ARDUINO_OPTA) Ethernet.MACAddress(in); -#endif + #endif return true; +#endif } }} // arduino::mac diff --git a/src/bpid/mac.h b/src/bpid/mac.h index ecf3c2c..4a8d048 100644 --- a/src/bpid/mac.h +++ b/src/bpid/mac.h @@ -28,7 +28,7 @@ #include #define IFACE_MAC_ADDR_LENGTH 6 #else - #error "Unknown board" + #define IFACE_MAC_ADDR_LENGTH 0 #endif namespace arduino { namespace mac { @@ -45,8 +45,6 @@ namespace arduino { namespace mac { * ARDUINO_OPTA: Ethernet.begin(NULL,0,0); reversed */ - constexpr int IFACE_MAC_SIZE = IFACE_MAC_ADDR_LENGTH; - bool get(uint8_t *in, uint32_t size); }} // arduino::mac diff --git a/src/bpid/ucid.cpp b/src/bpid/ucid.cpp index a39e5d1..d67cc98 100644 --- a/src/bpid/ucid.cpp +++ b/src/bpid/ucid.cpp @@ -13,36 +13,40 @@ namespace arduino { namespace ucid { bool get(uint8_t *in, uint32_t size) { +#if UC_UID_SIZE == 0 + return false; +#else if (size < UC_UID_SIZE) { return false; } -#if defined(ARDUINO_SAMD_MKRWIFI1010) || \ - defined(ARDUINO_SAMD_NANO_33_IOT) + #if defined(ARDUINO_SAMD_MKRWIFI1010) || \ + defined(ARDUINO_SAMD_NANO_33_IOT) (*(uint32_t*)(&in[0x0])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A00C)); (*(uint32_t*)(&in[0x4])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A040)); (*(uint32_t*)(&in[0x8])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A044)); (*(uint32_t*)(&in[0xC])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A048)); -#elif defined(ARDUINO_PORTENTA_H7_M7) || \ - defined(ARDUINO_NICLA_VISION) || \ - defined(ARDUINO_OPTA) || \ - defined(ARDUINO_GIGA) + #elif defined(ARDUINO_PORTENTA_H7_M7) || \ + defined(ARDUINO_NICLA_VISION) || \ + defined(ARDUINO_OPTA) || \ + defined(ARDUINO_GIGA) (*(uint32_t*)(&in[0x0])) = __builtin_bswap32(HAL_GetUIDw0()); (*(uint32_t*)(&in[0x4])) = __builtin_bswap32(HAL_GetUIDw1()); (*(uint32_t*)(&in[0x8])) = __builtin_bswap32(HAL_GetUIDw2()); -#elif defined(ARDUINO_PORTENTA_C33) || \ - defined(ARDUINO_UNOR4_WIFI) + #elif defined(ARDUINO_PORTENTA_C33) || \ + defined(ARDUINO_UNOR4_WIFI) const bsp_unique_id_t* t = R_BSP_UniqueIdGet(); (*(uint32_t*)(&in[0x0])) = __builtin_bswap32(t->unique_id_words[0x0]); (*(uint32_t*)(&in[0x4])) = __builtin_bswap32(t->unique_id_words[0x1]); (*(uint32_t*)(&in[0x8])) = __builtin_bswap32(t->unique_id_words[0x2]); (*(uint32_t*)(&in[0xC])) = __builtin_bswap32(t->unique_id_words[0x3]); -#elif defined(ARDUINO_NANO_RP2040_CONNECT) + #elif defined(ARDUINO_NANO_RP2040_CONNECT) uint8_t id[UC_UID_SIZE]; flash_get_unique_id(id); (*(uint32_t*)(&in[0x0])) = __builtin_bswap32(*(uint32_t*)&id[0x0]); (*(uint32_t*)(&in[0x4])) = __builtin_bswap32(*(uint32_t*)&id[0x4]); -#endif + #endif return true; +#endif } }} // arduino::ucid diff --git a/src/bpid/ucid.h b/src/bpid/ucid.h index 14a204f..3d5a409 100644 --- a/src/bpid/ucid.h +++ b/src/bpid/ucid.h @@ -19,22 +19,22 @@ namespace arduino { namespace ucid { #if defined(ARDUINO_SAMD_MKRWIFI1010) || \ defined(ARDUINO_SAMD_NANO_33_IOT) - constexpr int UC_UID_SIZE = 16; + #define UC_UID_SIZE 16 #elif defined(ARDUINO_PORTENTA_H7_M7) || \ defined(ARDUINO_NICLA_VISION) || \ defined(ARDUINO_OPTA) || \ defined(ARDUINO_GIGA) - constexpr int UC_UID_SIZE = 12; + #define UC_UID_SIZE 12 #elif defined(ARDUINO_PORTENTA_C33) || \ defined(ARDUINO_UNOR4_WIFI) - constexpr int UC_UID_SIZE = 16; + #define UC_UID_SIZE 16 #elif defined(ARDUINO_NANO_RP2040_CONNECT) extern "C" { #include "hardware/flash.h" } - constexpr int UC_UID_SIZE = FLASH_UNIQUE_ID_SIZE_BYTES; + #define UC_UID_SIZE FLASH_UNIQUE_ID_SIZE_BYTES #else - #error "Unknown board" + #define UC_UID_SIZE 0 #endif bool get(uint8_t *in, uint32_t size); From 4e4411e56bbccafc261de8951cab49feae187128 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 2 Dec 2024 11:30:43 +0100 Subject: [PATCH 2/5] ci: add library dependencies and new examples --- .github/workflows/compile-examples.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 5de7a2c..8acb193 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -21,10 +21,16 @@ jobs: UNIVERSAL_LIBRARIES: | - source-path: ./ - name: Arduino_DebugUtils + - name: Arduino_SecureElement + - name: ArduinoECCX08 + - name: WiFiNINA # sketch paths to compile (recursive) for all boards UNIVERSAL_SKETCH_PATHS: | - examples/lzssDecoder - examples/crc32 + - examples/crc16 + - examples/sha256 + - examples/boardID SKETCHES_REPORTS_PATH: sketches-reports strategy: From 770e48141b4e846ebfb2b927544ac2f01877d9d4 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 2 Dec 2024 11:58:34 +0100 Subject: [PATCH 3/5] Add missing includes --- src/bpid/csn.cpp | 2 ++ src/bpid/csn.h | 14 ++++++++------ src/bpid/mac.cpp | 2 ++ src/bpid/mac.h | 2 ++ src/bpid/ucid.cpp | 2 ++ src/bpid/ucid.h | 10 +++++----- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/bpid/csn.cpp b/src/bpid/csn.cpp index 31c7ae0..f0e312a 100644 --- a/src/bpid/csn.cpp +++ b/src/bpid/csn.cpp @@ -14,6 +14,8 @@ namespace arduino { namespace csn { bool get(uint8_t *in, uint32_t size) { #if CRYPTO_SN_SIZE == 0 + (void)in; + (void)size; return false; #else if (size < CRYPTO_SN_SIZE) { diff --git a/src/bpid/csn.h b/src/bpid/csn.h index 2106749..1175dd8 100644 --- a/src/bpid/csn.h +++ b/src/bpid/csn.h @@ -11,12 +11,6 @@ #pragma once #include -#include - -namespace arduino { namespace csn { - /* - * This library contains the methods to get board microcontroller id - */ #if defined(ARDUINO_NANO_RP2040_CONNECT) || \ defined(ARDUINO_SAMD_NANO_33_IOT) || \ @@ -29,16 +23,24 @@ namespace arduino { namespace csn { defined(ARDUINO_PORTENTA_H7_M7) || \ defined(ARDUINO_OPTA) || \ defined(ARDUINO_GIGA) + #include #define CRYPTO_SN_SIZE 9 #elif defined(ARDUINO_PORTENTA_C33) || \ defined(ARDUINO_NICLA_VISION) + #include #define CRYPTO_SN_SIZE SE05X_SN_LENGTH #elif defined(ARDUINO_UNOR4_WIFI) + #include #define CRYPTO_SN_SIZE 6 #else #define CRYPTO_SN_SIZE 0 #endif +namespace arduino { namespace csn { + /* + * This library contains the methods to get board microcontroller id + */ + bool get(uint8_t *in, uint32_t size); }} // arduino::csn diff --git a/src/bpid/mac.cpp b/src/bpid/mac.cpp index 8594bb7..8938534 100644 --- a/src/bpid/mac.cpp +++ b/src/bpid/mac.cpp @@ -14,6 +14,8 @@ namespace arduino { namespace mac { bool get(uint8_t *in, uint32_t size) { #if IFACE_MAC_ADDR_LENGTH == 0 + (void)in; + (void)size; return false; #else if (size < IFACE_MAC_ADDR_LENGTH) { diff --git a/src/bpid/mac.h b/src/bpid/mac.h index 4a8d048..be83415 100644 --- a/src/bpid/mac.h +++ b/src/bpid/mac.h @@ -10,6 +10,8 @@ #pragma once +#include + #if defined(ARDUINO_NANO_RP2040_CONNECT) || \ defined(ARDUINO_SAMD_MKRWIFI1010) || \ defined(ARDUINO_SAMD_NANO_33_IOT) || \ diff --git a/src/bpid/ucid.cpp b/src/bpid/ucid.cpp index d67cc98..38a2b0a 100644 --- a/src/bpid/ucid.cpp +++ b/src/bpid/ucid.cpp @@ -14,6 +14,8 @@ namespace arduino { namespace ucid { bool get(uint8_t *in, uint32_t size) { #if UC_UID_SIZE == 0 + (void)in; + (void)size; return false; #else if (size < UC_UID_SIZE) { diff --git a/src/bpid/ucid.h b/src/bpid/ucid.h index 3d5a409..63786fc 100644 --- a/src/bpid/ucid.h +++ b/src/bpid/ucid.h @@ -12,11 +12,6 @@ #include -namespace arduino { namespace ucid { - /* - * This library contains the methods to get board microcontroller id - */ - #if defined(ARDUINO_SAMD_MKRWIFI1010) || \ defined(ARDUINO_SAMD_NANO_33_IOT) #define UC_UID_SIZE 16 @@ -37,6 +32,11 @@ namespace arduino { namespace ucid { #define UC_UID_SIZE 0 #endif +namespace arduino { namespace ucid { + /* + * This library contains the methods to get board microcontroller id + */ + bool get(uint8_t *in, uint32_t size); }} // arduino::ucid From d8bbd1520c0309b417d5adc70d66f1ff5723db2a Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 2 Dec 2024 12:43:27 +0100 Subject: [PATCH 4/5] TEMP skip crypto sn check --- src/bpid/csn.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bpid/csn.h b/src/bpid/csn.h index 1175dd8..47ef85d 100644 --- a/src/bpid/csn.h +++ b/src/bpid/csn.h @@ -24,14 +24,14 @@ defined(ARDUINO_OPTA) || \ defined(ARDUINO_GIGA) #include - #define CRYPTO_SN_SIZE 9 + #define CRYPTO_SN_SIZE 0 #elif defined(ARDUINO_PORTENTA_C33) || \ defined(ARDUINO_NICLA_VISION) #include - #define CRYPTO_SN_SIZE SE05X_SN_LENGTH + #define CRYPTO_SN_SIZE 0 #elif defined(ARDUINO_UNOR4_WIFI) #include - #define CRYPTO_SN_SIZE 6 + #define CRYPTO_SN_SIZE 0 #else #define CRYPTO_SN_SIZE 0 #endif From b2ffa42f3484244308c5ba5ae8a03c01974cc592 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 3 Dec 2024 09:12:17 +0100 Subject: [PATCH 5/5] ucid: add missing boards --- src/bpid/ucid.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bpid/ucid.h b/src/bpid/ucid.h index 63786fc..4fca022 100644 --- a/src/bpid/ucid.h +++ b/src/bpid/ucid.h @@ -12,8 +12,13 @@ #include -#if defined(ARDUINO_SAMD_MKRWIFI1010) || \ - defined(ARDUINO_SAMD_NANO_33_IOT) +#if defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_SAMD_MKRWIFI1010) || \ + defined(ARDUINO_SAMD_MKRGSM1400) || \ + defined(ARDUINO_SAMD_MKRWAN1300) || \ + defined(ARDUINO_SAMD_MKRWAN1310) || \ + defined(ARDUINO_SAMD_MKRNB1500) || \ + defined(ARDUINO_SAMD_MKR1000) #define UC_UID_SIZE 16 #elif defined(ARDUINO_PORTENTA_H7_M7) || \ defined(ARDUINO_NICLA_VISION) || \