Module Name:    src
Committed By:   christos
Date:           Fri Feb  9 16:10:18 UTC 2024

Modified Files:
        src/usr.bin/mkubootimage: crc32.c mkubootimage.1 mkubootimage.c
Added Files:
        src/usr.bin/mkubootimage: crc32.h

Log Message:
PR/57914: Jan-Benedict Glaw: Set reproducible timestamp
Cleanup lint.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/mkubootimage/crc32.c
cvs rdiff -u -r0 -r1.1 src/usr.bin/mkubootimage/crc32.h
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/mkubootimage/mkubootimage.1
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/mkubootimage/mkubootimage.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/mkubootimage/crc32.c
diff -u src/usr.bin/mkubootimage/crc32.c:1.4 src/usr.bin/mkubootimage/crc32.c:1.5
--- src/usr.bin/mkubootimage/crc32.c:1.4	Sat Dec 29 11:18:08 2012
+++ src/usr.bin/mkubootimage/crc32.c	Fri Feb  9 11:10:18 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: crc32.c,v 1.4 2012/12/29 16:18:08 jmcneill Exp $ */
+/* $NetBSD: crc32.c,v 1.5 2024/02/09 16:10:18 christos Exp $ */
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -33,14 +33,12 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: crc32.c,v 1.4 2012/12/29 16:18:08 jmcneill Exp $");
+__RCSID("$NetBSD: crc32.c,v 1.5 2024/02/09 16:10:18 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <stdint.h>
-
-uint32_t	crc32(const void *, size_t);
-uint32_t	crc32v(const struct iovec *, int);
+#include "crc32.h"
 
 static uint32_t crc32_tab[] = {
 	0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
@@ -99,6 +97,7 @@ crc32v(const struct iovec *iov, int cnt)
 
 	for (i = 0; i < cnt; i++) {
 		p = iov[i].iov_base;
+/*###102 [lint] warning conversion from 'unsigned long' to 'int' may lose accuracy [132]%%%*/
 		len = iov[i].iov_len;
 		while (len--)
 			crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);

Index: src/usr.bin/mkubootimage/mkubootimage.1
diff -u src/usr.bin/mkubootimage/mkubootimage.1:1.14 src/usr.bin/mkubootimage/mkubootimage.1:1.15
--- src/usr.bin/mkubootimage/mkubootimage.1:1.14	Sat Dec  7 07:34:17 2019
+++ src/usr.bin/mkubootimage/mkubootimage.1	Fri Feb  9 11:10:18 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mkubootimage.1,v 1.14 2019/12/07 12:34:17 wiz Exp $
+.\"	$NetBSD: mkubootimage.1,v 1.15 2024/02/09 16:10:18 christos Exp $
 .\"
 .\" Copyright (c) 2012 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -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,9 @@ 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

Index: src/usr.bin/mkubootimage/mkubootimage.c
diff -u src/usr.bin/mkubootimage/mkubootimage.c:1.30 src/usr.bin/mkubootimage/mkubootimage.c:1.31
--- src/usr.bin/mkubootimage/mkubootimage.c:1.30	Sat Feb  8 08:27:00 2020
+++ src/usr.bin/mkubootimage/mkubootimage.c	Fri Feb  9 11:10:18 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: mkubootimage.c,v 1.30 2020/02/08 13:27:00 ryo Exp $ */
+/* $NetBSD: mkubootimage.c,v 1.31 2024/02/09 16:10:18 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <jmcne...@invisible.ca>
@@ -30,7 +30,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: mkubootimage.c,v 1.30 2020/02/08 13:27:00 ryo Exp $");
+__RCSID("$NetBSD: mkubootimage.c,v 1.31 2024/02/09 16:10:18 christos Exp $");
 
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -51,6 +51,7 @@ __RCSID("$NetBSD: mkubootimage.c,v 1.30 
 
 #include "uboot.h"
 #include "arm64.h"
+#include "crc32.h"
 
 #ifndef __arraycount
 #define __arraycount(__x)	(sizeof(__x) / sizeof(__x[0]))
@@ -62,9 +63,6 @@ enum image_format {
 	FMT_ARM64,	/* Linux ARM64 image (booti) */
 };
 
-extern uint32_t crc32(const void *, size_t);
-extern uint32_t crc32v(const struct iovec *, int);
-
 static enum uboot_image_os image_os = IH_OS_NETBSD;
 static enum uboot_image_arch image_arch = IH_ARCH_UNKNOWN;
 static enum uboot_image_type image_type = IH_TYPE_UNKNOWN;
@@ -264,12 +262,12 @@ get_comp_name(enum uboot_image_comp comp
 __dead static void
 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[-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");
+	fprintf(stderr,
+"Usage: %s [-hu] -A <arm|arm64|i386|mips|mips64|or1k|powerpc|sh> -a address\n"
+"\t-C <bz2|gz|lzma|lzo|none> [-E address] [-e address] [-t timestamp]\n"
+"\t[-f <arm64|uimg>] [-m magic] -n image -O <freebsd|linux|netbsd|openbsd>\n"
+"\t-T <fs|kernel|kernel_noload|ramdisk|script|standalone>\n"
+"\tsource destination\n", getprogname());
 
 	exit(EXIT_FAILURE);
 }
@@ -298,7 +296,8 @@ dump_header_uimg(struct uboot_image_head
 }
 
 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;
@@ -323,7 +322,7 @@ generate_header_uimg(struct uboot_image_
 	}
 	if (image_type == IH_TYPE_SCRIPT) {
 		struct iovec iov[3];
-		dsize = st.st_size + (sizeof(uint32_t) * 2);
+		dsize = (uint32_t)(st.st_size + (sizeof(uint32_t) * 2));
 		size_buf[0] = htonl(st.st_size);
 		size_buf[1] = htonl(0);
 		iov[0].iov_base = &size_buf[0];
@@ -334,15 +333,15 @@ generate_header_uimg(struct uboot_image_
 		iov[2].iov_len = st.st_size;
 		crc = crc32v(iov, 3);
 	} else {
-		dsize = update_image ?
-		    (uint32_t)st.st_size - sizeof(*hdr) : (uint32_t)st.st_size;
+		dsize = update_image ? (uint32_t)(st.st_size - sizeof(*hdr)) :
+		    (uint32_t)st.st_size;
 		crc = crc32(p, st.st_size);
 	}
 	munmap(p, st.st_size);
 
 	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 +461,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:t:u")) != -1) {
 		switch (ch) {
 		case 'A':	/* arch */
 			image_arch = get_arch(optarg);
@@ -514,6 +514,9 @@ main(int argc, char *argv[])
 		case 'n':	/* name */
 			image_name = strdup(optarg);
 			break;
+		case 't':       /* FS timestamp */
+			repro_time = atoll(optarg);
+			break;
 		case 'u':	/* update image */
 			update_image = 1;
 			break;
@@ -584,7 +587,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),

Added files:

Index: src/usr.bin/mkubootimage/crc32.h
diff -u /dev/null src/usr.bin/mkubootimage/crc32.h:1.1
--- /dev/null	Fri Feb  9 11:10:18 2024
+++ src/usr.bin/mkubootimage/crc32.h	Fri Feb  9 11:10:18 2024
@@ -0,0 +1,28 @@
+/*-
+ * Copyright (c) 2023 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+uint32_t	crc32(const void *, size_t);
+uint32_t	crc32v(const struct iovec *, int);

Reply via email to