boot.c revision 1.40 1 1.40 jmcneill /* $NetBSD: boot.c,v 1.40 2021/10/17 14:12:54 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2016 Kimihiro Nonaka <nonaka (at) netbsd.org>
5 1.1 jmcneill * Copyright (c) 2018 Jared McNeill <jmcneill (at) invisible.ca>
6 1.1 jmcneill * All rights reserved.
7 1.1 jmcneill *
8 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
9 1.1 jmcneill * modification, are permitted provided that the following conditions
10 1.1 jmcneill * are met:
11 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
12 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
13 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
15 1.1 jmcneill * documentation and/or other materials provided with the distribution.
16 1.1 jmcneill *
17 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 1.1 jmcneill * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.1 jmcneill * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1 jmcneill * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 1.1 jmcneill * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1 jmcneill * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.1 jmcneill * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 jmcneill * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.1 jmcneill * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1 jmcneill * SUCH DAMAGE.
28 1.1 jmcneill */
29 1.1 jmcneill
30 1.1 jmcneill #include "efiboot.h"
31 1.3 jmcneill #include "efiblock.h"
32 1.25 jmcneill #include "efifile.h"
33 1.21 riastrad #include "efirng.h"
34 1.22 jmcneill #include "module.h"
35 1.38 jmcneill #include "bootmenu.h"
36 1.38 jmcneill
37 1.38 jmcneill #ifdef EFIBOOT_FDT
38 1.38 jmcneill #include "efifdt.h"
39 1.24 thorpej #include "overlay.h"
40 1.38 jmcneill #endif
41 1.38 jmcneill
42 1.38 jmcneill #ifdef EFIBOOT_ACPI
43 1.38 jmcneill #include "efiacpi.h"
44 1.38 jmcneill #endif
45 1.1 jmcneill
46 1.1 jmcneill #include <sys/bootblock.h>
47 1.1 jmcneill #include <sys/boot_flag.h>
48 1.1 jmcneill #include <machine/limits.h>
49 1.1 jmcneill
50 1.1 jmcneill #include <loadfile.h>
51 1.23 jmcneill #include <bootcfg.h>
52 1.1 jmcneill
53 1.1 jmcneill extern const char bootprog_name[], bootprog_rev[], bootprog_kernrev[];
54 1.1 jmcneill
55 1.1 jmcneill extern char twiddle_toggle;
56 1.1 jmcneill
57 1.11 mrg static const char * const names[] = {
58 1.11 mrg "netbsd", "netbsd.gz",
59 1.11 mrg "onetbsd", "onetbsd.gz",
60 1.11 mrg "netbsd.old", "netbsd.old.gz",
61 1.1 jmcneill };
62 1.1 jmcneill
63 1.1 jmcneill #define NUMNAMES __arraycount(names)
64 1.1 jmcneill
65 1.13 jmcneill static const char *efi_memory_type[] = {
66 1.13 jmcneill [EfiReservedMemoryType] = "Reserved Memory Type",
67 1.13 jmcneill [EfiLoaderCode] = "Loader Code",
68 1.13 jmcneill [EfiLoaderData] = "Loader Data",
69 1.13 jmcneill [EfiBootServicesCode] = "Boot Services Code",
70 1.13 jmcneill [EfiBootServicesData] = "Boot Services Data",
71 1.13 jmcneill [EfiRuntimeServicesCode] = "Runtime Services Code",
72 1.13 jmcneill [EfiRuntimeServicesData] = "Runtime Services Data",
73 1.13 jmcneill [EfiConventionalMemory] = "Conventional Memory",
74 1.13 jmcneill [EfiUnusableMemory] = "Unusable Memory",
75 1.13 jmcneill [EfiACPIReclaimMemory] = "ACPI Reclaim Memory",
76 1.13 jmcneill [EfiACPIMemoryNVS] = "ACPI Memory NVS",
77 1.13 jmcneill [EfiMemoryMappedIO] = "MMIO",
78 1.13 jmcneill [EfiMemoryMappedIOPortSpace] = "MMIO (Port Space)",
79 1.13 jmcneill [EfiPalCode] = "Pal Code",
80 1.13 jmcneill [EfiPersistentMemory] = "Persistent Memory",
81 1.13 jmcneill };
82 1.13 jmcneill
83 1.3 jmcneill static char default_device[32];
84 1.28 jmcneill static int default_fstype = FS_UNUSED;
85 1.6 jmcneill static char initrd_path[255];
86 1.7 jmcneill static char dtb_path[255];
87 1.14 jmcneill static char netbsd_path[255];
88 1.15 skrll static char netbsd_args[255];
89 1.19 riastrad static char rndseed_path[255];
90 1.11 mrg
91 1.11 mrg #define DEFFILENAME names[0]
92 1.11 mrg
93 1.11 mrg int set_bootfile(const char *);
94 1.15 skrll int set_bootargs(const char *);
95 1.3 jmcneill
96 1.1 jmcneill void command_boot(char *);
97 1.3 jmcneill void command_dev(char *);
98 1.6 jmcneill void command_initrd(char *);
99 1.19 riastrad void command_rndseed(char *);
100 1.38 jmcneill #ifdef EFIBOOT_FDT
101 1.38 jmcneill void command_dtb(char *);
102 1.24 thorpej void command_dtoverlay(char *);
103 1.24 thorpej void command_dtoverlays(char *);
104 1.38 jmcneill #endif
105 1.22 jmcneill void command_modules(char *);
106 1.22 jmcneill void command_load(char *);
107 1.22 jmcneill void command_unload(char *);
108 1.3 jmcneill void command_ls(char *);
109 1.37 jmcneill void command_gop(char *);
110 1.13 jmcneill void command_mem(char *);
111 1.23 jmcneill void command_menu(char *);
112 1.1 jmcneill void command_reset(char *);
113 1.39 jmcneill void command_setup(char *);
114 1.1 jmcneill void command_version(char *);
115 1.1 jmcneill void command_quit(char *);
116 1.1 jmcneill
117 1.1 jmcneill const struct boot_command commands[] = {
118 1.6 jmcneill { "boot", command_boot, "boot [dev:][filename] [args]\n (ex. \"hd0a:\\netbsd.old -s\"" },
119 1.3 jmcneill { "dev", command_dev, "dev" },
120 1.38 jmcneill #ifdef EFIBOOT_FDT
121 1.7 jmcneill { "dtb", command_dtb, "dtb [dev:][filename]" },
122 1.38 jmcneill { "dtoverlay", command_dtoverlay, "dtoverlay [dev:][filename]" },
123 1.38 jmcneill { "dtoverlays", command_dtoverlays, "dtoverlays [{on|off|reset}]" },
124 1.38 jmcneill #endif
125 1.6 jmcneill { "initrd", command_initrd, "initrd [dev:][filename]" },
126 1.35 jmcneill { "fs", command_initrd, NULL },
127 1.19 riastrad { "rndseed", command_rndseed, "rndseed [dev:][filename]" },
128 1.22 jmcneill { "modules", command_modules, "modules [{on|off|reset}]" },
129 1.22 jmcneill { "load", command_load, "load <module_name>" },
130 1.22 jmcneill { "unload", command_unload, "unload <module_name>" },
131 1.4 jmcneill { "ls", command_ls, "ls [hdNn:/path]" },
132 1.37 jmcneill { "gop", command_gop, "gop [mode]" },
133 1.13 jmcneill { "mem", command_mem, "mem" },
134 1.23 jmcneill { "menu", command_menu, "menu" },
135 1.9 jmcneill { "reboot", command_reset, "reboot|reset" },
136 1.9 jmcneill { "reset", command_reset, NULL },
137 1.39 jmcneill { "setup", command_setup, "setup" },
138 1.1 jmcneill { "version", command_version, "version" },
139 1.20 jmcneill { "ver", command_version, NULL },
140 1.1 jmcneill { "help", command_help, "help|?" },
141 1.1 jmcneill { "?", command_help, NULL },
142 1.1 jmcneill { "quit", command_quit, "quit" },
143 1.1 jmcneill { NULL, NULL },
144 1.1 jmcneill };
145 1.1 jmcneill
146 1.28 jmcneill static int
147 1.28 jmcneill bootcfg_path(char *pathbuf, size_t pathbuflen)
148 1.28 jmcneill {
149 1.28 jmcneill
150 1.28 jmcneill /*
151 1.30 rin * Fallback to default_device
152 1.30 rin * - for ISO9660 (efi_file_path() succeeds but does not work correctly)
153 1.30 rin * - or whenever efi_file_path() fails (due to broken firmware)
154 1.28 jmcneill */
155 1.30 rin if (default_fstype == FS_ISO9660 || efi_bootdp == NULL ||
156 1.30 rin efi_file_path(efi_bootdp, BOOTCFG_FILENAME, pathbuf, pathbuflen))
157 1.30 rin snprintf(pathbuf, pathbuflen, "%s:%s", default_device,
158 1.30 rin BOOTCFG_FILENAME);
159 1.28 jmcneill
160 1.30 rin return 0;
161 1.28 jmcneill }
162 1.28 jmcneill
163 1.1 jmcneill void
164 1.1 jmcneill command_help(char *arg)
165 1.1 jmcneill {
166 1.1 jmcneill int n;
167 1.1 jmcneill
168 1.1 jmcneill printf("commands are:\n");
169 1.1 jmcneill for (n = 0; commands[n].c_name; n++) {
170 1.1 jmcneill if (commands[n].c_help)
171 1.1 jmcneill printf("%s\n", commands[n].c_help);
172 1.1 jmcneill }
173 1.1 jmcneill }
174 1.1 jmcneill
175 1.1 jmcneill void
176 1.1 jmcneill command_boot(char *arg)
177 1.1 jmcneill {
178 1.1 jmcneill char *fname = arg;
179 1.11 mrg const char *kernel = *fname ? fname : bootfile;
180 1.1 jmcneill char *bootargs = gettrailer(arg);
181 1.1 jmcneill
182 1.11 mrg if (!kernel || !*kernel)
183 1.11 mrg kernel = DEFFILENAME;
184 1.11 mrg
185 1.16 skrll if (!*bootargs)
186 1.16 skrll bootargs = netbsd_args;
187 1.16 skrll
188 1.32 jmcneill efi_block_set_readahead(true);
189 1.11 mrg exec_netbsd(kernel, bootargs);
190 1.32 jmcneill efi_block_set_readahead(false);
191 1.1 jmcneill }
192 1.1 jmcneill
193 1.1 jmcneill void
194 1.3 jmcneill command_dev(char *arg)
195 1.3 jmcneill {
196 1.3 jmcneill if (arg && *arg) {
197 1.3 jmcneill set_default_device(arg);
198 1.3 jmcneill } else {
199 1.3 jmcneill efi_block_show();
200 1.4 jmcneill efi_net_show();
201 1.3 jmcneill }
202 1.3 jmcneill
203 1.3 jmcneill if (strlen(default_device) > 0) {
204 1.3 jmcneill printf("\n");
205 1.3 jmcneill printf("default: %s\n", default_device);
206 1.3 jmcneill }
207 1.3 jmcneill }
208 1.3 jmcneill
209 1.3 jmcneill void
210 1.38 jmcneill command_initrd(char *arg)
211 1.7 jmcneill {
212 1.38 jmcneill set_initrd_path(arg);
213 1.7 jmcneill }
214 1.7 jmcneill
215 1.7 jmcneill void
216 1.38 jmcneill command_rndseed(char *arg)
217 1.18 thorpej {
218 1.38 jmcneill set_rndseed_path(arg);
219 1.18 thorpej }
220 1.18 thorpej
221 1.38 jmcneill #ifdef EFIBOOT_FDT
222 1.18 thorpej void
223 1.38 jmcneill command_dtb(char *arg)
224 1.24 thorpej {
225 1.38 jmcneill set_dtb_path(arg);
226 1.24 thorpej }
227 1.24 thorpej
228 1.24 thorpej void
229 1.24 thorpej command_dtoverlays(char *arg)
230 1.6 jmcneill {
231 1.24 thorpej if (arg && *arg) {
232 1.24 thorpej if (strcmp(arg, "on") == 0)
233 1.24 thorpej dtoverlay_enable(1);
234 1.24 thorpej else if (strcmp(arg, "off") == 0)
235 1.24 thorpej dtoverlay_enable(0);
236 1.24 thorpej else if (strcmp(arg, "reset") == 0)
237 1.24 thorpej dtoverlay_remove_all();
238 1.24 thorpej else {
239 1.24 thorpej command_help("");
240 1.24 thorpej return;
241 1.24 thorpej }
242 1.24 thorpej } else {
243 1.24 thorpej printf("Device Tree overlays are %sabled\n",
244 1.24 thorpej dtoverlay_enabled ? "en" : "dis");
245 1.24 thorpej }
246 1.6 jmcneill }
247 1.6 jmcneill
248 1.6 jmcneill void
249 1.24 thorpej command_dtoverlay(char *arg)
250 1.19 riastrad {
251 1.24 thorpej if (!arg || !*arg) {
252 1.24 thorpej command_help("");
253 1.24 thorpej return;
254 1.24 thorpej }
255 1.24 thorpej
256 1.24 thorpej dtoverlay_add(arg);
257 1.19 riastrad }
258 1.38 jmcneill #endif
259 1.19 riastrad
260 1.19 riastrad void
261 1.22 jmcneill command_modules(char *arg)
262 1.22 jmcneill {
263 1.22 jmcneill if (arg && *arg) {
264 1.22 jmcneill if (strcmp(arg, "on") == 0)
265 1.22 jmcneill module_enable(1);
266 1.22 jmcneill else if (strcmp(arg, "off") == 0)
267 1.22 jmcneill module_enable(0);
268 1.22 jmcneill else if (strcmp(arg, "reset") == 0)
269 1.22 jmcneill module_remove_all();
270 1.22 jmcneill else {
271 1.22 jmcneill command_help("");
272 1.22 jmcneill return;
273 1.22 jmcneill }
274 1.22 jmcneill } else {
275 1.22 jmcneill printf("modules are %sabled\n", module_enabled ? "en" : "dis");
276 1.22 jmcneill }
277 1.22 jmcneill }
278 1.22 jmcneill
279 1.22 jmcneill void
280 1.22 jmcneill command_load(char *arg)
281 1.22 jmcneill {
282 1.22 jmcneill if (!arg || !*arg) {
283 1.22 jmcneill command_help("");
284 1.22 jmcneill return;
285 1.22 jmcneill }
286 1.22 jmcneill
287 1.22 jmcneill module_add(arg);
288 1.22 jmcneill }
289 1.22 jmcneill
290 1.22 jmcneill void
291 1.22 jmcneill command_unload(char *arg)
292 1.22 jmcneill {
293 1.22 jmcneill if (!arg || !*arg) {
294 1.22 jmcneill command_help("");
295 1.22 jmcneill return;
296 1.22 jmcneill }
297 1.22 jmcneill
298 1.22 jmcneill module_remove(arg);
299 1.22 jmcneill }
300 1.22 jmcneill
301 1.22 jmcneill void
302 1.3 jmcneill command_ls(char *arg)
303 1.3 jmcneill {
304 1.3 jmcneill ls(arg);
305 1.3 jmcneill }
306 1.3 jmcneill
307 1.3 jmcneill void
308 1.37 jmcneill command_gop(char *arg)
309 1.37 jmcneill {
310 1.37 jmcneill UINT32 mode;
311 1.37 jmcneill
312 1.37 jmcneill if (!arg || !*arg) {
313 1.37 jmcneill efi_gop_dump();
314 1.37 jmcneill return;
315 1.37 jmcneill }
316 1.37 jmcneill
317 1.37 jmcneill mode = atoi(arg);
318 1.37 jmcneill efi_gop_setmode(mode);
319 1.37 jmcneill }
320 1.37 jmcneill
321 1.37 jmcneill void
322 1.13 jmcneill command_mem(char *arg)
323 1.13 jmcneill {
324 1.13 jmcneill EFI_MEMORY_DESCRIPTOR *md, *memmap;
325 1.13 jmcneill UINTN nentries, mapkey, descsize;
326 1.13 jmcneill UINT32 descver;
327 1.13 jmcneill int n;
328 1.13 jmcneill
329 1.13 jmcneill printf("Type Start End Attributes\n");
330 1.13 jmcneill printf("---------------------- ---------------- ---------------- ----------------\n");
331 1.13 jmcneill memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
332 1.13 jmcneill for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
333 1.13 jmcneill const char *mem_type = "<unknown>";
334 1.13 jmcneill if (md->Type < __arraycount(efi_memory_type))
335 1.13 jmcneill mem_type = efi_memory_type[md->Type];
336 1.13 jmcneill
337 1.13 jmcneill printf("%-22s %016" PRIx64 " %016" PRIx64 " %016" PRIx64 "\n",
338 1.13 jmcneill mem_type, md->PhysicalStart, md->PhysicalStart + (md->NumberOfPages * EFI_PAGE_SIZE) - 1,
339 1.13 jmcneill md->Attribute);
340 1.13 jmcneill }
341 1.13 jmcneill }
342 1.13 jmcneill
343 1.13 jmcneill void
344 1.23 jmcneill command_menu(char *arg)
345 1.23 jmcneill {
346 1.23 jmcneill if (bootcfg_info.nummenu == 0) {
347 1.23 jmcneill printf("No menu defined in boot.cfg\n");
348 1.23 jmcneill return;
349 1.23 jmcneill }
350 1.23 jmcneill
351 1.23 jmcneill doboottypemenu(); /* Does not return */
352 1.23 jmcneill }
353 1.23 jmcneill
354 1.23 jmcneill void
355 1.1 jmcneill command_version(char *arg)
356 1.1 jmcneill {
357 1.26 jmcneill char pathbuf[80];
358 1.1 jmcneill char *ufirmware;
359 1.39 jmcneill const UINT64 *osindsup;
360 1.1 jmcneill int rv;
361 1.1 jmcneill
362 1.20 jmcneill printf("Version: %s (%s)\n", bootprog_rev, bootprog_kernrev);
363 1.20 jmcneill printf("EFI: %d.%02d\n",
364 1.1 jmcneill ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
365 1.1 jmcneill ufirmware = NULL;
366 1.1 jmcneill rv = ucs2_to_utf8(ST->FirmwareVendor, &ufirmware);
367 1.1 jmcneill if (rv == 0) {
368 1.20 jmcneill printf("Firmware: %s (rev 0x%x)\n", ufirmware,
369 1.17 jmcneill ST->FirmwareRevision);
370 1.1 jmcneill FreePool(ufirmware);
371 1.1 jmcneill }
372 1.28 jmcneill if (bootcfg_path(pathbuf, sizeof(pathbuf)) == 0) {
373 1.26 jmcneill printf("Config path: %s\n", pathbuf);
374 1.26 jmcneill }
375 1.5 jmcneill
376 1.39 jmcneill osindsup = LibGetVariable(L"OsIndicationsSupported", &EfiGlobalVariable);
377 1.39 jmcneill if (osindsup != NULL) {
378 1.39 jmcneill printf("UEFI OS indications supported: 0x%" PRIx64 "\n", *osindsup);
379 1.39 jmcneill }
380 1.39 jmcneill
381 1.38 jmcneill #ifdef EFIBOOT_FDT
382 1.5 jmcneill efi_fdt_show();
383 1.38 jmcneill #endif
384 1.38 jmcneill #ifdef EFIBOOT_ACPI
385 1.10 jmcneill efi_acpi_show();
386 1.38 jmcneill #endif
387 1.21 riastrad efi_rng_show();
388 1.29 jmcneill efi_md_show();
389 1.37 jmcneill efi_gop_show();
390 1.1 jmcneill }
391 1.1 jmcneill
392 1.1 jmcneill void
393 1.1 jmcneill command_quit(char *arg)
394 1.1 jmcneill {
395 1.1 jmcneill efi_exit();
396 1.1 jmcneill }
397 1.1 jmcneill
398 1.9 jmcneill void
399 1.9 jmcneill command_reset(char *arg)
400 1.9 jmcneill {
401 1.9 jmcneill efi_reboot();
402 1.9 jmcneill }
403 1.9 jmcneill
404 1.39 jmcneill void
405 1.39 jmcneill command_setup(char *arg)
406 1.39 jmcneill {
407 1.39 jmcneill EFI_STATUS status;
408 1.39 jmcneill const UINT64 *osindsup;
409 1.39 jmcneill UINT64 osind;
410 1.39 jmcneill
411 1.39 jmcneill osindsup = LibGetVariable(L"OsIndicationsSupported", &EfiGlobalVariable);
412 1.39 jmcneill if (osindsup == NULL || (*osindsup & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) == 0) {
413 1.39 jmcneill printf("Not supported by firmware\n");
414 1.39 jmcneill return;
415 1.39 jmcneill }
416 1.39 jmcneill
417 1.39 jmcneill osind = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
418 1.39 jmcneill status = LibSetNVVariable(L"OsIndications", &EfiGlobalVariable, sizeof(osind), &osind);
419 1.39 jmcneill if (EFI_ERROR(status)) {
420 1.39 jmcneill printf("Failed to set OsIndications variable: %lu\n", (u_long)status);
421 1.39 jmcneill return;
422 1.39 jmcneill }
423 1.39 jmcneill
424 1.39 jmcneill efi_reboot();
425 1.39 jmcneill }
426 1.39 jmcneill
427 1.3 jmcneill int
428 1.11 mrg set_default_device(const char *arg)
429 1.3 jmcneill {
430 1.3 jmcneill if (strlen(arg) + 1 > sizeof(default_device))
431 1.3 jmcneill return ERANGE;
432 1.3 jmcneill strcpy(default_device, arg);
433 1.3 jmcneill return 0;
434 1.3 jmcneill }
435 1.3 jmcneill
436 1.3 jmcneill char *
437 1.3 jmcneill get_default_device(void)
438 1.3 jmcneill {
439 1.3 jmcneill return default_device;
440 1.3 jmcneill }
441 1.3 jmcneill
442 1.28 jmcneill void
443 1.28 jmcneill set_default_fstype(int fstype)
444 1.28 jmcneill {
445 1.28 jmcneill default_fstype = fstype;
446 1.28 jmcneill }
447 1.28 jmcneill
448 1.28 jmcneill int
449 1.28 jmcneill get_default_fstype(void)
450 1.28 jmcneill {
451 1.28 jmcneill return default_fstype;
452 1.28 jmcneill }
453 1.28 jmcneill
454 1.6 jmcneill int
455 1.11 mrg set_initrd_path(const char *arg)
456 1.6 jmcneill {
457 1.6 jmcneill if (strlen(arg) + 1 > sizeof(initrd_path))
458 1.6 jmcneill return ERANGE;
459 1.6 jmcneill strcpy(initrd_path, arg);
460 1.6 jmcneill return 0;
461 1.6 jmcneill }
462 1.6 jmcneill
463 1.6 jmcneill char *
464 1.6 jmcneill get_initrd_path(void)
465 1.6 jmcneill {
466 1.6 jmcneill return initrd_path;
467 1.6 jmcneill }
468 1.6 jmcneill
469 1.7 jmcneill int
470 1.11 mrg set_dtb_path(const char *arg)
471 1.7 jmcneill {
472 1.7 jmcneill if (strlen(arg) + 1 > sizeof(dtb_path))
473 1.7 jmcneill return ERANGE;
474 1.7 jmcneill strcpy(dtb_path, arg);
475 1.7 jmcneill return 0;
476 1.7 jmcneill }
477 1.7 jmcneill
478 1.7 jmcneill char *
479 1.7 jmcneill get_dtb_path(void)
480 1.7 jmcneill {
481 1.7 jmcneill return dtb_path;
482 1.7 jmcneill }
483 1.7 jmcneill
484 1.11 mrg int
485 1.19 riastrad set_rndseed_path(const char *arg)
486 1.19 riastrad {
487 1.19 riastrad if (strlen(arg) + 1 > sizeof(rndseed_path))
488 1.19 riastrad return ERANGE;
489 1.19 riastrad strcpy(rndseed_path, arg);
490 1.19 riastrad return 0;
491 1.19 riastrad }
492 1.19 riastrad
493 1.19 riastrad char *
494 1.19 riastrad get_rndseed_path(void)
495 1.19 riastrad {
496 1.19 riastrad return rndseed_path;
497 1.19 riastrad }
498 1.19 riastrad
499 1.19 riastrad int
500 1.11 mrg set_bootfile(const char *arg)
501 1.11 mrg {
502 1.14 jmcneill if (strlen(arg) + 1 > sizeof(netbsd_path))
503 1.11 mrg return ERANGE;
504 1.14 jmcneill strcpy(netbsd_path, arg);
505 1.11 mrg return 0;
506 1.11 mrg }
507 1.11 mrg
508 1.15 skrll int
509 1.15 skrll set_bootargs(const char *arg)
510 1.15 skrll {
511 1.15 skrll if (strlen(arg) + 1 > sizeof(netbsd_args))
512 1.15 skrll return ERANGE;
513 1.15 skrll strcpy(netbsd_args, arg);
514 1.15 skrll return 0;
515 1.15 skrll }
516 1.15 skrll
517 1.1 jmcneill void
518 1.1 jmcneill boot(void)
519 1.1 jmcneill {
520 1.25 jmcneill char pathbuf[80];
521 1.1 jmcneill int currname, c;
522 1.1 jmcneill
523 1.28 jmcneill if (bootcfg_path(pathbuf, sizeof(pathbuf)) == 0) {
524 1.25 jmcneill twiddle_toggle = 1;
525 1.25 jmcneill parsebootconf(pathbuf);
526 1.25 jmcneill }
527 1.23 jmcneill
528 1.23 jmcneill if (bootcfg_info.clear)
529 1.23 jmcneill uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
530 1.23 jmcneill
531 1.36 nia print_bootcfg_banner(bootprog_name, bootprog_rev);
532 1.23 jmcneill
533 1.23 jmcneill /* Display menu if configured */
534 1.23 jmcneill if (bootcfg_info.nummenu > 0) {
535 1.23 jmcneill doboottypemenu(); /* No return */
536 1.23 jmcneill }
537 1.23 jmcneill
538 1.11 mrg printf("Press return to boot now, any other key for boot prompt\n");
539 1.1 jmcneill
540 1.14 jmcneill if (netbsd_path[0] != '\0')
541 1.11 mrg currname = -1;
542 1.11 mrg else
543 1.11 mrg currname = 0;
544 1.11 mrg
545 1.12 mrg for (; currname < (int)NUMNAMES; currname++) {
546 1.11 mrg if (currname >= 0)
547 1.11 mrg set_bootfile(names[currname]);
548 1.16 skrll printf("booting %s%s%s - starting in ", netbsd_path,
549 1.16 skrll netbsd_args[0] != '\0' ? " " : "", netbsd_args);
550 1.1 jmcneill
551 1.40 jmcneill c = awaitkey(bootcfg_info.timeout, 1);
552 1.11 mrg if (c != '\r' && c != '\n' && c != '\0')
553 1.1 jmcneill bootprompt(); /* does not return */
554 1.1 jmcneill
555 1.32 jmcneill efi_block_set_readahead(true);
556 1.15 skrll exec_netbsd(netbsd_path, netbsd_args);
557 1.32 jmcneill efi_block_set_readahead(false);
558 1.1 jmcneill }
559 1.1 jmcneill
560 1.1 jmcneill bootprompt(); /* does not return */
561 1.1 jmcneill }
562