aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/kbuild/kbuild.txt3
-rw-r--r--scripts/gen_initramfs_list.sh9
-rw-r--r--usr/gen_init_cpio.c53
3 files changed, 50 insertions, 15 deletions
diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt
index f11ebb33e4a6..646e2c114fff 100644
--- a/Documentation/kbuild/kbuild.txt
+++ b/Documentation/kbuild/kbuild.txt
@@ -205,7 +205,8 @@ gcc -W... options for more extensive build-time checking.
205KBUILD_BUILD_TIMESTAMP 205KBUILD_BUILD_TIMESTAMP
206-------------------------------------------------- 206--------------------------------------------------
207Setting this to a date string overrides the timestamp used in the 207Setting this to a date string overrides the timestamp used in the
208UTS_VERSION definition (uname -v in the running kernel). The default value 208UTS_VERSION definition (uname -v in the running kernel). The value has to
209be a string that can be passed to date -d. The default value
209is the output of the date command at one point during build. 210is the output of the date command at one point during build.
210 211
211KBUILD_BUILD_USER, KBUILD_BUILD_HOST 212KBUILD_BUILD_USER, KBUILD_BUILD_HOST
diff --git a/scripts/gen_initramfs_list.sh b/scripts/gen_initramfs_list.sh
index 4a43fe12d179..d44cf675bc22 100644
--- a/scripts/gen_initramfs_list.sh
+++ b/scripts/gen_initramfs_list.sh
@@ -287,8 +287,15 @@ done
287# we are carefull to delete tmp files 287# we are carefull to delete tmp files
288if [ ! -z ${output_file} ]; then 288if [ ! -z ${output_file} ]; then
289 if [ -z ${cpio_file} ]; then 289 if [ -z ${cpio_file} ]; then
290 timestamp=
291 if test -n "$KBUILD_BUILD_TIMESTAMP"; then
292 timestamp="$(date -d"$KBUILD_BUILD_TIMESTAMP" +%s || :)"
293 if test -n "$timestamp"; then
294 timestamp="-t $timestamp"
295 fi
296 fi
290 cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)" 297 cpio_tfile="$(mktemp ${TMPDIR:-/tmp}/cpiofile.XXXXXX)"
291 usr/gen_init_cpio ${cpio_list} > ${cpio_tfile} 298 usr/gen_init_cpio $timestamp ${cpio_list} > ${cpio_tfile}
292 else 299 else
293 cpio_tfile=${cpio_file} 300 cpio_tfile=${cpio_file}
294 fi 301 fi
diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
index 7f06884ecd41..af0f22fb1ef7 100644
--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -22,6 +22,7 @@
22 22
23static unsigned int offset; 23static unsigned int offset;
24static unsigned int ino = 721; 24static unsigned int ino = 721;
25static time_t default_mtime;
25 26
26struct file_handler { 27struct file_handler {
27 const char *type; 28 const char *type;
@@ -102,7 +103,6 @@ static int cpio_mkslink(const char *name, const char *target,
102 unsigned int mode, uid_t uid, gid_t gid) 103 unsigned int mode, uid_t uid, gid_t gid)
103{ 104{
104 char s[256]; 105 char s[256];
105 time_t mtime = time(NULL);
106 106
107 if (name[0] == '/') 107 if (name[0] == '/')
108 name++; 108 name++;
@@ -114,7 +114,7 @@ static int cpio_mkslink(const char *name, const char *target,
114 (long) uid, /* uid */ 114 (long) uid, /* uid */
115 (long) gid, /* gid */ 115 (long) gid, /* gid */
116 1, /* nlink */ 116 1, /* nlink */
117 (long) mtime, /* mtime */ 117 (long) default_mtime, /* mtime */
118 (unsigned)strlen(target)+1, /* filesize */ 118 (unsigned)strlen(target)+1, /* filesize */
119 3, /* major */ 119 3, /* major */
120 1, /* minor */ 120 1, /* minor */
@@ -152,7 +152,6 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
152 uid_t uid, gid_t gid) 152 uid_t uid, gid_t gid)
153{ 153{
154 char s[256]; 154 char s[256];
155 time_t mtime = time(NULL);
156 155
157 if (name[0] == '/') 156 if (name[0] == '/')
158 name++; 157 name++;
@@ -164,7 +163,7 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,
164 (long) uid, /* uid */ 163 (long) uid, /* uid */
165 (long) gid, /* gid */ 164 (long) gid, /* gid */
166 2, /* nlink */ 165 2, /* nlink */
167 (long) mtime, /* mtime */ 166 (long) default_mtime, /* mtime */
168 0, /* filesize */ 167 0, /* filesize */
169 3, /* major */ 168 3, /* major */
170 1, /* minor */ 169 1, /* minor */
@@ -242,7 +241,6 @@ static int cpio_mknod(const char *name, unsigned int mode,
242 unsigned int maj, unsigned int min) 241 unsigned int maj, unsigned int min)
243{ 242{
244 char s[256]; 243 char s[256];
245 time_t mtime = time(NULL);
246 244
247 if (dev_type == 'b') 245 if (dev_type == 'b')
248 mode |= S_IFBLK; 246 mode |= S_IFBLK;
@@ -259,7 +257,7 @@ static int cpio_mknod(const char *name, unsigned int mode,
259 (long) uid, /* uid */ 257 (long) uid, /* uid */
260 (long) gid, /* gid */ 258 (long) gid, /* gid */
261 1, /* nlink */ 259 1, /* nlink */
262 (long) mtime, /* mtime */ 260 (long) default_mtime, /* mtime */
263 0, /* filesize */ 261 0, /* filesize */
264 3, /* major */ 262 3, /* major */
265 1, /* minor */ 263 1, /* minor */
@@ -460,7 +458,7 @@ static int cpio_mkfile_line(const char *line)
460static void usage(const char *prog) 458static void usage(const char *prog)
461{ 459{
462 fprintf(stderr, "Usage:\n" 460 fprintf(stderr, "Usage:\n"
463 "\t%s <cpio_list>\n" 461 "\t%s [-t <timestamp>] <cpio_list>\n"
464 "\n" 462 "\n"
465 "<cpio_list> is a file containing newline separated entries that\n" 463 "<cpio_list> is a file containing newline separated entries that\n"
466 "describe the files to be included in the initramfs archive:\n" 464 "describe the files to be included in the initramfs archive:\n"
@@ -491,7 +489,11 @@ static void usage(const char *prog)
491 "nod /dev/console 0600 0 0 c 5 1\n" 489 "nod /dev/console 0600 0 0 c 5 1\n"
492 "dir /root 0700 0 0\n" 490 "dir /root 0700 0 0\n"
493 "dir /sbin 0755 0 0\n" 491 "dir /sbin 0755 0 0\n"
494 "file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n", 492 "file /sbin/kinit /usr/src/klibc/kinit/kinit 0755 0 0\n"
493 "\n"
494 "<timestamp> is time in seconds since Epoch that will be used\n"
495 "as mtime for symlinks, special files and directories. The default\n"
496 "is to use the current time for these entries.\n",
495 prog); 497 prog);
496} 498}
497 499
@@ -529,17 +531,42 @@ int main (int argc, char *argv[])
529 char *args, *type; 531 char *args, *type;
530 int ec = 0; 532 int ec = 0;
531 int line_nr = 0; 533 int line_nr = 0;
534 const char *filename;
535
536 default_mtime = time(NULL);
537 while (1) {
538 int opt = getopt(argc, argv, "t:h");
539 char *invalid;
532 540
533 if (2 != argc) { 541 if (opt == -1)
542 break;
543 switch (opt) {
544 case 't':
545 default_mtime = strtol(optarg, &invalid, 10);
546 if (!*optarg || *invalid) {
547 fprintf(stderr, "Invalid timestamp: %s\n",
548 optarg);
549 usage(argv[0]);
550 exit(1);
551 }
552 break;
553 case 'h':
554 case '?':
555 usage(argv[0]);
556 exit(opt == 'h' ? 0 : 1);
557 }
558 }
559
560 if (argc - optind != 1) {
534 usage(argv[0]); 561 usage(argv[0]);
535 exit(1); 562 exit(1);
536 } 563 }
537 564 filename = argv[optind];
538 if (!strcmp(argv[1], "-")) 565 if (!strcmp(filename, "-"))
539 cpio_list = stdin; 566 cpio_list = stdin;
540 else if (! (cpio_list = fopen(argv[1], "r"))) { 567 else if (!(cpio_list = fopen(filename, "r"))) {
541 fprintf(stderr, "ERROR: unable to open '%s': %s\n\n", 568 fprintf(stderr, "ERROR: unable to open '%s': %s\n\n",
542 argv[1], strerror(errno)); 569 filename, strerror(errno));
543 usage(argv[0]); 570 usage(argv[0]);
544 exit(1); 571 exit(1);
545 } 572 }