mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/riotboot: add revert and invalidate slot functions
Update the function description update write function refactor riotboot_flashwrite_invalidate function minor changes minor nitpicks
This commit is contained in:
parent
c337089de5
commit
d4c32caaaa
@ -224,6 +224,32 @@ static inline int riotboot_flashwrite_finish(riotboot_flashwrite_t *state)
|
|||||||
RIOTBOOT_FLASHWRITE_SKIPLEN);
|
RIOTBOOT_FLASHWRITE_SKIPLEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Invalidate a slot header (riotboot version)
|
||||||
|
*
|
||||||
|
* This function invalidates the target slot.
|
||||||
|
*
|
||||||
|
* @note If this function is called with only one valid slot,
|
||||||
|
* the invalidation will fail in order to keep one valid
|
||||||
|
* image to run after reboot
|
||||||
|
*
|
||||||
|
* @param[in] slot Target slot to invalidate
|
||||||
|
*
|
||||||
|
* @returns 0 on success, <0 otherwise
|
||||||
|
*/
|
||||||
|
int riotboot_flashwrite_invalidate(int slot);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Invalidate the latest firmware version (riotboot version)
|
||||||
|
*
|
||||||
|
* This function invalidates the slot having the most recent firmware revision
|
||||||
|
*
|
||||||
|
* @note This function requires two valid images to succeed
|
||||||
|
*
|
||||||
|
* @returns 0 on success, <0 otherwise
|
||||||
|
*/
|
||||||
|
int riotboot_flashwrite_invalidate_latest(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a slot's size
|
* @brief Get a slot's size
|
||||||
*
|
*
|
||||||
|
@ -24,11 +24,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "riotboot/flashwrite.h"
|
#include "riotboot/flashwrite.h"
|
||||||
|
#include "riotboot/slot.h"
|
||||||
#include "od.h"
|
#include "od.h"
|
||||||
|
|
||||||
#define LOG_PREFIX "riotboot_flashwrite: "
|
#define LOG_PREFIX "riotboot_flashwrite: "
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Magic number used to invalidate a slot
|
||||||
|
*/
|
||||||
|
#define INVALIDATE_HDR 0xAA
|
||||||
|
|
||||||
static inline size_t min(size_t a, size_t b)
|
static inline size_t min(size_t a, size_t b)
|
||||||
{
|
{
|
||||||
return a <= b ? a : b;
|
return a <= b ? a : b;
|
||||||
@ -150,6 +156,34 @@ int riotboot_flashwrite_putbytes(riotboot_flashwrite_t *state,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int riotboot_flashwrite_invalidate(int slot)
|
||||||
|
{
|
||||||
|
if (riotboot_slot_numof == 1) {
|
||||||
|
LOG_WARNING(LOG_PREFIX "abort, only one slot configured\n");
|
||||||
|
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);
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data_flash[4];
|
||||||
|
memset(data_flash, INVALIDATE_HDR, sizeof(data_flash));
|
||||||
|
|
||||||
|
flashpage_write((void *)riotboot_slot_get_hdr(slot), data_flash, sizeof(data_flash));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
return riotboot_flashwrite_invalidate(_slot_to_revert);
|
||||||
|
}
|
||||||
|
|
||||||
int riotboot_flashwrite_finish_raw(riotboot_flashwrite_t *state,
|
int riotboot_flashwrite_finish_raw(riotboot_flashwrite_t *state,
|
||||||
const uint8_t *bytes, size_t len)
|
const uint8_t *bytes, size_t len)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user