From c13f102d1e764b4b7e91e72cabc3d3b1f56dc219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20=C3=85gren?= Date: Thu, 17 Apr 2025 08:43:27 +0200 Subject: [PATCH] fw: Add ERASE_DATA syscall Erase one or more flash sectors in app storage areas --- hw/application_fpga/fw/testapp/main.c | 24 +++++++++++++++++++- hw/application_fpga/fw/tk1/syscall_handler.c | 10 ++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/hw/application_fpga/fw/testapp/main.c b/hw/application_fpga/fw/testapp/main.c index f85902b..5619ebd 100644 --- a/hw/application_fpga/fw/testapp/main.c +++ b/hw/application_fpga/fw/testapp/main.c @@ -145,7 +145,7 @@ int main(void) } puts(IO_CDC, "done.\r\n"); - puts(IO_CDC, "\r\nReading from storage area..."); + puts(IO_CDC, "\r\nReading data from storage area..."); uint8_t in_data[14] = {0}; if (syscall(TK1_SYSCALL_READ_DATA, 0, (uint32_t)in_data, @@ -158,6 +158,28 @@ int main(void) } puts(IO_CDC, "done.\r\n"); + puts(IO_CDC, "\r\nErasing written data from storage area..."); + + if (syscall(TK1_SYSCALL_ERASE_DATA, 0, 4096, 0) != 0) { + failmsg("Failed to erase storage area"); + } + puts(IO_CDC, "done.\r\n"); + + puts(IO_CDC, "\r\nVerify erased storage area data..."); + + if (syscall(TK1_SYSCALL_READ_DATA, 0, (uint32_t)in_data, + sizeof(in_data)) != 0) { + failmsg("Failed to write to storage area"); + } + uint8_t check_data[sizeof(in_data)] = {0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff}; + if (!memeq(in_data, check_data, sizeof(check_data))) { + failmsg("Failed to read back data from storage area"); + anyfailed = 1; + } + puts(IO_CDC, "done.\r\n"); + puts(IO_CDC, "\r\nDeallocating storage area..."); if (syscall(TK1_SYSCALL_DEALLOC_AREA, 0, 0, 0) != 0) { diff --git a/hw/application_fpga/fw/tk1/syscall_handler.c b/hw/application_fpga/fw/tk1/syscall_handler.c index 7a24021..a269d1c 100644 --- a/hw/application_fpga/fw/tk1/syscall_handler.c +++ b/hw/application_fpga/fw/tk1/syscall_handler.c @@ -78,6 +78,16 @@ int32_t syscall_handler(uint32_t number, uint32_t arg1, uint32_t arg2, } return 0; + + case TK1_SYSCALL_ERASE_DATA: + if (storage_erase_sector(&part_table_storage.table, arg1, + arg2) < 0) { + debug_puts("couldn't erase storage area\n"); + return -1; + } + + return 0; + case TK1_SYSCALL_GET_VIDPID: // UDI is 2 words: VID/PID & serial. Return just the // first word. Serial is kept secret to the device