Commit Graph

956 Commits (2f9a8ea15dcdebd6b0eb9f28fa47a3df8e7db85e)

Author SHA1 Message Date
Aidan Garske 6aecce0463 Enable the secure application handoff on STM32H5 2026-09-22 15:35:42 +02:00
Aidan Garske c48a882cd9 Add a generic secure application handoff with a measured boot record 2026-09-22 15:35:42 +02:00
Alex Lanzano 386147ed94 Rename board.h to wolfHAL_board.h 2026-09-22 15:29:32 +02:00
David Garske 4f33091f74 uart: replace the duplicated NS16550 console code with a shared driver 2026-09-21 18:12:32 +02:00
David Garske 4093fa0e17 Add NXP i.MX 8QuadMax MEK port including BL33 support 2026-09-21 18:07:44 +02:00
David Garske e353b20504 va416x0: fix vector table alignment and length, FRAM defects and ML-DSA 2026-09-21 17:13:42 +02:00
Daniele Lacamera ac519daf11 Address 3 Fenrir findings on PR 905 2026-09-18 21:38:27 +02:00
Daniele Lacamera dfe715056e F-13623: nRF5340 hal_flash_protect lock the full requested range
The region count truncated (n = len / SPU_FLASH_BLOCK_SIZE), so a len
smaller than one 16 KiB SPU block locked nothing and a non-multiple len
left the tail block writable, while the function returned 0 either way.
Round the block count up so the locked range covers [start, start+len)
whole (partial blocks at both ends locked whole, which only ever widens
protection), and reject len < 0. Add unit-nrf5340-flash-protect, which
sed-extracts the real function and runs it against a mock SPU region
array; mutation (revert to the truncating count) fails 3 of 6 tests.
2026-09-18 11:43:50 +02:00
Daniele Lacamera 21c82fa4d8 F-12883: nRF5340 uart_write CRLF dropped multiline tail data
After emitting CRLF the buffer advanced to the newline, not the byte
after it, so multiline input reprocessed the newline (stray CRLFs) and
lost the following text. Extract the CRLF conversion to
hal/nrf5340_uart.c (no nrfx) for host unit testing; add a regression
test.
2026-09-18 04:27:28 +02:00
David Garske 8bac8cc589
Merge pull request #892 from danielinux/fenrir-fixes-2026-09-15
Update_ram fallback fixes + fenrir fixes 2026 09 15
2026-09-17 08:10:03 -07:00
Aidan Garske 670280e5b3 Assert the STM32H5 secure link leaves room for the stack 2026-09-17 13:06:11 +02:00
David Garske a8c8c19fe8 Add LS1028A eSDHC SD card disk boot support 2026-09-17 12:33:19 +02:00
Daniele Lacamera 6814b503ef PR 892: address 6 Fenrir review findings
- hal/nxp_p1021.c: fix ONFI status polarity (bit 0 set = fail, bit 7
  clear = protected; was checking bits 0+1 set = success)
- src/libwolfboot.c: move partition state APIs under HAVE_PARTITION_TRAILERS
  so CUSTOM_PARTITION_TRAILER without WOLFBOOT_FIXED_PARTITIONS links
- src/x86/ata.c: do not zeroize DMA buffer when another async op is
  in progress (buffer still owned by first command's transfer)
- unit-p1021-fcm-bytes/erase-advance: update mocks to ONFI status bytes
- unit-update-ram-custom-trailer: add BOOT selection assertion via
  mock_max_read_addr, PID-suffixed temp files, unlink in cleanup
- unit-update-ram-nofixed-noramboot: unlink PID-specific temp files
2026-09-16 16:18:49 +02:00
Daniele Lacamera 66be5eb520 PR 892: P1021 NAND status bits + test coverage for F-12883/F-12922
- hal/nxp_p1021.c: fix JEDEC status bit polarity (DQ0 clear = fail,
  DQ1 clear = protected; was checking set bits)
- hal/s32k1xx.c: clarify watchdog timeout comment (65535 ticks at
  128kHz LPO = ~512ms unprescaled, ~131s with 1:256 prescaler)
- unit-keygen-xmss-params.c: assert wc_ForceZero + wc_FreeRng called
  after keygen (F-12883)
- unit-mock-flash.c: track largest ext_flash_read source addr/len
- unit-p1021-erase-advance.c: add test_erase_stops_on_status_fail
  (cmd succeeds but NAND reports DQ0 clear)
- unit-update-ram-noramboot.c: verify fallback loads from UPDATE
  partition, not oversize BOOT (F-12922)
2026-09-16 14:40:42 +02:00
Daniele Lacamera ae2145a380 F-9724: partial-flash-write uses bitwise NOT
The formula is data | ~current_data (bitwise); the comment used the
logical '!'
2026-09-16 12:14:13 +02:00
Daniele Lacamera b9f5cfdefe F-9260: S32K watchdog timeout is ~131s, not ~2s
WDOG_TOVAL=0xFFFF with a 1:256 prescaler at 128kHz LPO gives
~131 seconds, not ~2 seconds.
2026-09-16 12:14:13 +02:00
Daniele Lacamera d170977f50 F-9259: T2080 handoff sets TCR to 0
wolfBoot clears TCR to 0 (matching CW U-Boot pre-bootm); the
comment described the old 0x04000000 value.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 96cd60d28d F-9258: SPI cont keeps CS low (asserted)
cont!=0 holds chip-select asserted (low) after the transfer; the
comment said 'not let CS go low'.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 7a6e450ec6 F-9257: DDR training retry: WRCALIB is the gate
The reliability gate is WRCALIB, not PHY_TRAINING_STATUS. MTC is a
secondary gate skipped when TIP completes full training, and the
retry budget is 3 inner x 6 outer (up to 18 attempts), not 5.
2026-09-16 12:14:13 +02:00
Daniele Lacamera 908d4ec1e3 F-7048: make UDS all-value scan constant-time
buffer_is_all_value() early-exited on the first byte differing from
the target, so the loop trip count leaked the length of the leading
0xFF/0x00 run of the UDS, the DICE root secret read in
hal_uds_derive_key().

Replace the early exit with a volatile |= accumulator over the full
buffer, matching the constant-time compare pattern already used by
image_CT_compare() and the other secret comparisons in the tree.

Verified: gcc -S -O2 shows a straight-line loop body with only the
data-independent i < len branch; arm-none-eabi-gcc (stm32h5 preset)
compiles the file clean.

Reported by Fenrir.
2026-09-15 15:48:15 +02:00
Daniele Lacamera 2c636e9606 nrf5340: add memory clobber to DSB()
The F-12879 fix publishes SHM status with plain C stores before
IPC_TASKS_SEND; without a compiler memory barrier an optimized
build can reorder the stores past the dsb asm. Matches the
existing clobber in imx95_m7.h and stm32g4.h.
2026-09-15 14:32:18 +02:00
Daniele Lacamera b99847624b F-12879: nrf5340: publish SHM status before signaling IPC
hal_shm_status_set() triggered the IPC event before storing the
magic/status fields, so the peer core could wake on the event, read
stale fields, and wait for a second event that never comes. Store
the fields first, order them with a DSB, then signal; the receiver
pairs it with a DSB after clearing the event, before re-reading the
fields. Not verified on real nRF5340 hardware.
2026-09-15 08:47:28 +02:00
Daniele Lacamera 4e01a45e3b F-12881: p1021: check NAND program/erase status and ECC results
The write/erase loops discarded the JEDEC status byte from MDR and
hal_flash_command ignored the PAR (uncorrectable ECC) and FCT (FCM
timeout) bits, so failed programs, erases and uncorrectable reads
all reported success. Check P/WPS in the status byte and stop the
loop, and fail the command on PAR/FCT. The small-page FCM sequence
now ends with the status command (CM3+RSW) so MDR holds a valid
status like the large-page path; not verified on real P1021
hardware. config_io_pin now uses a single masked store for CPDIR/
CPPAR (F-12880): the clear-then-set pair could drop a concurrent
update to another pin in the same register.

F-12880, F-12881, F-12882
2026-09-15 08:42:58 +02:00
David Garske 8eafe1ef76
Merge pull request #890 from bigbrett/tc4-wolfboot
AURIX TC4xx support
2026-09-14 14:22:21 -07:00
Brett Nicholas 7c88ae7413 add TC4 PVER retry 2026-09-14 10:55:07 -06:00
Brett Nicholas ade42b51fa add TC4 EVER retry 2026-09-14 10:40:31 -06:00
David Garske b0fe251747 Add Nuvoton NuMaker M2354 Cortex-M23 target with TrustZone 2026-09-14 18:08:40 +02:00
Brett Nicholas 6d652d444f Support for AURIX TC4xx host and CSRM cores 2026-09-12 09:21:38 -06:00
David Garske bafa907e9a
Merge pull request #873 from danielinux/pkcs11-store-batch-commit
pkcs11 store: Improve Store performance through batch sector commits to Store_Close
2026-09-10 16:14:04 -07:00
David Garske 871ab86dc5
Merge pull request #886 from bigbrett/aurix-makefile-reorg
AURIX makefile housekeeping
2026-09-10 16:13:56 -07:00
Daniele Lacamera 3d5bebeefe pkcs11 store: tighten power-fail assert, rebase F4 footprint limits
vault_obj_read() now separates "object absent" from a failed read, so the
power-fail test rejects a corrupted vault instead of accepting any negative.
hal_cache_invalidate() shrank 120 -> 44 bytes; the 48 it still costs every
STM32F407 build is folded into the test-size-all limits.
2026-09-10 19:23:57 +02:00
Daniele Lacamera 9b06b907f8 hal: always define hal_cache_invalidate(), implement it on F4 and G4
The weak no-op sat inside NVM_FLASH_WRITEONCE, so pkcs11_store.c failed to
link on the nrf5340/nrf54l TrustZone configs. STM32F4 and STM32G4 enable the
flash instruction/data caches and never reset them, so give them a real one.
2026-09-10 18:42:54 +02:00
Brett Nicholas 678781db39 AURIX tc3 ARCH/TARGET refactor anticipating TC4xx 2026-09-10 10:19:08 -06:00
Daniele Lacamera 42e6dba558 pkcs11 store: invalidate the flash read cache after every commit
The store commits sectors with hal_flash_erase()/hal_flash_write() and
then reads them back through the memory map - sector_ptr(),
cache_get_sector()'s refill, and the raw magic reads in check_vault().
On a part that caches flash reads (STM32 ICACHE) those reads can return
pre-erase bytes. check_vault() is the worst case: a stale magic there
does not merely read wrong, it triggers restore_backup() or a full vault
re-initialisation, losing the token.
2026-09-10 10:45:55 +02:00
David Garske a2639e88f8 versal: report EL2 exceptions, fix FIT ramdisk fixup and the EL2->EL1 cache handoff 2026-09-10 08:17:21 +02:00
David Garske 24c23e767b Add T1040 eSDHC SD card disk boot support, first big-endian disk-boot target 2026-09-10 08:15:48 +02:00
Daniele Lacamera fc688f18c1 Address PR review: SWS macros + test decl style
hal/stm32wb.c: dedicated RCC_CFGR_SWS_{MSI,MASK} macros for the
clock-switch confirmation wait; SW/SWS encodings verified identical
in RM0434 6.4.3 and the STM32WB55 SVD.
unit-stm32u5-write.c: START_TEST brace on the next line, matching
the file and the unit-suite convention.
2026-09-07 17:43:22 +02:00
Daniele Lacamera 4751f89967 Merge branch 'wb-campaign-a4' into fenrir-fixes-2026-09-07 2026-09-07 16:38:42 +02:00
Daniele Lacamera 33e5bed910 Merge branch 'wb-campaign-a2' into fenrir-fixes-2026-09-07 2026-09-07 16:38:42 +02:00
Daniele Lacamera cfd44bc5c1 F-12878: STM32U5: program the 16-byte unit through an aligned pointer
An unaligned starting address split the four word stores across two
16-byte program units, leaving partial quad-words that set
FLASH_SR_WDW and hang the wait for completion. Align the destination
down to the unit, read-modify-write the whole unit, and store through
the aligned pointer. The unit test gains unaligned-start cases.
2026-09-07 16:31:07 +02:00
Daniele Lacamera ca06782f42 F-12877: STM32L5: program the 8-byte unit through an aligned pointer
hal_flash_write() stored both words of the 64-bit program unit
relative to the caller's address, so a write starting inside a unit
split the two stores across two units: the flash has no 32-bit
program mode, so nothing is programmed and the second store faults
on alignment. Align the destination down to the unit, take the bytes
outside the requested span from the unit itself, and store through
the aligned pointer, as hal/stm32h5.c does. The TrustZone claim is
unchanged: it is page-granular and already covers every non-secure
byte the aligned program touches.

Extend unit-stm32l5-write with unaligned-start cases. The host data
model cannot observe the program-unit split (pre-fix the bytes land
identically), so these pin the fixed layout: bytes before the
request preserved, nothing past it touched.
2026-09-07 16:31:07 +02:00
Daniele Lacamera 8e86847c1f F-12870: STM32C0: program flash writes through absolute addresses
The HAL contract is absolute (0x08000000-based) addresses, as the
erase path and every NVM caller use, but the double-word fast path
added the flash base on top and targeted an address space past the
flash. The read-modify-write path located its unit from the request
base indexed by i/4, landing in the wrong 8-byte unit once a request
started inside one. Both paths now program the 8-byte unit at
(address + i), and the now-dead FLASHMEM_ADDRESS_SPACE define is
gone.

Add unit-stm32c0-write: runs the extracted hal_flash_write() against
a host register/flash model with a second mapping standing in for
the wrong address space (4/5 checks fail pre-fix, 5/5 pass post-fix).
2026-09-07 16:05:51 +02:00
Daniele Lacamera 376f9e124f F-12920: zero firmware-DTB initrd pointers in hal_get_boot_dts
The CM4 firmware DTB is unverified (unsigned FAT partition) and this
path never attaches an authenticated ramdisk, so a non-zero
linux,initrd-start/end in it would direct the signed kernel to an
unauthenticated initramfs in RAM. Zero both properties on the
relocated DTB (fail closed on fixup error) and update the SECURITY
comment to state the new behavior.
2026-09-07 15:49:31 +02:00
Daniele Lacamera 9475169bdc F-12875: stm32f7 fix non-dual-bank sector 11 start address
Sector 11 was at 0x818C000, inside sector 10's 256 KB range
(0x8180000-0x81C0000), so hal_flash_erase mapped the upper part of
sector 10 to sector 11 and erased the wrong sector. Sector 11 is
0x81C0000, contiguous after sector 10 and ending at FLASH_TOP.
2026-09-07 14:43:15 +02:00
Daniele Lacamera 22356e6d02 F-12874: stm32wb switch SYSCLK to MSI and confirm SWS before disabling PLL
The MSIRDY wait read RCC_CFGR (bit 1 is SW status) instead of RCC_CR,
so it never gated, and the MSI selection was cleared only in a local
variable, never written back to RCC_CFGR. The PLL was disabled while
still the SYSCLK source, dropping the system clock. Now: wait MSIRDY,
commit the MSI selection, wait for SWS to confirm, then turn off PLL.
2026-09-07 14:43:15 +02:00
Daniele Lacamera c2916395a9 x86_64_efi: early-return after remaining panic() sites under UNIT_TEST
do_boot() already returned after its panic() calls, but GetVolume() and
efi_main() did not: under UNIT_TEST panic() returns, so GetVolume() hit a
NULL deref / uninitialized return and efi_main() ran wolfBoot_start().
Return NULL / EFI_LOAD_ERROR at each site (unreachable on target).
2026-09-04 21:08:36 +02:00
Daniele Lacamera faaad372cc Address minor PR 882 review nits
Cap the library fw_size clamp at UINT32_MAX (a > 4 GiB file would
otherwise truncate to a small value), say 'restore' not 'store' in the
scatter-restore error message, and print stdout as well as stderr in
the compile-check scripts on failure.
2026-09-04 16:39:26 +02:00
Daniele Lacamera 01a71c7d39 x86_64_efi: return after LoadImage-failure panic under UNIT_TEST
panic() returns under UNIT_TEST, so the LoadImage-failure site fell
through to StartImage on a failed load. Add the return to match the
zero-size guard; on target panic() never returns, so behavior is
unchanged.
2026-09-04 15:52:27 +02:00
Daniele Lacamera d64f15af05 F-7392: stm32h7: document inherent OTP immutability in set_readonly
The H7 OTP memory is one-time programmable, so the keystore and UDS
are permanent once written; the H7 has no OTP block-lock register
(unlike the H5), so there is no write-protection step to perform.
Replace the misleading TODO with the reason the no-op is correct.
2026-09-04 14:33:29 +02:00
Daniele Lacamera eb3d587fe2 F-9746: x86_64_efi: fix do_boot prototype mismatch, drop unused param
boot_x86_64.c declared x86_64_efi_do_boot(uint8_t *) while the HAL
defines (uint32_t *, uint8_t *): the linker connected the incompatible
pair and the call was undefined behavior, mostly latent because the
second parameter was discarded. Match the AArch64 sibling: single
const uint32_t *boot_addr in the declaration, definition and call,
and remove the unused dts_address parameter.
2026-09-04 10:57:08 +02:00