Skip to content

Commit 9ba4bcb

Browse files
P J Ptorvalds
authored andcommitted
initramfs: 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@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ba24762 commit 9ba4bcb

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

scripts/gen_initramfs_list.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,24 @@ case "$arg" in
240240
output_file="$1"
241241
cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)"
242242
output=${cpio_list}
243-
echo "$output_file" | grep -q "\.gz$" && compr="gzip -n -9 -f"
244-
echo "$output_file" | grep -q "\.bz2$" && compr="bzip2 -9 -f"
245-
echo "$output_file" | grep -q "\.lzma$" && compr="lzma -9 -f"
246-
echo "$output_file" | grep -q "\.xz$" && \
247-
compr="xz --check=crc32 --lzma2=dict=1MiB"
248-
echo "$output_file" | grep -q "\.lzo$" && compr="lzop -9 -f"
243+
echo "$output_file" | grep -q "\.gz$" \
244+
&& [ -x "`which gzip 2> /dev/null`" ] \
245+
&& compr="gzip -n -9 -f"
246+
echo "$output_file" | grep -q "\.bz2$" \
247+
&& [ -x "`which bzip2 2> /dev/null`" ] \
248+
&& compr="bzip2 -9 -f"
249+
echo "$output_file" | grep -q "\.lzma$" \
250+
&& [ -x "`which lzma 2> /dev/null`" ] \
251+
&& compr="lzma -9 -f"
252+
echo "$output_file" | grep -q "\.xz$" \
253+
&& [ -x "`which xz 2> /dev/null`" ] \
254+
&& compr="xz --check=crc32 --lzma2=dict=1MiB"
255+
echo "$output_file" | grep -q "\.lzo$" \
256+
&& [ -x "`which lzop 2> /dev/null`" ] \
257+
&& compr="lzop -9 -f"
258+
echo "$output_file" | grep -q "\.lz4$" \
259+
&& [ -x "`which lz4 2> /dev/null`" ] \
260+
&& compr="lz4 -9 -f"
249261
echo "$output_file" | grep -q "\.cpio$" && compr="cat"
250262
shift
251263
;;

usr/Makefile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ klibcdirs:;
66
PHONY += klibcdirs
77

88

9-
# Gzip
10-
suffix_$(CONFIG_INITRAMFS_COMPRESSION_GZIP) = .gz
11-
129
# Bzip2
13-
suffix_$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) = .bz2
10+
suffix_$(CONFIG_RD_BZIP2) = .bz2
1411

1512
# Lzma
16-
suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZMA) = .lzma
13+
suffix_$(CONFIG_RD_LZMA) = .lzma
1714

1815
# XZ
19-
suffix_$(CONFIG_INITRAMFS_COMPRESSION_XZ) = .xz
16+
suffix_$(CONFIG_RD_XZ) = .xz
2017

2118
# Lzo
22-
suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZO) = .lzo
19+
suffix_$(CONFIG_RD_LZO) = .lzo
20+
21+
# Lz4
22+
suffix_$(CONFIG_RD_LZ4) = .lz4
23+
24+
# Gzip
25+
suffix_$(CONFIG_RD_GZIP) = .gz
2326

2427
AFLAGS_initramfs_data.o += -DINITRAMFS_IMAGE="usr/initramfs_data.cpio$(suffix_y)"
2528

@@ -53,7 +56,10 @@ endif
5356
quiet_cmd_initfs = GEN $@
5457
cmd_initfs = $(initramfs) -o $@ $(ramfs-args) $(ramfs-input)
5558

56-
targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 initramfs_data.cpio.lzma initramfs_data.cpio.xz initramfs_data.cpio.lzo initramfs_data.cpio
59+
targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 \
60+
initramfs_data.cpio.lzma initramfs_data.cpio.xz \
61+
initramfs_data.cpio.lzo initramfs_data.cpio.lz4 \
62+
initramfs_data.cpio
5763
# do not try to update files included in initramfs
5864
$(deps_initramfs): ;
5965

@@ -66,4 +72,3 @@ $(deps_initramfs): klibcdirs
6672
$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
6773
$(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
6874
$(call if_changed,initfs)
69-

0 commit comments

Comments
 (0)