diff options
Diffstat (limited to 'scripts/extract-vmlinux')
| -rwxr-xr-x | scripts/extract-vmlinux | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/scripts/extract-vmlinux b/scripts/extract-vmlinux index 5061abcc2540..266df9bc7a48 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,18 +8,19 @@ # # (c) 2011 Corentin Chary <corentin.chary@gmail.com> # -# Licensed under the GNU General Public License, version 2 (GPLv2). # ---------------------------------------------------------------------- +me=${0##*/} + 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" + echo "$me: Extracted vmlinux using '$2' from offset $3" >&2 + exit 0 + fi } try_decompress() @@ -31,12 +33,11 @@ try_decompress() do pos=${pos%%:*} tail -c+$pos "$img" | $3 > $tmp 2> /dev/null - check_vmlinux $tmp + check_vmlinux $tmp "$3" $pos done } # Check invocation: -me=${0##*/} img=$1 if [ $# -ne 1 -o ! -s "$img" ] then @@ -48,15 +49,17 @@ fi 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" cat 0 # Bail out: echo "$me: Cannot find vmlinux." >&2 |
