From a2b4a7479a71ea7c2d03aaf94cb54cf812f5f431 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sat, 1 Oct 2022 18:31:52 +0200 Subject: [PATCH] payload: Add a custom header with a payload size field for initramfs' This add supports for concatenated (compressed) cpio archives and relies on the kernel to decompress the initramfs. Signed-off-by: Janne Grunau --- src/payload.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/payload.c b/src/payload.c index 99e744cd..6c25b4a7 100644 --- a/src/payload.c +++ b/src/payload.c @@ -24,6 +24,9 @@ static const u8 kernel_magic[] = {'A', 'R', 'M', 0x64}; // at 0x38 static const u8 cpio_magic[] = {'0', '7', '0', '7', '0'}; // '1' or '2' next static const u8 img4_magic[] = {0x16, 0x04, 'I', 'M', 'G', '4'}; // IA5String 'IMG4' static const u8 sig_magic[] = {'m', '1', 'n', '1', '_', 's', 'i', 'g'}; +static const u8 initramfs_magic[] = { + 'm', '1', 'n', '1', '_', 'i', 'n', + 'i', 't', 'r', 'a', 'm', 'f', 's'}; // followed by size as little endian uint32_t static const u8 empty[] = {0, 0, 0, 0}; static char expect_compatible[256]; @@ -218,6 +221,12 @@ static void *load_one_payload(void *start, size_t size) printf("Found a m1n1 signature at %p, skipping 0x%x bytes\n", p, size); return p + size; + } else if (!memcmp(p, initramfs_magic, sizeof(initramfs_magic))) { + u32 size; + memcpy(&size, p + sizeof(initramfs_magic), 4); + printf("Found a m1n1 initramfs payload at %p, 0x%x bytes\n", p, size); + p += sizeof(initramfs_magic) + 4; + return load_cpio(p, size); } else if (check_var(&p)) { return p; } else if (!memcmp(p, empty, sizeof empty) ||