Skip to content

Commit 7f8256a

Browse files
BenjaminGrayNp1masahir0y
authored andcommitted
initramfs: Encode dependency on KBUILD_BUILD_TIMESTAMP
gen_initramfs.sh has an internal dependency on KBUILD_BUILD_TIMESTAMP for generating file mtimes that is not exposed to make, so changing KBUILD_BUILD_TIMESTAMP will not trigger a rebuild of the archive. Declare the mtime date as a new parameter to gen_initramfs.sh to encode KBUILD_BUILD_TIMESTAMP in the shell command, thereby making make aware of the dependency. It will rebuild if KBUILD_BUILD_TIMESTAMP changes or is newly set/unset. It will _not_ rebuild if KBUILD_BUILD_TIMESTAMP is unset before and after. This should be fine for anyone who doesn't care about setting specific build times in the first place. Reviewed-by: Andrew Donnellan <[email protected]> Tested-by: Andrew Donnellan <[email protected]> Signed-off-by: Benjamin Gray <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent feb843a commit 7f8256a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

usr/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ quiet_cmd_initfs = GEN $@
6464
$(CONFIG_SHELL) $< -o $@ -l $(obj)/.initramfs_data.cpio.d \
6565
$(if $(CONFIG_INITRAMFS_ROOT_UID), -u $(CONFIG_INITRAMFS_ROOT_UID)) \
6666
$(if $(CONFIG_INITRAMFS_ROOT_GID), -g $(CONFIG_INITRAMFS_ROOT_GID)) \
67+
$(if $(KBUILD_BUILD_TIMESTAMP), -d "$(KBUILD_BUILD_TIMESTAMP)") \
6768
$(ramfs-input)
6869

6970
# We rebuild initramfs_data.cpio if:

usr/gen_initramfs.sh

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $0 [-o <file>] [-l <dep_list>] [-u <uid>] [-g <gid>] {-d | <cpio_source>} ...
2323
-g <gid> Group ID to map to group ID 0 (root).
2424
<gid> is only meaningful if <cpio_source> is a
2525
directory. "squash" forces all files to gid 0.
26+
-d <date> Use date for all file mtime values
2627
<cpio_source> File list or directory for cpio archive.
2728
If <cpio_source> is a .cpio file it will be used
2829
as direct input to initramfs.
@@ -190,6 +191,7 @@ prog=$0
190191
root_uid=0
191192
root_gid=0
192193
dep_list=
194+
timestamp=
193195
cpio_list=$(mktemp ${TMPDIR:-/tmp}/cpiolist.XXXXXX)
194196
output="/dev/stdout"
195197

@@ -218,6 +220,13 @@ while [ $# -gt 0 ]; do
218220
[ "$root_gid" = "-1" ] && root_gid=$(id -g || echo 0)
219221
shift
220222
;;
223+
"-d") # date for file mtimes
224+
timestamp="$(date -d"$1" +%s || :)"
225+
if test -n "$timestamp"; then
226+
timestamp="-t $timestamp"
227+
fi
228+
shift
229+
;;
221230
"-h")
222231
usage
223232
exit 0
@@ -237,11 +246,4 @@ done
237246

238247
# If output_file is set we will generate cpio archive
239248
# we are careful to delete tmp files
240-
timestamp=
241-
if test -n "$KBUILD_BUILD_TIMESTAMP"; then
242-
timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)"
243-
if test -n "$timestamp"; then
244-
timestamp="-t $timestamp"
245-
fi
246-
fi
247249
usr/gen_init_cpio $timestamp $cpio_list > $output

0 commit comments

Comments
 (0)