From a7fe69ed6b15672413ce48d9e634b166d915c3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 13 Oct 2022 12:55:28 +0200 Subject: [PATCH 1/5] Support for ATECCA608B Cryptographic Coprocessor --- platformio.ini | 1 + src/configuration.h | 7 +++++++ src/detect/i2cScan.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 4 ++++ src/main.h | 4 ++++ 5 files changed, 58 insertions(+) diff --git a/platformio.ini b/platformio.ini index 2ac06440b..0c48f7917 100644 --- a/platformio.ini +++ b/platformio.ini @@ -65,6 +65,7 @@ lib_deps = ${env.lib_deps} ; Portduino is using meshtastic fork for now jgromes/RadioLib@5.4.1 + sparkfun/SparkFun ATECCX08a Arduino Library@^1.3.0 build_flags = ${env.build_flags} -Os -DRADIOLIB_SPI_PARANOID=0 diff --git a/src/configuration.h b/src/configuration.h index 524dbec36..2aeb0f4a5 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -110,6 +110,13 @@ along with this program. If not, see . #define INA_ADDR_ALTERNATE 0x41 #define QMC6310_ADDR 0x1C #define QMI8658_ADDR 0x6B + +// ----------------------------------------------------------------------------- +// Security +// ----------------------------------------------------------------------------- + +#define ATECC608B_ADDR 0x35 + // ----------------------------------------------------------------------------- // GPS // ----------------------------------------------------------------------------- diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 3adb44277..69fc1a8a8 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -9,6 +9,39 @@ #endif #if HAS_WIRE + +void printATECCInfo() +{ + atecc.readConfigZone(false); + + DEBUG_MSG("ATECC608B Serial Number: "); + for (int i = 0 ; i < 9 ; i++) { + DEBUG_MSG("%02x",atecc.serialNumber[i]); + } + + DEBUG_MSG(", Rev Number: "); + for (int i = 0 ; i < 4 ; i++) { + DEBUG_MSG("%02x",atecc.revisionNumber[i]); + } + DEBUG_MSG("\n"); + + DEBUG_MSG("ATECC608B Config %s",atecc.configLockStatus ? "Locked" : "Unlocked"); + DEBUG_MSG(", Data %s",atecc.dataOTPLockStatus ? "Locked" : "Unlocked"); + DEBUG_MSG(", Slot 0 %s\n",atecc.slot0LockStatus ? "Locked" : "Unlocked"); + + if (atecc.configLockStatus && atecc.dataOTPLockStatus && atecc.slot0LockStatus) { + if (atecc.generatePublicKey() == false) { + DEBUG_MSG("ATECC608B Error generating public key\n"); + } else { + DEBUG_MSG("ATECC608B Public Key: "); + for (int i = 0 ; i < 64 ; i++) { + DEBUG_MSG("%02x",atecc.publicKey64Bytes[i]); + } + DEBUG_MSG("\n"); + } + } +} + uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length) { uint16_t value = 0x00; Wire.beginTransmission(address); @@ -79,6 +112,15 @@ void scanI2Cdevice(void) DEBUG_MSG("unknown display found\n"); } } + if (addr == ATECC608B_ADDR){ + keystore_found = addr; + if (atecc.begin(keystore_found) == true) { + DEBUG_MSG("ATECC608B initialized\n"); + } else { + DEBUG_MSG("ATECC608B initialization failed\n"); + } + printATECCInfo(); + } #ifdef RV3028_RTC if (addr == RV3028_RTC){ rtc_found = addr; diff --git a/src/main.cpp b/src/main.cpp index c3f892bce..a17de7eca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -80,6 +80,10 @@ uint8_t kb_model; // The I2C address of the RTC Module (if found) uint8_t rtc_found; +// Keystore Chips +uint8_t keystore_found; +ATECCX08A atecc; + bool eink_found = true; uint32_t serialSinceMsec; diff --git a/src/main.h b/src/main.h index f3f9c62c9..f0f18a943 100644 --- a/src/main.h +++ b/src/main.h @@ -6,18 +6,22 @@ #include "PowerStatus.h" #include "graphics/Screen.h" #include "mesh/generated/telemetry.pb.h" +#include extern uint8_t screen_found; extern uint8_t screen_model; extern uint8_t cardkb_found; extern uint8_t kb_model; extern uint8_t rtc_found; +extern uint8_t keystore_found; extern bool eink_found; extern bool pmu_found; extern bool isCharging; extern bool isUSBPowered; +extern ATECCX08A atecc; + extern uint8_t nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658+1]; extern int TCPPort; // set by Portduino From b5fb0f60b0d748d03380bae29f4add3d08d2a14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 13 Oct 2022 13:01:24 +0200 Subject: [PATCH 2/5] don't compile on Portduino --- src/detect/i2cScan.h | 4 ++++ src/main.cpp | 2 ++ src/main.h | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 69fc1a8a8..1148495ba 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -12,6 +12,7 @@ void printATECCInfo() { +#ifndef ARCH_PORTDUINO atecc.readConfigZone(false); DEBUG_MSG("ATECC608B Serial Number: "); @@ -40,6 +41,7 @@ void printATECCInfo() DEBUG_MSG("\n"); } } +#endif } uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length) { @@ -112,6 +114,7 @@ void scanI2Cdevice(void) DEBUG_MSG("unknown display found\n"); } } +#ifndef ARCH_PORTDUINO if (addr == ATECC608B_ADDR){ keystore_found = addr; if (atecc.begin(keystore_found) == true) { @@ -121,6 +124,7 @@ void scanI2Cdevice(void) } printATECCInfo(); } +#endif #ifdef RV3028_RTC if (addr == RV3028_RTC){ rtc_found = addr; diff --git a/src/main.cpp b/src/main.cpp index a17de7eca..8779a6ab0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,7 +82,9 @@ uint8_t rtc_found; // Keystore Chips uint8_t keystore_found; +#ifndef ARCH_PORTDUINO ATECCX08A atecc; +#endif bool eink_found = true; diff --git a/src/main.h b/src/main.h index f0f18a943..3744c8acd 100644 --- a/src/main.h +++ b/src/main.h @@ -6,7 +6,9 @@ #include "PowerStatus.h" #include "graphics/Screen.h" #include "mesh/generated/telemetry.pb.h" +#ifndef ARCH_PORTDUINO #include +#endif extern uint8_t screen_found; extern uint8_t screen_model; @@ -20,7 +22,9 @@ extern bool pmu_found; extern bool isCharging; extern bool isUSBPowered; +#ifndef ARCH_PORTDUINO extern ATECCX08A atecc; +#endif extern uint8_t nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658+1]; From 6e22ee9061553e30a6bf94cb2e7f6d81f74ff3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 13 Oct 2022 13:31:19 +0200 Subject: [PATCH 3/5] make nRF52 happy --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 0c48f7917..44572632c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -65,7 +65,7 @@ lib_deps = ${env.lib_deps} ; Portduino is using meshtastic fork for now jgromes/RadioLib@5.4.1 - sparkfun/SparkFun ATECCX08a Arduino Library@^1.3.0 + https://github.com/caveman99/SparkFun_ATECCX08a_Arduino_Library.git#bf41031838d3e9b9fd9df846e6b26c1e6b22051c build_flags = ${env.build_flags} -Os -DRADIOLIB_SPI_PARANOID=0 From 994e396c0013b801b298c795991f443b612f7fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 13 Oct 2022 13:57:17 +0200 Subject: [PATCH 4/5] update Raspberry Pico Framework --- arch/rp2040/rp2040.ini | 1 - platformio.ini | 2 +- variants/{pico => rpipico}/platformio.ini | 4 +- variants/{pico => rpipico}/variant.h | 0 variants/rpipicow/platformio.ini | 17 ++++++++ variants/rpipicow/variant.h | 52 +++++++++++++++++++++++ 6 files changed, 72 insertions(+), 4 deletions(-) rename variants/{pico => rpipico}/platformio.ini (90%) rename variants/{pico => rpipico}/variant.h (100%) create mode 100644 variants/rpipicow/platformio.ini create mode 100644 variants/rpipicow/variant.h diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index 6660cccd2..20c99dc5e 100644 --- a/arch/rp2040/rp2040.ini +++ b/arch/rp2040/rp2040.ini @@ -2,7 +2,6 @@ [rp2040_base] platform = https://github.com/maxgerhardt/platform-raspberrypi.git extends = arduino_base -board_build.core = earlephilhower board_build.filesystem_size = 0.5m build_flags = ${arduino_base.build_flags} -Wno-unused-variable diff --git a/platformio.ini b/platformio.ini index 44572632c..bc46f3f23 100644 --- a/platformio.ini +++ b/platformio.ini @@ -65,7 +65,7 @@ lib_deps = ${env.lib_deps} ; Portduino is using meshtastic fork for now jgromes/RadioLib@5.4.1 - https://github.com/caveman99/SparkFun_ATECCX08a_Arduino_Library.git#bf41031838d3e9b9fd9df846e6b26c1e6b22051c + https://github.com/caveman99/SparkFun_ATECCX08a_Arduino_Library.git#008e7f9d40bad66b2f7a0074aaac05b7c424339d build_flags = ${env.build_flags} -Os -DRADIOLIB_SPI_PARANOID=0 diff --git a/variants/pico/platformio.ini b/variants/rpipico/platformio.ini similarity index 90% rename from variants/pico/platformio.ini rename to variants/rpipico/platformio.ini index 4f238fa14..122fbd42f 100644 --- a/variants/pico/platformio.ini +++ b/variants/rpipico/platformio.ini @@ -1,12 +1,12 @@ [env:pico] extends = rp2040_base -board = pico +board = rpipico upload_protocol = picotool # add our variants files to the include and src paths build_flags = ${rp2040_base.build_flags} -DPRIVATE_HW - -Ivariants/pico + -Ivariants/rpipico -DARDUINO_AVR_NANO_EVERY -DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI diff --git a/variants/pico/variant.h b/variants/rpipico/variant.h similarity index 100% rename from variants/pico/variant.h rename to variants/rpipico/variant.h diff --git a/variants/rpipicow/platformio.ini b/variants/rpipicow/platformio.ini new file mode 100644 index 000000000..697ec1caa --- /dev/null +++ b/variants/rpipicow/platformio.ini @@ -0,0 +1,17 @@ +[env:picow] +extends = rp2040_base +board = rpipicow +upload_protocol = picotool + +# add our variants files to the include and src paths +build_flags = ${rp2040_base.build_flags} + -DPRIVATE_HW + -Ivariants/rpipicow + -DARDUINO_AVR_NANO_EVERY + -DDEBUG_RP2040_WIRE + -DDEBUG_RP2040_SPI + -DDEBUG_RP2040_CORE + -DDEBUG_RP2040_PORT=Serial + -DUSE_TINYUSB +lib_deps = + ${rp2040_base.lib_deps} \ No newline at end of file diff --git a/variants/rpipicow/variant.h b/variants/rpipicow/variant.h new file mode 100644 index 000000000..d620a356b --- /dev/null +++ b/variants/rpipicow/variant.h @@ -0,0 +1,52 @@ +// #define RADIOLIB_CUSTOM_ARDUINO 1 +// #define RADIOLIB_TONE_UNSUPPORTED 1 +// #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED 1 + +#define ARDUINO_ARCH_AVR + +#define CBC 0 +#define CTR 1 +#define ECB 0 + +#define NO_GPS 1 +#define USE_SH1106 1 +#undef GPS_SERIAL_NUM + +// #define I2C_SDA 6 +// #define I2C_SCL 7 + +#define BUTTON_PIN 17 +#define EXT_NOTIFY_OUT 4 + +#define BATTERY_PIN 26 +// ratio of voltage divider = 3.0 (R17=200k, R18=100k) +#define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic + +#define USE_RF95 +#define USE_SX1262 + +#undef RF95_SCK +#undef RF95_MISO +#undef RF95_MOSI +#undef RF95_NSS + +#define RF95_SCK 10 +#define RF95_MISO 12 +#define RF95_MOSI 11 +#define RF95_NSS 3 + +#define LORA_DIO0 RADIOLIB_NC +#define LORA_RESET 15 +#define LORA_DIO1 20 +#define LORA_DIO2 2 +#define LORA_DIO3 RADIOLIB_NC + +#ifdef USE_SX1262 +#define SX126X_CS RF95_NSS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_E22 +#endif + +#include \ No newline at end of file From 7b10441a285fd013b03c69031a44365553cd85dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 13 Oct 2022 14:21:48 +0200 Subject: [PATCH 5/5] update raspberry pi framework some more... --- arch/rp2040/rp2040.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index 20c99dc5e..9eea340bf 100644 --- a/arch/rp2040/rp2040.ini +++ b/arch/rp2040/rp2040.ini @@ -1,7 +1,8 @@ ; Common settings for rp2040 Processor based targets [rp2040_base] -platform = https://github.com/maxgerhardt/platform-raspberrypi.git +platform = https://github.com/maxgerhardt/platform-raspberrypi.git#5ce1a228e7cae453f366deb8962252b9b7356bbc extends = arduino_base +board_build.core = earlephilhower board_build.filesystem_size = 0.5m build_flags = ${arduino_base.build_flags} -Wno-unused-variable