Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/i386/stand Add GPT and RAIDframe support to bootloa...
details: https://anonhg.NetBSD.org/src/rev/5d942235d9c4
branches: trunk
changeset: 964795:5d942235d9c4
user: manu <manu%NetBSD.org@localhost>
date: Sun Aug 18 02:18:24 2019 +0000
description:
Add GPT and RAIDframe support to bootloaders
Classic BIOS (/boot) and EFI bootloaders can now name devices
using the NAME=gpt_label syntax, or using raid partitions. Here
are examples:
boot NAME=root:/netbsd
boot raid0e:/netbsd
diffstat:
sys/arch/i386/stand/boot/boot2.c | 72 ++-
sys/arch/i386/stand/boot/devopen.c | 34 +-
sys/arch/i386/stand/boot/devopen.h | 4 +-
sys/arch/i386/stand/efiboot/boot.c | 64 ++-
sys/arch/i386/stand/efiboot/devopen.c | 28 +-
sys/arch/i386/stand/efiboot/devopen.h | 6 +-
sys/arch/i386/stand/efiboot/efidisk.c | 153 +++++-
sys/arch/i386/stand/lib/Makefile | 3 +-
sys/arch/i386/stand/lib/biosdisk.c | 867 ++++++++++++++++++++++++++++++---
sys/arch/i386/stand/lib/biosdisk.h | 16 +-
10 files changed, 1097 insertions(+), 150 deletions(-)
diffs (truncated from 1987 to 300 lines):
diff -r cbccab534ccc -r 5d942235d9c4 sys/arch/i386/stand/boot/boot2.c
--- a/sys/arch/i386/stand/boot/boot2.c Sat Aug 17 21:14:22 2019 +0000
+++ b/sys/arch/i386/stand/boot/boot2.c Sun Aug 18 02:18:24 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: boot2.c,v 1.70 2017/11/14 09:55:41 maxv Exp $ */
+/* $NetBSD: boot2.c,v 1.71 2019/08/18 02:18:24 manu Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -79,6 +79,7 @@
#include <libi386.h>
#include <bootmod.h>
#include <bootmenu.h>
+#include <biosdisk.h>
#include <vbe.h>
#include "devopen.h"
@@ -104,11 +105,16 @@
#define NUMNAMES (sizeof(names)/sizeof(names[0]))
#define DEFFILENAME names[0][0]
+#ifndef NO_GPT
+#define MAXDEVNAME 39 /* "NAME=" + 34 char part_name */
+#else
#define MAXDEVNAME 16
+#endif
static char *default_devname;
static int default_unit, default_partition;
static const char *default_filename;
+static const char *default_part_name;
char *sprint_bootsel(const char *);
static void bootit(const char *, int);
@@ -160,9 +166,15 @@
int *unit, int *partition, const char **file)
{
const char *col;
+ static char savedevname[MAXDEVNAME+1];
*fsname = "ufs";
- *devname = default_devname;
+ if (default_part_name == NULL) {
+ *devname = default_devname;
+ } else {
+ snprintf(savedevname, MAXDEVNAME, "NAME=%s", default_part_name);
+ *devname = savedevname;
+ }
*unit = default_unit;
*partition = default_partition;
*file = default_filename;
@@ -171,7 +183,6 @@
return 0;
if ((col = strchr(fname, ':')) != NULL) { /* device given */
- static char savedevname[MAXDEVNAME+1];
int devlen;
int u = 0, p = 0;
int i = 0;
@@ -180,6 +191,17 @@
if (devlen > MAXDEVNAME)
return EINVAL;
+#ifndef NO_GPT
+ if (strstr(fname, "NAME=") == fname) {
+ strlcpy(savedevname, fname, devlen + 1);
+ *devname = savedevname;
+ *unit = -1;
+ *partition = -1;
+ fname = col + 1;
+ goto out;
+ }
+#endif
+
#define isvalidname(c) ((c) >= 'a' && (c) <= 'z')
if (!isvalidname(fname[i]))
return EINVAL;
@@ -215,6 +237,7 @@
fname = col + 1;
}
+out:
if (*fname)
*file = fname;
@@ -231,8 +254,11 @@
if (parsebootfile(filename, &fsname, &devname, &unit,
&partition, &file) == 0) {
- snprintf(buf, sizeof(buf), "%s%d%c:%s", devname, unit,
- 'a' + partition, file);
+ if (strstr(devname, "NAME=") == devname)
+ snprintf(buf, sizeof(buf), "%s:%s", devname, file);
+ else
+ snprintf(buf, sizeof(buf), "%s%d%c:%s", devname, unit,
+ 'a' + partition, file);
return buf;
}
return "(invalid)";
@@ -319,7 +345,7 @@
/* try to set default device to what BIOS tells us */
bios2dev(biosdev, biossector, &default_devname, &default_unit,
- &default_partition);
+ &default_partition, &default_part_name);
/* if the user types "boot" without filename */
default_filename = DEFFILENAME;
@@ -401,13 +427,21 @@
{
printf("commands are:\n"
- "boot [xdNx:][filename] [-12acdqsvxz]\n"
+ "boot [dev:][filename] [-12acdqsvxz]\n"
+#ifndef NO_RAIDFRAME
+ " dev syntax is (hd|fd|cd|raid)[N[x]]\n"
+#else
+ " dev syntax is (hd|fd|cd)[N[x]]n"
+#endif
+#ifndef NO_GPT
+ " or NAME=gpt_label\n"
+#endif
" (ex. \"hd0a:netbsd.old -s\")\n"
- "pkboot [xdNx:][filename] [-12acdqsvxz]\n"
+ "pkboot [dev:][filename] [-12acdqsvxz]\n"
#if LIBSA_ENABLE_LS_OP
- "ls [path]\n"
+ "ls [dev:][path]\n"
#endif
- "dev xd[N[x]]:\n"
+ "dev [dev:]\n"
"consdev {pc|com[0123]|com[0123]kbd|auto}\n"
"vesa {modenum|on|off|enabled|disabled|list}\n"
#ifndef SMALL
@@ -415,7 +449,7 @@
#endif
"modules {on|off|enabled|disabled}\n"
"load {path_to_module}\n"
- "multiboot [xdNx:][filename] [<args>]\n"
+ "multiboot [dev:][filename] [<args>]\n"
"splash {path_to_image_file}\n"
"userconf {command}\n"
"rndseed {path_to_rndseed_file}\n"
@@ -490,8 +524,16 @@
if (*arg == '\0') {
biosdisk_probe();
- printf("default %s%d%c\n", default_devname, default_unit,
- 'a' + default_partition);
+
+#ifndef NO_GPT
+ if (default_part_name)
+ printf("default NAME=%s on %s%d\n", default_part_name,
+ default_devname, default_unit);
+ else
+#endif
+ printf("default %s%d%c\n",
+ default_devname, default_unit,
+ 'a' + default_partition);
return;
}
@@ -505,6 +547,10 @@
/* put to own static storage */
strncpy(savedevname, devname, MAXDEVNAME + 1);
default_devname = savedevname;
+
+ /* +5 to skip leading NAME= */
+ if (strstr(devname, "NAME=") == devname)
+ default_part_name = default_devname + 5;
}
static const struct cons_devs {
diff -r cbccab534ccc -r 5d942235d9c4 sys/arch/i386/stand/boot/devopen.c
--- a/sys/arch/i386/stand/boot/devopen.c Sat Aug 17 21:14:22 2019 +0000
+++ b/sys/arch/i386/stand/boot/devopen.c Sun Aug 18 02:18:24 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: devopen.c,v 1.8 2010/12/24 20:40:42 jakllsch Exp $ */
+/* $NetBSD: devopen.c,v 1.9 2019/08/18 02:18:24 manu Exp $ */
/*-
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -89,7 +89,8 @@
}
void
-bios2dev(int biosdev, daddr_t sector, char **devname, int *unit, int *partition)
+bios2dev(int biosdev, daddr_t sector, char **devname, int *unit,
+ int *partition, const char **part_name)
{
/* set default */
@@ -109,7 +110,7 @@
} else
*devname = "fd";
- *partition = biosdisk_findpartition(biosdev, sector);
+ (void)biosdisk_findpartition(biosdev, sector, partition, part_name);
}
#ifdef _STANDALONE
@@ -128,9 +129,9 @@
int biosdev;
int error;
- if ((error = parsebootfile(fname, &fsname, &devname,
- &unit, &partition, (const char **) file))
- || (error = dev2bios(devname, unit, &biosdev)))
+ error = parsebootfile(fname, &fsname, &devname,
+ &unit, &partition, (const char **) file);
+ if (error)
return error;
f->f_dev = &devsw[0]; /* must be biosdisk */
@@ -142,5 +143,26 @@
}
#endif
+#ifndef NO_GPT
+ /* Search by GPT label name */
+ if (strstr(devname, "NAME=") == devname) {
+ f->f_dev = &devsw[0]; /* must be biosdisk */
+
+ return biosdisk_open_name(f, devname);
+ }
+#endif
+#ifndef NO_RAIDFRAME
+ /* Search by raidframe name */
+ if (strstr(devname, "raid") == devname) {
+ f->f_dev = &devsw[0]; /* must be biosdisk */
+
+ return biosdisk_open_name(f, devname);
+ }
+#endif
+
+ error = dev2bios(devname, unit, &biosdev);
+ if (error)
+ return error;
+
return biosdisk_open(f, biosdev, partition);
}
diff -r cbccab534ccc -r 5d942235d9c4 sys/arch/i386/stand/boot/devopen.h
--- a/sys/arch/i386/stand/boot/devopen.h Sat Aug 17 21:14:22 2019 +0000
+++ b/sys/arch/i386/stand/boot/devopen.h Sun Aug 18 02:18:24 2019 +0000
@@ -1,5 +1,5 @@
-/* $NetBSD: devopen.h,v 1.4 2010/12/24 20:40:42 jakllsch Exp $ */
+/* $NetBSD: devopen.h,v 1.5 2019/08/18 02:18:24 manu Exp $ */
extern int boot_biosdev;
-void bios2dev(int, daddr_t, char **, int *, int *);
+void bios2dev(int, daddr_t, char **, int *, int *, const char **);
diff -r cbccab534ccc -r 5d942235d9c4 sys/arch/i386/stand/efiboot/boot.c
--- a/sys/arch/i386/stand/efiboot/boot.c Sat Aug 17 21:14:22 2019 +0000
+++ b/sys/arch/i386/stand/efiboot/boot.c Sun Aug 18 02:18:24 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: boot.c,v 1.13 2019/07/29 11:28:51 nonaka Exp $ */
+/* $NetBSD: boot.c,v 1.14 2019/08/18 02:18:24 manu Exp $ */
/*-
* Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -35,6 +35,7 @@
#include "bootcfg.h"
#include "bootmod.h"
#include "bootmenu.h"
+#include "biosdisk.h"
#include "devopen.h"
int errno;
@@ -113,6 +114,7 @@
static char *default_devname;
static int default_unit, default_partition;
static const char *default_filename;
+static const char *default_part_name;
static char *sprint_bootsel(const char *);
static void bootit(const char *, int);
@@ -122,9 +124,15 @@
int *partition, const char **file)
{
const char *col;
+ static char savedevname[MAXDEVNAME+1];
*fsname = "ufs";
- *devname = default_devname;
+ if (default_part_name == NULL) {
+ *devname = default_devname;
+ } else {
+ snprintf(savedevname, MAXDEVNAME, "NAME=%s", default_part_name);
+ *devname = savedevname;
+ }
*unit = default_unit;
*partition = default_partition;
*file = default_filename;
@@ -133,7 +141,6 @@
return 0;
if ((col = strchr(fname, ':')) != NULL) { /* device given */
- static char savedevname[MAXDEVNAME+1];
int devlen;
Home |
Main Index |
Thread Index |
Old Index