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 support for generating boot.scr scr...



details:   https://anonhg.NetBSD.org/src/rev/0b1127f64695
branches:  trunk
changeset: 783566:0b1127f64695
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Dec 29 15:11:56 2012 +0000

description:
add support for generating boot.scr scripts with -T script

diffstat:

 usr.bin/mkubootimage/crc32.c        |  28 +++++++++++++++----
 usr.bin/mkubootimage/mkubootimage.1 |   6 ++--
 usr.bin/mkubootimage/mkubootimage.c |  51 +++++++++++++++++++++++++++++++-----
 usr.bin/mkubootimage/uboot.h        |   3 +-
 4 files changed, 71 insertions(+), 17 deletions(-)

diffs (231 lines):

diff -r d0f08e7266a4 -r 0b1127f64695 usr.bin/mkubootimage/crc32.c
--- a/usr.bin/mkubootimage/crc32.c      Sat Dec 29 14:51:41 2012 +0000
+++ b/usr.bin/mkubootimage/crc32.c      Sat Dec 29 15:11:56 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: crc32.c,v 1.2 2010/06/22 14:54:11 dogcow Exp $ */
+/* $NetBSD: crc32.c,v 1.3 2012/12/29 15:11:56 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2002 Marcel Moolenaar
@@ -33,9 +33,10 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: crc32.c,v 1.2 2010/06/22 14:54:11 dogcow Exp $");
+__RCSID("$NetBSD: crc32.c,v 1.3 2012/12/29 15:11:56 jmcneill Exp $");
 
 #include <sys/types.h>
+#include <sys/uio.h>
 #include <stdint.h>
 
 uint32_t       crc32(const void *, size_t);
@@ -87,16 +88,31 @@
 };
 
 uint32_t
-crc32(const void *buf, size_t size)
+crc32v(const struct iovec *iov, int cnt)
 {
        const uint8_t *p;
        uint32_t crc;
+       int i, len;
 
-       p = buf;
        crc = ~0U;
 
-       while (size--)
-               crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
+       for (i = 0; i < cnt; i++) {
+               p = iov[i].iov_base;
+               len = iov[i].iov_len;
+               while (len--)
+                       crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
+       }
 
        return crc ^ ~0U;
 }
+
+uint32_t
+crc32(const void *buf, size_t size)
+{
+       struct iovec iov[1];
+
+       iov[0].iov_base = __UNCONST(buf);
+       iov[0].iov_len = size;
+
+       return crc32v(iov, 1);
+}
diff -r d0f08e7266a4 -r 0b1127f64695 usr.bin/mkubootimage/mkubootimage.1
--- a/usr.bin/mkubootimage/mkubootimage.1       Sat Dec 29 14:51:41 2012 +0000
+++ b/usr.bin/mkubootimage/mkubootimage.1       Sat Dec 29 15:11:56 2012 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mkubootimage.1,v 1.4 2012/12/01 08:16:25 wiz Exp $
+.\"    $NetBSD: mkubootimage.1,v 1.5 2012/12/29 15:11:56 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 November 28, 2012
+.Dd December 29, 2012
 .Dt MKUBOOTIMAGE 1
 .Os
 .Sh NAME
@@ -108,7 +108,7 @@
 Defines the operating system type.
 The default OS name is
 .Qq netbsd .
-.It Fl T No ( fs Ns | Ns kernel Ns | Ns ramdisk Ns | Ns standalone )
+.It Fl T No ( fs Ns | Ns kernel Ns | Ns ramdisk Ns | Ns standalone Ns | Ns script )
 Defines the image type.
 This is required.
 .El
diff -r d0f08e7266a4 -r 0b1127f64695 usr.bin/mkubootimage/mkubootimage.c
--- a/usr.bin/mkubootimage/mkubootimage.c       Sat Dec 29 14:51:41 2012 +0000
+++ b/usr.bin/mkubootimage/mkubootimage.c       Sat Dec 29 15:11:56 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkubootimage.c,v 1.16 2012/02/17 08:28:36 matt Exp $ */
+/* $NetBSD: mkubootimage.c,v 1.17 2012/12/29 15:11:56 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -30,11 +30,12 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: mkubootimage.c,v 1.16 2012/02/17 08:28:36 matt Exp $");
+__RCSID("$NetBSD: mkubootimage.c,v 1.17 2012/12/29 15:11:56 jmcneill Exp $");
 
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/endian.h>
+#include <sys/uio.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -53,6 +54,7 @@
 #endif
 
 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;
@@ -143,6 +145,7 @@
        { IH_TYPE_KERNEL,       "kernel" },
        { IH_TYPE_RAMDISK,      "ramdisk" },
        { IH_TYPE_FILESYSTEM,   "fs" },
+       { IH_TYPE_SCRIPT,       "script" },
 };
 
 static enum uboot_image_type
@@ -214,7 +217,7 @@
        fprintf(stderr, "usage: mkubootimage -A <arm|mips|mips64|powerpc>");
        fprintf(stderr, " -C <none|bz2|gz|lzma|lzo>");
        fprintf(stderr, " -O <openbsd|netbsd|freebsd|linux>");
-       fprintf(stderr, " -T <standalone|kernel|ramdisk|fs>");
+       fprintf(stderr, " -T <standalone|kernel|ramdisk|fs|script>");
        fprintf(stderr, " -a <addr> [-e <ep>] [-m <magic>] -n <name>");
        fprintf(stderr, " <srcfile> <dstfile>\n");
 
@@ -249,7 +252,7 @@
 {
        uint8_t *p;
        struct stat st;
-       uint32_t crc;
+       uint32_t crc, dsize, size_buf[2];
        int error;
 
        error = fstat(kernel_fd, &st);
@@ -268,13 +271,28 @@
                perror("mmap kernel");
                return EINVAL;
        }
-       crc = crc32(p, st.st_size);
+       if (image_type == IH_TYPE_SCRIPT) {
+               struct iovec iov[3];
+               dsize = 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];
+               iov[0].iov_len = sizeof(size_buf[0]);
+               iov[1].iov_base = &size_buf[1];
+               iov[1].iov_len = sizeof(size_buf[1]);
+               iov[2].iov_base = p;
+               iov[2].iov_len = st.st_size;
+               crc = crc32v(iov, 3);
+       } else {
+               dsize = 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_size = htonl(st.st_size);
+       hdr->ih_size = htonl(dsize);
        hdr->ih_load = htonl(image_loadaddr);
        hdr->ih_ep = htonl(image_entrypoint);
        hdr->ih_dcrc = htonl(crc);
@@ -296,6 +314,15 @@
 {
        uint8_t buf[4096];
        ssize_t rlen, wlen;
+       struct stat st;
+       uint32_t size_buf[2];
+       int error;
+
+       error = fstat(kernel_fd, &st);
+       if (error == -1) {
+               perror("stat");
+               return errno;
+       }
 
        wlen = write(image_fd, hdr, sizeof(*hdr));
        if (wlen != sizeof(*hdr)) {
@@ -303,6 +330,16 @@
                return errno;
        }
 
+       if (image_type == IH_TYPE_SCRIPT) {
+               size_buf[0] = htonl(st.st_size);
+               size_buf[1] = htonl(0);
+               wlen = write(image_fd, &size_buf, sizeof(size_buf));
+               if (wlen != sizeof(size_buf)) {
+                       perror("short write");
+                       return errno;
+               }
+       }
+
        while ((rlen = read(kernel_fd, buf, sizeof(buf))) > 0) {
                wlen = write(image_fd, buf, rlen);
                if (wlen != rlen) {
@@ -388,7 +425,7 @@
 
        if (image_arch == IH_ARCH_UNKNOWN ||
            image_type == IH_TYPE_UNKNOWN ||
-           image_loadaddr == 0 ||
+           (image_type != IH_TYPE_SCRIPT && image_loadaddr == 0) ||
            image_name == NULL)
                usage();
 
diff -r d0f08e7266a4 -r 0b1127f64695 usr.bin/mkubootimage/uboot.h
--- a/usr.bin/mkubootimage/uboot.h      Sat Dec 29 14:51:41 2012 +0000
+++ b/usr.bin/mkubootimage/uboot.h      Sat Dec 29 15:11:56 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uboot.h,v 1.4 2011/08/03 17:46:40 matt Exp $ */
+/* $NetBSD: uboot.h,v 1.5 2012/12/29 15:11:56 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -49,6 +49,7 @@
        IH_TYPE_STANDALONE = 1,
        IH_TYPE_KERNEL = 2,
        IH_TYPE_RAMDISK = 3,
+       IH_TYPE_SCRIPT = 6,
        IH_TYPE_FILESYSTEM = 7,
 };
 



Home | Main Index | Thread Index | Old Index