Module Name:    src
Committed By:   thorpej
Date:           Fri Jun 26 03:23:04 UTC 2020

Modified Files:
        src/sys/stand/efiboot: Makefile.efiboot boot.c bootmenu.c efiboot.c
            efiboot.h efienv.c efienv.h exec.c version
Added Files:
        src/sys/stand/efiboot: overlay.c overlay.h

Log Message:
Add dtoverlay command to specify device tree overlays from the boot
loader command line.  Add support for specifying device tree overlays
in boot.cfg, with the syntax:

dtoverlay=/path/to/overlay.dtbo
dtoverlay=hd0e:/overlays/example.dtbo

Multiple overlays can be specified, and they are loaded in the order
they appear in boot.cfg.

Remove support for efiboot.plist.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.23 -r1.24 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.1 -r1.2 src/sys/stand/efiboot/bootmenu.c
cvs rdiff -u -r1.19 -r1.20 src/sys/stand/efiboot/efiboot.c
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.5 -r1.6 src/sys/stand/efiboot/efienv.c
cvs rdiff -u -r1.2 -r1.3 src/sys/stand/efiboot/efienv.h
cvs rdiff -u -r1.16 -r1.17 src/sys/stand/efiboot/exec.c
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/overlay.c \
    src/sys/stand/efiboot/overlay.h
cvs rdiff -u -r1.17 -r1.18 src/sys/stand/efiboot/version

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/stand/efiboot/Makefile.efiboot
diff -u src/sys/stand/efiboot/Makefile.efiboot:1.15 src/sys/stand/efiboot/Makefile.efiboot:1.16
--- src/sys/stand/efiboot/Makefile.efiboot:1.15	Sun Jun 21 23:53:26 2020
+++ src/sys/stand/efiboot/Makefile.efiboot	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.15 2020/06/21 23:53:26 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.16 2020/06/26 03:23:04 thorpej Exp $
 
 S=		${.CURDIR}/../../..
 
@@ -22,7 +22,7 @@ AFLAGS.start.S= ${${ACTIVE_CC} == "clang
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=	crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
 SOURCES+=	boot.c bootmenu.c conf.c console.c dev_net.c devopen.c exec.c \
-		module.c panic.c prompt.c
+		module.c overlay.c panic.c prompt.c
 SOURCES+=	efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c \
 		efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
 

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.23 src/sys/stand/efiboot/boot.c:1.24
--- src/sys/stand/efiboot/boot.c:1.23	Sun Jun 21 23:53:26 2020
+++ src/sys/stand/efiboot/boot.c	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.23 2020/06/21 23:53:26 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.24 2020/06/26 03:23:04 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -34,6 +34,7 @@
 #include "efienv.h"
 #include "efirng.h"
 #include "module.h"
+#include "overlay.h"
 #include "bootmenu.h"
 
 #include <sys/bootblock.h>
@@ -76,7 +77,6 @@ static const char *efi_memory_type[] = {
 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];
 static char rndseed_path[255];
@@ -90,9 +90,10 @@ int	set_bootargs(const char *);
 void	command_boot(char *);
 void	command_dev(char *);
 void	command_dtb(char *);
-void	command_plist(char *);
 void	command_initrd(char *);
 void	command_rndseed(char *);
+void	command_dtoverlay(char *);
+void	command_dtoverlays(char *);
 void	command_modules(char *);
 void	command_load(char *);
 void	command_unload(char *);
@@ -111,9 +112,10 @@ const struct boot_command commands[] = {
 	{ "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]" },
 	{ "rndseed",	command_rndseed,	"rndseed [dev:][filename]" },
+	{ "dtoverlay",	command_dtoverlay,	"dtoverlay [dev:][filename]" },
+	{ "dtoverlays",	command_dtoverlays,	"dtoverlays [{on|off|reset}]" },
 	{ "modules",	command_modules,	"modules [{on|off|reset}]" },
 	{ "load",	command_load,		"load <module_name>" },
 	{ "unload",	command_unload,		"unload <module_name>" },
@@ -185,13 +187,6 @@ command_dtb(char *arg)
 }
 
 void
-command_plist(char *arg)
-{
-	if (set_efibootplist_path(arg) == 0)
-		load_efibootplist(false);
-}
-
-void
 command_initrd(char *arg)
 {
 	set_initrd_path(arg);
@@ -204,6 +199,37 @@ command_rndseed(char *arg)
 }
 
 void
+command_dtoverlays(char *arg)
+{
+	if (arg && *arg) {
+		if (strcmp(arg, "on") == 0)
+			dtoverlay_enable(1);
+		else if (strcmp(arg, "off") == 0)
+			dtoverlay_enable(0);
+		else if (strcmp(arg, "reset") == 0)
+			dtoverlay_remove_all();
+		else {
+			command_help("");
+			return;
+		}
+	} else {
+		printf("Device Tree overlays are %sabled\n",
+		    dtoverlay_enabled ? "en" : "dis");
+	}
+}
+
+void
+command_dtoverlay(char *arg)
+{
+	if (!arg || !*arg) {
+		command_help("");
+		return;
+	}
+
+	dtoverlay_add(arg);
+}
+
+void
 command_modules(char *arg)
 {
 	if (arg && *arg) {
@@ -410,20 +436,6 @@ get_dtb_path(void)
 }
 
 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_rndseed_path(const char *arg)
 {
 	if (strlen(arg) + 1 > sizeof(rndseed_path))
@@ -469,21 +481,6 @@ read_env(void)
 {
 	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

Index: src/sys/stand/efiboot/bootmenu.c
diff -u src/sys/stand/efiboot/bootmenu.c:1.1 src/sys/stand/efiboot/bootmenu.c:1.2
--- src/sys/stand/efiboot/bootmenu.c:1.1	Sun Jun 21 23:53:26 2020
+++ src/sys/stand/efiboot/bootmenu.c	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmenu.c,v 1.1 2020/06/21 23:53:26 jmcneill Exp $	*/
+/*	$NetBSD: bootmenu.c,v 1.2 2020/06/26 03:23:04 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -40,6 +40,7 @@
 #include "bootmenu.h"
 #include "efiboot.h"
 #include "module.h"
+#include "overlay.h"
 
 static void docommandchoice(int);
 
@@ -63,6 +64,8 @@ do_bootcfg_command(const char *cmd, char
 	else if (strcmp(cmd, BOOTCFG_CMD_USERCONF) == 0)
 		userconf_add(arg);
 #endif
+	else if (strcmp(cmd, "dtoverlay") == 0)
+		dtoverlay_add(arg);
 }
 
 int

Index: src/sys/stand/efiboot/efiboot.c
diff -u src/sys/stand/efiboot/efiboot.c:1.19 src/sys/stand/efiboot/efiboot.c:1.20
--- src/sys/stand/efiboot/efiboot.c:1.19	Sun Jun 21 23:53:26 2020
+++ src/sys/stand/efiboot/efiboot.c	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efiboot.c,v 1.19 2020/06/21 23:53:26 jmcneill Exp $ */
+/* $NetBSD: efiboot.c,v 1.20 2020/06/26 03:23:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -57,8 +57,6 @@ static EFI_EVENT delay_ev = 0;
 
 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)
 {
@@ -186,10 +184,6 @@ efi_cleanup(void)
 	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);

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.11 src/sys/stand/efiboot/efiboot.h:1.12
--- src/sys/stand/efiboot/efiboot.h:1.11	Wed Dec 18 21:46:03 2019
+++ src/sys/stand/efiboot/efiboot.h	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.11 2019/12/18 21:46:03 riastradh Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.12 2020/06/26 03:23:04 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -35,8 +35,6 @@
 #include <loadfile.h>
 #include <net.h>
 
-#include <prop/proplib.h>
-
 #include "efiboot_machdep.h"
 
 struct boot_command {
@@ -62,8 +60,6 @@ int set_initrd_path(const char *);
 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);
 int set_rndseed_path(const char *);
 char *get_rndseed_path(void);
 
@@ -79,7 +75,6 @@ void efi_exit(void);
 void efi_delay(int);
 void efi_reboot(void);
 extern int howto;
-extern prop_dictionary_t efibootplist;
 
 /* efichar.c */
 size_t ucs2len(const CHAR16 *);
@@ -108,7 +103,6 @@ bool efi_pxe_match_booted_interface(cons
 
 /* exec.c */
 int exec_netbsd(const char *, const char *);
-void load_efibootplist(bool);
 
 /* panic.c */
 __dead VOID Panic(IN CHAR16 *, ...);

Index: src/sys/stand/efiboot/efienv.c
diff -u src/sys/stand/efiboot/efienv.c:1.5 src/sys/stand/efiboot/efienv.c:1.6
--- src/sys/stand/efiboot/efienv.c:1.5	Thu May 14 08:34:18 2020
+++ src/sys/stand/efiboot/efienv.c	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efienv.c,v 1.5 2020/05/14 08:34:18 msaitoh Exp $ */
+/* $NetBSD: efienv.c,v 1.6 2020/06/26 03:23:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -36,69 +36,6 @@
 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;

Index: src/sys/stand/efiboot/efienv.h
diff -u src/sys/stand/efiboot/efienv.h:1.2 src/sys/stand/efiboot/efienv.h:1.3
--- src/sys/stand/efiboot/efienv.h:1.2	Sun Apr 21 22:30:41 2019
+++ src/sys/stand/efiboot/efienv.h	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: efienv.h,v 1.2 2019/04/21 22:30:41 thorpej Exp $ */
+/* $NetBSD: efienv.h,v 1.3 2020/06/26 03:23:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -26,7 +26,6 @@
  * 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 *);

Index: src/sys/stand/efiboot/exec.c
diff -u src/sys/stand/efiboot/exec.c:1.16 src/sys/stand/efiboot/exec.c:1.17
--- src/sys/stand/efiboot/exec.c:1.16	Sun Jun 21 17:24:26 2020
+++ src/sys/stand/efiboot/exec.c	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.16 2020/06/21 17:24:26 jmcneill Exp $ */
+/* $NetBSD: exec.c,v 1.17 2020/06/26 03:23:04 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -33,6 +33,7 @@
 #include "efiacpi.h"
 #include "efirng.h"
 #include "module.h"
+#include "overlay.h"
 
 #include <sys/param.h>
 #include <sys/reboot.h>
@@ -122,92 +123,19 @@ load_file(const char *path, u_long extra
 	return 0;
 }
 
-static const char default_efibootplist_path[] = "/etc/efiboot.plist";
-
-/* This is here because load_file() is here. */
-void
-load_efibootplist(bool default_fallback)
-{
-	EFI_PHYSICAL_ADDRESS plist_addr = 0;
-	u_long plist_size = 0;
-	prop_dictionary_t plist = NULL, oplist = NULL;
-	bool load_quietly = false;
-	bool old_twiddle_toggle = twiddle_toggle;
-
-	const char *path = get_efibootplist_path();
-	if (path == NULL || strlen(path) == 0) {
-		if (!default_fallback)
-			return;
-		path = default_efibootplist_path;
-		load_quietly = true;
-	}
-
-	twiddle_toggle = load_quietly;
-
-	/*
-	 * Fudge the size so we can ensure the resulting buffer
-	 * is NUL-terminated for convenience.
-	 */
-	if (load_file(path, 1, load_quietly, &plist_addr, &plist_size) != 0 ||
-	    plist_addr == 0) {
-		/* Error messages have already been displayed. */
-		goto out;
-	}
-	char *plist_buf = (char *)((uintptr_t)plist_addr);
-	plist_buf[plist_size - 1] = '\0';
-
-	plist = prop_dictionary_internalize(plist_buf);
-	if (plist == NULL) {
-		printf("boot: unable to parse plist '%s'\n", path);
-		goto out;
-	}
-
-out:
-	oplist = efibootplist;
-
-	twiddle_toggle = old_twiddle_toggle;
-
-	/*
-	 * If we had a failure, create an empty one for
-	 * convenience.  But a failure should not clobber
-	 * an in-memory plist we already have.
-	 */
-	if (plist == NULL &&
-	    (oplist == NULL || prop_dictionary_count(oplist) == 0))
-		plist = prop_dictionary_create();
-
-#ifdef EFIBOOT_DEBUG
-	printf(">> load_efibootplist: oplist = 0x%lx, plist = 0x%lx\n",
-	    (u_long)oplist, (u_long)plist);
-#endif
-
-	if (plist_addr) {
-		uefi_call_wrapper(BS->FreePages, 2, plist_addr,
-		    EFI_SIZE_TO_PAGES(plist_size));
-	}
-
-	if (plist) {
-		efibootplist = plist;
-		efi_env_from_efibootplist();
-
-		if (oplist)
-			prop_object_release(oplist);
-	}
-}
-
 static void
-apply_overlay(void *dtbo)
+apply_overlay(const char *path, void *dtbo)
 {
 
 	if (!efi_fdt_overlay_is_compatible(dtbo)) {
-		printf("boot: incompatible overlay\n");
+		printf("boot: %s: incompatible overlay\n", path);
 		return;
 	}
 
 	int fdterr;
 
 	if (efi_fdt_overlay_apply(dtbo, &fdterr) != 0) {
-		printf("boot: error %d applying overlay\n", fdterr);
+		printf("boot: %s: error %d applying overlay\n", path, fdterr);
 	}
 }
 
@@ -226,7 +154,7 @@ apply_overlay_file(const char *path)
 		goto out;
 	}
 
-	apply_overlay((void *)(uintptr_t)dtbo_addr);
+	apply_overlay(path, (void *)(uintptr_t)dtbo_addr);
 
 out:
 	if (dtbo_addr) {
@@ -235,46 +163,13 @@ out:
 	}
 }
 
-#define	DT_OVERLAYS_PROP	"device-tree-overlays"
-
 static void
 load_fdt_overlays(void)
 {
-	/*
-	 * We support loading device tree overlays specified in efiboot.plist
-	 * using the following schema:
-	 *
-	 *	<key>device-tree-overlays</key>
-	 *	<array>
-	 *		<string>/path/to/some/overlay.dtbo</string>
-	 *		<string>hd0e:/some/other/overlay.dtbo</string>
-	 *	</array>
-	 *
-	 * The overlays are loaded in array order.
-	 */
-	prop_array_t overlays = prop_dictionary_get(efibootplist,
-	    DT_OVERLAYS_PROP);
-	if (overlays == NULL) {
-#ifdef EFIBOOT_DEBUG
-		printf("boot: no device-tree-overlays\n");
-#endif
+	if (!dtoverlay_enabled)
 		return;
-	}
-	if (prop_object_type(overlays) != PROP_TYPE_ARRAY) {
-		printf("boot: invalid %s\n", DT_OVERLAYS_PROP);
-		return;
-	}
 
-	prop_object_iterator_t iter = prop_array_iterator(overlays);
-	prop_string_t pathobj;
-	while ((pathobj = prop_object_iterator_next(iter)) != NULL) {
-		if (prop_object_type(pathobj) != PROP_TYPE_STRING) {
-			printf("boot: invalid %s entry\n", DT_OVERLAYS_PROP);
-			continue;
-		}
-		apply_overlay_file(prop_string_cstring_nocopy(pathobj));
-	}
-	prop_object_iterator_release(iter);
+	dtoverlay_foreach(apply_overlay_file);
 }
 
 static void

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.17 src/sys/stand/efiboot/version:1.18
--- src/sys/stand/efiboot/version:1.17	Sun Jun 21 23:53:26 2020
+++ src/sys/stand/efiboot/version	Fri Jun 26 03:23:04 2020
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.17 2020/06/21 23:53:26 jmcneill Exp $
+$NetBSD: version,v 1.18 2020/06/26 03:23:04 thorpej Exp $
 
 NOTE ANY CHANGES YOU MAKE TO THE EFI BOOTLOADER HERE.  The format of this
 file is important - make sure the entries are appended on end, last item
@@ -21,3 +21,4 @@ is taken as the current.
 1.14:	Add EFI RNG support.
 1.15:	Add module support.
 2.0:	Add boot.cfg support.
+2.1:	Remove efiboot.plist support; support dtoverlay in boot.cfg.

Added files:

Index: src/sys/stand/efiboot/overlay.c
diff -u /dev/null src/sys/stand/efiboot/overlay.c:1.1
--- /dev/null	Fri Jun 26 03:23:04 2020
+++ src/sys/stand/efiboot/overlay.c	Fri Jun 26 03:23:04 2020
@@ -0,0 +1,114 @@
+/* $NetBSD: overlay.c,v 1.1 2020/06/26 03:23:04 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcne...@invisible.ca> and Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "efiboot.h"
+#include "overlay.h"
+
+#include <sys/queue.h>
+
+int	dtoverlay_enabled = 1;
+
+struct dtoverlay_entry {
+	TAILQ_ENTRY(dtoverlay_entry) entries;
+	char overlay_path[];
+};
+TAILQ_HEAD(, dtoverlay_entry) dtoverlay_entries =
+    TAILQ_HEAD_INITIALIZER(dtoverlay_entries);
+
+#define	DTOVERLAY_ENTRY_SIZE(p)	(sizeof(struct dtoverlay_entry) + strlen(p) + 1)
+
+void
+dtoverlay_foreach(void (*fn)(const char *))
+{
+	struct dtoverlay_entry *d;
+
+	TAILQ_FOREACH(d, &dtoverlay_entries, entries) {
+		fn(d->overlay_path);
+	}
+}
+
+void
+dtoverlay_add(const char *overlay_path)
+{
+	struct dtoverlay_entry *d;
+
+	/* Trim leading whitespace */
+	while (*overlay_path == ' ' || *overlay_path == '\t')
+		++overlay_path;
+
+	/* Duplicate check */
+	TAILQ_FOREACH(d, &dtoverlay_entries, entries) {
+		if (strcmp(d->overlay_path, overlay_path) == 0)
+			return;
+	}
+
+	/* Add to list of overlays. */
+	d = alloc(DTOVERLAY_ENTRY_SIZE(overlay_path));
+	strcpy(d->overlay_path, overlay_path);
+	TAILQ_INSERT_TAIL(&dtoverlay_entries, d, entries);
+}
+
+#if 0
+void
+dtoverlay_remove(const char *overlay_path)
+{
+	struct dtoverlay_entry *d;
+
+	/* Trim leading whitespace */
+	while (*overlay_path == ' ' || *overlay_path == '\t')
+		++overlay_path;
+
+	TAILQ_FOREACH(d, &dtoverlay_entries, entries) {
+		if (strcmp(d->overlay_path, overlay_path) == 0) {
+			TAILQ_REMOVE(&dtoverlay_entries, d, entries);
+			dealloc(d, DTOVERLAY_ENTRY_SIZE(d->overlay_path));
+			return;
+		}
+	}
+}
+#endif
+
+void
+dtoverlay_remove_all(void)
+{
+	struct dtoverlay_entry *d;
+
+	while ((d = TAILQ_FIRST(&dtoverlay_entries)) != NULL) {
+		TAILQ_REMOVE(&dtoverlay_entries, d, entries);
+		dealloc(d, DTOVERLAY_ENTRY_SIZE(d->overlay_path));
+	}
+}
+
+void
+dtoverlay_enable(int onoff)
+{
+	dtoverlay_enabled = onoff;
+}
Index: src/sys/stand/efiboot/overlay.h
diff -u /dev/null src/sys/stand/efiboot/overlay.h:1.1
--- /dev/null	Fri Jun 26 03:23:04 2020
+++ src/sys/stand/efiboot/overlay.h	Fri Jun 26 03:23:04 2020
@@ -0,0 +1,37 @@
+/* $NetBSD: overlay.h,v 1.1 2020/06/26 03:23:04 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* overlay.c */
+extern int	dtoverlay_enabled;
+void		dtoverlay_foreach(void (*)(const char *));
+void		dtoverlay_add(const char *);
+void		dtoverlay_enable(int);
+void		dtoverlay_remove_all(void);

Reply via email to