331c1c3662950abad0e02282b5ffbe6edcb7dc99
[openwrt/staging/jogo.git] /
1 From f3f431a712729a1af94d01bd1bfde17a252ff02c Mon Sep 17 00:00:00 2001
2 From: Paul Kocialkowski <contact@paulk.fr>
3 Date: Sun, 26 Jul 2015 18:48:15 +0200
4 Subject: [PATCH] Reproducible U-Boot build support, using SOURCE_DATE_EPOCH
5
6 In order to achieve reproducible builds in U-Boot, timestamps that are defined
7 at build-time have to be somewhat eliminated. The SOURCE_DATE_EPOCH environment
8 variable allows setting a fixed value for those timestamps.
9
10 Simply by setting SOURCE_DATE_EPOCH to a fixed value, a number of targets can be
11 built reproducibly. This is the case for e.g. sunxi devices.
12
13 However, some other devices might need some more tweaks, especially regarding
14 the image generation tools.
15
16 Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
17 ---
18 Makefile | 7 ++++---
19 README | 12 ++++++++++++
20 tools/default_image.c | 21 ++++++++++++++++++++-
21 3 files changed, 36 insertions(+), 4 deletions(-)
22
23 --- a/README
24 +++ b/README
25 @@ -2785,6 +2785,18 @@ Low Level (hardware related) configurati
26 that is executed before the actual U-Boot. E.g. when
27 compiling a NAND SPL.
28
29 +Reproducible builds
30 +-------------------
31 +
32 +In order to achieve reproducible builds, timestamps used in the U-Boot build
33 +process have to be set to a fixed value.
34 +
35 +This is done using the SOURCE_DATE_EPOCH environment variable.
36 +SOURCE_DATE_EPOCH is to be set on the build host's shell, not as a configuration
37 +option for U-Boot or an environment variable in U-Boot.
38 +
39 +SOURCE_DATE_EPOCH should be set to a number of seconds since the epoch, in UTC.
40 +
41 Building the Software:
42 ======================
43
44 --- a/tools/default_image.c
45 +++ b/tools/default_image.c
46 @@ -101,6 +101,9 @@ static void image_set_header (void *ptr,
47 struct mkimage_params *params)
48 {
49 uint32_t checksum;
50 + char *source_date_epoch;
51 + struct tm *time_universal;
52 + time_t time;
53
54 image_header_t * hdr = (image_header_t *)ptr;
55
56 @@ -109,9 +112,25 @@ static void image_set_header (void *ptr,
57 sizeof(image_header_t)),
58 sbuf->st_size - sizeof(image_header_t));
59
60 +source_date_epoch = getenv("SOURCE_DATE_EPOCH");
61 + if (source_date_epoch != NULL) {
62 + time = (time_t) strtol(source_date_epoch, NULL, 10);
63 +
64 + time_universal = gmtime(&time);
65 + if (time_universal == NULL) {
66 + fprintf(stderr, "%s: SOURCE_DATE_EPOCH is not valid\n",
67 + __func__);
68 + time = 0;
69 + } else {
70 + time = mktime(time_universal);
71 + }
72 + } else {
73 + time = sbuf->st_mtime;
74 + }
75 +
76 /* Build new header */
77 image_set_magic (hdr, IH_MAGIC);
78 - image_set_time (hdr, sbuf->st_mtime);
79 + image_set_time(hdr, time);
80 image_set_size (hdr, sbuf->st_size - sizeof(image_header_t));
81 image_set_load (hdr, params->addr);
82 image_set_ep (hdr, params->ep);