From e1d25f6d744094d9ea32176ce82becceef362ec5 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Fri, 4 Apr 2025 15:36:43 +0200 Subject: [PATCH] fw: Indicate which partition table used by return value when reading - Return 0: Slot 0 used. - Return 1: Slot 1 used, indicating slot 0 broken! --- hw/application_fpga/fw/tk1/partition_table.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/application_fpga/fw/tk1/partition_table.c b/hw/application_fpga/fw/tk1/partition_table.c index 594d1a7..e8c6c8c 100644 --- a/hw/application_fpga/fw/tk1/partition_table.c +++ b/hw/application_fpga/fw/tk1/partition_table.c @@ -24,6 +24,14 @@ void part_digest(struct partition_table *part_table, uint8_t *out_digest, size_t assert(blake2err == 0); } +// part_table_read reads and verifies the partition table storage, +// first trying slot 0, then slot 1 if slot 0 does not verify. +// +// It stores the partition table in storage. +// +// Returns negative values on errors. +// Returns 0 if using slot 0. +// Returns 1 if using slot 1, indicating that slot 0 failed verification. int part_table_read(struct partition_table_storage *storage) { uint32_t offset[2] = { @@ -41,7 +49,7 @@ int part_table_read(struct partition_table_storage *storage) part_digest(&storage->table, check_digest, sizeof(check_digest)); if (memeq(check_digest, storage->check_digest, sizeof(check_digest))) { - return 0; + return i; } }