Skip to content

Commit 859ceb4

Browse files
committed
Bpid: allow build on all boards
1 parent a09612c commit 859ceb4

File tree

8 files changed

+53
-41
lines changed

8 files changed

+53
-41
lines changed

src/bpid/bpid.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ namespace arduino { namespace bpid {
2222
if (!arduino::ucid::get(&in[offset], size)) {
2323
return false;
2424
}
25-
offset += arduino::ucid::UC_UID_SIZE;
25+
offset += UC_UID_SIZE;
2626
if (!arduino::mac::get(&in[offset], size - offset)) {
2727
return false;
2828
}
29-
offset += arduino::mac::IFACE_MAC_SIZE;
29+
offset += IFACE_MAC_ADDR_LENGTH;
3030
if (!arduino::csn::get(&in[offset], size - offset)) {
3131
return false;
3232
}
@@ -41,6 +41,7 @@ namespace arduino { namespace bpid {
4141
uint8_t out[SHA256::HASH_SIZE];
4242
arduino::sha256::oneshot(data, sizeof(data), out);
4343
return arduino::hex::encode(out, sizeof(out));
44+
return String("");
4445
}
4546

4647
}} // arduino::bpid

src/bpid/bpid.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ namespace arduino { namespace bpid {
2020
* This library contains the methods to get board provisioning id
2121
*/
2222

23-
constexpr int BOARD_PROVISIONING_ID_SIZE = arduino::ucid::UC_UID_SIZE +
24-
arduino::mac::IFACE_MAC_SIZE +
25-
arduino::csn::CRYPTO_SN_SIZE;
23+
constexpr int BOARD_PROVISIONING_ID_SIZE = UC_UID_SIZE +
24+
IFACE_MAC_ADDR_LENGTH +
25+
CRYPTO_SN_SIZE;
2626

2727
bool get(uint8_t* in, uint32_t size);
2828
String get();

src/bpid/csn.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
namespace arduino { namespace csn {
1414

1515
bool get(uint8_t *in, uint32_t size) {
16-
#if defined ARDUINO_UNOR4_WIFI
17-
return false;
16+
#if CRYPTO_SN_SIZE == 0
17+
return false;
1818
#else
1919
if (size < CRYPTO_SN_SIZE) {
2020
return false;

src/bpid/csn.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ namespace arduino { namespace csn {
1919
*/
2020

2121
#if defined(ARDUINO_NANO_RP2040_CONNECT) || \
22-
defined(ARDUINO_SAMD_MKRWIFI1010) || \
2322
defined(ARDUINO_SAMD_NANO_33_IOT) || \
23+
defined(ARDUINO_SAMD_MKRWIFI1010) || \
24+
defined(ARDUINO_SAMD_MKRGSM1400) || \
25+
defined(ARDUINO_SAMD_MKRWAN1300) || \
26+
defined(ARDUINO_SAMD_MKRWAN1310) || \
27+
defined(ARDUINO_SAMD_MKRNB1500) || \
28+
defined(ARDUINO_SAMD_MKR1000) || \
2429
defined(ARDUINO_PORTENTA_H7_M7) || \
2530
defined(ARDUINO_OPTA) || \
2631
defined(ARDUINO_GIGA)
27-
constexpr int CRYPTO_SN_SIZE = 9;
32+
#define CRYPTO_SN_SIZE 9
2833
#elif defined(ARDUINO_PORTENTA_C33) || \
2934
defined(ARDUINO_NICLA_VISION)
30-
constexpr int CRYPTO_SN_SIZE = SE05X_SN_LENGTH;
35+
#define CRYPTO_SN_SIZE SE05X_SN_LENGTH
3136
#elif defined(ARDUINO_UNOR4_WIFI)
32-
constexpr int CRYPTO_SN_SIZE = 6;
37+
#define CRYPTO_SN_SIZE 6
3338
#else
34-
#error "Unknown board"
39+
#define CRYPTO_SN_SIZE 0
3540
#endif
3641

3742
bool get(uint8_t *in, uint32_t size);

src/bpid/mac.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,29 @@
1313
namespace arduino { namespace mac {
1414

1515
bool get(uint8_t *in, uint32_t size) {
16-
if (size < IFACE_MAC_SIZE) {
16+
#if IFACE_MAC_ADDR_LENGTH == 0
17+
return false;
18+
#else
19+
if (size < IFACE_MAC_ADDR_LENGTH) {
1720
return false;
1821
}
19-
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
20-
defined(ARDUINO_SAMD_NANO_33_IOT)
22+
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
23+
defined(ARDUINO_SAMD_NANO_33_IOT)
2124
WiFi.macAddress(in);
22-
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
23-
defined(ARDUINO_NICLA_VISION) || \
24-
defined(ARDUINO_GIGA)
25+
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
26+
defined(ARDUINO_NICLA_VISION) || \
27+
defined(ARDUINO_GIGA)
2528
WiFi.macAddress(in);
26-
#elif defined(ARDUINO_PORTENTA_C33) || \
27-
defined(ARDUINO_UNOR4_WIFI)
29+
#elif defined(ARDUINO_PORTENTA_C33) || \
30+
defined(ARDUINO_UNOR4_WIFI)
2831
WiFi.macAddress(in);
29-
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
32+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
3033
WiFi.macAddress(in);
31-
#elif defined(ARDUINO_OPTA)
34+
#elif defined(ARDUINO_OPTA)
3235
Ethernet.MACAddress(in);
33-
#endif
36+
#endif
3437
return true;
38+
#endif
3539
}
3640

3741
}} // arduino::mac

src/bpid/mac.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <Ethernet.h>
2929
#define IFACE_MAC_ADDR_LENGTH 6
3030
#else
31-
#error "Unknown board"
31+
#define IFACE_MAC_ADDR_LENGTH 0
3232
#endif
3333

3434
namespace arduino { namespace mac {
@@ -45,8 +45,6 @@ namespace arduino { namespace mac {
4545
* ARDUINO_OPTA: Ethernet.begin(NULL,0,0); reversed
4646
*/
4747

48-
constexpr int IFACE_MAC_SIZE = IFACE_MAC_ADDR_LENGTH;
49-
5048
bool get(uint8_t *in, uint32_t size);
5149

5250
}} // arduino::mac

src/bpid/ucid.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,40 @@
1313
namespace arduino { namespace ucid {
1414

1515
bool get(uint8_t *in, uint32_t size) {
16+
#if UC_UID_SIZE == 0
17+
return false;
18+
#else
1619
if (size < UC_UID_SIZE) {
1720
return false;
1821
}
19-
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
20-
defined(ARDUINO_SAMD_NANO_33_IOT)
22+
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
23+
defined(ARDUINO_SAMD_NANO_33_IOT)
2124
(*(uint32_t*)(&in[0x0])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A00C));
2225
(*(uint32_t*)(&in[0x4])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A040));
2326
(*(uint32_t*)(&in[0x8])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A044));
2427
(*(uint32_t*)(&in[0xC])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A048));
25-
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
26-
defined(ARDUINO_NICLA_VISION) || \
27-
defined(ARDUINO_OPTA) || \
28-
defined(ARDUINO_GIGA)
28+
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
29+
defined(ARDUINO_NICLA_VISION) || \
30+
defined(ARDUINO_OPTA) || \
31+
defined(ARDUINO_GIGA)
2932
(*(uint32_t*)(&in[0x0])) = __builtin_bswap32(HAL_GetUIDw0());
3033
(*(uint32_t*)(&in[0x4])) = __builtin_bswap32(HAL_GetUIDw1());
3134
(*(uint32_t*)(&in[0x8])) = __builtin_bswap32(HAL_GetUIDw2());
32-
#elif defined(ARDUINO_PORTENTA_C33) || \
33-
defined(ARDUINO_UNOR4_WIFI)
35+
#elif defined(ARDUINO_PORTENTA_C33) || \
36+
defined(ARDUINO_UNOR4_WIFI)
3437
const bsp_unique_id_t* t = R_BSP_UniqueIdGet();
3538
(*(uint32_t*)(&in[0x0])) = __builtin_bswap32(t->unique_id_words[0x0]);
3639
(*(uint32_t*)(&in[0x4])) = __builtin_bswap32(t->unique_id_words[0x1]);
3740
(*(uint32_t*)(&in[0x8])) = __builtin_bswap32(t->unique_id_words[0x2]);
3841
(*(uint32_t*)(&in[0xC])) = __builtin_bswap32(t->unique_id_words[0x3]);
39-
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
42+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
4043
uint8_t id[UC_UID_SIZE];
4144
flash_get_unique_id(id);
4245
(*(uint32_t*)(&in[0x0])) = __builtin_bswap32(*(uint32_t*)&id[0x0]);
4346
(*(uint32_t*)(&in[0x4])) = __builtin_bswap32(*(uint32_t*)&id[0x4]);
44-
#endif
47+
#endif
4548
return true;
49+
#endif
4650
}
4751

4852
}} // arduino::ucid

src/bpid/ucid.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ namespace arduino { namespace ucid {
1919

2020
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
2121
defined(ARDUINO_SAMD_NANO_33_IOT)
22-
constexpr int UC_UID_SIZE = 16;
22+
#define UC_UID_SIZE 16
2323
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
2424
defined(ARDUINO_NICLA_VISION) || \
2525
defined(ARDUINO_OPTA) || \
2626
defined(ARDUINO_GIGA)
27-
constexpr int UC_UID_SIZE = 12;
27+
#define UC_UID_SIZE 12
2828
#elif defined(ARDUINO_PORTENTA_C33) || \
2929
defined(ARDUINO_UNOR4_WIFI)
30-
constexpr int UC_UID_SIZE = 16;
30+
#define UC_UID_SIZE 16
3131
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
3232
extern "C" {
3333
#include "hardware/flash.h"
3434
}
35-
constexpr int UC_UID_SIZE = FLASH_UNIQUE_ID_SIZE_BYTES;
35+
#define UC_UID_SIZE FLASH_UNIQUE_ID_SIZE_BYTES
3636
#else
37-
#error "Unknown board"
37+
#define UC_UID_SIZE 0
3838
#endif
3939

4040
bool get(uint8_t *in, uint32_t size);

0 commit comments

Comments
 (0)