diff --git a/hw/application_fpga/fw/testloadapp/main.c b/hw/application_fpga/fw/testloadapp/main.c index 16f3e73..5d28e09 100644 --- a/hw/application_fpga/fw/testloadapp/main.c +++ b/hw/application_fpga/fw/testloadapp/main.c @@ -154,7 +154,10 @@ void reset_from_client(void) rst.type = START_CLIENT; - syscall(TK1_SYSCALL_RESET, (uint32_t)&rst, 0, 0); + // Give the next in chain something to look at. + memset(rst.next_app_data, 17, sizeof(rst.next_app_data)); + + syscall(TK1_SYSCALL_RESET, (uint32_t)&rst, sizeof(rst.next_app_data), 0); } int main(void) diff --git a/hw/application_fpga/fw/tk1/main.c b/hw/application_fpga/fw/tk1/main.c index c03007b..07810af 100644 --- a/hw/application_fpga/fw/tk1/main.c +++ b/hw/application_fpga/fw/tk1/main.c @@ -444,7 +444,19 @@ static enum state start_where(struct context *ctx) { assert(ctx != NULL); - // Where do we start? Read resetinfo 'startfrom' + debug_puts("resetinfo->type: "); + debug_putinthex(resetinfo->type); + debug_lf(); + + debug_puts(" ->app_digest: \n"); + debug_hexdump(resetinfo->app_digest, RESET_DIGEST_SIZE); + debug_lf(); + + debug_puts(" ->next_app_data: \n"); + debug_hexdump(resetinfo->next_app_data, RESET_DATA_SIZE); + debug_lf(); + + // Where do we start? switch (resetinfo->type) { case START_DEFAULT: // fallthrough diff --git a/hw/application_fpga/fw/tk1/mgmt_app.c b/hw/application_fpga/fw/tk1/mgmt_app.c index e5732aa..f520f06 100644 --- a/hw/application_fpga/fw/tk1/mgmt_app.c +++ b/hw/application_fpga/fw/tk1/mgmt_app.c @@ -12,9 +12,9 @@ // // To update this, compute the BLAKE2s digest of the app.bin static const uint8_t allowed_app_digest[32] = { - 0xf8, 0x90, 0x34, 0x31, 0xe0, 0xed, 0xab, 0x8b, 0x91, 0xe5, 0x63, - 0xe6, 0xea, 0x6a, 0x49, 0xe6, 0x53, 0x1e, 0xc7, 0x47, 0xca, 0x2f, - 0x2b, 0x8f, 0xf3, 0x5e, 0x67, 0x13, 0x0f, 0xfa, 0x93, 0x36, + 0x85, 0x29, 0xe3, 0x25, 0xf5, 0x8d, 0x53, 0x5f, 0xe1, 0x2a, 0x77, + 0x92, 0xe7, 0xdc, 0x4b, 0x4d, 0x1, 0x85, 0x17, 0xca, 0xfd, 0x54, + 0x83, 0xb3, 0xbb, 0x28, 0x4f, 0xa1, 0x98, 0x5f, 0x9e, 0x56, }; static uint8_t current_app_digest[32]; diff --git a/hw/application_fpga/fw/tk1/reset.c b/hw/application_fpga/fw/tk1/reset.c index df43ab2..f3ed41c 100644 --- a/hw/application_fpga/fw/tk1/reset.c +++ b/hw/application_fpga/fw/tk1/reset.c @@ -38,3 +38,21 @@ int reset(struct reset *userreset, size_t nextlen) __builtin_unreachable(); } + +int reset_data(uint8_t *next_app_data) +{ + if ((uint32_t)next_app_data < TK1_RAM_BASE || + (uint32_t)next_app_data >= TK1_RAM_BASE + TK1_RAM_SIZE) { + return -1; + } + + if ((uint32_t)next_app_data + RESET_DATA_SIZE > + TK1_RAM_BASE + TK1_RAM_SIZE) { + return -1; + } + + memcpy(next_app_data, (void *)resetinfo->next_app_data, + RESET_DATA_SIZE); + + return 0; +} diff --git a/hw/application_fpga/fw/tk1/reset.h b/hw/application_fpga/fw/tk1/reset.h index a434d38..f763d89 100644 --- a/hw/application_fpga/fw/tk1/reset.h +++ b/hw/application_fpga/fw/tk1/reset.h @@ -9,6 +9,8 @@ #define TK1_MMIO_RESETINFO_BASE 0xd0000f00 #define TK1_MMIO_RESETINFO_SIZE 0x100 +#define RESET_DIGEST_SIZE 32 +#define RESET_DATA_SIZE 220 enum reset_start { START_DEFAULT = 0, // Probably cold boot @@ -21,10 +23,11 @@ enum reset_start { }; struct reset { - uint32_t type; // Reset type - uint8_t app_digest[32]; // Program digest - uint8_t next_app_data[220]; // Data to leave around for next app + enum reset_start type; + uint8_t app_digest[RESET_DIGEST_SIZE]; + uint8_t next_app_data[RESET_DATA_SIZE]; }; int reset(struct reset *userreset, size_t nextlen); +int reset_data(uint8_t *next_app_data); #endif diff --git a/hw/application_fpga/fw/tk1/syscall_handler.c b/hw/application_fpga/fw/tk1/syscall_handler.c index 7d3c310..f07aeff 100644 --- a/hw/application_fpga/fw/tk1/syscall_handler.c +++ b/hw/application_fpga/fw/tk1/syscall_handler.c @@ -9,10 +9,9 @@ #include "partition_table.h" #include "preload_app.h" +#include "reset.h" #include "storage.h" - -#include "../tk1/reset.h" -#include "../tk1/syscall_num.h" +#include "syscall_num.h" // clang-format off static volatile uint32_t *udi = (volatile uint32_t *)TK1_MMIO_TK1_UDI_FIRST; @@ -100,6 +99,10 @@ int32_t syscall_handler(uint32_t number, uint32_t arg1, uint32_t arg2, case TK1_SYSCALL_STATUS: return part_get_status(); + case TK1_SYSCALL_GET_APP_DATA: + // arg1 next_app_data + return reset_data((uint8_t *)arg1); + default: assert(1 == 2); } diff --git a/hw/application_fpga/fw/tk1/syscall_num.h b/hw/application_fpga/fw/tk1/syscall_num.h index f7255d6..14109a0 100644 --- a/hw/application_fpga/fw/tk1/syscall_num.h +++ b/hw/application_fpga/fw/tk1/syscall_num.h @@ -18,6 +18,7 @@ enum syscall_num { TK1_SYSCALL_PRELOAD_GET_DIGSIG = 11, TK1_SYSCALL_REG_MGMT = 12, TK1_SYSCALL_STATUS = 13, + TK1_SYSCALL_GET_APP_DATA = 14, }; #endif diff --git a/hw/application_fpga/tools/default_partition.bin b/hw/application_fpga/tools/default_partition.bin index e0b4b46..38fa3af 100644 Binary files a/hw/application_fpga/tools/default_partition.bin and b/hw/application_fpga/tools/default_partition.bin differ