Add fw state and fw cmd to trigger a start of a preloaded app

This commit is contained in:
Daniel Jobson 2024-09-03 15:29:21 +02:00
parent 9a1c9635f4
commit 7f7820b698
No known key found for this signature in database
GPG Key ID: 3707A9DBF4BB8F1A
4 changed files with 32 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#include "blake2s/blake2s.h"
#include "lib.h"
#include "partition_table.h"
#include "preload_app.h"
#include "proto.h"
#include "state.h"
@ -248,6 +249,13 @@ static enum state initial_commands(const struct frame_header *hdr,
break;
}
case FW_CMD_LOAD_APP_FLASH:
rsp[0] = STATUS_OK;
fwreply(*hdr, FW_RSP_LOAD_APP_FLASH, rsp);
state = FW_STATE_LOAD_APP_FLASH;
break;
default:
htif_puts("Got unknown firmware cmd: 0x");
htif_puthex(cmd[0]);
@ -421,8 +429,6 @@ int main(void)
/*@+mustfreeonly@*/
ctx.use_uss = false;
readbyte();
scramble_ram();
part_table_read(&part_table);
@ -447,6 +453,23 @@ int main(void)
state = loading_commands(&hdr, cmd, state, &ctx);
break;
case FW_STATE_LOAD_APP_FLASH:
if (preload_start(&part_table) == -1) {
state = FW_STATE_FAIL;
break;
}
*app_size = part_table.pre_app_data.size;
int digest_err = compute_app_digest(ctx.digest);
assert(digest_err == 0);
print_digest(ctx.digest);
ctx.use_uss = false;
state = FW_STATE_RUN;
break;
case FW_STATE_RUN:
run(&ctx);
break; // This is never reached!

View File

@ -108,6 +108,10 @@ void fwreply(struct frame_header hdr, enum fwcmd rspcode, uint8_t *buf)
len = LEN_32;
break;
case FW_RSP_LOAD_APP_FLASH:
len = LEN_1;
break;
default:
htif_puts("fwreply(): Unknown response code: 0x");
htif_puthex(rspcode);

View File

@ -37,6 +37,8 @@ enum fwcmd {
FW_CMD_GET_UDI = 0x08,
FW_RSP_GET_UDI = 0x09,
FW_CMD_MAX = 0x0a,
FW_CMD_LOAD_APP_FLASH = 0xF0,
FW_RSP_LOAD_APP_FLASH = 0xF1,
};
// clang-format on

View File

@ -11,6 +11,7 @@ enum state {
FW_STATE_LOADING,
FW_STATE_RUN,
FW_STATE_FAIL,
FW_STATE_LOAD_APP_FLASH,
FW_STATE_MAX,
};
#endif