Skip to content

Commit 9725f8d

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

File tree

7 files changed

+51
-33
lines changed

7 files changed

+51
-33
lines changed

src/ArduinoIoTCloudTCP.cpp

+2-32
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

+6
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

+5
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

+5
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

+14
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,18 @@ 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+
95+
return false
96+
}
97+
8498
#endif /* ARDUINO_ARCH_SAMD */

src/utility/ota/OTA.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,26 @@
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
/******************************************************************************
@@ -88,6 +92,20 @@ String OTA::getImageSHA256()
8892
#endif
8993
}
9094

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

92110
void OTA::setNetworkAdapter(NetworkAdapter iface)
93111
{
@@ -105,4 +123,3 @@ void OTA::setNetworkAdapter(NetworkAdapter iface)
105123
}
106124

107125
#endif /* OTA_ENABLED */
108-

src/utility/ota/OTA.h

+1
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)