orphan
[debian/elilo] / elilo.c
diff --git a/elilo.c b/elilo.c
index 2773f3f469193b195052e5c18d1a42be15bef751..ade977d401c1b654a411bc7eaec5b95b14f2b95f 100644 (file)
--- a/elilo.c
+++ b/elilo.c
 #include "loader.h"
 #include "config.h" /* for config_init() */
 
-#define ELILO_VERSION                  L"3.7"
 #define ELILO_SHARED_CMDLINE_OPTS      L"pPMC:aDhd:i:vVc:E"
 
 elilo_config_t elilo_opt;
 
 EFI_SYSTEM_TABLE *systab;      /* pointer to EFI system table */
 
+extern INTN wait_timeout (UINTN);
+
 /*
  * Load the Linux kernel in memory from the boot media
  * Output:
@@ -92,7 +93,7 @@ do_kernel_load(CHAR16 *kname, kdesc_t *kd)
 INTN
 kernel_load(EFI_HANDLE image, CHAR16 *kname, kdesc_t *kd, memdesc_t *imem, memdesc_t *mmem)
 {
-       CHAR16 kernel[CMDLINE_MAXLEN];
+       CHAR16 kernel[FILENAME_MAXLEN];
 
        /*
         * Do the vm image switch here
@@ -127,11 +128,12 @@ kernel_load(EFI_HANDLE image, CHAR16 *kname, kdesc_t *kd, memdesc_t *imem, memde
                        return ELILO_LOAD_RETRY;        
        }
 
-       VERB_PRT(3, Print(L"kernel loaded in [0x%lx-0x%lx] entry=0x%lx\n", 
-                         (unsigned long)kd->kstart, (unsigned long)kd->kend, (unsigned long)kd->kentry));
+       VERB_PRT(3, Print(L"kernel loaded in [" PTR_FMT "-" PTR_FMT "] entry=" PTR_FMT "\n", 
+                         kd->kstart, kd->kend, kd->kentry));
 
        if (elilo_opt.initrd[0]) {
 
+               /* ramdisk image is moved to the top of available extended memory later by start_kernel() */
                if (sysdeps_initrd_get_addr(kd, imem) == -1) goto exit_error;
 
                switch(load_file(elilo_opt.initrd, imem)) {
@@ -212,7 +214,7 @@ main_loop(EFI_HANDLE dev, CHAR16 **argv, INTN argc, INTN index, EFI_HANDLE image
        EFI_STATUS status = EFI_SUCCESS;
        kdesc_t kd;
        memdesc_t imem, mmem;
-       INTN r;
+       INTN r, retries=0;
 
        /*
         * First place where we potentially do system dependent
@@ -242,15 +244,49 @@ do_launch:
 
        VERB_PRT(3, Print(L"final cmdline(%d): %s\n", r, cmdline));
 
+       /* Give user time to see the output before launch */
+       if (elilo_opt.debug || elilo_opt.verbose) {
+               r = wait_timeout(150);
+       /* have to turn off all console output(except error output) now before final get_mmemap()
+        * call or it can cause the efi map key to change and the ExitBootSvc call to fail,
+        * forcing debug and verbose options off is the surest way to enforce this.
+        */
+               elilo_opt.debug=0;
+               elilo_opt.verbose=0; 
+       }
+
        /* free resources associated with file accesses (before ExitBootServices) */
        close_devices();
 
        /* No console output permitted after create_boot_params()! */
        if ((bp=create_boot_params(cmdline, &imem, &mmem, &cookie)) == 0) goto error;
 
-       /* terminate bootservices */
+       /* terminate bootservices 
+       * efi ExitBootSvcs spec: *note, get_memmap is called by create_boot_params() 
+       * An EFI OS loader must ensure that it has the system's current memory map at the time 
+       * it calls ExitBootServices(). This is done by passing in the current memory map's 
+       * MapKey value as returned by GetMemoryMap(). Care must be taken to ensure that the 
+       * memory map does not change between these two calls. It is suggested that 
+       * GetMemoryMap()be called immediately before calling ExitBootServices(). */
+
+retry:
        status = uefi_call_wrapper(BS->ExitBootServices, 2, image, cookie);
-       if (EFI_ERROR(status)) goto bad_exit;
+       if (EFI_ERROR(status)) 
+       {
+               ERR_PRT((L"\nExitBootSvcs: failed, memory map has changed.\n"));
+               if (retries < 2)
+               {       
+                       ERR_PRT((L"Main_Loop: Retrying,... have to rebuild boot params"));
+                       retries++;
+                       free_boot_params(bp);
+                       if ((bp=create_boot_params(cmdline, &imem, &mmem, &cookie)) == 0) goto error;                   
+                       goto retry;
+               } else {
+                       ERR_PRT((L"\nMain_Loop: tried ExitBootSvcs 3 times... retries exceeded.... giving up\n"));
+                       goto bad_exit;
+               }
+       }
+
 
        start_kernel(kd.kentry, bp);
        /* NOT REACHED */
@@ -264,6 +300,7 @@ bad_exit:
 error:
        free_kmem();
        if (imem.start_addr) free(imem.start_addr);
+       if (mmem.start_addr) free(mmem.start_addr);
        if (bp) free_boot_params(bp);
 exit_error:
        return ELILO_LOAD_ERROR;
@@ -455,7 +492,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *system_tab)
                return EFI_LOAD_ERROR;
        }
 
-       VERB_PRT(5,Print(L"Loaded at 0x%lx size=%d bytes code=%d data=%d\n", info->ImageBase, info->ImageSize, info->ImageCodeType, info->ImageDataType));
+       VERB_PRT(5,Print(L"Loaded at " PTR_FMT " size=%ld bytes code=%d data=%d\n", info->ImageBase, info->ImageSize, info->ImageCodeType, info->ImageDataType));
        /*
         * verify EDD3.0 status. Users may have to reboot 
         */
@@ -599,7 +636,7 @@ efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *system_tab)
                                goto do_exit;
                }
        }
-       DBG_PRT((L"Optind=%d optarg=%x argc=%d", Optind, Optarg, argc));
+       DBG_PRT((L"Optind=%d optarg=" PTR_FMT " argc=%d", Optind, Optarg, argc));
 
        /*
         * we can't defer this phase any longer...