From 9d4af1146e8273645693405f83a88cc9574de697 Mon Sep 17 00:00:00 2001 From: Ric In New Mexico <78682404+RicInNewMexico@users.noreply.github.com> Date: Fri, 17 Nov 2023 05:46:59 -0700 Subject: [PATCH 01/33] INA3221 bugfixes & refinement (#2944) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reorganized and refactored some INA3221 code Added comments Added missing shunt resistor value (100mΩ) Added INA3221 Channel 1 to getINAVoltage() for device battery monitoring modified: src/Power.cpp modified: src/modules/Telemetry/PowerTelemetry.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.h modified: src/power.h --- src/Power.cpp | 4 ++++ src/modules/Telemetry/PowerTelemetry.cpp | 5 ----- src/modules/Telemetry/Sensor/INA3221Sensor.cpp | 3 ++- src/modules/Telemetry/Sensor/INA3221Sensor.h | 15 +++++++++------ src/power.h | 2 ++ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 72bb38181..c7392c90b 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -52,6 +52,7 @@ static const adc_atten_t atten = ADC_ATTENUATION; #if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) INA260Sensor ina260Sensor; INA219Sensor ina219Sensor; +INA3221Sensor ina3221Sensor; #endif #ifdef HAS_PMU @@ -286,6 +287,9 @@ class AnalogBatteryLevel : public HasBatteryLevel } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first == config.power.device_battery_ina_address) { return ina260Sensor.getBusVoltageMv(); + } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first == + config.power.device_battery_ina_address) { + return ina3221Sensor.getBusVoltageMv(); } return 0; } diff --git a/src/modules/Telemetry/PowerTelemetry.cpp b/src/modules/Telemetry/PowerTelemetry.cpp index 53e26ee6a..032d7fc27 100644 --- a/src/modules/Telemetry/PowerTelemetry.cpp +++ b/src/modules/Telemetry/PowerTelemetry.cpp @@ -11,11 +11,6 @@ #include "sleep.h" #include "target_specific.h" -#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) -#include "Sensor/INA3221Sensor.h" -INA3221Sensor ina3221Sensor; -#endif - #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true diff --git a/src/modules/Telemetry/Sensor/INA3221Sensor.cpp b/src/modules/Telemetry/Sensor/INA3221Sensor.cpp index 634f5a5c9..3269ba47a 100644 --- a/src/modules/Telemetry/Sensor/INA3221Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA3221Sensor.cpp @@ -13,8 +13,9 @@ int32_t INA3221Sensor::runOnce() return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } if (!status) { - ina3221.setAddr(INA3221_ADDR42_SDA); + ina3221.setAddr(INA3221_ADDR42_SDA); // i2c address 0x42 ina3221.begin(); + ina3221.setShuntRes(100, 100, 100); // 0.1 Ohm shunt resistors status = true; } else { status = true; diff --git a/src/modules/Telemetry/Sensor/INA3221Sensor.h b/src/modules/Telemetry/Sensor/INA3221Sensor.h index a1c0fb2a7..4c82fc34d 100644 --- a/src/modules/Telemetry/Sensor/INA3221Sensor.h +++ b/src/modules/Telemetry/Sensor/INA3221Sensor.h @@ -1,16 +1,19 @@ #include "../mesh/generated/meshtastic/telemetry.pb.h" #include "TelemetrySensor.h" +#include "VoltageSensor.h" #include -class INA3221Sensor : public TelemetrySensor +class INA3221Sensor : public TelemetrySensor, VoltageSensor { + private: + INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA); + + protected: + void setup() override; + public: INA3221Sensor(); int32_t runOnce() override; - void setup() override; bool getMetrics(meshtastic_Telemetry *measurement) override; - virtual uint16_t getBusVoltageMv(); - - private: - INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA); + virtual uint16_t getBusVoltageMv() override; }; \ No newline at end of file diff --git a/src/power.h b/src/power.h index e90e3f21b..54d98e715 100644 --- a/src/power.h +++ b/src/power.h @@ -25,8 +25,10 @@ extern RTC_NOINIT_ATTR uint64_t RTC_reg_b; #if HAS_TELEMETRY && !defined(ARCH_PORTDUINO) #include "modules/Telemetry/Sensor/INA219Sensor.h" #include "modules/Telemetry/Sensor/INA260Sensor.h" +#include "modules/Telemetry/Sensor/INA3221Sensor.h" extern INA260Sensor ina260Sensor; extern INA219Sensor ina219Sensor; +extern INA3221Sensor ina3221Sensor; #endif class Power : private concurrency::OSThread From 46bd6ca7ba7c322a2d9fe2549296dfb39ee5a55a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 18 Nov 2023 08:12:34 -0600 Subject: [PATCH 02/33] YAML based config for PI / Portduino (#2943) * Add configuration via /etc/meshtastic/config.yaml * Move example config, support more locations * Fix config check * Use access() to check for config file presence * Throw an error and exit on radio init fail * Adds error check for reading Bluetooth MAC * Settle on meshtasticd, add install script * Shell fixes * Fine. I'll put it back and then disable you * Get wrekt, shellchekt * Firat attempt at adding raspbian CI build * Tickle the workflow * Beatings will continue til morale improves * Permissions are overrated --------- Co-authored-by: Jonathan Bennett --- .github/workflows/build_raspbian.yml | 30 +++++++++++++ .trunk/configs/.shellcheckrc | 3 ++ bin/build-native.sh | 16 ++++--- bin/config-dist.yaml | 26 +++++++++++ bin/meshtasticd.service | 9 ++++ bin/native-install.sh | 10 +++++ src/configuration.h | 6 +-- src/gps/GPS.cpp | 3 ++ src/main.cpp | 36 +++++++++++---- src/mesh/SX126xInterface.cpp | 11 ++++- src/platform/portduino/PortduinoGlue.cpp | 56 ++++++++++++++++++++++-- src/platform/portduino/PortduinoGlue.h | 21 +++++++++ variants/portduino/platformio.ini | 2 +- variants/portduino/variant.h | 28 ------------ 14 files changed, 206 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/build_raspbian.yml create mode 100644 bin/config-dist.yaml create mode 100644 bin/meshtasticd.service create mode 100755 bin/native-install.sh create mode 100644 src/platform/portduino/PortduinoGlue.h diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml new file mode 100644 index 000000000..1860e9098 --- /dev/null +++ b/.github/workflows/build_raspbian.yml @@ -0,0 +1,30 @@ +name: Build Raspbian + +on: workflow_call + +permissions: + contents: write + packages: write + +jobs: + build-raspbian: + runs-on: [self-hosted, linux, ARM64] + steps: + - uses: actions/checkout@v3 + - name: Build base + id: base + uses: ./.github/actions/setup-base + + - name: Build Raspbian + run: bin/build-native.sh + + - name: Get release version string + run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT + id: version + + - name: Store binaries as an artifact + uses: actions/upload-artifact@v3 + with: + name: firmware-native-${{ steps.version.outputs.version }}.zip + path: | + release/meshtasticd_linux_arm64 diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc index 8c7b1ada8..b2e8a14cc 100644 --- a/.trunk/configs/.shellcheckrc +++ b/.trunk/configs/.shellcheckrc @@ -1,7 +1,10 @@ enable=all source-path=SCRIPTDIR disable=SC2154 +disable=SC2248 +disable=SC2250 # If you're having issues with shellcheck following source, disable the errors via: # disable=SC1090 # disable=SC1091 +# \ No newline at end of file diff --git a/bin/build-native.sh b/bin/build-native.sh index 8bc262860..64c5adb50 100755 --- a/bin/build-native.sh +++ b/bin/build-native.sh @@ -2,8 +2,8 @@ set -e -VERSION=`bin/buildinfo.py long` -SHORT_VERSION=`bin/buildinfo.py short` +VERSION=$(bin/buildinfo.py long) +SHORT_VERSION=$(bin/buildinfo.py short) OUTDIR=release/ @@ -13,11 +13,15 @@ mkdir -p $OUTDIR/ rm -r $OUTDIR/* || true # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio pkg update +platformio pkg update -pio run --environment native -cp .pio/build/native/program $OUTDIR/meshtasticd_linux_amd64 +if command -v raspi-config &>/dev/null; then + pio run --environment raspbian + cp .pio/build/raspbian/program $OUTDIR/meshtasticd_linux_arm64 +else + pio run --environment native + cp .pio/build/native/program $OUTDIR/meshtasticd_linux_amd64 +fi cp bin/device-install.* $OUTDIR cp bin/device-update.* $OUTDIR - diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml new file mode 100644 index 000000000..2a3abac6f --- /dev/null +++ b/bin/config-dist.yaml @@ -0,0 +1,26 @@ +# Define your devices here. +# Use Broadcom pin numbering + +#Waveshare SX126X XXXM + +#USE_SX1262: true +#SX126X_DIO2_AS_RF_SWITCH: true +#SX126X_CS: 21 +#SX126X_DIO1: 16 +#SX126X_BUSY: 20 +#SX126X_RESET: 18 + +#Waveshare SX1302 LISTEN ONLY AT THIS TIME! + +#USE_SX1262: true +#SX126X_CS: 7 +#SX126X_DIO1: 17 +#SX126X_RESET: 22 + +#Adafruit RFM9x + +#USE_RF95: true +#RF95_RESET: 25 +#RF95_NSS: 7 +#RF95_IRQ: 22 +#RF95_DIO1: 23 diff --git a/bin/meshtasticd.service b/bin/meshtasticd.service new file mode 100644 index 000000000..4ed1bfd8f --- /dev/null +++ b/bin/meshtasticd.service @@ -0,0 +1,9 @@ +[unit] +description=Meshtastic Native Daemon + +[Service] +Type=simple +ExecStart=/usr/sbin/meshtasticd + +[Install] +WantedBy=multi-user.target diff --git a/bin/native-install.sh b/bin/native-install.sh new file mode 100755 index 000000000..d1d0c8707 --- /dev/null +++ b/bin/native-install.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +cp release/meshtasticd_linux_arm64 /usr/sbin/meshtasticd +mkdir /etc/meshtasticd +if [[ -f "/etc/meshtasticd/config.yaml" ]]; then + cp bin/config-dist.yaml /etc/meshtasticd/config-upgrade.yaml +else + cp bin/config-dist.yaml /etc/meshtasticd/config.yaml +fi +cp bin/meshtasticd.service /usr/lib/systemd/system/meshtasticd.service diff --git a/src/configuration.h b/src/configuration.h index 199880c6b..cb7ee218b 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -57,8 +57,8 @@ along with this program. If not, see . #define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found /// Convert a preprocessor name into a quoted string -#define xstr(s) str(s) -#define str(s) #s +#define xstr(s) ystr(s) +#define ystr(s) #s /// Convert a preprocessor name into a quoted string and if that string is empty use "unset" #define optstr(s) (xstr(s)[0] ? xstr(s) : "unset") @@ -209,4 +209,4 @@ along with this program. If not, see . #ifndef HW_VENDOR #error HW_VENDOR must be defined -#endif +#endif \ No newline at end of file diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 47ba067d2..af622e3d8 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -17,6 +17,9 @@ #if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(ARCH_ESP32) HardwareSerial *GPS::_serial_gps = &Serial1; +#elif defined(ARCH_RASPBERRY_PI) +// need a translation layer to make _serial_gps work with pigpio https://abyz.me.uk/rpi/pigpio/cif.html#serOpen +HardwareSerial *GPS::_serial_gps = NULL; #else HardwareSerial *GPS::_serial_gps = NULL; #endif diff --git a/src/main.cpp b/src/main.cpp index d5b3895d2..5c3151fc0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,6 +69,7 @@ NRF52Bluetooth *nrf52Bluetooth; #ifdef ARCH_RASPBERRY_PI #include "platform/portduino/PiHal.h" +#include "platform/portduino/PortduinoGlue.h" #include #include #include @@ -690,15 +691,32 @@ void setup() #endif #ifdef ARCH_RASPBERRY_PI - PiHal *RadioLibHAL = new PiHal(1); - if (!rIf) { - rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, 21, 16, 18, 20); - if (!rIf->init()) { - LOG_WARN("Failed to find SX1262 radio\n"); - delete rIf; - rIf = NULL; - } else { - LOG_INFO("SX1262 Radio init succeeded, using SX1262 radio\n"); + if (settingsMap[use_sx1262]) { + if (!rIf) { + PiHal *RadioLibHAL = new PiHal(1); + rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[sx126x_cs], settingsMap[sx126x_dio1], + settingsMap[sx126x_reset], settingsMap[sx126x_busy]); + if (!rIf->init()) { + LOG_ERROR("Failed to find SX1262 radio\n"); + delete rIf; + exit(EXIT_FAILURE); + } else { + LOG_INFO("SX1262 Radio init succeeded, using SX1262 radio\n"); + } + } + } else if (settingsMap[use_rf95]) { + if (!rIf) { + PiHal *RadioLibHAL = new PiHal(1); + rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[rf95_nss], settingsMap[rf95_irq], + settingsMap[rf95_reset], settingsMap[rf95_dio1]); + if (!rIf->init()) { + LOG_ERROR("Failed to find RF95 radio\n"); + delete rIf; + rIf = NULL; + exit(EXIT_FAILURE); + } else { + LOG_INFO("RF95 Radio init succeeded, using RF95 radio\n"); + } } } diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index 980107917..ba3f2bc2a 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -2,6 +2,9 @@ #include "configuration.h" #include "error.h" #include "mesh/NodeDB.h" +#ifdef ARCH_RASPBERRY_PI +#include "PortduinoGlue.h" +#endif // Particular boards might define a different max power based on what their hardware can do, default to max power output if not // specified (may be dangerous if using external PA and SX126x power config forgotten) @@ -74,6 +77,12 @@ template bool SX126xInterface::init() #ifdef SX126X_DIO2_AS_RF_SWITCH LOG_DEBUG("Setting DIO2 as RF switch\n"); bool dio2AsRfSwitch = true; +#elif defined(ARCH_RASPBERRY_PI) + bool dio2AsRfSwitch = false; + if (settingsMap[sx126x_dio2_as_rf_switch]) { + LOG_DEBUG("Setting DIO2 as RF switch\n"); + dio2AsRfSwitch = true; + } #else LOG_DEBUG("Setting DIO2 as not RF switch\n"); bool dio2AsRfSwitch = false; @@ -318,4 +327,4 @@ template bool SX126xInterface::sleep() #endif return true; -} +} \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index fb71a429b..b3c2dc5f2 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -9,7 +9,14 @@ #include #ifdef ARCH_RASPBERRY_PI +#include "PortduinoGlue.h" #include "pigpio.h" +#include "yaml-cpp/yaml.h" +#include +#include +#include + +std::map settingsMap; #else #include @@ -27,7 +34,7 @@ void cpuDeepSleep(uint32_t msecs) } void updateBatteryLevel(uint8_t level) NOT_IMPLEMENTED("updateBatteryLevel"); - +#ifndef ARCH_RASPBERRY_PI /** a simulated pin for busted IRQ hardware * Porduino helper class to do this i2c based polling: */ @@ -54,7 +61,7 @@ class PolledIrqPin : public GPIOPin }; static GPIOPin *loraIrq; - +#endif int TCPPort = 4403; static error_t parse_opt(int key, char *arg, struct argp_state *state) @@ -94,6 +101,48 @@ void portduinoSetup() printf("Setting up Meshtastic on Portduino...\n"); #ifdef ARCH_RASPBERRY_PI + YAML::Node yamlConfig; + + if (access("config.yaml", R_OK) == 0) { + try { + yamlConfig = YAML::LoadFile("config.yaml"); + } catch (YAML::Exception e) { + std::cout << "*** Exception " << e.what() << std::endl; + exit(EXIT_FAILURE); + } + } else if (access("/etc/meshtasticd/config.yaml", R_OK) == 0) { + try { + yamlConfig = YAML::LoadFile("/etc/meshtasticd/config.yaml"); + } catch (YAML::Exception e) { + std::cout << "*** Exception " << e.what() << std::endl; + exit(EXIT_FAILURE); + } + } else { + std::cout << "No 'config.yaml' found, exiting." << std::endl; + exit(EXIT_FAILURE); + } + + try { + settingsMap[use_sx1262] = yamlConfig["USE_SX1262"].as(false); + settingsMap[sx126x_dio2_as_rf_switch] = yamlConfig["SX126X_DIO2_AS_RF_SWITCH"].as(false); + settingsMap[sx126x_cs] = yamlConfig["SX126X_CS"].as(RADIOLIB_NC); + settingsMap[sx126x_dio1] = yamlConfig["SX126X_DIO1"].as(RADIOLIB_NC); + settingsMap[sx126x_busy] = yamlConfig["SX126X_BUSY"].as(RADIOLIB_NC); + settingsMap[sx126x_reset] = yamlConfig["SX126X_RESET"].as(RADIOLIB_NC); + settingsMap[use_rf95] = yamlConfig["USE_RF95"].as(false); + settingsMap[rf95_nss] = yamlConfig["RF95_NSS"].as(RADIOLIB_NC); + settingsMap[rf95_irq] = yamlConfig["RF95_IRQ"].as(RADIOLIB_NC); + settingsMap[rf95_reset] = yamlConfig["RF95_RESET"].as(RADIOLIB_NC); + settingsMap[rf95_dio1] = yamlConfig["RF95_DIO1"].as(RADIOLIB_NC); + + } catch (YAML::Exception e) { + std::cout << "*** Exception " << e.what() << std::endl; + exit(EXIT_FAILURE); + } + if (access("/sys/kernel/debug/bluetooth/hci0/identity", R_OK) != 0) { + std::cout << "Cannot read Bluetooth MAC Address. Please run as root" << std::endl; + exit(EXIT_FAILURE); + } return; #endif @@ -121,7 +170,7 @@ void portduinoSetup() gpioBind(loraCs); } else #endif - +#ifndef ARCH_RASPBERRY_PI { // Set the random seed equal to TCPPort to have a different seed per instance randomSeed(TCPPort); @@ -140,4 +189,5 @@ void portduinoSetup() } // gpioBind((new SimGPIOPin(LORA_RESET, "LORA_RESET"))); // gpioBind((new SimGPIOPin(RF95_NSS, "RF95_NSS"))->setSilent()); +#endif } \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h new file mode 100644 index 000000000..91fc4c2b1 --- /dev/null +++ b/src/platform/portduino/PortduinoGlue.h @@ -0,0 +1,21 @@ +#pragma once +#ifdef ARCH_RASPBERRY_PI +#include + +extern std::map settingsMap; + +enum { + use_sx1262, + sx126x_cs, + sx126x_dio1, + sx126x_busy, + sx126x_reset, + sx126x_dio2_as_rf_switch, + use_rf95, + rf95_nss, + rf95_irq, + rf95_reset, + rf95_dio1 +}; + +#endif \ No newline at end of file diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index 323609d0e..be07bcb15 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -16,7 +16,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Raspberry Pi actually has accessible SPI and GPIO, so we can support real hardware there. [env:raspbian] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -DRADIOLIB_DEBUG -lpigpio +build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -DRADIOLIB_DEBUG -lpigpio -lyaml-cpp board = linux_arm lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index 2ce871ddc..46f7d1f0c 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -1,34 +1,6 @@ #if defined(ARCH_RASPBERRY_PI) -#define HAS_RADIO 1 -#define GPIOD_CHIP_LABEL "pinctrl-bcm2711" - -// define USE_RF95 -#define USE_SX1262 -#define SX126X_TXEN 6 -#define SX126X_DIO2_AS_RF_SWITCH #define NO_SCREEN -#define RF95_SCK 11 -#define RF95_MISO 9 -#define RF95_MOSI 10 -#define RF95_NSS RADIOLIB_NC - -// #define LORA_DIO0 4 // a No connect on the SX1262 module -// #define LORA_DIO0_LABEL "GPIO_GCLK" -#define LORA_RESET 18 -#define LORA_RESET_LABEL "GPIO18" -#define LORA_DIO1 16 // SX1262 IRQ, called DIO0 on pinelora schematic, pin 7 on ch341f "ack" - FIXME, enable hwints in linux -// #define LORA_DIO2 20 // SX1262 BUSY, actually connected to "DIO5" on pinelora schematic, pin 8 on ch341f "slct" -// #define LORA_DIO3 6 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled - -#ifdef USE_SX1262 -#define SX126X_CS 21 -#define SX126X_DIO1 16 -#define SX126X_BUSY 20 -#define SX126X_RESET LORA_RESET -// HOPE RFM90 does not have a TCXO therefore not SX126X_E22 -#endif - #else // Pine64 mode. // Pine64 uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if From dc8903ec4212b901da3bdab9e41b38091531c635 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 08:55:19 -0600 Subject: [PATCH 03/33] Add Raspbian to Main CI (#2948) --- .github/workflows/main_matrix.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 145a75c2d..bd024b0af 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -129,6 +129,12 @@ jobs: with: board: ${{ matrix.board }} + build-raspbian: + strategy: + fail-fast: false + max-parallel: 1 + uses: ./.github/workflows/build_raspbian.yml + build-native: runs-on: ubuntu-latest steps: From b6ddbd0087dce616ed53b9088b0e09970a9c045e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 11:04:21 -0600 Subject: [PATCH 04/33] More CI work for Raspbian (#2949) * More CI work for Raspbian * Workaround quirks of Arm64/debian runners --- .github/workflows/build_raspbian.yml | 24 +++++++++++++++++++----- .github/workflows/main_matrix.yml | 10 ++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml index 1860e9098..78122cb35 100644 --- a/.github/workflows/build_raspbian.yml +++ b/.github/workflows/build_raspbian.yml @@ -10,10 +10,24 @@ jobs: build-raspbian: runs-on: [self-hosted, linux, ARM64] steps: - - uses: actions/checkout@v3 - - name: Build base - id: base - uses: ./.github/actions/setup-base + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: recursive + ref: ${{github.event.pull_request.head.ref}} + repository: ${{github.event.pull_request.head.repo.full_name}} + + - name: Upgrade python tools + shell: bash + run: | + python -m pip install --upgrade pip + pip install -U platformio adafruit-nrfutil + pip install -U meshtastic --pre + + - name: Upgrade platformio + shell: bash + run: | + pio upgrade - name: Build Raspbian run: bin/build-native.sh @@ -25,6 +39,6 @@ jobs: - name: Store binaries as an artifact uses: actions/upload-artifact@v3 with: - name: firmware-native-${{ steps.version.outputs.version }}.zip + name: firmware-raspbian-${{ steps.version.outputs.version }}.zip path: | release/meshtasticd_linux_arm64 diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index bd024b0af..259306f0c 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -103,7 +103,6 @@ jobs: build-nrf52: strategy: fail-fast: false - max-parallel: 2 matrix: include: - board: rak4631 @@ -210,7 +209,14 @@ jobs: gather-artifacts: runs-on: ubuntu-latest needs: - [build-esp32, build-esp32-s3, build-nrf52, build-native, build-rpi2040] + [ + build-esp32, + build-esp32-s3, + build-nrf52, + build-raspbian, + build-native, + build-rpi2040, + ] steps: - name: Checkout code uses: actions/checkout@v3 From 7bd2b0702404dcb5194f933fe2873035c6747890 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 11:26:07 -0600 Subject: [PATCH 05/33] Disable radiolib debug --- variants/portduino/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index be07bcb15..5e9428d4e 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -16,7 +16,7 @@ build_src_filter = ${portduino_base.build_src_filter} ; The Raspberry Pi actually has accessible SPI and GPIO, so we can support real hardware there. [env:raspbian] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -DRADIOLIB_DEBUG -lpigpio -lyaml-cpp +build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -lpigpio -lyaml-cpp board = linux_arm lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} \ No newline at end of file From f8e766ebc7b5224569b81e509193580e76c8f2c1 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 11:41:33 -0600 Subject: [PATCH 06/33] Include Raspbian in release zip --- .github/workflows/build_raspbian.yml | 1 + .github/workflows/main_matrix.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_raspbian.yml b/.github/workflows/build_raspbian.yml index 78122cb35..103f43a71 100644 --- a/.github/workflows/build_raspbian.yml +++ b/.github/workflows/build_raspbian.yml @@ -42,3 +42,4 @@ jobs: name: firmware-raspbian-${{ steps.version.outputs.version }}.zip path: | release/meshtasticd_linux_arm64 + bin/config-dist.yaml diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 259306f0c..77459330a 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -233,7 +233,7 @@ jobs: id: version - name: Move files up - run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat + run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./*raspbian*/meshtasticd_linux_arm64 ./*raspbian*/config-dist.yaml - name: Repackage in single firmware zip uses: actions/upload-artifact@v3 From 297267d03769c83b1d6701114f25c30852d1b759 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 13:26:05 -0600 Subject: [PATCH 07/33] Try harder to find Raspbian binary --- .github/workflows/main_matrix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 77459330a..960ff3bdd 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -233,7 +233,7 @@ jobs: id: version - name: Move files up - run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./*raspbian*/meshtasticd_linux_arm64 ./*raspbian*/config-dist.yaml + run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./**/meshtasticd_linux_arm64 ./**/config-dist.yaml - name: Repackage in single firmware zip uses: actions/upload-artifact@v3 From 7ef4abb9749b4097481e134ce82ad30f228e091e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 14:56:40 -0600 Subject: [PATCH 08/33] Add debugging output to main workflow --- .github/workflows/main_matrix.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 960ff3bdd..ccd198589 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -306,6 +306,9 @@ jobs: name: firmware-${{ steps.version.outputs.version }} path: ./output + - name: Display structure of downloaded files + run: ls -R + - name: Device scripts permissions run: | chmod +x ./output/device-install.sh From 16ef40b21f3c976b5c138859dad7f1a971f3c968 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 15:16:36 -0600 Subject: [PATCH 09/33] Add even moar workflow debugging --- .github/workflows/main_matrix.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index ccd198589..f1f5222ab 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -228,6 +228,9 @@ jobs: with: path: ./ + - name: Display structure of downloaded files + run: ls -R + - name: Get release version string run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT id: version From 08297bb0b72eb5986cfb6129cfefea67274b8123 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 18 Nov 2023 15:36:41 -0600 Subject: [PATCH 10/33] Copy and Paste output file location for workflow --- .github/workflows/main_matrix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index f1f5222ab..960f0d51f 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -236,7 +236,7 @@ jobs: id: version - name: Move files up - run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./**/meshtasticd_linux_arm64 ./**/config-dist.yaml + run: mv -b -t ./ ./*tbeam-2*/littlefs*.bin ./*tbeam-2*/bleota.bin ./*tbeam-s3*/bleota-s3.bin ./**/firmware*.bin ./*t-echo*/Meshtastic_nRF52_factory_erase.uf2 ./**/firmware-*.uf2 ./**/firmware-*-ota.zip ./**/*.elf ./*native*/*device-*.sh ./*native*/*device-*.bat ./firmware-raspbian-*/release/meshtasticd_linux_arm64 ./firmware-raspbian-*/bin/config-dist.yaml - name: Repackage in single firmware zip uses: actions/upload-artifact@v3 From 4af90eeb3934f505f466e865b9eadbc9ab857c78 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 14:00:03 -0600 Subject: [PATCH 11/33] Revamp yaml config for Raspbian --- bin/config-dist.yaml | 43 +++++++++++------------- src/main.cpp | 8 ++--- src/mesh/SX126xInterface.cpp | 2 +- src/platform/portduino/PortduinoGlue.cpp | 26 ++++++++------ src/platform/portduino/PortduinoGlue.h | 14 +------- 5 files changed, 40 insertions(+), 53 deletions(-) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 2a3abac6f..3924335a2 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -1,26 +1,21 @@ -# Define your devices here. -# Use Broadcom pin numbering +# Define your devices here using Broadcom pin numbering +# Uncomment the block that corresponds to your hardware +--- +Lora: +# Module: sx1262 # Waveshare SX126X XXXM +# DIO2_AS_RF_SWITCH: true +# CS: 21 +# IRQ: 16 +# Busy: 20 +# Reset: 18 -#Waveshare SX126X XXXM +# Module: sx1262 # Waveshare SX1302 LISTEN ONLY AT THIS TIME! +# CS: 7 +# IRQ: 17 +# Reset: 22 -#USE_SX1262: true -#SX126X_DIO2_AS_RF_SWITCH: true -#SX126X_CS: 21 -#SX126X_DIO1: 16 -#SX126X_BUSY: 20 -#SX126X_RESET: 18 - -#Waveshare SX1302 LISTEN ONLY AT THIS TIME! - -#USE_SX1262: true -#SX126X_CS: 7 -#SX126X_DIO1: 17 -#SX126X_RESET: 22 - -#Adafruit RFM9x - -#USE_RF95: true -#RF95_RESET: 25 -#RF95_NSS: 7 -#RF95_IRQ: 22 -#RF95_DIO1: 23 +# Module: RF95 # Adafruit RFM9x +# Reset: 25 +# CS: 7 +# IRQ: 22 +# Busy: 23 diff --git a/src/main.cpp b/src/main.cpp index 5c3151fc0..cfd6279e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -694,8 +694,8 @@ void setup() if (settingsMap[use_sx1262]) { if (!rIf) { PiHal *RadioLibHAL = new PiHal(1); - rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[sx126x_cs], settingsMap[sx126x_dio1], - settingsMap[sx126x_reset], settingsMap[sx126x_busy]); + rIf = new SX1262Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], + settingsMap[busy]); if (!rIf->init()) { LOG_ERROR("Failed to find SX1262 radio\n"); delete rIf; @@ -707,8 +707,8 @@ void setup() } else if (settingsMap[use_rf95]) { if (!rIf) { PiHal *RadioLibHAL = new PiHal(1); - rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[rf95_nss], settingsMap[rf95_irq], - settingsMap[rf95_reset], settingsMap[rf95_dio1]); + rIf = new RF95Interface((LockingArduinoHal *)RadioLibHAL, settingsMap[cs], settingsMap[irq], settingsMap[reset], + settingsMap[busy]); if (!rIf->init()) { LOG_ERROR("Failed to find RF95 radio\n"); delete rIf; diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index ba3f2bc2a..5083eeb53 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -79,7 +79,7 @@ template bool SX126xInterface::init() bool dio2AsRfSwitch = true; #elif defined(ARCH_RASPBERRY_PI) bool dio2AsRfSwitch = false; - if (settingsMap[sx126x_dio2_as_rf_switch]) { + if (settingsMap[dio2_as_rf_switch]) { LOG_DEBUG("Setting DIO2 as RF switch\n"); dio2AsRfSwitch = true; } diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index b3c2dc5f2..2e402c0a0 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -123,17 +123,21 @@ void portduinoSetup() } try { - settingsMap[use_sx1262] = yamlConfig["USE_SX1262"].as(false); - settingsMap[sx126x_dio2_as_rf_switch] = yamlConfig["SX126X_DIO2_AS_RF_SWITCH"].as(false); - settingsMap[sx126x_cs] = yamlConfig["SX126X_CS"].as(RADIOLIB_NC); - settingsMap[sx126x_dio1] = yamlConfig["SX126X_DIO1"].as(RADIOLIB_NC); - settingsMap[sx126x_busy] = yamlConfig["SX126X_BUSY"].as(RADIOLIB_NC); - settingsMap[sx126x_reset] = yamlConfig["SX126X_RESET"].as(RADIOLIB_NC); - settingsMap[use_rf95] = yamlConfig["USE_RF95"].as(false); - settingsMap[rf95_nss] = yamlConfig["RF95_NSS"].as(RADIOLIB_NC); - settingsMap[rf95_irq] = yamlConfig["RF95_IRQ"].as(RADIOLIB_NC); - settingsMap[rf95_reset] = yamlConfig["RF95_RESET"].as(RADIOLIB_NC); - settingsMap[rf95_dio1] = yamlConfig["RF95_DIO1"].as(RADIOLIB_NC); + if (yamlConfig["Lora"]) { + settingsMap[use_sx1262] = false; + settingsMap[use_rf95] = false; + + if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "sx1262") { + settingsMap[use_sx1262] = true; + } else if (yamlConfig["Lora"]["Module"] && yamlConfig["Lora"]["Module"].as("") == "RF95") { + settingsMap[use_rf95] = true; + } + settingsMap[dio2_as_rf_switch] = yamlConfig["Lora"]["DIO2_AS_RF_SWITCH"].as(false); + settingsMap[cs] = yamlConfig["Lora"]["CS"].as(RADIOLIB_NC); + settingsMap[irq] = yamlConfig["Lora"]["IRQ"].as(RADIOLIB_NC); + settingsMap[busy] = yamlConfig["Lora"]["Busy"].as(RADIOLIB_NC); + settingsMap[reset] = yamlConfig["Lora"]["Reset"].as(RADIOLIB_NC); + } } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index 91fc4c2b1..7dc563038 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -4,18 +4,6 @@ extern std::map settingsMap; -enum { - use_sx1262, - sx126x_cs, - sx126x_dio1, - sx126x_busy, - sx126x_reset, - sx126x_dio2_as_rf_switch, - use_rf95, - rf95_nss, - rf95_irq, - rf95_reset, - rf95_dio1 -}; +enum { use_sx1262, cs, irq, busy, reset, dio2_as_rf_switch, use_rf95 }; #endif \ No newline at end of file From 5ad12fed60e6d3938a23eccc8c65c76610745d1e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 14:05:47 -0600 Subject: [PATCH 12/33] Chill out, yamllint --- .trunk/configs/.yamllint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml index 4d444662d..790846156 100644 --- a/.trunk/configs/.yamllint.yaml +++ b/.trunk/configs/.yamllint.yaml @@ -3,7 +3,7 @@ rules: required: only-when-needed extra-allowed: ["{|}"] empty-values: - forbid-in-block-mappings: true + forbid-in-block-mappings: false forbid-in-flow-mappings: true key-duplicates: {} octal-values: From d33521ee86109f2930aaa642e9ddcbac158938ae Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 14:30:34 -0600 Subject: [PATCH 13/33] Add package-raspbian workflow --- .github/workflows/package_raspbian.yml | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/package_raspbian.yml diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml new file mode 100644 index 000000000..64b0dade2 --- /dev/null +++ b/.github/workflows/package_raspbian.yml @@ -0,0 +1,34 @@ +name: Package Raspbian + +on: workflow_dispatch + +permissions: + contents: write + packages: write + +jobs: + build-raspbian: + uses: ./.github/workflows/build_raspbian.yml + + package-raspbian: + runs-on: [self-hosted, linux, ARM64] + steps: + - name: build .debpkg + run: | + mkdir -p .debpkg/usr/sbin + mkdir -p .debpkg/etc/meshtasticd + mkdir -p .debpkg/usr/lib/systemd/system/ + cp release/meshtasticd_linux_arm64 /usr/sbin/meshtasticd + cp bin/config-dist.yaml /etc/meshtasticd/config.yaml + chmod +x .debpkg/usr/sbin/meshtasticd + cp bin/meshtasticd.service /usr/lib/systemd/system/meshtasticd.service + + - uses: jiro4989/build-deb-action@v3 + with: + package: meshtasticd + package_root: .debpkg + maintainer: Jonathan Bennett + version: ${{ github.ref }} # refs/tags/v*.*.* + arch: arm64 + depends: libyaml-cpp0.7 + desc: Native Linux Meshtastic binary. From 31d7c6826dd59ea781962004b787dbf50cd68fcd Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 15:03:46 -0600 Subject: [PATCH 14/33] Update package_raspbian.yml Properly run build_raspbian as a step --- .github/workflows/package_raspbian.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 64b0dade2..7906f9659 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -7,12 +7,11 @@ permissions: packages: write jobs: - build-raspbian: - uses: ./.github/workflows/build_raspbian.yml - package-raspbian: runs-on: [self-hosted, linux, ARM64] steps: + - uses: ./.github/workflows/build_raspbian.yml + - name: build .debpkg run: | mkdir -p .debpkg/usr/sbin From dad824c0e9529b3850a664bed666ad7c9ce7f693 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 15:16:11 -0600 Subject: [PATCH 15/33] Update package_raspbian.yml -- add checkout step --- .github/workflows/package_raspbian.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 7906f9659..2b0327228 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -10,6 +10,8 @@ jobs: package-raspbian: runs-on: [self-hosted, linux, ARM64] steps: + - uses: actions/checkout@v2 + - uses: ./.github/workflows/build_raspbian.yml - name: build .debpkg From 8e92754b59162bd3ed13f118946226b0cdb75b59 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 15:48:43 -0600 Subject: [PATCH 16/33] Update package_raspbian.yml --- .github/workflows/package_raspbian.yml | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 2b0327228..4b56e4557 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -7,29 +7,43 @@ permissions: packages: write jobs: + build-raspbian: + uses: ./.github/workflows/build_raspbian.yml + package-raspbian: runs-on: [self-hosted, linux, ARM64] + needs: build-raspbian steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: ./.github/workflows/build_raspbian.yml + - name: Get release version string + run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT + id: version + + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: firmware-raspbian-${{ steps.version.outputs.version }}.zip + + - name: Display structure of downloaded files + run: ls -R - name: build .debpkg run: | mkdir -p .debpkg/usr/sbin mkdir -p .debpkg/etc/meshtasticd mkdir -p .debpkg/usr/lib/systemd/system/ - cp release/meshtasticd_linux_arm64 /usr/sbin/meshtasticd - cp bin/config-dist.yaml /etc/meshtasticd/config.yaml + cp release/meshtasticd_linux_arm64 .debpkg/usr/sbin/meshtasticd + cp bin/config-dist.yaml .debpkg/etc/meshtasticd/config.yaml chmod +x .debpkg/usr/sbin/meshtasticd - cp bin/meshtasticd.service /usr/lib/systemd/system/meshtasticd.service + cp bin/meshtasticd.service .debpkg/usr/lib/systemd/system/meshtasticd.service - uses: jiro4989/build-deb-action@v3 with: package: meshtasticd package_root: .debpkg maintainer: Jonathan Bennett - version: ${{ github.ref }} # refs/tags/v*.*.* + version: ${{ steps.version.outputs.version }} # refs/tags/v*.*.* arch: arm64 depends: libyaml-cpp0.7 desc: Native Linux Meshtastic binary. From d04ff29c2a759916aecd27a07999367e4a1e9bc6 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 15:56:41 -0600 Subject: [PATCH 17/33] Update package_raspbian.yml use ubuntu-latest --- .github/workflows/package_raspbian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 4b56e4557..f5fbfe30f 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -11,7 +11,7 @@ jobs: uses: ./.github/workflows/build_raspbian.yml package-raspbian: - runs-on: [self-hosted, linux, ARM64] + runs-on: ubuntu-latest needs: build-raspbian steps: - uses: actions/checkout@v3 From 8f0ce606db10def8f56ab691acefed1694785682 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 16:07:08 -0600 Subject: [PATCH 18/33] Update package_raspbian.yml upload .deb as artifact --- .github/workflows/package_raspbian.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index f5fbfe30f..b30c7f45c 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -47,3 +47,9 @@ jobs: arch: arm64 depends: libyaml-cpp0.7 desc: Native Linux Meshtastic binary. + + - uses: actions/upload-artifact@v3 + with: + name: artifact-deb + path: | + ./*.deb From cfb09ee1154fd0f476425b60f77b996ab619bddd Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 16:41:47 -0600 Subject: [PATCH 19/33] add .deb to release --- .github/workflows/main_matrix.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 960f0d51f..8c7ba5919 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -134,6 +134,9 @@ jobs: max-parallel: 1 uses: ./.github/workflows/build_raspbian.yml + package-raspbian: + uses: ./.github/workflows/package_raspbian.yml + build-native: runs-on: ubuntu-latest steps: @@ -216,6 +219,7 @@ jobs: build-raspbian, build-native, build-rpi2040, + package-raspbian, ] steps: - name: Checkout code @@ -308,6 +312,10 @@ jobs: with: name: firmware-${{ steps.version.outputs.version }} path: ./output + + - uses: actions/download-artifact@v3 + with: + name: artifact-deb - name: Display structure of downloaded files run: ls -R @@ -365,6 +373,16 @@ jobs: asset_name: debug-elfs-${{ steps.version.outputs.version }}.zip asset_content_type: application/zip + - name: Add raspbian .deb + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./meshtasticd_${{ steps.version.outputs.version }}_arm64.deb + asset_name: meshtasticd_${{ steps.version.outputs.version }}_arm64.deb + asset_content_type: application/vnd.debian.binary-package + - name: Bump version.properties run: >- bin/bump_version.py From a9d846c1b35cfe993804905671e1a439c29229d5 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 16:45:06 -0600 Subject: [PATCH 20/33] make package_raspbian.yml a reusable workflow --- .github/workflows/package_raspbian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index b30c7f45c..a43a5ce30 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -1,6 +1,6 @@ name: Package Raspbian -on: workflow_dispatch +on: workflow_call permissions: contents: write From 7380f3b170a731848c14e6eb7e8ce12fe4eef1b1 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 16:53:00 -0600 Subject: [PATCH 21/33] Trunk fmt fix whitespace --- .github/workflows/package_raspbian.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index a43a5ce30..028c05471 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -9,13 +9,13 @@ permissions: jobs: build-raspbian: uses: ./.github/workflows/build_raspbian.yml - + package-raspbian: runs-on: ubuntu-latest needs: build-raspbian steps: - uses: actions/checkout@v3 - + - name: Get release version string run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT id: version @@ -27,7 +27,7 @@ jobs: - name: Display structure of downloaded files run: ls -R - + - name: build .debpkg run: | mkdir -p .debpkg/usr/sbin From c1f5878648e9cf271eea91a634e7d5fff22d884e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 17:11:54 -0600 Subject: [PATCH 22/33] Add Raspbian to firmware zip --- .github/workflows/main_matrix.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 8c7ba5919..6b6ff1ad7 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -252,6 +252,8 @@ jobs: ./firmware-*-ota.zip ./device-*.sh ./device-*.bat + ./meshtasticd_linux_arm64 + ./config-dist.yaml retention-days: 90 - uses: actions/download-artifact@v3 @@ -312,7 +314,7 @@ jobs: with: name: firmware-${{ steps.version.outputs.version }} path: ./output - + - uses: actions/download-artifact@v3 with: name: artifact-deb From 195706e0e599ef71be0527a93cc8fcaebc544b8b Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 20:19:43 -0600 Subject: [PATCH 23/33] Update package_raspbian.yml to pull correct code for PR runs --- .github/workflows/package_raspbian.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 028c05471..8bbfdd372 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -14,7 +14,12 @@ jobs: runs-on: ubuntu-latest needs: build-raspbian steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: "recursive" + ref: ${{github.event.pull_request.head.ref}} + repository: ${{github.event.pull_request.head.repo.full_name}} - name: Get release version string run: echo "version=$(./bin/buildinfo.py long)" >> $GITHUB_OUTPUT From 1b20a82b551d34c33036ab82874e259c453ec646 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 19 Nov 2023 20:28:37 -0600 Subject: [PATCH 24/33] Update package_raspbian.yml Trunk --- .github/workflows/package_raspbian.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 8bbfdd372..3c17c9da1 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -17,7 +17,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 with: - submodules: "recursive" + submodules: recursive ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} From 57542ce9e6f099ed67ccf36132b3cd3163898fb1 Mon Sep 17 00:00:00 2001 From: Ric In New Mexico <78682404+RicInNewMexico@users.noreply.github.com> Date: Mon, 20 Nov 2023 05:33:14 -0700 Subject: [PATCH 25/33] Retain device nodeinfo during reset-nodedb (#2951) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * INA3221 bugfixes & refinement Reorganized and refactored some INA3221 code Added comments Added missing shunt resistor value (100mΩ) Added INA3221 Channel 1 to getINAVoltage() for device battery monitoring modified: src/Power.cpp modified: src/modules/Telemetry/PowerTelemetry.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.h modified: src/power.h * reset-nodedb retain device nodeinfo modified: src/mesh/NodeDB.cpp * reset-nodedb #2 modified: src/mesh/NodeDB.cpp --------- Co-authored-by: Jonathan Bennett --- src/mesh/NodeDB.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index d7fa9e5ac..11106585f 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -316,8 +316,8 @@ void NodeDB::installDefaultChannels() void NodeDB::resetNodes() { - devicestate.node_db_lite_count = 0; - memset(devicestate.node_db_lite, 0, sizeof(devicestate.node_db_lite)); + devicestate.node_db_lite_count = 1; + std::fill(&devicestate.node_db_lite[1], &devicestate.node_db_lite[MAX_NUM_NODES - 1], meshtastic_NodeInfoLite()); saveDeviceStateToDisk(); if (neighborInfoModule && moduleConfig.neighbor_info.enabled) neighborInfoModule->resetNeighbors(); From 4712b1ca65f49ead0954bea9648fe919e13fb9a1 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 22 Nov 2023 07:17:48 -0600 Subject: [PATCH 26/33] Add manual run option to package_raspbian.yml (#2954) --- .github/workflows/package_raspbian.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/package_raspbian.yml b/.github/workflows/package_raspbian.yml index 3c17c9da1..61f82e9d7 100644 --- a/.github/workflows/package_raspbian.yml +++ b/.github/workflows/package_raspbian.yml @@ -1,6 +1,8 @@ name: Package Raspbian -on: workflow_call +on: + workflow_call: + workflow_dispatch: permissions: contents: write From cbb8eb65baefb07425d6eb90ec50d6ab4afc8136 Mon Sep 17 00:00:00 2001 From: HookdomPonix <83303405+HookdomPonix@users.noreply.github.com> Date: Wed, 22 Nov 2023 09:30:55 -0700 Subject: [PATCH 27/33] Add USB detection to RAK4631 based boards. (#2956) * Add support for the rak10701 board, no touch * Moved tftblack fillin and changed teh src flags * Added rak10701 to platformio.ini * Add USB detection to RAK4631 units. * Eliminate spurious symbol in comment field. --------- Co-authored-by: Ben Meadors --- src/Power.cpp | 26 +++++++++++++++++++++--- variants/rak10701/variant.h | 3 +++ variants/rak4631/variant.h | 3 +++ variants/rak4631_epaper/variant.h | 5 ++++- variants/rak4631_epaper_onrxtx/variant.h | 5 ++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index c7392c90b..0a56a1ba2 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -19,6 +19,11 @@ #include "meshUtils.h" #include "sleep.h" +// Working USB detection for powered/charging states on the RAK platform +#ifdef NRF_APM +#include "nrfx_power.h" +#endif + #ifdef DEBUG_HEAP_MQTT #include "mqtt/MQTT.h" #include "target_specific.h" @@ -460,10 +465,25 @@ void Power::readPowerStatus() } } + OptionalBool NRF_USB = OptFalse; + +#ifdef NRF_APM // Section of code detects USB power on the RAK4631 and updates the power states. Takes 20 seconds or so to detect + // changes. + + nrfx_power_usb_state_t nrf_usb_state = nrfx_power_usbstatus_get(); + + if (nrf_usb_state == NRFX_POWER_USB_STATE_DISCONNECTED) { + powerFSM.trigger(EVENT_POWER_DISCONNECTED); + NRF_USB = OptFalse; + } else { + powerFSM.trigger(EVENT_POWER_CONNECTED); + NRF_USB = OptTrue; + } +#endif // Notify any status instances that are observing us - const PowerStatus powerStatus2 = - PowerStatus(hasBattery ? OptTrue : OptFalse, batteryLevel->isVbusIn() ? OptTrue : OptFalse, - batteryLevel->isCharging() ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent); + const PowerStatus powerStatus2 = PowerStatus( + hasBattery ? OptTrue : OptFalse, batteryLevel->isVbusIn() || NRF_USB == OptTrue ? OptTrue : OptFalse, + batteryLevel->isCharging() || NRF_USB == OptTrue ? OptTrue : OptFalse, batteryVoltageMv, batteryChargePercent); LOG_DEBUG("Battery: usbPower=%d, isCharging=%d, batMv=%d, batPct=%d\n", powerStatus2.getHasUSB(), powerStatus2.getIsCharging(), powerStatus2.getBatteryVoltageMv(), powerStatus2.getBatteryChargePercent()); newStatus.notifyObservers(&powerStatus2); diff --git a/variants/rak10701/variant.h b/variants/rak10701/variant.h index 3b771d62b..5ff12a7de 100644 --- a/variants/rak10701/variant.h +++ b/variants/rak10701/variant.h @@ -234,6 +234,9 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 +// Testing USB detection +#define NRF_APM + // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index 89bb62c73..956bcd772 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -215,6 +215,9 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 +// Testing USB detection +#define NRF_APM + // enables 3.3V periphery like GPS or IO Module #define PIN_3V3_EN (34) diff --git a/variants/rak4631_epaper/variant.h b/variants/rak4631_epaper/variant.h index 0253ec14d..bc2eddfee 100644 --- a/variants/rak4631_epaper/variant.h +++ b/variants/rak4631_epaper/variant.h @@ -209,6 +209,9 @@ static const uint8_t SCK = PIN_SPI_SCK; // RAK12002 RTC Module #define RV3028_RTC (uint8_t)0b1010010 +// Testing USB detection +#define NRF_APM + // Battery // The battery sense is hooked to pin A0 (5) #define BATTERY_PIN PIN_A0 @@ -241,4 +244,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif +#endif \ No newline at end of file diff --git a/variants/rak4631_epaper_onrxtx/variant.h b/variants/rak4631_epaper_onrxtx/variant.h index 6fc6da373..411e3eb17 100644 --- a/variants/rak4631_epaper_onrxtx/variant.h +++ b/variants/rak4631_epaper_onrxtx/variant.h @@ -84,6 +84,9 @@ static const uint8_t AREF = PIN_AREF; #define PIN_SERIAL2_RX (-1) #define PIN_SERIAL2_TX (-1) +// Testing USB detection +#define NRF_APM + /* * SPI Interfaces */ @@ -212,4 +215,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif +#endif \ No newline at end of file From b3852322efc5e413d0301349f829cf280e585a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 24 Nov 2023 14:40:20 +0100 Subject: [PATCH 28/33] Add config example for Elecrow Hat NFC --- bin/config-dist.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 3924335a2..6c8f1946f 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -19,3 +19,8 @@ Lora: # CS: 7 # IRQ: 22 # Busy: 23 + +# Module: RF95 # Elecrow Lora RFM95 IOT https://www.elecrow.com/lora-rfm95-iot-board-for-rpi.html +# Reset: 22 +# CS: 7 +# IRQ: 25 From d6fc1c314f8a31cc925ebab0dce01a6d5d715796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Tue, 14 Nov 2023 15:33:54 +0100 Subject: [PATCH 29/33] WIP: Add battery level for Nimble --- src/nimble/NimbleBluetooth.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/nimble/NimbleBluetooth.cpp b/src/nimble/NimbleBluetooth.cpp index 1f06b25f2..3175e0f09 100644 --- a/src/nimble/NimbleBluetooth.cpp +++ b/src/nimble/NimbleBluetooth.cpp @@ -9,6 +9,7 @@ #include NimBLECharacteristic *fromNumCharacteristic; +NimBLECharacteristic *BatteryCharacteristic; NimBLEServer *bleServer; static bool passkeyShowing; @@ -181,6 +182,18 @@ void NimbleBluetooth::setupService() FromRadioCharacteristic->setCallbacks(fromRadioCallbacks); bleService->start(); + + // Setup the battery service + NimBLEService *batteryService = bleServer->createService(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service + BatteryCharacteristic = batteryService->createCharacteristic( // 0x2A19 is the Battery Level characteristic) + (uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); + + NimBLE2904 *batteryLevelDescriptor = (NimBLE2904 *)BatteryCharacteristic->createDescriptor((uint16_t)0x2904); + batteryLevelDescriptor->setFormat(NimBLE2904::FORMAT_UINT8); + batteryLevelDescriptor->setNamespace(1); + batteryLevelDescriptor->setUnit(0x27ad); + + batteryService->start(); } void NimbleBluetooth::startAdvertising() @@ -188,13 +201,15 @@ void NimbleBluetooth::startAdvertising() NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising(); pAdvertising->reset(); pAdvertising->addServiceUUID(MESH_SERVICE_UUID); + pAdvertising->addServiceUUID(NimBLEUUID((uint16_t)0x180f)); // 0x180F is the Battery Service pAdvertising->start(0); } /// Given a level between 0-100, update the BLE attribute void updateBatteryLevel(uint8_t level) { - // blebas.write(level); + BatteryCharacteristic->setValue(&level, 1); + BatteryCharacteristic->notify(); } void NimbleBluetooth::clearBonds() From 1feb74f52570186f4d8d0fe7c86872eac5e9ff29 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 25 Nov 2023 19:34:30 -0600 Subject: [PATCH 30/33] Add number of sats to default position flags (#2962) --- src/mesh/NodeDB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 11106585f..2e6c8131e 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -200,7 +200,7 @@ void NodeDB::installDefaultConfig() config.position.position_flags = (meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE | meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE_MSL | meshtastic_Config_PositionConfig_PositionFlags_SPEED | meshtastic_Config_PositionConfig_PositionFlags_HEADING | - meshtastic_Config_PositionConfig_PositionFlags_DOP); + meshtastic_Config_PositionConfig_PositionFlags_DOP | meshtastic_Config_PositionConfig_PositionFlags_SATINVIEW); #ifdef T_WATCH_S3 config.display.screen_on_secs = 30; From ac318a9850d6c4828f1a8517eb54cd655f713294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 23 Nov 2023 10:10:16 +0100 Subject: [PATCH 31/33] Swapped out crypto engine for one that also works with AES-256 --- arch/rp2040/rp2040.ini | 2 +- src/platform/rp2040/rp2040CryptoEngine.cpp | 46 ++++++++++++++++++---- variants/rak11310/variant.h | 7 ---- variants/rpipico/variant.h | 7 ---- variants/rpipicow/variant.h | 7 ---- 5 files changed, 39 insertions(+), 30 deletions(-) diff --git a/arch/rp2040/rp2040.ini b/arch/rp2040/rp2040.ini index b6ac4f171..495b52a86 100644 --- a/arch/rp2040/rp2040.ini +++ b/arch/rp2040/rp2040.ini @@ -21,4 +21,4 @@ lib_deps = ${arduino_base.lib_deps} ${environmental_base.lib_deps} jgromes/RadioLib@^6.1.0 - https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b \ No newline at end of file + rweather/Crypto \ No newline at end of file diff --git a/src/platform/rp2040/rp2040CryptoEngine.cpp b/src/platform/rp2040/rp2040CryptoEngine.cpp index c90126cc7..5486e51e5 100644 --- a/src/platform/rp2040/rp2040CryptoEngine.cpp +++ b/src/platform/rp2040/rp2040CryptoEngine.cpp @@ -1,33 +1,63 @@ +#include "AES.h" +#include "CTR.h" #include "CryptoEngine.h" -#include "aes.hpp" #include "configuration.h" class RP2040CryptoEngine : public CryptoEngine { + + CTRCommon *ctr = NULL; + public: RP2040CryptoEngine() {} ~RP2040CryptoEngine() {} + virtual void setKey(const CryptoKey &k) override + { + CryptoEngine::setKey(k); + LOG_DEBUG("Installing AES%d key!\n", key.length * 8); + if (ctr) { + delete ctr; + ctr = NULL; + } + if (key.length != 0) { + if (key.length == 16) + ctr = new CTR(); + else + ctr = new CTR(); + + ctr->setKey(key.bytes, key.length); + } + } /** * Encrypt a packet * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { - AES_ctx ctx; - initNonce(fromNode, packetNum); - AES_init_ctx_iv(&ctx, key.bytes, nonce); - AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); + initNonce(fromNode, packetId); + if (numBytes <= MAX_BLOCKSIZE) { + static uint8_t scratch[MAX_BLOCKSIZE]; + memcpy(scratch, bytes, numBytes); + memset(scratch + numBytes, 0, + sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it) + + ctr->setIV(nonce, sizeof(nonce)); + ctr->setCounterSize(4); + ctr->encrypt(bytes, scratch, numBytes); + } else { + LOG_ERROR("Packet too large for crypto engine: %d. noop encryption!\n", numBytes); + } } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same - encrypt(fromNode, packetNum, numBytes, bytes); + encrypt(fromNode, packetId, numBytes, bytes); } private: diff --git a/variants/rak11310/variant.h b/variants/rak11310/variant.h index 1ea6d141d..acc21ce99 100644 --- a/variants/rak11310/variant.h +++ b/variants/rak11310/variant.h @@ -4,13 +4,6 @@ #define ARDUINO_ARCH_AVR -#undef CBC -#define CBC 0 -#undef CTR -#define CTR 1 -#undef ECB -#define ECB 0 - #define LED_CONN PIN_LED2 #define LED_PIN LED_BUILTIN diff --git a/variants/rpipico/variant.h b/variants/rpipico/variant.h index 5c92dec59..be26099de 100644 --- a/variants/rpipico/variant.h +++ b/variants/rpipico/variant.h @@ -4,13 +4,6 @@ #define ARDUINO_ARCH_AVR -#undef CBC -#define CBC 0 -#undef CTR -#define CTR 1 -#undef ECB -#define ECB 0 - #define USE_SH1106 1 // default I2C pins: diff --git a/variants/rpipicow/variant.h b/variants/rpipicow/variant.h index 6de2f7bd4..77cb1ffd6 100644 --- a/variants/rpipicow/variant.h +++ b/variants/rpipicow/variant.h @@ -4,13 +4,6 @@ #define ARDUINO_ARCH_AVR -#undef CBC -#define CBC 0 -#undef CTR -#define CTR 1 -#undef ECB -#define ECB 0 - #define USE_SH1106 1 // default I2C pins: From 603e564db37db26861933a3f046ddbd5ee8518e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 23 Nov 2023 12:44:40 +0100 Subject: [PATCH 32/33] same change for STM32WL - also update trunk --- .trunk/trunk.yaml | 20 ++++----- arch/stm32/stm32wl5e.ini | 2 +- src/platform/stm32wl/STM32WLCryptoEngine.cpp | 46 ++++++++++++++++---- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index e31b026f4..66a16a152 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,25 +1,25 @@ version: 0.1 cli: - version: 1.17.1 + version: 1.17.2 plugins: sources: - id: trunk - ref: v1.2.6 + ref: v1.3.0 uri: https://github.com/trunk-io/plugins lint: enabled: - bandit@1.7.5 - - checkov@3.0.16 + - checkov@3.1.9 - terrascan@1.18.3 - - trivy@0.46.1 - - trufflehog@3.62.1 + - trivy@0.47.0 + - trufflehog@3.63.2-rc0 - taplo@0.8.1 - - ruff@0.1.3 - - yamllint@1.32.0 + - ruff@0.1.6 + - yamllint@1.33.0 - isort@5.12.0 - markdownlint@0.37.0 - oxipng@9.0.0 - - svgo@3.0.2 + - svgo@3.0.4 - actionlint@1.6.26 - flake8@6.1.0 - hadolint@2.12.0 @@ -27,9 +27,9 @@ lint: - shellcheck@0.9.0 - black@23.9.1 - git-diff-check - - gitleaks@8.18.0 + - gitleaks@8.18.1 - clang-format@16.0.3 - - prettier@3.0.3 + - prettier@3.1.0 runtimes: enabled: - python@3.10.8 diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index 524edd6b9..262da12a6 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -21,7 +21,7 @@ upload_protocol = stlink lib_deps = ${env.lib_deps} jgromes/RadioLib@^6.1.0 - https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b + rweather/Crypto https://github.com/littlefs-project/littlefs.git#v2.5.1 https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1 diff --git a/src/platform/stm32wl/STM32WLCryptoEngine.cpp b/src/platform/stm32wl/STM32WLCryptoEngine.cpp index 7367a2bc0..6187cf302 100644 --- a/src/platform/stm32wl/STM32WLCryptoEngine.cpp +++ b/src/platform/stm32wl/STM32WLCryptoEngine.cpp @@ -1,33 +1,63 @@ +#include "AES.h" +#include "CTR.h" #include "CryptoEngine.h" -#include "aes.hpp" #include "configuration.h" class STM32WLCryptoEngine : public CryptoEngine { + + CTRCommon *ctr = NULL; + public: STM32WLCryptoEngine() {} ~STM32WLCryptoEngine() {} + virtual void setKey(const CryptoKey &k) override + { + CryptoEngine::setKey(k); + LOG_DEBUG("Installing AES%d key!\n", key.length * 8); + if (ctr) { + delete ctr; + ctr = NULL; + } + if (key.length != 0) { + if (key.length == 16) + ctr = new CTR(); + else + ctr = new CTR(); + + ctr->setKey(key.bytes, key.length); + } + } /** * Encrypt a packet * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { - AES_ctx ctx; - initNonce(fromNode, packetNum); - AES_init_ctx_iv(&ctx, key.bytes, nonce); - AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); + initNonce(fromNode, packetId); + if (numBytes <= MAX_BLOCKSIZE) { + static uint8_t scratch[MAX_BLOCKSIZE]; + memcpy(scratch, bytes, numBytes); + memset(scratch + numBytes, 0, + sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it) + + ctr->setIV(nonce, sizeof(nonce)); + ctr->setCounterSize(4); + ctr->encrypt(bytes, scratch, numBytes); + } else { + LOG_ERROR("Packet too large for crypto engine: %d. noop encryption!\n", numBytes); + } } } - virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same - encrypt(fromNode, packetNum, numBytes, bytes); + encrypt(fromNode, packetId, numBytes, bytes); } private: From c7e3485dd77eff6632c7c9e053d73b9269c42422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 23 Nov 2023 13:47:07 +0100 Subject: [PATCH 33/33] Revert "same change for STM32WL - also update trunk" This reverts commit f9fdb0f98d5e095b5537e9b740231368fc088210. --- .trunk/trunk.yaml | 20 ++++----- arch/stm32/stm32wl5e.ini | 2 +- src/platform/stm32wl/STM32WLCryptoEngine.cpp | 46 ++++---------------- 3 files changed, 19 insertions(+), 49 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 66a16a152..e31b026f4 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,25 +1,25 @@ version: 0.1 cli: - version: 1.17.2 + version: 1.17.1 plugins: sources: - id: trunk - ref: v1.3.0 + ref: v1.2.6 uri: https://github.com/trunk-io/plugins lint: enabled: - bandit@1.7.5 - - checkov@3.1.9 + - checkov@3.0.16 - terrascan@1.18.3 - - trivy@0.47.0 - - trufflehog@3.63.2-rc0 + - trivy@0.46.1 + - trufflehog@3.62.1 - taplo@0.8.1 - - ruff@0.1.6 - - yamllint@1.33.0 + - ruff@0.1.3 + - yamllint@1.32.0 - isort@5.12.0 - markdownlint@0.37.0 - oxipng@9.0.0 - - svgo@3.0.4 + - svgo@3.0.2 - actionlint@1.6.26 - flake8@6.1.0 - hadolint@2.12.0 @@ -27,9 +27,9 @@ lint: - shellcheck@0.9.0 - black@23.9.1 - git-diff-check - - gitleaks@8.18.1 + - gitleaks@8.18.0 - clang-format@16.0.3 - - prettier@3.1.0 + - prettier@3.0.3 runtimes: enabled: - python@3.10.8 diff --git a/arch/stm32/stm32wl5e.ini b/arch/stm32/stm32wl5e.ini index 262da12a6..524edd6b9 100644 --- a/arch/stm32/stm32wl5e.ini +++ b/arch/stm32/stm32wl5e.ini @@ -21,7 +21,7 @@ upload_protocol = stlink lib_deps = ${env.lib_deps} jgromes/RadioLib@^6.1.0 - rweather/Crypto + https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b https://github.com/littlefs-project/littlefs.git#v2.5.1 https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1 diff --git a/src/platform/stm32wl/STM32WLCryptoEngine.cpp b/src/platform/stm32wl/STM32WLCryptoEngine.cpp index 6187cf302..7367a2bc0 100644 --- a/src/platform/stm32wl/STM32WLCryptoEngine.cpp +++ b/src/platform/stm32wl/STM32WLCryptoEngine.cpp @@ -1,63 +1,33 @@ -#include "AES.h" -#include "CTR.h" #include "CryptoEngine.h" +#include "aes.hpp" #include "configuration.h" class STM32WLCryptoEngine : public CryptoEngine { - - CTRCommon *ctr = NULL; - public: STM32WLCryptoEngine() {} ~STM32WLCryptoEngine() {} - virtual void setKey(const CryptoKey &k) override - { - CryptoEngine::setKey(k); - LOG_DEBUG("Installing AES%d key!\n", key.length * 8); - if (ctr) { - delete ctr; - ctr = NULL; - } - if (key.length != 0) { - if (key.length == 16) - ctr = new CTR(); - else - ctr = new CTR(); - - ctr->setKey(key.bytes, key.length); - } - } /** * Encrypt a packet * * @param bytes is updated in place */ - virtual void encrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override + virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { if (key.length > 0) { - initNonce(fromNode, packetId); - if (numBytes <= MAX_BLOCKSIZE) { - static uint8_t scratch[MAX_BLOCKSIZE]; - memcpy(scratch, bytes, numBytes); - memset(scratch + numBytes, 0, - sizeof(scratch) - numBytes); // Fill rest of buffer with zero (in case cypher looks at it) - - ctr->setIV(nonce, sizeof(nonce)); - ctr->setCounterSize(4); - ctr->encrypt(bytes, scratch, numBytes); - } else { - LOG_ERROR("Packet too large for crypto engine: %d. noop encryption!\n", numBytes); - } + AES_ctx ctx; + initNonce(fromNode, packetNum); + AES_init_ctx_iv(&ctx, key.bytes, nonce); + AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes); } } - virtual void decrypt(uint32_t fromNode, uint64_t packetId, size_t numBytes, uint8_t *bytes) override + virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override { // For CTR, the implementation is the same - encrypt(fromNode, packetId, numBytes, bytes); + encrypt(fromNode, packetNum, numBytes, bytes); } private: