Skip to content

Commit

Permalink
initramfs: read CONFIG_RD_ variables for initramfs compression
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
P J P authored and torvalds committed Nov 13, 2013
1 parent ba24762 commit 9ba4bcb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
24 changes: 18 additions & 6 deletions scripts/gen_initramfs_list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,24 @@ 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 "`which gzip 2> /dev/null`" ] \
&& compr="gzip -n -9 -f"
echo "$output_file" | grep -q "\.bz2$" \
&& [ -x "`which bzip2 2> /dev/null`" ] \
&& compr="bzip2 -9 -f"
echo "$output_file" | grep -q "\.lzma$" \
&& [ -x "`which lzma 2> /dev/null`" ] \
&& compr="lzma -9 -f"
echo "$output_file" | grep -q "\.xz$" \
&& [ -x "`which xz 2> /dev/null`" ] \
&& compr="xz --check=crc32 --lzma2=dict=1MiB"
echo "$output_file" | grep -q "\.lzo$" \
&& [ -x "`which lzop 2> /dev/null`" ] \
&& compr="lzop -9 -f"
echo "$output_file" | grep -q "\.lz4$" \
&& [ -x "`which lz4 2> /dev/null`" ] \
&& compr="lz4 -9 -f"
echo "$output_file" | grep -q "\.cpio$" && compr="cat"
shift
;;
Expand Down
23 changes: 14 additions & 9 deletions usr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down Expand Up @@ -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): ;

Expand All @@ -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)

0 comments on commit 9ba4bcb

Please sign in to comment.