Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 807f450

Browse filesBrowse files
committed
Rewriting SSUBoot to allow decompression of LZSS compressed binary files while updating the flash
1 parent 1dfca16 commit 807f450
Copy full SHA for 807f450

File tree

5 files changed

+2537
-2385
lines changed
Filter options

5 files changed

+2537
-2385
lines changed

‎libraries/SSU/extras/SSUBoot/SSUBoot.ino

Copy file name to clipboardExpand all lines: libraries/SSU/extras/SSUBoot/SSUBoot.ino
+54-24Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <FlashStorage.h>
2424
#include <MKRGSM.h>
2525

26+
#include "lzss.h"
2627

2728
/**************************************************************************************
2829
DEFINE
@@ -37,17 +38,16 @@
3738
GLOBAL CONSTANTS
3839
**************************************************************************************/
3940

40-
static constexpr char UPDATE_FILE_NAME[] = "UPDATE.BIN";
41-
static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK";
42-
41+
const char * UPDATE_FILE_NAME = "UPDATE.BIN";
42+
const char * UPDATE_FILE_NAME_LZSS = "UPDATE.BIN.LZSS";
43+
static const char * CHECK_FILE_NAME = "UPDATE.OK";
4344

4445
/**************************************************************************************
4546
GLOBAL VARIABLES
4647
**************************************************************************************/
4748

4849
FlashClass mcu_flash;
49-
50-
GSMFileUtils fileUtils;
50+
GSMFileUtils fileUtils;
5151

5252
/**************************************************************************************
5353
FUNCTION DECLARATION
@@ -75,29 +75,59 @@ int main()
7575

7676
// Try to update only if update file
7777
// has been download successfully.
78-
if (fileUtils.listFile(CHECK_FILE_NAME) == 1) {
79-
uint32_t size = fileUtils.listFile(UPDATE_FILE_NAME);
80-
size_t cycles = (size / blockSize) + 1;
81-
82-
if (size > SSU_SIZE) {
83-
size -= SSU_SIZE;
84-
85-
/* Erase the MCU flash */
86-
uint32_t flash_address = (uint32_t)SKETCH_START;
87-
mcu_flash.erase((void*)flash_address, size);
88-
89-
for (auto i = 0; i < cycles; i++) {
90-
uint8_t block[blockSize] { 0 };
91-
digitalWrite(LED_BUILTIN, LOW);
92-
uint32_t read = fileUtils.readBlock(UPDATE_FILE_NAME, (i * blockSize) + SSU_SIZE, blockSize, block);
93-
digitalWrite(LED_BUILTIN, HIGH);
94-
mcu_flash.write((void*)flash_address, block, read);
95-
flash_address += read;
96-
}
78+
if (fileUtils.listFile(CHECK_FILE_NAME) > 0)
79+
{
80+
/* This is for LZSS compressed binaries. */
81+
if (fileUtils.listFile(UPDATE_FILE_NAME_LZSS) > 0)
82+
{
83+
/* Erase the complete flash starting from the SSU forward
84+
* because we've got no possibility of knowing how large
85+
* the decompressed binary will finally be.
86+
*/
87+
mcu_flash.erase((void*)SKETCH_START, 0x40000 - (uint32_t)SKETCH_START);
88+
/* Initialize the lzss module with the data which
89+
* it requires.
90+
*/
91+
lzss_init((uint32_t)SKETCH_START);
92+
/* During the process of decoding UPDATE.BIN.LZSS
93+
* is decompressed and stored as UPDATE.BIN.
94+
*/
95+
lzss_decode();
96+
/* Write the data remaining in the write buffer to
97+
* the file.
98+
*/
99+
lzss_flush();
100+
/* Signal a successul update. */
97101
update_success = true;
98102
}
103+
/* This is for uncompressed binaries. */
104+
else if (fileUtils.listFile(UPDATE_FILE_NAME) > 0)
105+
{
106+
uint32_t size = fileUtils.listFile(UPDATE_FILE_NAME);
107+
size_t cycles = (size / blockSize) + 1;
108+
109+
if (size > SSU_SIZE) {
110+
size -= SSU_SIZE;
111+
112+
/* Erase the MCU flash */
113+
uint32_t flash_address = (uint32_t)SKETCH_START;
114+
mcu_flash.erase((void*)flash_address, size);
115+
116+
for (auto i = 0; i < cycles; i++) {
117+
uint8_t block[blockSize] { 0 };
118+
digitalWrite(LED_BUILTIN, LOW);
119+
uint32_t read = fileUtils.readBlock(UPDATE_FILE_NAME, (i * blockSize) + SSU_SIZE, blockSize, block);
120+
digitalWrite(LED_BUILTIN, HIGH);
121+
mcu_flash.write((void*)flash_address, block, read);
122+
flash_address += read;
123+
}
124+
update_success = true;
125+
}
126+
}
127+
/* Clean up in case of success */
99128
if (update_success) {
100129
fileUtils.deleteFile(UPDATE_FILE_NAME);
130+
fileUtils.deleteFile(UPDATE_FILE_NAME_LZSS);
101131
fileUtils.deleteFile(CHECK_FILE_NAME);
102132
}
103133
}

‎libraries/SSU/extras/SSUBoot/lzss.c

Copy file name to clipboardExpand all lines: libraries/SSU/extras/SSUBoot/lzss.c
-180Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.