aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src/mkdlinkfw-lib.c
diff options
context:
space:
mode:
authorMathias Kresin <dev@kresin.me>2019-01-05 07:34:02 +0100
committerMathias Kresin <dev@kresin.me>2019-01-13 18:31:10 +0100
commite428b127e7c9964a20cfd4cfb30b43262a10bfbe (patch)
tree7341b5868a2f27c63a70926966b875eaac1db9f8 /tools/firmware-utils/src/mkdlinkfw-lib.c
parentf4aa9d8839958c39d24d7cca3d3215efad98a1e2 (diff)
downloadupstream-e428b127e7c9964a20cfd4cfb30b43262a10bfbe.tar.gz
upstream-e428b127e7c9964a20cfd4cfb30b43262a10bfbe.tar.bz2
upstream-e428b127e7c9964a20cfd4cfb30b43262a10bfbe.zip
firmware-utils: mkdlinkfw: create reproducible header
Use the SOURCE_DATE_EPOCH environment variable if set instead of the current time. The used timestamp matches the timestamp of the latest commit this way and make the images reproducible. Signed-off-by: Mathias Kresin <dev@kresin.me>
Diffstat (limited to 'tools/firmware-utils/src/mkdlinkfw-lib.c')
-rw-r--r--tools/firmware-utils/src/mkdlinkfw-lib.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/tools/firmware-utils/src/mkdlinkfw-lib.c b/tools/firmware-utils/src/mkdlinkfw-lib.c
index a661c0bc82..3b71fda7db 100644
--- a/tools/firmware-utils/src/mkdlinkfw-lib.c
+++ b/tools/firmware-utils/src/mkdlinkfw-lib.c
@@ -34,9 +34,24 @@ extern char *progname;
uint32_t jboot_timestamp(void)
{
- time_t rawtime;
- time(&rawtime);
- return (((uint32_t) rawtime) - TIMESTAMP_MAGIC) >> 2;
+ char *env = getenv("SOURCE_DATE_EPOCH");
+ char *endptr = env;
+ time_t fixed_timestamp = -1;
+ errno = 0;
+
+ if (env && *env) {
+ fixed_timestamp = strtoull(env, &endptr, 10);
+
+ if (errno || (endptr && *endptr != '\0')) {
+ fprintf(stderr, "Invalid SOURCE_DATE_EPOCH");
+ fixed_timestamp = -1;
+ }
+ }
+
+ if (fixed_timestamp == -1)
+ time(&fixed_timestamp);
+
+ return (((uint32_t) fixed_timestamp) - TIMESTAMP_MAGIC) >> 2;
}
uint16_t jboot_checksum(uint16_t start_val, uint16_t *data, int size)