aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src/jcgimage.c
diff options
context:
space:
mode:
authorAlexander Couzens <lynxis@fe80.eu>2017-06-18 02:21:21 +0200
committerAlexander Couzens <lynxis@fe80.eu>2017-06-19 14:34:52 +0200
commitc47a1a3527d988b637c1daee573cbe0170ef73c6 (patch)
tree0c101781d043cf4b9fc1d4637725154c234b7d04 /tools/firmware-utils/src/jcgimage.c
parent77dc6a2ae7c94ac3d496ebab589d4574ac7169d0 (diff)
downloadupstream-c47a1a3527d988b637c1daee573cbe0170ef73c6.tar.gz
upstream-c47a1a3527d988b637c1daee573cbe0170ef73c6.tar.bz2
upstream-c47a1a3527d988b637c1daee573cbe0170ef73c6.zip
firmware-utils: honor env SOURCE_DATE_EPOCH
Use the timestamp from the enviroment SOURCE_DATE_EPOCH if set instead of the build time. Fixes reproducible builds for certain firmware images. Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
Diffstat (limited to 'tools/firmware-utils/src/jcgimage.c')
-rw-r--r--tools/firmware-utils/src/jcgimage.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/firmware-utils/src/jcgimage.c b/tools/firmware-utils/src/jcgimage.c
index 7755eab1ed..354c26be19 100644
--- a/tools/firmware-utils/src/jcgimage.c
+++ b/tools/firmware-utils/src/jcgimage.c
@@ -158,6 +158,20 @@ opensize(char *name, size_t *size)
return fd;
}
+static time_t source_date_epoch = -1;
+static void set_source_date_epoch() {
+ char *env = getenv("SOURCE_DATE_EPOCH");
+ char *endptr = env;
+ errno = 0;
+ if (env && *env) {
+ source_date_epoch = strtoull(env, &endptr, 10);
+ if (errno || (endptr && *endptr != '\0')) {
+ fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
+ exit(1);
+ }
+ }
+}
+
/*
* Write the JCG header
*/
@@ -167,6 +181,13 @@ mkjcgheader(struct jcg_header *h, size_t psize, char *version)
uLong crc;
uint16_t major = 0, minor = 0;
void *payload = (void *)h + sizeof(*h);
+ time_t t;
+
+ if (source_date_epoch != -1) {
+ t = source_date_epoch;
+ } else if ((time(&t) == (time_t)(-1))) {
+ err(1, "time call failed");
+ }
if (version != NULL) {
if (sscanf(version, "%hu.%hu", &major, &minor) != 2) {
@@ -177,7 +198,7 @@ mkjcgheader(struct jcg_header *h, size_t psize, char *version)
memset(h, 0, sizeof(*h));
h->jh_magic = htonl(JH_MAGIC);
h->jh_type = htonl(1);
- h->jh_time = htonl(time(NULL));
+ h->jh_time = htonl(t);
h->jh_major = htons(major);
h->jh_minor = htons(minor);
@@ -303,6 +324,7 @@ main(int argc, char **argv)
/* Make sure the headers have the right size */
assert(sizeof(struct jcg_header) == 512);
assert(sizeof(struct uimage_header) == 64);
+ set_source_date_epoch();
while ((c = getopt(argc, argv, "o:k:f:u:v:h")) != -1) {
switch (c) {