From 6cc464a7eba3accd7f828b2d207283e998eaf00f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 21 Dec 2020 13:02:33 +0100 Subject: [PATCH 01/17] Enable OTA for Portenta H7 target --- src/ArduinoIoTCloudTCP.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 4a68ac7ae..88755fa62 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -123,7 +123,12 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) * The bootloader is excluded from the calculation and occupies flash address * range 0 to 0x2000, total flash size of 0x40000 bytes (256 kByte). */ +#if defined(ARDUINO_PORTENTA_H7_M7) + // TODO: check if we need to checksum the whole flash or just the first megabyte + _ota_img_sha256 = FlashSHA256::calc(0x8040000, 0x200000 - 0x40000); +#else _ota_img_sha256 = FlashSHA256::calc(0x2000, 0x40000 - 0x2000); +#endif #endif /* OTA_ENABLED */ #ifdef BOARD_HAS_OFFLOADED_ECCX08 @@ -391,7 +396,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length) if ((_shadowTopicIn == topic) && (_state == State::RequestLastValues)) { - DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values received", __FUNCTION__, millis()); + DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s [%d] last values received"), __FUNCTION__, millis()); CBORDecoder::decode(_property_container, (uint8_t*)bytes, length, true); sendPropertiesToCloud(); execCloudEventCallback(ArduinoIoTCloudEvent::SYNC); @@ -438,6 +443,10 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l return 0; } +#if OTA_STORAGE_PORTENTA_QSPI +#include "ArduinoOTAPortenta.h" +#endif + #if OTA_ENABLED void ArduinoIoTCloudTCP::onOTARequest() { From b00e31fb4bb60042d5f3f8bf9c0f83a222a55020 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 21 Dec 2020 15:32:07 +0100 Subject: [PATCH 02/17] Force check on Portenta BL version --- src/AIoTC_Config.h | 7 +++++++ src/ArduinoIoTCloudTCP.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/AIoTC_Config.h b/src/AIoTC_Config.h index 59292db11..9d1008f34 100644 --- a/src/AIoTC_Config.h +++ b/src/AIoTC_Config.h @@ -100,6 +100,13 @@ #define OTA_STORAGE_SSU (0) #endif +#if defined(ARDUINO_PORTENTA_H7_M7) + #define OTA_STORAGE_PORTENTA_QSPI (1) + #define OTA_STORAGE_PORTENTA (1) +#else + #define OTA_STORAGE_PORTENTA_QSPI (0) +#endif + #if (OTA_STORAGE_SFU || OTA_STORAGE_SSU || OTA_STORAGE_SNU) && !defined(ARDUINO_AVR_UNO_WIFI_REV2) #define OTA_ENABLED (1) #else diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 88755fa62..e4f9d06fd 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -475,6 +475,30 @@ void ArduinoIoTCloudTCP::onOTARequest() ota_download_success = true; #endif /* OTA_STORAGE_SNU */ +#if OTA_STORAGE_PORTENTA_QSPI + /* Just to be safe delete any remains from previous updates. */ + remove("/fs/UPDATE.BIN.LZSS"); + + OTAPortenta.begin(QSPI_FLASH_FATFS_MBR, 2048); + + if (OTAPortenta.download(_ota_url.c_str())) + { + DBG_ERROR(F("ArduinoIoTCloudTCP::%s error download to nina: %d"), __FUNCTION__, nina_ota_err_code); + _ota_error = static_cast(OTAError::DownloadFailed); + return; + } + + auto update_file_size = OTAPortenta.decompress(); + OTAPortenta.setUpdateLen(update_file_size); + + /* The download was a success. */ + ota_download_success = true; + + while (1) { + OTAPortenta.update(); + } +#endif /* OTA_STORAGE_PORTENTA_QSPI */ + #ifndef __AVR__ /* Perform the reset to reboot to SxU. */ if (ota_download_success) From 080197943f94d403dc3882415c39bd7a664365ef Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 13 Jan 2021 06:24:42 +0100 Subject: [PATCH 03/17] Bugfix: _ota_cap is false per default, but we need to set it to true if the bootloader is in fact capable of OTA support. --- src/ArduinoIoTCloudTCP.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index e4f9d06fd..afcbdbd2f 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -191,6 +191,20 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) addPropertyReal(_ota_req, "OTA_REQ", Permission::ReadWrite).onSync(DEVICE_WINS); #endif /* OTA_ENABLED */ +#if OTA_STORAGE_PORTENTA_QSPI + #define BOOTLOADER_ADDR (0x8000000) + uint32_t bootloader_data_offset = 0x1F000; + uint8_t* bootloader_data = (uint8_t*)(BOOTLOADER_ADDR + bootloader_data_offset); + uint8_t currentBootloaderVersion = bootloader_data[1]; + if (currentBootloaderVersion < 22) { + _ota_cap = false; + DBG_WARNING(F("ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, update the bootloader"), __FUNCTION__); + } + else { + _ota_cap = true; + } +#endif + #if OTA_STORAGE_SNU && OTA_ENABLED String const nina_fw_version = WiFi.firmwareVersion(); if (nina_fw_version < "1.4.1") { @@ -479,7 +493,8 @@ void ArduinoIoTCloudTCP::onOTARequest() /* Just to be safe delete any remains from previous updates. */ remove("/fs/UPDATE.BIN.LZSS"); - OTAPortenta.begin(QSPI_FLASH_FATFS_MBR, 2048); + // Use second partition + OTAPortenta.begin(QSPI_FLASH_FATFS_MBR, 2); if (OTAPortenta.download(_ota_url.c_str())) { From 09784c884f9e38247aa419c489879c5d284cd45e Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 13 Jan 2021 06:28:12 +0100 Subject: [PATCH 04/17] Moving inclusion of ArduinoOTAPortenta into the correct spot of the codebase. --- src/ArduinoIoTCloudTCP.cpp | 4 ---- src/utility/ota/OTA.h | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index afcbdbd2f..f73ba73e8 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -457,10 +457,6 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l return 0; } -#if OTA_STORAGE_PORTENTA_QSPI -#include "ArduinoOTAPortenta.h" -#endif - #if OTA_ENABLED void ArduinoIoTCloudTCP::onOTARequest() { diff --git a/src/utility/ota/OTA.h b/src/utility/ota/OTA.h index bd1476fba..db5751cdd 100644 --- a/src/utility/ota/OTA.h +++ b/src/utility/ota/OTA.h @@ -37,6 +37,10 @@ #include #endif /* OTA_STORAGE_SFU */ +#if OTA_STORAGE_PORTENTA_QSPI + #include +#endif /* OTA_STORAGE_PORTENTA_QSPI */ + /****************************************************************************** * TYPEDEF ******************************************************************************/ From a315afbb8840ad577afaa2adf44570dacbdb8677 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 13 Jan 2021 06:43:37 +0100 Subject: [PATCH 05/17] Temporary change: Add link to latest ArduinoOTAPortenta library to be used in order to verify CI build. This needs to be replaced with the library name only as soon as this library has been properly released. --- .github/workflows/compile-examples.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 22d4a42a4..a6d5dd62a 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -137,6 +137,7 @@ jobs: name: arduino:mbed libraries: | - name: ArduinoECCX08 + - source-url: https://github.com/facchinm/ArduinoOTAPortenta.git sketch-paths: | - examples/utility/Provisioning # ESP8266 boards From 690108f04b49f594d7b14530d8e339615fe48632 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 19 Jan 2021 14:56:18 +0100 Subject: [PATCH 06/17] Restructuring OTA code in light of adaptions made to Arduino_OTA_Portenta library. --- .github/workflows/compile-examples.yml | 2 +- src/ArduinoIoTCloudTCP.cpp | 58 ++++++++++++++------------ src/utility/ota/OTA.h | 2 +- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index a6d5dd62a..833acccaa 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -137,7 +137,7 @@ jobs: name: arduino:mbed libraries: | - name: ArduinoECCX08 - - source-url: https://github.com/facchinm/ArduinoOTAPortenta.git + - source-url: https://github.com/facchinm/Arduino_OTA_Portenta.git sketch-paths: | - examples/utility/Provisioning # ESP8266 boards diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index f73ba73e8..5b450d1b6 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -330,7 +330,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected() { if (!_mqttClient.connected()) { - DEBUG_ERROR("ArduinoIoTCloudTCP::%s MQTT client connection lost", __FUNCTION__); + DBG_ERROR(F("ArduinoIoTCloudTCP::%s MQTT client connection lost"), __FUNCTION__); /* Forcefully disconnect MQTT client and trigger a reconnection. */ _mqttClient.stop(); @@ -460,12 +460,7 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l #if OTA_ENABLED void ArduinoIoTCloudTCP::onOTARequest() { - DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s _ota_url = %s", __FUNCTION__, _ota_url.c_str()); - - /* Status flag to prevent the reset from being executed - * when HTTPS download is not supported. - */ - bool ota_download_success = false; + DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s _ota_url = %s"), __FUNCTION__, _ota_url.c_str()); #if OTA_STORAGE_SNU /* Just to be safe delete any remains from previous updates. */ @@ -481,40 +476,49 @@ void ArduinoIoTCloudTCP::onOTARequest() return; } - /* The download was a success. */ - ota_download_success = true; + /* Perform the reset to reboot to SxU. */ + NVIC_SystemReset(); #endif /* OTA_STORAGE_SNU */ #if OTA_STORAGE_PORTENTA_QSPI /* Just to be safe delete any remains from previous updates. */ remove("/fs/UPDATE.BIN.LZSS"); - // Use second partition - OTAPortenta.begin(QSPI_FLASH_FATFS_MBR, 2); + Arduino_OTA_Portenta::Error ota_portenta_err = Arduino_OTA_Portenta::Error::None; + /* Use 2nd partition of QSPI (1st partition contains WiFi firmware) */ + Arduino_OTA_Portenta_QSPI ota_portenta_qspi(QSPI_FLASH_FATFS_MBR, 2); - if (OTAPortenta.download(_ota_url.c_str())) - { - DBG_ERROR(F("ArduinoIoTCloudTCP::%s error download to nina: %d"), __FUNCTION__, nina_ota_err_code); - _ota_error = static_cast(OTAError::DownloadFailed); + /* Initialize the QSPI memory for OTA handling. */ + if((ota_portenta_err = ota_portenta_qspi.begin()) != Arduino_OTA_Portenta::Error::None) { + DBG_ERROR(F("Arduino_OTA_Portenta_QSPI::begin() failed with %d"), static_cast(ota_portenta_err)); return; } - auto update_file_size = OTAPortenta.decompress(); - OTAPortenta.setUpdateLen(update_file_size); + /* Download the OTA file from the web storage location. */ + int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download((char*)(_ota_url.c_str())); + DBG_VERBOSE(F("Arduino_OTA_Portenta_QSPI::download(%s) returns %d"), _ota_url.c_str(), ota_portenta_qspi_download_ret_code); - /* The download was a success. */ - ota_download_success = true; + /* Decompress the LZSS compressed OTA file. */ + int const ota_portenta_qspi_decompress_ret_code = ota_portenta_qspi.decompress(); + DBG_VERBOSE(F("Arduino_OTA_Portenta_QSPI::decompress() returns %d"), ota_portenta_qspi_decompress_ret_code); + if (ota_portenta_qspi_decompress_ret_code < 0) + { + DBG_ERROR(F("Arduino_OTA_Portenta_QSPI::decompress() failed with %d"), ota_portenta_qspi_decompress_ret_code); + return; + } + /* Set the correct update size. */ + size_t const update_file_size = ota_portenta_qspi_decompress_ret_code; + ota_portenta_qspi.setUpdateLen(update_file_size); - while (1) { - OTAPortenta.update(); + /* Schedule the firmware update. */ + if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_OTA_Portenta::Error::None) { + DBG_ERROR(F("Arduino_OTA_Portenta_QSPI::update() failed with %d"), static_cast(ota_portenta_err)); + return; } -#endif /* OTA_STORAGE_PORTENTA_QSPI */ -#ifndef __AVR__ - /* Perform the reset to reboot to SxU. */ - if (ota_download_success) - NVIC_SystemReset(); -#endif + /* Perform the reset to reboot - then the bootloader performs the actual application update. */ + NVIC_SystemReset(); +#endif /* OTA_STORAGE_PORTENTA_QSPI */ } #endif diff --git a/src/utility/ota/OTA.h b/src/utility/ota/OTA.h index db5751cdd..7da19806f 100644 --- a/src/utility/ota/OTA.h +++ b/src/utility/ota/OTA.h @@ -38,7 +38,7 @@ #endif /* OTA_STORAGE_SFU */ #if OTA_STORAGE_PORTENTA_QSPI - #include + #include #endif /* OTA_STORAGE_PORTENTA_QSPI */ /****************************************************************************** From c915dfd585802cea6671ad212a2788ee162c1d4f Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 20 Jan 2021 07:08:41 +0100 Subject: [PATCH 07/17] Adjusting renaming of types names for Portenta OTA to follow suit with renamings within the Arduino_Portenta_OTA library itself. --- src/ArduinoIoTCloudTCP.cpp | 18 +++++++++--------- src/utility/ota/OTA.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 5b450d1b6..6f3c5da6a 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -484,26 +484,26 @@ void ArduinoIoTCloudTCP::onOTARequest() /* Just to be safe delete any remains from previous updates. */ remove("/fs/UPDATE.BIN.LZSS"); - Arduino_OTA_Portenta::Error ota_portenta_err = Arduino_OTA_Portenta::Error::None; + Arduino_Portenta_OTA::Error ota_portenta_err = Arduino_Portenta_OTA::Error::None; /* Use 2nd partition of QSPI (1st partition contains WiFi firmware) */ - Arduino_OTA_Portenta_QSPI ota_portenta_qspi(QSPI_FLASH_FATFS_MBR, 2); + Arduino_Portenta_OTA_QSPI ota_portenta_qspi(QSPI_FLASH_FATFS_MBR, 2); /* Initialize the QSPI memory for OTA handling. */ - if((ota_portenta_err = ota_portenta_qspi.begin()) != Arduino_OTA_Portenta::Error::None) { - DBG_ERROR(F("Arduino_OTA_Portenta_QSPI::begin() failed with %d"), static_cast(ota_portenta_err)); + if((ota_portenta_err = ota_portenta_qspi.begin()) != Arduino_Portenta_OTA::Error::None) { + DBG_ERROR(F("Arduino_Portenta_OTA_QSPI::begin() failed with %d"), static_cast(ota_portenta_err)); return; } /* Download the OTA file from the web storage location. */ int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download((char*)(_ota_url.c_str())); - DBG_VERBOSE(F("Arduino_OTA_Portenta_QSPI::download(%s) returns %d"), _ota_url.c_str(), ota_portenta_qspi_download_ret_code); + DBG_VERBOSE(F("Arduino_Portenta_OTA_QSPI::download(%s) returns %d"), _ota_url.c_str(), ota_portenta_qspi_download_ret_code); /* Decompress the LZSS compressed OTA file. */ int const ota_portenta_qspi_decompress_ret_code = ota_portenta_qspi.decompress(); - DBG_VERBOSE(F("Arduino_OTA_Portenta_QSPI::decompress() returns %d"), ota_portenta_qspi_decompress_ret_code); + DBG_VERBOSE(F("Arduino_Portenta_OTA_QSPI::decompress() returns %d"), ota_portenta_qspi_decompress_ret_code); if (ota_portenta_qspi_decompress_ret_code < 0) { - DBG_ERROR(F("Arduino_OTA_Portenta_QSPI::decompress() failed with %d"), ota_portenta_qspi_decompress_ret_code); + DBG_ERROR(F("Arduino_Portenta_OTA_QSPI::decompress() failed with %d"), ota_portenta_qspi_decompress_ret_code); return; } /* Set the correct update size. */ @@ -511,8 +511,8 @@ void ArduinoIoTCloudTCP::onOTARequest() ota_portenta_qspi.setUpdateLen(update_file_size); /* Schedule the firmware update. */ - if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_OTA_Portenta::Error::None) { - DBG_ERROR(F("Arduino_OTA_Portenta_QSPI::update() failed with %d"), static_cast(ota_portenta_err)); + if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_Portenta_OTA::Error::None) { + DBG_ERROR(F("Arduino_Portenta_OTA_QSPI::update() failed with %d"), static_cast(ota_portenta_err)); return; } diff --git a/src/utility/ota/OTA.h b/src/utility/ota/OTA.h index 7da19806f..670b5ac07 100644 --- a/src/utility/ota/OTA.h +++ b/src/utility/ota/OTA.h @@ -38,7 +38,7 @@ #endif /* OTA_STORAGE_SFU */ #if OTA_STORAGE_PORTENTA_QSPI - #include + #include #endif /* OTA_STORAGE_PORTENTA_QSPI */ /****************************************************************************** From b4806cc62dc133ba712116e24953d29c9dd16f1d Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 28 Jan 2021 12:17:14 +0100 Subject: [PATCH 08/17] Renaming still incorrect debug macros. --- src/ArduinoIoTCloudTCP.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 6f3c5da6a..8f2607852 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -330,7 +330,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected() { if (!_mqttClient.connected()) { - DBG_ERROR(F("ArduinoIoTCloudTCP::%s MQTT client connection lost"), __FUNCTION__); + DEBUG_ERROR("ArduinoIoTCloudTCP::%s MQTT client connection lost", __FUNCTION__); /* Forcefully disconnect MQTT client and trigger a reconnection. */ _mqttClient.stop(); @@ -410,7 +410,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length) if ((_shadowTopicIn == topic) && (_state == State::RequestLastValues)) { - DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s [%d] last values received"), __FUNCTION__, millis()); + DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values received", __FUNCTION__, millis()); CBORDecoder::decode(_property_container, (uint8_t*)bytes, length, true); sendPropertiesToCloud(); execCloudEventCallback(ArduinoIoTCloudEvent::SYNC); @@ -490,7 +490,7 @@ void ArduinoIoTCloudTCP::onOTARequest() /* Initialize the QSPI memory for OTA handling. */ if((ota_portenta_err = ota_portenta_qspi.begin()) != Arduino_Portenta_OTA::Error::None) { - DBG_ERROR(F("Arduino_Portenta_OTA_QSPI::begin() failed with %d"), static_cast(ota_portenta_err)); + DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::begin() failed with %d", static_cast(ota_portenta_err)); return; } @@ -503,7 +503,7 @@ void ArduinoIoTCloudTCP::onOTARequest() DBG_VERBOSE(F("Arduino_Portenta_OTA_QSPI::decompress() returns %d"), ota_portenta_qspi_decompress_ret_code); if (ota_portenta_qspi_decompress_ret_code < 0) { - DBG_ERROR(F("Arduino_Portenta_OTA_QSPI::decompress() failed with %d"), ota_portenta_qspi_decompress_ret_code); + DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::decompress() failed with %d", ota_portenta_qspi_decompress_ret_code); return; } /* Set the correct update size. */ @@ -512,7 +512,7 @@ void ArduinoIoTCloudTCP::onOTARequest() /* Schedule the firmware update. */ if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_Portenta_OTA::Error::None) { - DBG_ERROR(F("Arduino_Portenta_OTA_QSPI::update() failed with %d"), static_cast(ota_portenta_err)); + DEBUG_ERROR(F("Arduino_Portenta_OTA_QSPI::update() failed with %d"), static_cast(ota_portenta_err)); return; } From 7076c27f75b49e74a699b56b5ed9cc14c89d9f1a Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 28 Jan 2021 12:28:05 +0100 Subject: [PATCH 09/17] Ensure that OTA_ENABLE is set correctly. --- src/AIoTC_Config.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AIoTC_Config.h b/src/AIoTC_Config.h index 9d1008f34..bc451ad44 100644 --- a/src/AIoTC_Config.h +++ b/src/AIoTC_Config.h @@ -102,12 +102,11 @@ #if defined(ARDUINO_PORTENTA_H7_M7) #define OTA_STORAGE_PORTENTA_QSPI (1) - #define OTA_STORAGE_PORTENTA (1) #else #define OTA_STORAGE_PORTENTA_QSPI (0) #endif -#if (OTA_STORAGE_SFU || OTA_STORAGE_SSU || OTA_STORAGE_SNU) && !defined(ARDUINO_AVR_UNO_WIFI_REV2) +#if (OTA_STORAGE_SFU || OTA_STORAGE_SSU || OTA_STORAGE_SNU || OTA_STORAGE_PORTENTA_QSPI) && !defined(ARDUINO_AVR_UNO_WIFI_REV2) #define OTA_ENABLED (1) #else #define OTA_ENABLED (0) From c9dea0f32ac7b5190ff77839785c9cc2e617ec37 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 28 Jan 2021 12:28:38 +0100 Subject: [PATCH 10/17] Eliminating no longer existing API setUpdateLen. --- src/ArduinoIoTCloudTCP.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 8f2607852..cf687fb95 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -506,9 +506,6 @@ void ArduinoIoTCloudTCP::onOTARequest() DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::decompress() failed with %d", ota_portenta_qspi_decompress_ret_code); return; } - /* Set the correct update size. */ - size_t const update_file_size = ota_portenta_qspi_decompress_ret_code; - ota_portenta_qspi.setUpdateLen(update_file_size); /* Schedule the firmware update. */ if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_Portenta_OTA::Error::None) { From d395a2bfae3b8e23614bb972cf9434dcc09687e4 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 28 Jan 2021 12:33:22 +0100 Subject: [PATCH 11/17] Fixing a couple of more wrong debug macros. --- src/ArduinoIoTCloudTCP.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index cf687fb95..e3a59c0e6 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -198,7 +198,7 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) uint8_t currentBootloaderVersion = bootloader_data[1]; if (currentBootloaderVersion < 22) { _ota_cap = false; - DBG_WARNING(F("ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, update the bootloader"), __FUNCTION__); + DEBUG_WARNING("ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, update the bootloader", __FUNCTION__); } else { _ota_cap = true; @@ -460,7 +460,7 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l #if OTA_ENABLED void ArduinoIoTCloudTCP::onOTARequest() { - DBG_VERBOSE(F("ArduinoIoTCloudTCP::%s _ota_url = %s"), __FUNCTION__, _ota_url.c_str()); + DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s _ota_url = %s", __FUNCTION__, _ota_url.c_str()); #if OTA_STORAGE_SNU /* Just to be safe delete any remains from previous updates. */ @@ -496,11 +496,11 @@ void ArduinoIoTCloudTCP::onOTARequest() /* Download the OTA file from the web storage location. */ int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download((char*)(_ota_url.c_str())); - DBG_VERBOSE(F("Arduino_Portenta_OTA_QSPI::download(%s) returns %d"), _ota_url.c_str(), ota_portenta_qspi_download_ret_code); + DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", _ota_url.c_str(), ota_portenta_qspi_download_ret_code); /* Decompress the LZSS compressed OTA file. */ int const ota_portenta_qspi_decompress_ret_code = ota_portenta_qspi.decompress(); - DBG_VERBOSE(F("Arduino_Portenta_OTA_QSPI::decompress() returns %d"), ota_portenta_qspi_decompress_ret_code); + DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::decompress() returns %d", ota_portenta_qspi_decompress_ret_code); if (ota_portenta_qspi_decompress_ret_code < 0) { DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::decompress() failed with %d", ota_portenta_qspi_decompress_ret_code); @@ -509,7 +509,7 @@ void ArduinoIoTCloudTCP::onOTARequest() /* Schedule the firmware update. */ if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_Portenta_OTA::Error::None) { - DEBUG_ERROR(F("Arduino_Portenta_OTA_QSPI::update() failed with %d"), static_cast(ota_portenta_err)); + DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::update() failed with %d", static_cast(ota_portenta_err)); return; } From 66ce560336a53f3d1495964637f3f48ebbe02a35 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 1 Feb 2021 10:34:03 +0100 Subject: [PATCH 12/17] Extending bin2ota script for generating OTA file for PORTENTA_H7_M7. --- extras/tools/bin2ota.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extras/tools/bin2ota.py b/extras/tools/bin2ota.py index 99e86c0df..648aa2395 100755 --- a/extras/tools/bin2ota.py +++ b/extras/tools/bin2ota.py @@ -22,6 +22,8 @@ magic_number = 0x23418054.to_bytes(4,byteorder='little') elif board == "NANO_33_IOT": magic_number = 0x23418057.to_bytes(4,byteorder='little') +elif board == "PORTENTA_H7_M7": + magic_number = 0x2341025B.to_bytes(4,byteorder='little') else: print ("Error,", board, "is not a supported board type") sys.exit() From 194c95ca62fe4cdbd20d77202e9ed58ace3271f6 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 1 Feb 2021 14:41:28 +0100 Subject: [PATCH 13/17] Moving the delete step of any previous update file to after where the file system is initialised. --- src/ArduinoIoTCloudTCP.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index e3a59c0e6..47095de4a 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -481,9 +481,6 @@ void ArduinoIoTCloudTCP::onOTARequest() #endif /* OTA_STORAGE_SNU */ #if OTA_STORAGE_PORTENTA_QSPI - /* Just to be safe delete any remains from previous updates. */ - remove("/fs/UPDATE.BIN.LZSS"); - Arduino_Portenta_OTA::Error ota_portenta_err = Arduino_Portenta_OTA::Error::None; /* Use 2nd partition of QSPI (1st partition contains WiFi firmware) */ Arduino_Portenta_OTA_QSPI ota_portenta_qspi(QSPI_FLASH_FATFS_MBR, 2); @@ -494,6 +491,9 @@ void ArduinoIoTCloudTCP::onOTARequest() return; } + /* Just to be safe delete any remains from previous updates. */ + remove("/fs/UPDATE.BIN.LZSS"); + /* Download the OTA file from the web storage location. */ int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download((char*)(_ota_url.c_str())); DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", _ota_url.c_str(), ota_portenta_qspi_download_ret_code); From 8a663ce237f4cfc02e3355fc58638af483dd9a72 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 1 Feb 2021 14:47:56 +0100 Subject: [PATCH 14/17] Also remove the update binary in case there are any remains left from previous updates. --- src/ArduinoIoTCloudTCP.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 47095de4a..49ea8841f 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -492,6 +492,7 @@ void ArduinoIoTCloudTCP::onOTARequest() } /* Just to be safe delete any remains from previous updates. */ + remove("/fs/UPDATE.BIN"); remove("/fs/UPDATE.BIN.LZSS"); /* Download the OTA file from the web storage location. */ From 52177d5db7d2ea31abdc5e1634b0de9698ac4c8b Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 2 Feb 2021 09:10:56 +0100 Subject: [PATCH 15/17] Add more detailed information on how to update the bootloader for Portenta H7. --- src/ArduinoIoTCloudTCP.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 49ea8841f..0bb7e09bd 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -199,6 +199,7 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) if (currentBootloaderVersion < 22) { _ota_cap = false; DEBUG_WARNING("ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, update the bootloader", __FUNCTION__); + DEBUG_WARNING("ArduinoIoTCloudTCP::%s File -> Examples -> Portenta_System -> PortentaH7_updateBootloader", __FUNCTION__); } else { _ota_cap = true; From a6bef66cce606d2fe842262aa05503c31281656b Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 2 Feb 2021 09:54:09 +0100 Subject: [PATCH 16/17] Adapt to new dowload API call. --- src/ArduinoIoTCloudTCP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 0bb7e09bd..4bd44e056 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -497,7 +497,7 @@ void ArduinoIoTCloudTCP::onOTARequest() remove("/fs/UPDATE.BIN.LZSS"); /* Download the OTA file from the web storage location. */ - int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download((char*)(_ota_url.c_str())); + int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download((char*)(_ota_url.c_str()), true /* is_https */); DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", _ota_url.c_str(), ota_portenta_qspi_download_ret_code); /* Decompress the LZSS compressed OTA file. */ From 43476acdcdf615f7d13548e939fe67e2aafecf52 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 2 Feb 2021 11:02:13 +0100 Subject: [PATCH 17/17] Update location of Arduino_Portenta_OTA library. --- .github/workflows/compile-examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 833acccaa..d491ead03 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -137,7 +137,7 @@ jobs: name: arduino:mbed libraries: | - name: ArduinoECCX08 - - source-url: https://github.com/facchinm/Arduino_OTA_Portenta.git + - source-url: https://github.com/arduino-libraries/Arduino_Portenta_OTA.git sketch-paths: | - examples/utility/Provisioning # ESP8266 boards