Update extract-vmlinux for lz4
This also adds a better workaround for arm64 so we can support multiple
decompression techniques simultaneously.
Bug: 150391496
Change-Id: Ibb81eb3f9b5ab4d9eca534f149b0a2949f1a2b7c
diff --git a/scripts/extract-vmlinux b/scripts/extract-vmlinux
index 9354943..2226fb4 100755
--- a/scripts/extract-vmlinux
+++ b/scripts/extract-vmlinux
@@ -1,4 +1,5 @@
#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-only
# ----------------------------------------------------------------------
# extract-vmlinux - Extract uncompressed vmlinux from a kernel image
#
@@ -7,7 +8,6 @@
#
# (c) 2011 Corentin Chary <corentin.chary@gmail.com>
#
-# Licensed under the GNU General Public License, version 2 (GPLv2).
# ----------------------------------------------------------------------
check_vmlinux()
@@ -15,7 +15,11 @@
# 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
+ readelf -h $1 > /dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ # On ARM64, the kernel might be a PE file instead
+ file $1 | grep -q "MS-DOS executable$" || return 1
+ fi
cat $1
exit 0
@@ -44,25 +48,21 @@
exit 2
fi
-# The kernel is an Image.gz on aarch64, so just decompress
-if [ `uname -m` = aarch64 ]; then
- gunzip < "$1"
- exit $?
-fi
-
# Prepare temp files:
tmp=$(mktemp /tmp/vmlinux-XXX)
trap "rm -f $tmp" 0
-# Initial attempt for uncompressed images or objects:
-check_vmlinux $img
-
# That didn't work, so retry after decompression.
try_decompress '\037\213\010' xy gunzip
try_decompress '\3757zXZ\000' abcde unxz
try_decompress 'BZh' xy bunzip2
try_decompress '\135\0\0\0' xxx unlzma
try_decompress '\211\114\132' xy 'lzop -d'
+try_decompress '\002!L\030' xxx 'lz4 -d'
+try_decompress '(\265/\375' xxx unzstd
+
+# Finally check for uncompressed images or objects:
+check_vmlinux $img
# Bail out:
echo "$me: Cannot find vmlinux." >&2