Imported Upstream version 3.14
[debian/elilo] / fileops.c
index 674fc5c4100f20db1abd3d523f2e9eff609e3cc4..9cf66ebb2d80a1e6c172647d1645a71c36a68161 100644 (file)
--- a/fileops.c
+++ b/fileops.c
@@ -1,6 +1,9 @@
 /*
  *  Copyright (C) 2001-2003 Hewlett-Packard Co.
  *     Contributed by Stephane Eranian <eranian@hpl.hp.com>
+ *     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.
  *
@@ -135,7 +138,7 @@ glue_filesystem(EFI_GUID *proto, EFI_HANDLE dev, fops_fs_glue_t glue)
        VOID *intf = NULL;
        EFI_STATUS status;
 
-       status = BS->HandleProtocol(dev, proto, &intf);
+       status = uefi_call_wrapper(BS->HandleProtocol, 3, dev, proto, &intf);
        if (EFI_ERROR(status)) {
                ERR_PRT((L"unable to locate %g: should not happen", proto));
                return NULL; /* should not happen */
@@ -345,12 +348,39 @@ fops_seek(fops_fd_t fd, UINT64 newpos)
 }
 
 EFI_STATUS
-fops_setdefaults(CHAR16 *config, CHAR16 *kname, UINTN maxlen, CHAR16 *devpath)
+fops_setdefaults(struct config_file *defconf, CHAR16 *kname, UINTN maxlen, CHAR16 *devpath)
 {
+    INTN i;
+
+/*
+ * The first default config file is architecture dependent. This is useful
+ * in case of network booting where the server is used for both types of
+ * architectures.
+ */
+#if defined(CONFIG_ia64)
+#define FILEOPS_ARCH_DEFAULT_CONFIG    L"elilo-ia64.conf"
+#elif defined (CONFIG_ia32)
+#define FILEOPS_ARCH_DEFAULT_CONFIG    L"elilo-ia32.conf"
+#elif defined (CONFIG_x86_64)
+#define FILEOPS_ARCH_DEFAULT_CONFIG    L"elilo-x86_64.conf"
+#else
+#error "You need to specfy your default arch config file"
+#endif
+
+/* 
+ * last resort config file. Common to all architectures
+ */
+#define FILEOPS_DEFAULT_CONFIG L"elilo.conf"
+
 #define FILEOPS_DEFAULT_KERNEL         L"vmlinux"
-#define FILEOPS_DEFAULT_CONFIG         L"elilo.conf"
 
-       if (config == NULL || kname == NULL) return EFI_INVALID_PARAMETER;
+#ifdef ELILO_DEBUG
+       if (defconf == NULL || kname == NULL) return EFI_INVALID_PARAMETER;
+#endif
+
+        for (i=0; i<MAX_DEFAULT_CONFIGS; i++) {
+            defconf[i].fname[0] = CHAR_NULL;
+        }
 
        if (boot_dev == NULL || boot_dev->fops == NULL) {
                if (boot_dev == NULL) 
@@ -360,13 +390,30 @@ fops_setdefaults(CHAR16 *config, CHAR16 *kname, UINTN maxlen, CHAR16 *devpath)
 
                Print(L"Using builtin defaults for kernel and config file\n");
 
-               StrnCpy(config, FILEOPS_DEFAULT_CONFIG, maxlen-1);
                StrnCpy(kname, FILEOPS_DEFAULT_KERNEL, maxlen-1);
-
-               return EFI_UNSUPPORTED;
        }
-       
-       return boot_dev->fops->setdefaults(boot_dev->fops->intf, config, kname, maxlen, devpath);
+        else {
+                boot_dev->fops->setdefaults(boot_dev->fops->intf, defconf, kname, maxlen, devpath);
+        }
+        i=0; while (i<MAX_DEFAULT_CONFIGS && defconf[i].fname[0] != CHAR_NULL) i += 1;
+#ifdef ELILO_DEBUG
+        if ((i+3) >= MAX_DEFAULT_CONFIGS) {
+            Print(L"ERROR: i = %d, MAX_DEFAULT_CONFIGS is not large enough\n", i);
+            return EFI_INVALID_PARAMETER;
+        }
+#endif
+        StrnCpy(defconf[i].fname, FILEOPS_ARCH_DEFAULT_CONFIG, maxlen-1);
+        StrnCpy(defconf[i+1].fname, FILEOPS_DEFAULT_CONFIG, maxlen-1);
+
+#ifdef ELILO_DEBUG
+        VERB_PRT(3,Print(L"Default config filename list:\n"));
+        for (i=0; i<MAX_DEFAULT_CONFIGS; i++) {
+                if (defconf[i].fname[0] == CHAR_NULL) { break; }
+                        VERB_PRT(3,Print(L"\t%s\n", defconf[i].fname));
+        }
+#endif
+        
+       return EFI_SUCCESS;
 }
 
 EFI_STATUS
@@ -413,7 +460,7 @@ add_dev_tab(EFI_GUID *proto, EFI_HANDLE boot_handle, UINTN size, fops_fs_glue_t
        /*
         * get the actual device handles now
         */
-       status = BS->LocateHandle(ByProtocol, proto, NULL, &size, tab);
+       status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, proto, NULL, &size, tab);
        if (status != EFI_SUCCESS) {
                ERR_PRT((L"failed to get handles for proto %g size=%d: %r", proto, size, status));
                free(tab);
@@ -450,7 +497,7 @@ add_dev_tab(EFI_GUID *proto, EFI_HANDLE boot_handle, UINTN size, fops_fs_glue_t
 
                        str2 = str == NULL ? L"Unknown" : str;
 
-                       DBG_PRT((L"%s : %-8s : %s\n", dev_tab[idx].name,
+                       DBG_PRT((L"%s : %-8s : %s", dev_tab[idx].name,
                                (dev_tab[idx].fops ? dev_tab[idx].fops->name: L"N/A"), str2));
 
                        if (str) FreePool(str);
@@ -494,7 +541,7 @@ find_filesystems(EFI_HANDLE boot_handle)
         */
        for(fs = fs_tab; *fs; fs++) {
                size = 0;
-               BS->LocateHandle(ByProtocol, &(*fs)->proto, NULL, &size, NULL);
+               uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &(*fs)->proto, NULL, &size, NULL);
                total += size;
        }
        if (total == 0) {
@@ -518,7 +565,7 @@ find_filesystems(EFI_HANDLE boot_handle)
        for(fs = fs_tab; *fs; fs++) {
                size = 0;
 
-               BS->LocateHandle(ByProtocol, &(*fs)->proto, NULL, &size, NULL);
+               uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &(*fs)->proto, NULL, &size, NULL);
                if (size == 0) continue;
 
                add_dev_tab(&(*fs)->proto, boot_handle, size, (*fs)->glue);