Skip to content

Commit 5dd7cf0

Browse files
authored
Merge pull request #30 from pennam/portenta-eth
Add support for ethernet interface
2 parents 4ffda14 + 53437f5 commit 5dd7cf0

5 files changed

+48
-12
lines changed

src/Arduino_Portenta_OTA.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ Arduino_Portenta_OTA::Error Arduino_Portenta_OTA::begin()
6767
if (!isOtaCapable())
6868
return Error::NoCapableBootloader;
6969

70+
if (!caStorageInit())
71+
return Error::CaStorageInit;
72+
73+
if (!caStorageOpen())
74+
return Error::CaStorageOpen;
75+
7076
if (!init())
7177
return Error::OtaStorageInit;
7278

@@ -131,3 +137,34 @@ void Arduino_Portenta_OTA::write()
131137
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR2, _data_offset);
132138
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR3, _program_length);
133139
}
140+
141+
bool Arduino_Portenta_OTA::caStorageInit()
142+
{
143+
_bd_raw_qspi = mbed::BlockDevice::get_default_instance();
144+
145+
if (_bd_raw_qspi->init() != QSPIF_BD_ERROR_OK) {
146+
Debug.print(DBG_ERROR, F("Error: QSPI init failure."));
147+
return false;
148+
}
149+
150+
mbed::MBRBlockDevice * cert_bd_qspi = new mbed::MBRBlockDevice(_bd_raw_qspi, 1);
151+
mbed::FATFileSystem * cert_fs_qspi = new mbed::FATFileSystem("wlan");
152+
int const err_mount = cert_fs_qspi->mount(cert_bd_qspi);
153+
if (err_mount) {
154+
Debug.print(DBG_ERROR, F("Error while mounting the certificate filesystem. Err = %d"), err_mount);
155+
return false;
156+
}
157+
return true;
158+
}
159+
160+
bool Arduino_Portenta_OTA::caStorageOpen()
161+
{
162+
FILE* fp = fopen("/wlan/cacert.pem", "r");
163+
if (!fp) {
164+
Debug.print(DBG_ERROR, F("Error while opening the certificate file."));
165+
return false;
166+
}
167+
fclose(fp);
168+
169+
return true;
170+
}

src/Arduino_Portenta_OTA.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
#include <LittleFileSystem.h>
3838
#include <Arduino_DebugUtils.h>
3939

40+
#include "WiFi.h" /* WiFi from ArduinoCore-mbed */
41+
#include <SocketHelpers.h>
42+
4043
/******************************************************************************
4144
* DEFINE
4245
******************************************************************************/
@@ -81,6 +84,8 @@ class Arduino_Portenta_OTA
8184
OtaHeaderLength = -5,
8285
OtaHeaderCrc = -6,
8386
OtaHeaterMagicNumber = -7,
87+
CaStorageInit = -8,
88+
CaStorageOpen = -9,
8489
};
8590

8691
Arduino_Portenta_OTA(StorageTypePortenta const storage_type, uint32_t const data_offset);
@@ -95,7 +100,7 @@ class Arduino_Portenta_OTA
95100
/* This functionality is intended for usage with the Arduino IoT Cloud for
96101
* performing OTA firmware updates using the Arduino IoT Cloud servers.
97102
*/
98-
int download(const char * url, bool const is_https);
103+
int download(const char * url, bool const is_https, MbedSocketClass * socket = static_cast<MbedSocketClass*>(&WiFi));
99104
int decompress();
100105
void setFeedWatchdogFunc(ArduinoPortentaOtaWatchdogResetFuncPointer func);
101106
void feedWatchdog();
@@ -106,6 +111,7 @@ class Arduino_Portenta_OTA
106111
StorageTypePortenta _storage_type;
107112
uint32_t _data_offset;
108113
uint32_t _program_length;
114+
mbed::BlockDevice * _bd_raw_qspi;
109115

110116
virtual bool init() = 0;
111117
virtual bool open() = 0;
@@ -115,6 +121,8 @@ class Arduino_Portenta_OTA
115121
private:
116122

117123
void write();
124+
bool caStorageInit();
125+
bool caStorageOpen();
118126
ArduinoPortentaOtaWatchdogResetFuncPointer _feed_watchdog_func = 0;
119127

120128
};

src/Arduino_Portenta_OTA_QSPI.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ Arduino_Portenta_OTA_QSPI::Arduino_Portenta_OTA_QSPI(StorageTypePortenta const s
4646

4747
bool Arduino_Portenta_OTA_QSPI::init()
4848
{
49-
_bd_raw_qspi = mbed::BlockDevice::get_default_instance();
50-
if (_bd_raw_qspi->init() != QSPIF_BD_ERROR_OK) {
51-
Debug.print(DBG_ERROR, F("Error: QSPI init failure."));
52-
return false;
53-
}
54-
5549
if(_storage_type == QSPI_FLASH_FATFS)
5650
{
5751
_fs_qspi = new mbed::FATFileSystem("fs");
@@ -75,7 +69,6 @@ bool Arduino_Portenta_OTA_QSPI::init()
7569
}
7670
return true;
7771
}
78-
7972
return false;
8073
}
8174

src/Arduino_Portenta_OTA_QSPI.h

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class Arduino_Portenta_OTA_QSPI : public Arduino_Portenta_OTA
4848

4949
private:
5050

51-
mbed::BlockDevice * _bd_raw_qspi;
5251
mbed::BlockDevice * _bd_qspi;
5352
mbed::FATFileSystem * _fs_qspi;
5453
};

src/decompress/utility.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include "lzss.h"
2424

25-
#include "WiFi.h" /* WiFi from ArduinoCore-mbed */
2625
#include "Arduino_Portenta_OTA.h"
2726

2827
/**************************************************************************************
@@ -90,9 +89,9 @@ uint32_t crc_update(uint32_t crc, const void * data, size_t data_len)
9089
MAIN
9190
**************************************************************************************/
9291

93-
int Arduino_Portenta_OTA::download(const char * url, bool const is_https)
92+
int Arduino_Portenta_OTA::download(const char * url, bool const is_https, MbedSocketClass * socket)
9493
{
95-
return WiFi.download((char *)url, UPDATE_FILE_NAME_LZSS, is_https);
94+
return socket->download((char *)url, UPDATE_FILE_NAME_LZSS, is_https);
9695
}
9796

9897
int Arduino_Portenta_OTA::decompress()

0 commit comments

Comments
 (0)