From fc79d8b8aeb7fa0d51dbb550c1d5be14bf091d0d Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 7 Jul 2020 09:34:16 +0200 Subject: [PATCH 1/7] Adding lzss encoder by Haruhiko Okumura available in the public domain --- extras/tools/lzss.c | 180 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 extras/tools/lzss.c diff --git a/extras/tools/lzss.c b/extras/tools/lzss.c new file mode 100644 index 000000000..58391f535 --- /dev/null +++ b/extras/tools/lzss.c @@ -0,0 +1,180 @@ +/* LZSS encoder-decoder (Haruhiko Okumura; public domain) */ + +#include +#include + +#define EI 11 /* typically 10..13 */ +#define EJ 4 /* typically 4..5 */ +#define P 1 /* If match length <= P then output one character */ +#define N (1 << EI) /* buffer size */ +#define F ((1 << EJ) + 1) /* lookahead buffer size */ + +int bit_buffer = 0, bit_mask = 128; +unsigned long codecount = 0, textcount = 0; +unsigned char buffer[N * 2]; +FILE *infile, *outfile; + +void error(void) +{ + printf("Output error\n"); exit(1); +} + +void putbit1(void) +{ + bit_buffer |= bit_mask; + if ((bit_mask >>= 1) == 0) { + if (fputc(bit_buffer, outfile) == EOF) error(); + bit_buffer = 0; bit_mask = 128; codecount++; + } +} + +void putbit0(void) +{ + if ((bit_mask >>= 1) == 0) { + if (fputc(bit_buffer, outfile) == EOF) error(); + bit_buffer = 0; bit_mask = 128; codecount++; + } +} + +void flush_bit_buffer(void) +{ + if (bit_mask != 128) { + if (fputc(bit_buffer, outfile) == EOF) error(); + codecount++; + } +} + +void output1(int c) +{ + int mask; + + putbit1(); + mask = 256; + while (mask >>= 1) { + if (c & mask) putbit1(); + else putbit0(); + } +} + +void output2(int x, int y) +{ + int mask; + + putbit0(); + mask = N; + while (mask >>= 1) { + if (x & mask) putbit1(); + else putbit0(); + } + mask = (1 << EJ); + while (mask >>= 1) { + if (y & mask) putbit1(); + else putbit0(); + } +} + +void encode(void) +{ + int i, j, f1, x, y, r, s, bufferend, c; + + for (i = 0; i < N - F; i++) buffer[i] = ' '; + for (i = N - F; i < N * 2; i++) { + if ((c = fgetc(infile)) == EOF) break; + buffer[i] = c; textcount++; + } + bufferend = i; r = N - F; s = 0; + while (r < bufferend) { + f1 = (F <= bufferend - r) ? F : bufferend - r; + x = 0; y = 1; c = buffer[r]; + for (i = r - 1; i >= s; i--) + if (buffer[i] == c) { + for (j = 1; j < f1; j++) + if (buffer[i + j] != buffer[r + j]) break; + if (j > y) { + x = i; y = j; + } + } + if (y <= P) { y = 1; output1(c); } + else output2(x & (N - 1), y - 2); + r += y; s += y; + if (r >= N * 2 - F) { + for (i = 0; i < N; i++) buffer[i] = buffer[i + N]; + bufferend -= N; r -= N; s -= N; + while (bufferend < N * 2) { + if ((c = fgetc(infile)) == EOF) break; + buffer[bufferend++] = c; textcount++; + } + } + } + flush_bit_buffer(); + printf("text: %ld bytes\n", textcount); + printf("code: %ld bytes (%ld%%)\n", + codecount, (codecount * 100) / textcount); +} + +int getbit(int n) /* get n bits */ +{ + int i, x; + static int buf, mask = 0; + + x = 0; + for (i = 0; i < n; i++) { + if (mask == 0) { + if ((buf = fgetc(infile)) == EOF) return EOF; + mask = 128; + } + x <<= 1; + if (buf & mask) x++; + mask >>= 1; + } + return x; +} + +void decode(void) +{ + int i, j, k, r, c; + + for (i = 0; i < N - F; i++) buffer[i] = ' '; + r = N - F; + while ((c = getbit(1)) != EOF) { + if (c) { + if ((c = getbit(8)) == EOF) break; + fputc(c, outfile); + buffer[r++] = c; r &= (N - 1); + } else { + if ((i = getbit(EI)) == EOF) break; + if ((j = getbit(EJ)) == EOF) break; + for (k = 0; k <= j + 1; k++) { + c = buffer[(i + k) & (N - 1)]; + fputc(c, outfile); + buffer[r++] = c; r &= (N - 1); + } + } + } +} + +int main(int argc, char *argv[]) +{ + int enc; + char *s; + + if (argc != 4) { + printf("Usage: lzss e/d infile outfile\n\te = encode\td = decode\n"); + return 1; + } + s = argv[1]; + if (s[1] == 0 && (*s == 'd' || *s == 'D' || *s == 'e' || *s == 'E')) + enc = (*s == 'e' || *s == 'E'); + else { + printf("? %s\n", s); return 1; + } + if ((infile = fopen(argv[2], "rb")) == NULL) { + printf("? %s\n", argv[2]); return 1; + } + if ((outfile = fopen(argv[3], "wb")) == NULL) { + printf("? %s\n", argv[3]); return 1; + } + if (enc) encode(); else decode(); + fclose(infile); fclose(outfile); + return 0; +} From 236f7445c3ee8862011884d67d1ea4d6f943bfc4 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 9 Jul 2020 14:30:54 +0200 Subject: [PATCH 2/7] Ignoring the file extensions commonly stored in this folder, that is .bin, .ota and .json --- extras/tools/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 extras/tools/.gitignore diff --git a/extras/tools/.gitignore b/extras/tools/.gitignore new file mode 100644 index 000000000..c2f9380db --- /dev/null +++ b/extras/tools/.gitignore @@ -0,0 +1,4 @@ +*.bin +*.ota +*.json + From ddf15410bd7f053d0940bb8032ddc8a030dce094 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Thu, 9 Jul 2020 14:35:52 +0200 Subject: [PATCH 3/7] Extend README with better instructions for how to perform OTA via cloud server --- extras/tools/README.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/extras/tools/README.md b/extras/tools/README.md index 475fe41f3..795522e26 100644 --- a/extras/tools/README.md +++ b/extras/tools/README.md @@ -1,5 +1,18 @@ -`bin2ota.py` -============ +Firmware Over-The-Air Tools +=========================== + +## How-to-OTA + +Arduino IDE: `Sketch` -> `Export compiled Binary` +```bash +cp sketch.bin ~/Arduino/libraries/ArduinoIoTCloud/extras/tools/ +cd ~/Arduino/libraries/ArduinoIoTCloud/extras/tools +./bin2ota.py sketch.bin sketch.ota +./bin2json.py sketch.ota sketch.json +./ota-upload.sh CLIENT_ID CLIENT_SECRET DEVICE_ID sketch.json +``` + +## `bin2ota.py` This tool can be used to extend (actually prefix) a binary generated with e.g. the Arduino IDE with the required length and crc values required to perform an OTA (Over-The-Air) update of the firmware. ### How-To-Use @@ -25,8 +38,7 @@ This tool can be used to extend (actually prefix) a binary generated with e.g. t 0000030 0000 0000 7485 0000 0000 0000 0000 0000 ``` -`bin2json.py` -============= +## `bin2json.py` This tool converts the binary file into base64 encoded JSON which is necessary for feeding it to the server. ### How-To-Use @@ -34,8 +46,7 @@ This tool converts the binary file into base64 encoded JSON which is necessary f ./bin2json.py sketch.ota sketch.json ``` -`ota-upload.sh` -============== +## `ota-upload.sh` This tool allows to upload a OTA binary to a device via a Arduino cloud server. ### How-To-Use From d1abdfef34450cd075c4b0c19f2fc9fb18d462e2 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 13 Jul 2020 13:47:47 +0200 Subject: [PATCH 4/7] Converting lzss.c from to linux line endings via dos2unix and replacing main with functions for encoding/decoding to be called from a python script --- extras/tools/lzss.c | 366 ++++++++++++++++++++++---------------------- 1 file changed, 186 insertions(+), 180 deletions(-) diff --git a/extras/tools/lzss.c b/extras/tools/lzss.c index 58391f535..ac28cb01f 100644 --- a/extras/tools/lzss.c +++ b/extras/tools/lzss.c @@ -1,180 +1,186 @@ -/* LZSS encoder-decoder (Haruhiko Okumura; public domain) */ - -#include -#include - -#define EI 11 /* typically 10..13 */ -#define EJ 4 /* typically 4..5 */ -#define P 1 /* If match length <= P then output one character */ -#define N (1 << EI) /* buffer size */ -#define F ((1 << EJ) + 1) /* lookahead buffer size */ - -int bit_buffer = 0, bit_mask = 128; -unsigned long codecount = 0, textcount = 0; -unsigned char buffer[N * 2]; -FILE *infile, *outfile; - -void error(void) -{ - printf("Output error\n"); exit(1); -} - -void putbit1(void) -{ - bit_buffer |= bit_mask; - if ((bit_mask >>= 1) == 0) { - if (fputc(bit_buffer, outfile) == EOF) error(); - bit_buffer = 0; bit_mask = 128; codecount++; - } -} - -void putbit0(void) -{ - if ((bit_mask >>= 1) == 0) { - if (fputc(bit_buffer, outfile) == EOF) error(); - bit_buffer = 0; bit_mask = 128; codecount++; - } -} - -void flush_bit_buffer(void) -{ - if (bit_mask != 128) { - if (fputc(bit_buffer, outfile) == EOF) error(); - codecount++; - } -} - -void output1(int c) -{ - int mask; - - putbit1(); - mask = 256; - while (mask >>= 1) { - if (c & mask) putbit1(); - else putbit0(); - } -} - -void output2(int x, int y) -{ - int mask; - - putbit0(); - mask = N; - while (mask >>= 1) { - if (x & mask) putbit1(); - else putbit0(); - } - mask = (1 << EJ); - while (mask >>= 1) { - if (y & mask) putbit1(); - else putbit0(); - } -} - -void encode(void) -{ - int i, j, f1, x, y, r, s, bufferend, c; - - for (i = 0; i < N - F; i++) buffer[i] = ' '; - for (i = N - F; i < N * 2; i++) { - if ((c = fgetc(infile)) == EOF) break; - buffer[i] = c; textcount++; - } - bufferend = i; r = N - F; s = 0; - while (r < bufferend) { - f1 = (F <= bufferend - r) ? F : bufferend - r; - x = 0; y = 1; c = buffer[r]; - for (i = r - 1; i >= s; i--) - if (buffer[i] == c) { - for (j = 1; j < f1; j++) - if (buffer[i + j] != buffer[r + j]) break; - if (j > y) { - x = i; y = j; - } - } - if (y <= P) { y = 1; output1(c); } - else output2(x & (N - 1), y - 2); - r += y; s += y; - if (r >= N * 2 - F) { - for (i = 0; i < N; i++) buffer[i] = buffer[i + N]; - bufferend -= N; r -= N; s -= N; - while (bufferend < N * 2) { - if ((c = fgetc(infile)) == EOF) break; - buffer[bufferend++] = c; textcount++; - } - } - } - flush_bit_buffer(); - printf("text: %ld bytes\n", textcount); - printf("code: %ld bytes (%ld%%)\n", - codecount, (codecount * 100) / textcount); -} - -int getbit(int n) /* get n bits */ -{ - int i, x; - static int buf, mask = 0; - - x = 0; - for (i = 0; i < n; i++) { - if (mask == 0) { - if ((buf = fgetc(infile)) == EOF) return EOF; - mask = 128; - } - x <<= 1; - if (buf & mask) x++; - mask >>= 1; - } - return x; -} - -void decode(void) -{ - int i, j, k, r, c; - - for (i = 0; i < N - F; i++) buffer[i] = ' '; - r = N - F; - while ((c = getbit(1)) != EOF) { - if (c) { - if ((c = getbit(8)) == EOF) break; - fputc(c, outfile); - buffer[r++] = c; r &= (N - 1); - } else { - if ((i = getbit(EI)) == EOF) break; - if ((j = getbit(EJ)) == EOF) break; - for (k = 0; k <= j + 1; k++) { - c = buffer[(i + k) & (N - 1)]; - fputc(c, outfile); - buffer[r++] = c; r &= (N - 1); - } - } - } -} - -int main(int argc, char *argv[]) -{ - int enc; - char *s; - - if (argc != 4) { - printf("Usage: lzss e/d infile outfile\n\te = encode\td = decode\n"); - return 1; - } - s = argv[1]; - if (s[1] == 0 && (*s == 'd' || *s == 'D' || *s == 'e' || *s == 'E')) - enc = (*s == 'e' || *s == 'E'); - else { - printf("? %s\n", s); return 1; - } - if ((infile = fopen(argv[2], "rb")) == NULL) { - printf("? %s\n", argv[2]); return 1; - } - if ((outfile = fopen(argv[3], "wb")) == NULL) { - printf("? %s\n", argv[3]); return 1; - } - if (enc) encode(); else decode(); - fclose(infile); fclose(outfile); - return 0; -} +/* LZSS encoder-decoder (Haruhiko Okumura; public domain) */ + +#include +#include + +#define EI 11 /* typically 10..13 */ +#define EJ 4 /* typically 4..5 */ +#define P 1 /* If match length <= P then output one character */ +#define N (1 << EI) /* buffer size */ +#define F ((1 << EJ) + 1) /* lookahead buffer size */ + +int bit_buffer = 0, bit_mask = 128; +unsigned long codecount = 0, textcount = 0; +unsigned char buffer[N * 2]; +FILE *infile, *outfile; + +void error(void) +{ + printf("Output error\n"); exit(1); +} + +void putbit1(void) +{ + bit_buffer |= bit_mask; + if ((bit_mask >>= 1) == 0) { + if (fputc(bit_buffer, outfile) == EOF) error(); + bit_buffer = 0; bit_mask = 128; codecount++; + } +} + +void putbit0(void) +{ + if ((bit_mask >>= 1) == 0) { + if (fputc(bit_buffer, outfile) == EOF) error(); + bit_buffer = 0; bit_mask = 128; codecount++; + } +} + +void flush_bit_buffer(void) +{ + if (bit_mask != 128) { + if (fputc(bit_buffer, outfile) == EOF) error(); + codecount++; + } +} + +void output1(int c) +{ + int mask; + + putbit1(); + mask = 256; + while (mask >>= 1) { + if (c & mask) putbit1(); + else putbit0(); + } +} + +void output2(int x, int y) +{ + int mask; + + putbit0(); + mask = N; + while (mask >>= 1) { + if (x & mask) putbit1(); + else putbit0(); + } + mask = (1 << EJ); + while (mask >>= 1) { + if (y & mask) putbit1(); + else putbit0(); + } +} + +void encode(void) +{ + int i, j, f1, x, y, r, s, bufferend, c; + + for (i = 0; i < N - F; i++) buffer[i] = ' '; + for (i = N - F; i < N * 2; i++) { + if ((c = fgetc(infile)) == EOF) break; + buffer[i] = c; textcount++; + } + bufferend = i; r = N - F; s = 0; + while (r < bufferend) { + f1 = (F <= bufferend - r) ? F : bufferend - r; + x = 0; y = 1; c = buffer[r]; + for (i = r - 1; i >= s; i--) + if (buffer[i] == c) { + for (j = 1; j < f1; j++) + if (buffer[i + j] != buffer[r + j]) break; + if (j > y) { + x = i; y = j; + } + } + if (y <= P) { y = 1; output1(c); } + else output2(x & (N - 1), y - 2); + r += y; s += y; + if (r >= N * 2 - F) { + for (i = 0; i < N; i++) buffer[i] = buffer[i + N]; + bufferend -= N; r -= N; s -= N; + while (bufferend < N * 2) { + if ((c = fgetc(infile)) == EOF) break; + buffer[bufferend++] = c; textcount++; + } + } + } + flush_bit_buffer(); + printf("text: %ld bytes\n", textcount); + printf("code: %ld bytes (%ld%%)\n", + codecount, (codecount * 100) / textcount); +} + +int getbit(int n) /* get n bits */ +{ + int i, x; + static int buf, mask = 0; + + x = 0; + for (i = 0; i < n; i++) { + if (mask == 0) { + if ((buf = fgetc(infile)) == EOF) return EOF; + mask = 128; + } + x <<= 1; + if (buf & mask) x++; + mask >>= 1; + } + return x; +} + +void decode(void) +{ + int i, j, k, r, c; + + for (i = 0; i < N - F; i++) buffer[i] = ' '; + r = N - F; + while ((c = getbit(1)) != EOF) { + if (c) { + if ((c = getbit(8)) == EOF) break; + fputc(c, outfile); + buffer[r++] = c; r &= (N - 1); + } else { + if ((i = getbit(EI)) == EOF) break; + if ((j = getbit(EJ)) == EOF) break; + for (k = 0; k <= j + 1; k++) { + c = buffer[(i + k) & (N - 1)]; + fputc(c, outfile); + buffer[r++] = c; r &= (N - 1); + } + } + } +} + +int encode_file(char const * in, char const * out) +{ + infile = fopen(in, "rb"); + if (infile == NULL) return 0; + + outfile = fopen(out, "wb"); + if (outfile == NULL) return 0; + + encode(); + + fclose(infile); + fclose(outfile); + + return 0; +} + +int decode_file(char const * in, char const * out) +{ + infile = fopen(in, "rb"); + if (infile == NULL) return 0; + + outfile = fopen(out, "wb"); + if (outfile == NULL) return 0; + + decode(); + + fclose(infile); + fclose(outfile); + + return 0; +} From b35fcf1d429f23127b7322f414042649da1973d4 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 13 Jul 2020 13:48:21 +0200 Subject: [PATCH 5/7] Adding shared object built from lzss.c via cc -fPIC -shared -o lzss.so lzss.c --- extras/tools/lzss.so | Bin 0 -> 12984 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 extras/tools/lzss.so diff --git a/extras/tools/lzss.so b/extras/tools/lzss.so new file mode 100755 index 0000000000000000000000000000000000000000..dadd5d8942e477381d7edd035244f69ecefcbeab GIT binary patch literal 12984 zcmeHNe{@vUoxd|lBtS^Q?73&(o!pqlgxyqO)_zQ(0~Sm zqm?maO{I3z<5^43s%2Muj#iHcZ7o4sf?e8%ZP#+z)DsWr&TO(0&PJWpl-bYs-us=r zd6V>P|Jt+XaOb@F-tXsrzu)`4Ki|9WeIGQpY;-ytf>VyTO%V6ubcIyuf@7c48IUSb zA*SH}TCqUN=8YF+<#x_j5K|!x2~ZtZ;X1cavY>{{Fg@c`c=c>WS&v}Si)+2O)??bM zo5D0-tLK8!by}C(=?z+rDalf*elP5!{NlNi&7xri3#P1hC-lhA|7|MPg4=a{ll4ov z?iZ%IIkIhYU?T_DraNlHlg{7w-*SD+8+Wzc{-dJ5AN<;VPmP?SDrVv;z(r=J;5yICvD@)#=b@ucxgaJsF7lIbyB6%7DYW_T2CAhA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^)E>yD#Q9W+HjJkWTiZJRf+oVHx#Yb@3rVX-(p} literal 0 HcmV?d00001 From cd3f1dc759c352d12db3fd78cbb2453d75eeb693 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 13 Jul 2020 13:48:56 +0200 Subject: [PATCH 6/7] Adding python script lzss.py which allows to encode/decode binary files via LZSS --- extras/tools/lzss.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 extras/tools/lzss.py diff --git a/extras/tools/lzss.py b/extras/tools/lzss.py new file mode 100755 index 000000000..e134ad807 --- /dev/null +++ b/extras/tools/lzss.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +import sys +import ctypes + +LZSS_SO_FILE = "./lzss.so" + +if len(sys.argv) != 4: + print ("Usage: lzss.py --[encode|decode] sketch.bin sketch.lzss") + sys.exit() + +lzss_functions = ctypes.CDLL(LZSS_SO_FILE) + +mode = sys.argv[1] +ifile = sys.argv[2] +ofile = sys.argv[3] + +b_ifile = ifile.encode('utf-8') +b_ofile = ofile.encode('utf-8') + +if mode == "--encode": + lzss_functions.encode_file.argtypes = [ctypes.c_char_p, ctypes.c_char_p] + lzss_functions.encode_file(b_ifile, b_ofile) +elif mode == "--decode": + lzss_functions.decode_file.argtypes = [ctypes.c_char_p, ctypes.c_char_p] + lzss_functions.decode_file(b_ifile, b_ofile) +else: + print ("Error, invalid mode parameter, use --encode or --decode") From a7ee5007efbdf49992a4c51d8af1d12c57505de5 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 13 Jul 2020 13:51:39 +0200 Subject: [PATCH 7/7] Adding lzss.py to README and improvind documentation --- extras/tools/README.md | 13 +++++++++++++ extras/tools/lzss.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/extras/tools/README.md b/extras/tools/README.md index 795522e26..ac0a5d2e5 100644 --- a/extras/tools/README.md +++ b/extras/tools/README.md @@ -38,6 +38,19 @@ This tool can be used to extend (actually prefix) a binary generated with e.g. t 0000030 0000 0000 7485 0000 0000 0000 0000 0000 ``` +## `lzss.py` +This tool allows to compress a binary file using the LZSS algorithm. + +### How-To-Use +* Encoding (Compressing) +```bash +./lzss.py --encode sketch.bin sketch.lzss +``` +* Decoding (Extracting) +```bash +./lzss.py --decode sketch.lzss sketch.bin +``` + ## `bin2json.py` This tool converts the binary file into base64 encoded JSON which is necessary for feeding it to the server. diff --git a/extras/tools/lzss.py b/extras/tools/lzss.py index e134ad807..b37aa4f96 100755 --- a/extras/tools/lzss.py +++ b/extras/tools/lzss.py @@ -6,7 +6,7 @@ LZSS_SO_FILE = "./lzss.so" if len(sys.argv) != 4: - print ("Usage: lzss.py --[encode|decode] sketch.bin sketch.lzss") + print ("Usage: lzss.py --[encode|decode] infile outfile") sys.exit() lzss_functions = ctypes.CDLL(LZSS_SO_FILE)