Re: [Patch] Read CONFIG_RD_ variables for initramfs compression
From: P J P
Date: Wed Oct 30 2013 - 06:27:47 EST
Hello Andrew,
+-- On Tue, 29 Oct 2013, Andrew Morton wrote --+
| On Tue, 15 Oct 2013 20:25:57 +0530 (IST) P J P <ppandit@xxxxxxxxxx> 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 TeamFrom c903542c15ea30785d209ad7dd8fa0d461e084cb Mon Sep 17 00:00:00 2001
From: P J P <prasad@xxxxxxxxxx>
Date: Wed, 30 Oct 2013 15:32:16 +0530
Subject: Read CONFIG_RD_ variables for initramfs compression
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. Also updates the
'gen_initramfs_list.sh' script to check whether a selected
compression command is accessible or not. And fall-back to default
gzip(1) compression when it is not.
Signed-off-by: P J P <prasad@xxxxxxxxxx>
diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
index b482f16..2889a83 100644
--- a/scripts/gen_initramfs_list.sh
+++ b/scripts/gen_initramfs_list.sh
@@ -240,12 +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 "\.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 --git a/usr/Makefile b/usr/Makefile
index 029ffe6..e767f01 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -6,20 +6,23 @@ klibcdirs:;
PHONY += klibcdirs
-# Gzip
-suffix_$(CONFIG_INITRAMFS_COMPRESSION_GZIP) = .gz
-
# Bzip2
-suffix_$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) = .bz2
+suffix_$(CONFIG_RD_BZIP2) = .bz2
# Lzma
-suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZMA) = .lzma
+suffix_$(CONFIG_RD_LZMA) = .lzma
# XZ
-suffix_$(CONFIG_INITRAMFS_COMPRESSION_XZ) = .xz
+suffix_$(CONFIG_RD_XZ) = .xz
# Lzo
-suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZO) = .lzo
+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)"
@@ -53,7 +56,10 @@ endif
quiet_cmd_initfs = GEN $@
cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
-targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 initramfs_data.cpio.lzma initramfs_data.cpio.xz initramfs_data.cpio.lzo initramfs_data.cpio
+targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 \
+ initramfs_data.cpio.lzma initramfs_data.cpio.xz \
+ initramfs_data.cpio.lzo initramfs_data.cpio.lz4 \
+ initramfs_data.cpio
# do not try to update files included in initramfs
$(deps_initramfs): ;
@@ -66,4 +72,3 @@ $(deps_initramfs): klibcdirs
$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
$(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
$(call if_changed,initfs)
-
--
1.8.3.1