Source-Changes-HG archive

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

[src/trunk]: src/sys/stand/efiboot - Add support for a boot configuration fil...



details:   https://anonhg.NetBSD.org/src/rev/22c845e07c79
branches:  trunk
changeset: 456073:22c845e07c79
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Apr 21 22:30:41 2019 +0000

description:
- Add support for a boot configuration file, defaulting to /etc/efiboot.plist.
- Add support for pre-loading EFI environment variables from efiboot.plist.
- Add support for device tree overlays specified in efiboot.plist.

(Man page for efiboot forthcoming.)

diffstat:

 sys/stand/efiboot/Makefile.efiboot |    6 +-
 sys/stand/efiboot/boot.c           |   41 +++++++-
 sys/stand/efiboot/efiboot.c        |    8 +-
 sys/stand/efiboot/efiboot.h        |    8 +-
 sys/stand/efiboot/efienv.c         |   66 ++++++++++++-
 sys/stand/efiboot/efienv.h         |    3 +-
 sys/stand/efiboot/efifdt.c         |   50 +++++++++-
 sys/stand/efiboot/efifdt.h         |    4 +-
 sys/stand/efiboot/exec.c           |  187 ++++++++++++++++++++++++++++++++++--
 sys/stand/efiboot/version          |    3 +-
 10 files changed, 354 insertions(+), 22 deletions(-)

diffs (truncated from 660 to 300 lines):

diff -r 204c5328b518 -r 22c845e07c79 sys/stand/efiboot/Makefile.efiboot
--- a/sys/stand/efiboot/Makefile.efiboot        Sun Apr 21 21:52:09 2019 +0000
+++ b/sys/stand/efiboot/Makefile.efiboot        Sun Apr 21 22:30:41 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.6 2018/10/12 22:08:04 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.7 2019/04/21 22:30:41 thorpej Exp $
 
 S=             ${.CURDIR}/../../..
 
@@ -26,7 +26,7 @@
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=     -I${S}/external/bsd/libfdt/dist
-SOURCES+=      fdt.c fdt_addresses.c fdt_empty_tree.c
+SOURCES+=      fdt.c fdt_addresses.c fdt_empty_tree.c fdt_overlay.c
 SOURCES+=      fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c fdt_wip.c
 
 SRCS= ${SOURCES} ${EXTRA_SOURCES}
@@ -51,6 +51,7 @@
 CPPFLAGS+= -I$S -I${.CURDIR} -I${.CURDIR}/../common -I$S/lib/libsa
 CPPFLAGS+= -I${.OBJDIR}
 CPPFLAGS+= -I${.CURDIR}/../../lib
+CPPFLAGS+= -I${S}/../common/include
 
 COPTS+=        -fpic -g -O2
 COPTS+=        -fshort-wchar -fno-strict-aliasing
@@ -77,6 +78,7 @@
 CPPFLAGS+= -DSUPPORT_TFTP
 CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
 
+#CPPFLAGS+= -DEFIBOOT_DEBUG
 #CPPFLAGS+= -DARP_DEBUG
 #CPPFLAGS+= -DBOOTP_DEBUG
 #CPPFLAGS+= -DNET_DEBUG
diff -r 204c5328b518 -r 22c845e07c79 sys/stand/efiboot/boot.c
--- a/sys/stand/efiboot/boot.c  Sun Apr 21 21:52:09 2019 +0000
+++ b/sys/stand/efiboot/boot.c  Sun Apr 21 22:30:41 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.17 2019/04/20 11:28:53 jmcneill Exp $       */
+/*     $NetBSD: boot.c,v 1.18 2019/04/21 22:30:41 thorpej Exp $        */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -72,6 +72,7 @@
 static char default_device[32];
 static char initrd_path[255];
 static char dtb_path[255];
+static char efibootplist_path[255];
 static char netbsd_path[255];
 static char netbsd_args[255];
 
@@ -84,6 +85,7 @@
 void   command_boot(char *);
 void   command_dev(char *);
 void   command_dtb(char *);
+void   command_plist(char *);
 void   command_initrd(char *);
 void   command_ls(char *);
 void   command_mem(char *);
@@ -99,6 +101,7 @@
        { "boot",       command_boot,           "boot [dev:][filename] [args]\n     (ex. \"hd0a:\\netbsd.old -s\"" },
        { "dev",        command_dev,            "dev" },
        { "dtb",        command_dtb,            "dtb [dev:][filename]" },
+       { "plist",      command_plist,          "plist [dev:][filename]" },
        { "initrd",     command_initrd,         "initrd [dev:][filename]" },
        { "ls",         command_ls,             "ls [hdNn:/path]" },
        { "mem",        command_mem,            "mem" },
@@ -166,6 +169,13 @@
 }
 
 void
+command_plist(char *arg)
+{
+       if (set_efibootplist_path(arg) == 0)
+               load_efibootplist(false);
+}
+
+void
 command_initrd(char *arg)
 {
        set_initrd_path(arg);
@@ -324,6 +334,20 @@
 }
 
 int
+set_efibootplist_path(const char *arg)
+{
+       if (strlen(arg) + 1 > sizeof(efibootplist_path))
+               return ERANGE;
+       strcpy(efibootplist_path, arg);
+       return 0;
+}
+
+char *get_efibootplist_path(void)
+{
+       return efibootplist_path;
+}
+
+int
 set_bootfile(const char *arg)
 {
        if (strlen(arg) + 1 > sizeof(netbsd_path))
@@ -354,6 +378,21 @@
 {
        char *s;
 
+       s = efi_env_get("efibootplist");
+       if (s) {
+#ifdef EFIBOOT_DEBUG
+               printf(">> Setting efiboot.plist path to '%s' from environment\n", s);
+#endif
+               set_efibootplist_path(s);
+               FreePool(s);
+       }
+
+       /*
+        * Read the efiboot.plist now as it may contain additional
+        * environment variables.
+        */
+       load_efibootplist(true);
+
        s = efi_env_get("fdtfile");
        if (s) {
 #ifdef EFIBOOT_DEBUG
diff -r 204c5328b518 -r 22c845e07c79 sys/stand/efiboot/efiboot.c
--- a/sys/stand/efiboot/efiboot.c       Sun Apr 21 21:52:09 2019 +0000
+++ b/sys/stand/efiboot/efiboot.c       Sun Apr 21 22:30:41 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.15 2019/04/20 11:23:16 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.16 2019/04/21 22:30:41 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -56,6 +56,8 @@
 
 EFI_STATUS EFIAPI efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE *);
 
+prop_dictionary_t efibootplist;
+
 EFI_STATUS EFIAPI
 efi_main(EFI_HANDLE imageHandle, EFI_SYSTEM_TABLE *systemTable)
 {
@@ -180,6 +182,10 @@
        UINTN nentries, mapkey, descsize;
        UINT32 descver;
 
+       if (efibootplist) {
+               prop_object_release(efibootplist);
+       }
+
        memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
 
        status = uefi_call_wrapper(BS->ExitBootServices, 2, IH, mapkey);
diff -r 204c5328b518 -r 22c845e07c79 sys/stand/efiboot/efiboot.h
--- a/sys/stand/efiboot/efiboot.h       Sun Apr 21 21:52:09 2019 +0000
+++ b/sys/stand/efiboot/efiboot.h       Sun Apr 21 22:30:41 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: efiboot.h,v 1.9 2018/11/15 23:52:33 jmcneill Exp $     */
+/*     $NetBSD: efiboot.h,v 1.10 2019/04/21 22:30:41 thorpej Exp $     */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -35,6 +35,8 @@
 #include <loadfile.h>
 #include <net.h>
 
+#include <prop/proplib.h>
+
 #include "efiboot_machdep.h"
 
 struct boot_command {
@@ -60,6 +62,8 @@
 char *get_initrd_path(void);
 int set_dtb_path(const char *);
 char *get_dtb_path(void);
+int set_efibootplist_path(const char *);
+char *get_efibootplist_path(void);
 
 /* console.c */
 int ischar(void);
@@ -73,6 +77,7 @@
 void efi_delay(int);
 void efi_reboot(void);
 extern int howto;
+extern prop_dictionary_t efibootplist;
 
 /* efichar.c */
 size_t ucs2len(const CHAR16 *);
@@ -101,6 +106,7 @@
 
 /* exec.c */
 int exec_netbsd(const char *, const char *);
+void load_efibootplist(bool);
 
 /* panic.c */
 __dead VOID Panic(IN CHAR16 *, ...);
diff -r 204c5328b518 -r 22c845e07c79 sys/stand/efiboot/efienv.c
--- a/sys/stand/efiboot/efienv.c        Sun Apr 21 21:52:09 2019 +0000
+++ b/sys/stand/efiboot/efienv.c        Sun Apr 21 22:30:41 2019 +0000
@@ -1,6 +1,7 @@
-/* $NetBSD: efienv.c,v 1.3 2019/03/30 12:47:53 jmcneill Exp $ */
+/* $NetBSD: efienv.c,v 1.4 2019/04/21 22:30:41 thorpej Exp $ */
 
 /*-
+ * Copyright (c) 2019 Jason R. Thorpe
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
  * All rights reserved.
  *
@@ -35,6 +36,69 @@
 static EFI_GUID EfibootVendorGuid = EFIBOOT_VENDOR_GUID;
 
 void
+efi_env_from_efibootplist(void)
+{
+       /*
+        * We support pre-loading the EFI environment from efiboot.plist
+        * using the following schema:
+        *
+        *      <key>environment-variables</key>
+        *      <dict>
+        *              <key>varname1</key>
+        *              <string>value_for_varname1</string>
+        *              <key>varname2</key>
+        *              <string>value_for_varname2</string>
+        *      </dict>
+        *
+        * Only string values are supported.
+        */
+       prop_dictionary_t environment;
+       prop_dictionary_keysym_t key;
+       prop_string_t value;
+       prop_object_iterator_t iter;
+
+       const char *env_key;
+       char *env_value;
+
+       environment = prop_dictionary_get(efibootplist,
+           "environment-variables");
+       if (environment == NULL)
+               return;
+
+       iter = prop_dictionary_iterator(environment);
+       if (iter == NULL)
+               goto failed;
+
+       while ((key = prop_object_iterator_next(iter)) != NULL) {
+               value = prop_dictionary_get_keysym(environment, key);
+               if (value == NULL) {
+                       printf("boot: env: failed to get value for '%s'\n",
+                           prop_dictionary_keysym_cstring_nocopy(key));
+                       continue;
+               }
+               if (prop_object_type(value) != PROP_TYPE_STRING) {
+                       printf("boot: env: value for '%s' is not a string\n",
+                           prop_dictionary_keysym_cstring_nocopy(key));
+                       continue;
+               }
+               /* XXX __UNCONST because gnuefi */
+               env_key = prop_dictionary_keysym_cstring_nocopy(key);;
+               env_value = __UNCONST(prop_string_cstring_nocopy(value));;
+#ifdef EFIBOOT_DEBUG
+               printf(">> efiboot.plist env: '%s' = '%s'\n", env_key,
+                   env_value);
+#endif
+               efi_env_set(env_key, env_value);
+       }
+       prop_object_iterator_release(iter);
+
+       return;
+
+ failed:
+       printf("boot: failed to load environment from efiboot.plist");
+}
+
+void
 efi_env_set(const char *key, char *val)
 {
        EFI_STATUS status;
diff -r 204c5328b518 -r 22c845e07c79 sys/stand/efiboot/efienv.h
--- a/sys/stand/efiboot/efienv.h        Sun Apr 21 21:52:09 2019 +0000
+++ b/sys/stand/efiboot/efienv.h        Sun Apr 21 22:30:41 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efienv.h,v 1.1 2018/09/09 17:55:22 jmcneill Exp $ */
+/* $NetBSD: efienv.h,v 1.2 2019/04/21 22:30:41 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -26,6 +26,7 @@
  * SUCH DAMAGE.
  */
 
+void efi_env_from_efibootplist(void);
 void efi_env_set(const char *, char *);
 char *efi_env_get(const char *);
 void efi_env_clear(const char *);
diff -r 204c5328b518 -r 22c845e07c79 sys/stand/efiboot/efifdt.c
--- a/sys/stand/efiboot/efifdt.c        Sun Apr 21 21:52:09 2019 +0000
+++ b/sys/stand/efiboot/efifdt.c        Sun Apr 21 22:30:41 2019 +0000
@@ -1,6 +1,7 @@
-/* $NetBSD: efifdt.c,v 1.14 2018/11/15 23:52:33 jmcneill Exp $ */



Home | Main Index | Thread Index | Old Index