From 3e609d3f138306bbde7c4ea1a75fe7274c5c9513 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 2 Aug 2022 09:38:43 +0200 Subject: [PATCH 1/4] Add support for opta board --- library.properties | 2 +- src/Arduino_Portenta_OTA_Config.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index ee8aff2..39ba184 100644 --- a/library.properties +++ b/library.properties @@ -6,5 +6,5 @@ sentence=Firmware update for the Portenta H7. paragraph=This library allows performing a firmware update on the Arduino Portenta H7. The firmware can be stored in various different locations such as within the microcontroller's flash, on an external SD card or on the QSPI flash chip. category=Communication url=https://github.com/arduino-libraries/Arduino_Portenta_OTA -architectures=mbed,mbed_portenta,mbed_nicla +architectures=mbed,mbed_portenta,mbed_nicla,mbed_opta includes=Arduino_Portenta_OTA.h diff --git a/src/Arduino_Portenta_OTA_Config.h b/src/Arduino_Portenta_OTA_Config.h index 1d7b214..346f55e 100644 --- a/src/Arduino_Portenta_OTA_Config.h +++ b/src/Arduino_Portenta_OTA_Config.h @@ -35,4 +35,9 @@ #define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT #endif +#if defined(ARDUINO_OPTA) + #define ARDUINO_PORTENTA_OTA_MAGIC 0x23410264 + #define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT +#endif + #endif /* ARDUINO_PORTENTA_OTA_CONFIG_H_ */ From 5457939326daaddccedf473f1a2a16c5e2124837 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 22 Nov 2022 16:07:30 +0100 Subject: [PATCH 2/4] Add example to perform OTA with Ethernet on OPTA and PORTENTA_H7 --- .../OTA_Qspi_Flash_Ethernet.ino | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 examples/OTA_Qspi_Flash_Ethernet/OTA_Qspi_Flash_Ethernet.ino diff --git a/examples/OTA_Qspi_Flash_Ethernet/OTA_Qspi_Flash_Ethernet.ino b/examples/OTA_Qspi_Flash_Ethernet/OTA_Qspi_Flash_Ethernet.ino new file mode 100644 index 0000000..b17fb29 --- /dev/null +++ b/examples/OTA_Qspi_Flash_Ethernet/OTA_Qspi_Flash_Ethernet.ino @@ -0,0 +1,113 @@ +/* + * This example demonstrates how to use to update the firmware of the Arduino Portenta H7 using + * a firmware image stored on the QSPI. + * + * Steps: + * 1) Create a sketch for the Portenta H7 and verify + * that it both compiles and works on a board. + * 2) In the IDE select: Sketch -> Export compiled Binary. + * 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in + * https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools . + * A) ./lzss.py --encode SKETCH.bin SKETCH.lzss + * B) ./bin2ota.py PORTENTA_H7_M7 SKETCH.lzss SKETCH.ota + * 4) Upload the OTA file to a network reachable location, e.g. OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * has been uploaded to: http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * 5) Perform an OTA update via steps outlined below. + */ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + +#include + +/****************************************************************************** + * CONSTANT + ******************************************************************************/ +#if defined(ARDUINO_OPTA) +static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.OPTA.ota"; +#elif defined(ARDUINO_PORTENTA_H7_M7) +static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota"; +#else +#error "Board not supported" +#endif + +/****************************************************************************** + * SETUP/LOOP + ******************************************************************************/ + +void setup() +{ + Serial.begin(115200); + while (!Serial) {} + + while (Ethernet.linkStatus() == LinkOFF) + { + Serial.println("Attempting to connect to the network ..."); + Ethernet.begin(); + } + Serial.println("Connected"); + + Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2); + Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None; + + if (!ota.isOtaCapable()) + { + Serial.println("Higher version bootloader required to perform OTA."); + Serial.println("Please update the bootloader."); + Serial.println("File -> Examples -> STM32H747_System -> STM32H747_manageBootloader"); + return; + } + + Serial.println("Initializing OTA storage"); + if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None) + { + Serial.print ("Arduino_Portenta_OTA::begin() failed with error code "); + Serial.println((int)ota_err); + return; + } + + Serial.println("Starting download to QSPI ..."); + int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */); + if (ota_download <= 0) + { + Serial.print ("Arduino_Portenta_OTA_QSPI::download failed with error code "); + Serial.println(ota_download); + return; + } + Serial.print (ota_download); + Serial.println(" bytes stored."); + + + Serial.println("Decompressing LZSS compressed file ..."); + int const ota_decompress = ota.decompress(); + if (ota_decompress < 0) + { + Serial.print("Arduino_Portenta_OTA_QSPI::decompress() failed with error code"); + Serial.println(ota_decompress); + return; + } + Serial.print(ota_decompress); + Serial.println(" bytes decompressed."); + + + Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ..."); + if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None) + { + Serial.print ("ota.update() failed with error code "); + Serial.println((int)ota_err); + return; + } + + Serial.println("Performing a reset after which the bootloader will update the firmware."); + Serial.println("Hint: Board LED will blink Red-Blue-Green."); + delay(1000); /* Make sure the serial message gets out before the reset. */ + ota.reset(); +} + +void loop() +{ + +} From a21c84e746c2f0efd6f8f131a1666ffbe6876274 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 19 Dec 2022 10:44:20 +0100 Subject: [PATCH 3/4] Add opta compile example workflow --- .github/workflows/compile-examples.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 1977579..c9f4b39 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -49,6 +49,15 @@ jobs: sketch-paths: | - examples/OTA_Qspi_Flash - examples/OTA_Usage_Portenta + - fqbn: arduino:mbed_opta:opta + platforms: | + - name: arduino:mbed_opta + libraries: | + - name: Arduino_DebugUtils + sketch-paths: | + - examples/OTA_Qspi_Flash + - examples/OTA_Qspi_Flash_Ethernet + - examples/OTA_Usage_Portenta steps: - name: Checkout From f842b37f2f015e1479c9be10a9c6c1dd429152df Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 20 Dec 2022 09:17:45 +0100 Subject: [PATCH 4/4] Update magic number to match core release --- src/Arduino_Portenta_OTA_Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_Portenta_OTA_Config.h b/src/Arduino_Portenta_OTA_Config.h index 346f55e..bdfab4b 100644 --- a/src/Arduino_Portenta_OTA_Config.h +++ b/src/Arduino_Portenta_OTA_Config.h @@ -36,7 +36,7 @@ #endif #if defined(ARDUINO_OPTA) - #define ARDUINO_PORTENTA_OTA_MAGIC 0x23410264 + #define ARDUINO_PORTENTA_OTA_MAGIC 0x23410064 #define ARDUINO_PORTENTA_OTA_QSPI_SUPPORT #endif