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 <j@jannau.net>
This commit is contained in:
Janne Grunau 2022-10-01 18:31:52 +02:00 committed by Hector Martin
parent 54f44be7d6
commit cd8e9d6676

View file

@ -27,6 +27,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];
@ -228,6 +231,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) ||