Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc/stand/ofwboot Add support for /boot.cfg. Impl...



details:   https://anonhg.NetBSD.org/src/rev/dff460e017ac
branches:  trunk
changeset: 753581:dff460e017ac
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Apr 02 18:39:44 2010 +0000

description:
Add support for /boot.cfg. Implement a single command for now: override
the boot partition, which will be used for bootable CDs. Add cd9660
support.

diffstat:

 sys/arch/sparc/stand/ofwboot/Makefile |    4 +-
 sys/arch/sparc/stand/ofwboot/boot.c   |  105 +++++++++++++++++++++++++++++++++-
 sys/arch/sparc/stand/ofwboot/ofdev.c  |    4 +-
 3 files changed, 109 insertions(+), 4 deletions(-)

diffs (183 lines):

diff -r a8ba7d880d9e -r dff460e017ac sys/arch/sparc/stand/ofwboot/Makefile
--- a/sys/arch/sparc/stand/ofwboot/Makefile     Fri Apr 02 18:34:16 2010 +0000
+++ b/sys/arch/sparc/stand/ofwboot/Makefile     Fri Apr 02 18:39:44 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.22 2009/11/27 11:14:23 tsutsui Exp $
+#      $NetBSD: Makefile,v 1.23 2010/04/02 18:39:44 martin Exp $
 
 CURDIR=        ${.CURDIR}
 S=     ${CURDIR}/../../../..
@@ -59,7 +59,7 @@
 CPPFLAGS+=     -DSPARC_BOOT_ELF
 CPPFLAGS+=     -DSPARC_BOOT_UFS
 CPPFLAGS+=     -DSPARC_BOOT_NFS
-#CPPFLAGS+=    -DSPARC_BOOT_CD9660
+CPPFLAGS+=     -DSPARC_BOOT_CD9660
 
 ### find out what to use for libkern
 KERN_AS=       library
diff -r a8ba7d880d9e -r dff460e017ac sys/arch/sparc/stand/ofwboot/boot.c
--- a/sys/arch/sparc/stand/ofwboot/boot.c       Fri Apr 02 18:34:16 2010 +0000
+++ b/sys/arch/sparc/stand/ofwboot/boot.c       Fri Apr 02 18:39:44 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.21 2010/01/27 22:18:37 martin Exp $ */
+/*     $NetBSD: boot.c,v 1.22 2010/04/02 18:39:44 martin Exp $ */
 
 /*
  * Copyright (c) 1997, 1999 Eduardo E. Horvath.  All rights reserved.
@@ -89,6 +89,8 @@
 };
 
 char bootdev[PROM_MAX_PATH];
+bool root_fs_quickseekable = true;     /* unset for tftp boots */
+static bool bootinfo_pass_bootdev = false;
 
 int debug  = 0;
 int compatmode = 0;
@@ -272,6 +274,17 @@
        bi_add(&bi_sym, BTINFO_SYMTAB, sizeof(bi_sym));
        bi_kend.addr= bootinfo + BOOTINFO_SIZE;
        bi_add(&bi_kend, BTINFO_KERNEND, sizeof(bi_kend));
+       if (bootinfo_pass_bootdev) {
+               struct {
+                       struct btinfo_common common;
+                       char name[256];
+               } info;
+               
+               strcpy(info.name, bootdev);
+               bi_add(&info, BTINFO_BOOTDEV, strlen(bootdev)
+                       +sizeof(struct btinfo_bootdev));
+       }
+
        sparc64_finalize_tlb(marks[MARK_DATA]);
        sparc64_bi_add();
 
@@ -383,6 +396,95 @@
                "  disk:a netbsd -s\n");
 }
 
+static void
+do_config_command(const char *cmd, const char *arg)
+{
+       DPRINTF(("do_config_command: %s\n", cmd));
+       if (strcmp(cmd, "bootpartition") == 0) {
+               char *c;
+
+               DPRINTF(("switching boot partition to %s from %s\n",
+                   arg, bootdev));
+               c = strrchr(bootdev, ':');
+               if (!c) return;
+               if (c[1] == 0) return;
+               if (strlen(arg) > strlen(c)) return;
+               strcpy(c, arg);
+               DPRINTF(("new boot device: %s\n", bootdev));
+               bootinfo_pass_bootdev = true;
+       }
+}
+
+static void
+parse_boot_config(char *cfg, size_t len)
+{
+       const char *cmd = NULL, *arg = NULL;
+
+       while (len) {
+               if (isspace(*cfg)) {
+                       cfg++; len--; continue;
+               }
+               if (*cfg == ';' || *cfg == '#') {
+                       while (len && *cfg != '\r' && *cfg != '\n') {
+                               cfg++; len--;
+                       }
+                       continue;
+               }
+               cmd = cfg;
+               while (len && !isspace(*cfg)) {
+                       cfg++; len--;
+               }
+               *cfg = 0;
+               if (len > 0) {
+                       cfg++; len--;
+                       while (isspace(*cfg) && len) {
+                               cfg++; len--;
+                       }
+                       if (len > 0 ) {
+                               arg = cfg;
+                               while (len && !isspace(*cfg)) {
+                                       cfg++; len--;
+                               }
+                               *cfg = 0;
+                       }
+               }
+               do_config_command(cmd, arg);
+               if (len > 0) {
+                       cfg++; len--;
+               }
+       }
+}
+
+static void
+check_boot_config(void)
+{
+       int fd, err, off, len;
+       struct stat st;
+       char *bc;
+
+       if (!root_fs_quickseekable) return;
+       DPRINTF(("checking for /boot.cfg...\n"));
+       fd = open("/boot.cfg", 0);
+       if (fd < 0) return;
+       DPRINTF(("found /boot.cfg\n"));
+       if (fstat(fd, &st) == -1 || st.st_size > 32*1024) {
+               close(fd);
+               return;
+       }
+       bc = alloc(st.st_size+1);
+       off = 0;
+       do {
+               len = read(fd, bc+off, 1024);
+               if (len <= 0)
+                       break;
+               off += len;
+       } while (len > 0);
+       bc[off] = 0;
+       close(fd);
+
+       parse_boot_config(bc, off);
+}
+
 void
 main(void *ofw)
 {
@@ -438,6 +540,7 @@
                        boothowto |= RB_ASKNAME;
                }
 
+               check_boot_config();
                start_kernel(kernel, bootline, ofw);
 
                /*
diff -r a8ba7d880d9e -r dff460e017ac sys/arch/sparc/stand/ofwboot/ofdev.c
--- a/sys/arch/sparc/stand/ofwboot/ofdev.c      Fri Apr 02 18:34:16 2010 +0000
+++ b/sys/arch/sparc/stand/ofwboot/ofdev.c      Fri Apr 02 18:39:44 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofdev.c,v 1.26 2010/02/17 15:50:06 eeh Exp $   */
+/*     $NetBSD: ofdev.c,v 1.27 2010/04/02 18:39:44 martin Exp $        */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -58,6 +58,7 @@
 #include "boot.h"
 
 extern char bootdev[];
+extern bool root_fs_quickseekable;
 
 /*
  * This is ugly.  A path on a sparc machine is something like this:
@@ -545,6 +546,7 @@
                                net_close(&ofdev);
                                goto bad;
                        }
+                       root_fs_quickseekable = false;
                } else {
                        memcpy(&file_system[0], &file_system_nfs, sizeof file_system[0]);
                        if (error = net_mountroot()) {



Home | Main Index | Thread Index | Old Index