[PATCH -next] initramfs: Add CRC32 debugging mechanism for unpack failures
From: Xueqin Luo
Date: Thu May 28 2026 - 05:42:05 EST
Some motherboards report high probability unpack initramfs failed,
resulting in the system cannot start normally. The error is as follows:
[ 9.400739][ 0] [ T11] Trying to unpack rootfs image as initramfs...
[ 9.408430][ 5] [ T1] calling register_arm64_panic_block+0x0/0x40 @ 1
[ 9.417144][ 0] [ T11] Initramfs unpacking failed: junk at the end of compressed archive
Initramfs unpacking failures can be difficult to diagnose because it is
often unclear whether the initrd image was corrupted before unpacking or
whether the decompressor failed while processing a valid image.
Add an optional debugging mode that computes and prints a CRC32 checksum
of the external initrd before unpacking.
Comparing the CRC32 value across multiple boot attempts may help
distinguish between corrupted initrd contents and decompression failures.
This patch does not change the default boot behavior unless explicitly
enabled through the "initramfs_debug=1" kernel command-line parameter.
Co-developed-by: xiongxin <xiongxin@xxxxxxxxxx>
Signed-off-by: xiongxin <xiongxin@xxxxxxxxxx>
Signed-off-by: Xueqin Luo <luoxueqin@xxxxxxxxxx>
---
init/initramfs.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/init/initramfs.c b/init/initramfs.c
index 20a18fcda48e..4809065aed29 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -21,6 +21,7 @@
#include <linux/types.h>
#include <linux/umh.h>
#include <linux/utime.h>
+#include <linux/crc32.h>
#include <asm/byteorder.h>
@@ -30,6 +31,9 @@
static __initdata bool csum_present;
static __initdata u32 io_csum;
+static bool initramfs_debug;
+core_param(initramfs_debug, initramfs_debug, bool, 0400);
+
static ssize_t __init xwrite(struct file *file, const unsigned char *p,
size_t count, loff_t *pos)
{
@@ -716,6 +720,20 @@ static void __init populate_initrd_image(char *err)
}
#endif /* CONFIG_BLK_DEV_RAM */
+/*
+ * Record a CRC32 checksum of the initrd contents for diagnostics.
+ */
+static void debug_initrd_crc32(const void *data, size_t len)
+{
+ u32 crc;
+
+ pr_info("initramfs: integrity diagnostics enabled\n");
+
+ crc = crc32_le(~0, data, len);
+
+ pr_info("initramfs: external initrd CRC32 checksum: %08x\n", crc);
+}
+
static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
{
/* Load the built in initramfs */
@@ -726,6 +744,10 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
if (!initrd_start || IS_ENABLED(CONFIG_INITRAMFS_FORCE))
goto done;
+ if (initramfs_debug)
+ debug_initrd_crc32((char *)initrd_start,
+ initrd_end - initrd_start);
+
if (IS_ENABLED(CONFIG_BLK_DEV_RAM))
printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
else
--
2.43.0