Skip to content

Commit a525698

Browse files
committed
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.
1 parent 102c6c9 commit a525698

17 files changed

Lines changed: 397 additions & 21 deletions

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ include/target.h: $(TARGET_H_TEMPLATE) FORCE
638638
sed -e "s/@WOLFBOOT_DTS_UPDATE_ADDRESS@/$(WOLFBOOT_DTS_UPDATE_ADDRESS)/g" | \
639639
sed -e "s/@WOLFBOOT_LOAD_ADDRESS@/$(WOLFBOOT_LOAD_ADDRESS)/g" | \
640640
sed -e "s/@WOLFBOOT_LOAD_DTS_ADDRESS@/$(WOLFBOOT_LOAD_DTS_ADDRESS)/g" | \
641+
sed -e "s/@WOLFBOOT_LOAD_RAMDISK_ADDRESS@/$(WOLFBOOT_LOAD_RAMDISK_ADDRESS)/g" | \
641642
sed -e "s|@WOLFBOOT_RAMBOOT_MAX_SIZE_DEFINE@|$(if $(strip $(WOLFBOOT_RAMBOOT_MAX_SIZE)),#define WOLFBOOT_RAMBOOT_MAX_SIZE $(WOLFBOOT_RAMBOOT_MAX_SIZE),/* WOLFBOOT_RAMBOOT_MAX_SIZE undefined */)|g" | \
642643
sed -e "s/@WOLFBOOT_PARTITION_SELF_HEADER_ADDRESS@/$(WOLFBOOT_PARTITION_SELF_HEADER_ADDRESS)/g" \
643644
> $@

config/examples/polarfire_mpfs250.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ WOLFTPM?=0
4646
ELF?=1
4747
#DEBUG_ELF?=1
4848

49+
# Native gzip decompression for FIT subimages (set GZIP=0 to disable)
50+
GZIP?=1
51+
4952
# Use RISC-V assembly version of ECDSA and SHA
5053
NO_ASM?=0
5154

config/examples/polarfire_mpfs250_qspi.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ WOLFTPM?=0
3535
ELF?=1
3636
#DEBUG_ELF?=1
3737

38+
# Native gzip decompression for FIT subimages (set GZIP=0 to disable)
39+
GZIP?=1
40+
3841
# Use RISC-V assembly version of ECDSA and SHA
3942
NO_ASM?=0
4043

config/examples/versal_vmk180.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ NO_XIP=1
5959
# ELF loading support
6060
ELF?=1
6161

62+
# Native gzip decompression for FIT subimages (set GZIP=0 to disable)
63+
GZIP?=1
64+
6265
# Toolchain
6366
USE_GCC=1
6467
CROSS_COMPILE=aarch64-none-elf-

config/examples/versal_vmk180_sdcard.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ NO_XIP=1
3333
# ELF loading support
3434
ELF?=1
3535

36+
# Native gzip decompression for FIT subimages (set GZIP=0 to disable)
37+
GZIP?=1
38+
3639
# Boot Benchmarking (optional)
3740
BOOT_BENCHMARK?=1
3841

config/examples/zynqmp.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ USE_GCC=1
5858
ELF?=1
5959
#DEBUG_ELF?=1
6060

61+
# Native gzip decompression for FIT subimages (set GZIP=0 to disable)
62+
GZIP?=1
63+
6164
# Flash Sector Size
6265
WOLFBOOT_SECTOR_SIZE=0x20000
6366
# Application Partition Size

config/examples/zynqmp_sdcard.config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ NO_XIP=1
4343
ELF?=1
4444
#DEBUG_ELF?=1
4545

46+
# Native gzip decompression for FIT subimages (set GZIP=0 to disable)
47+
GZIP?=1
48+
4649
# Boot Exception Level: leave wolfBoot at EL2 for handoff to Linux (matches
4750
# the standard PetaLinux U-Boot flow and preserves KVM/hypervisor use of
4851
# EL2). The EL2 Linux-cleanup path in do_boot() will clean dcache/disable
@@ -100,6 +103,21 @@ CFLAGS_EXTRA+=-DDISK_BLOCK_SIZE=0x80000
100103
# Check `ls /sys/class/mmc_host/` on your running target to confirm.
101104
CFLAGS_EXTRA+=-DLINUX_BOOTARGS_ROOT=\"/dev/mmcblk0p4\"
102105

106+
# ============================================================================
107+
# Optional: FIT-bundled initramfs (ramdisk) instead of an on-disk rootfs
108+
# ============================================================================
109+
# Expects the PetaLinux INITRAMFS_IMAGE_BUNDLE=0 layout (FIT contains kernel
110+
# + DTB + ramdisk). wolfBoot extracts the ramdisk to
111+
# WOLFBOOT_LOAD_RAMDISK_ADDRESS and patches the loaded DTB with
112+
# /chosen/linux,initrd-{start,end} so the kernel can find it. Compressed
113+
# (gzip) ramdisks decompress automatically when GZIP=1.
114+
#
115+
# To enable: uncomment the three lines below and comment out the
116+
# LINUX_BOOTARGS_ROOT line above (root= is supplied by the cpio's /init).
117+
#RAMDISK?=1
118+
#WOLFBOOT_LOAD_RAMDISK_ADDRESS?=0x40000000
119+
#CFLAGS_EXTRA+=-DLINUX_BOOTARGS='"earlycon console=ttyPS0,115200 init_fatal_sh=1"'
120+
103121
# ============================================================================
104122
# Boot Memory Layout
105123
# ============================================================================

hal/versal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,8 +1276,9 @@ int hal_dts_fixup(void* dts_addr)
12761276
wolfBoot_printf("FDT: Version %d, Size %d\n",
12771277
fdt_version(fdt), fdt_totalsize(fdt));
12781278

1279-
/* Expand total size to allow adding/modifying properties */
1280-
fdt_set_totalsize(fdt, fdt_totalsize(fdt) + 512);
1279+
/* Expand total size to allow adding/modifying properties (bootargs and,
1280+
* when WOLFBOOT_FIT_RAMDISK is in play, linux,initrd-{start,end}). */
1281+
fdt_set_totalsize(fdt, fdt_totalsize(fdt) + 768);
12811282

12821283
/* Find /chosen node; create it only if genuinely missing. Any other
12831284
* negative return (malformed FDT, etc.) is surfaced directly rather

hal/zynq.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,11 +1927,12 @@ int hal_dts_fixup(void* dts_addr)
19271927
fdt_version(fdt), fdt_totalsize(fdt));
19281928

19291929
/* Expand totalsize so fdt_setprop() has in-blob free space to place
1930-
* a new/larger bootargs property. Physical headroom is already
1931-
* guaranteed by the load-address layout (DTB at WOLFBOOT_LOAD_DTS_ADDRESS,
1932-
* kernel loaded much higher), so growing the header is safe. Matches
1933-
* the pattern used in hal/versal.c:hal_dts_fixup. */
1934-
fdt_set_totalsize(fdt, fdt_totalsize(fdt) + 512);
1930+
* a new/larger bootargs property and (when WOLFBOOT_FIT_RAMDISK is in
1931+
* play) the linux,initrd-{start,end} properties. Physical headroom is
1932+
* already guaranteed by the load-address layout (DTB at
1933+
* WOLFBOOT_LOAD_DTS_ADDRESS, kernel loaded much higher), so growing
1934+
* the header is safe. Matches the pattern in hal/versal.c. */
1935+
fdt_set_totalsize(fdt, fdt_totalsize(fdt) + 768);
19351936

19361937
/* Find /chosen node; create it only if genuinely missing. Any other
19371938
* negative return (malformed FDT, etc.) is surfaced directly rather

include/fdt.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,15 @@ int fdt_fixup_val64(void* fdt, int off, const char* node, const char* name, uint
158158
int fdt_shrink(void* fdt);
159159

160160
/* FIT */
161-
const char* fit_find_images(void* fdt, const char** pkernel, const char** pflat_dt);
161+
const char* fit_find_images(void* fdt, const char** pkernel, const char** pflat_dt,
162+
const char** pramdisk);
162163
void* fit_load_image(void* fdt, const char* image, int* lenp);
164+
void* fit_load_image_ex(void* fdt, const char* image, int* lenp, uint32_t out_max);
165+
166+
/* FDT initrd fixup: writes /chosen/linux,initrd-{start,end} as 64-bit
167+
* big-endian properties. Creates /chosen if missing. Returns 0 on success
168+
* or a negative FDT_ERR_*. */
169+
int fdt_fixup_initrd(void* fdt, uint64_t start, uint64_t size);
163170

164171
#ifdef __cplusplus
165172
}

0 commit comments

Comments
 (0)