Wed Jun 14 00:42:21 2023 UTC ()
Add missing member for terminating sentinel.


(rin)
diff -r1.44 -r1.45 src/sys/stand/efiboot/boot.c

cvs diff -r1.44 -r1.45 src/sys/stand/efiboot/boot.c (switch to unified diff)

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