]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
scripts: add zboot support to extract-vmlinux
authorJeremy Linton <jeremy.linton@arm.com>
Mon, 14 Jul 2025 22:29:23 +0000 (17:29 -0500)
committerMasahiro Yamada <masahiroy@kernel.org>
Sat, 26 Jul 2025 06:31:30 +0000 (15:31 +0900)
Zboot compressed kernel images are used for arm64 kernels on various
distros.

extract-vmlinux fails with those kernels because the wrapped image is
another PE. While this could be a bit confusing, the tools primary
purpose of unwrapping and decompressing the contained kernel image
makes it the obvious place for this functionality.

Add a 'file' check in check_vmlinux() that detects a contained PE
image before trying readelf. Recent (FILES_39, Jun/2020) file
implementations output something like:

"Linux kernel ARM64 boot executable Image, little-endian, 4K pages"

Which is also a stronger statement than readelf provides so drop that
part of the comment. At the same time this means that kernel images
which don't appear to contain a compressed image will be returned
rather than reporting an error. Which matches the behavior for
existing ELF files.

The extracted PE image can then be inspected, or used as would any
other kernel PE.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/extract-vmlinux

index 8995cd304e6e962fd860e72e98ce5a68b2e2bf74..189956b5a5c8c3eb7941a2adf226473a9b5f3c77 100755 (executable)
 
 check_vmlinux()
 {
-       # Use readelf to check if it's a valid ELF
-       # TODO: find a better to way to check that it's really vmlinux
-       #       and not just an elf
-       readelf -h $1 > /dev/null 2>&1 || return 1
-
-       cat $1
-       exit 0
+       if file "$1" | grep -q 'Linux kernel.*boot executable' ||
+               readelf -h "$1" > /dev/null 2>&1
+       then
+               cat "$1"
+               exit 0
+       fi
 }
 
 try_decompress()