Skip to content

Add support for ethernet interface #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Arduino_Portenta_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ Arduino_Portenta_OTA::Error Arduino_Portenta_OTA::begin()
if (!isOtaCapable())
return Error::NoCapableBootloader;

if (!caStorageInit())
return Error::CaStorageInit;

if (!caStorageOpen())
return Error::CaStorageOpen;

if (!init())
return Error::OtaStorageInit;

Expand Down Expand Up @@ -131,3 +137,34 @@ void Arduino_Portenta_OTA::write()
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR2, _data_offset);
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR3, _program_length);
}

bool Arduino_Portenta_OTA::caStorageInit()
{
_bd_raw_qspi = mbed::BlockDevice::get_default_instance();

if (_bd_raw_qspi->init() != QSPIF_BD_ERROR_OK) {
Debug.print(DBG_ERROR, F("Error: QSPI init failure."));
return false;
}

mbed::MBRBlockDevice * cert_bd_qspi = new mbed::MBRBlockDevice(_bd_raw_qspi, 1);
mbed::FATFileSystem * cert_fs_qspi = new mbed::FATFileSystem("wlan");
int const err_mount = cert_fs_qspi->mount(cert_bd_qspi);
if (err_mount) {
Debug.print(DBG_ERROR, F("Error while mounting the certificate filesystem. Err = %d"), err_mount);
return false;
}
return true;
}

bool Arduino_Portenta_OTA::caStorageOpen()
{
FILE* fp = fopen("/wlan/cacert.pem", "r");
if (!fp) {
Debug.print(DBG_ERROR, F("Error while opening the certificate file."));
return false;
}
fclose(fp);

return true;
}
10 changes: 9 additions & 1 deletion src/Arduino_Portenta_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <LittleFileSystem.h>
#include <Arduino_DebugUtils.h>

#include "WiFi.h" /* WiFi from ArduinoCore-mbed */
#include <SocketHelpers.h>

/******************************************************************************
* DEFINE
******************************************************************************/
Expand Down Expand Up @@ -81,6 +84,8 @@ class Arduino_Portenta_OTA
OtaHeaderLength = -5,
OtaHeaderCrc = -6,
OtaHeaterMagicNumber = -7,
CaStorageInit = -8,
CaStorageOpen = -9,
};

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

virtual bool init() = 0;
virtual bool open() = 0;
Expand All @@ -115,6 +121,8 @@ class Arduino_Portenta_OTA
private:

void write();
bool caStorageInit();
bool caStorageOpen();
ArduinoPortentaOtaWatchdogResetFuncPointer _feed_watchdog_func = 0;

};
Expand Down
7 changes: 0 additions & 7 deletions src/Arduino_Portenta_OTA_QSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ Arduino_Portenta_OTA_QSPI::Arduino_Portenta_OTA_QSPI(StorageTypePortenta const s

bool Arduino_Portenta_OTA_QSPI::init()
{
_bd_raw_qspi = mbed::BlockDevice::get_default_instance();
if (_bd_raw_qspi->init() != QSPIF_BD_ERROR_OK) {
Debug.print(DBG_ERROR, F("Error: QSPI init failure."));
return false;
}

if(_storage_type == QSPI_FLASH_FATFS)
{
_fs_qspi = new mbed::FATFileSystem("fs");
Expand All @@ -75,7 +69,6 @@ bool Arduino_Portenta_OTA_QSPI::init()
}
return true;
}

return false;
}

Expand Down
1 change: 0 additions & 1 deletion src/Arduino_Portenta_OTA_QSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Arduino_Portenta_OTA_QSPI : public Arduino_Portenta_OTA

private:

mbed::BlockDevice * _bd_raw_qspi;
mbed::BlockDevice * _bd_qspi;
mbed::FATFileSystem * _fs_qspi;
};
Expand Down
5 changes: 2 additions & 3 deletions src/decompress/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "lzss.h"

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

/**************************************************************************************
Expand Down Expand Up @@ -90,9 +89,9 @@ uint32_t crc_update(uint32_t crc, const void * data, size_t data_len)
MAIN
**************************************************************************************/

int Arduino_Portenta_OTA::download(const char * url, bool const is_https)
int Arduino_Portenta_OTA::download(const char * url, bool const is_https, MbedSocketClass * socket)
{
return WiFi.download((char *)url, UPDATE_FILE_NAME_LZSS, is_https);
return socket->download((char *)url, UPDATE_FILE_NAME_LZSS, is_https);
}

int Arduino_Portenta_OTA::decompress()
Expand Down