mirror of
https://github.com/tillitis/tillitis-key1.git
synced 2024-10-01 01:45:38 -04:00
Add fw state and fw cmd to trigger a start of a preloaded app
This commit is contained in:
parent
b52e57d4ea
commit
534ac06e86
@ -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,9 +429,9 @@ int main(void)
|
||||
/*@+mustfreeonly@*/
|
||||
ctx.use_uss = false;
|
||||
|
||||
readbyte();
|
||||
|
||||
scramble_ram();
|
||||
|
||||
/*readbyte(); // wait for input to start*/
|
||||
part_table_init(&part_table);
|
||||
|
||||
for (;;) {
|
||||
@ -446,6 +454,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!
|
||||
|
@ -30,6 +30,10 @@ int part_table_init(partition_table_t *part_table)
|
||||
part_table->app_storage[i].size = SIZE_STORAGE_AREA;
|
||||
}
|
||||
|
||||
/* Hardcode that a preloaded app exists in flash */
|
||||
part_table->pre_app_data.size = 28024;
|
||||
part_table->pre_app_data.status = 0x02;
|
||||
|
||||
part_table_write(part_table);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -11,6 +11,7 @@ enum state {
|
||||
FW_STATE_LOADING,
|
||||
FW_STATE_RUN,
|
||||
FW_STATE_FAIL,
|
||||
FW_STATE_LOAD_APP_FLASH,
|
||||
FW_STATE_MAX,
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user