NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

misc/57914: [RB] evbarm/earmv4eb mkubootimage: Set reproducible timestamp



>Number:         57914
>Category:       misc
>Synopsis:       [RB] evbarm/earmv4eb mkubootimage: Set reproducible timestamp
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    misc-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 09 07:05:00 +0000 2024
>Originator:     Jan-Benedict Glaw
>Release:        current
>Organization:
>Environment:
>Description:
uBoot images contain (build) timestamps. For reproducible builds, use the top commit's timestamp instead.
>How-To-Repeat:
Build twice, compare build artifacts.
>Fix:
index 3a101134aaa2..9ef4c3eb15a4 100644
--- a/distrib/evbarm/instkernel/ramdisk/Makefile
+++ b/distrib/evbarm/instkernel/ramdisk/Makefile
@@ -34,6 +34,10 @@ UBOOT_IMAGE_ARCH=    arm64
 UBOOT_IMAGE_ARCH=      arm
 .endif
 
+.if ${MKREPRO_TIMESTAMP:Uno} != "no"
+MKUBOOTIMAGE_TIMESTAMP=-t "${MKREPRO_TIMESTAMP}"
+.endif
+
 # Use stubs to eliminate some large stuff from libc
 HACKSRC=       ${DISTRIBDIR}/utils/libhack
 .include       "${HACKSRC}/Makefile.inc"
@@ -50,7 +54,7 @@ release:      ${IMAGE}
        ${INSTALL} -d -m 755 ${RAMDISKDIR}
        ${RELEASE_INSTALL} ${IMAGE}  ${RAMDISKDIR}
        ${TOOL_MKUBOOTIMAGE} -A ${UBOOT_IMAGE_ARCH} -C none -O linux \
-           -T ramdisk -a 0 -n "NetBSD/${MACHINE_ARCH} ramdisk" ${IMAGE} \
-           ${RAMDISKDIR}/${IMAGE:S/.fs/.ub/}
+           -T ramdisk -a 0 -n "NetBSD/${MACHINE_ARCH} ramdisk" \
+           ${MKUBOOTIMAGE_TIMESTAMP} ${IMAGE} ${RAMDISKDIR}/${IMAGE:S/.fs/.ub/}
 
 .include <bsd.prog.mk>
diff --git a/usr.bin/mkubootimage/mkubootimage.1 b/usr.bin/mkubootimage/mkubootimage.1
index a02e34d8160d..82dae3247e02 100644
--- a/usr.bin/mkubootimage/mkubootimage.1
+++ b/usr.bin/mkubootimage/mkubootimage.1
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 4, 2019
+.Dd February 7, 2024
 .Dt MKUBOOTIMAGE 1
 .Os
 .Sh NAME
@@ -119,6 +119,8 @@ This is required.
 Defines the operating system type.
 The default OS name is
 .Qq netbsd .
+.It Fl t Ar epoch
+Use given epoch timestamp as image creation time. (This is only used for legacy U-Boot images.)
 .It Fl T No ( fs Ns | Ns kernel Ns | Ns kernel_noload Ns | Ns ramdisk Ns | Ns script Ns | Ns standalone )
 Defines the image type.
 This is required for
diff --git a/usr.bin/mkubootimage/mkubootimage.c b/usr.bin/mkubootimage/mkubootimage.c
index b7ebcb6d7abe..15f1dd16f4fe 100644
--- a/usr.bin/mkubootimage/mkubootimage.c
+++ b/usr.bin/mkubootimage/mkubootimage.c
@@ -266,7 +266,7 @@ usage(void)
 {
        fprintf(stderr, "usage: mkubootimage [-hu] -A "
            "<arm|arm64|i386|mips|mips64|or1k|powerpc|sh> -a address\n");
-       fprintf(stderr, "\t-C <bz2|gz|lzma|lzo|none> [-E address] [-e address]\n");
+       fprintf(stderr, "\t-C <bz2|gz|lzma|lzo|none> [-E address] [-e address] [ -t epoch]\n");
        fprintf(stderr, "\t[-f <arm64|uimg>] [-m magic] -n image -O <freebsd|linux|netbsd|openbsd>\n");
        fprintf(stderr, "\t-T <fs|kernel|kernel_noload|ramdisk|script|standalone>\n");
        fprintf(stderr, "\tsource destination\n");
@@ -298,7 +298,7 @@ dump_header_uimg(struct uboot_image_header *hdr)
 }
 
 static int
-generate_header_uimg(struct uboot_image_header *hdr, int kernel_fd)
+generate_header_uimg(struct uboot_image_header *hdr, time_t repro_time, int kernel_fd)
 {
        uint8_t *p;
        struct stat st;
@@ -342,7 +342,7 @@ generate_header_uimg(struct uboot_image_header *hdr, int kernel_fd)
 
        memset(hdr, 0, sizeof(*hdr));
        hdr->ih_magic = htonl(image_magic);
-       hdr->ih_time = htonl(st.st_mtime);
+       hdr->ih_time = htonl(repro_time? repro_time: st.st_mtime);
        hdr->ih_size = htonl(dsize);
        hdr->ih_load = htonl(image_loadaddr);
        hdr->ih_ep = htonl(image_entrypoint);
@@ -462,8 +462,9 @@ main(int argc, char *argv[])
        int kernel_fd, image_fd;
        int ch;
        unsigned long long num;
+       time_t repro_time = 0;
 
-       while ((ch = getopt(argc, argv, "A:C:E:O:T:a:e:f:hm:n:u")) != -1) {
+       while ((ch = getopt(argc, argv, "A:C:E:O:T:a:e:f:hm:n:ut:")) != -1) {
                switch (ch) {
                case 'A':       /* arch */
                        image_arch = get_arch(optarg);
@@ -474,6 +475,9 @@ main(int argc, char *argv[])
                case 'O':       /* os */
                        image_os = get_os(optarg);
                        break;
+               case 't':       /* FS timestamp */
+                       repro_time = atol(optarg);
+                       break;
                case 'T':       /* type */
                        image_type = get_type(optarg);
                        break;
@@ -584,7 +588,7 @@ main(int argc, char *argv[])
 
        switch (image_format) {
        case FMT_UIMG:
-               if (generate_header_uimg(&hdr_uimg, kernel_fd) != 0)
+               if (generate_header_uimg(&hdr_uimg, repro_time, kernel_fd) != 0)
                        return EXIT_FAILURE;
 
                if (write_image(&hdr_uimg, sizeof(hdr_uimg),



Home | Main Index | Thread Index | Old Index