From dd147657a41dd6311317746e5900c96bda4fadb8 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Tue, 18 Mar 2025 14:56:15 +0100 Subject: [PATCH] Introduce syscalls to change preloaded app Introduce syscalls: - TK1_SYSCALL_PRELOAD_STORE - TK1_SYSCALL_PRELOAD_STORE_FIN - TK1_SYSCALL_PRELOAD_DELETE - TK1_SYSCALL_REG_MGMT = 11 Change preload_store_finalize() not to take USS arg. Unused for preloaded apps. --- hw/application_fpga/fw/tk1/preload_app.c | 5 +---- hw/application_fpga/fw/tk1/preload_app.h | 3 +-- hw/application_fpga/fw/tk1/syscall_handler.c | 21 ++++++++++++++++++++ hw/application_fpga/fw/tk1/syscall_num.h | 6 +++++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/hw/application_fpga/fw/tk1/preload_app.c b/hw/application_fpga/fw/tk1/preload_app.c index b46e79b..0560bf9 100644 --- a/hw/application_fpga/fw/tk1/preload_app.c +++ b/hw/application_fpga/fw/tk1/preload_app.c @@ -75,8 +75,7 @@ int preload_store(struct partition_table *part_table, uint32_t offset, return flash_write_data(address, data, size); } -int preload_store_finalize(struct partition_table *part_table, bool use_uss, - uint8_t *uss, size_t app_size, uint8_t to_slot) +int preload_store_finalize(struct partition_table *part_table, size_t app_size, uint8_t to_slot) { /* Check if we are allowed to store */ if (!mgmt_app_authenticate(&part_table->mgmt_app_data)) { @@ -88,8 +87,6 @@ int preload_store_finalize(struct partition_table *part_table, bool use_uss, return -1; } - // TODO: Maybe add the uss fields - if (app_size == 0 || app_size > SIZE_PRE_LOADED_APP) { return -2; } diff --git a/hw/application_fpga/fw/tk1/preload_app.h b/hw/application_fpga/fw/tk1/preload_app.h index 29473ac..3401c8a 100644 --- a/hw/application_fpga/fw/tk1/preload_app.h +++ b/hw/application_fpga/fw/tk1/preload_app.h @@ -14,8 +14,7 @@ bool preload_check_valid_app(struct partition_table *part_table, int preload_load(struct partition_table *part_table, uint8_t from_slot); int preload_store(struct partition_table *part_table, uint32_t offset, uint8_t *data, size_t size, uint8_t to_slot); -int preload_store_finalize(struct partition_table *part_table, bool use_uss, - uint8_t *uss, size_t app_size, uint8_t to_slot); +int preload_store_finalize(struct partition_table *part_table, size_t app_size, uint8_t to_slot); int preload_delete(struct partition_table *part_table, uint8_t slot); #endif diff --git a/hw/application_fpga/fw/tk1/syscall_handler.c b/hw/application_fpga/fw/tk1/syscall_handler.c index 0de09cd..86b1392 100644 --- a/hw/application_fpga/fw/tk1/syscall_handler.c +++ b/hw/application_fpga/fw/tk1/syscall_handler.c @@ -9,7 +9,9 @@ #include #include +#include "mgmt_app.h" #include "partition_table.h" +#include "preload_app.h" #include "storage.h" #include "../tk1/resetinfo.h" @@ -71,6 +73,25 @@ int32_t syscall_handler(uint32_t number, uint32_t arg1, uint32_t arg2, // first word. Serial is kept secret to the device // app. return udi[0]; + + case TK1_SYSCALL_PRELOAD_DELETE: + return preload_delete(&part_table, 1); + + case TK1_SYSCALL_PRELOAD_STORE: + // arg1 offset + // arg2 data + // arg3 size + // always using slot 1 + return preload_store(&part_table, arg1, (uint8_t *)arg2, arg3, 1); + + case TK1_SYSCALL_PRELOAD_STORE_FIN: + // arg1 app_size + // always using slot 1 + return preload_store_finalize(&part_table, arg1, 1); + + case TK1_SYSCALL_REG_MGMT: + return mgmt_app_register(&part_table); + 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 e1b5a95..41fdc0c 100644 --- a/hw/application_fpga/fw/tk1/syscall_num.h +++ b/hw/application_fpga/fw/tk1/syscall_num.h @@ -12,7 +12,11 @@ enum syscall_num { TK1_SYSCALL_READ_DATA = 5, TK1_SYSCALL_ERASE_DATA = 6, TK1_SYSCALL_GET_VIDPID = 7, - TK1_SYSCALL_SET_LED = 10, + TK1_SYSCALL_PRELOAD_STORE = 8, + TK1_SYSCALL_PRELOAD_STORE_FIN = 9, + TK1_SYSCALL_PRELOAD_DELETE = 10, + TK1_SYSCALL_REG_MGMT = 11, + TK1_SYSCALL_SET_LED = 30, }; #endif