2013-10-15 15:00:24

by Prasad Pandit

[permalink] [raw]
Subject: [Patch] Read CONFIG_RD_ variables for initramfs compression

Hello Andrew,

When expert configuration option(CONFIG_EXPERT) is enabled, menuconfig offers
choice of compression algorithm, to compress initial ramfs image. This choice
is stored into CONFIG_RD_<GZIP/BZIP2/...> variables.

But, usr/Makefile reads from earlier INITRAMFS_COMPRESSION_* variables to set
the ramfs file extension(.gzip/.bz2/...), which is later(in
scripts/gen_initramfs_list.sh) used to apply actual compression.

Since none of the INITRAMFS_COMPRESSION_* variables are defined, the resulting
'usr/initramfs_data.cpio' file remains un-compressed.

The patch attached herein, updates the usr/Makefile to read CONFIG_RD_*
variables, and also adds support for the Lz4 compression algorithm.

Could you please review it?
==
PS:
IIUC, I think INITRAMFS_COMPRESSION_* variables are not used anywhere at all.
Though I'm not sure about the EMBEDDED configurations. But if they are not
used, it could be better to remove their description/references from
usr/Kconfig and other places.


Thank you.
--
Prasad J Pandit / Red Hat Security Response Team


Attachments:
0001-Read-CONFIG_RD_-variables-for-initramfs-compression.patch (2.81 kB)

2013-10-29 22:15:11

by Andrew Morton

[permalink] [raw]
Subject: Re: [Patch] Read CONFIG_RD_ variables for initramfs compression

On Tue, 15 Oct 2013 20:25:57 +0530 (IST) P J P <[email protected]> wrote:

> When expert configuration option(CONFIG_EXPERT) is enabled,
> menuconfig offers a choice of compression algorithm to compress
> initial ramfs image; This choice is stored into CONFIG_RD_*
> variables. But usr/Makefile uses earlier INITRAMFS_COMPRESSION_*
> macros to build initial ramfs file. Since none of them is defined,
> resulting 'initramfs_data.cpio' file remains un-compressed.
>
> This patch updates the Makefile to use CONFIG_RD_* variables and
> adds support for LZ4 compression algorithm.

This patch breaks my x86_64 allmodconfig build, because I don't have
the lz4 executable installed:

/usr/src/25/scripts/gen_initramfs_list.sh: line 307: lz4: command not found
make[1]: *** [usr/initramfs_data.cpio.lz4] Error 1

This obviously isn't acceptable!

2013-10-30 10:27:44

by Prasad Pandit

[permalink] [raw]
Subject: Re: [Patch] Read CONFIG_RD_ variables for initramfs compression

Hello Andrew,

+-- On Tue, 29 Oct 2013, Andrew Morton wrote --+
| On Tue, 15 Oct 2013 20:25:57 +0530 (IST) P J P <[email protected]> wrote:
| This patch breaks my x86_64 allmodconfig build, because I don't have
| the lz4 executable installed:
|
| /usr/src/25/scripts/gen_initramfs_list.sh: line 307: lz4: command not found
| make[1]: *** [usr/initramfs_data.cpio.lz4] Error 1
|
| This obviously isn't acceptable!

Oops! '$ make allmodconfig' seems to enables all compression algorithms; So
the last one overrides the previous choices in usr/Makefile.

===
...
CONFIG_RD_GZIP=y
CONFIG_RD_BZIP2=y
CONFIG_RD_LZMA=y
CONFIG_RD_XZ=y
CONFIG_RD_LZO=y
CONFIG_RD_LZ4=y
===

Please see an updated patch herein. I've patched 'gen_initramfs_list.sh'
script to check if a selected compression command is accessible or not; And
fall-back to the default gzip(1) format when it is not. usr/Makefile also
defaults to '.gz' format when all are enabled.

I hope this works well; Sorry about the trouble though.

Thank you!
--
Prasad J Pandit / Red Hat Security Response Team


Attachments:
0001-Read-CONFIG_RD_-variables-for-initramfs-compression.patch (3.90 kB)

2013-10-30 22:05:23

by Andrew Morton

[permalink] [raw]
Subject: Re: [Patch] Read CONFIG_RD_ variables for initramfs compression

On Wed, 30 Oct 2013 15:57:20 +0530 (IST) P J P <[email protected]> wrote:

> +-- On Tue, 29 Oct 2013, Andrew Morton wrote --+
> | On Tue, 15 Oct 2013 20:25:57 +0530 (IST) P J P <[email protected]> wrote:
> | This patch breaks my x86_64 allmodconfig build, because I don't have
> | the lz4 executable installed:
> |
> | /usr/src/25/scripts/gen_initramfs_list.sh: line 307: lz4: command not found
> | make[1]: *** [usr/initramfs_data.cpio.lz4] Error 1
> |
> | This obviously isn't acceptable!
>
> Oops! '$ make allmodconfig' seems to enables all compression algorithms; So
> the last one overrides the previous choices in usr/Makefile.
>
> ===
> ...
> CONFIG_RD_GZIP=y
> CONFIG_RD_BZIP2=y
> CONFIG_RD_LZMA=y
> CONFIG_RD_XZ=y
> CONFIG_RD_LZO=y
> CONFIG_RD_LZ4=y
> ===
>
> Please see an updated patch herein. I've patched 'gen_initramfs_list.sh'
> script to check if a selected compression command is accessible or not; And
> fall-back to the default gzip(1) format when it is not. usr/Makefile also
> defaults to '.gz' format when all are enabled.

Below is the delta.

Requiring that the executables exist in /bin is unpleasant. Isn't
there some convenient way of testing for the presence of an executable
in $PATH?

The shell-builtin `which' seems to dtrt:

akpm3:/usr/src/25> if which gzip > /dev/null ; then echo foo ; fi
foo
akpm3:/usr/src/25> if which lz4 > /dev/null ; then echo foo ; fi
akpm3:/usr/src/25>

/bin/which should do the same thing.

There's probably some kbuild-approved way of doing this, but I
don't know what it is off-hand.



From: P J P <[email protected]>
Subject: initramfs-read-config_rd_-variables-for-initramfs-compression-fix

Oops! '$ make allmodconfig' seems to enables all compression algorithms;
So the last one overrides the previous choices in usr/Makefile.

Please see an updated patch herein. I've patched 'gen_initramfs_list.sh'
script to check if a selected compression command is accessible or not;
And fall-back to the default gzip(1) format when it is not. usr/Makefile
also defaults to '.gz' format when all are enabled.

Signed-off-by: P J P <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
---

scripts/gen_initramfs_list.sh | 19 ++++++++++++-------
usr/Makefile | 6 +++---
2 files changed, 15 insertions(+), 10 deletions(-)

diff -puN scripts/gen_initramfs_list.sh~initramfs-read-config_rd_-variables-for-initramfs-compression-fix scripts/gen_initramfs_list.sh
--- a/scripts/gen_initramfs_list.sh~initramfs-read-config_rd_-variables-for-initramfs-compression-fix
+++ a/scripts/gen_initramfs_list.sh
@@ -240,13 +240,18 @@ case "$arg" in
output_file="$1"
cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)"
output=${cpio_list}
- echo "$output_file" | grep -q "\.gz$" && compr="gzip -n -9 -f"
- echo "$output_file" | grep -q "\.bz2$" && compr="bzip2 -9 -f"
- echo "$output_file" | grep -q "\.lzma$" && compr="lzma -9 -f"
- echo "$output_file" | grep -q "\.xz$" && \
- compr="xz --check=crc32 --lzma2=dict=1MiB"
- echo "$output_file" | grep -q "\.lzo$" && compr="lzop -9 -f"
- echo "$output_file" | grep -q "\.lz4$" && compr="lz4 -9 -f"
+ echo "$output_file" | grep -q "\.gz$" && [ -x "/bin/gzip" ] \
+ && compr="gzip -n -9 -f"
+ echo "$output_file" | grep -q "\.bz2$" && [ -x "/bin/bzip2" ] \
+ && compr="bzip2 -9 -f"
+ echo "$output_file" | grep -q "\.lzma$" && [ -x "/bin/lzma" ] \
+ && compr="lzma -9 -f"
+ echo "$output_file" | grep -q "\.xz$" && [ -x "/bin/xz" ] \
+ && compr="xz --check=crc32 --lzma2=dict=1MiB"
+ echo "$output_file" | grep -q "\.lzo$" && [ -x "/bin/lzop" ] \
+ && compr="lzop -9 -f"
+ echo "$output_file" | grep -q "\.lz4$" && [ -x "/bin/lz4" ] \
+ && compr="lz4 -9 -f"
echo "$output_file" | grep -q "\.cpio$" && compr="cat"
shift
;;
diff -puN usr/Makefile~initramfs-read-config_rd_-variables-for-initramfs-compression-fix usr/Makefile
--- a/usr/Makefile~initramfs-read-config_rd_-variables-for-initramfs-compression-fix
+++ a/usr/Makefile
@@ -6,9 +6,6 @@ klibcdirs:;
PHONY += klibcdirs


-# Gzip
-suffix_$(CONFIG_RD_GZIP) = .gz
-
# Bzip2
suffix_$(CONFIG_RD_BZIP2) = .bz2

@@ -24,6 +21,9 @@ suffix_$(CONFIG_RD_LZO) = .lzo
# Lz4
suffix_$(CONFIG_RD_LZ4) = .lz4

+# Gzip
+suffix_$(CONFIG_RD_GZIP) = .gz
+
AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/initramfs_data.cpio$(suffix_y)"

# Generate builtin.o based on initramfs_data.o
_

2013-10-31 07:05:17

by Prasad Pandit

[permalink] [raw]
Subject: Re: [Patch] Read CONFIG_RD_ variables for initramfs compression

Hello Andrew,

+-- On Wed, 30 Oct 2013, Andrew Morton wrote --+
| Isn't there some convenient way of testing for the presence of an
| executable in $PATH?
|
| The shell-builtin `which' seems to dtrt:

True. Please see an updated patch attached herein.

Thank you.
--
Prasad J Pandit / Red Hat Security Response Team


Attachments:
0001-Read-CONFIG_RD_-variables-for-initramfs-compression.patch (4.11 kB)