Module Name: src Committed By: martin Date: Fri Apr 2 18:39:44 UTC 2010
Modified Files: src/sys/arch/sparc/stand/ofwboot: Makefile boot.c ofdev.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/sys/arch/sparc/stand/ofwboot/Makefile cvs rdiff -u -r1.21 -r1.22 src/sys/arch/sparc/stand/ofwboot/boot.c cvs rdiff -u -r1.26 -r1.27 src/sys/arch/sparc/stand/ofwboot/ofdev.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/sparc/stand/ofwboot/Makefile diff -u src/sys/arch/sparc/stand/ofwboot/Makefile:1.22 src/sys/arch/sparc/stand/ofwboot/Makefile:1.23 --- src/sys/arch/sparc/stand/ofwboot/Makefile:1.22 Fri Nov 27 11:14:23 2009 +++ src/sys/arch/sparc/stand/ofwboot/Makefile Fri Apr 2 18:39:44 2010 @@ -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 Index: src/sys/arch/sparc/stand/ofwboot/boot.c diff -u src/sys/arch/sparc/stand/ofwboot/boot.c:1.21 src/sys/arch/sparc/stand/ofwboot/boot.c:1.22 --- src/sys/arch/sparc/stand/ofwboot/boot.c:1.21 Wed Jan 27 22:18:37 2010 +++ src/sys/arch/sparc/stand/ofwboot/boot.c Fri Apr 2 18:39:44 2010 @@ -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); /* Index: src/sys/arch/sparc/stand/ofwboot/ofdev.c diff -u src/sys/arch/sparc/stand/ofwboot/ofdev.c:1.26 src/sys/arch/sparc/stand/ofwboot/ofdev.c:1.27 --- src/sys/arch/sparc/stand/ofwboot/ofdev.c:1.26 Wed Feb 17 15:50:06 2010 +++ src/sys/arch/sparc/stand/ofwboot/ofdev.c Fri Apr 2 18:39:44 2010 @@ -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()) {