Skip to content

Commit b13c9c1

Browse files
committed
Add SBU_LoadLZSS.ino sketch + support for LZSS encoding
1 parent 8755881 commit b13c9c1

File tree

7 files changed

+1303
-1035
lines changed

7 files changed

+1303
-1035
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <MKRNB.h>
2+
#include <SBU.h>
3+
#include <FlashStorage.h>
4+
5+
#include "lzss.h"
6+
7+
FlashClass mcu_flash;
8+
9+
static char const BINARY[] =
10+
{
11+
#include "Binary.h"
12+
};
13+
14+
static char const CHECK_FILE[] =
15+
{
16+
"OK"
17+
};
18+
19+
static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK";
20+
constexpr char UPDATE_FILE_NAME[] = "UPDATE.BIN.LZSS";
21+
22+
NBFileUtils fileUtils;
23+
bool update_available = false;
24+
25+
void setup() {
26+
Serial.begin(9600);
27+
while (!Serial) { }
28+
29+
unsigned long const start = millis();
30+
for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { };
31+
32+
Serial.print("Accessing SARA Filesystem... ");
33+
if (!fileUtils.begin(false)) {
34+
Serial.println("failed.");
35+
return;
36+
37+
}
38+
Serial.println("OK");
39+
40+
uint32_t bytes_to_write = sizeof(BINARY);
41+
Serial.print("Size of BINARY.H: ");
42+
Serial.println(bytes_to_write);
43+
44+
Serial.print("Encoding \"BINARY.H\" into \"UPDATE.BIN.LZSS\" and writing it into the Sara-R410M module ... ");
45+
46+
/*
47+
* Set the lzss parameter in the following way:
48+
* - 0, false : you want to perform a LZSS encoding (.H -> .LZSS)
49+
* - SKETCH_START, true: you want to perform a LZSS decoding (.LZSS -> .H)
50+
*/
51+
lzss_init(0, false);
52+
53+
//Encode into .lzss and write to the Sara modem
54+
int bytes_written = lzss_encode(BINARY, bytes_to_write);
55+
56+
if (bytes_written == 0) {
57+
Serial.println("something went wrong!");
58+
} else {
59+
Serial.println("OK!");
60+
}
61+
62+
Serial.print("Size of UPDATE.BIN.LZSS: ");
63+
Serial.println(bytes_written);
64+
65+
auto status = 0;
66+
while (status != 2) {
67+
status = fileUtils.createFile(CHECK_FILE_NAME, CHECK_FILE, 2);
68+
delay(100);
69+
}
70+
71+
Serial.println("Please type \"restart\" to apply the update");
72+
update_available = true;
73+
}
74+
75+
76+
void loop() {
77+
if (update_available == true) {
78+
String command = Serial.readStringUntil('\n');
79+
if (command.indexOf("restart") >= 0) {
80+
NVIC_SystemReset();
81+
}
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../extras/SBUBoot/lzss.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../extras/SBUBoot/lzss.h

libraries/SBU/extras/SBUBoot/SBUBoot.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ int main()
5252
// Try to update only if update file
5353
// has been download successfully.
5454

55-
if (fileUtils.existFile(CHECK_FILE_NAME))
55+
if (fileUtils.listFile(CHECK_FILE_NAME))
5656
{
5757
/*This is for LZSS compressed binaries. */
58-
if (fileUtils.existFile(UPDATE_FILE_NAME_LZSS))
58+
if (fileUtils.listFile(UPDATE_FILE_NAME_LZSS))
5959
{
60-
/* Erase the complete flash starting from the SSU forward
60+
/* Erase the complete flash starting from the SBU forward
6161
* because we've got no possibility of knowing how large
6262
* the decompressed binary will finally be.
6363
*/
6464
mcu_flash.erase((void*)SKETCH_START, 0x40000 - (uint32_t)SKETCH_START);
6565
/* Initialize the lzss module with the data which
6666
* it requires.
6767
*/
68-
lzss_init((uint32_t)SKETCH_START);
68+
lzss_init((uint32_t)SKETCH_START, true);
6969
/* During the process of decoding UPDATE.BIN.LZSS
7070
* is decompressed and stored as UPDATE.BIN.
7171
*/

libraries/SBU/extras/SBUBoot/lzss.cpp

-219
This file was deleted.

0 commit comments

Comments
 (0)