Index: boot.c =================================================================== RCS file: /cvsroot/src/sys/stand/efiboot/boot.c,v retrieving revision 1.9 diff -p -u -r1.9 boot.c --- boot.c 9 Sep 2018 18:00:20 -0000 1.9 +++ boot.c 15 Sep 2018 03:36:19 -0000 @@ -49,13 +49,14 @@ static const char * const names[][2] = { }; #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][0] void command_boot(char *); void command_dev(char *); @@ -105,9 +106,13 @@ void command_boot(char *arg) { char *fname = arg; + const char *kernel = *fname ? fname : get_bootfile(); char *bootargs = gettrailer(arg); - exec_netbsd(*fname ? fname : DEFFILENAME, bootargs); + if (!kernel || !*kernel) + kernel = DEFFILENAME; + + exec_netbsd(kernel, bootargs); } void @@ -225,7 +230,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; @@ -240,7 +245,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; @@ -255,7 +260,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; @@ -269,6 +274,21 @@ 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; +} + +char * +get_bootfile(void) +{ + return bootfile; +} + void print_banner(void) { @@ -300,6 +320,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 @@ -314,25 +343,39 @@ void boot(void) { int currname, c; + char *kernel; 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]); + + kernel = get_bootfile(); + if (kernel && *kernel) + currname = -1; + else + currname = 0; + for (; currname == -1 || currname < NUMNAMES; currname++) { + if (currname >= 0) + printf("booting %s - starting in ", names[currname][0]); + else + printf("booting %s - starting in ", get_bootfile()); c = awaitkey(DEFTIMEOUT, 1); 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], ""); + if (currname >= 0) { + /* + * try pairs of names[] entries, foo and foo.gz + */ + exec_netbsd(names[currname][0], ""); + exec_netbsd(names[currname][1], ""); + } else { + exec_netbsd(get_bootfile(), ""); + } } bootprompt(); /* does not return */ Index: efiboot.h =================================================================== RCS file: /cvsroot/src/sys/stand/efiboot/efiboot.h,v retrieving revision 1.6 diff -p -u -r1.6 efiboot.h --- efiboot.h 9 Sep 2018 18:00:20 -0000 1.6 +++ efiboot.h 15 Sep 2018 03:36:19 -0000 @@ -50,12 +50,14 @@ 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); +int set_bootfile(const char *); +char *get_bootfile(void); /* console.c */ int ischar(void); Index: version =================================================================== RCS file: /cvsroot/src/sys/stand/efiboot/version,v retrieving revision 1.3 diff -p -u -r1.3 version --- version 9 Sep 2018 17:55:22 -0000 1.3 +++ version 15 Sep 2018 03:36:19 -0000 @@ -7,3 +7,4 @@ is taken as the current. 1.0: Initial version. 1.1: Add PXE booting support. 1.2: Add environment variable support. +1.3: Add bootfile support.