Module Name:    src
Committed By:   jmcneill
Date:           Wed Dec  4 11:21:34 UTC 2019

Modified Files:
        src/usr.bin/mkubootimage: mkubootimage.1 mkubootimage.c

Log Message:
Add -u flag for updating headers in place.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/mkubootimage/mkubootimage.1
cvs rdiff -u -r1.24 -r1.25 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/mkubootimage.1
diff -u src/usr.bin/mkubootimage/mkubootimage.1:1.12 src/usr.bin/mkubootimage/mkubootimage.1:1.13
--- src/usr.bin/mkubootimage/mkubootimage.1:1.12	Sun Feb  4 15:44:51 2018
+++ src/usr.bin/mkubootimage/mkubootimage.1	Wed Dec  4 11:21:34 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: mkubootimage.1,v 1.12 2018/02/04 15:44:51 jmcneill Exp $
+.\"	$NetBSD: mkubootimage.1,v 1.13 2019/12/04 11:21:34 jmcneill 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 February 4, 2018
+.Dd December 4, 2019
 .Dt MKUBOOTIMAGE 1
 .Os
 .Sh NAME
@@ -46,6 +46,7 @@
 .Fl n Ar image
 .Op Fl O Po freebsd Ns | Ns linux Ns | Ns netbsd Ns | Ns openbsd Pc
 .Fl T No ( fs Ns | Ns kernel Ns | Ns kernel_noload Ns | Ns ramdisk Ns | Ns standalone )
+.Op Fl u
 .Ar source destination
 .\"
 .Sh DESCRIPTION
@@ -124,6 +125,8 @@ Defines the image type.
 This is required for
 .Qq uimg
 format images.
+.It Fl u
+Update the header in an existing file instead of creating a new one.
 .El
 .Pp
 The required

Index: src/usr.bin/mkubootimage/mkubootimage.c
diff -u src/usr.bin/mkubootimage/mkubootimage.c:1.24 src/usr.bin/mkubootimage/mkubootimage.c:1.25
--- src/usr.bin/mkubootimage/mkubootimage.c:1.24	Sun Feb  4 17:33:34 2018
+++ src/usr.bin/mkubootimage/mkubootimage.c	Wed Dec  4 11:21:34 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: mkubootimage.c,v 1.24 2018/02/04 17:33:34 jmcneill Exp $ */
+/* $NetBSD: mkubootimage.c,v 1.25 2019/12/04 11:21:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <[email protected]>
@@ -30,7 +30,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: mkubootimage.c,v 1.24 2018/02/04 17:33:34 jmcneill Exp $");
+__RCSID("$NetBSD: mkubootimage.c,v 1.25 2019/12/04 11:21:34 jmcneill Exp $");
 
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -74,6 +74,7 @@ static uint32_t image_entrypoint = 0;
 static char *image_name;
 static uint32_t image_magic = IH_MAGIC;
 static enum image_format image_format = FMT_UIMG;
+static int update_image = 0;
 
 static const struct uboot_image_format {
 	enum image_format format;
@@ -269,7 +270,7 @@ usage(void)
 	fprintf(stderr, " -O <openbsd|netbsd|freebsd|linux>");
 	fprintf(stderr, " -T <standalone|kernel|kernel_noload|ramdisk|fs|script>");
 	fprintf(stderr, " -a <addr> [-e <ep>] [-m <magic>] -n <name>");
-	fprintf(stderr, " [-f <uimg|arm64>]");
+	fprintf(stderr, " [-f <uimg|arm64>] [-u]");
 	fprintf(stderr, " <srcfile> <dstfile>\n");
 
 	exit(EXIT_FAILURE);
@@ -431,6 +432,13 @@ write_image(void *hdr, size_t hdrlen, in
 		}
 	}
 
+	if (update_image) {
+		if (lseek(kernel_fd, hdrlen, SEEK_SET) != hdrlen) {
+			perror("seek failed");
+			return errno;
+		}
+	}
+
 	while ((rlen = read(kernel_fd, buf, sizeof(buf))) > 0) {
 		wlen = write(image_fd, buf, rlen);
 		if (wlen != rlen) {
@@ -453,7 +461,7 @@ main(int argc, char *argv[])
 	int ch;
 	unsigned long long num;
 
-	while ((ch = getopt(argc, argv, "A:C:E:O:T:a:e:f:hm:n:")) != -1) {
+	while ((ch = getopt(argc, argv, "A:C:E:O:T:a:e:f:hm:n:u")) != -1) {
 		switch (ch) {
 		case 'A':	/* arch */
 			image_arch = get_arch(optarg);
@@ -504,6 +512,9 @@ main(int argc, char *argv[])
 		case 'n':	/* name */
 			image_name = strdup(optarg);
 			break;
+		case 'u':	/* update image */
+			update_image = 1;
+			break;
 		case 'h':
 		default:
 			usage();

Reply via email to