2 * Copyright (C) 2001-2003 Hewlett-Packard Co.
3 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
4 * Copyright (C) 2006-2009 Intel Corporation
5 * Contributed by Fenghua Yu <fenghua.yu@intel.com>
6 * Contributed by Bibo Mao <bibo.mao@intel.com>
7 * Contributed by Chandramouli Narayanan <mouli@linux.intel.com>
9 * This file is part of the ELILO, the EFI Linux boot loader.
11 * ELILO is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * ELILO is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with ELILO; see the file COPYING. If not, write to the Free
23 * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 * Please check out the elilo.txt for complete documentation on how
27 * to use this program.
36 /* static is ugly but does the job here! */
37 static CHAR16 **alt_argv;
40 display_label_info(CHAR16 *name)
43 CHAR16 initrd_name[CMDLINE_MAXLEN];
44 CHAR16 vmcode_name[CMDLINE_MAXLEN];
45 CHAR16 options_tmp[CMDLINE_MAXLEN];
46 CHAR16 options[CMDLINE_MAXLEN];
47 CHAR16 kname[FILENAME_MAXLEN];
49 desc = find_description(name);
51 Print(L"desc : %s\n", desc);
54 initrd_name[0] = vmcode_name[0] = options_tmp[0] = kname[0] = CHAR_NULL;
56 if (find_label(name, kname, options_tmp, initrd_name, vmcode_name) == -1) {
60 subst_vars(options_tmp, options, CMDLINE_MAXLEN);
62 Print(L"cmdline: %s %s\n", kname, options);
63 if (initrd_name[0]) Print(L"initrd : %s\n", initrd_name);
64 if (vmcode_name[0]) Print(L"vmcode : %s\n", vmcode_name);
68 print_infos(int force)
71 CHAR16 dpath[FILENAME_MAXLEN];
72 CHAR16 *boot_dev_name;
75 boot_dev_name = fops_bootdev_name();
76 config_file = get_config_file();
78 fops_getdefault_path(dpath, FILENAME_MAXLEN);
80 if (force || elilo_opt.verbose > 0)
81 Print(L"default file path: %s:%s\n", boot_dev_name, dpath);
83 is_abs = config_file && (config_file[0] == CHAR_BACKSLASH || config_file[0] == CHAR_SLASH) ? 1 : 0;
85 if (force || elilo_opt.verbose > 0)
86 Print(L"config file : %s%s\n", config_file && is_abs == 0 ? dpath : L"", config_file ? config_file : L"none used");
89 CHAR16 **p = alt_argv;
90 Print(L"found alternate default choice :");
91 while (*p) Print(L" %s", *p++);
99 if (force || elilo_opt.verbose > 0)
100 Print(L"command list (must be first character):\n=:print device list, %%:print variable list, &:print paths, ?:help\nTAB:print label information\n");
104 * interactively select a kernel image and options.
105 * The kernel can be an actual filename or a label in the config file
111 select_kernel(CHAR16 *buffer, INTN size)
113 #define CHAR_CTRL_C L'\003' /* Unicode CTRL-C */
114 #define CHAR_CTRL_D L'\004' /* Unicode CTRL-D */
115 #define CHAR_CTRL_U L'\025' /* Unicode CTRL-U */
116 //#define CHAR_TAB L'\t'
117 SIMPLE_INPUT_INTERFACE *ip = systab->ConIn;
124 * let's give some help first
131 buffer[pos] = CHAR_NULL;
133 Print(L"\nELILO boot: %s", buffer);
135 * autoboot with default choice after timeout expires
137 if (first_time && (ret=wait_timeout(elilo_opt.timeout)) != 1) {
138 return ret == -1 ? -1: 0;
143 while ((status = uefi_call_wrapper(ip->ReadKeyStroke, 2, ip, &key))
145 if (EFI_ERROR(status)) {
146 ERR_PRT((L"select_kernel readkey: %r", status));
149 switch (key.UnicodeChar) {
154 Print(L"(or a kernel file name: [[dev_name:/]path/]kernel_image cmdline options)\n");
156 buffer[pos] = CHAR_NULL;
157 display_label_info(buffer);
161 if (pos>0) goto normal_char;
166 if (pos>0) goto normal_char;
171 if (pos>0) goto normal_char;
176 if (pos>0) goto normal_char;
185 case CHAR_CTRL_U: /* clear line */
191 case CHAR_CTRL_C: /* kill line */
195 case CHAR_CARRIAGE_RETURN:
196 buffer[pos] = CHAR_NULL;
201 if (key.UnicodeChar == CHAR_CTRL_D || key.ScanCode == 0x17 ) {
202 Print(L"\nGiving up then...\n");
205 if (key.UnicodeChar == CHAR_NULL) break;
207 if (pos > size-1) break;
209 buffer[pos++] = key.UnicodeChar;
211 /* Write the character out */
212 Print(L"%c", key.UnicodeChar);
219 display_message(VOID)
227 if ((filename = get_message_filename(0)) == NULL) return;
229 if (*filename == CHAR_NULL) return;
231 VERB_PRT(3, Print(L"opening message file %s\n", filename));
233 status = fops_open(filename, &fd);
234 if (EFI_ERROR(status)) {
235 VERB_PRT(3, Print(L"message file %s not found\n", filename));
240 while ((status = fops_read(fd, buf, &len)) == EFI_SUCCESS) {
242 for (i=0; i < len; i++) {
243 Print(L"%c", (CHAR16)buf[i]);
245 if (len < 256) break;
251 simple_choose(CHAR16 **argv, INTN argc, INTN index, CHAR16 *kname, CHAR16 *cmdline)
253 # define BOOT_IMG_STR L"BOOT_IMAGE="
254 CHAR16 buffer[CMDLINE_MAXLEN];
255 CHAR16 alt_buffer[CMDLINE_MAXLEN];
256 CHAR16 initrd_name[CMDLINE_MAXLEN];
257 CHAR16 vmcode_name[CMDLINE_MAXLEN];
258 CHAR16 args[CMDLINE_MAXLEN];
259 CHAR16 devname[CMDLINE_MAXLEN];
260 CHAR16 dpath[FILENAME_MAXLEN];
261 CHAR16 *slash_pos, *colon_pos, *backslash_pos;
265 buffer[0] = alt_buffer[0] = CHAR_NULL;
270 initrd_name[0] = vmcode_name[0] = kname[0] = cmdline[0] = args[0] = CHAR_NULL;
272 /* reset per image loader options */
273 Memset(&elilo_opt.img_opt, 0, sizeof(elilo_opt.img_opt));
276 * check for alternate kernel image and params in EFI variable
278 if (elilo_opt.alt_check && alternate_kernel(alt_buffer, sizeof(alt_buffer)) == 0) {
279 argc = argify(alt_buffer,sizeof(alt_buffer), argv);
282 args[0] = initrd_name[0] = vmcode_name[0] = 0;
284 * don't check twice because the variable is deleted after
287 elilo_opt.alt_check = 0;
290 if (elilo_opt.prompt) {
291 ret = select_kernel(buffer, sizeof(buffer));
292 if (ret == -1) return -1;
293 argc = argify(buffer,sizeof(buffer), argv);
298 * if we found an alternate choice and the user
299 * did not force it manually, then use the alternate
302 if (alt_buffer[0] && buffer[0] == CHAR_NULL) {
303 StrCpy(buffer, alt_buffer);
307 * First search for matching label in the config file
308 * if options were specified on command line, they take
309 * precedence over the ones in the config file
311 * if no match is found, the args and initrd arguments may
312 * still be modified by global options in the config file.
314 ret = find_label((index < argc) ? argv[index] : NULL, kname, args, initrd_name, vmcode_name);
317 * not found, so assume first argument is kernel name and
321 if ((index < argc) && argv[index])
322 StrCpy(kname, argv[index]);
324 StrCpy(kname, elilo_opt.default_kernel);
327 * no matter what happened for kname, if user specified
328 * additional options, they override the ones in the
331 if (argc > 1+index) {
332 /*StrCpy(args, argv[++index]);*/
333 while (++index < argc) {
335 StrCat(args, argv[index]);
339 * if initrd specified on command line, it overrides
340 * the one defined in config file, if any
342 if (elilo_opt.initrd[0] == CHAR_NULL && initrd_name[0] != CHAR_NULL) {
343 StrCpy(elilo_opt.initrd, initrd_name);
346 if (elilo_opt.vmcode[0] == CHAR_NULL && vmcode_name[0] != CHAR_NULL) {
347 StrCpy(elilo_opt.vmcode, vmcode_name);
350 VERB_PRT(1, { Print(L"kernel is '%s'\n", kname);
351 Print(L"arguments are '%s'\n", args);
352 if (elilo_opt.initrd[0]) Print(L"initrd is '%s'\n", elilo_opt.initrd);
353 if (elilo_opt.vmcode[0]) Print(L"vmm is '%s'\n", elilo_opt.vmcode);
356 if (elilo_opt.prompt == 0) {
357 /* minimal printing */
359 ret = wait_timeout(elilo_opt.delay);
361 elilo_opt.prompt = 1;
362 elilo_opt.initrd[0] = elilo_opt.vmcode[0] = CHAR_NULL;
363 elilo_opt.timeout = ELILO_TIMEOUT_INFINITY;
368 * add the device name, if not already specified,
369 * so that we know where we came from
371 slash_pos = StrChr(kname, L'/');
372 backslash_pos = StrChr(kname, L'\\');
373 colon_pos = StrChr(kname, L':');
375 if (backslash_pos && backslash_pos < slash_pos) slash_pos = backslash_pos;
377 if (colon_pos == NULL || (slash_pos && (slash_pos < colon_pos))) {
378 StrCpy(devname, fops_bootdev_name());
379 StrCat(devname, L":");
381 /* the default path is always terminated with a separator */
382 if (kname[0] != L'/' && kname[0] != L'\\') {
383 fops_getdefault_path(dpath,FILENAME_MAXLEN);
384 StrCat(devname, dpath);
387 devname[0] = CHAR_NULL;
391 * create final argument list to the kernel
393 len = StrLen(BOOT_IMG_STR) /* BOOT_IMAGE= */
394 +StrLen(devname) /* device name */
396 +elilo_opt.vmcode[0] ? StrLen(elilo_opt.vmcode) : StrLen(kname)
398 +StrLen(args); /* args length */
400 if (len >= CMDLINE_MAXLEN-1) {
401 ERR_PRT((L" arguments list too long cannot fit BOOT_IMAGE\n"));
404 StrCpy(cmdline, L"BOOT_IMAGE=");
405 StrCat(cmdline, devname);
406 if (elilo_opt.vmcode[0])
407 StrCat(cmdline, elilo_opt.vmcode);
409 StrCat(cmdline, kname);
410 StrCat(cmdline, L" ");
411 StrCat(cmdline, args);
417 simple_probe(EFI_HANDLE dev)
419 /* this chooser always work */
423 chooser_t simple_chooser={