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