Add second pre-loaded app slot in flash

This commit is contained in:
Mikael Ågren 2025-03-18 13:18:33 +01:00
parent 6ad32f7317
commit 970668a47b
No known key found for this signature in database
GPG key ID: E02DA3D397792C46
6 changed files with 73 additions and 35 deletions

View file

@ -71,7 +71,8 @@ static uint32_t xorwow(uint32_t state, uint32_t acc);
#endif
static void scramble_ram(void);
static int compute_app_digest(uint8_t *digest);
static int load_flash_app(struct partition_table *part_table, uint8_t digest[32]);
static int load_flash_app(struct partition_table *part_table,
uint8_t digest[32], uint8_t slot);
static enum state start_where(struct context *ctx);
static void print_hw_version(void)
@ -375,9 +376,10 @@ static void jump_to_app(void)
__builtin_unreachable();
}
static int load_flash_app(struct partition_table *part_table, uint8_t digest[32])
static int load_flash_app(struct partition_table *part_table,
uint8_t digest[32], uint8_t slot)
{
if (preload_load(part_table) == -1) {
if (preload_load(part_table, slot) == -1) {
return -1;
}
@ -461,25 +463,25 @@ static enum state start_where(struct context *ctx)
case START_DEFAULT:
// fallthrough
case START_FLASH1:
ctx->flash_slot = 1;
ctx->flash_slot = 0;
ctx->ver_digest = NULL;
return FW_STATE_LOAD_FLASH;
case START_FLASH2:
ctx->flash_slot = 2;
ctx->flash_slot = 1;
ctx->ver_digest = NULL;
return FW_STATE_LOAD_FLASH;
case START_FLASH1_VER:
ctx->flash_slot = 1;
ctx->flash_slot = 0;
ctx->ver_digest = resetinfo->app_digest;
return FW_STATE_LOAD_FLASH;
case START_FLASH2_VER:
ctx->flash_slot = 2;
ctx->flash_slot = 1;
ctx->ver_digest = resetinfo->app_digest;
return FW_STATE_LOAD_FLASH;
@ -599,7 +601,7 @@ int main(void)
// authenticated.
part_table.pre_app_data.status = PRE_LOADED_STATUS_PRESENT;
if (load_flash_app(&part_table, ctx.digest) < 0) {
if (load_flash_app(&part_table, ctx.digest, ctx.flash_slot) < 0) {
debug_puts("Couldn't load app from flash\n");
state = FW_STATE_FAIL;
break;