Skip to content

Commit 306d569

Browse files
committed
Extracting Portenta H7 OTA code to method 'portenta_h7_onOTARequest'
1 parent 790fc11 commit 306d569

File tree

4 files changed

+93
-51
lines changed

4 files changed

+93
-51
lines changed

src/ArduinoIoTCloudTCP.cpp

+4-50
Original file line numberDiff line numberDiff line change
@@ -583,57 +583,11 @@ void ArduinoIoTCloudTCP::onOTARequest()
583583

584584
#ifdef ARDUINO_ARCH_SAMD
585585
_ota_error = samd_onOTARequest(_ota_url.c_str());
586-
#endif /* ARDUINO_ARCH_SAMD */
587-
588-
#if OTA_STORAGE_PORTENTA_QSPI
589-
mbed_watchdog_reset();
590-
591-
Arduino_Portenta_OTA::Error ota_portenta_err = Arduino_Portenta_OTA::Error::None;
592-
/* Use 2nd partition of QSPI (1st partition contains WiFi firmware) */
593-
Arduino_Portenta_OTA_QSPI ota_portenta_qspi(QSPI_FLASH_FATFS_MBR, 2);
594-
595-
mbed_watchdog_reset();
596-
597-
/* Initialize the QSPI memory for OTA handling. */
598-
if((ota_portenta_err = ota_portenta_qspi.begin()) != Arduino_Portenta_OTA::Error::None) {
599-
DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::begin() failed with %d", static_cast<int>(ota_portenta_err));
600-
return;
601-
}
602-
603-
mbed_watchdog_reset();
604-
605-
/* Just to be safe delete any remains from previous updates. */
606-
remove("/fs/UPDATE.BIN");
607-
remove("/fs/UPDATE.BIN.LZSS");
608-
609-
mbed_watchdog_reset();
610-
611-
/* Download the OTA file from the web storage location. */
612-
int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download((char*)(_ota_url.c_str()), true /* is_https */);
613-
DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", _ota_url.c_str(), ota_portenta_qspi_download_ret_code);
614-
615-
mbed_watchdog_reset();
616-
617-
/* Decompress the LZSS compressed OTA file. */
618-
int const ota_portenta_qspi_decompress_ret_code = ota_portenta_qspi.decompress();
619-
DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::decompress() returns %d", ota_portenta_qspi_decompress_ret_code);
620-
if (ota_portenta_qspi_decompress_ret_code < 0)
621-
{
622-
DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::decompress() failed with %d", ota_portenta_qspi_decompress_ret_code);
623-
return;
624-
}
625-
626-
mbed_watchdog_reset();
627-
628-
/* Schedule the firmware update. */
629-
if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_Portenta_OTA::Error::None) {
630-
DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::update() failed with %d", static_cast<int>(ota_portenta_err));
631-
return;
632-
}
586+
#endif
633587

634-
/* Perform the reset to reboot - then the bootloader performs the actual application update. */
635-
NVIC_SystemReset();
636-
#endif /* OTA_STORAGE_PORTENTA_QSPI */
588+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
589+
_ota_error = portenta_h7_onOTARequest(_ota_url.c_str());
590+
#endif
637591
}
638592
#endif
639593

src/utility/ota/OTA-portenta-h7.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
This file is part of ArduinoIoTCloud.
3+
4+
Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
5+
6+
This software is released under the GNU General Public License version 3,
7+
which covers the main part of arduino-cli.
8+
The terms of this license can be found at:
9+
https://www.gnu.org/licenses/gpl-3.0.en.html
10+
11+
You can be released from the requirements of the above licenses by purchasing
12+
a commercial license. Buying such a license is mandatory if you want to modify or
13+
otherwise use the software for commercial activities involving the Arduino
14+
software without disclosing the source code of your own applications. To purchase
15+
a commercial license, send an email to [email protected].
16+
*/
17+
18+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
19+
20+
/******************************************************************************
21+
* INCLUDE
22+
******************************************************************************/
23+
24+
#include "OTA.h"
25+
26+
#include <Arduino_DebugUtils.h>
27+
28+
#include "../watchdog/Watchdog.h"
29+
30+
/******************************************************************************
31+
* FUNCTION DEFINITION
32+
******************************************************************************/
33+
34+
int portenta_h7_onOTARequest(char const * ota_url)
35+
{
36+
mbed_watchdog_reset();
37+
38+
Arduino_Portenta_OTA::Error ota_portenta_err = Arduino_Portenta_OTA::Error::None;
39+
/* Use 2nd partition of QSPI (1st partition contains WiFi firmware) */
40+
Arduino_Portenta_OTA_QSPI ota_portenta_qspi(QSPI_FLASH_FATFS_MBR, 2);
41+
42+
mbed_watchdog_reset();
43+
44+
/* Initialize the QSPI memory for OTA handling. */
45+
if((ota_portenta_err = ota_portenta_qspi.begin()) != Arduino_Portenta_OTA::Error::None) {
46+
DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::begin() failed with %d", static_cast<int>(ota_portenta_err));
47+
return static_cast<int>(ota_portenta_err);
48+
}
49+
50+
mbed_watchdog_reset();
51+
52+
/* Just to be safe delete any remains from previous updates. */
53+
remove("/fs/UPDATE.BIN");
54+
remove("/fs/UPDATE.BIN.LZSS");
55+
56+
mbed_watchdog_reset();
57+
58+
/* Download the OTA file from the web storage location. */
59+
int const ota_portenta_qspi_download_ret_code = ota_portenta_qspi.download(ota_url, true /* is_https */);
60+
DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::download(%s) returns %d", ota_url, ota_portenta_qspi_download_ret_code);
61+
62+
mbed_watchdog_reset();
63+
64+
/* Decompress the LZSS compressed OTA file. */
65+
int const ota_portenta_qspi_decompress_ret_code = ota_portenta_qspi.decompress();
66+
DEBUG_VERBOSE("Arduino_Portenta_OTA_QSPI::decompress() returns %d", ota_portenta_qspi_decompress_ret_code);
67+
if (ota_portenta_qspi_decompress_ret_code < 0)
68+
{
69+
DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::decompress() failed with %d", ota_portenta_qspi_decompress_ret_code);
70+
return ota_portenta_qspi_decompress_ret_code;
71+
}
72+
73+
mbed_watchdog_reset();
74+
75+
/* Schedule the firmware update. */
76+
if((ota_portenta_err = ota_portenta_qspi.update()) != Arduino_Portenta_OTA::Error::None) {
77+
DEBUG_ERROR("Arduino_Portenta_OTA_QSPI::update() failed with %d", static_cast<int>(ota_portenta_err));
78+
return static_cast<int>(ota_portenta_err);
79+
}
80+
81+
/* Perform the reset to reboot - then the bootloader performs the actual application update. */
82+
NVIC_SystemReset();
83+
}
84+
85+
#endif /* defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) */

src/utility/ota/OTA-samd.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "OTA.h"
2525

26-
#include <Arduino.h>
2726
#include <Arduino_DebugUtils.h>
2827

2928
#include "../watchdog/Watchdog.h"

src/utility/ota/OTA.h

+4
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,8 @@ enum class OTAError : int
5858
int samd_onOTARequest(char const * ota_url);
5959
#endif
6060

61+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
62+
int portenta_h7_onOTARequest(char const * ota_url);
63+
#endif
64+
6165
#endif /* ARDUINO_OTA_LOGIC_H_ */

0 commit comments

Comments
 (0)