mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys: add riotboot_hdr submodule
riotboot_hdr enables to partition the internal flash memory into "slots", each one with a header providing information about the partition. The concept for now is limited to firmware partitions, which are recognised by the riotboot bootloader. In the future the concept might be extended to represent other content. Co-authored-by: Kaspar Schleiser <kaspar@schleiser.de>
This commit is contained in:
parent
ea219c3eba
commit
00adbd69f6
@ -791,6 +791,11 @@ ifneq (,$(filter uuid,$(USEMODULE)))
|
||||
USEMODULE += random
|
||||
endif
|
||||
|
||||
ifneq (,$(filter riotboot_hdr, $(USEMODULE)))
|
||||
USEMODULE += checksum
|
||||
USEMODULE += riotboot
|
||||
endif
|
||||
|
||||
# Enable periph_gpio when periph_gpio_irq is enabled
|
||||
ifneq (,$(filter periph_gpio_irq,$(USEMODULE)))
|
||||
FEATURES_REQUIRED += periph_gpio
|
||||
|
@ -54,6 +54,7 @@ PSEUDOMODULES += pktqueue
|
||||
PSEUDOMODULES += printf_float
|
||||
PSEUDOMODULES += prng
|
||||
PSEUDOMODULES += prng_%
|
||||
PSEUDOMODULES += riotboot_%
|
||||
PSEUDOMODULES += saul_adc
|
||||
PSEUDOMODULES += saul_default
|
||||
PSEUDOMODULES += saul_gpio
|
||||
|
@ -140,7 +140,6 @@ ifneq (,$(filter cord_ep,$(USEMODULE)))
|
||||
DIRS += net/application_layer/cord/ep
|
||||
endif
|
||||
|
||||
|
||||
DIRS += $(dir $(wildcard $(addsuffix /Makefile, $(USEMODULE))))
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
89
sys/include/riotboot/hdr.h
Normal file
89
sys/include/riotboot/hdr.h
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup sys_riotboot_hdr RIOT header helpers and tools
|
||||
* @ingroup sys
|
||||
* @{
|
||||
*
|
||||
* The header contains
|
||||
*
|
||||
* - "RIOT" as magic number
|
||||
* - the application version
|
||||
* - the address where the RIOT firmware is found
|
||||
* - the checksum of the three previous fields
|
||||
*
|
||||
* @file
|
||||
* @brief RIOT "partition" header and tools
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Francisco Acosta <francisco.acosta@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifndef RIOTBOOT_HDR_H
|
||||
#define RIOTBOOT_HDR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Magic number for riotboot_hdr
|
||||
*
|
||||
*/
|
||||
#define RIOTBOOT_MAGIC 0x544f4952 /* "RIOT" */
|
||||
|
||||
/**
|
||||
* @brief Structure to store image header - All members are little endian
|
||||
* @{
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t magic_number; /**< Header magic number (always "RIOT") */
|
||||
uint32_t version; /**< Integer representing the partition version */
|
||||
uint32_t start_addr; /**< Address after the allocated space for the header */
|
||||
uint32_t chksum; /**< Checksum of riotboot_hdr */
|
||||
} riotboot_hdr_t;
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Print formatted riotboot_hdr_t to STDIO
|
||||
*
|
||||
* @param[in] riotboot_hdr ptr to image header
|
||||
*
|
||||
*/
|
||||
void riotboot_hdr_print(const riotboot_hdr_t *riotboot_hdr);
|
||||
|
||||
/**
|
||||
* @brief Validate image header
|
||||
*
|
||||
* @param[in] riotboot_hdr ptr to image header
|
||||
*
|
||||
* @returns 0 if OK
|
||||
* @returns -1 if not OK
|
||||
*/
|
||||
int riotboot_hdr_validate(const riotboot_hdr_t *riotboot_hdr);
|
||||
|
||||
/**
|
||||
* @brief Calculate header checksum
|
||||
*
|
||||
* @param[in] riotboot_hdr ptr to image header
|
||||
*
|
||||
* @returns the checksum of the given riotboot_hdr
|
||||
*/
|
||||
uint32_t riotboot_hdr_checksum(const riotboot_hdr_t *riotboot_hdr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RIOTBOOT_HDR_H */
|
3
sys/riotboot/Makefile
Normal file
3
sys/riotboot/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
SUBMODULES := 1
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
68
sys/riotboot/hdr.c
Normal file
68
sys/riotboot/hdr.c
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 sys_riotboot_hdr
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief RIOT header helpers and tools
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Francisco Acosta <francisco.acosta@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef RIOT_VERSION
|
||||
#include "log.h"
|
||||
#else
|
||||
#define LOG_INFO(...) printf(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#include "riotboot/hdr.h"
|
||||
#include "checksum/fletcher32.h"
|
||||
#include "byteorder.h"
|
||||
|
||||
#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
|
||||
# error "This code is implementented in a way that it will only work for little-endian systems!"
|
||||
#endif
|
||||
|
||||
void riotboot_hdr_print(const riotboot_hdr_t *riotboot_hdr)
|
||||
{
|
||||
printf("Image magic_number: 0x%08x\n", (unsigned)riotboot_hdr->magic_number);
|
||||
printf("Image Version: 0x%08x\n", (unsigned)riotboot_hdr->version);
|
||||
printf("Image start address: 0x%08x\n", (unsigned)riotboot_hdr->start_addr);
|
||||
printf("Header chksum: 0x%08x\n", (unsigned)riotboot_hdr->chksum);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int riotboot_hdr_validate(const riotboot_hdr_t *riotboot_hdr)
|
||||
{
|
||||
if (riotboot_hdr->magic_number != RIOTBOOT_MAGIC) {
|
||||
LOG_INFO("%s: riotboot_hdr magic number invalid\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int res = riotboot_hdr_checksum(riotboot_hdr) == riotboot_hdr->chksum ? 0 : -1;
|
||||
if (res) {
|
||||
LOG_INFO("%s: riotboot_hdr checksum invalid\n", __func__);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
uint32_t riotboot_hdr_checksum(const riotboot_hdr_t *riotboot_hdr)
|
||||
{
|
||||
return fletcher32((uint16_t *)riotboot_hdr, offsetof(riotboot_hdr_t, chksum) / sizeof(uint16_t));
|
||||
}
|
Loading…
Reference in New Issue
Block a user