Module Name:    src
Committed By:   mrg
Date:           Fri Oct 26 20:56:35 UTC 2018

Modified Files:
        src/sys/stand/efiboot: boot.c efiboot.h version

Log Message:
add "boot-file" support.  now one can automatically boot a
non-default kernel with "setenv boot-file host/netbsd".

this is particularly useful with the current net / tftp
kernel boot, so the tftproot does not need a "/netbsd"
visible to all hosts, but some host-specific path.

some minor clean up.

version 1.4.

ok jmcneill@.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/stand/efiboot/boot.c
cvs rdiff -u -r1.7 -r1.8 src/sys/stand/efiboot/efiboot.h
cvs rdiff -u -r1.4 -r1.5 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/boot.c
diff -u src/sys/stand/efiboot/boot.c:1.10 src/sys/stand/efiboot/boot.c:1.11
--- src/sys/stand/efiboot/boot.c:1.10	Fri Oct 12 22:08:04 2018
+++ src/sys/stand/efiboot/boot.c	Fri Oct 26 20:56:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.10 2018/10/12 22:08:04 jmcneill Exp $	*/
+/*	$NetBSD: boot.c,v 1.11 2018/10/26 20:56:35 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -43,20 +43,23 @@ extern const char bootprog_name[], bootp
 
 extern char twiddle_toggle;
 
-static const char * const names[][2] = {
-	{ "netbsd", "netbsd.gz" },
-	{ "onetbsd", "onetbsd.gz" },
-	{ "netbsd.old", "netbsd.old.gz" },
+static const char * const names[] = {
+	"netbsd", "netbsd.gz",
+	"onetbsd", "onetbsd.gz",
+	"netbsd.old", "netbsd.old.gz",
 };
 
 #define NUMNAMES	__arraycount(names)
-#define DEFFILENAME	names[0][0]
-
-#define	DEFTIMEOUT	5
 
 static char default_device[32];
 static char initrd_path[255];
 static char dtb_path[255];
+static char bootfile[255];
+
+#define	DEFTIMEOUT	5
+#define DEFFILENAME	names[0]
+
+int	set_bootfile(const char *);
 
 void	command_boot(char *);
 void	command_dev(char *);
@@ -106,9 +109,13 @@ void
 command_boot(char *arg)
 {
 	char *fname = arg;
+	const char *kernel = *fname ? fname : bootfile;
 	char *bootargs = gettrailer(arg);
 
-	exec_netbsd(*fname ? fname : DEFFILENAME, bootargs);
+	if (!kernel || !*kernel)
+		kernel = DEFFILENAME;
+
+	exec_netbsd(kernel, bootargs);
 }
 
 void
@@ -227,7 +234,7 @@ command_reset(char *arg)
 }
 
 int
-set_default_device(char *arg)
+set_default_device(const char *arg)
 {
 	if (strlen(arg) + 1 > sizeof(default_device))
 		return ERANGE;
@@ -242,7 +249,7 @@ get_default_device(void)
 }
 
 int
-set_initrd_path(char *arg)
+set_initrd_path(const char *arg)
 {
 	if (strlen(arg) + 1 > sizeof(initrd_path))
 		return ERANGE;
@@ -257,7 +264,7 @@ get_initrd_path(void)
 }
 
 int
-set_dtb_path(char *arg)
+set_dtb_path(const char *arg)
 {
 	if (strlen(arg) + 1 > sizeof(dtb_path))
 		return ERANGE;
@@ -271,6 +278,15 @@ get_dtb_path(void)
 	return dtb_path;
 }
 
+int
+set_bootfile(const char *arg)
+{
+	if (strlen(arg) + 1 > sizeof(bootfile))
+		return ERANGE;
+	strcpy(bootfile, arg);
+	return 0;
+}
+
 void
 print_banner(void)
 {
@@ -302,6 +318,15 @@ read_env(void)
 		FreePool(s);
 	}
 
+	s = efi_env_get("bootfile");
+	if (s) {
+#ifdef EFIBOOT_DEBUG
+		printf(">> Setting bootfile path to '%s' from environment\n", s);
+#endif
+		set_bootfile(s);
+		FreePool(s);
+	}
+
 	s = efi_env_get("rootdev");
 	if (s) {
 #ifdef EFIBOOT_DEBUG
@@ -318,23 +343,24 @@ boot(void)
 	int currname, c;
 
 	read_env();
-
 	print_banner();
-
 	printf("Press return to boot now, any other key for boot prompt\n");
-	for (currname = 0; currname < NUMNAMES; currname++) {
-		printf("booting %s - starting in ", names[currname][0]);
+
+	if (bootfile[0] != '\0')
+		currname = -1;
+	else
+		currname = 0;
+
+	for (; currname < NUMNAMES; currname++) {
+		if (currname >= 0)
+			set_bootfile(names[currname]);
+		printf("booting %s - starting in ", bootfile);
 
 		c = awaitkey(DEFTIMEOUT, 1);
-		if ((c != '\r') && (c != '\n') && (c != '\0')) {
+		if (c != '\r' && c != '\n' && c != '\0')
 			bootprompt(); /* does not return */
-		}
 
-		/*
-		 * try pairs of names[] entries, foo and foo.gz
-		 */
-		exec_netbsd(names[currname][0], "");
-		exec_netbsd(names[currname][1], "");
+		exec_netbsd(bootfile, "");
 	}
 
 	bootprompt();	/* does not return */

Index: src/sys/stand/efiboot/efiboot.h
diff -u src/sys/stand/efiboot/efiboot.h:1.7 src/sys/stand/efiboot/efiboot.h:1.8
--- src/sys/stand/efiboot/efiboot.h:1.7	Sat Sep 15 17:06:32 2018
+++ src/sys/stand/efiboot/efiboot.h	Fri Oct 26 20:56:35 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.7 2018/09/15 17:06:32 jmcneill Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.8 2018/10/26 20:56:35 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -52,13 +52,12 @@ void clearit(void);
 void print_banner(void);
 extern const struct boot_command commands[];
 void command_help(char *);
-int set_default_device(char *);
+int set_default_device(const char *);
 char *get_default_device(void);
-int set_initrd_path(char *);
+int set_initrd_path(const char *);
 char *get_initrd_path(void);
-int set_dtb_path(char *);
+int set_dtb_path(const char *);
 char *get_dtb_path(void);
-extern int howto;
 
 /* console.c */
 int ischar(void);
@@ -71,6 +70,7 @@ void efi_cleanup(void);
 void efi_exit(void);
 void efi_delay(int);
 void efi_reboot(void);
+extern int howto;
 
 /* efichar.c */
 size_t ucs2len(const CHAR16 *);

Index: src/sys/stand/efiboot/version
diff -u src/sys/stand/efiboot/version:1.4 src/sys/stand/efiboot/version:1.5
--- src/sys/stand/efiboot/version:1.4	Sun Oct 21 00:57:38 2018
+++ src/sys/stand/efiboot/version	Fri Oct 26 20:56:35 2018
@@ -1,4 +1,4 @@
-$NetBSD: version,v 1.4 2018/10/21 00:57:38 jmcneill Exp $
+$NetBSD: version,v 1.5 2018/10/26 20:56:35 mrg 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
@@ -8,3 +8,4 @@ is taken as the current.
 1.1:	Add PXE booting support.
 1.2:	Add environment variable support.
 1.3:	Add ACPI support.
+1.4:	Add bootfile support.

Reply via email to