Skip to content

Commit 32922b4

Browse files
authored
Merge pull request #9 from pennam/fix-ci
Bpid: allow build on all boards
2 parents a09612c + b2ffa42 commit 32922b4

File tree

9 files changed

+87
-54
lines changed

9 files changed

+87
-54
lines changed

.github/workflows/compile-examples.yml

+6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@ jobs:
2121
UNIVERSAL_LIBRARIES: |
2222
- source-path: ./
2323
- name: Arduino_DebugUtils
24+
- name: Arduino_SecureElement
25+
- name: ArduinoECCX08
26+
- name: WiFiNINA
2427
# sketch paths to compile (recursive) for all boards
2528
UNIVERSAL_SKETCH_PATHS: |
2629
- examples/lzssDecoder
2730
- examples/crc32
31+
- examples/crc16
32+
- examples/sha256
33+
- examples/boardID
2834
SKETCHES_REPORTS_PATH: sketches-reports
2935

3036
strategy:

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
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+
(void)in;
18+
(void)size;
19+
return false;
1820
#else
1921
if (size < CRYPTO_SN_SIZE) {
2022
return false;

src/bpid/csn.h

+18-11
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,36 @@
1111
#pragma once
1212

1313
#include <Arduino.h>
14-
#include <Arduino_SecureElement.h>
15-
16-
namespace arduino { namespace csn {
17-
/*
18-
* This library contains the methods to get board microcontroller id
19-
*/
2014

2115
#if defined(ARDUINO_NANO_RP2040_CONNECT) || \
22-
defined(ARDUINO_SAMD_MKRWIFI1010) || \
2316
defined(ARDUINO_SAMD_NANO_33_IOT) || \
17+
defined(ARDUINO_SAMD_MKRWIFI1010) || \
18+
defined(ARDUINO_SAMD_MKRGSM1400) || \
19+
defined(ARDUINO_SAMD_MKRWAN1300) || \
20+
defined(ARDUINO_SAMD_MKRWAN1310) || \
21+
defined(ARDUINO_SAMD_MKRNB1500) || \
22+
defined(ARDUINO_SAMD_MKR1000) || \
2423
defined(ARDUINO_PORTENTA_H7_M7) || \
2524
defined(ARDUINO_OPTA) || \
2625
defined(ARDUINO_GIGA)
27-
constexpr int CRYPTO_SN_SIZE = 9;
26+
#include <Arduino_SecureElement.h>
27+
#define CRYPTO_SN_SIZE 0
2828
#elif defined(ARDUINO_PORTENTA_C33) || \
2929
defined(ARDUINO_NICLA_VISION)
30-
constexpr int CRYPTO_SN_SIZE = SE05X_SN_LENGTH;
30+
#include <Arduino_SecureElement.h>
31+
#define CRYPTO_SN_SIZE 0
3132
#elif defined(ARDUINO_UNOR4_WIFI)
32-
constexpr int CRYPTO_SN_SIZE = 6;
33+
#include <Arduino_SecureElement.h>
34+
#define CRYPTO_SN_SIZE 0
3335
#else
34-
#error "Unknown board"
36+
#define CRYPTO_SN_SIZE 0
3537
#endif
3638

39+
namespace arduino { namespace csn {
40+
/*
41+
* This library contains the methods to get board microcontroller id
42+
*/
43+
3744
bool get(uint8_t *in, uint32_t size);
3845

3946
}} // arduino::csn

src/bpid/mac.cpp

+17-11
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,31 @@
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+
(void)in;
18+
(void)size;
19+
return false;
20+
#else
21+
if (size < IFACE_MAC_ADDR_LENGTH) {
1722
return false;
1823
}
19-
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
20-
defined(ARDUINO_SAMD_NANO_33_IOT)
24+
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
25+
defined(ARDUINO_SAMD_NANO_33_IOT)
2126
WiFi.macAddress(in);
22-
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
23-
defined(ARDUINO_NICLA_VISION) || \
24-
defined(ARDUINO_GIGA)
27+
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
28+
defined(ARDUINO_NICLA_VISION) || \
29+
defined(ARDUINO_GIGA)
2530
WiFi.macAddress(in);
26-
#elif defined(ARDUINO_PORTENTA_C33) || \
27-
defined(ARDUINO_UNOR4_WIFI)
31+
#elif defined(ARDUINO_PORTENTA_C33) || \
32+
defined(ARDUINO_UNOR4_WIFI)
2833
WiFi.macAddress(in);
29-
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
34+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
3035
WiFi.macAddress(in);
31-
#elif defined(ARDUINO_OPTA)
36+
#elif defined(ARDUINO_OPTA)
3237
Ethernet.MACAddress(in);
33-
#endif
38+
#endif
3439
return true;
40+
#endif
3541
}
3642

3743
}} // arduino::mac

src/bpid/mac.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#pragma once
1212

13+
#include <Arduino.h>
14+
1315
#if defined(ARDUINO_NANO_RP2040_CONNECT) || \
1416
defined(ARDUINO_SAMD_MKRWIFI1010) || \
1517
defined(ARDUINO_SAMD_NANO_33_IOT) || \
@@ -28,7 +30,7 @@
2830
#include <Ethernet.h>
2931
#define IFACE_MAC_ADDR_LENGTH 6
3032
#else
31-
#error "Unknown board"
33+
#define IFACE_MAC_ADDR_LENGTH 0
3234
#endif
3335

3436
namespace arduino { namespace mac {
@@ -45,8 +47,6 @@ namespace arduino { namespace mac {
4547
* ARDUINO_OPTA: Ethernet.begin(NULL,0,0); reversed
4648
*/
4749

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

5252
}} // arduino::mac

src/bpid/ucid.cpp

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

1515
bool get(uint8_t *in, uint32_t size) {
16+
#if UC_UID_SIZE == 0
17+
(void)in;
18+
(void)size;
19+
return false;
20+
#else
1621
if (size < UC_UID_SIZE) {
1722
return false;
1823
}
19-
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
20-
defined(ARDUINO_SAMD_NANO_33_IOT)
24+
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
25+
defined(ARDUINO_SAMD_NANO_33_IOT)
2126
(*(uint32_t*)(&in[0x0])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A00C));
2227
(*(uint32_t*)(&in[0x4])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A040));
2328
(*(uint32_t*)(&in[0x8])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A044));
2429
(*(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)
30+
#elif defined(ARDUINO_PORTENTA_H7_M7) || \
31+
defined(ARDUINO_NICLA_VISION) || \
32+
defined(ARDUINO_OPTA) || \
33+
defined(ARDUINO_GIGA)
2934
(*(uint32_t*)(&in[0x0])) = __builtin_bswap32(HAL_GetUIDw0());
3035
(*(uint32_t*)(&in[0x4])) = __builtin_bswap32(HAL_GetUIDw1());
3136
(*(uint32_t*)(&in[0x8])) = __builtin_bswap32(HAL_GetUIDw2());
32-
#elif defined(ARDUINO_PORTENTA_C33) || \
33-
defined(ARDUINO_UNOR4_WIFI)
37+
#elif defined(ARDUINO_PORTENTA_C33) || \
38+
defined(ARDUINO_UNOR4_WIFI)
3439
const bsp_unique_id_t* t = R_BSP_UniqueIdGet();
3540
(*(uint32_t*)(&in[0x0])) = __builtin_bswap32(t->unique_id_words[0x0]);
3641
(*(uint32_t*)(&in[0x4])) = __builtin_bswap32(t->unique_id_words[0x1]);
3742
(*(uint32_t*)(&in[0x8])) = __builtin_bswap32(t->unique_id_words[0x2]);
3843
(*(uint32_t*)(&in[0xC])) = __builtin_bswap32(t->unique_id_words[0x3]);
39-
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
44+
#elif defined(ARDUINO_NANO_RP2040_CONNECT)
4045
uint8_t id[UC_UID_SIZE];
4146
flash_get_unique_id(id);
4247
(*(uint32_t*)(&in[0x0])) = __builtin_bswap32(*(uint32_t*)&id[0x0]);
4348
(*(uint32_t*)(&in[0x4])) = __builtin_bswap32(*(uint32_t*)&id[0x4]);
44-
#endif
49+
#endif
4550
return true;
51+
#endif
4652
}
4753

4854
}} // arduino::ucid

src/bpid/ucid.h

+17-12
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,36 @@
1212

1313
#include <Arduino.h>
1414

15-
namespace arduino { namespace ucid {
16-
/*
17-
* This library contains the methods to get board microcontroller id
18-
*/
19-
20-
#if defined(ARDUINO_SAMD_MKRWIFI1010) || \
21-
defined(ARDUINO_SAMD_NANO_33_IOT)
22-
constexpr int UC_UID_SIZE = 16;
15+
#if defined(ARDUINO_SAMD_NANO_33_IOT) || \
16+
defined(ARDUINO_SAMD_MKRWIFI1010) || \
17+
defined(ARDUINO_SAMD_MKRGSM1400) || \
18+
defined(ARDUINO_SAMD_MKRWAN1300) || \
19+
defined(ARDUINO_SAMD_MKRWAN1310) || \
20+
defined(ARDUINO_SAMD_MKRNB1500) || \
21+
defined(ARDUINO_SAMD_MKR1000)
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

40+
namespace arduino { namespace ucid {
41+
/*
42+
* This library contains the methods to get board microcontroller id
43+
*/
44+
4045
bool get(uint8_t *in, uint32_t size);
4146

4247
}} // arduino::ucid

0 commit comments

Comments
 (0)