Check diagnostics partition is aligned and doesn't overlap

Also updates docs to specify the requirement of the HAL flash driver by
wolfBoot_clear_failures().
pull/815/head
Mattia Moffa 2026-07-02 15:02:52 +02:00 committed by Daniele Lacamera
parent ceaed58782
commit 00e228d8d7
2 changed files with 48 additions and 0 deletions

View File

@ -116,6 +116,11 @@ The application can read the records, ordered newest-first, through this API:
copy record `index` (0 is the most recent) into `out`. Returns 0 on success.
- `int wolfBoot_clear_failures(void)`: erase the diagnostics region.
The read functions only read the region and have no external dependency.
`wolfBoot_clear_failures()`, however, erases flash, so an application that calls
it must have the HAL flash driver (`hal_flash_unlock`, `hal_flash_erase`,
`hal_flash_lock`) similarly to `wolfBoot_success()`.
Each `struct wolfBoot_failure_record` reports `phase`, `cause`, `partition`,
`fw_version` (the version of the offending image, when known) and a monotonic
`seq` number.

View File

@ -146,6 +146,49 @@
#endif
#endif
#ifdef WOLFBOOT_PERSIST_FAILURE_STATUS
#ifndef WOLFBOOT_DIAGNOSTICS_SECTORS
#define WOLFBOOT_DIAGNOSTICS_SECTORS 2
#endif
#if (WOLFBOOT_DIAGNOSTICS_ADDRESS % WOLFBOOT_SECTOR_SIZE) != 0
#error "Diagnostics region is not sector-aligned"
#endif
#if !defined(WOLFBOOT_PART_USE_ARCH_OFFSET) && \
!defined(PULL_LINKER_DEFINES) && !defined(WOLFBOOT_DIAGNOSTICS_EXT)
#if !defined(PART_BOOT_EXT) && \
((WOLFBOOT_PARTITION_BOOT_ADDRESS + 0) != 0) && \
((WOLFBOOT_DIAGNOSTICS_ADDRESS + 0 + \
WOLFBOOT_DIAGNOSTICS_SECTORS * WOLFBOOT_SECTOR_SIZE) > \
(WOLFBOOT_PARTITION_BOOT_ADDRESS + 0)) && \
((WOLFBOOT_DIAGNOSTICS_ADDRESS + 0) < \
(WOLFBOOT_PARTITION_BOOT_ADDRESS + 0 + WOLFBOOT_PARTITION_SIZE + 0))
#error "Diagnostics region overlaps the boot partition"
#endif
#if !defined(PART_UPDATE_EXT) && \
((WOLFBOOT_PARTITION_UPDATE_ADDRESS + 0) != 0) && \
((WOLFBOOT_DIAGNOSTICS_ADDRESS + 0 + \
WOLFBOOT_DIAGNOSTICS_SECTORS * WOLFBOOT_SECTOR_SIZE) > \
(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 0)) && \
((WOLFBOOT_DIAGNOSTICS_ADDRESS + 0) < \
(WOLFBOOT_PARTITION_UPDATE_ADDRESS + 0 + WOLFBOOT_PARTITION_SIZE + 0))
#error "Diagnostics region overlaps the update partition"
#endif
#if !defined(PART_SWAP_EXT) && \
((WOLFBOOT_PARTITION_SWAP_ADDRESS + 0) != 0) && \
((WOLFBOOT_DIAGNOSTICS_ADDRESS + 0 + \
WOLFBOOT_DIAGNOSTICS_SECTORS * WOLFBOOT_SECTOR_SIZE) > \
(WOLFBOOT_PARTITION_SWAP_ADDRESS + 0)) && \
((WOLFBOOT_DIAGNOSTICS_ADDRESS + 0) < \
(WOLFBOOT_PARTITION_SWAP_ADDRESS + 0 + WOLFBOOT_SECTOR_SIZE))
#error "Diagnostics region overlaps the swap partition"
#endif
#endif
#endif /* WOLFBOOT_PERSIST_FAILURE_STATUS */
#endif /* WOLFBOOT_FIXED_PARTITIONS */
#if !defined(WOLFBOOT_NO_LOAD_ADDRESS)