Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/mkubootimage Add -u flag for updating headers in place.



details:   https://anonhg.NetBSD.org/src/rev/9e3edb52dcf4
branches:  trunk
changeset: 846923:9e3edb52dcf4
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Wed Dec 04 11:21:34 2019 +0000

description:
Add -u flag for updating headers in place.

diffstat:

 usr.bin/mkubootimage/mkubootimage.1 |   7 +++++--
 usr.bin/mkubootimage/mkubootimage.c |  19 +++++++++++++++----
 2 files changed, 20 insertions(+), 6 deletions(-)

diffs (103 lines):

diff -r 36af295baa09 -r 9e3edb52dcf4 usr.bin/mkubootimage/mkubootimage.1
--- a/usr.bin/mkubootimage/mkubootimage.1       Wed Dec 04 10:12:47 2019 +0000
+++ b/usr.bin/mkubootimage/mkubootimage.1       Wed Dec 04 11:21:34 2019 +0000
@@ -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 @@
 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
diff -r 36af295baa09 -r 9e3edb52dcf4 usr.bin/mkubootimage/mkubootimage.c
--- a/usr.bin/mkubootimage/mkubootimage.c       Wed Dec 04 10:12:47 2019 +0000
+++ b/usr.bin/mkubootimage/mkubootimage.c       Wed Dec 04 11:21:34 2019 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 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 @@
        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 @@
                }
        }
 
+       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 @@
        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 @@
                case 'n':       /* name */
                        image_name = strdup(optarg);
                        break;
+               case 'u':       /* update image */
+                       update_image = 1;
+                       break;
                case 'h':
                default:
                        usage();



Home | Main Index | Thread Index | Old Index