Bug#831003: support gzip'd kernel image
On Thu, 23 May 2019 10:36:15 -0700 Vagrant Cascadian wrote: Untested and refreshed patch against current git attached. I wanted to extend this, but I ended up almost completely rewriting it: https://salsa.debian.org/installer-team/flash-kernel/merge_requests/15/ Instead of only using a compressed kernel as-is, my implementation can also decompress/recompress into a preferred format, with many more compression types. Regardless of my MR, +compress_type() { +local file="$1" +magic="$(od -x -N2 $file | head -1 | cut -d' ' -f2)" If compress_type is called without an argument, od reads from stdin which might cause flash-kernel to 'hang' unexpectedly. Quoting "$file" instead exits in error.
Bug#831003: support gzip'd kernel image
On 2016-07-13, dann frazier wrote: > flash-kernel currently always sets the compression type to "none" when > generating uImages. However, if the source vmlinuz file is gzip'd - as > is the case if you build the "Image.gz" kernel target - this will > prevent U-Boot from being able to boot it[1]. If the uImage is > generated with a compression type of "gzip", then it boots fine. > > The attached patch checks the source image type and sets the > compression setting appropriately. > > [1] At least, this is true on APM Mustang systems Sorry for the long delay... Untested and refreshed patch against current git attached. live well, vagrant From 846e0fec533875605d58a93aa0680fcc31c06c62 Mon Sep 17 00:00:00 2001 From: dann frazier Date: Thu, 23 May 2019 10:26:06 -0700 Subject: [PATCH] support gzip'd kernel image (Closes: #831003). (Refreshed: Vagrant Cascadian flash-kernel 3.99~) --- functions | 18 +- test_functions | 25 + 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 1533192..44bc822 100644 --- a/functions +++ b/functions @@ -432,15 +432,31 @@ get_kernel_cmdline_defaults() { echo "$LINUX_KERNEL_CMDLINE_DEFAULTS" } +compress_type() { +local file="$1" +magic="$(od -x -N2 $file | head -1 | cut -d' ' -f2)" +case $magic in +8b1f) +echo "gzip" +;; +*) +echo "none" +;; +esac +} + mkimage_kernel() { local kaddr="$1" local epoint="$2" local kdesc="$3" local kdata="$4" local uimage="$5" + local comp + + comp="$(compress_type $kdata)" printf "Generating kernel u-boot image... " >&2 - mkimage -A "$mkarch" -O linux -T kernel -C none -a "$kaddr" -e "$epoint" \ + mkimage -A "$mkarch" -O linux -T kernel -C "$comp" -a "$kaddr" -e "$epoint" \ -n "$kdesc" -d "$kdata" "$uimage" >&2 1>/dev/null echo "done." >&2 } diff --git a/test_functions b/test_functions index eeea52f..74f7880 100755 --- a/test_functions +++ b/test_functions @@ -561,7 +561,9 @@ test_set_machine_id() { } add_test test_set_machine_id -test_mkimage_kernel() { +_test_mkimage_kernel() { +local kdata="$1" +local expected="$2" ( mkimage() { saved_args="$@" @@ -569,16 +571,31 @@ test_mkimage_kernel() { . "$functions" saved_args="" mkarch="arm" -mkimage_kernel "0xdeadbeef" "0xbaddcafe" "desc" "input" "output" 2>/dev/null -expected="-A arm -O linux -T kernel -C none -a 0xdeadbeef -e 0xbaddcafe -n desc -d input output" +mkimage_kernel "0xdeadbeef" "0xbaddcafe" "desc" "$kdata" "output" 2>/dev/null if [ "$expected" != "$saved_args" ]; then echo "Expected mkimage_kernel to be called with \"$expected\" but it was called with \"$saved_args\"" >&2 -exit 1 +return 1 fi ) } + +test_mkimage_kernel() { +local kdata="/dev/zero" +local expected="-A arm -O linux -T kernel -C none -a 0xdeadbeef -e 0xbaddcafe -n desc -d $kdata output" +_test_mkimage_kernel "$kdata" "$expected" || exit 1 +} add_test test_mkimage_kernel +test_mkimage_kernel_gzip() { +local kdata="$(mktemp)" +gzip < /dev/null > "$kdata" + +local expected="-A arm -O linux -T kernel -C gzip -a 0xdeadbeef -e 0xbaddcafe -n desc -d $kdata output" +_test_mkimage_kernel "$kdata" "$expected" || exit 1 +rm -f "$kdata" +} +add_test test_mkimage_kernel_gzip + test_mkimage_initrd() { ( mkimage() { -- 2.20.1 signature.asc Description: PGP signature
Bug#831003: support gzip'd kernel image
Package: flash-kernel Version: 3.67 Tags: patch flash-kernel currently always sets the compression type to "none" when generating uImages. However, if the source vmlinuz file is gzip'd - as is the case if you build the "Image.gz" kernel target - this will prevent U-Boot from being able to boot it[1]. If the uImage is generated with a compression type of "gzip", then it boots fine. The attached patch checks the source image type and sets the compression setting appropriately. [1] At least, this is true on APM Mustang systems diff -urpN flash-kernel-3.67/debian/changelog flash-kernel-3.68/debian/changelog --- flash-kernel-3.67/debian/changelog 2016-06-20 00:20:31.0 -0600 +++ flash-kernel-3.68/debian/changelog 2016-07-13 09:33:53.714642651 -0600 @@ -1,3 +1,9 @@ +flash-kernel (3.68) UNRELEASED; urgency=medium + + * Add support for gzip-compressed kernel images + + -- dann frazierWed, 13 Jul 2016 09:22:49 -0600 + flash-kernel (3.67) unstable; urgency=medium [ Vagrant Cascadian ] diff -urpN flash-kernel-3.67/functions flash-kernel-3.68/functions --- flash-kernel-3.67/functions 2016-04-01 21:01:45.0 -0600 +++ flash-kernel-3.68/functions 2016-07-13 09:25:43.520547829 -0600 @@ -409,15 +409,31 @@ get_kernel_cmdline_defaults() { echo "$LINUX_KERNEL_CMDLINE_DEFAULTS" } +compress_type() { +local file="$1" +magic="$(od -x -N2 $file | head -1 | cut -d' ' -f2)" +case $magic in + 8b1f) + echo "gzip" + ;; + *) + echo "none" + ;; +esac +} + mkimage_kernel() { local kaddr="$1" local epoint="$2" local kdesc="$3" local kdata="$4" local uimage="$5" + local comp + + comp="$(compress_type $kdata)" printf "Generating kernel u-boot image... " >&2 - mkimage -A arm -O linux -T kernel -C none -a "$kaddr" -e "$epoint" \ + mkimage -A arm -O linux -T kernel -C $comp -a "$kaddr" -e "$epoint" \ -n "$kdesc" -d "$kdata" "$uimage" >&2 1>/dev/null echo "done." >&2 } diff -urpN flash-kernel-3.67/test_functions flash-kernel-3.68/test_functions --- flash-kernel-3.67/test_functions 2016-02-14 21:01:43.0 -0700 +++ flash-kernel-3.68/test_functions 2016-07-13 09:28:35.812630206 -0600 @@ -569,23 +569,40 @@ test_set_machine_id() { } add_test test_set_machine_id -test_mkimage_kernel() { +_test_mkimage_kernel() { +local kdata="$1" +local expected="$2" ( mkimage() { saved_args="$@" } . "$functions" saved_args="" -mkimage_kernel "0xdeadbeef" "0xbaddcafe" "desc" "input" "output" 2>/dev/null -expected="-A arm -O linux -T kernel -C none -a 0xdeadbeef -e 0xbaddcafe -n desc -d input output" +mkimage_kernel "0xdeadbeef" "0xbaddcafe" "desc" "$kdata" "output" 2>/dev/null if [ "$expected" != "$saved_args" ]; then echo "Expected mkimage_kernel to be called with \"$expected\" but it was called with \"$saved_args\"" >&2 -exit 1 +return 1 fi ) } + +test_mkimage_kernel() { +local kdata="/dev/zero" +local expected="-A arm -O linux -T kernel -C none -a 0xdeadbeef -e 0xbaddcafe -n desc -d $kdata output" +_test_mkimage_kernel "$kdata" "$expected" || exit 1 +} add_test test_mkimage_kernel +test_mkimage_kernel_gzip() { +local kdata="$(mktemp)" +gzip < /dev/null > "$kdata" + +local expected="-A arm -O linux -T kernel -C gzip -a 0xdeadbeef -e 0xbaddcafe -n desc -d $kdata output" +_test_mkimage_kernel "$kdata" "$expected" || exit 1 +rm -f "$kdata" +} +add_test test_mkimage_kernel_gzip + test_mkimage_initrd() { ( mkimage() {