Skip to content

Bpid: allow build on all boards #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions src/bpid/bpid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/bpid/bpid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/bpid/csn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
namespace arduino { namespace csn {

bool get(uint8_t *in, uint32_t size) {
#if defined ARDUINO_UNOR4_WIFI
return false;
#if CRYPTO_SN_SIZE == 0
(void)in;
(void)size;
return false;
#else
if (size < CRYPTO_SN_SIZE) {
return false;
Expand Down
29 changes: 18 additions & 11 deletions src/bpid/csn.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,36 @@
#pragma once

#include <Arduino.h>
#include <Arduino_SecureElement.h>

namespace arduino { namespace csn {
/*
* This library contains the methods to get board microcontroller id
*/

#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;
#include <Arduino_SecureElement.h>
#define CRYPTO_SN_SIZE 0
#elif defined(ARDUINO_PORTENTA_C33) || \
defined(ARDUINO_NICLA_VISION)
constexpr int CRYPTO_SN_SIZE = SE05X_SN_LENGTH;
#include <Arduino_SecureElement.h>
#define CRYPTO_SN_SIZE 0
#elif defined(ARDUINO_UNOR4_WIFI)
constexpr int CRYPTO_SN_SIZE = 6;
#include <Arduino_SecureElement.h>
#define CRYPTO_SN_SIZE 0
#else
#error "Unknown board"
#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
28 changes: 17 additions & 11 deletions src/bpid/mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,31 @@
namespace arduino { namespace mac {

bool get(uint8_t *in, uint32_t size) {
if (size < IFACE_MAC_SIZE) {
#if IFACE_MAC_ADDR_LENGTH == 0
(void)in;
(void)size;
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
6 changes: 3 additions & 3 deletions src/bpid/mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#pragma once

#include <Arduino.h>

#if defined(ARDUINO_NANO_RP2040_CONNECT) || \
defined(ARDUINO_SAMD_MKRWIFI1010) || \
defined(ARDUINO_SAMD_NANO_33_IOT) || \
Expand All @@ -28,7 +30,7 @@
#include <Ethernet.h>
#define IFACE_MAC_ADDR_LENGTH 6
#else
#error "Unknown board"
#define IFACE_MAC_ADDR_LENGTH 0
#endif

namespace arduino { namespace mac {
Expand All @@ -45,8 +47,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
26 changes: 16 additions & 10 deletions src/bpid/ucid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,42 @@
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) {
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
29 changes: 17 additions & 12 deletions src/bpid/ucid.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,36 @@

#include <Arduino.h>

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)
constexpr int UC_UID_SIZE = 16;
#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) || \
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

namespace arduino { namespace ucid {
/*
* This library contains the methods to get board microcontroller id
*/

bool get(uint8_t *in, uint32_t size);

}} // arduino::ucid
Loading