X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fopenwrt.git;a=blobdiff_plain;f=tools%2Ffirmware-utils%2Fsrc%2Fhcsmakeimage.c;h=7baa7b5845e1ab9f67aa8f3b86446dce2a98326c;hp=603ea882b11b9e83b79fd8123b8fe1991ffc7db5;hb=c47a1a3527d988b637c1daee573cbe0170ef73c6;hpb=77dc6a2ae7c94ac3d496ebab589d4574ac7169d0 diff --git a/tools/firmware-utils/src/hcsmakeimage.c b/tools/firmware-utils/src/hcsmakeimage.c index 603ea882b1..7baa7b5845 100644 --- a/tools/firmware-utils/src/hcsmakeimage.c +++ b/tools/firmware-utils/src/hcsmakeimage.c @@ -5,7 +5,8 @@ #include #include #include -#include +#include +#include #include #include #include "bcmalgo.h" @@ -42,6 +43,19 @@ static void print_help ( const char* ename ) printf ( "\n" ); } +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); + } + } +} int main ( int argc, char** argv ) { @@ -149,11 +163,19 @@ int main ( int argc, char** argv ) { fname = filename; } - struct timeval tm; - gettimeofday ( &tm,NULL ); + + time_t t = -1; + set_source_date_epoch(); + if (source_date_epoch != -1) { + t = source_date_epoch; + } else if ((time(&t) == (time_t)(-1))) { + fprintf(stderr, "time call failed\n"); + return EXIT_FAILURE; + } + struct stat buf; stat ( input,&buf ); - ldr_header_t* head = construct_header ( magicnum, (uint16_t) majrev, (uint16_t) minrev, ( uint32_t ) tm.tv_sec, ( uint32_t ) buf.st_size, ldaddress, fname, get_file_crc ( input ) ); + ldr_header_t* head = construct_header ( magicnum, (uint16_t) majrev, (uint16_t) minrev, ( uint32_t ) t, ( uint32_t ) buf.st_size, ldaddress, fname, get_file_crc ( input ) ); free(dupe); //uint32_t magic, uint16_t rev_maj,uint16_t rev_min, uint32_t build_date, uint32_t filelen, uint32_t ldaddress, const char* filename, uint32_t crc //FILE* fd = fopen ("/tftpboot/haxorware11rev32.bin","r");