1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/suit/storage: use XFA

This commit is contained in:
Francisco Molina 2022-04-04 11:29:04 +02:00
parent d20d353633
commit 013838626e
3 changed files with 26 additions and 33 deletions

View File

@ -22,6 +22,7 @@
#include "kernel_defines.h"
#include "log.h"
#include "xfa.h"
#include "suit.h"
#include "suit/storage.h"
@ -29,6 +30,8 @@
#include "riotboot/flashwrite.h"
#include "riotboot/slot.h"
XFA_USE(suit_storage_t, suit_storage_reg);
static inline suit_storage_flashwrite_t *_get_fw(suit_storage_t *storage)
{
return container_of(storage, suit_storage_flashwrite_t, storage);
@ -234,8 +237,10 @@ static const suit_storage_driver_t suit_storage_flashwrite_driver = {
.separator = '\0',
};
suit_storage_flashwrite_t suit_storage_flashwrite = {
static suit_storage_flashwrite_t suit_storage_flashwrite = {
.storage = {
.driver = &suit_storage_flashwrite_driver,
},
};
XFA(suit_storage_reg, 0) suit_storage_t* suit_storage_flashwrite_ptr = &suit_storage_flashwrite.storage;

View File

@ -24,11 +24,14 @@
#include "fmt.h"
#include "kernel_defines.h"
#include "log.h"
#include "xfa.h"
#include "suit.h"
#include "suit/storage.h"
#include "suit/storage/ram.h"
XFA_USE(suit_storage_t, suit_storage_reg);
static inline suit_storage_ram_t *_get_ram(suit_storage_t *storage)
{
return container_of(storage, suit_storage_ram_t, storage);
@ -227,3 +230,5 @@ suit_storage_ram_t suit_storage_ram = {
.driver = &suit_storage_ram_driver,
},
};
XFA(suit_storage_reg, 0) suit_storage_t* suit_storage_ram_ptr = &suit_storage_ram.storage;

View File

@ -25,32 +25,15 @@
#include "suit.h"
#include "suit/storage.h"
#ifdef MODULE_SUIT_STORAGE_FLASHWRITE
#include "suit/storage/flashwrite.h"
extern suit_storage_flashwrite_t suit_storage_flashwrite;
#endif
#include "xfa.h"
#ifdef MODULE_SUIT_STORAGE_RAM
#include "suit/storage/ram.h"
extern suit_storage_ram_t suit_storage_ram;
#endif
static suit_storage_t *reg[] = {
#ifdef MODULE_SUIT_STORAGE_FLASHWRITE
&suit_storage_flashwrite.storage,
#endif
#ifdef MODULE_SUIT_STORAGE_RAM
&suit_storage_ram.storage,
#endif
};
static const size_t reg_size = ARRAY_SIZE(reg);
XFA_INIT(suit_storage_t*, suit_storage_reg);
suit_storage_t *suit_storage_find_by_id(const char *id)
{
for (size_t i = 0; i < reg_size; i++) {
if (suit_storage_has_location(reg[i], id)) {
return reg[i];
for (size_t i = 0; i < XFA_LEN(suit_storage_t*, suit_storage_reg); i++) {
if (suit_storage_has_location(suit_storage_reg[i], id)) {
return suit_storage_reg[i];
}
}
return NULL;
@ -58,22 +41,22 @@ suit_storage_t *suit_storage_find_by_id(const char *id)
void suit_storage_init_all(void)
{
for (size_t i = 0; i < reg_size; i++) {
suit_storage_init(reg[i]);
for (size_t i = 0; i < XFA_LEN(suit_storage_t*, suit_storage_reg); i++) {
suit_storage_init(suit_storage_reg[i]);
}
}
suit_storage_t *suit_storage_find_by_component(const suit_manifest_t *manifest,
const suit_component_t *component)
{
for (size_t i = 0; i < reg_size; i++) {
for (size_t i = 0; i < XFA_LEN(suit_storage_t*, suit_storage_reg); i++) {
char name[CONFIG_SUIT_COMPONENT_MAX_NAME_LEN];
if (suit_component_name_to_string(manifest, component,
reg[i]->driver->separator,
suit_storage_reg[i]->driver->separator,
name, sizeof(name)) == SUIT_OK) {
if (suit_storage_has_location(reg[i], name)) {
return reg[i];
if (suit_storage_has_location(suit_storage_reg[i], name)) {
return suit_storage_reg[i];
}
}
}
@ -85,9 +68,9 @@ int suit_storage_get_highest_seq_no(uint32_t *seq_no)
uint32_t max_seq = 0;
int res = SUIT_ERR_STORAGE;
for (size_t i = 0; i < reg_size; i++) {
for (size_t i = 0; i < XFA_LEN(suit_storage_t*, suit_storage_reg); i++) {
uint32_t seq_no = 0;
if (suit_storage_get_seq_no(reg[i], &seq_no) == SUIT_OK) {
if (suit_storage_get_seq_no(suit_storage_reg[i], &seq_no) == SUIT_OK) {
res = SUIT_OK;
if (seq_no > max_seq) {
max_seq = seq_no;
@ -100,8 +83,8 @@ int suit_storage_get_highest_seq_no(uint32_t *seq_no)
int suit_storage_set_seq_no_all(uint32_t seq_no)
{
for (size_t i = 0; i < reg_size; i++) {
suit_storage_set_seq_no(reg[i], seq_no);
for (size_t i = 0; i < XFA_LEN(suit_storage_t*, suit_storage_reg); i++) {
suit_storage_set_seq_no(suit_storage_reg[i], seq_no);
}
return 0;
}