Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sandpoint/stand/altboot Suport for loading a kernel...



details:   https://anonhg.NetBSD.org/src/rev/b26d80e3ee75
branches:  trunk
changeset: 762967:b26d80e3ee75
user:      phx <phx%NetBSD.org@localhost>
date:      Sun Mar 06 18:22:13 2011 +0000

description:
Suport for loading a kernel from memory (RAM, ROM or Flash).
The boot file path should look like "mem:<address>", where <address> is
the start address, in hex notation, of the file in memory.

diffstat:

 sys/arch/sandpoint/stand/altboot/Makefile   |    7 +-
 sys/arch/sandpoint/stand/altboot/brdsetup.c |   11 +--
 sys/arch/sandpoint/stand/altboot/devopen.c  |   11 ++-
 sys/arch/sandpoint/stand/altboot/globals.h  |    5 +-
 sys/arch/sandpoint/stand/altboot/main.c     |   33 ++++++-
 sys/arch/sandpoint/stand/altboot/memfs.c    |  122 ++++++++++++++++++++++++++++
 sys/arch/sandpoint/stand/altboot/memfs.h    |   31 +++++++
 7 files changed, 202 insertions(+), 18 deletions(-)

diffs (truncated from 327 to 300 lines):

diff -r 6f3761d12574 -r b26d80e3ee75 sys/arch/sandpoint/stand/altboot/Makefile
--- a/sys/arch/sandpoint/stand/altboot/Makefile Sun Mar 06 18:15:30 2011 +0000
+++ b/sys/arch/sandpoint/stand/altboot/Makefile Sun Mar 06 18:22:13 2011 +0000
@@ -1,12 +1,13 @@
-#      $NetBSD: Makefile,v 1.9 2011/03/06 13:55:12 phx Exp $
+#      $NetBSD: Makefile,v 1.10 2011/03/06 18:22:13 phx Exp $
 
 S=             ${.CURDIR}/../../../..
 
 PROG=          altboot
 FILES+=                ${PROG}.bin ${PROG}.img
 NOMAN=         # defined
-SRCS=          entry.S main.c brdsetup.c pci.c devopen.c dev_net.c nif.c
-SRCS+=         fxp.c tlp.c rge.c skg.c stg.c dsk.c pciide.c siisata.c
+SRCS=          entry.S main.c brdsetup.c pci.c devopen.c dev_net.c memfs.c
+SRCS+=         nif.c fxp.c tlp.c rge.c skg.c stg.c
+SRCS+=         dsk.c pciide.c siisata.c
 SRCS+=         printf.c vers.c
 CLEANFILES+=   vers.c ${PROG} ${PROG}.bin ${PROG}.img
 CFLAGS+=       -Wall -Wno-main -ffreestanding -msoft-float -mmultiple
diff -r 6f3761d12574 -r b26d80e3ee75 sys/arch/sandpoint/stand/altboot/brdsetup.c
--- a/sys/arch/sandpoint/stand/altboot/brdsetup.c       Sun Mar 06 18:15:30 2011 +0000
+++ b/sys/arch/sandpoint/stand/altboot/brdsetup.c       Sun Mar 06 18:22:13 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: brdsetup.c,v 1.6 2011/03/06 13:55:12 phx Exp $ */
+/* $NetBSD: brdsetup.c,v 1.7 2011/03/06 18:22:13 phx Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -959,20 +959,13 @@
        return NULL;
 }
 
-static uint8_t hex2nibble(char c)
-{
-       if (c >= 'a')
-               c &= ~0x20;
-       return c > '9' ? c - 'A' + 10 : c - '0';
-}
-
 static void
 read_mac_string(uint8_t *mac, char *p)
 {
        int i;
 
        for (i = 0; i < 6; i++, p += 3)
-               *mac++ = (hex2nibble(p[0]) << 4) | hex2nibble(p[1]);
+               *mac++ = read_hex(p);
 }
 
 /*
diff -r 6f3761d12574 -r b26d80e3ee75 sys/arch/sandpoint/stand/altboot/devopen.c
--- a/sys/arch/sandpoint/stand/altboot/devopen.c        Sun Mar 06 18:15:30 2011 +0000
+++ b/sys/arch/sandpoint/stand/altboot/devopen.c        Sun Mar 06 18:22:13 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: devopen.c,v 1.1 2011/01/23 01:05:30 nisimura Exp $ */
+/* $NetBSD: devopen.c,v 1.2 2011/03/06 18:22:13 phx Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -40,6 +40,7 @@
 #include <lib/libkern/libkern.h>
 
 #include "globals.h"
+#include "memfs.h"
 
 struct devsw devnet = { "net", net_strategy, net_open, net_close, noioctl };
 struct devsw devdsk = { "dsk", dsk_strategy, dsk_open, dsk_close, noioctl };
@@ -50,6 +51,7 @@
 struct fs_ops fs_tftp  = FS_OPS(tftp);
 struct fs_ops fs_ffsv2 = FS_OPS(ffsv2);
 struct fs_ops fs_ffsv1 = FS_OPS(ffsv1);
+struct fs_ops fs_mem   = FS_OPS(mem);
 extern char *fsmod;
 
 static void parseunit(const char *, int *, int *, char **);
@@ -64,6 +66,13 @@
        if (of->f_flags != F_READ)
                return EPERM;
 
+       if (strncmp("mem:", name, 4) == 0) {
+               of->f_dev = NULL;
+               of->f_flags |= F_NODEV;
+               file_system[0] = fs_mem;
+               *file = (char *)&name[4];
+               return 0;               /* MEM */
+       }
        if (strncmp("net:", name, 4) == 0 || strncmp("nfs:", name, 4) == 0) {
                of->f_dev = &devnet;
                if ((error = net_open(of, &name[4], "nfs")) != 0)
diff -r 6f3761d12574 -r b26d80e3ee75 sys/arch/sandpoint/stand/altboot/globals.h
--- a/sys/arch/sandpoint/stand/altboot/globals.h        Sun Mar 06 18:15:30 2011 +0000
+++ b/sys/arch/sandpoint/stand/altboot/globals.h        Sun Mar 06 18:22:13 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: globals.h,v 1.7 2011/03/06 13:55:12 phx Exp $ */
+/* $NetBSD: globals.h,v 1.8 2011/03/06 18:22:13 phx Exp $ */
 
 #ifdef DEBUG
 #define        DPRINTF(x)      printf x
@@ -117,6 +117,9 @@
 void _wbinv(uint32_t, uint32_t);
 void _inv(uint32_t, uint32_t);
 
+/* parsing */
+uint32_t read_hex(const char *);
+
 /* heap */
 void *allocaligned(size_t, size_t);
 
diff -r 6f3761d12574 -r b26d80e3ee75 sys/arch/sandpoint/stand/altboot/main.c
--- a/sys/arch/sandpoint/stand/altboot/main.c   Sun Mar 06 18:15:30 2011 +0000
+++ b/sys/arch/sandpoint/stand/altboot/main.c   Sun Mar 06 18:22:13 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.8 2011/03/06 13:55:12 phx Exp $ */
+/* $NetBSD: main.c,v 1.9 2011/03/06 18:22:13 phx Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -482,6 +482,31 @@
        return (void *)((p + align) & ~align);
 }
 
+static int hex2nibble(char c)
+{
+
+       if (c >= 'a')
+               c &= ~0x20;
+       if (c >= 'A' && c <= 'F')
+               c -= 'A' - ('9' + 1);
+       else if (c < '0' || c > '9')
+               return -1;
+
+       return c - '0';
+}
+
+uint32_t
+read_hex(const char *s)
+{
+       int n;
+       uint32_t val;
+
+       val = 0;
+       while ((n = hex2nibble(*s++)) >= 0)
+               val = (val << 4) | n;
+       return val;
+}
+
 static int
 check_bootname(char *s)
 {
@@ -491,12 +516,12 @@
         * tftp:
         * tftp:<bootfile>
         * wd[N[P]]:<bootfile>
+        * mem:<address>
         *
         * net is a synonym of nfs.
         */
-       if (strncmp(s, "nfs:", 4) == 0 || strncmp(s, "net:", 4) == 0)
-               return 1;
-       if (strncmp(s, "tftp:", 5) == 0)
+       if (strncmp(s, "nfs:", 4) == 0 || strncmp(s, "net:", 4) == 0 ||
+           strncmp(s, "tftp:", 5) == 0 || strncmp(s, "mem:", 4) == 0)
                return 1;
        if (s[0] == 'w' && s[1] == 'd') {
                s += 2;
diff -r 6f3761d12574 -r b26d80e3ee75 sys/arch/sandpoint/stand/altboot/memfs.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sandpoint/stand/altboot/memfs.c  Sun Mar 06 18:22:13 2011 +0000
@@ -0,0 +1,122 @@
+/* $NetBSD: memfs.c,v 1.1 2011/03/06 18:22:13 phx Exp $ */
+
+/*-
+ * Copyright (c) 2011 Frank Wille.
+ * All rights reserved.
+ *
+ * Written by Frank Wille for The NetBSD Project.
+ *
+ * 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.
+ */
+
+#include <sys/param.h>
+
+#include <lib/libsa/stand.h>
+
+#include "globals.h"
+#include "memfs.h"
+
+struct memhandle {
+       char *base;
+       off_t off;
+};
+
+int
+mem_open(const char *path, struct open_file *f)
+{
+       struct memhandle *mh;
+
+       mh = alloc(sizeof(struct memhandle));
+       if (mh == NULL)
+               return ENOMEM;
+       mh->base = (char *)read_hex(path);
+       mh->off = 0;
+       f->f_fsdata = mh;
+       return 0;
+}
+
+#ifndef LIBSA_NO_FS_CLOSE
+int
+mem_close(struct open_file *f)
+{
+
+       dealloc(f->f_fsdata, sizeof(struct memhandle));
+       return 0;
+}
+#endif
+
+int
+mem_read(struct open_file *f, void *buf, size_t size, size_t *resid)
+{
+       struct memhandle *mh;
+
+       mh = f->f_fsdata;
+       memcpy(buf, mh->base + mh->off, size);
+       mh->off += size;
+       if (resid)
+               *resid = 0;
+       return 0;
+}
+
+#ifndef LIBSA_NO_FS_WRITE
+int
+mem_write(struct open_file *f, void *buf, size_t size, size_t *resid)
+{
+       struct memhandle *mh;
+
+       mh = f->f_fsdata;
+       memcpy(mh->base + mh->off, buf, size);
+       mh->off += size;
+       if (resid)
+               *resid = 0;
+       return 0;
+}
+#endif
+
+#ifndef LIBSA_NO_FS_SEEK
+off_t
+mem_seek(struct open_file *f, off_t offset, int where)
+{
+       struct memhandle *mh;
+
+       mh = f->f_fsdata;
+       switch (where) {
+       case SEEK_SET:
+               mh->off = offset;
+               break;
+       case SEEK_CUR:
+               mh->off += offset;
+               break;
+       default:
+               errno = EOFFSET;
+               return -1;
+       }
+       return mh->off;
+}
+#endif
+
+int
+mem_stat(struct open_file *f, struct stat *sb)
+{
+
+       return EIO;
+}
diff -r 6f3761d12574 -r b26d80e3ee75 sys/arch/sandpoint/stand/altboot/memfs.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sandpoint/stand/altboot/memfs.h  Sun Mar 06 18:22:13 2011 +0000
@@ -0,0 +1,31 @@
+/* $NetBSD: memfs.h,v 1.1 2011/03/06 18:22:13 phx Exp $ */
+
+/*-
+ * Copyright (c) 2011 Frank Wille.



Home | Main Index | Thread Index | Old Index