mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #15956 from fjmolinas/pr_riotboot_uncrustify
sys/riotboot: uncrustify
This commit is contained in:
commit
807b154fc4
2
dist/tools/uncrustify/whitelist.txt
vendored
2
dist/tools/uncrustify/whitelist.txt
vendored
@ -6,5 +6,7 @@ cpu/fe310/periph/.*\.c
|
||||
cpu/riscv_common/.*\.c
|
||||
cpu/riscv_common/include/.*\.h
|
||||
cpu/riscv_common/periph/.*\.c
|
||||
sys/riotboot/.*\.h
|
||||
sys/riotboot/.*\.c
|
||||
sys/ztimer/.*\.c
|
||||
sys/include/ztimer.*\.h
|
||||
|
@ -206,7 +206,7 @@ int riotboot_flashwrite_flush(riotboot_flashwrite_t *state);
|
||||
* @returns 0 on success, <0 otherwise
|
||||
*/
|
||||
int riotboot_flashwrite_finish_raw(riotboot_flashwrite_t *state,
|
||||
const uint8_t *bytes, size_t len);
|
||||
const uint8_t *bytes, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Finish a firmware update (riotboot version)
|
||||
|
@ -115,15 +115,15 @@ void riotboot_slot_dump_addrs(void);
|
||||
*/
|
||||
static inline size_t riotboot_slot_size(unsigned slot)
|
||||
{
|
||||
switch(slot) {
|
||||
case 0:
|
||||
return SLOT0_LEN;
|
||||
#if NUM_SLOTS==2
|
||||
case 1:
|
||||
return SLOT1_LEN;
|
||||
switch (slot) {
|
||||
case 0:
|
||||
return SLOT0_LEN;
|
||||
#if NUM_SLOTS == 2
|
||||
case 1:
|
||||
return SLOT1_LEN;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ extern const unsigned riotboot_slot_numof;
|
||||
/**
|
||||
* @brief Storage for header pointers of the configured slots
|
||||
*/
|
||||
extern const riotboot_hdr_t * const riotboot_slots[];
|
||||
extern const riotboot_hdr_t *const riotboot_slots[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ static inline size_t min(size_t a, size_t b)
|
||||
}
|
||||
|
||||
size_t riotboot_flashwrite_slotsize(
|
||||
const riotboot_flashwrite_t *state)
|
||||
const riotboot_flashwrite_t *state)
|
||||
{
|
||||
return riotboot_slot_size(state->target_slot);
|
||||
}
|
||||
|
||||
int riotboot_flashwrite_init_raw(riotboot_flashwrite_t *state, int target_slot,
|
||||
size_t offset)
|
||||
size_t offset)
|
||||
{
|
||||
#ifdef FLASHPAGE_SIZE
|
||||
assert(offset <= FLASHPAGE_SIZE);
|
||||
@ -50,7 +50,8 @@ int riotboot_flashwrite_init_raw(riotboot_flashwrite_t *state, int target_slot,
|
||||
static_assert(!(FLASHPAGE_SIZE % RIOTBOOT_FLASHPAGE_BUFFER_SIZE));
|
||||
#else
|
||||
/* The flashpage buffer must be a multiple of the write block size */
|
||||
static_assert(!(RIOTBOOT_FLASHPAGE_BUFFER_SIZE % FLASHPAGE_WRITE_BLOCK_SIZE));
|
||||
static_assert(!(RIOTBOOT_FLASHPAGE_BUFFER_SIZE %
|
||||
FLASHPAGE_WRITE_BLOCK_SIZE));
|
||||
#endif
|
||||
|
||||
|
||||
@ -61,7 +62,8 @@ int riotboot_flashwrite_init_raw(riotboot_flashwrite_t *state, int target_slot,
|
||||
|
||||
state->offset = offset;
|
||||
state->target_slot = target_slot;
|
||||
state->flashpage = flashpage_page((void *)riotboot_slot_get_hdr(target_slot));
|
||||
state->flashpage =
|
||||
flashpage_page((void *)riotboot_slot_get_hdr(target_slot));
|
||||
|
||||
if (CONFIG_RIOTBOOT_FLASHWRITE_RAW && offset) {
|
||||
/* Erase the first page only if the offset (!=0) specifies that there is
|
||||
@ -76,12 +78,13 @@ int riotboot_flashwrite_flush(riotboot_flashwrite_t *state)
|
||||
{
|
||||
if (CONFIG_RIOTBOOT_FLASHWRITE_RAW) {
|
||||
/* Check if there is leftover data in the buffer */
|
||||
size_t flashwrite_buffer_pos = state->offset % RIOTBOOT_FLASHPAGE_BUFFER_SIZE;
|
||||
size_t flashwrite_buffer_pos = state->offset %
|
||||
RIOTBOOT_FLASHPAGE_BUFFER_SIZE;
|
||||
if (flashwrite_buffer_pos == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t* slot_start =
|
||||
(uint8_t*)riotboot_slot_get_hdr(state->target_slot);
|
||||
uint8_t *slot_start =
|
||||
(uint8_t *)riotboot_slot_get_hdr(state->target_slot);
|
||||
/* Get the offset of the remaining chunk */
|
||||
size_t flashpage_pos = state->offset - flashwrite_buffer_pos;
|
||||
/* Write remaining chunk */
|
||||
@ -90,8 +93,10 @@ int riotboot_flashwrite_flush(riotboot_flashwrite_t *state)
|
||||
RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
|
||||
}
|
||||
else {
|
||||
if (flashpage_write_and_verify(state->flashpage, state->flashpage_buf) != FLASHPAGE_OK) {
|
||||
LOG_WARNING(LOG_PREFIX "error writing flashpage %u!\n", state->flashpage);
|
||||
if (flashpage_write_and_verify(state->flashpage,
|
||||
state->flashpage_buf) != FLASHPAGE_OK) {
|
||||
LOG_WARNING(LOG_PREFIX "error writing flashpage %u!\n",
|
||||
state->flashpage);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -101,29 +106,34 @@ int riotboot_flashwrite_flush(riotboot_flashwrite_t *state)
|
||||
int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state,
|
||||
const uint8_t *bytes, size_t len, bool more)
|
||||
{
|
||||
LOG_DEBUG(LOG_PREFIX "processing bytes %u-%u\n", state->offset, state->offset + len - 1);
|
||||
LOG_DEBUG(LOG_PREFIX "processing bytes %u-%u\n", state->offset,
|
||||
state->offset + len - 1);
|
||||
|
||||
while (len) {
|
||||
/* Position within the page, calculated from state->offset by
|
||||
* subtracting the start offset of the current page */
|
||||
size_t flashpage_pos = state->offset -
|
||||
(flashpage_addr(state->flashpage) - (void*)riotboot_slot_get_hdr(state->target_slot));
|
||||
size_t flashwrite_buffer_pos = state->offset % RIOTBOOT_FLASHPAGE_BUFFER_SIZE;
|
||||
size_t flashpage_avail = RIOTBOOT_FLASHPAGE_BUFFER_SIZE - flashwrite_buffer_pos;
|
||||
(flashpage_addr(state->flashpage) -
|
||||
(void *)riotboot_slot_get_hdr(
|
||||
state->target_slot));
|
||||
size_t flashwrite_buffer_pos = state->offset %
|
||||
RIOTBOOT_FLASHPAGE_BUFFER_SIZE;
|
||||
size_t flashpage_avail = RIOTBOOT_FLASHPAGE_BUFFER_SIZE -
|
||||
flashwrite_buffer_pos;
|
||||
|
||||
size_t to_copy = min(flashpage_avail, len);
|
||||
|
||||
if (CONFIG_RIOTBOOT_FLASHWRITE_RAW &&
|
||||
flashpage_pos == flashpage_size(state->flashpage)) {
|
||||
flashpage_pos == flashpage_size(state->flashpage)) {
|
||||
/* Erase the next page */
|
||||
state->flashpage++;
|
||||
flashpage_pos = 0;
|
||||
flashpage_erase(state->flashpage);
|
||||
}
|
||||
if (CONFIG_RIOTBOOT_FLASHWRITE_RAW &&
|
||||
flashwrite_buffer_pos == 0) {
|
||||
flashwrite_buffer_pos == 0) {
|
||||
memset(state->flashpage_buf, 0, RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
|
||||
};
|
||||
}
|
||||
|
||||
memcpy(state->flashpage_buf + flashwrite_buffer_pos, bytes, to_copy);
|
||||
flashpage_avail -= to_copy;
|
||||
@ -134,24 +144,25 @@ int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state,
|
||||
len -= to_copy;
|
||||
if ((!flashpage_avail) || (!more)) {
|
||||
#if CONFIG_RIOTBOOT_FLASHWRITE_RAW /* Guards access to state::firstblock_buf */
|
||||
void * addr = flashpage_addr(state->flashpage);
|
||||
void *addr = flashpage_addr(state->flashpage);
|
||||
if (addr == riotboot_slot_get_hdr(state->target_slot) &&
|
||||
state->offset == RIOTBOOT_FLASHPAGE_BUFFER_SIZE) {
|
||||
state->offset == RIOTBOOT_FLASHPAGE_BUFFER_SIZE) {
|
||||
/* Skip flashing the first block, store it for later to flash it
|
||||
* during the flashwrite_finish function */
|
||||
memcpy(state->firstblock_buf,
|
||||
state->flashpage_buf, RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
|
||||
}
|
||||
else {
|
||||
flashpage_write((uint8_t*)addr + flashpage_pos,
|
||||
state->flashpage_buf,
|
||||
RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
|
||||
flashpage_write((uint8_t *)addr + flashpage_pos,
|
||||
state->flashpage_buf,
|
||||
RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
|
||||
}
|
||||
#else
|
||||
int res = flashpage_write_and_verify(state->flashpage,
|
||||
state->flashpage_buf);
|
||||
if (res != FLASHPAGE_OK) {
|
||||
LOG_WARNING(LOG_PREFIX "error writing flashpage %u!\n", state->flashpage);
|
||||
LOG_WARNING(LOG_PREFIX "error writing flashpage %u!\n",
|
||||
state->flashpage);
|
||||
return -1;
|
||||
}
|
||||
state->flashpage++;
|
||||
@ -169,7 +180,9 @@ int riotboot_flashwrite_invalidate(int slot)
|
||||
return -1;
|
||||
}
|
||||
if (riotboot_slot_validate(1 - slot) != 0) {
|
||||
LOG_WARNING(LOG_PREFIX "abort, can not erase slot[%d], other slot[%d] is invalid\n",slot, 1 - slot);
|
||||
LOG_WARNING(
|
||||
LOG_PREFIX "abort, can not erase slot[%d], other slot[%d] is invalid\n", slot,
|
||||
1 - slot);
|
||||
return -2;
|
||||
}
|
||||
|
||||
@ -188,9 +201,10 @@ int riotboot_flashwrite_invalidate(int slot)
|
||||
int riotboot_flashwrite_invalidate_latest(void)
|
||||
{
|
||||
int _slot_to_revert;
|
||||
|
||||
_slot_to_revert = (riotboot_slot_get_hdr(riotboot_slot_other())->version
|
||||
> riotboot_slot_get_hdr(riotboot_slot_current())->version)
|
||||
? riotboot_slot_other() : riotboot_slot_current();
|
||||
> riotboot_slot_get_hdr(riotboot_slot_current())->version)
|
||||
? riotboot_slot_other() : riotboot_slot_current();
|
||||
return riotboot_flashwrite_invalidate(_slot_to_revert);
|
||||
}
|
||||
|
||||
@ -203,7 +217,8 @@ int riotboot_flashwrite_finish_raw(riotboot_flashwrite_t *state,
|
||||
|
||||
#if CONFIG_RIOTBOOT_FLASHWRITE_RAW
|
||||
memcpy(state->firstblock_buf, bytes, len);
|
||||
flashpage_write(slot_start, state->firstblock_buf, RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
|
||||
flashpage_write(slot_start, state->firstblock_buf,
|
||||
RIOTBOOT_FLASHPAGE_BUFFER_SIZE);
|
||||
#else
|
||||
uint8_t *firstpage;
|
||||
|
||||
|
@ -27,7 +27,8 @@
|
||||
#include "log.h"
|
||||
#include "riotboot/slot.h"
|
||||
|
||||
int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest, size_t img_len, int target_slot)
|
||||
int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest,
|
||||
size_t img_len, int target_slot)
|
||||
{
|
||||
char digest[SHA256_DIGEST_LENGTH];
|
||||
|
||||
@ -40,7 +41,8 @@ int riotboot_flashwrite_verify_sha256(const uint8_t *sha256_digest, size_t img_l
|
||||
|
||||
uint8_t *img_start = (uint8_t *)riotboot_slot_get_hdr(target_slot);
|
||||
|
||||
LOG_INFO("riotboot: verifying digest at %p (img at: %p size: %u)\n", sha256_digest, img_start, img_len);
|
||||
LOG_INFO("riotboot: verifying digest at %p (img at: %p size: %u)\n",
|
||||
sha256_digest, img_start, img_len);
|
||||
|
||||
sha256_init(&sha256);
|
||||
|
||||
|
@ -36,12 +36,14 @@
|
||||
#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!"
|
||||
# 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 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);
|
||||
@ -55,7 +57,8 @@ int riotboot_hdr_validate(const riotboot_hdr_t *riotboot_hdr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int res = riotboot_hdr_checksum(riotboot_hdr) == riotboot_hdr->chksum ? 0 : -1;
|
||||
int res = riotboot_hdr_checksum(riotboot_hdr) ==
|
||||
riotboot_hdr->chksum ? 0 : -1;
|
||||
if (res) {
|
||||
LOG_INFO("%s: riotboot_hdr checksum invalid\n", __func__);
|
||||
}
|
||||
@ -65,5 +68,7 @@ int riotboot_hdr_validate(const riotboot_hdr_t *riotboot_hdr)
|
||||
|
||||
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));
|
||||
return fletcher32((uint16_t *)riotboot_hdr, offsetof(riotboot_hdr_t,
|
||||
chksum) /
|
||||
sizeof(uint16_t));
|
||||
}
|
||||
|
@ -34,10 +34,10 @@
|
||||
* address of the bootloader, thus the header is located after the
|
||||
* space reserved to the bootloader.
|
||||
*/
|
||||
const riotboot_hdr_t * const riotboot_slots[] = {
|
||||
(riotboot_hdr_t*)(CPU_FLASH_BASE + SLOT0_OFFSET), /* First slot address -> firmware image */
|
||||
const riotboot_hdr_t *const riotboot_slots[] = {
|
||||
(riotboot_hdr_t *)(CPU_FLASH_BASE + SLOT0_OFFSET), /* First slot address -> firmware image */
|
||||
#if NUM_SLOTS == 2
|
||||
(riotboot_hdr_t*)(CPU_FLASH_BASE + SLOT1_OFFSET), /* Second slot address -> firmware image */
|
||||
(riotboot_hdr_t *)(CPU_FLASH_BASE + SLOT1_OFFSET), /* Second slot address -> firmware image */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -30,8 +30,10 @@ static usbus_dfu_device_t dfu;
|
||||
static char _stack[USBUS_STACKSIZE];
|
||||
static usbus_t usbus;
|
||||
|
||||
void riotboot_usb_dfu_init(unsigned forced) {
|
||||
void riotboot_usb_dfu_init(unsigned forced)
|
||||
{
|
||||
uint32_t *reset_addr = (uint32_t *)RIOTBOOT_DFU_ADDR;
|
||||
|
||||
if (forced == 1 || *reset_addr == RIOTBOOT_MAGIC_NUMBER) {
|
||||
*reset_addr = 0;
|
||||
usbus_init(&usbus, usbdev_get_ctx(0));
|
||||
|
Loading…
Reference in New Issue
Block a user