-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[WIP] Add ota_update module (second attempt) #7398
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
Changes from all commits
deb952e
3ec5b04
cefaf7e
7261285
40f60f7
1492095
c16a58f
71c4dac
cc023ba
3cf9626
fa89d61
f25d8c8
bbd9b59
fafd430
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| APPLICATION = bootloader | ||
| BOARD ?= samr21-xpro | ||
|
|
||
| USEMODULE += bootloader | ||
| USEMODULE += firmware | ||
|
|
||
| #CFLAGS += -DNDEBUG -DLOG_LEVEL=LOG_NONE | ||
| #DISABLE_MODULE += auto_init | ||
| CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(5*THREAD_STACKSIZE_DEFAULT\) | ||
| # This has to be the absolute path to the RIOT base directory: | ||
| RIOTBASE ?= $(CURDIR)/.. | ||
|
|
||
| include $(RIOTBASE)/Makefile.include |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * Copyright (C) 2017 Kaspar Schleiser | ||
| * 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 <string.h> | ||
| #include <stdio.h> | ||
|
|
||
| #include "firmware.h" | ||
|
|
||
|
|
||
| static int validate_and_boot(uint8_t slot) | ||
| { | ||
| if (firmware_validate_int_slot(slot) != -1) { | ||
| printf("[bootlaoder] slot %d validated! Booting...\n", slot); | ||
| firmware_jump_to_slot(slot); | ||
| } | ||
| else { | ||
| puts("[bootloader] no valid signature!"); | ||
| return -1; | ||
| } | ||
|
|
||
| /* Should not happen */ | ||
| return -1; | ||
| } | ||
|
|
||
| static int boot_img(void) | ||
| { | ||
| uint8_t boot_slot = 0; | ||
| uint32_t appid_slot1 = 0, appid_slot2 = 0; | ||
| firmware_metadata_t metadata; | ||
|
|
||
| puts("[bootlaoder] Checking for slots metadata..."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo 'bootloader' |
||
| memcpy(&metadata, firmware_get_metadata(1), sizeof(firmware_metadata_t)); | ||
| if (firmware_validate_metadata_checksum(&metadata) != -1) { | ||
| appid_slot1 = metadata.appid; | ||
| printf("[bootlaoder] Found slot 1 with APPID: 0x%lx \n", appid_slot1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo bootloader |
||
| } | ||
| else { | ||
| puts("[bootloader] Slot 1 not valid"); | ||
| } | ||
|
|
||
| memcpy(&metadata, firmware_get_metadata(2), sizeof(firmware_metadata_t)); | ||
| if (firmware_validate_metadata_checksum(&metadata) != -1) { | ||
| appid_slot2 = metadata.appid; | ||
| printf("[bootlaoder] Found slot 2 with APPID: 0x%lx \n", appid_slot2); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
| } | ||
| else { | ||
| puts("[bootloader] Slot 2 not valid"); | ||
| } | ||
|
|
||
| if ((appid_slot1 == 0) && (appid_slot2 == 0)) { | ||
| puts("[bootloader] No valid slot found!"); | ||
| return -1; | ||
| } | ||
| else { | ||
| if (appid_slot1 != appid_slot2) { | ||
| puts("[bootloader] Warning! application IDs are different!"); | ||
| puts("[bootloader] falling back to slot 1"); | ||
| if (validate_and_boot(1) == -1) { | ||
| puts("[bootloader] Booting failed!"); | ||
| } | ||
| else { | ||
| puts("[bootlaoder] Slot 1 inconsistent, no image to boot..."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
| return -1; | ||
| } | ||
| } | ||
| else { | ||
| puts("[bootloader] Looking for the newest image on ROM, listing..."); | ||
| boot_slot = firmware_find_newest_int_image(); | ||
|
|
||
| if (boot_slot > 0) { | ||
| printf("[bootloader] newest image found on slot %d, checking...\n", | ||
| boot_slot); | ||
| if (validate_and_boot(boot_slot) == -1) { | ||
| puts("[bootloader] Booting failed!"); | ||
| } | ||
| } | ||
| else { | ||
| (void) puts("No bootable slot found!\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (void) can be removed here |
||
| return -1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* Shouldn't happen */ | ||
| return 0; | ||
| } | ||
|
|
||
| int main(void) | ||
| { | ||
| return boot_img(); | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| RIOTBASE := ../../.. | ||
| RIOT_INCLUDE := $(RIOTBASE)/sys/include | ||
| SHA256_DIR := $(RIOTBASE)/sys/hashes | ||
| SHA256_INCLUDE := $(RIOT_INCLUDE)/hashes | ||
| TWEETNACL_DIR := tweetnacl | ||
| TWEETNACL_SRC := $(TWEETNACL_DIR)/tweetnacl.c randombytes.c | ||
| TWEETNACL_HDR := $(TWEETNACL_DIR)/tweetnacl.h | ||
| COMMON_SRC := common.c | ||
| COMMON_HDR := common.h | ||
|
|
||
| RIOT_FIRMWARE_SRC := \ | ||
| $(SHA256_DIR)/sha256.c \ | ||
| $(RIOTBASE)/sys/checksum/fletcher32.c \ | ||
| $(RIOTBASE)/sys/firmware/firmware.c | ||
|
|
||
| RIOT_FIRMWARE_HDR := $(RIOT_INCLUDE)/firmware.h \ | ||
| $(RIOT_INCLUDE)/hashes/sha256.h \ | ||
| $(RIOT_INCLUDE)/checksum/fletcher32.h | ||
|
|
||
| FIRMWARE_SRC := $(COMMON_SRC) $(TWEETNACL_SRC) $(RIOT_FIRMWARE_SRC) \ | ||
| firmware.c verify.c genkeys.c genmeta.c | ||
|
|
||
| FIRMWARE_HDR := $(COMMON_HDR) $(RIOT_FIRMWARE_HDR) | ||
|
|
||
| GITCACHE = ../git/git-cache | ||
| TWEETNACL_URL = https://github.com/RIOT-OS/tweetnacl.git | ||
| TWEETNACL_VERSION = 7ea05c7098a16c87fa66e9166ce301666f3f2623 | ||
|
|
||
| CFLAGS += -g -I. -O3 -Wall -Wextra -pedantic -std=c99 | ||
|
|
||
| all: bin/firmware | ||
|
|
||
| bin/: | ||
| mkdir -p bin | ||
|
|
||
| git-fetch-tweetnacl: | ||
| rm -Rf $(TWEETNACL_DIR) | ||
| mkdir -p $(TWEETNACL_DIR) | ||
| $(GITCACHE) clone "$(TWEETNACL_URL)" "$(TWEETNACL_VERSION)" "$(TWEETNACL_DIR)" | ||
| touch $@ | ||
|
|
||
| bin/firmware: git-fetch-tweetnacl $(FIRMWARE_HDR) $(FIRMWARE_SRC) Makefile | bin/ | ||
| $(CC) $(CFLAGS) -I$(RIOT_INCLUDE) -I$(TWEETNACL_DIR) $(FIRMWARE_SRC) -o $@ | ||
|
|
||
| clean: | ||
| rm -rf bin/firmware | ||
|
|
||
| distclean: | ||
| rm -rf $(TWEETNACL_DIR) | ||
| rm -f git-fetch-tweetnacl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo bootloader