boot.c revision 1.18.2.3 1 1.18.2.3 martin /* $NetBSD: boot.c,v 1.18.2.3 2020/04/08 14:09:02 martin 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.3 martin static char rndseed_path[255];
79 1.18.2.2 christos
80 1.18.2.2 christos #define DEFTIMEOUT 5
81 1.18.2.2 christos #define DEFFILENAME names[0]
82 1.18.2.2 christos
83 1.18.2.2 christos int set_bootfile(const char *);
84 1.18.2.2 christos int set_bootargs(const char *);
85 1.18.2.2 christos
86 1.18.2.2 christos void command_boot(char *);
87 1.18.2.2 christos void command_dev(char *);
88 1.18.2.2 christos void command_dtb(char *);
89 1.18.2.2 christos void command_plist(char *);
90 1.18.2.2 christos void command_initrd(char *);
91 1.18.2.3 martin void command_rndseed(char *);
92 1.18.2.2 christos void command_ls(char *);
93 1.18.2.2 christos void command_mem(char *);
94 1.18.2.2 christos void command_printenv(char *);
95 1.18.2.2 christos void command_setenv(char *);
96 1.18.2.2 christos void command_clearenv(char *);
97 1.18.2.2 christos void command_resetenv(char *);
98 1.18.2.2 christos void command_reset(char *);
99 1.18.2.2 christos void command_version(char *);
100 1.18.2.2 christos void command_quit(char *);
101 1.18.2.2 christos
102 1.18.2.2 christos const struct boot_command commands[] = {
103 1.18.2.2 christos { "boot", command_boot, "boot [dev:][filename] [args]\n (ex. \"hd0a:\\netbsd.old -s\"" },
104 1.18.2.2 christos { "dev", command_dev, "dev" },
105 1.18.2.2 christos { "dtb", command_dtb, "dtb [dev:][filename]" },
106 1.18.2.2 christos { "plist", command_plist, "plist [dev:][filename]" },
107 1.18.2.2 christos { "initrd", command_initrd, "initrd [dev:][filename]" },
108 1.18.2.3 martin { "rndseed", command_rndseed, "rndseed [dev:][filename]" },
109 1.18.2.2 christos { "ls", command_ls, "ls [hdNn:/path]" },
110 1.18.2.2 christos { "mem", command_mem, "mem" },
111 1.18.2.2 christos { "printenv", command_printenv, "printenv [key]" },
112 1.18.2.2 christos { "setenv", command_setenv, "setenv <key> <value>" },
113 1.18.2.2 christos { "clearenv", command_clearenv, "clearenv <key>" },
114 1.18.2.2 christos { "resetenv", command_resetenv, "resetenv" },
115 1.18.2.2 christos { "reboot", command_reset, "reboot|reset" },
116 1.18.2.2 christos { "reset", command_reset, NULL },
117 1.18.2.2 christos { "version", command_version, "version" },
118 1.18.2.3 martin { "ver", command_version, NULL },
119 1.18.2.2 christos { "help", command_help, "help|?" },
120 1.18.2.2 christos { "?", command_help, NULL },
121 1.18.2.2 christos { "quit", command_quit, "quit" },
122 1.18.2.2 christos { NULL, NULL },
123 1.18.2.2 christos };
124 1.18.2.2 christos
125 1.18.2.2 christos void
126 1.18.2.2 christos command_help(char *arg)
127 1.18.2.2 christos {
128 1.18.2.2 christos int n;
129 1.18.2.2 christos
130 1.18.2.2 christos printf("commands are:\n");
131 1.18.2.2 christos for (n = 0; commands[n].c_name; n++) {
132 1.18.2.2 christos if (commands[n].c_help)
133 1.18.2.2 christos printf("%s\n", commands[n].c_help);
134 1.18.2.2 christos }
135 1.18.2.2 christos }
136 1.18.2.2 christos
137 1.18.2.2 christos void
138 1.18.2.2 christos command_boot(char *arg)
139 1.18.2.2 christos {
140 1.18.2.2 christos char *fname = arg;
141 1.18.2.2 christos const char *kernel = *fname ? fname : bootfile;
142 1.18.2.2 christos char *bootargs = gettrailer(arg);
143 1.18.2.2 christos
144 1.18.2.2 christos if (!kernel || !*kernel)
145 1.18.2.2 christos kernel = DEFFILENAME;
146 1.18.2.2 christos
147 1.18.2.2 christos if (!*bootargs)
148 1.18.2.2 christos bootargs = netbsd_args;
149 1.18.2.2 christos
150 1.18.2.2 christos exec_netbsd(kernel, bootargs);
151 1.18.2.2 christos }
152 1.18.2.2 christos
153 1.18.2.2 christos void
154 1.18.2.2 christos command_dev(char *arg)
155 1.18.2.2 christos {
156 1.18.2.2 christos if (arg && *arg) {
157 1.18.2.2 christos set_default_device(arg);
158 1.18.2.2 christos } else {
159 1.18.2.2 christos efi_block_show();
160 1.18.2.2 christos efi_net_show();
161 1.18.2.2 christos }
162 1.18.2.2 christos
163 1.18.2.2 christos if (strlen(default_device) > 0) {
164 1.18.2.2 christos printf("\n");
165 1.18.2.2 christos printf("default: %s\n", default_device);
166 1.18.2.2 christos }
167 1.18.2.2 christos }
168 1.18.2.2 christos
169 1.18.2.2 christos void
170 1.18.2.2 christos command_dtb(char *arg)
171 1.18.2.2 christos {
172 1.18.2.2 christos set_dtb_path(arg);
173 1.18.2.2 christos }
174 1.18.2.2 christos
175 1.18.2.2 christos void
176 1.18.2.2 christos command_plist(char *arg)
177 1.18.2.2 christos {
178 1.18.2.2 christos if (set_efibootplist_path(arg) == 0)
179 1.18.2.2 christos load_efibootplist(false);
180 1.18.2.2 christos }
181 1.18.2.2 christos
182 1.18.2.2 christos void
183 1.18.2.2 christos command_initrd(char *arg)
184 1.18.2.2 christos {
185 1.18.2.2 christos set_initrd_path(arg);
186 1.18.2.2 christos }
187 1.18.2.2 christos
188 1.18.2.2 christos void
189 1.18.2.3 martin command_rndseed(char *arg)
190 1.18.2.3 martin {
191 1.18.2.3 martin set_rndseed_path(arg);
192 1.18.2.3 martin }
193 1.18.2.3 martin
194 1.18.2.3 martin void
195 1.18.2.2 christos command_ls(char *arg)
196 1.18.2.2 christos {
197 1.18.2.2 christos ls(arg);
198 1.18.2.2 christos }
199 1.18.2.2 christos
200 1.18.2.2 christos void
201 1.18.2.2 christos command_mem(char *arg)
202 1.18.2.2 christos {
203 1.18.2.2 christos EFI_MEMORY_DESCRIPTOR *md, *memmap;
204 1.18.2.2 christos UINTN nentries, mapkey, descsize;
205 1.18.2.2 christos UINT32 descver;
206 1.18.2.2 christos int n;
207 1.18.2.2 christos
208 1.18.2.2 christos printf("Type Start End Attributes\n");
209 1.18.2.2 christos printf("---------------------- ---------------- ---------------- ----------------\n");
210 1.18.2.2 christos memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
211 1.18.2.2 christos for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
212 1.18.2.2 christos const char *mem_type = "<unknown>";
213 1.18.2.2 christos if (md->Type < __arraycount(efi_memory_type))
214 1.18.2.2 christos mem_type = efi_memory_type[md->Type];
215 1.18.2.2 christos
216 1.18.2.2 christos printf("%-22s %016" PRIx64 " %016" PRIx64 " %016" PRIx64 "\n",
217 1.18.2.2 christos mem_type, md->PhysicalStart, md->PhysicalStart + (md->NumberOfPages * EFI_PAGE_SIZE) - 1,
218 1.18.2.2 christos md->Attribute);
219 1.18.2.2 christos }
220 1.18.2.2 christos }
221 1.18.2.2 christos
222 1.18.2.2 christos void
223 1.18.2.2 christos command_printenv(char *arg)
224 1.18.2.2 christos {
225 1.18.2.2 christos char *val;
226 1.18.2.2 christos
227 1.18.2.2 christos if (arg && *arg) {
228 1.18.2.2 christos val = efi_env_get(arg);
229 1.18.2.2 christos if (val) {
230 1.18.2.2 christos printf("\"%s\" = \"%s\"\n", arg, val);
231 1.18.2.2 christos FreePool(val);
232 1.18.2.2 christos }
233 1.18.2.2 christos } else {
234 1.18.2.2 christos efi_env_print();
235 1.18.2.2 christos }
236 1.18.2.2 christos }
237 1.18.2.2 christos
238 1.18.2.2 christos void
239 1.18.2.2 christos command_setenv(char *arg)
240 1.18.2.2 christos {
241 1.18.2.2 christos char *spc;
242 1.18.2.2 christos
243 1.18.2.2 christos spc = strchr(arg, ' ');
244 1.18.2.2 christos if (spc == NULL || spc[1] == '\0') {
245 1.18.2.2 christos command_help("");
246 1.18.2.2 christos return;
247 1.18.2.2 christos }
248 1.18.2.2 christos
249 1.18.2.2 christos *spc = '\0';
250 1.18.2.2 christos efi_env_set(arg, spc + 1);
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_clearenv(char *arg)
255 1.18.2.2 christos {
256 1.18.2.2 christos if (*arg == '\0') {
257 1.18.2.2 christos command_help("");
258 1.18.2.2 christos return;
259 1.18.2.2 christos }
260 1.18.2.2 christos efi_env_clear(arg);
261 1.18.2.2 christos }
262 1.18.2.2 christos
263 1.18.2.2 christos void
264 1.18.2.2 christos command_resetenv(char *arg)
265 1.18.2.2 christos {
266 1.18.2.2 christos efi_env_reset();
267 1.18.2.2 christos }
268 1.18.2.2 christos
269 1.18.2.2 christos void
270 1.18.2.2 christos command_version(char *arg)
271 1.18.2.2 christos {
272 1.18.2.2 christos char *ufirmware;
273 1.18.2.2 christos int rv;
274 1.18.2.2 christos
275 1.18.2.3 martin printf("Version: %s (%s)\n", bootprog_rev, bootprog_kernrev);
276 1.18.2.3 martin printf("EFI: %d.%02d\n",
277 1.18.2.2 christos ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
278 1.18.2.2 christos ufirmware = NULL;
279 1.18.2.2 christos rv = ucs2_to_utf8(ST->FirmwareVendor, &ufirmware);
280 1.18.2.2 christos if (rv == 0) {
281 1.18.2.3 martin printf("Firmware: %s (rev 0x%x)\n", ufirmware,
282 1.18.2.2 christos ST->FirmwareRevision);
283 1.18.2.2 christos FreePool(ufirmware);
284 1.18.2.2 christos }
285 1.18.2.2 christos
286 1.18.2.2 christos efi_fdt_show();
287 1.18.2.2 christos efi_acpi_show();
288 1.18.2.2 christos }
289 1.18.2.2 christos
290 1.18.2.2 christos void
291 1.18.2.2 christos command_quit(char *arg)
292 1.18.2.2 christos {
293 1.18.2.2 christos efi_exit();
294 1.18.2.2 christos }
295 1.18.2.2 christos
296 1.18.2.2 christos void
297 1.18.2.2 christos command_reset(char *arg)
298 1.18.2.2 christos {
299 1.18.2.2 christos efi_reboot();
300 1.18.2.2 christos }
301 1.18.2.2 christos
302 1.18.2.2 christos int
303 1.18.2.2 christos set_default_device(const char *arg)
304 1.18.2.2 christos {
305 1.18.2.2 christos if (strlen(arg) + 1 > sizeof(default_device))
306 1.18.2.2 christos return ERANGE;
307 1.18.2.2 christos strcpy(default_device, arg);
308 1.18.2.2 christos return 0;
309 1.18.2.2 christos }
310 1.18.2.2 christos
311 1.18.2.2 christos char *
312 1.18.2.2 christos get_default_device(void)
313 1.18.2.2 christos {
314 1.18.2.2 christos return default_device;
315 1.18.2.2 christos }
316 1.18.2.2 christos
317 1.18.2.2 christos int
318 1.18.2.2 christos set_initrd_path(const char *arg)
319 1.18.2.2 christos {
320 1.18.2.2 christos if (strlen(arg) + 1 > sizeof(initrd_path))
321 1.18.2.2 christos return ERANGE;
322 1.18.2.2 christos strcpy(initrd_path, arg);
323 1.18.2.2 christos return 0;
324 1.18.2.2 christos }
325 1.18.2.2 christos
326 1.18.2.2 christos char *
327 1.18.2.2 christos get_initrd_path(void)
328 1.18.2.2 christos {
329 1.18.2.2 christos return initrd_path;
330 1.18.2.2 christos }
331 1.18.2.2 christos
332 1.18.2.2 christos int
333 1.18.2.2 christos set_dtb_path(const char *arg)
334 1.18.2.2 christos {
335 1.18.2.2 christos if (strlen(arg) + 1 > sizeof(dtb_path))
336 1.18.2.2 christos return ERANGE;
337 1.18.2.2 christos strcpy(dtb_path, arg);
338 1.18.2.2 christos return 0;
339 1.18.2.2 christos }
340 1.18.2.2 christos
341 1.18.2.2 christos char *
342 1.18.2.2 christos get_dtb_path(void)
343 1.18.2.2 christos {
344 1.18.2.2 christos return dtb_path;
345 1.18.2.2 christos }
346 1.18.2.2 christos
347 1.18.2.2 christos int
348 1.18.2.2 christos set_efibootplist_path(const char *arg)
349 1.18.2.2 christos {
350 1.18.2.2 christos if (strlen(arg) + 1 > sizeof(efibootplist_path))
351 1.18.2.2 christos return ERANGE;
352 1.18.2.2 christos strcpy(efibootplist_path, arg);
353 1.18.2.2 christos return 0;
354 1.18.2.2 christos }
355 1.18.2.2 christos
356 1.18.2.2 christos char *get_efibootplist_path(void)
357 1.18.2.2 christos {
358 1.18.2.2 christos return efibootplist_path;
359 1.18.2.2 christos }
360 1.18.2.2 christos
361 1.18.2.2 christos int
362 1.18.2.3 martin set_rndseed_path(const char *arg)
363 1.18.2.3 martin {
364 1.18.2.3 martin if (strlen(arg) + 1 > sizeof(rndseed_path))
365 1.18.2.3 martin return ERANGE;
366 1.18.2.3 martin strcpy(rndseed_path, arg);
367 1.18.2.3 martin return 0;
368 1.18.2.3 martin }
369 1.18.2.3 martin
370 1.18.2.3 martin char *
371 1.18.2.3 martin get_rndseed_path(void)
372 1.18.2.3 martin {
373 1.18.2.3 martin return rndseed_path;
374 1.18.2.3 martin }
375 1.18.2.3 martin
376 1.18.2.3 martin int
377 1.18.2.2 christos set_bootfile(const char *arg)
378 1.18.2.2 christos {
379 1.18.2.2 christos if (strlen(arg) + 1 > sizeof(netbsd_path))
380 1.18.2.2 christos return ERANGE;
381 1.18.2.2 christos strcpy(netbsd_path, arg);
382 1.18.2.2 christos return 0;
383 1.18.2.2 christos }
384 1.18.2.2 christos
385 1.18.2.2 christos int
386 1.18.2.2 christos set_bootargs(const char *arg)
387 1.18.2.2 christos {
388 1.18.2.2 christos if (strlen(arg) + 1 > sizeof(netbsd_args))
389 1.18.2.2 christos return ERANGE;
390 1.18.2.2 christos strcpy(netbsd_args, arg);
391 1.18.2.2 christos return 0;
392 1.18.2.2 christos }
393 1.18.2.2 christos
394 1.18.2.2 christos void
395 1.18.2.2 christos print_banner(void)
396 1.18.2.2 christos {
397 1.18.2.2 christos printf("\n\n"
398 1.18.2.3 martin ">> %s, Revision %s\n",
399 1.18.2.3 martin bootprog_name, bootprog_rev);
400 1.18.2.2 christos }
401 1.18.2.2 christos
402 1.18.2.2 christos static void
403 1.18.2.2 christos read_env(void)
404 1.18.2.2 christos {
405 1.18.2.2 christos char *s;
406 1.18.2.2 christos
407 1.18.2.2 christos s = efi_env_get("efibootplist");
408 1.18.2.2 christos if (s) {
409 1.18.2.2 christos #ifdef EFIBOOT_DEBUG
410 1.18.2.2 christos printf(">> Setting efiboot.plist path to '%s' from environment\n", s);
411 1.18.2.2 christos #endif
412 1.18.2.2 christos set_efibootplist_path(s);
413 1.18.2.2 christos FreePool(s);
414 1.18.2.2 christos }
415 1.18.2.2 christos
416 1.18.2.2 christos /*
417 1.18.2.2 christos * Read the efiboot.plist now as it may contain additional
418 1.18.2.2 christos * environment variables.
419 1.18.2.2 christos */
420 1.18.2.2 christos load_efibootplist(true);
421 1.18.2.2 christos
422 1.18.2.2 christos s = efi_env_get("fdtfile");
423 1.18.2.2 christos if (s) {
424 1.18.2.2 christos #ifdef EFIBOOT_DEBUG
425 1.18.2.2 christos printf(">> Setting DTB path to '%s' from environment\n", s);
426 1.18.2.2 christos #endif
427 1.18.2.2 christos set_dtb_path(s);
428 1.18.2.2 christos FreePool(s);
429 1.18.2.2 christos }
430 1.18.2.2 christos
431 1.18.2.2 christos s = efi_env_get("initrd");
432 1.18.2.2 christos if (s) {
433 1.18.2.2 christos #ifdef EFIBOOT_DEBUG
434 1.18.2.2 christos printf(">> Setting initrd path to '%s' from environment\n", s);
435 1.18.2.2 christos #endif
436 1.18.2.2 christos set_initrd_path(s);
437 1.18.2.2 christos FreePool(s);
438 1.18.2.2 christos }
439 1.18.2.2 christos
440 1.18.2.2 christos s = efi_env_get("bootfile");
441 1.18.2.2 christos if (s) {
442 1.18.2.2 christos #ifdef EFIBOOT_DEBUG
443 1.18.2.2 christos printf(">> Setting bootfile path to '%s' from environment\n", s);
444 1.18.2.2 christos #endif
445 1.18.2.2 christos set_bootfile(s);
446 1.18.2.2 christos FreePool(s);
447 1.18.2.2 christos }
448 1.18.2.2 christos
449 1.18.2.2 christos s = efi_env_get("rootdev");
450 1.18.2.2 christos if (s) {
451 1.18.2.2 christos #ifdef EFIBOOT_DEBUG
452 1.18.2.2 christos printf(">> Setting default device to '%s' from environment\n", s);
453 1.18.2.2 christos #endif
454 1.18.2.2 christos set_default_device(s);
455 1.18.2.2 christos FreePool(s);
456 1.18.2.2 christos }
457 1.18.2.2 christos
458 1.18.2.2 christos s = efi_env_get("bootargs");
459 1.18.2.2 christos if (s) {
460 1.18.2.2 christos #ifdef EFIBOOT_DEBUG
461 1.18.2.2 christos printf(">> Setting default boot args to '%s' from environment\n", s);
462 1.18.2.2 christos #endif
463 1.18.2.2 christos set_bootargs(s);
464 1.18.2.2 christos FreePool(s);
465 1.18.2.2 christos }
466 1.18.2.3 martin
467 1.18.2.3 martin s = efi_env_get("rndseed");
468 1.18.2.3 martin if (s) {
469 1.18.2.3 martin #ifdef EFIBOOT_DEBUG
470 1.18.2.3 martin printf(">> Setting rndseed path to '%s' from environment\n", s);
471 1.18.2.3 martin #endif
472 1.18.2.3 martin set_rndseed_path(s);
473 1.18.2.3 martin FreePool(s);
474 1.18.2.3 martin }
475 1.18.2.2 christos }
476 1.18.2.2 christos
477 1.18.2.2 christos void
478 1.18.2.2 christos boot(void)
479 1.18.2.2 christos {
480 1.18.2.2 christos int currname, c;
481 1.18.2.2 christos
482 1.18.2.2 christos read_env();
483 1.18.2.2 christos print_banner();
484 1.18.2.2 christos printf("Press return to boot now, any other key for boot prompt\n");
485 1.18.2.2 christos
486 1.18.2.2 christos if (netbsd_path[0] != '\0')
487 1.18.2.2 christos currname = -1;
488 1.18.2.2 christos else
489 1.18.2.2 christos currname = 0;
490 1.18.2.2 christos
491 1.18.2.2 christos for (; currname < (int)NUMNAMES; currname++) {
492 1.18.2.2 christos if (currname >= 0)
493 1.18.2.2 christos set_bootfile(names[currname]);
494 1.18.2.2 christos printf("booting %s%s%s - starting in ", netbsd_path,
495 1.18.2.2 christos netbsd_args[0] != '\0' ? " " : "", netbsd_args);
496 1.18.2.2 christos
497 1.18.2.2 christos c = awaitkey(DEFTIMEOUT, 1);
498 1.18.2.2 christos if (c != '\r' && c != '\n' && c != '\0')
499 1.18.2.2 christos bootprompt(); /* does not return */
500 1.18.2.2 christos
501 1.18.2.2 christos exec_netbsd(netbsd_path, netbsd_args);
502 1.18.2.2 christos }
503 1.18.2.2 christos
504 1.18.2.2 christos bootprompt(); /* does not return */
505 1.18.2.2 christos }
506