Skip to content

Commit cd8e9d6

Browse files
jannaumarcan
authored andcommitted
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 <[email protected]>
1 parent 54f44be commit cd8e9d6

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/payload.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ static const u8 kernel_magic[] = {'A', 'R', 'M', 0x64}; // at 0x38
2727
static const u8 cpio_magic[] = {'0', '7', '0', '7', '0'}; // '1' or '2' next
2828
static const u8 img4_magic[] = {0x16, 0x04, 'I', 'M', 'G', '4'}; // IA5String 'IMG4'
2929
static const u8 sig_magic[] = {'m', '1', 'n', '1', '_', 's', 'i', 'g'};
30+
static const u8 initramfs_magic[] = {
31+
'm', '1', 'n', '1', '_', 'i', 'n',
32+
'i', 't', 'r', 'a', 'm', 'f', 's'}; // followed by size as little endian uint32_t
3033
static const u8 empty[] = {0, 0, 0, 0};
3134

3235
static char expect_compatible[256];
@@ -228,6 +231,12 @@ static void *load_one_payload(void *start, size_t size)
228231

229232
printf("Found a m1n1 signature at %p, skipping 0x%x bytes\n", p, size);
230233
return p + size;
234+
} else if (!memcmp(p, initramfs_magic, sizeof(initramfs_magic))) {
235+
u32 size;
236+
memcpy(&size, p + sizeof(initramfs_magic), 4);
237+
printf("Found a m1n1 initramfs payload at %p, 0x%x bytes\n", p, size);
238+
p += sizeof(initramfs_magic) + 4;
239+
return load_cpio(p, size);
231240
} else if (check_var(&p)) {
232241
return p;
233242
} else if (!memcmp(p, empty, sizeof empty) ||

0 commit comments

Comments
 (0)