Home | History | Annotate | Line # | Download | only in efiboot
boot.c revision 1.18.2.2
      1  1.18.2.2  christos /*	$NetBSD: boot.c,v 1.18.2.2 2019/06/10 22:09:56 christos Exp $	*/
      2  1.18.2.2  christos 
      3  1.18.2.2  christos /*-
      4  1.18.2.2  christos  * Copyright (c) 2016 Kimihiro Nonaka <nonaka (at) netbsd.org>
      5  1.18.2.2  christos  * Copyright (c) 2018 Jared McNeill <jmcneill (at) invisible.ca>
      6  1.18.2.2  christos  * All rights reserved.
      7  1.18.2.2  christos  *
      8  1.18.2.2  christos  * Redistribution and use in source and binary forms, with or without
      9  1.18.2.2  christos  * modification, are permitted provided that the following conditions
     10  1.18.2.2  christos  * are met:
     11  1.18.2.2  christos  * 1. Redistributions of source code must retain the above copyright
     12  1.18.2.2  christos  *    notice, this list of conditions and the following disclaimer.
     13  1.18.2.2  christos  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.18.2.2  christos  *    notice, this list of conditions and the following disclaimer in the
     15  1.18.2.2  christos  *    documentation and/or other materials provided with the distribution.
     16  1.18.2.2  christos  *
     17  1.18.2.2  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     18  1.18.2.2  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  1.18.2.2  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  1.18.2.2  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     21  1.18.2.2  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  1.18.2.2  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  1.18.2.2  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  1.18.2.2  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  1.18.2.2  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  1.18.2.2  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  1.18.2.2  christos  * SUCH DAMAGE.
     28  1.18.2.2  christos  */
     29  1.18.2.2  christos 
     30  1.18.2.2  christos #include "efiboot.h"
     31  1.18.2.2  christos #include "efiblock.h"
     32  1.18.2.2  christos #include "efifdt.h"
     33  1.18.2.2  christos #include "efiacpi.h"
     34  1.18.2.2  christos #include "efienv.h"
     35  1.18.2.2  christos 
     36  1.18.2.2  christos #include <sys/bootblock.h>
     37  1.18.2.2  christos #include <sys/boot_flag.h>
     38  1.18.2.2  christos #include <machine/limits.h>
     39  1.18.2.2  christos 
     40  1.18.2.2  christos #include <loadfile.h>
     41  1.18.2.2  christos 
     42  1.18.2.2  christos extern const char bootprog_name[], bootprog_rev[], bootprog_kernrev[];
     43  1.18.2.2  christos 
     44  1.18.2.2  christos extern char twiddle_toggle;
     45  1.18.2.2  christos 
     46  1.18.2.2  christos static const char * const names[] = {
     47  1.18.2.2  christos 	"netbsd", "netbsd.gz",
     48  1.18.2.2  christos 	"onetbsd", "onetbsd.gz",
     49  1.18.2.2  christos 	"netbsd.old", "netbsd.old.gz",
     50  1.18.2.2  christos };
     51  1.18.2.2  christos 
     52  1.18.2.2  christos #define NUMNAMES	__arraycount(names)
     53  1.18.2.2  christos 
     54  1.18.2.2  christos static const char *efi_memory_type[] = {
     55  1.18.2.2  christos         [EfiReservedMemoryType]         = "Reserved Memory Type",
     56  1.18.2.2  christos         [EfiLoaderCode]                 = "Loader Code",
     57  1.18.2.2  christos         [EfiLoaderData]                 = "Loader Data",
     58  1.18.2.2  christos         [EfiBootServicesCode]           = "Boot Services Code",
     59  1.18.2.2  christos         [EfiBootServicesData]           = "Boot Services Data",
     60  1.18.2.2  christos         [EfiRuntimeServicesCode]        = "Runtime Services Code",
     61  1.18.2.2  christos         [EfiRuntimeServicesData]        = "Runtime Services Data",
     62  1.18.2.2  christos         [EfiConventionalMemory]         = "Conventional Memory",
     63  1.18.2.2  christos         [EfiUnusableMemory]             = "Unusable Memory",
     64  1.18.2.2  christos         [EfiACPIReclaimMemory]          = "ACPI Reclaim Memory",
     65  1.18.2.2  christos         [EfiACPIMemoryNVS]              = "ACPI Memory NVS",
     66  1.18.2.2  christos         [EfiMemoryMappedIO]             = "MMIO",
     67  1.18.2.2  christos         [EfiMemoryMappedIOPortSpace]    = "MMIO (Port Space)",
     68  1.18.2.2  christos         [EfiPalCode]                    = "Pal Code",
     69  1.18.2.2  christos         [EfiPersistentMemory]           = "Persistent Memory",
     70  1.18.2.2  christos };
     71  1.18.2.2  christos 
     72  1.18.2.2  christos static char default_device[32];
     73  1.18.2.2  christos static char initrd_path[255];
     74  1.18.2.2  christos static char dtb_path[255];
     75  1.18.2.2  christos static char efibootplist_path[255];
     76  1.18.2.2  christos static char netbsd_path[255];
     77  1.18.2.2  christos static char netbsd_args[255];
     78  1.18.2.2  christos 
     79  1.18.2.2  christos #define	DEFTIMEOUT	5
     80  1.18.2.2  christos #define DEFFILENAME	names[0]
     81  1.18.2.2  christos 
     82  1.18.2.2  christos int	set_bootfile(const char *);
     83  1.18.2.2  christos int	set_bootargs(const char *);
     84  1.18.2.2  christos 
     85  1.18.2.2  christos void	command_boot(char *);
     86  1.18.2.2  christos void	command_dev(char *);
     87  1.18.2.2  christos void	command_dtb(char *);
     88  1.18.2.2  christos void	command_plist(char *);
     89  1.18.2.2  christos void	command_initrd(char *);
     90  1.18.2.2  christos void	command_ls(char *);
     91  1.18.2.2  christos void	command_mem(char *);
     92  1.18.2.2  christos void	command_printenv(char *);
     93  1.18.2.2  christos void	command_setenv(char *);
     94  1.18.2.2  christos void	command_clearenv(char *);
     95  1.18.2.2  christos void	command_resetenv(char *);
     96  1.18.2.2  christos void	command_reset(char *);
     97  1.18.2.2  christos void	command_version(char *);
     98  1.18.2.2  christos void	command_quit(char *);
     99  1.18.2.2  christos 
    100  1.18.2.2  christos const struct boot_command commands[] = {
    101  1.18.2.2  christos 	{ "boot",	command_boot,		"boot [dev:][filename] [args]\n     (ex. \"hd0a:\\netbsd.old -s\"" },
    102  1.18.2.2  christos 	{ "dev",	command_dev,		"dev" },
    103  1.18.2.2  christos 	{ "dtb",	command_dtb,		"dtb [dev:][filename]" },
    104  1.18.2.2  christos 	{ "plist",	command_plist,		"plist [dev:][filename]" },
    105  1.18.2.2  christos 	{ "initrd",	command_initrd,		"initrd [dev:][filename]" },
    106  1.18.2.2  christos 	{ "ls",		command_ls,		"ls [hdNn:/path]" },
    107  1.18.2.2  christos 	{ "mem",	command_mem,		"mem" },
    108  1.18.2.2  christos 	{ "printenv",	command_printenv,	"printenv [key]" },
    109  1.18.2.2  christos 	{ "setenv",	command_setenv,		"setenv <key> <value>" },
    110  1.18.2.2  christos 	{ "clearenv",	command_clearenv,	"clearenv <key>" },
    111  1.18.2.2  christos 	{ "resetenv",	command_resetenv,	"resetenv" },
    112  1.18.2.2  christos 	{ "reboot",	command_reset,		"reboot|reset" },
    113  1.18.2.2  christos 	{ "reset",	command_reset,		NULL },
    114  1.18.2.2  christos 	{ "version",	command_version,	"version" },
    115  1.18.2.2  christos 	{ "help",	command_help,		"help|?" },
    116  1.18.2.2  christos 	{ "?",		command_help,		NULL },
    117  1.18.2.2  christos 	{ "quit",	command_quit,		"quit" },
    118  1.18.2.2  christos 	{ NULL,		NULL },
    119  1.18.2.2  christos };
    120  1.18.2.2  christos 
    121  1.18.2.2  christos void
    122  1.18.2.2  christos command_help(char *arg)
    123  1.18.2.2  christos {
    124  1.18.2.2  christos 	int n;
    125  1.18.2.2  christos 
    126  1.18.2.2  christos 	printf("commands are:\n");
    127  1.18.2.2  christos 	for (n = 0; commands[n].c_name; n++) {
    128  1.18.2.2  christos 		if (commands[n].c_help)
    129  1.18.2.2  christos 			printf("%s\n", commands[n].c_help);
    130  1.18.2.2  christos 	}
    131  1.18.2.2  christos }
    132  1.18.2.2  christos 
    133  1.18.2.2  christos void
    134  1.18.2.2  christos command_boot(char *arg)
    135  1.18.2.2  christos {
    136  1.18.2.2  christos 	char *fname = arg;
    137  1.18.2.2  christos 	const char *kernel = *fname ? fname : bootfile;
    138  1.18.2.2  christos 	char *bootargs = gettrailer(arg);
    139  1.18.2.2  christos 
    140  1.18.2.2  christos 	if (!kernel || !*kernel)
    141  1.18.2.2  christos 		kernel = DEFFILENAME;
    142  1.18.2.2  christos 
    143  1.18.2.2  christos 	if (!*bootargs)
    144  1.18.2.2  christos 		bootargs = netbsd_args;
    145  1.18.2.2  christos 
    146  1.18.2.2  christos 	exec_netbsd(kernel, bootargs);
    147  1.18.2.2  christos }
    148  1.18.2.2  christos 
    149  1.18.2.2  christos void
    150  1.18.2.2  christos command_dev(char *arg)
    151  1.18.2.2  christos {
    152  1.18.2.2  christos 	if (arg && *arg) {
    153  1.18.2.2  christos 		set_default_device(arg);
    154  1.18.2.2  christos 	} else {
    155  1.18.2.2  christos 		efi_block_show();
    156  1.18.2.2  christos 		efi_net_show();
    157  1.18.2.2  christos 	}
    158  1.18.2.2  christos 
    159  1.18.2.2  christos 	if (strlen(default_device) > 0) {
    160  1.18.2.2  christos 		printf("\n");
    161  1.18.2.2  christos 		printf("default: %s\n", default_device);
    162  1.18.2.2  christos 	}
    163  1.18.2.2  christos }
    164  1.18.2.2  christos 
    165  1.18.2.2  christos void
    166  1.18.2.2  christos command_dtb(char *arg)
    167  1.18.2.2  christos {
    168  1.18.2.2  christos 	set_dtb_path(arg);
    169  1.18.2.2  christos }
    170  1.18.2.2  christos 
    171  1.18.2.2  christos void
    172  1.18.2.2  christos command_plist(char *arg)
    173  1.18.2.2  christos {
    174  1.18.2.2  christos 	if (set_efibootplist_path(arg) == 0)
    175  1.18.2.2  christos 		load_efibootplist(false);
    176  1.18.2.2  christos }
    177  1.18.2.2  christos 
    178  1.18.2.2  christos void
    179  1.18.2.2  christos command_initrd(char *arg)
    180  1.18.2.2  christos {
    181  1.18.2.2  christos 	set_initrd_path(arg);
    182  1.18.2.2  christos }
    183  1.18.2.2  christos 
    184  1.18.2.2  christos void
    185  1.18.2.2  christos command_ls(char *arg)
    186  1.18.2.2  christos {
    187  1.18.2.2  christos 	ls(arg);
    188  1.18.2.2  christos }
    189  1.18.2.2  christos 
    190  1.18.2.2  christos void
    191  1.18.2.2  christos command_mem(char *arg)
    192  1.18.2.2  christos {
    193  1.18.2.2  christos 	EFI_MEMORY_DESCRIPTOR *md, *memmap;
    194  1.18.2.2  christos 	UINTN nentries, mapkey, descsize;
    195  1.18.2.2  christos 	UINT32 descver;
    196  1.18.2.2  christos 	int n;
    197  1.18.2.2  christos 
    198  1.18.2.2  christos 	printf("Type                    Start             End               Attributes\n");
    199  1.18.2.2  christos 	printf("----------------------  ----------------  ----------------  ----------------\n");
    200  1.18.2.2  christos 	memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
    201  1.18.2.2  christos 	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
    202  1.18.2.2  christos 		const char *mem_type = "<unknown>";
    203  1.18.2.2  christos 		if (md->Type < __arraycount(efi_memory_type))
    204  1.18.2.2  christos 			mem_type = efi_memory_type[md->Type];
    205  1.18.2.2  christos 
    206  1.18.2.2  christos 		printf("%-22s  %016" PRIx64 "  %016" PRIx64 "  %016" PRIx64 "\n",
    207  1.18.2.2  christos 		    mem_type, md->PhysicalStart, md->PhysicalStart + (md->NumberOfPages * EFI_PAGE_SIZE) - 1,
    208  1.18.2.2  christos 		    md->Attribute);
    209  1.18.2.2  christos 	}
    210  1.18.2.2  christos }
    211  1.18.2.2  christos 
    212  1.18.2.2  christos void
    213  1.18.2.2  christos command_printenv(char *arg)
    214  1.18.2.2  christos {
    215  1.18.2.2  christos 	char *val;
    216  1.18.2.2  christos 
    217  1.18.2.2  christos 	if (arg && *arg) {
    218  1.18.2.2  christos 		val = efi_env_get(arg);
    219  1.18.2.2  christos 		if (val) {
    220  1.18.2.2  christos 			printf("\"%s\" = \"%s\"\n", arg, val);
    221  1.18.2.2  christos 			FreePool(val);
    222  1.18.2.2  christos 		}
    223  1.18.2.2  christos 	} else {
    224  1.18.2.2  christos 		efi_env_print();
    225  1.18.2.2  christos 	}
    226  1.18.2.2  christos }
    227  1.18.2.2  christos 
    228  1.18.2.2  christos void
    229  1.18.2.2  christos command_setenv(char *arg)
    230  1.18.2.2  christos {
    231  1.18.2.2  christos 	char *spc;
    232  1.18.2.2  christos 
    233  1.18.2.2  christos 	spc = strchr(arg, ' ');
    234  1.18.2.2  christos 	if (spc == NULL || spc[1] == '\0') {
    235  1.18.2.2  christos 		command_help("");
    236  1.18.2.2  christos 		return;
    237  1.18.2.2  christos 	}
    238  1.18.2.2  christos 
    239  1.18.2.2  christos 	*spc = '\0';
    240  1.18.2.2  christos 	efi_env_set(arg, spc + 1);
    241  1.18.2.2  christos }
    242  1.18.2.2  christos 
    243  1.18.2.2  christos void
    244  1.18.2.2  christos command_clearenv(char *arg)
    245  1.18.2.2  christos {
    246  1.18.2.2  christos 	if (*arg == '\0') {
    247  1.18.2.2  christos 		command_help("");
    248  1.18.2.2  christos 		return;
    249  1.18.2.2  christos 	}
    250  1.18.2.2  christos 	efi_env_clear(arg);
    251  1.18.2.2  christos }
    252  1.18.2.2  christos 
    253  1.18.2.2  christos void
    254  1.18.2.2  christos command_resetenv(char *arg)
    255  1.18.2.2  christos {
    256  1.18.2.2  christos 	efi_env_reset();
    257  1.18.2.2  christos }
    258  1.18.2.2  christos 
    259  1.18.2.2  christos void
    260  1.18.2.2  christos command_version(char *arg)
    261  1.18.2.2  christos {
    262  1.18.2.2  christos 	char *ufirmware;
    263  1.18.2.2  christos 	int rv;
    264  1.18.2.2  christos 
    265  1.18.2.2  christos 	printf("EFI version: %d.%02d\n",
    266  1.18.2.2  christos 	    ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
    267  1.18.2.2  christos 	ufirmware = NULL;
    268  1.18.2.2  christos 	rv = ucs2_to_utf8(ST->FirmwareVendor, &ufirmware);
    269  1.18.2.2  christos 	if (rv == 0) {
    270  1.18.2.2  christos 		printf("EFI Firmware: %s (rev 0x%x)\n", ufirmware,
    271  1.18.2.2  christos 		    ST->FirmwareRevision);
    272  1.18.2.2  christos 		FreePool(ufirmware);
    273  1.18.2.2  christos 	}
    274  1.18.2.2  christos 
    275  1.18.2.2  christos 	efi_fdt_show();
    276  1.18.2.2  christos 	efi_acpi_show();
    277  1.18.2.2  christos }
    278  1.18.2.2  christos 
    279  1.18.2.2  christos void
    280  1.18.2.2  christos command_quit(char *arg)
    281  1.18.2.2  christos {
    282  1.18.2.2  christos 	efi_exit();
    283  1.18.2.2  christos }
    284  1.18.2.2  christos 
    285  1.18.2.2  christos void
    286  1.18.2.2  christos command_reset(char *arg)
    287  1.18.2.2  christos {
    288  1.18.2.2  christos 	efi_reboot();
    289  1.18.2.2  christos }
    290  1.18.2.2  christos 
    291  1.18.2.2  christos int
    292  1.18.2.2  christos set_default_device(const char *arg)
    293  1.18.2.2  christos {
    294  1.18.2.2  christos 	if (strlen(arg) + 1 > sizeof(default_device))
    295  1.18.2.2  christos 		return ERANGE;
    296  1.18.2.2  christos 	strcpy(default_device, arg);
    297  1.18.2.2  christos 	return 0;
    298  1.18.2.2  christos }
    299  1.18.2.2  christos 
    300  1.18.2.2  christos char *
    301  1.18.2.2  christos get_default_device(void)
    302  1.18.2.2  christos {
    303  1.18.2.2  christos 	return default_device;
    304  1.18.2.2  christos }
    305  1.18.2.2  christos 
    306  1.18.2.2  christos int
    307  1.18.2.2  christos set_initrd_path(const char *arg)
    308  1.18.2.2  christos {
    309  1.18.2.2  christos 	if (strlen(arg) + 1 > sizeof(initrd_path))
    310  1.18.2.2  christos 		return ERANGE;
    311  1.18.2.2  christos 	strcpy(initrd_path, arg);
    312  1.18.2.2  christos 	return 0;
    313  1.18.2.2  christos }
    314  1.18.2.2  christos 
    315  1.18.2.2  christos char *
    316  1.18.2.2  christos get_initrd_path(void)
    317  1.18.2.2  christos {
    318  1.18.2.2  christos 	return initrd_path;
    319  1.18.2.2  christos }
    320  1.18.2.2  christos 
    321  1.18.2.2  christos int
    322  1.18.2.2  christos set_dtb_path(const char *arg)
    323  1.18.2.2  christos {
    324  1.18.2.2  christos 	if (strlen(arg) + 1 > sizeof(dtb_path))
    325  1.18.2.2  christos 		return ERANGE;
    326  1.18.2.2  christos 	strcpy(dtb_path, arg);
    327  1.18.2.2  christos 	return 0;
    328  1.18.2.2  christos }
    329  1.18.2.2  christos 
    330  1.18.2.2  christos char *
    331  1.18.2.2  christos get_dtb_path(void)
    332  1.18.2.2  christos {
    333  1.18.2.2  christos 	return dtb_path;
    334  1.18.2.2  christos }
    335  1.18.2.2  christos 
    336  1.18.2.2  christos int
    337  1.18.2.2  christos set_efibootplist_path(const char *arg)
    338  1.18.2.2  christos {
    339  1.18.2.2  christos 	if (strlen(arg) + 1 > sizeof(efibootplist_path))
    340  1.18.2.2  christos 		return ERANGE;
    341  1.18.2.2  christos 	strcpy(efibootplist_path, arg);
    342  1.18.2.2  christos 	return 0;
    343  1.18.2.2  christos }
    344  1.18.2.2  christos 
    345  1.18.2.2  christos char *get_efibootplist_path(void)
    346  1.18.2.2  christos {
    347  1.18.2.2  christos 	return efibootplist_path;
    348  1.18.2.2  christos }
    349  1.18.2.2  christos 
    350  1.18.2.2  christos int
    351  1.18.2.2  christos set_bootfile(const char *arg)
    352  1.18.2.2  christos {
    353  1.18.2.2  christos 	if (strlen(arg) + 1 > sizeof(netbsd_path))
    354  1.18.2.2  christos 		return ERANGE;
    355  1.18.2.2  christos 	strcpy(netbsd_path, arg);
    356  1.18.2.2  christos 	return 0;
    357  1.18.2.2  christos }
    358  1.18.2.2  christos 
    359  1.18.2.2  christos int
    360  1.18.2.2  christos set_bootargs(const char *arg)
    361  1.18.2.2  christos {
    362  1.18.2.2  christos 	if (strlen(arg) + 1 > sizeof(netbsd_args))
    363  1.18.2.2  christos 		return ERANGE;
    364  1.18.2.2  christos 	strcpy(netbsd_args, arg);
    365  1.18.2.2  christos 	return 0;
    366  1.18.2.2  christos }
    367  1.18.2.2  christos 
    368  1.18.2.2  christos void
    369  1.18.2.2  christos print_banner(void)
    370  1.18.2.2  christos {
    371  1.18.2.2  christos 	printf("\n\n"
    372  1.18.2.2  christos 	    ">> %s, Revision %s (from NetBSD %s)\n",
    373  1.18.2.2  christos 	    bootprog_name, bootprog_rev, bootprog_kernrev);
    374  1.18.2.2  christos }
    375  1.18.2.2  christos 
    376  1.18.2.2  christos static void
    377  1.18.2.2  christos read_env(void)
    378  1.18.2.2  christos {
    379  1.18.2.2  christos 	char *s;
    380  1.18.2.2  christos 
    381  1.18.2.2  christos 	s = efi_env_get("efibootplist");
    382  1.18.2.2  christos 	if (s) {
    383  1.18.2.2  christos #ifdef EFIBOOT_DEBUG
    384  1.18.2.2  christos 		printf(">> Setting efiboot.plist path to '%s' from environment\n", s);
    385  1.18.2.2  christos #endif
    386  1.18.2.2  christos 		set_efibootplist_path(s);
    387  1.18.2.2  christos 		FreePool(s);
    388  1.18.2.2  christos 	}
    389  1.18.2.2  christos 
    390  1.18.2.2  christos 	/*
    391  1.18.2.2  christos 	 * Read the efiboot.plist now as it may contain additional
    392  1.18.2.2  christos 	 * environment variables.
    393  1.18.2.2  christos 	 */
    394  1.18.2.2  christos 	load_efibootplist(true);
    395  1.18.2.2  christos 
    396  1.18.2.2  christos 	s = efi_env_get("fdtfile");
    397  1.18.2.2  christos 	if (s) {
    398  1.18.2.2  christos #ifdef EFIBOOT_DEBUG
    399  1.18.2.2  christos 		printf(">> Setting DTB path to '%s' from environment\n", s);
    400  1.18.2.2  christos #endif
    401  1.18.2.2  christos 		set_dtb_path(s);
    402  1.18.2.2  christos 		FreePool(s);
    403  1.18.2.2  christos 	}
    404  1.18.2.2  christos 
    405  1.18.2.2  christos 	s = efi_env_get("initrd");
    406  1.18.2.2  christos 	if (s) {
    407  1.18.2.2  christos #ifdef EFIBOOT_DEBUG
    408  1.18.2.2  christos 		printf(">> Setting initrd path to '%s' from environment\n", s);
    409  1.18.2.2  christos #endif
    410  1.18.2.2  christos 		set_initrd_path(s);
    411  1.18.2.2  christos 		FreePool(s);
    412  1.18.2.2  christos 	}
    413  1.18.2.2  christos 
    414  1.18.2.2  christos 	s = efi_env_get("bootfile");
    415  1.18.2.2  christos 	if (s) {
    416  1.18.2.2  christos #ifdef EFIBOOT_DEBUG
    417  1.18.2.2  christos 		printf(">> Setting bootfile path to '%s' from environment\n", s);
    418  1.18.2.2  christos #endif
    419  1.18.2.2  christos 		set_bootfile(s);
    420  1.18.2.2  christos 		FreePool(s);
    421  1.18.2.2  christos 	}
    422  1.18.2.2  christos 
    423  1.18.2.2  christos 	s = efi_env_get("rootdev");
    424  1.18.2.2  christos 	if (s) {
    425  1.18.2.2  christos #ifdef EFIBOOT_DEBUG
    426  1.18.2.2  christos 		printf(">> Setting default device to '%s' from environment\n", s);
    427  1.18.2.2  christos #endif
    428  1.18.2.2  christos 		set_default_device(s);
    429  1.18.2.2  christos 		FreePool(s);
    430  1.18.2.2  christos 	}
    431  1.18.2.2  christos 
    432  1.18.2.2  christos 	s = efi_env_get("bootargs");
    433  1.18.2.2  christos 	if (s) {
    434  1.18.2.2  christos #ifdef EFIBOOT_DEBUG
    435  1.18.2.2  christos 		printf(">> Setting default boot args to '%s' from environment\n", s);
    436  1.18.2.2  christos #endif
    437  1.18.2.2  christos 		set_bootargs(s);
    438  1.18.2.2  christos 		FreePool(s);
    439  1.18.2.2  christos 	}
    440  1.18.2.2  christos }
    441  1.18.2.2  christos 
    442  1.18.2.2  christos void
    443  1.18.2.2  christos boot(void)
    444  1.18.2.2  christos {
    445  1.18.2.2  christos 	int currname, c;
    446  1.18.2.2  christos 
    447  1.18.2.2  christos 	read_env();
    448  1.18.2.2  christos 	print_banner();
    449  1.18.2.2  christos 	printf("Press return to boot now, any other key for boot prompt\n");
    450  1.18.2.2  christos 
    451  1.18.2.2  christos 	if (netbsd_path[0] != '\0')
    452  1.18.2.2  christos 		currname = -1;
    453  1.18.2.2  christos 	else
    454  1.18.2.2  christos 		currname = 0;
    455  1.18.2.2  christos 
    456  1.18.2.2  christos 	for (; currname < (int)NUMNAMES; currname++) {
    457  1.18.2.2  christos 		if (currname >= 0)
    458  1.18.2.2  christos 			set_bootfile(names[currname]);
    459  1.18.2.2  christos 		printf("booting %s%s%s - starting in ", netbsd_path,
    460  1.18.2.2  christos 		    netbsd_args[0] != '\0' ? " " : "", netbsd_args);
    461  1.18.2.2  christos 
    462  1.18.2.2  christos 		c = awaitkey(DEFTIMEOUT, 1);
    463  1.18.2.2  christos 		if (c != '\r' && c != '\n' && c != '\0')
    464  1.18.2.2  christos 			bootprompt(); /* does not return */
    465  1.18.2.2  christos 
    466  1.18.2.2  christos 		exec_netbsd(netbsd_path, netbsd_args);
    467  1.18.2.2  christos 	}
    468  1.18.2.2  christos 
    469  1.18.2.2  christos 	bootprompt();	/* does not return */
    470  1.18.2.2  christos }
    471