Commit Graph

484 Commits (8a70a830391ed6031d91c27f0b1ce1b8ff8ddf24)

Author SHA1 Message Date
Daniele Lacamera d1df8b2df0 Fix initialization of string in otp_keystore tag (fix build error)
Emerged in newer gcc15, due to -Wunterminated-string-initialization
added to -Wall
2026-05-06 10:22:59 +02:00
Brett Nicholas 627e0664a2 fix include order for unit tests 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 9ca1d435b9 Peer review fixes (copilot)
src/fdt.c, include/fdt.h
  - Propagate fdt_fixup_initrd error in fit_load_ramdisk so a /chosen
    patch failure no longer silently boots a kernel with no initrd.
  - Add fit_load_image_to(): decompress (or memcpy) directly to a
    caller-supplied destination buffer instead of going through the
    FIT-declared `load` address. fit_load_ramdisk now uses this when
    WOLFBOOT_LOAD_RAMDISK_ADDRESS is set, so the override is a real
    safety bound for compressed ramdisks (previously the gzip stream
    was still inflated to the FIT `load` and only memcpy'd afterward).
  - Refactor fit_load_image_ex into a shared inner helper.
  - Reword the WOLFBOOT_FIT_MAX_DECOMP comment: the cap is a sanity
    ceiling, not a per-destination memory-safety bound. Authenticity
    is provided by the outer wolfBoot signature; tighter bounds need
    fit_load_image_ex / _to with an explicit out_max / dst_max.
  - Add WOLFBOOT_FIT_MAX_RAMDISK (defaults to WOLFBOOT_FIT_MAX_DECOMP)
    so targets can pin a tighter ramdisk decompression bound.

src/update_ram.c, src/update_disk.c
  - Panic when fit_load_image() returns NULL for the kernel subimage
    instead of letting load_address=NULL propagate into do_boot().

tools/unit-tests/unit-gzip.c
  - Add deterministic stored / fixed-Huffman / dynamic-Huffman gzip
    fixtures so the inflater's BTYPE 00/01/10 paths are exercised
    independent of host gzip(1) heuristics.
  - Add FEXTRA / FNAME / FCOMMENT / FHCRC and combined-flag fixtures
    plus a truncated-FEXTRA negative case to cover the optional gzip
    header parser.

tools/unit-tests/unit-fit-gzip.c (new), tools/unit-tests/Makefile
  - New libcheck binary covering the FIT loader's compression
    branches: gzip success, gzip stream corruption, unknown
    compression, compression="none" baseline, and the no-load
    fail-closed path. Built twice from the same source - once with
    WOLFBOOT_GZIP for the success / runtime-failure paths, and once
    without it so the compile-time fail-closed branch is also tested.
2026-05-05 10:16:16 +02:00
David Garske d92053037c Fixes from peer review (Thank you Daniele and Marco) 2026-05-05 10:16:16 +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 090f0ef411 gzip: add clean-room RFC 1951/1952 inflater + libcheck tests
New src/gzip.c implements DEFLATE (RFC 1951) plus the gzip wrapper
(RFC 1952) from the RFC text only. Single-pass inflate, no allocations:
the output buffer doubles as the LZ77 sliding window, so back-references
read from out[out_pos - distance]. Canonical Huffman decode using
counts[] / symbols[] tables, ~10x smaller code than fast lookup tables
which matters in the bootloader. CRC32 + ISIZE verified against the
gzip trailer. Gated by WOLFBOOT_GZIP.

include/gzip.h carries the public entry point plus the RFC-canonical
constants (magic bytes, CM=DEFLATE, fixed Huffman boundaries, EOB
symbol, dynamic block field widths, run-length repeat metadata, CRC32
init/final-XOR, header/trailer sizes, alphabet sizes) so future
maintainers can cross-reference the RFC sections by name instead of
chasing literal numbers.

Tests in tools/unit-tests/unit-gzip.c round-trip 6 corpora through host
gzip(1) and back through wolfBoot_gunzip (empty, short text, all-zeros,
structured text, pseudo-random, ~2 MB kernel-sized). 9 negative cases
cover bad magic, bad CM, reserved FLG bits, truncated header,
truncated DEFLATE body, CRC32 mismatch, ISIZE mismatch, output overflow,
and NULL parameters. All 15 pass under libcheck.
2026-05-05 10:16:16 +02:00
Daniele Lacamera dfc7656071 Validate GPT partition array CRC
F/3045
2026-04-29 12:10:02 +02:00
Brett Nicholas c02019be68 rename aggregate RSA PSS macro, add Renesas protection 2026-04-28 15:02:57 +02:00
Brett Nicholas 182844b7a1 unify rsa and rsa-pss into single verify method 2026-04-28 15:02:57 +02:00
Brett Nicholas 1f72804143 support rsa-pss in ARMORED mode 2026-04-28 15:02:57 +02:00
Brett Nicholas 65d84a29ec Add SW-only RSA PSS 2026-04-28 15:02:57 +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 f2fe1f42fa ZynqMP ZCU102 SD-card boot fixes 2026-04-28 14:55:06 +02:00
Thomas Cook d3a3edede5 fix hash testing 2026-04-27 17:30:42 +02:00
Thomas Cook b545979da0 address several pr issues 2026-04-27 17:30:42 +02:00
Thomas Cook 8d3f459d20 Regression test fixes 2026-04-27 17:30:42 +02:00
Thomas Cook 01270723cf turn on other aes algs for test/benchmark 2026-04-27 17:30:42 +02:00
Thomas Cook e83f61c9db Add benchmark and test capability to test-app 2026-04-27 17:30:42 +02:00
Daniele Lacamera cffa75d4a4 Proper interface renaming + documentation 2026-04-22 14:14:28 +02:00
Daniele Lacamera b22c85ed27 Added support for fTPM in TrustZone + STM32H5 test app 2026-04-21 20:53:48 +02:00
Brett Nicholas 2e7839e4ee add additional check for DELTA_UPDATE + DISABLE_BACKUP incompatibility 2026-04-17 08:27:05 +02:00
Brett Nicholas c45268ed7f monolithic self-updates: force DISABLE_BACKUP=1, eliminate swap, eliminate update code 2026-04-17 08:27:05 +02:00
Daniele Lacamera 776378ca78 Preparing release v2.8.0 + update copyright 2026-04-16 13:11:56 +02:00
Daniele Lacamera 9ac6b1f485 Fixed more regressions 2026-04-14 16:47:11 +02:00
Daniele Lacamera 4c0f425a7a Fix WOLFBOOT_MAX_SPACE precedence and test
F/2587
2026-04-14 14:28:44 +02:00
Daniele Lacamera 41ffb2c637 Add partition overlap guards
F/2571
2026-04-14 07:55:26 +02:00
Daniele Lacamera 3697f9e335 image: use portable noinline macro
F/2273
2026-04-10 21:39:19 +02:00
Daniele Lacamera c1b2c40a40 image: restore ct compare contract
Make image_CT_compare return 0 on match again and update RSA hash checks plus delta base-hash validation to use the original semantics.

F/CI
2026-04-10 21:22:26 +02:00
Daniele Lacamera 0d6ad205d7 tpm: localize constant compare again
Restore wolfBoot_constant_compare to TPM-local code and use file-local helpers in update_flash and AHCI instead of a shared cross-module symbol.

F/CI
2026-04-10 06:17:41 +02:00
Daniele Lacamera 087ff9016c image: fix hardened hash compare sense
Use image_CT_compare directly in the protected RSA_VERIFY_HASH macro so signature confirmation only follows a real digest match.

F/CI
2026-04-10 05:59:18 +02:00
Daniele Lacamera 8033366c3e core: make constant compare common
Move wolfBoot_constant_compare out of TPM-only code so AHCI and update paths can use it without TPM feature gating.

F/CI
2026-04-10 05:48:36 +02:00
Daniele Lacamera fff5222e2d hal: document flash protect API contract 2026-04-09 14:54:14 +02:00
Daniele Lacamera fc9e7a3e8a Use constant-time delta base hash compare
F/2253
2026-04-08 19:53:50 +02:00
Daniele Lacamera f5d50d4257 enforce skip-verify prerequisites
F/2256
2026-04-08 19:53:50 +02:00
Daniele Lacamera 1528bc8d99 Use constant-time TPM secret checks
F/2248
2026-04-08 19:53:50 +02:00
Daniele Lacamera 44c5b4ab0a Protect bootloader before application boot
F/2255
2026-04-08 19:53:50 +02:00
Daniele Lacamera 9715b4df26 Use constant-time RSA hash comparison
F/2247
2026-04-08 19:53:50 +02:00
Brett Nicholas 9debc4c559 Fix XMSS and ML_DSA keygen type mismatch between image headers and keystore by unifying AUTH_KEY_*/KEYGEN_* constants 2026-03-30 16:32:44 +02:00
Paul Adelsbach 3d2a555e1a Update wolfHSM pointer, fix minor issues 2026-03-23 20:05:07 +01:00
Daniele Lacamera 5f919c1b2e Updated submodules 2026-03-20 14:57:43 +01:00
David Garske a56c70e90a Support for NXP T1040 RDB 2026-03-20 14:51:15 +01:00
Mattia Moffa b5fab30310 Enable NSC veneers when TZEN=1, even without WOLFCRYPT_TZ 2026-03-18 22:26:32 +01:00
Mattia Moffa fcf72e008c Remove NO_DIRECT_READ_OF_ERASED_SECTOR option; write after erase instead 2026-03-18 11:53:26 +01:00
Thomas Cook 3b1ef9d6bc Address copilot pr comments. 2026-03-18 11:53:26 +01:00
Thomas Cook dd4312679b Deploy NO_DIRECT_READ_OF_ERASED_SECTOR to protect against hardfault with AHB read of erased sector. 2026-03-18 11:53:26 +01:00
Mattia Moffa 0656ff4afa Nordic nrf54l port (with and without TrustZone) 2026-03-18 09:15:00 +01:00
Daniele Lacamera 180e53b186 Fix regression in WOLFBOOT_RAMBOOT_MAX_SIZE 2026-03-12 09:28:51 +01:00
Daniele Lacamera 4eca085b54 Added USE_CLANG option to Makefile 2026-03-10 15:49:45 +01:00