Source-Changes-HG archive

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

[src/trunk]: src/sys efiboot: try to read boot.cfg from /EFI/NetBSD on ESP of...



details:   https://anonhg.NetBSD.org/src/rev/8da071e78487
branches:  trunk
changeset: 360836:8da071e78487
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Mon Apr 02 09:44:18 2018 +0000

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

diffstat:

 sys/arch/i386/stand/efiboot/TODO.efiboot |   1 -
 sys/arch/i386/stand/efiboot/boot.c       |  10 +++++++-
 sys/arch/i386/stand/efiboot/devopen.c    |  20 ++++++++++++++---
 sys/arch/i386/stand/efiboot/devopen.h    |   5 +++-
 sys/arch/i386/stand/efiboot/efidisk.c    |  36 +++++++++++++++++++++++++++++++-
 sys/arch/i386/stand/efiboot/efidisk.h    |   3 +-
 sys/arch/i386/stand/lib/biosdisk.c       |   6 ++--
 sys/arch/i386/stand/lib/biosdisk.h       |   8 ++++++-
 sys/arch/i386/stand/lib/bootmenu.c       |   6 ++--
 sys/arch/i386/stand/lib/bootmenu.h       |   4 +-
 sys/lib/libsa/bootcfg.c                  |  14 +++++++-----
 sys/lib/libsa/bootcfg.h                  |   4 +-
 12 files changed, 90 insertions(+), 27 deletions(-)

diffs (truncated from 319 to 300 lines):

diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/efiboot/TODO.efiboot
--- a/sys/arch/i386/stand/efiboot/TODO.efiboot  Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/efiboot/TODO.efiboot  Mon Apr 02 09:44:18 2018 +0000
@@ -1,6 +1,5 @@
 - efiboot
  * handle UEFI variables
- * load boot.cfg from EFI system partition (FAT32)
 
 - kernel
  * handle UEFI variables (/dev/efivar)
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/efiboot/boot.c
--- a/sys/arch/i386/stand/efiboot/boot.c        Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/efiboot/boot.c        Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.8 2018/03/27 14:15:05 nonaka Exp $  */
+/*     $NetBSD: boot.c,v 1.9 2018/04/02 09:44:18 nonaka Exp $  */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -55,7 +55,9 @@
 #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 @@
        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;
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/efiboot/devopen.c
--- a/sys/arch/i386/stand/efiboot/devopen.c     Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/efiboot/devopen.c     Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: devopen.c,v 1.3 2018/03/20 10:16:17 nonaka Exp $        */
+/*     $NetBSD: devopen.c,v 1.4 2018/04/02 09:44:18 nonaka 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 @@
        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 */
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/efiboot/devopen.h
--- a/sys/arch/i386/stand/efiboot/devopen.h     Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/efiboot/devopen.h     Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: devopen.h,v 1.1 2017/01/24 11:09:14 nonaka Exp $       */
+/*     $NetBSD: devopen.h,v 1.2 2018/04/02 09:44:18 nonaka Exp $       */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -27,5 +27,8 @@
  */
 
 extern int boot_biosdev;
+extern daddr_t boot_biossector;
+
+#define        MAXDEVNAME      16
 
 void bios2dev(int, daddr_t, char **, int *, int *);
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/efiboot/efidisk.c
--- a/sys/arch/i386/stand/efiboot/efidisk.c     Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/efiboot/efidisk.c     Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: efidisk.c,v 1.4 2018/03/27 14:15:05 nonaka Exp $       */
+/*     $NetBSD: efidisk.c,v 1.5 2018/04/02 09:44:18 nonaka Exp $       */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -213,3 +213,37 @@
 {
        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;
+}
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/efiboot/efidisk.h
--- a/sys/arch/i386/stand/efiboot/efidisk.h     Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/efiboot/efidisk.h     Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: efidisk.h,v 1.2 2018/03/08 10:34:33 nonaka Exp $       */
+/*     $NetBSD: efidisk.h,v 1.3 2018/04/02 09:44:18 nonaka Exp $       */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -40,3 +40,4 @@
 TAILQ_HEAD(efidiskinfo_lh, efidiskinfo);
 
 const struct efidiskinfo *efidisk_getinfo(int);
+int efidisk_get_efi_system_partition(int, int *);
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/lib/biosdisk.c
--- a/sys/arch/i386/stand/lib/biosdisk.c        Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/lib/biosdisk.c        Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biosdisk.c,v 1.48 2018/03/20 10:21:01 nonaka Exp $     */
+/*     $NetBSD: biosdisk.c,v 1.49 2018/04/02 09:44:18 nonaka Exp $     */
 
 /*
  * Copyright (c) 1996, 1998
@@ -249,14 +249,14 @@
 #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);
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/lib/biosdisk.h
--- a/sys/arch/i386/stand/lib/biosdisk.h        Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/lib/biosdisk.h        Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biosdisk.h,v 1.9 2018/03/08 10:34:33 nonaka Exp $      */
+/*     $NetBSD: biosdisk.h,v 1.10 2018/04/02 09:44:18 nonaka Exp $     */
 
 /*
  * Copyright (c) 1996
@@ -44,3 +44,9 @@
 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
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/lib/bootmenu.c
--- a/sys/arch/i386/stand/lib/bootmenu.c        Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/lib/bootmenu.c        Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootmenu.c,v 1.16 2016/06/11 06:20:11 dholland Exp $   */
+/*     $NetBSD: bootmenu.c,v 1.17 2018/04/02 09:44:18 nonaka Exp $     */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -63,10 +63,10 @@
                userconf_add(arg);
 }
 
-void
+int
 parsebootconf(const char *conf)
 {
-       perform_bootcfg(conf, &do_bootcfg_command, 32768);
+       return perform_bootcfg(conf, &do_bootcfg_command, 32768);
 }
 
 /*
diff -r ea49aad327d3 -r 8da071e78487 sys/arch/i386/stand/lib/bootmenu.h
--- a/sys/arch/i386/stand/lib/bootmenu.h        Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/arch/i386/stand/lib/bootmenu.h        Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootmenu.h,v 1.5 2014/08/10 07:40:49 isaki Exp $       */
+/*     $NetBSD: bootmenu.h,v 1.6 2018/04/02 09:44:18 nonaka 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);
 
diff -r ea49aad327d3 -r 8da071e78487 sys/lib/libsa/bootcfg.c
--- a/sys/lib/libsa/bootcfg.c   Mon Apr 02 07:31:17 2018 +0000
+++ b/sys/lib/libsa/bootcfg.c   Mon Apr 02 09:44:18 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bootcfg.c,v 1.2 2014/08/10 07:40:49 isaki Exp $        */
+/*     $NetBSD: bootcfg.c,v 1.3 2018/04/02 09:44:19 nonaka Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -94,7 +94,7 @@
  * 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 @@
 
        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 @@
                bootcfg_info.def = 0;
        if (bootcfg_info.def >= cmenu)
                bootcfg_info.def = cmenu - 1;
+
+       return 0;



Home | Main Index | Thread Index | Old Index