Commit Graph

767 Commits (9bfecfb617c12015ca4e724033cc7fb417a855df)

Author SHA1 Message Date
Daniele Lacamera c165905fe2 F-5357: zeroize digest and uuid_be stack buffers in hal_uds_derive_key before every return
Add hal_uds_zeroize (volatile byte-loop, same pattern as hal_dice_zeroize in
the WOLFBOOT_DICE_HW block) and call it to clear the SHA digest and uuid_be
stack arrays on both error and success paths, preventing UDS key material and
UUID bytes from remaining on the stack after the function returns.
2026-06-10 21:01:16 +02:00
Daniele Lacamera 2b0fde4b2c F-5745: fix off-by-one in hal_flash_erase skipping last page when len%PAGE_SIZE!=0
The loop condition `p < end_address` excluded the final page whenever
len % FLASH_PAGE_SIZE != 0: end_address landed exactly on that page's
start offset and the strict less-than guard skipped it. Change to
`p <= end_address` to match the intended inclusive-end semantics.

Add a unit test (test_erase_unaligned_len_covers_last_page) to the
existing unit-flash-erase-h7 harness that verifies len=PAGE_SIZE+1
erases two pages, not one.
2026-06-10 21:01:16 +02:00
Alex Lanzano 01c52d87e8 remove wolfhal TARGET. Add WOLFHAL option 2026-06-10 17:12:25 +02:00
Alex Lanzano 125872c571 Create STM32WB wolfHAL example. GC sections on all test apps 2026-06-10 17:12:25 +02:00
Daniele Lacamera 03f5193dc2 F-5129: fix stm32h7 hal_flash_erase Bank 2 sector underflow
The Bank 2 branch of hal_flash_erase() subtracted the absolute base
FLASH_BANK2_BASE (0x08100000) from the bank-relative loop offset p,
instead of the relative FLASH_BANK2_BASE_REL (0x00100000) used by every
other comparison in the function. For a Bank 2 offset (p >= 0x00100000)
this underflowed uint32_t to ~0xF8000000, with two effects:

  1. the SNB sector index programmed into FLASH_CR2 came from the
     underflowed value (always sector 0, with stray high bits leaking
     into other CR2 fields), and
  2. the subtraction mutated the loop variable p itself, so after
     p += FLASH_PAGE_SIZE the offset jumped past any end_address and the
     loop exited after a single iteration.

The combined result: any multi-sector Bank 2 erase touched only one
sector with the wrong index, silently leaving the remaining requested
sectors (e.g. the SWAP partition at 0x081C0000) unerased.

Compute the sector index in a temporary from FLASH_BANK2_BASE_REL so the
loop variable is preserved, and mask it with FLASH_CR_SNB_MASK before
shifting into FLASH_CR2.

Adds unit-flash-erase-h7, which compiles hal_flash_erase() in isolation
(guarded by WOLFBOOT_UNIT_TEST_FLASH_ERASE, mirroring the unit-mpusize
approach for boot_arm.c) against mocked flash registers and asserts that
a two-sector Bank 2 erase programs sectors 6 and 7 across two iterations.
2026-06-09 15:52:07 +02:00
Daniele Lacamera d280262028 F-5356: bound i.MX RT flash write copy to caller buffer length
hal_flash_write() programs one full CONFIG_FLASH_PAGE_SIZE (256/512 byte)
page per loop iteration but unconditionally memcpy'd a whole page out of
the caller's buffer regardless of len. Sub-page writes - notably the
1-byte trailer updates from set_trailer_at()/trailer_write() on the
non-NVM_FLASH_WRITEONCE i.MX RT configs - therefore overread the source
buffer (e.g. 255 bytes past a 1-byte stack value) and could program
adjacent stack/RAM contents into flash.

Bound the copy to min(page, len - i) and pad the rest of the page buffer
with the erased value (0xFF). 0xFF is a no-op for NOR programming, so the
existing flash contents of the rest of the page are preserved.
2026-06-09 15:50:48 +02:00
Mattia Moffa 4830817bef Layerscape 1028a flash erase: reset status to 0 at each iteration
Fixes F#5347
2026-06-09 15:50:14 +02:00
Mattia Moffa b193bfbf68 Layerscape 1028a: add missing semicolon in while loop
Fixes F#5346
2026-06-09 15:50:14 +02:00
Mattia Moffa 6ac1fc1d07 Layerscape 1028a: fix pointer arithmetic errors
Fixes F#5345
2026-06-09 15:50:14 +02:00
Mattia Moffa 833373f57c Polarfire: prevent integer overflow in address bounds check
Fixes F#5128
2026-06-09 15:50:14 +02:00
David Garske b60bd311a3 Peer review feedback (thanks Daniele) 2026-06-09 15:30:27 +02:00
David Garske 14f6e4a298 Add wolfBoot FIT support for loading bitstream 2026-06-09 15:30:27 +02:00
David Garske e27e81f659 Improve SRAM partitioning for Ethernet DMA 2026-06-03 10:54:20 +02:00
David Garske 1e4fbc49b2 Peer review fixes (thanks Copilot) 2026-06-03 10:54:20 +02:00
David Garske bbb4d66479 stm32h5: clear MPCBB SRAM2/3 PRIVCFGR so NS ETH DMA can access them 2026-06-03 10:54:20 +02:00
David Garske 5b51344421 stm32h5: cede SRAM2 + clear GPIO SECCFGR for NS apps (TZEN=1) 2026-06-03 10:54:20 +02:00
David Garske 8fe46bb40f Peer review fixes (thanks Copilot)
hal/stm32g4.c:
- hal_flash_write unaligned path: rebase the aligned doubleword on
  (address + i), not the initial address; index as dst[0]/dst[1].
  The old form skipped to the wrong DW once i advanced past 8 with
  an unaligned starting address.
- hal_flash_erase: end_address was address + len - 1 paired with a
  strict less-than, which dropped the last page when len straddled a
  page boundary by one byte. Use address + len.
- flash_clear_errors / EOP clear at end of hal_flash_write: FLASH_SR
  bits are W1C. Read-modify-write via |= can clear unrelated W1C
  bits that happen to be set. Write the mask directly.
- uart_write: cast through uint8_t before promoting to uint32_t so
  high-bit chars do not sign-extend into TDR.

hal/stm32g4.h:
- DMB/ISB/DSB: add the "memory" clobber so the compiler also treats
  them as scheduling barriers, not just hardware-level fences.

hal/stm32g4.ld:
- Rename the output section .edidx to .ARM.exidx to match the
  input-section pattern and standard Cortex-M linker scripts.
2026-05-29 13:10:15 +02:00
David Garske c075549ea2 Add wolfBoot support for STM32G4 2026-05-29 13:10:15 +02:00
David Garske 0cb6bd42ac Vorago VA416x0: simplify iram_write/iram_fill (single RMW path) 2026-05-29 13:09:19 +02:00
David Garske 9786f5608b Add wolfBoot port for STM32N6 (NUCLEO-N657X0-Q)
Co-authored-by: Aidan Garske <aidan@wolfssl.com>
2026-05-28 16:49:57 +02:00
Brett Nicholas a1f86fa1c2 expose root CA list as makefile var 2026-05-26 17:37:50 +02:00
Brett Nicholas b8bc0a75e5 Add support for wolfHSM multi-root certificate verification 2026-05-26 17:37:50 +02:00
Yosuke Shimizu f4d5340641 Add hardware-based DICE on mcxn 2026-05-21 20:49:20 +02:00
Tobias Frauenschläger 6e60abd034 Continue the ML-DSA renaming 2026-05-19 11:21:20 -07:00
David Garske c3d255d8ed Vorago VA416x0: harden iram_write/iram_fill per review
Two follow-ups to the IRAM shadow update fix (da96f5a2):

1. Mark the bulk-copy destination as volatile uint32_t * so the compiler
   cannot lower a 32-bit assignment into byte/halfword stores. Sub-word
   stores are silently dropped by the IRAM ECC, so a future codegen
   change could have broken the workaround.

2. Use (uintptr_t)3u / ~(uintptr_t)3u for alignment masking. On targets
   where uintptr_t is wider than unsigned int the bare ~3u would zero
   the high half of the address; harmless on Cortex-M4 today, but the
   helper pattern is easy to copy elsewhere.

The int len type is kept to match the wolfBoot ext_flash_* HAL signature
convention across all ports.

Verified with arm-none-eabi-objdump: aligned bulk path emits only 32-bit
str instructions (no strb/strh).
2026-05-13 18:35:30 +02:00
David Garske 08c6673407 Fix Vorago VA416x0 IRAM shadow update (use word-aligned stores)
The VA416xx code RAM (IRAM at 0x00000000-0x0003FFFF) silently drops 8-bit
and 16-bit stores when ROM_PROT.WREN=1 - only word-aligned 32-bit stores
are honored, because the ECC machinery computes parity per 32-bit word
and rejects sub-word writes (no fault is raised). wolfBoot's local
memcpy()/memset() are byte-wise (ldrb/strb), so the IRAM shadow update
in ext_flash_write/read/erase appeared to succeed but actually left
the destination unchanged. The FRAM content was updated correctly, but
after the swap wolfBoot branched into the partition at 0xB800 in IRAM
where the stale image still lived, so the running app was the OLD
version even though the partition header (read from FRAM) reported the
new version.

Add iram_write/iram_fill helpers that use 32-bit stores for the bulk
of an aligned region and read-modify-write the containing word for any
unaligned head/tail, and use them in ext_flash_write/read/erase in
place of memcpy/memset for the shadow update. Partition addresses are
sector-aligned so in practice the path is always pure 32-bit stores.

Verified end-to-end on VA41630-EVK with build_test.sh update: app v1
boots, trigger sets, swap runs sector-by-sector, post-swap boot prints
"Booting version: 0x2" and the running app prints v2-specific output
in TESTING state. After wolfBoot_success() and a manual reset the
second boot reports state CONFIRMED.
2026-05-13 18:35:30 +02:00
David Garske b94954eab4 Add Xilinx Zynq-7000 (ZC702) wolfBoot port 2026-05-12 12:06:05 +02:00
Thomas Cook 6093b68f15 Fix lingering lpc55s69 issues 2026-05-07 17:06:35 -04:00
Mattia Moffa fda8668cc3 Address Copilot comments 2026-05-07 21:39:34 +02:00
Mattia Moffa dc6cfaaf83 Kinetis KL26 port 2026-05-07 21:39:34 +02:00
Mattia Moffa f2b95c2563 STM32H5, STM32U5, STM32L5: fix off-by-one error in hal_flash_erase
F#3537
2026-05-06 19:03:12 +02:00
Mattia Moffa 871dd854ff Flash test: fix off-by-one error
F#3536
2026-05-06 19:03:12 +02:00
David Garske af40ae1471 Add STM32C5 target (NUCLEO-C5A3ZG) 2026-05-06 19:02:58 +02:00
Brett Nicholas 24841a0eb8 support AURIX hw accel 2026-05-05 16:37:54 +02:00
Brett Nicholas 8ac4838b92 tc3: disable/capture bus errors for lifetime of bootloader 2026-05-05 16:37:54 +02:00
Brett Nicholas f5a8efeb25 tc3: fix for latest wolfHSM, remove devId from cryptoCtx as it no longer exists 2026-05-05 16:37:54 +02:00
Brett Nicholas e43e012e98 review feedback 2026-05-05 16:37:54 +02:00
Brett Nicholas a2e9267529 Adds generic cryptocb support for PK, hash, and symmetric crypto 2026-05-05 16:37:54 +02:00
David Garske 85fb32b1dd Fixes from peer review. Thank you Alex 2026-05-05 10:16:16 +02:00
David Garske c643215c5e fit: gzip-compressed kernel + ramdisk (initramfs) support
Wires the new wolfBoot_gunzip inflater into the FIT image-loading path
and adds initramfs (ramdisk) extraction with DTB /chosen fixup so a
single signed FIT can carry kernel, DTB, and rootfs.

GZIP path
---------
* fit_load_image_ex(out_max) added; fit_load_image kept as a wrapper.
* When a subimage carries compression="gzip", inflate straight to the
  FIT-declared load address, then verify the FIT hash-1 subnode
  (sha256 / sha384 if available) for defense in depth on top of the
  outer wolfBoot signature. The compression property is now read
  unconditionally so a build without WOLFBOOT_GZIP can warn and fail
  closed instead of silently memcpy-ing compressed bytes as if they
  were raw.
* fit_verify_hash propagates wc_InitSha256 / wc_Sha256Update /
  wc_Sha256Final return codes (and the SHA-384 equivalents) - any
  non-zero return is treated as a verification failure so a misbehaving
  backend cannot silently degrade to a no-op.
* GZIP=1 is the new default in the FIT-using example configs (zynqmp,
  zynqmp_sdcard, polarfire_mpfs250, polarfire_mpfs250_qspi,
  versal_vmk180, versal_vmk180_sdcard); set GZIP=0 to opt out.

Ramdisk path
------------
* fit_find_images() gains a ramdisk out-arg and fdt_fixup_initrd()
  writes /chosen/linux,initrd-{start,end} as 64-bit big-endian cells.
* update_disk.c and update_ram.c load the FIT ramdisk node (under
  WOLFBOOT_FIT_RAMDISK) and patch the loaded DTB. Compressed (gzip)
  ramdisks reuse the same fit_load_image_ex() decompress path.
* RAMDISK=1 build switch defines WOLFBOOT_FIT_RAMDISK;
  WOLFBOOT_LOAD_RAMDISK_ADDRESS is plumbed through tools/config.mk ->
  Makefile sed -> include/target.h.in. Defaults to 0; when 0 the
  ramdisk stays at whatever fit_load_image returned.
* hal/zynq.c and hal/versal.c bump fdt_totalsize headroom from 512 to
  768 bytes to fit the new linux,initrd-{start,end} entries.
* config/examples/zynqmp_sdcard.config gains a commented-out opt-in
  block (RAMDISK=1, WOLFBOOT_LOAD_RAMDISK_ADDRESS=0x40000000, alt
  LINUX_BOOTARGS) so a single config file covers both rootfs-on-disk
  and FIT-bundled-initramfs flows.

Builds against the existing master configs are byte-identical when
GZIP=0 and RAMDISK is unset.
2026-05-05 10:16:16 +02:00
David Garske 8c7b8640dd
Merge pull request #762 from danielinux/fenrir-fixes-2026-04-29
Fenrir fixes
2026-04-29 11:24:44 -07:00
Daniele Lacamera b0f1bf9bd1 Handle library image malloc failure
F/3038
2026-04-29 11:24:44 +02:00
Daniele Lacamera c0f6b12721 Addressed copilot's comments 2026-04-28 15:22:41 +02:00
Daniele Lacamera 42455508c0 Fix NRF52 UART DMA and Renode test infrastructure
hal/nrf52.c:
- Use static volatile buffer for UARTE DMA source instead of stack
  variable address. GCC 15.2 with -Os optimized away the store to the
  stack slot, causing the DMA to read zeros.
- Set UART0_ENABLE to 4 (UARTE mode) per NRF52840 datasheet.

tools/test-expect-version/test-expect-version.c:
- Replace deprecated termio.h and linux/serial.h with sys/ioctl.h
  for compatibility with newer glibc.

tools/renode/docker-test.sh:
- Remove unused RENODE_CHECKOUT env var.

tools/scripts/renode-test-update.sh:
- Add robust UART wait functions with timeouts and liveness checks.
- Log Renode output to /tmp/renode.log for diagnostics on failure.
- Use run_expect_version helper with configurable timeout.
2026-04-28 15:04:35 +02:00
David Garske 0baae6b318 Added boot benchmark support to update_flash.c. 2026-04-28 14:58:42 +02:00
David Garske 08232a61a1 ZynqMP: revert WOLFBOOT_ORIGIN to 0x8000000
The previous commit moved WOLFBOOT_ORIGIN from 0x8000000 to 0x10000000
to match the linker script, but WOLFBOOT_LOAD_ADDRESS is also 0x10000000.
This causes wolfBoot to overwrite itself when loading the firmware image
(32MB FIT written to 0x10000000 overwrites wolfBoot's .text at the same
address mid-read, hanging the boot).

Revert to 0x8000000 (128MB, same as U-Boot) and update linker script to
match. WOLFBOOT_LOAD_ADDRESS at 0x10000000 is safely above wolfBoot's
2MB footprint at 0x8000000-0x8200000.
2026-04-28 14:55:06 +02:00
David Garske cbaecdd5d8 Peer review fixes + ZynqMP robustness improvements
hal/zynq.c:
  - Route IOU_TAPDLY_BYPASS writes through pmu_request at EL<=2 in the
    <=40 MHz and <=100 MHz branches (previously only done at <=150 MHz);
    the register is equally unwritable from EL2/EL1 at lower clocks.
  - Add qspi_flash_reset() (RESET_ENABLE 0x66 + RESET_MEMORY 0x99),
    called per chip in qspi_init so the flash starts from a known state
    regardless of what FSBL/BootROM left behind (XIP, 4-byte addr,
    auto-boot).
  - Drop unused 'reg' in csu_aes and 'ms' in csu_init so
    -Werror=unused-variable builds (OPTIMIZATION_LEVEL=0 / DEBUG=1) pass.

hal/zynq.ld:
  - Move wolfBoot ORIGIN from 0x08000000 to 0x10000000. Large FIT images
    (kernel load=0x00200000, payload >~126 MB) would sweep across
    0x08000000 at handoff and overwrite wolfBoot's own code.

tools/scripts/zcu102/zcu102-ca53-qspi.cmm:
  - Rewrite against the Lauterbach TRACE32 ZCU102 QSPI demo: PREPAREONLY
    entry mode, single/dual toggle, READ_ID_TEST, separate flash dialogs
    for BOOT.BIN (offset 0) and test-app/image_v1_signed.bin.
  - Document the ~128 MB TRACE32 temp-memory ceiling on FLASHFILE.Create:
    larger files must be split externally and loaded in chunks.
2026-04-28 14:55:06 +02:00
David Garske 75439c7a87 Removed the redundant "FDT: Setting bootargs" print 2026-04-28 14:55:06 +02:00
David Garske c2f187dadd ZynqMP ZCU102 SD-card Linux boot: EL2 cleanup, DTS bootargs, SDHCI init
Add the pieces needed to boot Linux end-to-end from the ZCU102 SD card
with wolfBoot at EL2:

* src/boot_aarch64_start.S: new el2_flush_and_disable_mmu helper that
  cleans D-cache to PoC, invalidates I-cache to PoU, and clears
  SCTLR_EL2.{M,C,I}, then returns. Satisfies the ARM64 Linux boot
  protocol and is also correct for any other payload that sets up its
  own translation (hypervisor, RTOS, later bootloader stage).
* src/boot_aarch64.c: call el2_flush_and_disable_mmu from do_boot() on
  the EL2 direct-jump path before falling through to the br x4 block.
  Also pull in hal/zynq.h and hal/nxp_ls1028a.h so the EL_HYPERVISOR /
  BOOT_EL1 guards compile for those targets.
* hal/zynq.c: implement hal_dts_fixup() — set /chosen/bootargs from
  LINUX_BOOTARGS (with a LINUX_BOOTARGS_ROOT default of /dev/mmcblk0p4)
  and grow DTB totalsize by 512 bytes to give fdt_setprop() headroom
  (matches hal/versal.c). Add hal_get_timer_us() via CNTPCT_EL0.
* src/sdhci.c: add a 1 ms settling delay after sdhci_platform_init()
  and a CMD0 retry loop (up to 10 x 10 ms) so the ZCU102 Arasan
  controller reliably detects the card after the slot-type change +
  soft reset.
* config/examples/zynqmp_sdcard.config: stay at EL2 by default (comment
  out BOOT_EL1), default rootfs to /dev/mmcblk0p4, turn DEBUG off.
* hal/versal.c: correct the default LINUX_BOOTARGS_ROOT to
  /dev/mmcblk0p4 to match the shipped MBR layout.
* docs/Targets.md: note the unconditional EL2 cleanup in the ZynqMP
  and Versal SD-card sections.

Behavior change: non-Linux AArch64 EL2 payloads now enter with MMU
off and caches clean instead of inheriting wolfBoot's tables. No
in-tree payload relies on the old state leakage.
2026-04-28 14:55:06 +02:00
Thomas Cook d2ef348763 Rework rng a bit 2026-04-27 17:30:42 +02:00