Imported Upstream version 3.12
[debian/elilo] / choosers / simple.c
index 9b0725e4b8264712d56e8f329b0fcf836696707c..f064e12b973ccf26b3b27b0050f37bd49400101d 100644 (file)
@@ -1,6 +1,10 @@
 /* 
  *  Copyright (C) 2001-2003 Hewlett-Packard Co.
  *     Contributed by Stephane Eranian <eranian@hpl.hp.com>
+ *  Copyright (C) 2006-2009 Intel Corporation
+ *     Contributed by Fenghua Yu <fenghua.yu@intel.com>
+ *     Contributed by Bibo Mao <bibo.mao@intel.com>
+ *     Contributed by Chandramouli Narayanan <mouli@linux.intel.com>
  *
  * This file is part of the ELILO, the EFI Linux boot loader.
  *
@@ -28,6 +32,7 @@
 
 #include "elilo.h"
 #include "vars.h"
+#include "console.h"
 
 /* static is ugly but does the job here! */
 static CHAR16 **alt_argv;
@@ -37,6 +42,7 @@ display_label_info(CHAR16 *name)
 {
        CHAR16 *desc;
        CHAR16 initrd_name[CMDLINE_MAXLEN];
+       CHAR16 vmcode_name[CMDLINE_MAXLEN];
        CHAR16 options_tmp[CMDLINE_MAXLEN];
        CHAR16 options[CMDLINE_MAXLEN];
        CHAR16 kname[FILENAME_MAXLEN];
@@ -46,9 +52,9 @@ display_label_info(CHAR16 *name)
                Print(L"desc   : %s\n", desc);
        }
 
-       initrd_name[0] = options_tmp[0] = kname[0] = CHAR_NULL;
+       initrd_name[0] = vmcode_name[0] = options_tmp[0] = kname[0] = CHAR_NULL;
 
-       if (find_label(name, kname, options_tmp, initrd_name) == -1) {
+       if (find_label(name, kname, options_tmp, initrd_name, vmcode_name) == -1) {
                StrCpy(kname, name);
                Print(L"\n");
        }
@@ -56,6 +62,7 @@ display_label_info(CHAR16 *name)
 
        Print(L"cmdline: %s %s\n", kname, options);
        if (initrd_name[0]) Print(L"initrd : %s\n", initrd_name);
+       if (vmcode_name[0]) Print(L"vmcode : %s\n", vmcode_name);
 }
 
 static VOID
@@ -134,7 +141,8 @@ reprint:
        first_time = 0;
 
        for (;;) {
-               while ((status=ip->ReadKeyStroke(ip, &key)) == EFI_NOT_READY);
+               while ((status = uefi_call_wrapper(ip->ReadKeyStroke, 2, ip, &key))
+                                == EFI_NOT_READY);
                if (EFI_ERROR(status)) {
                        ERR_PRT((L"select_kernel readkey: %r", status));
                        return -1;
@@ -213,7 +221,7 @@ display_message(VOID)
 {
        fops_fd_t fd;
        EFI_STATUS status;
-       INTN len, i;
+       UINTN len, i;
        CHAR16 *filename;
        CHAR8 buf[256];
 
@@ -247,6 +255,7 @@ simple_choose(CHAR16 **argv, INTN argc, INTN index, CHAR16 *kname, CHAR16 *cmdli
        CHAR16 buffer[CMDLINE_MAXLEN];
        CHAR16 alt_buffer[CMDLINE_MAXLEN];
        CHAR16 initrd_name[CMDLINE_MAXLEN];
+       CHAR16 vmcode_name[CMDLINE_MAXLEN];
        CHAR16 args[CMDLINE_MAXLEN];
        CHAR16 devname[CMDLINE_MAXLEN];
        CHAR16 dpath[FILENAME_MAXLEN];
@@ -259,7 +268,7 @@ simple_choose(CHAR16 **argv, INTN argc, INTN index, CHAR16 *kname, CHAR16 *cmdli
        display_message();
 
 restart:
-       initrd_name[0] = kname[0] = cmdline[0] = args[0] = CHAR_NULL;
+       initrd_name[0] = vmcode_name[0] = kname[0] = cmdline[0] = args[0] = CHAR_NULL;
 
        /* reset per image loader options */
        Memset(&elilo_opt.img_opt, 0, sizeof(elilo_opt.img_opt));
@@ -271,7 +280,7 @@ restart:
                argc     = argify(alt_buffer,sizeof(alt_buffer), argv); 
                alt_argv = argv;
                index    = 0;
-               args[0]  = initrd_name[0] = 0;
+               args[0]  = initrd_name[0] = vmcode_name[0] = 0;
                /* 
                 * don't check twice because the variable is deleted after
                 * first access
@@ -280,6 +289,7 @@ restart:
        }
 
        if (elilo_opt.prompt) {
+               console_textmode();
                ret = select_kernel(buffer, sizeof(buffer));
                if (ret == -1) return -1;
                argc    = argify(buffer,sizeof(buffer), argv); 
@@ -303,14 +313,14 @@ restart:
         * if no match is found, the args and initrd arguments may
         * still be modified by global options in the config file.
         */
-       ret = find_label(argv[index], kname, args, initrd_name);
+       ret = find_label((index < argc) ? argv[index] : NULL, kname, args, initrd_name, vmcode_name);
 
        /*
         * not found, so assume first argument is kernel name and
         * not label name 
         */
        if (ret == -1) {
-               if (argv[index]) 
+               if ((index < argc) && argv[index]) 
                        StrCpy(kname, argv[index]);
                else
                        StrCpy(kname, elilo_opt.default_kernel);
@@ -335,17 +345,23 @@ restart:
                StrCpy(elilo_opt.initrd, initrd_name);
        }
 
+       if (elilo_opt.vmcode[0] == CHAR_NULL && vmcode_name[0] != CHAR_NULL) {
+               StrCpy(elilo_opt.vmcode, vmcode_name);
+       }
+
        VERB_PRT(1,  { Print(L"kernel     is  '%s'\n", kname);
                       Print(L"arguments  are '%s'\n", args);
                        if (elilo_opt.initrd[0]) Print(L"initrd      is '%s'\n", elilo_opt.initrd);
+                       if (elilo_opt.vmcode[0]) Print(L"vmm         is '%s'\n", elilo_opt.vmcode);
                      });
 
        if (elilo_opt.prompt == 0) {
                /* minimal printing */
-               Print(L"ELILO\n");
+               Print(L"ELILO v%s for EFI/%a\n", ELILO_VERSION, ELILO_ARCH);
                ret = wait_timeout(elilo_opt.delay);
                if (ret != 0) {
                        elilo_opt.prompt = 1;
+                       elilo_opt.initrd[0] = elilo_opt.vmcode[0] = CHAR_NULL;
                        elilo_opt.timeout =  ELILO_TIMEOUT_INFINITY;
                        goto restart;
                }
@@ -378,7 +394,8 @@ restart:
         */
        len = StrLen(BOOT_IMG_STR)      /* BOOT_IMAGE= */
             +StrLen(devname)           /* device name */
-            +StrLen(kname)             /* kernel name */
+                                       /* kernel name */
+            +elilo_opt.vmcode[0] ? StrLen(elilo_opt.vmcode) : StrLen(kname)
             +1                         /* space */
             +StrLen(args);             /* args length */
 
@@ -388,7 +405,10 @@ restart:
        }
        StrCpy(cmdline, L"BOOT_IMAGE=");
        StrCat(cmdline, devname);
-       StrCat(cmdline, kname);
+       if (elilo_opt.vmcode[0])
+               StrCat(cmdline, elilo_opt.vmcode);
+       else
+               StrCat(cmdline, kname);
        StrCat(cmdline, L" ");
        StrCat(cmdline, args);