Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3eaef42
dist/tools: Add firmware metadata generator
kYc0o Nov 30, 2016
964b3e6
cpu/stm32f1/include: add cpu defines for FW slots
kYc0o Jan 20, 2017
0d7a131
cortexm_common: add internal flash slots management
kYc0o Apr 7, 2017
1239d09
sys: Add fw_slots module
kYc0o Nov 30, 2016
c56975f
Makefile.dep: add dependencies for fw_slots
kYc0o Jan 23, 2017
9ec007e
bootlaoder: add RIOT bootloader
kYc0o Oct 24, 2016
a6a3e0e
cpu/stm32f1/ldscripts: add bootloader and slots linker scripts
kYc0o Oct 24, 2016
9a27a8e
Makefile.include: add FW slots and Bootlaoder specific rules
kYc0o Oct 24, 2016
8ff9aa9
makefiles/arch/cortexm.inc.mk: add rules for linking FW slots
kYc0o Oct 24, 2016
ca605a2
cpu/stm32f1: add flash_slots feature
kYc0o Jan 25, 2017
15d2930
cpu/stm32f1: add specific platform defines for FW_SLOT
kYc0o Apr 11, 2017
fcf99f2
Makefile.dep: add tweetnacl dependency
kYc0o May 4, 2017
bd78334
Makefile.include: add key path
kYc0o May 4, 2017
8ab5c7b
bootloader: simplify and add signature validation
kYc0o May 4, 2017
b8e8b2e
bootloader: No interactive bootloader by default, increase stack
kYc0o May 4, 2017
1ff0239
firmware_metadata: sign hash with tweetnacl ed25519
kYc0o May 4, 2017
eeb4750
firmware_metadata: provide ed25519 example key
kYc0o May 4, 2017
99ce5f7
firmware_metadata: add tweetnacl package
kYc0o May 4, 2017
6be617b
firmware_metadata: add tweetnacl package
kYc0o May 4, 2017
06711d4
crypto: add ed25519 public key example
kYc0o May 4, 2017
daf5bec
fw_slots: add firmware signature verification with tweetnacl
kYc0o May 4, 2017
e560374
examples: add OTA programming example using tftp
kYc0o Mar 28, 2017
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
7 changes: 7 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,13 @@ USEPKG += nanocoap
USEMODULE += gnrc_sock_udp
endif

ifneq (,$(filter fw_slots,$(USEMODULE)))
USEPKG += tweetnacl
USEMODULE += hashes
FEATURES_REQUIRED += periph_flashpage
FEATURES_REQUIRED += flash_slots
endif

# include package dependencies
-include $(USEPKG:%=$(RIOTPKG)/%/Makefile.dep)

Expand Down
55 changes: 55 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ RIOTMAKE ?= $(RIOTBASE)/makefiles
RIOTPKG ?= $(RIOTBASE)/pkg
RIOTPROJECT ?= $(shell git rev-parse --show-toplevel 2>/dev/null || pwd)
GITCACHE ?= $(RIOTBASE)/dist/tools/git/git-cache
FW_METADATA ?= $(RIOTBASE)/dist/tools/firmware_metadata
APPDIR ?= $(CURDIR)
BINDIRBASE ?= $(APPDIR)/bin
ifdef FW_SLOT
BINDIR ?= $(BINDIRBASE)/$(BOARD)/slot$(FW_SLOT)
else
BINDIR ?= $(BINDIRBASE)/$(BOARD)
endif
PKGDIRBASE ?= $(BINDIRBASE)/pkg/$(BOARD)

__DIRECTORY_VARIABLES := \
Expand All @@ -41,6 +46,7 @@ override RIOTMAKE := $(abspath $(RIOTMAKE))
override RIOTPKG := $(abspath $(RIOTPKG))
override RIOTPROJECT := $(abspath $(RIOTPROJECT))
override GITCACHE := $(abspath $(GITCACHE))
override FW_METADATA := $(abspath $(FW_METADATA))
override APPDIR := $(abspath $(APPDIR))
override BINDIRBASE := $(abspath $(BINDIRBASE))
override BINDIR := $(abspath $(BINDIR))
Expand Down Expand Up @@ -274,12 +280,14 @@ endif
# the binaries to link
BASELIBS += $(BINDIR)/${APPLICATION}.a
BASELIBS += $(APPDEPS)
BASELIBS += $(SINGLE_SLOT)

.PHONY: all clean flash term doc debug debug-server reset objdump help info-modules
.PHONY: ..in-docker-container

ELFFILE ?= $(BINDIR)/$(APPLICATION).elf
HEXFILE ?= $(ELFFILE:.elf=.hex)
BINFILE ?= $(ELFFILE:.elf=.bin)

# variables used to compile and link c++
CPPMIX ?= $(if $(wildcard *.cpp),1,)
Expand All @@ -289,6 +297,17 @@ LINKFLAGPREFIX ?= -Wl,

DIRS += $(EXTERNAL_MODULE_DIRS)

# needed for bootloader...
ifdef FW_SLOT
TMPBIN = $(ELFFILE:.elf=.bin)
SLOTFILE = $(ELFFILE:.elf=slot$(FW_SLOT).o)
METADATA_FILE = $(BINDIR)/$(APPLICATION)-metadata-$(APPID)-$(VERSION).bin
FW_BINFILE = $(BINDIR)/$(APPLICATION)-slot$(FW_SLOT)-$(APPID)-$(VERSION).bin
FW_OBJFILE = $(BINDIR)/$(APPLICATION)-slot$(FW_SLOT)-$(APPID)-$(VERSION).o
BOOTLOADER_FILE = $(abspath $(BINDIR)/bootloader-$(APPLICATION).elf)
HEXFILE = $(BOOTLOADER_FILE:.elf=.hex)
endif #FW_SLOT

ifeq ($(BUILD_IN_DOCKER),1)
all: ..in-docker-container
else
Expand All @@ -303,9 +322,38 @@ else
endif
$(Q)$(SIZE) $(ELFFILE)
$(Q)$(OBJCOPY) $(OFLAGS) $(ELFFILE) $(HEXFILE)
$(Q)$(OBJCOPY) -O binary $(ELFFILE) $(BINFILE)
endif
endif # BUILD_IN_DOCKER


ifdef FW_SLOT
SECKEY = $(FW_METADATA)/key_ed25519.sec

firmware-slot: $(FW_OBJFILE)
$(FW_OBJFILE): all generate-metadata
$(Q)$(OBJCOPY) -O binary $(ELFFILE) $(TMPBIN)
$(Q)$(FW_METADATA)/bin/generate-metadata $(TMPBIN) $(VERSION) $(APPID) $(SECKEY) $(METADATA_FILE)
$(Q)srec_cat $(TMPBIN) -binary -offset $(FW_METADATA_SPACE) $(METADATA_FILE) -binary -o $(FW_BINFILE) -binary
$(Q)$(FW_METADATA)/bin/generate-metadata $(FW_BINFILE) $(VERSION) $(APPID) $(SECKEY) $(METADATA_FILE) --with-metadata
$(Q)srec_cat $(TMPBIN) -binary -offset $(FW_METADATA_SPACE) $(METADATA_FILE) -binary -o $(FW_BINFILE) -binary
$(Q)$(OBJCOPY) --output-target elf32-littlearm --binary-architecture=arm \
--change-section-vma .data=$(OFFSET_SLOT_$(FW_SLOT))\
--change-section-lma .data=$(OFFSET_SLOT_$(FW_SLOT))\
--rename-section .data=.slot.$(FW_SLOT).text \
--input-target binary $(FW_BINFILE) \
$(FW_OBJFILE)

bootloader: $(FW_OBJFILE)
$(Q)env -i ELFFILE=$(BOOTLOADER_FILE) PATH=$(PATH) \
make BOARD=$(BOARD) SINGLE_SLOT=$(FW_OBJFILE) -C $(RIOTBASE)/bootloader all

generate-metadata: $(FW_METADATA)/bin/generate-metadata

$(FW_METADATA)/bin/generate-metadata:
$(Q)env -i FW_METADATA_SPACE=$(FW_METADATA_SPACE) make -C $(FW_METADATA)
endif # FW_SLOT

..compiler-check:
@command -v $(CC) >/dev/null 2>&1 || \
{ $(COLOR_ECHO) \
Expand All @@ -314,6 +362,13 @@ endif # BUILD_IN_DOCKER

..build-message:
@$(COLOR_ECHO) '${COLOR_GREEN}Building application "$(APPLICATION)" for "$(BOARD)" with MCU "$(MCU)".${COLOR_RESET}'

ifdef FW_SLOT
@$(COLOR_ECHO) '${COLOR_PURPLE}This is a build for FW slot $(FW_SLOT).${COLOR_RESET}'
endif
ifeq ($(BOOTLOADER),1)
@$(COLOR_ECHO) '${COLOR_PURPLE}This is a Bootloader build.${COLOR_RESET}'
endif
@$(COLOR_ECHO)

# add extra include paths for packages in $(USEMODULE)
Expand Down
41 changes: 41 additions & 0 deletions bootloader/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# name of your application
APPLICATION = bootloader

# If no BOARD is found in the environment, use this default:
BOARD ?= iotlab-m3

# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/..

# Comment this out to disable code in RIOT that does safety checking
# which is not needed in a production environment but helps in the
# development process:
#CFLAGS += -DDEVELHELP

# Enable the bootloader flag
BOOTLOADER = 1

# Activate interactive bootloader, if no specified
INTERACTIVE_BOOTLOADER ?= 0
CFLAGS += -DINTERACTIVE_BOOTLOADER=$(INTERACTIVE_BOOTLOADER)

# Import metadata space size, otherwise it will be defaulted to 0x100 by
# the code
CFLAGS += -DFW_METADATA_SPACE=$(FW_METADATA_SPACE)

# Increase stack memory for flashpage requirements
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(5*THREAD_STACKSIZE_DEFAULT\)

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1

# Use fw_slots module to manage images on ROM
USEMODULE += fw_slots

# Add also the shell, some shell commands
ifeq ($(INTERACTIVE_BOOTLOADER),1)
USEMODULE += shell
USEMODULE += shell_commands
endif

include $(RIOTBASE)/Makefile.include
1 change: 1 addition & 0 deletions bootloader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
Loading