Module Name:    src
Committed By:   martin
Date:           Wed Apr  4 16:34:39 UTC 2018

Modified Files:
        src/sys/arch/i386/stand/efiboot [netbsd-8]: TODO.efiboot boot.c
            devopen.c devopen.h efidisk.c efidisk.h
        src/sys/arch/i386/stand/lib [netbsd-8]: biosdisk.c biosdisk.h
            bootmenu.c bootmenu.h
        src/sys/lib/libsa [netbsd-8]: bootcfg.c bootcfg.h

Log Message:
Pull up following revision(s) (requested by nonaka in ticket #692):

        sys/arch/i386/stand/efiboot/devopen.c: revision 1.4
        sys/arch/i386/stand/efiboot/efidisk.c: revision 1.5
        sys/arch/i386/stand/efiboot/devopen.h: revision 1.2
        sys/arch/i386/stand/efiboot/efidisk.h: revision 1.3
        sys/lib/libsa/bootcfg.h: revision 1.2
        sys/arch/i386/stand/efiboot/boot.c: revision 1.9
        sys/lib/libsa/bootcfg.c: revision 1.3
        sys/arch/i386/stand/lib/bootmenu.c: revision 1.17
        sys/arch/i386/stand/lib/biosdisk.c: revision 1.49
        sys/arch/i386/stand/efiboot/TODO.efiboot: revision 1.5
        sys/arch/i386/stand/lib/bootmenu.h: revision 1.6
        sys/arch/i386/stand/lib/biosdisk.h: revision 1.10

efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of the booted disk.


To generate a diff of this commit:
cvs rdiff -u -r1.3.10.1 -r1.3.10.2 \
    src/sys/arch/i386/stand/efiboot/TODO.efiboot
cvs rdiff -u -r1.5.2.3 -r1.5.2.4 src/sys/arch/i386/stand/efiboot/boot.c
cvs rdiff -u -r1.1.12.2 -r1.1.12.3 src/sys/arch/i386/stand/efiboot/devopen.c
cvs rdiff -u -r1.1 -r1.1.12.1 src/sys/arch/i386/stand/efiboot/devopen.h
cvs rdiff -u -r1.1.12.3 -r1.1.12.4 src/sys/arch/i386/stand/efiboot/efidisk.c
cvs rdiff -u -r1.1.12.1 -r1.1.12.2 src/sys/arch/i386/stand/efiboot/efidisk.h
cvs rdiff -u -r1.46.6.2 -r1.46.6.3 src/sys/arch/i386/stand/lib/biosdisk.c
cvs rdiff -u -r1.8.52.1 -r1.8.52.2 src/sys/arch/i386/stand/lib/biosdisk.h
cvs rdiff -u -r1.16 -r1.16.10.1 src/sys/arch/i386/stand/lib/bootmenu.c
cvs rdiff -u -r1.5 -r1.5.20.1 src/sys/arch/i386/stand/lib/bootmenu.h
cvs rdiff -u -r1.2 -r1.2.22.1 src/sys/lib/libsa/bootcfg.c
cvs rdiff -u -r1.1 -r1.1.24.1 src/sys/lib/libsa/bootcfg.h

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/i386/stand/efiboot/TODO.efiboot
diff -u src/sys/arch/i386/stand/efiboot/TODO.efiboot:1.3.10.1 src/sys/arch/i386/stand/efiboot/TODO.efiboot:1.3.10.2
--- src/sys/arch/i386/stand/efiboot/TODO.efiboot:1.3.10.1	Tue Mar 13 14:54:52 2018
+++ src/sys/arch/i386/stand/efiboot/TODO.efiboot	Wed Apr  4 16:34:39 2018
@@ -1,6 +1,5 @@
 - efiboot
  * handle UEFI variables
- * load boot.cfg from EFI system partition (FAT32)
 
 - kernel
  * handle UEFI variables (/dev/efivar)

Index: src/sys/arch/i386/stand/efiboot/boot.c
diff -u src/sys/arch/i386/stand/efiboot/boot.c:1.5.2.3 src/sys/arch/i386/stand/efiboot/boot.c:1.5.2.4
--- src/sys/arch/i386/stand/efiboot/boot.c:1.5.2.3	Mon Apr  2 08:50:33 2018
+++ src/sys/arch/i386/stand/efiboot/boot.c	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.5.2.3 2018/04/02 08:50:33 martin Exp $	*/
+/*	$NetBSD: boot.c,v 1.5.2.4 2018/04/04 16:34:39 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -55,7 +55,9 @@ static const char * const names[][2] = {
 #define NUMNAMES	__arraycount(names)
 #define DEFFILENAME	names[0][0]
 
-#define	MAXDEVNAME	16
+#ifndef	EFIBOOTCFG_FILENAME
+#define	EFIBOOTCFG_FILENAME	"esp:/EFI/NetBSD/boot.cfg"
+#endif
 
 void	command_help(char *);
 void	command_quit(char *);
@@ -273,6 +275,10 @@ boot(void)
 	default_filename = DEFFILENAME;
 
 	if (!(boot_params.bp_flags & X86_BP_FLAGS_NOBOOTCONF)) {
+#ifdef EFIBOOTCFG_FILENAME
+		int rv = parsebootconf(EFIBOOTCFG_FILENAME);
+		if (rv)
+#endif
 		parsebootconf(BOOTCFG_FILENAME);
 	} else {
 		bootcfg_info.timeout = boot_params.bp_timeout;

Index: src/sys/arch/i386/stand/efiboot/devopen.c
diff -u src/sys/arch/i386/stand/efiboot/devopen.c:1.1.12.2 src/sys/arch/i386/stand/efiboot/devopen.c:1.1.12.3
--- src/sys/arch/i386/stand/efiboot/devopen.c:1.1.12.2	Wed Mar 21 10:50:49 2018
+++ src/sys/arch/i386/stand/efiboot/devopen.c	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: devopen.c,v 1.1.12.2 2018/03/21 10:50:49 martin Exp $	 */
+/*	$NetBSD: devopen.c,v 1.1.12.3 2018/04/04 16:34:39 martin Exp $	 */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -59,6 +59,7 @@
 #include <biosdisk.h>
 #include "devopen.h"
 #include <bootinfo.h>
+#include "efidisk.h"
 
 static int
 dev2bios(char *devname, int unit, int *biosdev)
@@ -103,9 +104,20 @@ devopen(struct open_file *f, const char 
 	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;
+
+	if (strcmp(devname, "esp") == 0) {
+		bios2dev(boot_biosdev, boot_biossector, &devname, &unit,
+		    &partition);
+		if (efidisk_get_efi_system_partition(boot_biosdev, &partition))
+			return ENXIO;
+	}
+
+	error = dev2bios(devname, unit, &biosdev);
+	if (error)
 		return error;
 
 	f->f_dev = &devsw[0];		/* must be biosdisk */

Index: src/sys/arch/i386/stand/efiboot/devopen.h
diff -u src/sys/arch/i386/stand/efiboot/devopen.h:1.1 src/sys/arch/i386/stand/efiboot/devopen.h:1.1.12.1
--- src/sys/arch/i386/stand/efiboot/devopen.h:1.1	Tue Jan 24 11:09:14 2017
+++ src/sys/arch/i386/stand/efiboot/devopen.h	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: devopen.h,v 1.1 2017/01/24 11:09:14 nonaka Exp $	*/
+/*	$NetBSD: devopen.h,v 1.1.12.1 2018/04/04 16:34:39 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -27,5 +27,8 @@
  */
 
 extern int boot_biosdev;
+extern daddr_t boot_biossector;
+
+#define	MAXDEVNAME	16
 
 void bios2dev(int, daddr_t, char **, int *, int *);

Index: src/sys/arch/i386/stand/efiboot/efidisk.c
diff -u src/sys/arch/i386/stand/efiboot/efidisk.c:1.1.12.3 src/sys/arch/i386/stand/efiboot/efidisk.c:1.1.12.4
--- src/sys/arch/i386/stand/efiboot/efidisk.c:1.1.12.3	Mon Apr  2 08:50:33 2018
+++ src/sys/arch/i386/stand/efiboot/efidisk.c	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efidisk.c,v 1.1.12.3 2018/04/02 08:50:33 martin Exp $	*/
+/*	$NetBSD: efidisk.c,v 1.1.12.4 2018/04/04 16:34:39 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -213,3 +213,37 @@ get_harddrives(void)
 {
 	return nefidisks;
 }
+
+int
+efidisk_get_efi_system_partition(int dev, int *partition)
+{
+	extern const struct uuid GET_efi;
+	const struct efidiskinfo *edi;
+	struct biosdisk_partition *part;
+	int i, nparts;
+
+	edi = efidisk_getinfo(dev);
+	if (edi == NULL)
+		return ENXIO;
+
+	if (edi->type != BIOSDISK_TYPE_HD)
+		return ENOTSUP;
+
+	if (biosdisk_readpartition(edi->dev, &part, &nparts))
+		return EIO;
+
+	for (i = 0; i < nparts; i++) {
+		if (part[i].size == 0)
+			continue;
+		if (part[i].fstype == FS_UNUSED)
+			continue;
+		if (guid_is_equal(part[i].guid->guid, &GET_efi))
+			break;
+	}
+	dealloc(part, sizeof(*part) * nparts);
+	if (i == nparts)
+		return ENOENT;
+
+	*partition = i;
+	return 0;
+}

Index: src/sys/arch/i386/stand/efiboot/efidisk.h
diff -u src/sys/arch/i386/stand/efiboot/efidisk.h:1.1.12.1 src/sys/arch/i386/stand/efiboot/efidisk.h:1.1.12.2
--- src/sys/arch/i386/stand/efiboot/efidisk.h:1.1.12.1	Tue Mar 13 14:54:52 2018
+++ src/sys/arch/i386/stand/efiboot/efidisk.h	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efidisk.h,v 1.1.12.1 2018/03/13 14:54:52 martin Exp $	*/
+/*	$NetBSD: efidisk.h,v 1.1.12.2 2018/04/04 16:34:39 martin Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -40,3 +40,4 @@ struct efidiskinfo {
 TAILQ_HEAD(efidiskinfo_lh, efidiskinfo);
 
 const struct efidiskinfo *efidisk_getinfo(int);
+int efidisk_get_efi_system_partition(int, int *);

Index: src/sys/arch/i386/stand/lib/biosdisk.c
diff -u src/sys/arch/i386/stand/lib/biosdisk.c:1.46.6.2 src/sys/arch/i386/stand/lib/biosdisk.c:1.46.6.3
--- src/sys/arch/i386/stand/lib/biosdisk.c:1.46.6.2	Wed Mar 21 10:50:49 2018
+++ src/sys/arch/i386/stand/lib/biosdisk.c	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: biosdisk.c,v 1.46.6.2 2018/03/21 10:50:49 martin Exp $	*/
+/*	$NetBSD: biosdisk.c,v 1.46.6.3 2018/04/04 16:34:39 martin Exp $	*/
 
 /*
  * Copyright (c) 1996, 1998
@@ -249,14 +249,14 @@ md5(void *hash, const void *data, size_t
 #endif
 
 #ifndef NO_GPT
-static bool
+bool
 guid_is_nil(const struct uuid *u)
 {
 	static const struct uuid nil = { .time_low = 0 };
 	return (memcmp(u, &nil, sizeof(*u)) == 0 ? true : false);
 }
 
-static bool
+bool
 guid_is_equal(const struct uuid *a, const struct uuid *b)
 {
 	return (memcmp(a, b, sizeof(*a)) == 0 ? true : false);

Index: src/sys/arch/i386/stand/lib/biosdisk.h
diff -u src/sys/arch/i386/stand/lib/biosdisk.h:1.8.52.1 src/sys/arch/i386/stand/lib/biosdisk.h:1.8.52.2
--- src/sys/arch/i386/stand/lib/biosdisk.h:1.8.52.1	Tue Mar 13 14:54:52 2018
+++ src/sys/arch/i386/stand/lib/biosdisk.h	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: biosdisk.h,v 1.8.52.1 2018/03/13 14:54:52 martin Exp $	*/
+/*	$NetBSD: biosdisk.h,v 1.8.52.2 2018/04/04 16:34:39 martin Exp $	*/
 
 /*
  * Copyright (c) 1996
@@ -44,3 +44,9 @@ int biosdisk_close(struct open_file *);
 int biosdisk_ioctl(struct open_file *, u_long, void *);
 int biosdisk_findpartition(int, daddr_t);
 int biosdisk_readpartition(int, struct biosdisk_partition **, int *);
+
+#if !defined(NO_GPT)
+struct uuid;
+bool guid_is_nil(const struct uuid *);
+bool guid_is_equal(const struct uuid *, const struct uuid *);
+#endif

Index: src/sys/arch/i386/stand/lib/bootmenu.c
diff -u src/sys/arch/i386/stand/lib/bootmenu.c:1.16 src/sys/arch/i386/stand/lib/bootmenu.c:1.16.10.1
--- src/sys/arch/i386/stand/lib/bootmenu.c:1.16	Sat Jun 11 06:20:11 2016
+++ src/sys/arch/i386/stand/lib/bootmenu.c	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmenu.c,v 1.16 2016/06/11 06:20:11 dholland Exp $	*/
+/*	$NetBSD: bootmenu.c,v 1.16.10.1 2018/04/04 16:34:39 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,10 +63,10 @@ do_bootcfg_command(const char *cmd, char
 		userconf_add(arg);
 }
 
-void
+int
 parsebootconf(const char *conf)
 {
-	perform_bootcfg(conf, &do_bootcfg_command, 32768);
+	return perform_bootcfg(conf, &do_bootcfg_command, 32768);
 }
 
 /*

Index: src/sys/arch/i386/stand/lib/bootmenu.h
diff -u src/sys/arch/i386/stand/lib/bootmenu.h:1.5 src/sys/arch/i386/stand/lib/bootmenu.h:1.5.20.1
--- src/sys/arch/i386/stand/lib/bootmenu.h:1.5	Sun Aug 10 07:40:49 2014
+++ src/sys/arch/i386/stand/lib/bootmenu.h	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmenu.h,v 1.5 2014/08/10 07:40:49 isaki Exp $	*/
+/*	$NetBSD: bootmenu.h,v 1.5.20.1 2018/04/04 16:34:39 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #define COMMAND_SEPARATOR ';'
 
-void parsebootconf(const char *);
+int parsebootconf(const char *);
 void doboottypemenu(void);
 void bootdefault(void);
 

Index: src/sys/lib/libsa/bootcfg.c
diff -u src/sys/lib/libsa/bootcfg.c:1.2 src/sys/lib/libsa/bootcfg.c:1.2.22.1
--- src/sys/lib/libsa/bootcfg.c:1.2	Sun Aug 10 07:40:49 2014
+++ src/sys/lib/libsa/bootcfg.c	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootcfg.c,v 1.2 2014/08/10 07:40:49 isaki Exp $	*/
+/*	$NetBSD: bootcfg.c,v 1.2.22.1 2018/04/04 16:34:39 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -94,7 +94,7 @@ bootcfg_do_noop(const char *cmd, char *a
  * consdev=com0
  * default=1
 */
-void
+int
 perform_bootcfg(const char *conf, bootcfg_command command, const off_t maxsz)
 {
 	char *bc, *c;
@@ -114,25 +114,25 @@ perform_bootcfg(const char *conf, bootcf
 
 	fd = open(conf, 0);
 	if (fd < 0)
-		return;
+		return ENOENT;
 
 	err = fstat(fd, &st);
 	if (err == -1) {
 		close(fd);
-		return;
+		return EIO;
 	}
 
 	/* if a maximum size is being requested for the boot.cfg enforce it. */
 	if (0 < maxsz && st.st_size > maxsz) {
 		close(fd);
-		return;
+		return EFBIG;
 	}
 
 	bc = alloc(st.st_size + 1);
 	if (bc == NULL) {
 		printf("Could not allocate memory for boot configuration\n");
 		close(fd);
-		return;
+		return ENOMEM;
 	}
 
 	/*
@@ -269,4 +269,6 @@ perform_bootcfg(const char *conf, bootcf
 		bootcfg_info.def = 0;
 	if (bootcfg_info.def >= cmenu)
 		bootcfg_info.def = cmenu - 1;
+
+	return 0;
 }

Index: src/sys/lib/libsa/bootcfg.h
diff -u src/sys/lib/libsa/bootcfg.h:1.1 src/sys/lib/libsa/bootcfg.h:1.1.24.1
--- src/sys/lib/libsa/bootcfg.h:1.1	Sat Jun 28 09:16:18 2014
+++ src/sys/lib/libsa/bootcfg.h	Wed Apr  4 16:34:39 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootcfg.h,v 1.1 2014/06/28 09:16:18 rtr Exp $	*/
+/*	$NetBSD: bootcfg.h,v 1.1.24.1 2018/04/04 16:34:39 martin Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@ struct bootcfg_def {
 	int clear;				/* Clear the screen? */
 } extern bootcfg_info;
 
-void perform_bootcfg(const char *, bootcfg_command, const off_t);
+int perform_bootcfg(const char *, bootcfg_command, const off_t);
 void bootcfg_do_noop(const char *, char *);
 
 #endif /* !_BOOTCFG_H */

Reply via email to