* [PATCH v2 0/1] scripts: add zboot support to extract-vmlinux @ 2025-07-11 16:26 Jeremy Linton 2025-07-11 16:26 ` [PATCH v2 1/1] " Jeremy Linton 0 siblings, 1 reply; 5+ messages in thread From: Jeremy Linton @ 2025-07-11 16:26 UTC (permalink / raw) To: linux-kbuild Cc: masahiroy, nathan, nicolas.schier, linux-kernel, Jeremy Linton Enhance the extract-vmlinux script for use with EFI_ZBOOT compressed images. v1->v2: Merge 'file' check with its 'if' condition. Invert the resulting condition and move copy block inside. Tweak the commit message to clarify arm/arm64 as well as how recent of a 'file' command is needed. Jeremy Linton (1): scripts: add zboot support to extract-vmlinux scripts/extract-vmlinux | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) -- 2.50.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/1] scripts: add zboot support to extract-vmlinux 2025-07-11 16:26 [PATCH v2 0/1] scripts: add zboot support to extract-vmlinux Jeremy Linton @ 2025-07-11 16:26 ` Jeremy Linton 2025-07-12 15:47 ` Masahiro Yamada 0 siblings, 1 reply; 5+ messages in thread From: Jeremy Linton @ 2025-07-11 16:26 UTC (permalink / raw) To: linux-kbuild Cc: masahiroy, nathan, nicolas.schier, linux-kernel, Jeremy Linton 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> --- scripts/extract-vmlinux | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/extract-vmlinux b/scripts/extract-vmlinux index 8995cd304e6e..049bab337f0e 100755 --- a/scripts/extract-vmlinux +++ b/scripts/extract-vmlinux @@ -12,13 +12,12 @@ 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() -- 2.50.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] scripts: add zboot support to extract-vmlinux 2025-07-11 16:26 ` [PATCH v2 1/1] " Jeremy Linton @ 2025-07-12 15:47 ` Masahiro Yamada 2025-07-12 18:49 ` Jeremy Linton 0 siblings, 1 reply; 5+ messages in thread From: Masahiro Yamada @ 2025-07-12 15:47 UTC (permalink / raw) To: Jeremy Linton; +Cc: linux-kbuild, nathan, nicolas.schier, linux-kernel On Sat, Jul 12, 2025 at 1:26 AM Jeremy Linton <jeremy.linton@arm.com> wrote: > > 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> > --- > scripts/extract-vmlinux | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) > > diff --git a/scripts/extract-vmlinux b/scripts/extract-vmlinux > index 8995cd304e6e..049bab337f0e 100755 > --- a/scripts/extract-vmlinux > +++ b/scripts/extract-vmlinux > @@ -12,13 +12,12 @@ > > 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' \ Sorry for my nit-picking, but I'd like to get rid of this back-slash by breaking the line _after_ the OR operator, not before. That is, if command1 || command2 then ... fi rather than if command1 \ || command2 then ... fi > + || readelf -h "$1" > /dev/null 2>&1 > + then > + cat "$1" > + exit 0 > + fi > } > > try_decompress() > -- > 2.50.1 > -- Best Regards Masahiro Yamada ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] scripts: add zboot support to extract-vmlinux 2025-07-12 15:47 ` Masahiro Yamada @ 2025-07-12 18:49 ` Jeremy Linton 2025-07-13 5:45 ` Masahiro Yamada 0 siblings, 1 reply; 5+ messages in thread From: Jeremy Linton @ 2025-07-12 18:49 UTC (permalink / raw) To: Masahiro Yamada; +Cc: linux-kbuild, nathan, nicolas.schier, linux-kernel Hi, On 7/12/25 10:47 AM, Masahiro Yamada wrote: > On Sat, Jul 12, 2025 at 1:26 AM Jeremy Linton <jeremy.linton@arm.com> wrote: >> >> 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> >> --- >> scripts/extract-vmlinux | 13 ++++++------- >> 1 file changed, 6 insertions(+), 7 deletions(-) >> >> diff --git a/scripts/extract-vmlinux b/scripts/extract-vmlinux >> index 8995cd304e6e..049bab337f0e 100755 >> --- a/scripts/extract-vmlinux >> +++ b/scripts/extract-vmlinux >> @@ -12,13 +12,12 @@ >> >> 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' \ > > Sorry for my nit-picking, but I'd like to get rid of this back-slash > by breaking the line _after_ the OR operator, not before. > > That is, > > > if command1 || > command2 > then > ... > fi > > > rather than > > if command1 \ > || command2 > then > ... > fi Moving the || is no problem, but I am/was under the impression that implicit line continuation is a posix shell gray area? Particularly when its outside of an explicit compound statement. This AFAIK was one of the things bash clarifed. > >> + || readelf -h "$1" > /dev/null 2>&1 >> + then >> + cat "$1" >> + exit 0 >> + fi >> } >> >> try_decompress() >> -- >> 2.50.1 >> > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/1] scripts: add zboot support to extract-vmlinux 2025-07-12 18:49 ` Jeremy Linton @ 2025-07-13 5:45 ` Masahiro Yamada 0 siblings, 0 replies; 5+ messages in thread From: Masahiro Yamada @ 2025-07-13 5:45 UTC (permalink / raw) To: Jeremy Linton; +Cc: linux-kbuild, nathan, nicolas.schier, linux-kernel On Sun, Jul 13, 2025 at 3:50 AM Jeremy Linton <jeremy.linton@arm.com> wrote: > > Hi, > > On 7/12/25 10:47 AM, Masahiro Yamada wrote: > > On Sat, Jul 12, 2025 at 1:26 AM Jeremy Linton <jeremy.linton@arm.com> wrote: > >> > >> 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> > >> --- > >> scripts/extract-vmlinux | 13 ++++++------- > >> 1 file changed, 6 insertions(+), 7 deletions(-) > >> > >> diff --git a/scripts/extract-vmlinux b/scripts/extract-vmlinux > >> index 8995cd304e6e..049bab337f0e 100755 > >> --- a/scripts/extract-vmlinux > >> +++ b/scripts/extract-vmlinux > >> @@ -12,13 +12,12 @@ > >> > >> 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' \ > > > > Sorry for my nit-picking, but I'd like to get rid of this back-slash > > by breaking the line _after_ the OR operator, not before. > > > > That is, > > > > > > if command1 || > > command2 > > then > > ... > > fi > > > > > > rather than > > > > if command1 \ > > || command2 > > then > > ... > > fi > > Moving the || is no problem, but I am/was under the impression that > implicit line continuation is a posix shell gray area? Particularly when > its outside of an explicit compound statement. This AFAIK was one of the > things bash clarifed. I believe this is clearly defined in POSIX [1] 2.10.2 Shell Grammar Rules: and_or : pipeline | and_or AND_IF linebreak pipeline | and_or OR_IF linebreak pipeline ; linebreak : newline_list | /* empty */ ; [1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html So, you can optionally put a linebreak after the OF_IF token ('||' operator). -- Best Regards Masahiro Yamada ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-13 5:46 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-07-11 16:26 [PATCH v2 0/1] scripts: add zboot support to extract-vmlinux Jeremy Linton 2025-07-11 16:26 ` [PATCH v2 1/1] " Jeremy Linton 2025-07-12 15:47 ` Masahiro Yamada 2025-07-12 18:49 ` Jeremy Linton 2025-07-13 5:45 ` Masahiro Yamada
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®