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!
This commit is contained in:
Michael Cardell Widerkrantz 2025-04-04 15:36:43 +02:00 committed by Mikael Ågren
parent 2eee630649
commit e1d25f6d74
No known key found for this signature in database
GPG Key ID: E02DA3D397792C46

View File

@ -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;
}
}