8000 Differential Firmware Update Support (#169) · pycom/pycom-micropython-sigfox@8b00592 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 8b00592

Browse files
authored
Differential Firmware Update Support (#169)
Added the support to perform Differential Firmware Update.
1 parent 1fe9e43 commit 8b00592

19 files changed

+5860
-20
lines changed

esp32/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ MOD_SIGFOX_ENABLED ?= 1
3838
# Pybytes disabled by default
3939
PYBYTES_ENABLED ?= 0
4040

41+
# Flag to enable/disable Delta Update Feature. Disabled by default
42+
DIFF_UPDATE_ENABLED ?= 0
43+
4144
# by default make a BASE firmware with features as specified with defaults above
4245
# valid choices for VARIANT are: BASE, PYBYTES, PYGATE
4346
VARIANT ?=BASE
@@ -140,6 +143,11 @@ ifeq ($(MOD_COAP_ENABLED), 1)
140143
CFLAGS += -DMOD_COAP_ENABLED
141144
endif
142145

146+
ifeq ($(DIFF_UPDATE_ENABLED), 1)
147+
$(info Differential Update Enabled)
148+
CFLAGS += -DDIFF_UPDATE_ENABLED -DBZ_NO_STDIO
149+
endif
150+
143151
ifeq ($(MOD_SIGFOX_ENABLED), 1)
144152
$(info SIGFOX Module Enabled)
145153

esp32/application.mk

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,29 @@ APP_MODS_SRC_C = $(addprefix mods/,\
183183
modmdns.c \
184184
)
185185
ifeq ($(MOD_COAP_ENABLED), 1)
186+
APP_INC += -Ibsdiff
186187
APP_MODS_SRC_C += $(addprefix mods/,\
187188
modcoap.c \
188189
)
189190
endif
190191

192+
ifeq ($(DIFF_UPDATE_ENABLED), 1)
193+
APP_INC += -Ibzlib/
194+
APP_MODS_SRC_C += $(addprefix bsdiff/,\
195+
bspatch.c \
196+
)
197+
APP_MODS_SRC_C += $(addprefix bzlib/,\
198+
blocksort.c \
199+
huffman.c \
200+
crctable.c \
201+
randtable.c \
202+
compress.c \
203+
decompress.c \
204+
bzlib.c \
205+
bzlib_ext.c \
206+
)
207+
endif
208+
191209
APP_MODS_LORA_SRC_C = $(addprefix mods/,\
192210
modlora.c \
193211
)

esp32/bootloader/bootloader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct _boot_info_t
5656

5757
#define IMG_STATUS_CHECK 0
5858
#define IMG_STATUS_READY 1
59+
#define IMG_STATUS_PATCH 2
5960

6061
#define IMG_ACT_FACTORY 0
6162
#define IMG_ACT_UPDATE1 1

esp32/bsdiff/bsdiff_api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef __BSDIFF_API__
2+
3+
#define __BSDIFF_API__
4+
5+
off_t offtin(u_char *buf);
6+
7+
#endif

esp32/bsdiff/bspatch.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-
2+
* Copyright 2003-2005 Colin Percival
3+
* All rights reserved
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted providing that the following conditions
7+
* are met:
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
* POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
#if 0
28+
__FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:06 cperciva Exp $");
29+
#endif
30+
31+
#include <bzlib.h>
32+
33+
int offtin(unsigned char *buf)
34+
{
35+
int y;
36+
37+
y=buf[7]&0x7F;
38+
y=y*256;y+=buf[6];
39+
y=y*256;y+=buf[5];
40+
y=y*256;y+=buf[4];
41+
y=y*256;y+=buf[3];
42+
y=y*256;y+=buf[2];
43+
y=y*256;y+=buf[1];
44+
y=y*256;y+=buf[0];
45+
46+
if(buf[7]&0x80) y=-y;
47+
48+
return y;
49+
}

0 commit comments

Comments
 (0)
0