Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/ofppc/stand/ofwboot Added support for RDB partitions.



details:   https://anonhg.NetBSD.org/src/rev/3e1f43c21cba
branches:  trunk
changeset: 747325:3e1f43c21cba
user:      phx <phx%NetBSD.org@localhost>
date:      Fri Sep 11 12:00:12 2009 +0000

description:
Added support for RDB partitions.
Moved MBR parition code out of ofdev.c into mbr.c.
Tested on Pegasos2 (RDB and MBR) and RS6000.

diffstat:

 sys/arch/ofppc/stand/ofwboot/Makefile |    5 +-
 sys/arch/ofppc/stand/ofwboot/mbr.c    |  113 +++++++++++++++
 sys/arch/ofppc/stand/ofwboot/mbr.h    |   43 +++++
 sys/arch/ofppc/stand/ofwboot/ofdev.c  |   90 +----------
 sys/arch/ofppc/stand/ofwboot/ofdev.h  |    4 +-
 sys/arch/ofppc/stand/ofwboot/rdb.c    |  253 ++++++++++++++++++++++++++++++++++
 sys/arch/ofppc/stand/ofwboot/rdb.h    |   39 +++++
 sys/arch/ofppc/stand/ofwboot/version  |    3 +-
 8 files changed, 469 insertions(+), 81 deletions(-)

diffs (truncated from 659 to 300 lines):

diff -r f55edc9b36ff -r 3e1f43c21cba sys/arch/ofppc/stand/ofwboot/Makefile
--- a/sys/arch/ofppc/stand/ofwboot/Makefile     Fri Sep 11 11:44:38 2009 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/Makefile     Fri Sep 11 12:00:12 2009 +0000
@@ -1,9 +1,10 @@
-#      $NetBSD: Makefile,v 1.24 2009/01/12 07:49:57 tsutsui Exp $
+#      $NetBSD: Makefile,v 1.25 2009/09/11 12:00:12 phx Exp $
 
 S!=    cd ${.CURDIR}/../../../.. ; pwd
 
 PROG=          ofwboot
-SRCS=          ofwstart.S Locore.c boot.c ofdev.c net.c netif_of.c vers.c
+SRCS=          ofwstart.S Locore.c boot.c ofdev.c net.c netif_of.c
+SRCS+=         mbr.c rdb.c vers.c
 CFLAGS+=       -msoft-float -Wno-main -ffreestanding
 CFLAGS+=       -Wall -Wmissing-prototypes -Wstrict-prototypes -Wpointer-arith
 #CPPFLAGS+=    -g -DALLOC_TRACE -DDEBUG #-DOFW_DEBUG -DNETIF_DEBUG
diff -r f55edc9b36ff -r 3e1f43c21cba sys/arch/ofppc/stand/ofwboot/mbr.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/mbr.c        Fri Sep 11 12:00:12 2009 +0000
@@ -0,0 +1,113 @@
+/*     $NetBSD: mbr.c,v 1.1 2009/09/11 12:00:12 phx Exp $      */
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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 <sys/bootblock.h>
+
+#include <lib/libsa/byteorder.h>
+#include <lib/libsa/stand.h>
+
+#include "mbr.h"
+
+
+static u_long
+get_long(const void *p)
+{
+       const unsigned char *cp = p;
+
+       return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
+}
+
+
+/*
+ * Find a valid MBR disklabel.
+ */
+int
+search_mbr_label(struct of_dev *devp, u_long off, char *buf,
+    struct disklabel *lp, u_long off0)
+{
+       size_t read;
+       struct mbr_partition *p;
+       int i;
+       u_long poff;
+       static int recursion;
+
+       if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
+           || read != DEV_BSIZE)
+               return ERDLAB;
+
+       if (*(u_int16_t *)&buf[MBR_MAGIC_OFFSET] != sa_htole16(MBR_MAGIC))
+               return ERDLAB;
+
+       if (recursion++ <= 1)
+               off0 += off;
+       for (p = (struct mbr_partition *)(buf + MBR_PART_OFFSET), i = 0;
+            i < MBR_PART_COUNT; i++, p++) {
+               if (p->mbrp_type == MBR_PTYPE_NETBSD
+#ifdef COMPAT_386BSD_MBRPART
+                   || (p->mbrp_type == MBR_PTYPE_386BSD &&
+                       (printf("WARNING: old BSD partition ID!\n"), 1)
+                       /* XXX XXX - libsa printf() is void */ )
+#endif
+                   ) {
+                       poff = get_long(&p->mbrp_start) + off0;
+                       if (strategy(devp, F_READ, poff + LABELSECTOR,
+                                    DEV_BSIZE, buf, &read) == 0
+                           && read == DEV_BSIZE) {
+                               if (!getdisklabel(buf, lp)) {
+                                       recursion--;
+                                       return 0;
+                               }
+                       }
+                       if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
+                           || read != DEV_BSIZE) {
+                               recursion--;
+                               return ERDLAB;
+                       }
+               } else if (p->mbrp_type == MBR_PTYPE_EXT) {
+                       poff = get_long(&p->mbrp_start);
+                       if (!search_mbr_label(devp, poff, buf, lp, off0)) {
+                               recursion--;
+                               return 0;
+                       }
+                       if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
+                           || read != DEV_BSIZE) {
+                               recursion--;
+                               return ERDLAB;
+                       }
+               }
+       }
+
+       recursion--;
+       return ERDLAB;
+}
diff -r f55edc9b36ff -r 3e1f43c21cba sys/arch/ofppc/stand/ofwboot/mbr.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/mbr.h        Fri Sep 11 12:00:12 2009 +0000
@@ -0,0 +1,43 @@
+/* $NetBSD: mbr.h,v 1.1 2009/09/11 12:00:12 phx Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
+ */
+
+#ifndef MBR_H_
+#define MBR_H_
+
+#include <sys/disklabel.h>
+#include "ofdev.h"
+
+int search_mbr_label(struct of_dev *, u_long, char *, struct disklabel *,
+    u_long);
+
+#endif /* MBR_H_ */
diff -r f55edc9b36ff -r 3e1f43c21cba sys/arch/ofppc/stand/ofwboot/ofdev.c
--- a/sys/arch/ofppc/stand/ofwboot/ofdev.c      Fri Sep 11 11:44:38 2009 +0000
+++ b/sys/arch/ofppc/stand/ofwboot/ofdev.c      Fri Sep 11 12:00:12 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofdev.c,v 1.16 2009/01/12 07:49:57 tsutsui Exp $       */
+/*     $NetBSD: ofdev.c,v 1.17 2009/09/11 12:00:12 phx Exp $   */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -37,8 +37,6 @@
 #include "ofdev.h"
 
 #include <sys/param.h>
-#include <sys/disklabel.h>
-#include <sys/bootblock.h>
 
 #include <netinet/in.h>
 
@@ -52,6 +50,8 @@
 
 #include "net.h"
 #include "openfirm.h"
+#include "mbr.h"
+#include "rdb.h"
 
 extern char bootdev[];
 
@@ -120,7 +120,7 @@
        return 0;
 }
 
-static int
+int
 strategy(void *devdata, int rw, daddr_t blk, size_t size, void *buf,
         size_t *rsize)
 {
@@ -186,76 +186,6 @@
 char opened_name[256];
 int floppyboot;
 
-static u_long
-get_long(const void *p)
-{
-       const unsigned char *cp = p;
-
-       return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
-}
-
-/*
- * Find a valid disklabel.
- */
-static int
-search_label(struct of_dev *devp, u_long off, char *buf, struct disklabel *lp,
-                                                               u_long off0)
-{
-       size_t read;
-       struct mbr_partition *p;
-       int i;
-       u_long poff;
-       static int recursion;
-
-       if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
-           || read != DEV_BSIZE)
-               return ERDLAB;
-
-       if (*(u_int16_t *)&buf[MBR_MAGIC_OFFSET] != sa_htole16(MBR_MAGIC))
-               return ERDLAB;
-
-       if (recursion++ <= 1)
-               off0 += off;
-       for (p = (struct mbr_partition *)(buf + MBR_PART_OFFSET), i = 0;
-            i < MBR_PART_COUNT; i++, p++) {
-               if (p->mbrp_type == MBR_PTYPE_NETBSD
-#ifdef COMPAT_386BSD_MBRPART
-                   || (p->mbrp_type == MBR_PTYPE_386BSD &&
-                       (printf("WARNING: old BSD partition ID!\n"), 1)
-                       /* XXX XXX - libsa printf() is void */ )
-#endif
-                   ) {
-                       poff = get_long(&p->mbrp_start) + off0;
-                       if (strategy(devp, F_READ, poff + LABELSECTOR,
-                                    DEV_BSIZE, buf, &read) == 0
-                           && read == DEV_BSIZE) {
-                               if (!getdisklabel(buf, lp)) {
-                                       recursion--;
-                                       return 0;
-                               }
-                       }
-                       if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
-                           || read != DEV_BSIZE) {
-                               recursion--;
-                               return ERDLAB;
-                       }
-               } else if (p->mbrp_type == MBR_PTYPE_EXT) {
-                       poff = get_long(&p->mbrp_start);
-                       if (!search_label(devp, poff, buf, lp, off0)) {
-                               recursion--;
-                               return 0;
-                       }
-                       if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
-                           || read != DEV_BSIZE) {
-                               recursion--;
-                               return ERDLAB;
-                       }
-               }
-       }
-
-       recursion--;
-       return ERDLAB;
-}
 
 int
 devopen(struct open_file *of, const char *name, char **file)
@@ -263,11 +193,12 @@
        char *cp;
        char partition;
        char fname[256];
-       char buf[DEV_BSIZE];
        struct disklabel label;
        int handle, part;



Home | Main Index | Thread Index | Old Index