Commit 469e87e8 authored by Masahiro Yamada's avatar Masahiro Yamada

gen_initramfs.sh: always output cpio even without -o option

Currently, this script outputs a cpio file when -o option is
given, but otherwise a text file in the format recognized by
gen_init_cpio.

This behavior is unclear. Make it always output a cpio file.
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 4538f413
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
# #
# Generate a cpio packed initramfs. It uses gen_init_cpio to generate # Generate a cpio packed initramfs. It uses gen_init_cpio to generate
# the cpio archive, and then compresses it. # the cpio archive, and then compresses it.
# The script may also be used to generate the inputfile used for gen_init_cpio
# This script assumes that gen_init_cpio is located in usr/ directory # This script assumes that gen_init_cpio is located in usr/ directory
# error out on errors # error out on errors
...@@ -71,8 +70,8 @@ print_mtime() { ...@@ -71,8 +70,8 @@ print_mtime() {
my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1) my_mtime=$(find "$1" -printf "%T@\n" | sort -r | head -n 1)
fi fi
echo "# Last modified: ${my_mtime}" >> ${output} echo "# Last modified: ${my_mtime}" >> $cpio_list
echo "" >> ${output} echo "" >> $cpio_list
} }
list_parse() { list_parse() {
...@@ -125,7 +124,7 @@ parse() { ...@@ -125,7 +124,7 @@ parse() {
;; ;;
esac esac
echo "${str}" >> ${output} echo "${str}" >> $cpio_list
return 0 return 0
} }
...@@ -141,7 +140,7 @@ unknown_option() { ...@@ -141,7 +140,7 @@ unknown_option() {
} }
header() { header() {
printf "\n#####################\n# $1\n" >> ${output} printf "\n#####################\n# $1\n" >> $cpio_list
} }
# process one directory (incl sub-directories) # process one directory (incl sub-directories)
...@@ -177,8 +176,8 @@ input_file() { ...@@ -177,8 +176,8 @@ input_file() {
[ -n "$dep_list" ] && echo "$1" >> $dep_list [ -n "$dep_list" ] && echo "$1" >> $dep_list
return 0 return 0
fi fi
print_mtime "$1" >> ${output} print_mtime "$1" >> $cpio_list
cat "$1" >> ${output} cat "$1" >> $cpio_list
if [ -n "$dep_list" ]; then if [ -n "$dep_list" ]; then
echo "$1 \\" >> $dep_list echo "$1 \\" >> $dep_list
cat "$1" | while read type dir file perm ; do cat "$1" | while read type dir file perm ; do
...@@ -200,9 +199,9 @@ root_uid=0 ...@@ -200,9 +199,9 @@ root_uid=0
root_gid=0 root_gid=0
dep_list= dep_list=
cpio_file= cpio_file=
cpio_list= cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)
output="/dev/stdout" output="/dev/stdout"
output_file="" output_file="/dev/stdout"
is_cpio_compressed= is_cpio_compressed=
compr="gzip -n -9 -f" compr="gzip -n -9 -f"
...@@ -217,8 +216,7 @@ while [ $# -gt 0 ]; do ...@@ -217,8 +216,7 @@ while [ $# -gt 0 ]; do
;; ;;
"-o") # generate compressed cpio image named $1 "-o") # generate compressed cpio image named $1
output_file="$1" output_file="$1"
cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" output=$cpio_list
output=${cpio_list}
echo "$output_file" | grep -q "\.gz$" \ echo "$output_file" | grep -q "\.gz$" \
&& [ -x "`which gzip 2> /dev/null`" ] \ && [ -x "`which gzip 2> /dev/null`" ] \
&& compr="gzip -n -9 -f" && compr="gzip -n -9 -f"
...@@ -269,8 +267,7 @@ done ...@@ -269,8 +267,7 @@ done
# If output_file is set we will generate cpio archive and compress it # If output_file is set we will generate cpio archive and compress it
# we are careful to delete tmp files # we are careful to delete tmp files
if [ ! -z ${output_file} ]; then if [ -z ${cpio_file} ]; then
if [ -z ${cpio_file} ]; then
timestamp= timestamp=
if test -n "$KBUILD_BUILD_TIMESTAMP"; then if test -n "$KBUILD_BUILD_TIMESTAMP"; then
timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)" timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)"
...@@ -280,16 +277,15 @@ if [ ! -z ${output_file} ]; then ...@@ -280,16 +277,15 @@ if [ ! -z ${output_file} ]; then
fi fi
cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)" cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)"
usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile} usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile}
else else
cpio_tfile=${cpio_file} cpio_tfile=${cpio_file}
fi fi
rm ${cpio_list} rm ${cpio_list}
if [ "${is_cpio_compressed}" = "compressed" ]; then if [ "${is_cpio_compressed}" = "compressed" ]; then
cat ${cpio_tfile} > ${output_file} cat ${cpio_tfile} > ${output_file}
else else
(cat ${cpio_tfile} | ${compr} - > ${output_file}) \ (cat ${cpio_tfile} | ${compr} - > ${output_file}) \
|| (rm -f ${output_file} ; false) || (rm -f ${output_file} ; false)
fi
[ -z ${cpio_file} ] && rm ${cpio_tfile}
fi fi
[ -z ${cpio_file} ] && rm ${cpio_tfile}
exit 0 exit 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment