Skip to content

Commit d0346cb

Browse files
committed
Create OTA::isCapable and move code from ArduinoIoTCloudTCP
1 parent 7c217e5 commit d0346cb

File tree

7 files changed

+51
-35
lines changed

7 files changed

+51
-35
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -205,38 +205,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
205205
addPropertyReal(_tz_offset, "tz_offset", Permission::ReadWrite).onSync(CLOUD_WINS).onUpdate(updateTimezoneInfo);
206206
addPropertyReal(_tz_dst_until, "tz_dst_until", Permission::ReadWrite).onSync(CLOUD_WINS).onUpdate(updateTimezoneInfo);
207207

208-
#if OTA_STORAGE_PORTENTA_QSPI
209-
#define BOOTLOADER_ADDR (0x8000000)
210-
uint32_t bootloader_data_offset = 0x1F000;
211-
uint8_t* bootloader_data = (uint8_t*)(BOOTLOADER_ADDR + bootloader_data_offset);
212-
uint8_t currentBootloaderVersion = bootloader_data[1];
213-
if (currentBootloaderVersion < 22) {
214-
_ota_cap = false;
215-
DEBUG_WARNING("ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, update the bootloader", __FUNCTION__);
216-
DEBUG_WARNING("ArduinoIoTCloudTCP::%s File -> Examples -> Portenta_System -> PortentaH7_updateBootloader", __FUNCTION__);
217-
}
218-
else {
219-
_ota_cap = true;
220-
}
221-
#endif
222-
223-
#if OTA_STORAGE_SNU && OTA_ENABLED
224-
if (String(WiFi.firmwareVersion()) < String("1.4.1")) {
225-
_ota_cap = false;
226-
DEBUG_WARNING("ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, NINA firmware needs to be >= 1.4.1, current %s", __FUNCTION__, WiFi.firmwareVersion());
227-
}
228-
else {
229-
_ota_cap = true;
230-
}
231-
#endif /* OTA_STORAGE_SNU */
232-
233-
#if defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_NICLA_VISION)
234-
_ota_cap = true;
235-
#endif
236-
237-
#if defined(ARDUINO_ARCH_ESP32) && OTA_ENABLED
238-
/* NOTE: here is possible to check if current partition scheme is OTA compatible */
239-
_ota_cap = true;
208+
#if OTA_ENABLED
209+
_ota_cap = OTA::isCapable();
240210
#endif
241211

242212
#if OTA_ENABLED

src/utility/ota/OTA-esp32.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,10 @@ String esp32_getOTAImageSHA256()
120120
return sha256_str;
121121
}
122122

123+
bool esp32_isOTACapable()
124+
{
125+
/* NOTE: here is possible to check if current partition scheme is OTA compatible */
126+
return true;
127+
}
128+
123129
#endif /* ARDUINO_ARCH_ESP32 */

src/utility/ota/OTA-nano-rp2040.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,9 @@ String rp2040_connect_getOTAImageSHA256()
258258
return FlashSHA256::calc(XIP_BASE, 0x100000);
259259
}
260260

261+
bool rp2040_connect_isOTACapable()
262+
{
263+
return true;
264+
}
265+
261266
#endif /* ARDUINO_NANO_RP2040_CONNECT */

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ String portenta_h7_getOTAImageSHA256()
149149
return sha256_str;
150150
}
151151

152+
bool portenta_h7_isOTACapable()
153+
{
154+
return Arduino_Portenta_OTA::isOtaCapable();
155+
}
156+
152157
void portenta_h7_setNetworkAdapter(NetworkAdapter iface)
153158
{
154159
_ota_adapter = iface;

src/utility/ota/OTA-samd.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,17 @@ String samd_getOTAImageSHA256()
8181
return FlashSHA256::calc(0x2000, 0x40000 - 0x2000);
8282
}
8383

84+
bool samd_isOTACapable()
85+
{
86+
#if OTA_STORAGE_SNU
87+
if (String(WiFi.firmwareVersion()) < String("1.4.1")) {
88+
DEBUG_WARNING("ArduinoIoTCloudTCP::%s In order to be ready for cloud OTA, NINA firmware needs to be >= 1.4.1, current %s", __FUNCTION__, WiFi.firmwareVersion());
89+
return false;
90+
} else {
91+
return true;
92+
}
93+
#endif
94+
return false;
95+
}
96+
8497
#endif /* ARDUINO_ARCH_SAMD */

src/utility/ota/OTA.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,38 @@
2727
#include <Arduino_DebugUtils.h>
2828

2929
/******************************************************************************
30-
* FUNCTION DEFINITION
30+
* FUNCTION DECLARATION
3131
******************************************************************************/
3232

3333
#ifdef ARDUINO_ARCH_SAMD
3434
int samd_onOTARequest(char const * url);
3535
String samd_getOTAImageSHA256();
36+
bool samd_isOTACapable();
3637
#endif
3738

3839
#ifdef ARDUINO_NANO_RP2040_CONNECT
3940
int rp2040_connect_onOTARequest(char const * url);
4041
String rp2040_connect_getOTAImageSHA256();
42+
bool rp2040_connect_isOTACapable();
4143
#endif
4244

4345
#ifdef BOARD_STM32H7
4446
int portenta_h7_onOTARequest(char const * url);
4547
String portenta_h7_getOTAImageSHA256();
4648
void portenta_h7_setNetworkAdapter(NetworkAdapter iface);
49+
bool portenta_h7_isOTACapable();
4750
#endif
4851

4952
#ifdef ARDUINO_ARCH_ESP32
5053
int esp32_onOTARequest(char const * url);
5154
String esp32_getOTAImageSHA256();
55+
bool esp32_isOTACapable();
5256
#endif
5357

5458
/******************************************************************************
5559
* PUBLIC MEMBER FUNCTIONS
5660
******************************************************************************/
5761

58-
5962
int OTA::onRequest(String url)
6063
{
6164
DEBUG_INFO("ArduinoIoTCloudTCP::%s _ota_url = %s", __FUNCTION__, url.c_str());
@@ -88,6 +91,20 @@ String OTA::getImageSHA256()
8891
#endif
8992
}
9093

94+
bool OTA::isCapable()
95+
{
96+
#if defined (ARDUINO_ARCH_SAMD)
97+
return samd_isOTACapable();
98+
#elif defined (ARDUINO_NANO_RP2040_CONNECT)
99+
return rp2040_connect_isOTACapable();
100+
#elif defined (BOARD_STM32H7)
101+
return portenta_h7_isOTACapable();
102+
#elif defined (ARDUINO_ARCH_ESP32)
103+
return esp32_isOTACapable();
104+
#else
105+
#error "OTA not supported for this architecture"
106+
#endif
107+
}
91108

92109
void OTA::setNetworkAdapter(NetworkAdapter iface)
93110
{
@@ -105,4 +122,3 @@ void OTA::setNetworkAdapter(NetworkAdapter iface)
105122
}
106123

107124
#endif /* OTA_ENABLED */
108-

src/utility/ota/OTA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class OTA
6565
static int onRequest(String url);
6666
static String getImageSHA256();
6767
static void setNetworkAdapter(NetworkAdapter iface);
68+
static bool isCapable();
6869

6970
};
7071

0 commit comments

Comments
 (0)