2 * Copyright (C) 2001-2003 Hewlett-Packard Co.
3 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
5 * This file is part of the ELILO, the EFI Linux boot loader.
7 * ELILO is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * ELILO is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with ELILO; see the file COPYING. If not, write to the Free
19 * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 * Please check out the elilo.txt for complete documentation on how
23 * to use this program.
32 /* static is ugly but does the job here! */
33 static CHAR16 **alt_argv;
36 display_label_info(CHAR16 *name)
39 CHAR16 initrd_name[CMDLINE_MAXLEN];
40 CHAR16 vmcode_name[CMDLINE_MAXLEN];
41 CHAR16 options_tmp[CMDLINE_MAXLEN];
42 CHAR16 options[CMDLINE_MAXLEN];
43 CHAR16 kname[FILENAME_MAXLEN];
45 desc = find_description(name);
47 Print(L"desc : %s\n", desc);
50 initrd_name[0] = vmcode_name[0] = options_tmp[0] = kname[0] = CHAR_NULL;
52 if (find_label(name, kname, options_tmp, initrd_name, vmcode_name) == -1) {
56 subst_vars(options_tmp, options, CMDLINE_MAXLEN);
58 Print(L"cmdline: %s %s\n", kname, options);
59 if (initrd_name[0]) Print(L"initrd : %s\n", initrd_name);
60 if (vmcode_name[0]) Print(L"vmcode : %s\n", vmcode_name);
64 print_infos(int force)
67 CHAR16 dpath[FILENAME_MAXLEN];
68 CHAR16 *boot_dev_name;
71 boot_dev_name = fops_bootdev_name();
72 config_file = get_config_file();
74 fops_getdefault_path(dpath, FILENAME_MAXLEN);
76 if (force || elilo_opt.verbose > 0)
77 Print(L"default file path: %s:%s\n", boot_dev_name, dpath);
79 is_abs = config_file && (config_file[0] == CHAR_BACKSLASH || config_file[0] == CHAR_SLASH) ? 1 : 0;
81 if (force || elilo_opt.verbose > 0)
82 Print(L"config file : %s%s\n", config_file && is_abs == 0 ? dpath : L"", config_file ? config_file : L"none used");
85 CHAR16 **p = alt_argv;
86 Print(L"found alternate default choice :");
87 while (*p) Print(L" %s", *p++);
95 if (force || elilo_opt.verbose > 0)
96 Print(L"command list (must be first character):\n=:print device list, %%:print variable list, &:print paths, ?:help\nTAB:print label information\n");
100 * interactively select a kernel image and options.
101 * The kernel can be an actual filename or a label in the config file
107 select_kernel(CHAR16 *buffer, INTN size)
109 #define CHAR_CTRL_C L'\003' /* Unicode CTRL-C */
110 #define CHAR_CTRL_D L'\004' /* Unicode CTRL-D */
111 #define CHAR_CTRL_U L'\025' /* Unicode CTRL-U */
112 //#define CHAR_TAB L'\t'
113 SIMPLE_INPUT_INTERFACE *ip = systab->ConIn;
120 * let's give some help first
127 buffer[pos] = CHAR_NULL;
129 Print(L"\nELILO boot: %s", buffer);
131 * autoboot with default choice after timeout expires
133 if (first_time && (ret=wait_timeout(elilo_opt.timeout)) != 1) {
134 return ret == -1 ? -1: 0;
139 while ((status=ip->ReadKeyStroke(ip, &key)) == EFI_NOT_READY);
140 if (EFI_ERROR(status)) {
141 ERR_PRT((L"select_kernel readkey: %r", status));
144 switch (key.UnicodeChar) {
149 Print(L"(or a kernel file name: [[dev_name:/]path/]kernel_image cmdline options)\n");
151 buffer[pos] = CHAR_NULL;
152 display_label_info(buffer);
156 if (pos>0) goto normal_char;
161 if (pos>0) goto normal_char;
166 if (pos>0) goto normal_char;
171 if (pos>0) goto normal_char;
180 case CHAR_CTRL_U: /* clear line */
186 case CHAR_CTRL_C: /* kill line */
190 case CHAR_CARRIAGE_RETURN:
191 buffer[pos] = CHAR_NULL;
196 if (key.UnicodeChar == CHAR_CTRL_D || key.ScanCode == 0x17 ) {
197 Print(L"\nGiving up then...\n");
200 if (key.UnicodeChar == CHAR_NULL) break;
202 if (pos > size-1) break;
204 buffer[pos++] = key.UnicodeChar;
206 /* Write the character out */
207 Print(L"%c", key.UnicodeChar);
214 display_message(VOID)
222 if ((filename = get_message_filename(0)) == NULL) return;
224 if (*filename == CHAR_NULL) return;
226 VERB_PRT(3, Print(L"opening message file %s\n", filename));
228 status = fops_open(filename, &fd);
229 if (EFI_ERROR(status)) {
230 VERB_PRT(3, Print(L"message file %s not found\n", filename));
235 while ((status = fops_read(fd, buf, &len)) == EFI_SUCCESS) {
237 for (i=0; i < len; i++) {
238 Print(L"%c", (CHAR16)buf[i]);
240 if (len < 256) break;
246 simple_choose(CHAR16 **argv, INTN argc, INTN index, CHAR16 *kname, CHAR16 *cmdline)
248 # define BOOT_IMG_STR L"BOOT_IMAGE="
249 CHAR16 buffer[CMDLINE_MAXLEN];
250 CHAR16 alt_buffer[CMDLINE_MAXLEN];
251 CHAR16 initrd_name[CMDLINE_MAXLEN];
252 CHAR16 vmcode_name[CMDLINE_MAXLEN];
253 CHAR16 args[CMDLINE_MAXLEN];
254 CHAR16 devname[CMDLINE_MAXLEN];
255 CHAR16 dpath[FILENAME_MAXLEN];
256 CHAR16 *slash_pos, *colon_pos, *backslash_pos;
260 buffer[0] = alt_buffer[0] = CHAR_NULL;
265 initrd_name[0] = vmcode_name[0] = kname[0] = cmdline[0] = args[0] = CHAR_NULL;
267 /* reset per image loader options */
268 Memset(&elilo_opt.img_opt, 0, sizeof(elilo_opt.img_opt));
271 * check for alternate kernel image and params in EFI variable
273 if (elilo_opt.alt_check && alternate_kernel(alt_buffer, sizeof(alt_buffer)) == 0) {
274 argc = argify(alt_buffer,sizeof(alt_buffer), argv);
277 args[0] = initrd_name[0] = 0;
279 * don't check twice because the variable is deleted after
282 elilo_opt.alt_check = 0;
285 if (elilo_opt.prompt) {
286 ret = select_kernel(buffer, sizeof(buffer));
287 if (ret == -1) return -1;
288 argc = argify(buffer,sizeof(buffer), argv);
293 * if we found an alternate choice and the user
294 * did not force it manually, then use the alternate
297 if (alt_buffer[0] && buffer[0] == CHAR_NULL) {
298 StrCpy(buffer, alt_buffer);
302 * First search for matching label in the config file
303 * if options were specified on command line, they take
304 * precedence over the ones in the config file
306 * if no match is found, the args and initrd arguments may
307 * still be modified by global options in the config file.
309 ret = find_label((index < argc) ? argv[index] : NULL, kname, args, initrd_name, vmcode_name);
312 * not found, so assume first argument is kernel name and
316 if ((index < argc) && argv[index])
317 StrCpy(kname, argv[index]);
319 StrCpy(kname, elilo_opt.default_kernel);
322 * no matter what happened for kname, if user specified
323 * additional options, they override the ones in the
326 if (argc > 1+index) {
327 /*StrCpy(args, argv[++index]);*/
328 while (++index < argc) {
330 StrCat(args, argv[index]);
334 * if initrd specified on command line, it overrides
335 * the one defined in config file, if any
337 if (elilo_opt.initrd[0] == CHAR_NULL && initrd_name[0] != CHAR_NULL) {
338 StrCpy(elilo_opt.initrd, initrd_name);
341 if (elilo_opt.vmcode[0] == CHAR_NULL && vmcode_name[0] != CHAR_NULL) {
342 StrCpy(elilo_opt.vmcode, vmcode_name);
345 VERB_PRT(1, { Print(L"kernel is '%s'\n", kname);
346 Print(L"arguments are '%s'\n", args);
347 if (elilo_opt.initrd[0]) Print(L"initrd is '%s'\n", elilo_opt.initrd);
348 if (elilo_opt.vmcode[0]) Print(L"vmm is '%s'\n", elilo_opt.vmcode);
351 if (elilo_opt.prompt == 0) {
352 /* minimal printing */
354 ret = wait_timeout(elilo_opt.delay);
356 elilo_opt.prompt = 1;
357 elilo_opt.initrd[0] = CHAR_NULL;
358 elilo_opt.timeout = ELILO_TIMEOUT_INFINITY;
359 elilo_opt.initrd[0] = CHAR_NULL;
364 * add the device name, if not already specified,
365 * so that we know where we came from
367 slash_pos = StrChr(kname, L'/');
368 backslash_pos = StrChr(kname, L'\\');
369 colon_pos = StrChr(kname, L':');
371 if (backslash_pos && backslash_pos < slash_pos) slash_pos = backslash_pos;
373 if (colon_pos == NULL || (slash_pos && (slash_pos < colon_pos))) {
374 StrCpy(devname, fops_bootdev_name());
375 StrCat(devname, L":");
377 /* the default path is always terminated with a separator */
378 if (kname[0] != L'/' && kname[0] != L'\\') {
379 fops_getdefault_path(dpath,FILENAME_MAXLEN);
380 StrCat(devname, dpath);
383 devname[0] = CHAR_NULL;
387 * create final argument list to the kernel
389 len = StrLen(BOOT_IMG_STR) /* BOOT_IMAGE= */
390 +StrLen(devname) /* device name */
392 +elilo_opt.vmcode[0] ? StrLen(elilo_opt.vmcode) : StrLen(kname)
394 +StrLen(args); /* args length */
396 if (len >= CMDLINE_MAXLEN-1) {
397 ERR_PRT((L" arguments list too long cannot fit BOOT_IMAGE\n"));
400 StrCpy(cmdline, L"BOOT_IMAGE=");
401 StrCat(cmdline, devname);
402 if (elilo_opt.vmcode[0])
403 StrCat(cmdline, elilo_opt.vmcode);
405 StrCat(cmdline, kname);
406 StrCat(cmdline, L" ");
407 StrCat(cmdline, args);
413 simple_probe(EFI_HANDLE dev)
415 /* this chooser always work */
419 chooser_t simple_chooser={