Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+47 -64
+1 -2
usr/Makefile
··· 39 39 endif 40 40 41 41 quiet_cmd_initfs = GEN $@ 42 - cmd_initfs = $(CONFIG_SHELL) $< -o $@ $(ramfs-args) $(ramfs-input) 42 + cmd_initfs = $(CONFIG_SHELL) $< -o $@ -l $(obj)/$(datafile_d_y) $(ramfs-args) $(ramfs-input) 43 43 44 44 targets := $(datafile_y) 45 45 ··· 52 52 # 3) If gen_init_cpio are newer than initramfs_data.cpio 53 53 # 4) Arguments to gen_initramfs.sh changes 54 54 $(obj)/$(datafile_y): $(src)/gen_initramfs.sh $(obj)/gen_init_cpio $(deps_initramfs) FORCE 55 - $(Q)$< -l $(ramfs-input) > $(obj)/$(datafile_d_y) 56 55 $(call if_changed,initfs) 57 56 58 57 subdir-$(CONFIG_UAPI_HEADER_TEST) += include
+46 -62
usr/gen_initramfs.sh
··· 15 15 usage() { 16 16 cat << EOF 17 17 Usage: 18 - $0 [-o <file>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ... 18 + $0 [-o <file>] [-l <dep_list>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ... 19 19 -o <file> Create compressed initramfs file named <file> using 20 20 gen_init_cpio and compressor depending on the extension 21 + -l <dep_list> Create dependency list named <dep_list> 21 22 -u <uid> User ID to map to user ID 0 (root). 22 23 <uid> is only meaningful if <cpio_source> is a 23 24 directory. "squash" forces all files to uid 0. ··· 41 40 # $1 - field number; rest is argument string 42 41 field() { 43 42 shift $1 ; echo $1 44 - } 45 - 46 - list_default_initramfs() { 47 - # echo usr/kinit/kinit 48 - : 49 43 } 50 44 51 45 default_initramfs() { ··· 77 81 return 0 78 82 } 79 83 80 - list_print_mtime() { 81 - : 82 - } 83 - 84 84 print_mtime() { 85 85 local my_mtime="0" 86 86 ··· 89 97 } 90 98 91 99 list_parse() { 92 - if [ -L "$1" ]; then 100 + if [ -z "$dep_list" -o -L "$1" ]; then 93 101 return 94 102 fi 95 - echo "$1" | sed 's/:/\\:/g; s/$/ \\/' 103 + echo "$1" | sed 's/:/\\:/g; s/$/ \\/' >> $dep_list 96 104 } 97 105 98 106 # for each file print a line in following format ··· 153 161 exit 1 154 162 } 155 163 156 - list_header() { 157 - : 158 - } 159 - 160 164 header() { 161 165 printf "\n#####################\n# $1\n" >> ${output} 162 166 } 163 167 164 168 # process one directory (incl sub-directories) 165 169 dir_filelist() { 166 - ${dep_list}header "$1" 170 + header "$1" 167 171 168 172 srcdir=$(echo "$1" | sed -e 's://*:/:g') 169 173 dirlist=$(find "${srcdir}" -printf "%p %m %U %G\n" | LANG=C sort) 170 174 171 175 # If $dirlist is only one line, then the directory is empty 172 176 if [ "$(echo "${dirlist}" | wc -l)" -gt 1 ]; then 173 - ${dep_list}print_mtime "$1" 177 + print_mtime "$1" 174 178 175 179 echo "${dirlist}" | \ 176 180 while read x; do 177 - ${dep_list}parse ${x} 181 + list_parse $x 182 + parse $x 178 183 done 179 184 fi 180 185 } ··· 182 193 input_file() { 183 194 source="$1" 184 195 if [ -f "$1" ]; then 185 - ${dep_list}header "$1" 196 + header "$1" 186 197 is_cpio="$(echo "$1" | sed 's/^.*\.cpio\(\..*\)\{0,1\}/cpio/')" 187 198 if [ $2 -eq 0 -a ${is_cpio} = "cpio" ]; then 188 199 cpio_file=$1 189 200 echo "$1" | grep -q '^.*\.cpio\..*' && is_cpio_compressed="compressed" 190 - [ ! -z ${dep_list} ] && echo "$1" 201 + [ -n "$dep_list" ] && echo "$1" >> $dep_list 191 202 return 0 192 203 fi 193 - if [ -z ${dep_list} ]; then 194 - print_mtime "$1" >> ${output} 195 - cat "$1" >> ${output} 196 - else 197 - echo "$1 \\" 204 + print_mtime "$1" >> ${output} 205 + cat "$1" >> ${output} 206 + if [ -n "$dep_list" ]; then 207 + echo "$1 \\" >> $dep_list 198 208 cat "$1" | while read type dir file perm ; do 199 209 if [ "$type" = "file" ]; then 200 - echo "$file \\"; 210 + echo "$file \\" >> $dep_list 201 211 fi 202 212 done 203 213 fi ··· 219 231 is_cpio_compressed= 220 232 compr="gzip -n -9 -f" 221 233 222 - arg="$1" 223 - case "$arg" in 224 - "-l") # files included in initramfs - used by kbuild 225 - dep_list="list_" 226 - echo "deps_initramfs := \\" 227 - shift 228 - ;; 229 - "-o") # generate compressed cpio image named $1 230 - shift 231 - output_file="$1" 232 - cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" 233 - output=${cpio_list} 234 - echo "$output_file" | grep -q "\.gz$" \ 235 - && [ -x "`which gzip 2> /dev/null`" ] \ 236 - && compr="gzip -n -9 -f" 237 - echo "$output_file" | grep -q "\.bz2$" \ 238 - && [ -x "`which bzip2 2> /dev/null`" ] \ 239 - && compr="bzip2 -9 -f" 240 - echo "$output_file" | grep -q "\.lzma$" \ 241 - && [ -x "`which lzma 2> /dev/null`" ] \ 242 - && compr="lzma -9 -f" 243 - echo "$output_file" | grep -q "\.xz$" \ 244 - && [ -x "`which xz 2> /dev/null`" ] \ 245 - && compr="xz --check=crc32 --lzma2=dict=1MiB" 246 - echo "$output_file" | grep -q "\.lzo$" \ 247 - && [ -x "`which lzop 2> /dev/null`" ] \ 248 - && compr="lzop -9 -f" 249 - echo "$output_file" | grep -q "\.lz4$" \ 250 - && [ -x "`which lz4 2> /dev/null`" ] \ 251 - && compr="lz4 -l -9 -f" 252 - echo "$output_file" | grep -q "\.cpio$" && compr="cat" 253 - shift 254 - ;; 255 - esac 256 234 while [ $# -gt 0 ]; do 257 235 arg="$1" 258 236 shift 259 237 case "$arg" in 238 + "-l") # files included in initramfs - used by kbuild 239 + dep_list="$1" 240 + echo "deps_initramfs := \\" > $dep_list 241 + shift 242 + ;; 243 + "-o") # generate compressed cpio image named $1 244 + output_file="$1" 245 + cpio_list="$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)" 246 + output=${cpio_list} 247 + echo "$output_file" | grep -q "\.gz$" \ 248 + && [ -x "`which gzip 2> /dev/null`" ] \ 249 + && compr="gzip -n -9 -f" 250 + echo "$output_file" | grep -q "\.bz2$" \ 251 + && [ -x "`which bzip2 2> /dev/null`" ] \ 252 + && compr="bzip2 -9 -f" 253 + echo "$output_file" | grep -q "\.lzma$" \ 254 + && [ -x "`which lzma 2> /dev/null`" ] \ 255 + && compr="lzma -9 -f" 256 + echo "$output_file" | grep -q "\.xz$" \ 257 + && [ -x "`which xz 2> /dev/null`" ] \ 258 + && compr="xz --check=crc32 --lzma2=dict=1MiB" 259 + echo "$output_file" | grep -q "\.lzo$" \ 260 + && [ -x "`which lzop 2> /dev/null`" ] \ 261 + && compr="lzop -9 -f" 262 + echo "$output_file" | grep -q "\.lz4$" \ 263 + && [ -x "`which lz4 2> /dev/null`" ] \ 264 + && compr="lz4 -l -9 -f" 265 + echo "$output_file" | grep -q "\.cpio$" && compr="cat" 266 + shift 267 + ;; 260 268 "-u") # map $1 to uid=0 (root) 261 269 root_uid="$1" 262 270 [ "$root_uid" = "-1" ] && root_uid=$(id -u || echo 0) ··· 264 280 shift 265 281 ;; 266 282 "-d") # display default initramfs list 267 - ${dep_list}default_initramfs 283 + default_initramfs 268 284 ;; 269 285 "-h") 270 286 usage