Skip to content

Wdog feed during decompression process #10

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 7 commits into from
Jun 14, 2021
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
11 changes: 11 additions & 0 deletions src/Arduino_Portenta_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ void Arduino_Portenta_OTA::reset()
NVIC_SystemReset();
}

void Arduino_Portenta_OTA::setFeedWatchdogFunc(ArduinoPortentaOtaWatchdogResetFuncPointer func)
{
_feed_watchdog_func = func;
}

void Arduino_Portenta_OTA::feedWatchdog()
{
if (_feed_watchdog_func)
_feed_watchdog_func();
}

/******************************************************************************
* PROTECTED MEMBER FUNCTIONS
******************************************************************************/
Expand Down
7 changes: 7 additions & 0 deletions src/Arduino_Portenta_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#define APOTA_LITTLEFS_FLAG (1 << 6)
#define APOTA_MBR_FLAG (1 << 7)

#define ARDUINO_PORTENTA_OTA_HAS_WATCHDOG_FEED

/******************************************************************************
* TYPEDEF
******************************************************************************/
Expand All @@ -53,6 +55,8 @@ enum StorageTypePortenta {
SD_FATFS_MBR = APOTA_SDCARD_FLAG | APOTA_FATFS_FLAG | APOTA_MBR_FLAG,
};

typedef void(*ArduinoPortentaOtaWatchdogResetFuncPointer)(void);

/******************************************************************************
* CLASS DECLARATION
******************************************************************************/
Expand Down Expand Up @@ -87,6 +91,8 @@ class Arduino_Portenta_OTA
*/
int download(const char * url, bool const is_https);
int decompress();
void setFeedWatchdogFunc(ArduinoPortentaOtaWatchdogResetFuncPointer func);
void feedWatchdog();


protected:
Expand All @@ -103,6 +109,7 @@ class Arduino_Portenta_OTA
private:

void write();
ArduinoPortentaOtaWatchdogResetFuncPointer _feed_watchdog_func = 0;

};

Expand Down
7 changes: 6 additions & 1 deletion src/decompress/lzss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,27 @@ unsigned char buffer[N * 2];
static char write_buf[FPUTC_BUF_SIZE];
static size_t write_buf_num_bytes = 0;
static size_t bytes_written_fputc = 0;
static ArduinoPortentaOtaWatchdogResetFuncPointer wdog_feed_func = 0;

/**************************************************************************************
PUBLIC FUNCTIONS
**************************************************************************************/

void lzss_init(FILE * update_file_ptr, FILE * target_file_ptr, uint32_t const lzss_file_size)
void lzss_init(FILE * update_file_ptr, FILE * target_file_ptr, uint32_t const lzss_file_size, ArduinoPortentaOtaWatchdogResetFuncPointer wdog_feed_func_ptr)
{
update_file = update_file_ptr;
target_file = target_file_ptr;
LZSS_FILE_SIZE = lzss_file_size;
wdog_feed_func = wdog_feed_func_ptr;
}

void lzss_flush()
{
bytes_written_fputc += write_buf_num_bytes;

if (wdog_feed_func)
wdog_feed_func();

fwrite(write_buf, 1, write_buf_num_bytes, target_file);

write_buf_num_bytes = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/decompress/lzss.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

#include <Arduino.h>
#include <stdint.h>
#include "Arduino_Portenta_OTA.h"

/**************************************************************************************
FUNCTION DEFINITION
**************************************************************************************/

void lzss_init(FILE * update_file_ptr, FILE * target_file_ptr, uint32_t const lzss_file_size);
void lzss_init(FILE * update_file_ptr, FILE * target_file_ptr, uint32_t const lzss_file_size, ArduinoPortentaOtaWatchdogResetFuncPointer wdog_feed_func_ptr);
void lzss_decode();
void lzss_flush();

Expand Down
11 changes: 10 additions & 1 deletion src/decompress/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ int Arduino_Portenta_OTA::decompress()
uint32_t crc32, bytes_read;
uint8_t crc_buf[128];

feedWatchdog();

/* Read the OTA header ... */
fread(ota_header.buf, 1, sizeof(ota_header.buf), update_file);

Expand All @@ -147,6 +149,8 @@ int Arduino_Portenta_OTA::decompress()
return static_cast<int>(Error::OtaHeaderLength);
}

feedWatchdog();

/* ... and the CRC second ... rewind to start of CRC verified header ... */
fseek(update_file, sizeof(ota_header.header.len) + sizeof(ota_header.header.crc32), SEEK_SET);
/* ... initialize CRC ... */
Expand All @@ -161,6 +165,9 @@ int Arduino_Portenta_OTA::decompress()
}
fread(crc_buf, 1, ota_header.header.len - bytes_read, update_file);
crc32 = crc_update(crc32, crc_buf, ota_header.header.len - bytes_read);

feedWatchdog();

/* ... then finalise ... */
crc32 ^= 0xFFFFFFFF;
/* ... and compare. */
Expand All @@ -170,6 +177,8 @@ int Arduino_Portenta_OTA::decompress()
return static_cast<int>(Error::OtaHeaderCrc);
}

feedWatchdog();

if (ota_header.header.magic_number != 0x2341025b) /* 0x2341:025b = VID/PID Portenta H7 */
{
fclose(update_file);
Expand All @@ -184,7 +193,7 @@ int Arduino_Portenta_OTA::decompress()

FILE* decompressed = fopen(UPDATE_FILE_NAME, "w");

lzss_init(update_file, decompressed, LZSS_FILE_SIZE);
lzss_init(update_file, decompressed, LZSS_FILE_SIZE, _feed_watchdog_func);

/* During the process of decoding UPDATE.BIN.LZSS
* is decompressed and stored as UPDATE.BIN.
Expand Down