Module Name:    src
Committed By:   jmcneill
Date:           Fri Mar 25 21:23:00 UTC 2022

Modified Files:
        src/sys/stand/efiboot: Makefile.efiboot boot.c bootmenu.c efiboot.h
            efifdt.c efifdt.h version
Added Files:
        src/sys/stand/efiboot: userconf.c

Log Message:
efiboot: Add support for 'userconf' command.

Add support for the 'userconf' command at the boot prompt and in boot.cfg,
and for FDT based booting, pass the commands as a string list property
named "netbsd,userconf" on the /chosen node.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/stand/efiboot/Makefile.efiboot
cvs rdiff -u -r1.42 -r1.43 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.3 -r1.4 src/sys/stand/efiboot/bootmenu.c
cvs rdiff -u -r1.18 -r1.19 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.33 -r1.34 src/sys/stand/efiboot/efifdt.c
cvs rdiff -u -r1.11 -r1.12 src/sys/stand/efiboot/efifdt.h
cvs rdiff -u -r0 -r1.1 src/sys/stand/efiboot/userconf.c
cvs rdiff -u -r1.29 -r1.30 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.25 src/sys/stand/efiboot/Makefile.efiboot:1.26
--- src/sys/stand/efiboot/Makefile.efiboot:1.25	Sun Oct 17 14:12:54 2021
+++ src/sys/stand/efiboot/Makefile.efiboot	Fri Mar 25 21:23:00 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.25 2021/10/17 14:12:54 jmcneill Exp $
+# $NetBSD: Makefile.efiboot,v 1.26 2022/03/25 21:23:00 jmcneill 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 panic.c prompt.c userconf.c
 SOURCES+=	efiboot.c efichar.c efidev.c efigetsecs.c \
 		efifile.c efiblock.c efinet.c efipxe.c efirng.c \
 		efiwatchdog.c efigop.c smbios.c

Index: src/sys/stand/efiboot/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.42 src/sys/stand/efiboot/boot.c:1.43
--- src/sys/stand/efiboot/boot.c:1.42	Thu Nov  4 07:28:34 2021
+++ src/sys/stand/efiboot/boot.c	Fri Mar 25 21:23:00 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.42 2021/11/04 07:28:34 skrll Exp $	*/
+/*	$NetBSD: boot.c,v 1.43 2022/03/25 21:23:00 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <[email protected]>
@@ -114,6 +114,7 @@ void	command_mem(char *);
 void	command_menu(char *);
 void	command_reset(char *);
 void	command_setup(char *);
+void	command_userconf(char *);
 void	command_version(char *);
 void	command_quit(char *);
 
@@ -141,6 +142,7 @@ const struct boot_command commands[] = {
 	{ "reboot",	command_reset,		"reboot|reset" },
 	{ "reset",	command_reset,		NULL },
 	{ "setup",	command_setup,		"setup" },
+	{ "userconf",	command_userconf,	"userconf <command>" },
 	{ "version",	command_version,	"version" },
 	{ "ver",	command_version,	NULL },
 	{ "help",	command_help,		"help|?" },
@@ -450,6 +452,12 @@ command_setup(char *arg)
 	efi_reboot();
 }
 
+void
+command_userconf(char *arg)
+{
+	userconf_add(arg);
+}
+
 int
 set_default_device(const char *arg)
 {

Index: src/sys/stand/efiboot/bootmenu.c
diff -u src/sys/stand/efiboot/bootmenu.c:1.3 src/sys/stand/efiboot/bootmenu.c:1.4
--- src/sys/stand/efiboot/bootmenu.c:1.3	Wed Oct  6 10:13:19 2021
+++ src/sys/stand/efiboot/bootmenu.c	Fri Mar 25 21:23:00 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bootmenu.c,v 1.3 2021/10/06 10:13:19 jmcneill Exp $	*/
+/*	$NetBSD: bootmenu.c,v 1.4 2022/03/25 21:23:00 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -60,10 +60,8 @@ do_bootcfg_command(const char *cmd, char
 {
 	if (strcmp(cmd, BOOTCFG_CMD_LOAD) == 0)
 		module_add(arg);
-#if notyet
 	else if (strcmp(cmd, BOOTCFG_CMD_USERCONF) == 0)
 		userconf_add(arg);
-#endif
 #ifdef EFIBOOT_FDT
 	else if (strcmp(cmd, "dtoverlay") == 0)
 		dtoverlay_add(arg);

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.18 src/sys/stand/efiboot/efiboot.h:1.19
--- src/sys/stand/efiboot/efiboot.h:1.18	Wed Oct  6 10:13:19 2021
+++ src/sys/stand/efiboot/efiboot.h	Fri Mar 25 21:23:00 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.18 2021/10/06 10:13:19 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.19 2022/03/25 21:23:00 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <[email protected]>
@@ -131,3 +131,7 @@ char *gettrailer(char *);
 void docommand(char *);
 char awaitkey(int, int);
 __dead void bootprompt(void);
+
+/* userconf.c */
+void userconf_add(const char *);
+void userconf_foreach(void (*)(const char *));

Index: src/sys/stand/efiboot/efifdt.c
diff -u src/sys/stand/efiboot/efifdt.c:1.33 src/sys/stand/efiboot/efifdt.c:1.34
--- src/sys/stand/efiboot/efifdt.c:1.33	Sat Nov  6 19:44:22 2021
+++ src/sys/stand/efiboot/efifdt.c	Fri Mar 25 21:23:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.33 2021/11/06 19:44:22 jmcneill Exp $ */
+/* $NetBSD: efifdt.c,v 1.34 2022/03/25 21:23:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -442,6 +442,20 @@ efi_fdt_bootargs(const char *bootargs)
 	}
 }
 
+static void
+efi_fdt_userconf_addprop(const char *cmd)
+{
+	const int chosen = efi_fdt_chosen();
+
+	fdt_appendprop_string(fdt_data, chosen, "netbsd,userconf", cmd);
+}
+
+void
+efi_fdt_userconf(void)
+{
+	userconf_foreach(efi_fdt_userconf_addprop);
+}
+
 void
 efi_fdt_initrd(u_long initrd_addr, u_long initrd_size)
 {
@@ -615,6 +629,7 @@ arch_prepare_boot(const char *fname, con
 		efi_fdt_rndseed(rndseed_addr, rndseed_size);
 		efi_fdt_efirng(efirng_addr, efirng_size);
 		efi_fdt_bootargs(args);
+		efi_fdt_userconf();
 		efi_fdt_system_table();
 		efi_fdt_gop();
 		efi_fdt_memory_map();

Index: src/sys/stand/efiboot/efifdt.h
diff -u src/sys/stand/efiboot/efifdt.h:1.11 src/sys/stand/efiboot/efifdt.h:1.12
--- src/sys/stand/efiboot/efifdt.h:1.11	Wed Oct  6 10:13:19 2021
+++ src/sys/stand/efiboot/efifdt.h	Fri Mar 25 21:23:00 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.h,v 1.11 2021/10/06 10:13:19 jmcneill Exp $ */
+/* $NetBSD: efifdt.h,v 1.12 2022/03/25 21:23:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <[email protected]>
@@ -44,6 +44,7 @@ void efi_fdt_initrd(u_long, u_long);
 void efi_fdt_rndseed(u_long, u_long);
 void efi_fdt_efirng(u_long, u_long);
 void efi_fdt_module(const char *, u_long, u_long);
+void efi_fdt_userconf(void);
 void efi_fdt_init(u_long, u_long);
 void efi_fdt_fini(void);
 void efi_fdt_system_table(void);

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.29 src/sys/stand/efiboot/version:1.30
--- src/sys/stand/efiboot/version:1.29	Tue Sep 28 11:37:45 2021
+++ src/sys/stand/efiboot/version	Fri Mar 25 21:23:00 2022
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.29 2021/09/28 11:37:45 jmcneill Exp $
+$NetBSD: version,v 1.30 2022/03/25 21:23:00 jmcneill 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
@@ -32,3 +32,4 @@ is taken as the current.
 2.9:	Watchdog support.
 2.10:	Use disk I/O protocol for block devices.
 2.11:	Add support for changing the video mode.
+2.12:	Add userconf support.

Added files:

Index: src/sys/stand/efiboot/userconf.c
diff -u /dev/null src/sys/stand/efiboot/userconf.c:1.1
--- /dev/null	Fri Mar 25 21:23:00 2022
+++ src/sys/stand/efiboot/userconf.c	Fri Mar 25 21:23:00 2022
@@ -0,0 +1,81 @@
+/* $NetBSD: userconf.c,v 1.1 2022/03/25 21:23:00 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2022 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <[email protected]>.
+ *
+ * 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 <sys/queue.h>
+
+struct userconf_command {
+	const char *uc_text;
+	TAILQ_ENTRY(userconf_command) entries;
+};
+TAILQ_HEAD(, userconf_command) userconf_commands =
+    TAILQ_HEAD_INITIALIZER(userconf_commands);
+
+void
+userconf_foreach(void (*fn)(const char *))
+{
+	struct userconf_command *uc;
+
+	TAILQ_FOREACH(uc, &userconf_commands, entries) {
+		fn(uc->uc_text);
+	}
+}
+
+void
+userconf_add(const char *cmd)
+{
+	struct userconf_command *uc;
+	size_t len;
+	char *text;
+
+	while (*cmd == ' ' || *cmd == '\t') {
+		++cmd;
+	}
+	if (*cmd == '\0') {
+		return;
+	}
+
+	uc = alloc(sizeof(*uc));
+	if (uc == NULL) {
+		panic("couldn't allocate userconf command");
+	}
+
+	len = strlen(cmd) + 1;
+	text = alloc(len);
+	if (text == NULL) {
+		panic("couldn't allocate userconf command buffer");
+	}
+	memcpy(text, cmd, len);
+
+	uc->uc_text = text;
+	TAILQ_INSERT_TAIL(&userconf_commands, uc, entries);
+}

Reply via email to