boot.c revision 1.2.2.2 1 1.2.2.2 skrll /* $NetBSD: boot.c,v 1.2.2.2 2017/02/05 13:40:12 skrll Exp $ */
2 1.2.2.2 skrll
3 1.2.2.2 skrll /*-
4 1.2.2.2 skrll * Copyright (c) 2016 Kimihiro Nonaka <nonaka (at) netbsd.org>
5 1.2.2.2 skrll * All rights reserved.
6 1.2.2.2 skrll *
7 1.2.2.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.2.2.2 skrll * modification, are permitted provided that the following conditions
9 1.2.2.2 skrll * are met:
10 1.2.2.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.2.2.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.2.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.2.2 skrll * notice, this list of conditions and the following disclaimer in the
14 1.2.2.2 skrll * documentation and/or other materials provided with the distribution.
15 1.2.2.2 skrll *
16 1.2.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 1.2.2.2 skrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.2.2.2 skrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.2.2.2 skrll * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 1.2.2.2 skrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.2.2.2 skrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.2.2.2 skrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.2.2.2 skrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.2.2.2 skrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.2.2.2 skrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.2.2.2 skrll * SUCH DAMAGE.
27 1.2.2.2 skrll */
28 1.2.2.2 skrll
29 1.2.2.2 skrll #include "efiboot.h"
30 1.2.2.2 skrll
31 1.2.2.2 skrll #include <sys/bootblock.h>
32 1.2.2.2 skrll #include <sys/boot_flag.h>
33 1.2.2.2 skrll
34 1.2.2.2 skrll #include <lib/libsa/bootcfg.h>
35 1.2.2.2 skrll
36 1.2.2.2 skrll #include <bootmod.h>
37 1.2.2.2 skrll #include <bootmenu.h>
38 1.2.2.2 skrll #include "devopen.h"
39 1.2.2.2 skrll
40 1.2.2.2 skrll int errno;
41 1.2.2.2 skrll int boot_biosdev;
42 1.2.2.2 skrll daddr_t boot_biossector;
43 1.2.2.2 skrll
44 1.2.2.2 skrll extern const char bootprog_name[], bootprog_rev[], bootprog_kernrev[];
45 1.2.2.2 skrll
46 1.2.2.2 skrll extern struct x86_boot_params boot_params;
47 1.2.2.2 skrll extern char twiddle_toggle;
48 1.2.2.2 skrll
49 1.2.2.2 skrll static const char * const names[][2] = {
50 1.2.2.2 skrll { "netbsd", "netbsd.gz" },
51 1.2.2.2 skrll { "onetbsd", "onetbsd.gz" },
52 1.2.2.2 skrll { "netbsd.old", "netbsd.old.gz" },
53 1.2.2.2 skrll };
54 1.2.2.2 skrll
55 1.2.2.2 skrll #define NUMNAMES __arraycount(names)
56 1.2.2.2 skrll #define DEFFILENAME names[0][0]
57 1.2.2.2 skrll
58 1.2.2.2 skrll #define MAXDEVNAME 16
59 1.2.2.2 skrll
60 1.2.2.2 skrll void command_help(char *);
61 1.2.2.2 skrll void command_quit(char *);
62 1.2.2.2 skrll void command_boot(char *);
63 1.2.2.2 skrll void command_consdev(char *);
64 1.2.2.2 skrll void command_dev(char *);
65 1.2.2.2 skrll void command_devpath(char *);
66 1.2.2.2 skrll void command_efivar(char *);
67 1.2.2.2 skrll void command_gop(char *);
68 1.2.2.2 skrll #if LIBSA_ENABLE_LS_OP
69 1.2.2.2 skrll void command_ls(char *);
70 1.2.2.2 skrll #endif
71 1.2.2.2 skrll void command_memmap(char *);
72 1.2.2.2 skrll #ifndef SMALL
73 1.2.2.2 skrll void command_menu(char *);
74 1.2.2.2 skrll #endif
75 1.2.2.2 skrll void command_modules(char *);
76 1.2.2.2 skrll void command_multiboot(char *);
77 1.2.2.2 skrll void command_text(char *);
78 1.2.2.2 skrll void command_version(char *);
79 1.2.2.2 skrll
80 1.2.2.2 skrll const struct bootblk_command commands[] = {
81 1.2.2.2 skrll { "help", command_help },
82 1.2.2.2 skrll { "?", command_help },
83 1.2.2.2 skrll { "quit", command_quit },
84 1.2.2.2 skrll { "boot", command_boot },
85 1.2.2.2 skrll { "consdev", command_consdev },
86 1.2.2.2 skrll { "dev", command_dev },
87 1.2.2.2 skrll { "devpath", command_devpath },
88 1.2.2.2 skrll { "efivar", command_efivar },
89 1.2.2.2 skrll { "fs", fs_add },
90 1.2.2.2 skrll { "gop", command_gop },
91 1.2.2.2 skrll { "load", module_add },
92 1.2.2.2 skrll #if LIBSA_ENABLE_LS_OP
93 1.2.2.2 skrll { "ls", command_ls },
94 1.2.2.2 skrll #endif
95 1.2.2.2 skrll { "memmap", command_memmap },
96 1.2.2.2 skrll #ifndef SMALL
97 1.2.2.2 skrll { "menu", command_menu },
98 1.2.2.2 skrll #endif
99 1.2.2.2 skrll { "modules", command_modules },
100 1.2.2.2 skrll { "multiboot", command_multiboot },
101 1.2.2.2 skrll { "rndseed", rnd_add },
102 1.2.2.2 skrll { "splash", splash_add },
103 1.2.2.2 skrll { "text", command_text },
104 1.2.2.2 skrll { "userconf", userconf_add },
105 1.2.2.2 skrll { "version", command_version },
106 1.2.2.2 skrll { NULL, NULL },
107 1.2.2.2 skrll };
108 1.2.2.2 skrll
109 1.2.2.2 skrll static char *default_devname;
110 1.2.2.2 skrll static int default_unit, default_partition;
111 1.2.2.2 skrll static const char *default_filename;
112 1.2.2.2 skrll
113 1.2.2.2 skrll static char *sprint_bootsel(const char *);
114 1.2.2.2 skrll static void bootit(const char *, int);
115 1.2.2.2 skrll
116 1.2.2.2 skrll int
117 1.2.2.2 skrll parsebootfile(const char *fname, char **fsname, char **devname, int *unit,
118 1.2.2.2 skrll int *partition, const char **file)
119 1.2.2.2 skrll {
120 1.2.2.2 skrll const char *col;
121 1.2.2.2 skrll
122 1.2.2.2 skrll *fsname = "ufs";
123 1.2.2.2 skrll *devname = default_devname;
124 1.2.2.2 skrll *unit = default_unit;
125 1.2.2.2 skrll *partition = default_partition;
126 1.2.2.2 skrll *file = default_filename;
127 1.2.2.2 skrll
128 1.2.2.2 skrll if (fname == NULL)
129 1.2.2.2 skrll return 0;
130 1.2.2.2 skrll
131 1.2.2.2 skrll if ((col = strchr(fname, ':')) != NULL) { /* device given */
132 1.2.2.2 skrll static char savedevname[MAXDEVNAME+1];
133 1.2.2.2 skrll int devlen;
134 1.2.2.2 skrll int u = 0, p = 0;
135 1.2.2.2 skrll int i = 0;
136 1.2.2.2 skrll
137 1.2.2.2 skrll devlen = col - fname;
138 1.2.2.2 skrll if (devlen > MAXDEVNAME)
139 1.2.2.2 skrll return EINVAL;
140 1.2.2.2 skrll
141 1.2.2.2 skrll #define isvalidname(c) ((c) >= 'a' && (c) <= 'z')
142 1.2.2.2 skrll if (!isvalidname(fname[i]))
143 1.2.2.2 skrll return EINVAL;
144 1.2.2.2 skrll do {
145 1.2.2.2 skrll savedevname[i] = fname[i];
146 1.2.2.2 skrll i++;
147 1.2.2.2 skrll } while (isvalidname(fname[i]));
148 1.2.2.2 skrll savedevname[i] = '\0';
149 1.2.2.2 skrll
150 1.2.2.2 skrll #define isnum(c) ((c) >= '0' && (c) <= '9')
151 1.2.2.2 skrll if (i < devlen) {
152 1.2.2.2 skrll if (!isnum(fname[i]))
153 1.2.2.2 skrll return EUNIT;
154 1.2.2.2 skrll do {
155 1.2.2.2 skrll u *= 10;
156 1.2.2.2 skrll u += fname[i++] - '0';
157 1.2.2.2 skrll } while (isnum(fname[i]));
158 1.2.2.2 skrll }
159 1.2.2.2 skrll
160 1.2.2.2 skrll #define isvalidpart(c) ((c) >= 'a' && (c) <= 'z')
161 1.2.2.2 skrll if (i < devlen) {
162 1.2.2.2 skrll if (!isvalidpart(fname[i]))
163 1.2.2.2 skrll return EPART;
164 1.2.2.2 skrll p = fname[i++] - 'a';
165 1.2.2.2 skrll }
166 1.2.2.2 skrll
167 1.2.2.2 skrll if (i != devlen)
168 1.2.2.2 skrll return ENXIO;
169 1.2.2.2 skrll
170 1.2.2.2 skrll *devname = savedevname;
171 1.2.2.2 skrll *unit = u;
172 1.2.2.2 skrll *partition = p;
173 1.2.2.2 skrll fname = col + 1;
174 1.2.2.2 skrll }
175 1.2.2.2 skrll
176 1.2.2.2 skrll if (*fname)
177 1.2.2.2 skrll *file = fname;
178 1.2.2.2 skrll
179 1.2.2.2 skrll return 0;
180 1.2.2.2 skrll }
181 1.2.2.2 skrll
182 1.2.2.2 skrll static char *
183 1.2.2.2 skrll sprint_bootsel(const char *filename)
184 1.2.2.2 skrll {
185 1.2.2.2 skrll char *fsname, *devname;
186 1.2.2.2 skrll int unit, partition;
187 1.2.2.2 skrll const char *file;
188 1.2.2.2 skrll static char buf[80];
189 1.2.2.2 skrll
190 1.2.2.2 skrll if (parsebootfile(filename, &fsname, &devname, &unit,
191 1.2.2.2 skrll &partition, &file) == 0) {
192 1.2.2.2 skrll snprintf(buf, sizeof(buf), "%s%d%c:%s", devname, unit,
193 1.2.2.2 skrll 'a' + partition, file);
194 1.2.2.2 skrll return buf;
195 1.2.2.2 skrll }
196 1.2.2.2 skrll return "(invalid)";
197 1.2.2.2 skrll }
198 1.2.2.2 skrll
199 1.2.2.2 skrll void
200 1.2.2.2 skrll clearit(void)
201 1.2.2.2 skrll {
202 1.2.2.2 skrll
203 1.2.2.2 skrll if (bootcfg_info.clear)
204 1.2.2.2 skrll clear_pc_screen();
205 1.2.2.2 skrll }
206 1.2.2.2 skrll
207 1.2.2.2 skrll static void
208 1.2.2.2 skrll bootit(const char *filename, int howto)
209 1.2.2.2 skrll {
210 1.2.2.2 skrll
211 1.2.2.2 skrll if (howto & AB_VERBOSE)
212 1.2.2.2 skrll printf("booting %s (howto 0x%x)\n", sprint_bootsel(filename),
213 1.2.2.2 skrll howto);
214 1.2.2.2 skrll
215 1.2.2.2 skrll if (exec_netbsd(filename, 0, howto, 0, efi_cleanup) < 0)
216 1.2.2.2 skrll printf("boot: %s: %s\n", sprint_bootsel(filename),
217 1.2.2.2 skrll strerror(errno));
218 1.2.2.2 skrll else
219 1.2.2.2 skrll printf("boot returned\n");
220 1.2.2.2 skrll }
221 1.2.2.2 skrll
222 1.2.2.2 skrll void
223 1.2.2.2 skrll print_banner(void)
224 1.2.2.2 skrll {
225 1.2.2.2 skrll int n;
226 1.2.2.2 skrll
227 1.2.2.2 skrll clearit();
228 1.2.2.2 skrll if (bootcfg_info.banner[0]) {
229 1.2.2.2 skrll for (n = 0; n < BOOTCFG_MAXBANNER && bootcfg_info.banner[n];
230 1.2.2.2 skrll n++)
231 1.2.2.2 skrll printf("%s\n", bootcfg_info.banner[n]);
232 1.2.2.2 skrll } else
233 1.2.2.2 skrll command_version("short");
234 1.2.2.2 skrll }
235 1.2.2.2 skrll
236 1.2.2.2 skrll void
237 1.2.2.2 skrll boot(void)
238 1.2.2.2 skrll {
239 1.2.2.2 skrll int currname;
240 1.2.2.2 skrll int c;
241 1.2.2.2 skrll
242 1.2.2.2 skrll boot_modules_enabled = !(boot_params.bp_flags & X86_BP_FLAGS_NOMODULES);
243 1.2.2.2 skrll
244 1.2.2.2 skrll /* try to set default device to what BIOS tells us */
245 1.2.2.2 skrll bios2dev(boot_biosdev, boot_biossector, &default_devname, &default_unit,
246 1.2.2.2 skrll &default_partition);
247 1.2.2.2 skrll
248 1.2.2.2 skrll /* if the user types "boot" without filename */
249 1.2.2.2 skrll default_filename = DEFFILENAME;
250 1.2.2.2 skrll
251 1.2.2.2 skrll if (!(boot_params.bp_flags & X86_BP_FLAGS_NOBOOTCONF)) {
252 1.2.2.2 skrll parsebootconf(BOOTCFG_FILENAME);
253 1.2.2.2 skrll } else {
254 1.2.2.2 skrll bootcfg_info.timeout = boot_params.bp_timeout;
255 1.2.2.2 skrll }
256 1.2.2.2 skrll
257 1.2.2.2 skrll /*
258 1.2.2.2 skrll * If console set in boot.cfg, switch to it.
259 1.2.2.2 skrll * This will print the banner, so we don't need to explicitly do it
260 1.2.2.2 skrll */
261 1.2.2.2 skrll if (bootcfg_info.consdev)
262 1.2.2.2 skrll command_consdev(bootcfg_info.consdev);
263 1.2.2.2 skrll else
264 1.2.2.2 skrll print_banner();
265 1.2.2.2 skrll
266 1.2.2.2 skrll /* Display the menu, if applicable */
267 1.2.2.2 skrll twiddle_toggle = 0;
268 1.2.2.2 skrll if (bootcfg_info.nummenu > 0) {
269 1.2.2.2 skrll /* Does not return */
270 1.2.2.2 skrll doboottypemenu();
271 1.2.2.2 skrll }
272 1.2.2.2 skrll
273 1.2.2.2 skrll printf("Press return to boot now, any other key for boot menu\n");
274 1.2.2.2 skrll for (currname = 0; currname < NUMNAMES; currname++) {
275 1.2.2.2 skrll printf("booting %s - starting in ",
276 1.2.2.2 skrll sprint_bootsel(names[currname][0]));
277 1.2.2.2 skrll
278 1.2.2.2 skrll c = awaitkey((bootcfg_info.timeout < 0) ? 0
279 1.2.2.2 skrll : bootcfg_info.timeout, 1);
280 1.2.2.2 skrll if ((c != '\r') && (c != '\n') && (c != '\0')) {
281 1.2.2.2 skrll if ((boot_params.bp_flags & X86_BP_FLAGS_PASSWORD) == 0) {
282 1.2.2.2 skrll /* do NOT ask for password */
283 1.2.2.2 skrll bootmenu(); /* does not return */
284 1.2.2.2 skrll } else {
285 1.2.2.2 skrll /* DO ask for password */
286 1.2.2.2 skrll if (check_password((char *)boot_params.bp_password)) {
287 1.2.2.2 skrll /* password ok */
288 1.2.2.2 skrll printf("type \"?\" or \"help\" for help.\n");
289 1.2.2.2 skrll bootmenu(); /* does not return */
290 1.2.2.2 skrll } else {
291 1.2.2.2 skrll /* bad password */
292 1.2.2.2 skrll printf("Wrong password.\n");
293 1.2.2.2 skrll currname = 0;
294 1.2.2.2 skrll continue;
295 1.2.2.2 skrll }
296 1.2.2.2 skrll }
297 1.2.2.2 skrll }
298 1.2.2.2 skrll
299 1.2.2.2 skrll /*
300 1.2.2.2 skrll * try pairs of names[] entries, foo and foo.gz
301 1.2.2.2 skrll */
302 1.2.2.2 skrll /* don't print "booting..." again */
303 1.2.2.2 skrll bootit(names[currname][0], 0);
304 1.2.2.2 skrll /* since it failed, try compressed bootfile. */
305 1.2.2.2 skrll bootit(names[currname][1], AB_VERBOSE);
306 1.2.2.2 skrll }
307 1.2.2.2 skrll
308 1.2.2.2 skrll bootmenu(); /* does not return */
309 1.2.2.2 skrll }
310 1.2.2.2 skrll
311 1.2.2.2 skrll /* ARGSUSED */
312 1.2.2.2 skrll void
313 1.2.2.2 skrll command_help(char *arg)
314 1.2.2.2 skrll {
315 1.2.2.2 skrll
316 1.2.2.2 skrll printf("commands are:\n"
317 1.2.2.2 skrll "boot [xdNx:][filename] [-12acdqsvxz]\n"
318 1.2.2.2 skrll " (ex. \"hd0a:netbsd.old -s\"\n"
319 1.2.2.2 skrll "dev [xd[N[x]]:]\n"
320 1.2.2.2 skrll "consdev {pc|com[0123]|com[0123]kbd|auto}\n"
321 1.2.2.2 skrll "devpath\n"
322 1.2.2.2 skrll "efivar\n"
323 1.2.2.2 skrll "gop [{modenum|list}]\n"
324 1.2.2.2 skrll "load {path_to_module}\n"
325 1.2.2.2 skrll #if LIBSA_ENABLE_LS_OP
326 1.2.2.2 skrll "ls [path]\n"
327 1.2.2.2 skrll #endif
328 1.2.2.2 skrll "memmap [{sorted|unsorted}]\n"
329 1.2.2.2 skrll #ifndef SMALL
330 1.2.2.2 skrll "menu (reenters boot menu, if defined in boot.cfg)\n"
331 1.2.2.2 skrll #endif
332 1.2.2.2 skrll "modules {on|off|enabled|disabled}\n"
333 1.2.2.2 skrll "multiboot [xdNx:][filename] [<args>]\n"
334 1.2.2.2 skrll "rndseed {path_to_rndseed_file}\n"
335 1.2.2.2 skrll "splash {path_to_image_file}\n"
336 1.2.2.2 skrll "text [{modenum|list}]\n"
337 1.2.2.2 skrll "userconf {command}\n"
338 1.2.2.2 skrll "version\n"
339 1.2.2.2 skrll "help|?\n"
340 1.2.2.2 skrll "quit\n");
341 1.2.2.2 skrll }
342 1.2.2.2 skrll
343 1.2.2.2 skrll #if LIBSA_ENABLE_LS_OP
344 1.2.2.2 skrll void
345 1.2.2.2 skrll command_ls(char *arg)
346 1.2.2.2 skrll {
347 1.2.2.2 skrll const char *save = default_filename;
348 1.2.2.2 skrll
349 1.2.2.2 skrll default_filename = "/";
350 1.2.2.2 skrll ls(arg);
351 1.2.2.2 skrll default_filename = save;
352 1.2.2.2 skrll }
353 1.2.2.2 skrll #endif
354 1.2.2.2 skrll
355 1.2.2.2 skrll /* ARGSUSED */
356 1.2.2.2 skrll void
357 1.2.2.2 skrll command_quit(char *arg)
358 1.2.2.2 skrll {
359 1.2.2.2 skrll
360 1.2.2.2 skrll printf("Exiting...\n");
361 1.2.2.2 skrll delay(1 * 1000 * 1000);
362 1.2.2.2 skrll reboot();
363 1.2.2.2 skrll /* Note: we shouldn't get to this point! */
364 1.2.2.2 skrll panic("Could not reboot!");
365 1.2.2.2 skrll }
366 1.2.2.2 skrll
367 1.2.2.2 skrll void
368 1.2.2.2 skrll command_boot(char *arg)
369 1.2.2.2 skrll {
370 1.2.2.2 skrll char *filename;
371 1.2.2.2 skrll int howto;
372 1.2.2.2 skrll
373 1.2.2.2 skrll if (!parseboot(arg, &filename, &howto))
374 1.2.2.2 skrll return;
375 1.2.2.2 skrll
376 1.2.2.2 skrll if (filename != NULL) {
377 1.2.2.2 skrll bootit(filename, howto);
378 1.2.2.2 skrll } else {
379 1.2.2.2 skrll int i;
380 1.2.2.2 skrll
381 1.2.2.2 skrll if (howto == 0)
382 1.2.2.2 skrll bootdefault();
383 1.2.2.2 skrll for (i = 0; i < NUMNAMES; i++) {
384 1.2.2.2 skrll bootit(names[i][0], howto);
385 1.2.2.2 skrll bootit(names[i][1], howto);
386 1.2.2.2 skrll }
387 1.2.2.2 skrll }
388 1.2.2.2 skrll }
389 1.2.2.2 skrll
390 1.2.2.2 skrll void
391 1.2.2.2 skrll command_dev(char *arg)
392 1.2.2.2 skrll {
393 1.2.2.2 skrll static char savedevname[MAXDEVNAME + 1];
394 1.2.2.2 skrll char *fsname, *devname;
395 1.2.2.2 skrll const char *file; /* dummy */
396 1.2.2.2 skrll
397 1.2.2.2 skrll if (*arg == '\0') {
398 1.2.2.2 skrll biosdisk_probe();
399 1.2.2.2 skrll printf("default %s%d%c\n", default_devname, default_unit,
400 1.2.2.2 skrll 'a' + default_partition);
401 1.2.2.2 skrll return;
402 1.2.2.2 skrll }
403 1.2.2.2 skrll
404 1.2.2.2 skrll if (strchr(arg, ':') == NULL ||
405 1.2.2.2 skrll parsebootfile(arg, &fsname, &devname, &default_unit,
406 1.2.2.2 skrll &default_partition, &file)) {
407 1.2.2.2 skrll command_help(NULL);
408 1.2.2.2 skrll return;
409 1.2.2.2 skrll }
410 1.2.2.2 skrll
411 1.2.2.2 skrll /* put to own static storage */
412 1.2.2.2 skrll strncpy(savedevname, devname, MAXDEVNAME + 1);
413 1.2.2.2 skrll default_devname = savedevname;
414 1.2.2.2 skrll }
415 1.2.2.2 skrll
416 1.2.2.2 skrll /* ARGSUSED */
417 1.2.2.2 skrll void
418 1.2.2.2 skrll command_consdev(char *arg)
419 1.2.2.2 skrll {
420 1.2.2.2 skrll
421 1.2.2.2 skrll /* XXX not implemented yet */
422 1.2.2.2 skrll }
423 1.2.2.2 skrll
424 1.2.2.2 skrll #ifndef SMALL
425 1.2.2.2 skrll /* ARGSUSED */
426 1.2.2.2 skrll void
427 1.2.2.2 skrll command_menu(char *arg)
428 1.2.2.2 skrll {
429 1.2.2.2 skrll
430 1.2.2.2 skrll if (bootcfg_info.nummenu > 0) {
431 1.2.2.2 skrll /* Does not return */
432 1.2.2.2 skrll doboottypemenu();
433 1.2.2.2 skrll } else
434 1.2.2.2 skrll printf("No menu defined in boot.cfg\n");
435 1.2.2.2 skrll }
436 1.2.2.2 skrll #endif /* !SMALL */
437 1.2.2.2 skrll
438 1.2.2.2 skrll void
439 1.2.2.2 skrll command_modules(char *arg)
440 1.2.2.2 skrll {
441 1.2.2.2 skrll
442 1.2.2.2 skrll if (strcmp(arg, "enabled") == 0 ||
443 1.2.2.2 skrll strcmp(arg, "on") == 0)
444 1.2.2.2 skrll boot_modules_enabled = true;
445 1.2.2.2 skrll else if (strcmp(arg, "disabled") == 0 ||
446 1.2.2.2 skrll strcmp(arg, "off") == 0)
447 1.2.2.2 skrll boot_modules_enabled = false;
448 1.2.2.2 skrll else
449 1.2.2.2 skrll printf("invalid flag, must be 'enabled' or 'disabled'.\n");
450 1.2.2.2 skrll }
451 1.2.2.2 skrll
452 1.2.2.2 skrll void
453 1.2.2.2 skrll command_multiboot(char *arg)
454 1.2.2.2 skrll {
455 1.2.2.2 skrll char *filename;
456 1.2.2.2 skrll
457 1.2.2.2 skrll filename = arg;
458 1.2.2.2 skrll if (exec_multiboot(filename, gettrailer(arg)) < 0)
459 1.2.2.2 skrll printf("multiboot: %s: %s\n", sprint_bootsel(filename),
460 1.2.2.2 skrll strerror(errno));
461 1.2.2.2 skrll else
462 1.2.2.2 skrll printf("boot returned\n");
463 1.2.2.2 skrll }
464 1.2.2.2 skrll
465 1.2.2.2 skrll void
466 1.2.2.2 skrll command_version(char *arg)
467 1.2.2.2 skrll {
468 1.2.2.2 skrll
469 1.2.2.2 skrll if (strcmp(arg, "full") == 0) {
470 1.2.2.2 skrll printf("ImageBase: 0x%" PRIxPTR "\n",
471 1.2.2.2 skrll (uintptr_t)efi_li->ImageBase);
472 1.2.2.2 skrll printf("Stack: 0x%" PRIxPTR "\n", efi_main_sp);
473 1.2.2.2 skrll printf("EFI version: %d.%02d\n",
474 1.2.2.2 skrll ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
475 1.2.2.2 skrll Print(L"EFI Firmware: %s (rev %d.%02d)\n", ST->FirmwareVendor,
476 1.2.2.2 skrll ST->FirmwareRevision >> 16, ST->FirmwareRevision & 0xffff);
477 1.2.2.2 skrll }
478 1.2.2.2 skrll
479 1.2.2.2 skrll printf("\n"
480 1.2.2.2 skrll ">> %s, Revision %s (from NetBSD %s)\n"
481 1.2.2.2 skrll ">> Memory: %d/%d k\n",
482 1.2.2.2 skrll bootprog_name, bootprog_rev, bootprog_kernrev,
483 1.2.2.2 skrll getbasemem(), getextmem());
484 1.2.2.2 skrll }
485 1.2.2.2 skrll
486 1.2.2.2 skrll void
487 1.2.2.2 skrll command_memmap(char *arg)
488 1.2.2.2 skrll {
489 1.2.2.2 skrll bool sorted = true;
490 1.2.2.2 skrll
491 1.2.2.2 skrll if (*arg == '\0' || strcmp(arg, "sorted") == 0)
492 1.2.2.2 skrll /* Already sorted is true. */;
493 1.2.2.2 skrll else if (strcmp(arg, "unsorted") == 0)
494 1.2.2.2 skrll sorted = false;
495 1.2.2.2 skrll else {
496 1.2.2.2 skrll printf("invalid flag, "
497 1.2.2.2 skrll "must be 'sorted' or 'unsorted'.\n");
498 1.2.2.2 skrll return;
499 1.2.2.2 skrll }
500 1.2.2.2 skrll
501 1.2.2.2 skrll efi_memory_show_map(sorted);
502 1.2.2.2 skrll }
503 1.2.2.2 skrll
504 1.2.2.2 skrll void
505 1.2.2.2 skrll command_devpath(char *arg)
506 1.2.2.2 skrll {
507 1.2.2.2 skrll EFI_STATUS status;
508 1.2.2.2 skrll UINTN i, nhandles;
509 1.2.2.2 skrll EFI_HANDLE *handles;
510 1.2.2.2 skrll EFI_DEVICE_PATH *dp0, *dp;
511 1.2.2.2 skrll CHAR16 *path;
512 1.2.2.2 skrll UINTN cols, rows, row = 0;
513 1.2.2.2 skrll
514 1.2.2.2 skrll status = uefi_call_wrapper(ST->ConOut->QueryMode, 4, ST->ConOut,
515 1.2.2.2 skrll ST->ConOut->Mode->Mode, &cols, &rows);
516 1.2.2.2 skrll if (EFI_ERROR(status) || rows <= 2)
517 1.2.2.2 skrll rows = 0;
518 1.2.2.2 skrll else
519 1.2.2.2 skrll rows -= 2;
520 1.2.2.2 skrll
521 1.2.2.2 skrll /*
522 1.2.2.2 skrll * all devices.
523 1.2.2.2 skrll */
524 1.2.2.2 skrll status = LibLocateHandle(ByProtocol, &DevicePathProtocol, NULL,
525 1.2.2.2 skrll &nhandles, &handles);
526 1.2.2.2 skrll if (EFI_ERROR(status))
527 1.2.2.2 skrll return;
528 1.2.2.2 skrll
529 1.2.2.2 skrll for (i = 0; i < nhandles; i++) {
530 1.2.2.2 skrll status = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i],
531 1.2.2.2 skrll &DevicePathProtocol, (void **)&dp0);
532 1.2.2.2 skrll if (EFI_ERROR(status))
533 1.2.2.2 skrll break;
534 1.2.2.2 skrll
535 1.2.2.2 skrll Print(L"DevicePathType %d\n", DevicePathType(dp0));
536 1.2.2.2 skrll for (dp = dp0;
537 1.2.2.2 skrll !IsDevicePathEnd(dp);
538 1.2.2.2 skrll dp = NextDevicePathNode(dp)) {
539 1.2.2.2 skrll path = DevicePathToStr(dp);
540 1.2.2.2 skrll Print(L"%d:%d:%s\n", DevicePathType(dp), DevicePathSubType(dp), path);
541 1.2.2.2 skrll FreePool(path);
542 1.2.2.2 skrll
543 1.2.2.2 skrll if (++row >= rows) {
544 1.2.2.2 skrll row = 0;
545 1.2.2.2 skrll Print(L"Press Any Key to continue :");
546 1.2.2.2 skrll (void) awaitkey(-1, 0);
547 1.2.2.2 skrll Print(L"\n");
548 1.2.2.2 skrll }
549 1.2.2.2 skrll }
550 1.2.2.2 skrll }
551 1.2.2.2 skrll }
552 1.2.2.2 skrll
553 1.2.2.2 skrll void
554 1.2.2.2 skrll command_efivar(char *arg)
555 1.2.2.2 skrll {
556 1.2.2.2 skrll static const CHAR16 header[] =
557 1.2.2.2 skrll L"GUID Variable Name Value\n"
558 1.2.2.2 skrll L"=================================== ==================== ========\n";
559 1.2.2.2 skrll EFI_STATUS status;
560 1.2.2.2 skrll UINTN sz = 64;
561 1.2.2.2 skrll CHAR16 *name = NULL, *tmp, *val;
562 1.2.2.2 skrll EFI_GUID vendor;
563 1.2.2.2 skrll UINTN cols, rows, row = 0;
564 1.2.2.2 skrll
565 1.2.2.2 skrll status = uefi_call_wrapper(ST->ConOut->QueryMode, 4, ST->ConOut,
566 1.2.2.2 skrll ST->ConOut->Mode->Mode, &cols, &rows);
567 1.2.2.2 skrll if (EFI_ERROR(status) || rows <= 2)
568 1.2.2.2 skrll rows = 0;
569 1.2.2.2 skrll else
570 1.2.2.2 skrll rows -= 2;
571 1.2.2.2 skrll
572 1.2.2.2 skrll name = AllocatePool(sz);
573 1.2.2.2 skrll if (name == NULL) {
574 1.2.2.2 skrll Print(L"memory allocation failed: %ld bytes\n",
575 1.2.2.2 skrll (UINT64)sz);
576 1.2.2.2 skrll return;
577 1.2.2.2 skrll }
578 1.2.2.2 skrll
579 1.2.2.2 skrll name[0] = 0;
580 1.2.2.2 skrll vendor = NullGuid;
581 1.2.2.2 skrll
582 1.2.2.2 skrll Print(L"%s", header);
583 1.2.2.2 skrll for (;;) {
584 1.2.2.2 skrll status = uefi_call_wrapper(RT->GetNextVariableName, 3,
585 1.2.2.2 skrll &sz, name, &vendor);
586 1.2.2.2 skrll if (EFI_ERROR(status)) {
587 1.2.2.2 skrll if (status == EFI_NOT_FOUND)
588 1.2.2.2 skrll break;
589 1.2.2.2 skrll if (status != EFI_BUFFER_TOO_SMALL) {
590 1.2.2.2 skrll Print(L"GetNextVariableName failed: %r\n",
591 1.2.2.2 skrll status);
592 1.2.2.2 skrll break;
593 1.2.2.2 skrll }
594 1.2.2.2 skrll
595 1.2.2.2 skrll tmp = AllocatePool(sz);
596 1.2.2.2 skrll if (tmp == NULL) {
597 1.2.2.2 skrll Print(L"memory allocation failed: %ld bytes\n",
598 1.2.2.2 skrll (UINT64)sz);
599 1.2.2.2 skrll break;
600 1.2.2.2 skrll }
601 1.2.2.2 skrll FreePool(name);
602 1.2.2.2 skrll name = tmp;
603 1.2.2.2 skrll }
604 1.2.2.2 skrll
605 1.2.2.2 skrll val = LibGetVariable(name, &vendor);
606 1.2.2.2 skrll Print(L"%.-35g %.-20s %s\n", &vendor, name,
607 1.2.2.2 skrll val ? val : L"(null)");
608 1.2.2.2 skrll FreePool(val);
609 1.2.2.2 skrll
610 1.2.2.2 skrll if (++row >= rows) {
611 1.2.2.2 skrll row = 0;
612 1.2.2.2 skrll Print(L"Press Any Key to continue :");
613 1.2.2.2 skrll (void) awaitkey(-1, 0);
614 1.2.2.2 skrll Print(L"\n");
615 1.2.2.2 skrll }
616 1.2.2.2 skrll }
617 1.2.2.2 skrll
618 1.2.2.2 skrll FreePool(name);
619 1.2.2.2 skrll }
620