Skip to content
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

[WIP] [TF:OTA] OTA updates common work branch #9969

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f8fa196
REWORD ME riotboot: introduce riot-based minimal bootloader
kaspar030 Jun 15, 2017
37ff3d0
makefiles/riotboot: generate separate .signed.bin file
cladmi Jun 5, 2018
219701e
makefiles/riotboot: allow generating a combined binary
cladmi Jun 6, 2018
7c46949
EDIT/REWORD ME sys/firmware: initial import of firmware management fu…
kaspar030 Jun 16, 2017
9726a30
dist/tools/firmware: initial import of firmware metadata tools
kaspar030 Jun 16, 2017
a5ba1eb
cpu/cortexm_common: set MSP instead of PSP in cpu_jump_to_image()
kaspar030 Oct 5, 2017
8a884be
cpu/cortexm_common: initial multislot support
kaspar030 Jun 15, 2017
78d2b65
sys/ota: introduce CoAP OTA module
kaspar030 Mar 14, 2018
b721c08
examples/ota: initial commit of OTA example
kaspar030 Mar 14, 2018
666fd8f
Split update into firmware_simple and firmware_flashwrite
bergzand Apr 24, 2018
7d59ee4
firmware: remove metadata_type from struct
bergzand May 2, 2018
eccb8fd
suit: Initial include of SUIT manifest parser
bergzand May 23, 2018
1c4dd2d
Add conditional support
bergzand May 29, 2018
2797b25
ota_suit: Initial work
bergzand May 29, 2018
810834b
TODO BACKPORT IN INITIAL COMMITS firmware: fix support for bigger fla…
cladmi Jun 6, 2018
4c157f3
getters for the uuids
bergzand May 29, 2018
87591d4
Add simple url extraction
bergzand May 29, 2018
bb14500
url parsing
bergzand May 29, 2018
2383c60
Update
bergzand Jun 5, 2018
7a0406e
gen_manifest: add raw option
bergzand Jun 5, 2018
0687386
suit_updater: generate the keys.h from firmware.pub.key
cladmi Jun 5, 2018
517db38
DEBUG COMMIT REMOVE ME suit_updater: add ps debug output
cladmi Jun 5, 2018
be89133
DEBUG COMMIT sys/firmware: HACK disable _update_time as it is not wor…
cladmi Jun 5, 2018
964d531
ota_suit: increase STACKSIZE as it overflowed
cladmi Jun 5, 2018
8a64c07
DEBUG COMMIT: suit_updater: add global ipv6 addresses print
cladmi Jun 6, 2018
49585a0
firmware: add some debug information for flashwrite_putbytes
cladmi Jun 6, 2018
efdb9e1
fixup! ota_suit: Initial work
kYc0o Sep 14, 2018
cb0bf41
fixup! examples/ota: initial commit of OTA example
kYc0o Sep 14, 2018
957c40e
fixup! ota_suit: Initial work
kYc0o Sep 14, 2018
922ce91
fixup! sys/ota: introduce CoAP OTA module
kYc0o Sep 14, 2018
da1747b
fixup! fixup! sys/ota: introduce CoAP OTA module
kYc0o Sep 14, 2018
4ef8e7e
fixup! makefiles/riotboot: generate separate .signed.bin file
kYc0o Sep 14, 2018
12af153
fixup! ota_suit: Initial work
kYc0o Sep 14, 2018
dfb5bbc
fixup! ota_suit: Initial work
kYc0o Sep 14, 2018
ca8afb4
squash! REWORD ME riotboot: introduce riot-based minimal bootloader
cladmi Sep 17, 2018
0772c54
Fix FIRMWARE_METADATA_SIZE typo in riotboot.mk
fedepell Sep 17, 2018
373366c
squash! makefiles/riotboot: generate separate .signed.bin file
cladmi Sep 19, 2018
fc6ff36
fixup! makefiles/riotboot: allow generating a combined binary
cladmi Sep 19, 2018
4405b86
squash! squash! makefiles/riotboot: generate separate .signed.bin file
cladmi Sep 19, 2018
7004953
examples/ota: tiny documentation fix
fedepell Sep 20, 2018
359ee2e
makefiles/riotboot.mk: enforce rule precedence (signed.bin before .bin)
fedepell Sep 20, 2018
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
Next Next commit
REWORD ME riotboot: introduce riot-based minimal bootloader
TODO Rebase message edit at the end.

 * updated to edbg/openocd new variables
 * Use RIOTBOOT_FW_SLOT_SIZE: upcomming PRs should remove
   RIOTBOOT_SLOT1_SIZE and RIOTBOOT_SLOT2_SIZE
 * Use ROM_START_ADDR for 'firmware' to handle iotlab-m3
 * Use ROM_OFFSET and FW_ROM_LEN
 * Info on non supported existing bootloader for the moment in dist/riotboot
 * dist/riotboot: allow running different targets and not only flash
 * RIOTBOOT_HDR_LEN as hexadecimal and can be overwritten
  • Loading branch information
kaspar030 authored and kYc0o committed Oct 30, 2018
commit f8fa1969bf009ada0ef8283034d6afa321abfbfe
13 changes: 13 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,19 @@ ifneq (,$(filter periph_gpio_irq,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio
endif

ifneq (,$(RIOTBOOT_SLOT0_SIZE))
FEATURES_PROVIDED += riotboot
endif

ifneq (,$(filter ota_%,$(USEMODULE)))
USEMODULE += ota
endif

ifneq (,$(filter ota_coap,$(USEMODULE)))
USEMODULE += firmware
USEMODULE += nanocoap
endif

# always select gpio (until explicit dependencies are sorted out)
FEATURES_OPTIONAL += periph_gpio

Expand Down
3 changes: 3 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ CFLAGS += -include '$(RIOTBUILD_CONFIG_HEADER_C)'
# include mcuboot support
include $(RIOTMAKE)/mcuboot.mk

# include riotboot support
include $(RIOTMAKE)/riotboot.mk

# include Murdock helpers
include $(RIOTMAKE)/murdock.inc.mk

Expand Down
16 changes: 16 additions & 0 deletions dist/riotboot/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
APPLICATION = riotboot

BOARD ?= samr21-xpro

USEMODULE += firmware

CFLAGS += -DNDEBUG -DLOG_LEVEL=LOG_NONE
DISABLE_MODULE += auto_init

RIOTBASE ?= $(CURDIR)/../..

include $(RIOTBASE)/Makefile.include

# limit bootloader size
# HACK: FIXME it does not work if there is an existing board bootlader
ROM_LEN := $(RIOTBOOT_SLOT0_SIZE)
6 changes: 6 additions & 0 deletions dist/riotboot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Overview

This folder contains a simple bootloader that allows ping-pong style
over-the-air updates.

Please see examples/ota as example.
61 changes: 61 additions & 0 deletions dist/riotboot/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
* Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup bootloader
* @{
*
* @file
* @brief RIOT Bootloader
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Francisco Acosta <francisco.acosta@inria.fr>
*
* @}
*/

#include "firmware.h"
#include "cpu.h"
#include "panic.h"

void kernel_init(void)
{
uint32_t version = 0;
uint32_t slot = 0;

/* skip slot 0 (which points to the bootloader) */
for (unsigned i = 1; i < firmware_num_slots; i++) {
firmware_metadata_t *slot_metadata = firmware_get_metadata(i);
if (firmware_validate_metadata_checksum(slot_metadata)) {
/* skip slot if metadata broken */
continue;
}
if (slot_metadata->start_addr != firmware_get_image_startaddr(i)) {
continue;
}
if (!slot || slot_metadata->version > version) {
version = slot_metadata->version;
slot = i;
}
}

if (slot) {
firmware_jump_to_slot(slot);
}

/* serious trouble! */
while (1) {}
}

NORETURN void core_panic(core_panic_t crash_code, const char *message)
{
(void)crash_code;
(void)message;
while (1) {}
}
89 changes: 89 additions & 0 deletions makefiles/riotboot.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
ifneq (,$(filter riotboot,$(FEATURES_USED)))

.PHONY: riotboot/flash riotboot/flash-bootloader riotboot/flash-slot1 riotboot/flash-slot2 \
riotboot/verify-image riotboot/bootloader/%

RIOTBOOT ?= $(RIOTBASE)/tools/riotboot/bin/$(BOARD)/riotboot.elf
CFLAGS += -I$(BINDIR)/riotbuild

RIOTBOOT_SECKEY ?= $(RIOTBASE)/dist/tools/firmware/sec.key
RIOTBOOT_PUBKEY ?= $(RIOTBASE)/dist/tools/firmware/pub.key

FIRMWARE_TOOL ?= $(RIOTBASE)/dist/tools/firmware/bin/firmware
RIOTBOOT_HDR_LEN ?= 0x100

APP_ID ?= 0
APP_VER ?= 0

$(BINDIR)/$(APPLICATION)-%.elf: link
$(Q)$(_LINK) -o $@

# slot 1 targets
SLOT1_OFFSET := $$(($(RIOTBOOT_SLOT0_SIZE) + $(RIOTBOOT_HDR_LEN)))
SLOT2_OFFSET := $$(($(RIOTBOOT_SLOT0_SIZE) + $(RIOTBOOT_FW_SLOT_SIZE) + $(RIOTBOOT_HDR_LEN)))

$(BINDIR)/$(APPLICATION)-slot%.elf: FW_ROM_LEN=$(RIOTBOOT_FW_SLOT_SIZE)
$(BINDIR)/$(APPLICATION)-slot1.elf: ROM_OFFSET=$(SLOT1_OFFSET)
$(BINDIR)/$(APPLICATION)-slot2.elf: ROM_OFFSET=$(SLOT2_OFFSET)

# signing targets
$(BINDIR)/$(APPLICATION)-%.bin:
@echo "creating $@..."
$(Q) $(OBJCOPY) -Obinary $< $@.tmp
$(Q) $(FIRMWARE_TOOL) sign $@.tmp $(APP_VER) $(APP_ID) $$(($(ROM_START_ADDR)+$(OFFSET))) $(RIOTBOOT_SECKEY) - > $@
$(Q) cat $@.tmp >> $@
$(Q) rm $@.tmp

$(BINDIR)/$(APPLICATION)-slot1.bin: OFFSET=$(SLOT1_OFFSET)
$(BINDIR)/$(APPLICATION)-slot1.bin: $(BINDIR)/$(APPLICATION)-slot1.elf

$(BINDIR)/$(APPLICATION)-slot2.bin: OFFSET=$(SLOT2_OFFSET)
$(BINDIR)/$(APPLICATION)-slot2.bin: $(BINDIR)/$(APPLICATION)-slot2.elf

# creating pubkey header file
$(RIOTBUILD_CONFIG_HEADER_C): $(BINDIR)/riotbuild/ota_pubkey.h
$(BINDIR)/riotbuild/ota_pubkey.h: $(RIOTBOOT_PUBKEY)
@mkdir -p $(@D)
@{ \
echo "static const unsigned char ota_public_key[] = {"; \
cat $< | xxd -i ; \
echo "};"; \
} > $@

riotboot: $(BINDIR)/$(APPLICATION)-slot1.bin $(BINDIR)/$(APPLICATION)-slot2.bin $(BINDIR)/riotbuild/ota_pubkey.h

riotboot/verify-image:
$(FIRMWARE_TOOL) verify $(BINDIR)/$(APPLICATION)-slot1.bin $(RIOTBOOT_PUBKEY)
$(FIRMWARE_TOOL) verify $(BINDIR)/$(APPLICATION)-slot2.bin $(RIOTBOOT_PUBKEY)

riotboot/flash-bootloader: riotboot/bootloader/flash
riotboot/bootloader/%:
$(Q)/usr/bin/env -i \
QUIET=$(QUIET)\
PATH=$(PATH) BOARD=$(BOARD) \
make --no-print-directory -C $(RIOTBASE)/dist/riotboot $*

riotboot/flash-slot1: IMAGE_OFFSET=$(RIOTBOOT_SLOT0_SIZE)
# edbg
riotboot/flash-slot1: HEXFILE=$(BINDIR)/$(APPLICATION)-slot1.bin
# openocd
riotboot/flash-slot1: IMAGE_FILE=$(BINDIR)/$(APPLICATION)-slot1.bin
riotboot/flash-slot1: $(BINDIR)/$(APPLICATION)-slot1.bin riotboot/flash-bootloader
$(FLASHER) $(FFLAGS)

riotboot/flash-slot2: IMAGE_OFFSET=$$(($(RIOTBOOT_SLOT0_SIZE) + $(RIOTBOOT_FW_SLOT_SIZE)))
# edbg
riotboot/flash-slot2: HEXFILE=$(BINDIR)/$(APPLICATION)-slot2.bin
# openocd
riotboot/flash-slot2: IMAGE_FILE=$(BINDIR)/$(APPLICATION)-slot2.bin
riotboot/flash-slot2: $(BINDIR)/$(APPLICATION)-slot2.bin riotboot/flash-bootloader
$(FLASHER) $(FFLAGS)

riotboot/flash: riotboot/flash-slot1

else
riotboot:
$(Q)echo "error: riotboot feature not selected! (try FEATURES_REQUIRED += riotboot)"
$(Q)false

endif # (,$(filter riotboot,$(FEATURES_USED)))