initramfs: generate dependency list and cpio at the same time

Currently, this script is run twice, for the dependency list, and then
for the cpio archive.

The first one is re-run every time although its build log is suppressed
so nobody notices it.

Make it work more efficiently by generating the cpio and the dependency
list at the same time.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
This commit is contained in:
Masahiro Yamada
2020-01-05 00:02:34 +09:00
parent 3e17668363
commit 9668097599
2 changed files with 47 additions and 64 deletions

View File

@@ -39,7 +39,7 @@ ifneq ($(wildcard $(obj)/$(datafile_d_y)),)
endif endif
quiet_cmd_initfs = GEN $@ quiet_cmd_initfs = GEN $@
cmd_initfs = $(CONFIG_SHELL) $< -o $@ $(ramfs-args) $(ramfs-input) cmd_initfs = $(CONFIG_SHELL) $< -o $@ -l $(obj)/$(datafile_d_y) $(ramfs-args) $(ramfs-input)
targets := $(datafile_y) targets := $(datafile_y)
@@ -52,7 +52,6 @@ $(deps_initramfs): ;
# 3) If gen_init_cpio are newer than initramfs_data.cpio # 3) If gen_init_cpio are newer than initramfs_data.cpio
# 4) Arguments to gen_initramfs.sh changes # 4) Arguments to gen_initramfs.sh changes
$(obj)/$(datafile_y): $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE $(obj)/$(datafile_y): $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE
$(Q)$< -l $(ramfs-input) > $(obj)/$(datafile_d_y)
$(call if_changed,initfs) $(call if_changed,initfs)
subdir-$(CONFIG_UAPI_HEADER_TEST) += include subdir-$(CONFIG_UAPI_HEADER_TEST) += include

View File

@@ -15,9 +15,10 @@ set -e
usage() { usage() {
cat << EOF cat << EOF
Usage: Usage:
$0 [-o <file>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ... $0 [-o <file>] [-l <dep_list>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
-o <file> Create compressed initramfs file named <file> using -o <file> Create compressed initramfs file named <file> using
gen_init_cpio and compressor depending on the extension gen_init_cpio and compressor depending on the extension
-l <dep_list> Create dependency list named <dep_list>
-u <uid> User ID to map to user ID 0 (root). -u <uid> User ID to map to user ID 0 (root).
<uid> is only meaningful if <cpio_source> is a <uid> is only meaningful if <cpio_source> is a
directory. "squash" forces all files to uid 0. directory. "squash" forces all files to uid 0.
@@ -42,11 +43,6 @@ field() {
shift $1 ; echo $1 shift $1 ; echo $1
} }
list_default_initramfs() {
# echo usr/kinit/kinit
:
}
default_initramfs() { default_initramfs() {
cat <<-EOF >> ${output} cat <<-EOF >> ${output}
# This is a very simple, default initramfs # This is a very simple, default initramfs
@@ -81,10 +77,6 @@ filetype() {
return 0 return 0
} }
list_print_mtime() {
:
}
print_mtime() { print_mtime() {
local my_mtime="0" local my_mtime="0"
@@ -97,10 +89,10 @@ print_mtime() {
} }
list_parse() { list_parse() {
if [ -L "$1" ]; then if [ -z "$dep_list" -o -L "$1" ]; then
return return
fi fi
echo "$1" | sed 's/:/\\:/g; s/$/ \\/' echo "$1" | sed 's/:/\\:/g; s/$/ \\/' >> $dep_list
} }
# for each file print a line in following format # for each file print a line in following format
@@ -161,28 +153,25 @@ unknown_option() {
exit 1 exit 1
} }
list_header() {
:
}
header() { header() {
printf "\n#####################\n# $1\n" >> ${output} printf "\n#####################\n# $1\n" >> ${output}
} }
# process one directory (incl sub-directories) # process one directory (incl sub-directories)
dir_filelist() { dir_filelist() {
${dep_list}header "$1" header "$1"
srcdir=$(echo "$1" | sed -e 's://*:/:g') srcdir=$(echo "$1" | sed -e 's://*:/:g')
dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort) dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort)
# If $dirlist is only one line, then the directory is empty # If $dirlist is only one line, then the directory is empty
if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then
${dep_list}print_mtime "$1" print_mtime "$1"
echo "${dirlist}" | \ echo "${dirlist}" | \
while read x; do while read x; do
${dep_list}parse ${x} list_parse $x
parse $x
done done
fi fi
} }
@@ -193,22 +182,21 @@ dir_filelist() {
input_file() { input_file() {
source="$1" source="$1"
if [ -f "$1" ]; then if [ -f "$1" ]; then
${dep_list}header "$1" header "$1"
is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')" is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')"
if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then
cpio_file=$1 cpio_file=$1
echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed" echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed"
[ ! -z ${dep_list} ] && echo "$1" [ -n "$dep_list" ] && echo "$1" >> $dep_list
return 0 return 0
fi fi
if [ -z ${dep_list} ]; then
print_mtime "$1" >> ${output} print_mtime "$1" >> ${output}
cat "$1" >> ${output} cat "$1" >> ${output}
else if [ -n "$dep_list" ]; then
echo "$1 \\" echo "$1 \\" >> $dep_list
cat "$1" | while read type dir file perm ; do cat "$1" | while read type dir file perm ; do
if [ "$type" = "file" ]; then if [ "$type" = "file" ]; then
echo "$file \\"; echo "$file \\" >> $dep_list
fi fi
done done
fi fi
@@ -231,15 +219,16 @@ output_file=""
is_cpio_compressed= is_cpio_compressed=
compr="gzip -n -9 -f" compr="gzip -n -9 -f"
arg="$1" while [ $# -gt 0 ]; do
case "$arg" in arg="$1"
shift
case "$arg" in
"-l") # files included in initramfs - used by kbuild "-l") # files included in initramfs - used by kbuild
dep_list="list_" dep_list="$1"
echo "deps_initramfs := \\" echo "deps_initramfs := \\" > $dep_list
shift shift
;; ;;
"-o") # generate compressed cpio image named $1 "-o") # generate compressed cpio image named $1
shift
output_file="$1" output_file="$1"
cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)"
output=${cpio_list} output=${cpio_list}
@@ -264,11 +253,6 @@ case "$arg" in
echo "$output_file" | grep -q "\.cpio$" && compr="cat" echo "$output_file" | grep -q "\.cpio$" && compr="cat"
shift shift
;; ;;
esac
while [ $# -gt 0 ]; do
arg="$1"
shift
case "$arg" in
"-u") # map $1 to uid=0 (root) "-u") # map $1 to uid=0 (root)
root_uid="$1" root_uid="$1"
[ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0) [ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0)
@@ -280,7 +264,7 @@ while [ $# -gt 0 ]; do
shift shift
;; ;;
"-d") # display default initramfs list "-d") # display default initramfs list
${dep_list}default_initramfs default_initramfs
;; ;;
"-h") "-h")
usage usage