Imported Debian patch 3.6-2
[debian/elilo] / elilo.c
1 /* 
2  * elilo.c - IA-64/IA-32 EFI Linux loader
3  *
4  *  Copyright (C) 1999-2003 Hewlett-Packard Co.
5  *      Contributed by David Mosberger <davidm@hpl.hp.com>.
6  *      Contributed by Stephane Eranian <eranian@hpl.hp.com>
7  *
8  *  Copyright (C) 1999-2000 VA Linux Systems
9  *       Contributed by Johannes Erdfelt <jerdfelt@valinux.com>.
10  *
11  * This file is part of the ELILO, the EFI Linux boot loader.
12  *
13  *  ELILO is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU General Public License as published by
15  *  the Free Software Foundation; either version 2, or (at your option)
16  *  any later version.
17  *
18  *  ELILO is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU General Public License for more details.
22  *
23  *  You should have received a copy of the GNU General Public License
24  *  along with ELILO; see the file COPYING.  If not, write to the Free
25  *  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26  *  02111-1307, USA.
27  *
28  * Please check out the elilo.txt for complete documentation on how
29  * to use this program.
30  */
31
32 #include <efi.h>
33 #include <efilib.h>
34
35 #include "elilo.h"
36 #include "vars.h"
37 #include "gzip.h"
38
39 #include "getopt.h"
40 #include "fileops.h"
41 #include "loader.h"
42 #include "config.h" /* for config_init() */
43
44 #define ELILO_VERSION                   L"3.4"
45 #define ELILO_SHARED_CMDLINE_OPTS       L"pPMC:aDhd:i:vVc:E"
46
47 elilo_config_t elilo_opt;
48
49 EFI_SYSTEM_TABLE *systab;       /* pointer to EFI system table */
50
51 /*
52  * Load the Linux kernel in memory from the boot media
53  * Output:
54  *      kd = address of kernel entry point
55  *         + end address of kernel code+data+bss
56  *         + kernel entry point
57  * Return:
58  *      ELILO_LOAD_ERROR   : if something went wrong
59  *      ELILO_LOAD_ABORTED : user interruption while loading
60  *      ELILO_LOAD_SUCCESS : otherwise
61  */
62 static INTN
63 do_kernel_load(CHAR16 *kname, kdesc_t *kd)
64 {
65         loader_ops_t    *ldops;
66         EFI_STATUS status;
67         fops_fd_t fd;
68
69         status = fops_open(kname, &fd);
70         if (EFI_ERROR(status)) {
71                 ERR_PRT((L"Kernel file  not found %s", kname));
72                 return ELILO_LOAD_ERROR;
73         }
74         fops_close(fd);
75
76         ldops = loader_probe(kname);
77         if (ldops == NULL) {
78                 ERR_PRT((L"Cannot find a loader for %s", kname));
79                 return ELILO_LOAD_ERROR;
80         }
81
82         VERB_PRT(1,Print(L"Using %s loader\n", ldops->ld_name));
83         
84         return ldops->ld_load_kernel(kname, kd);
85 }
86
87 INTN
88 kernel_load(EFI_HANDLE image, CHAR16 *kname, kdesc_t *kd, memdesc_t *imem, memdesc_t *mmem)
89 {
90         CHAR16 kernel[CMDLINE_MAXLEN];
91
92         /*
93          * Do the vm image switch here
94          * if there is "vmm=" then elilo should load image specified
95          * in "vmm=" and then give the "image" to vmm as target kernel image
96          */
97         if (elilo_opt.vmcode[0])
98                 StrCpy(kernel, elilo_opt.vmcode);
99         else
100                 StrCpy(kernel, kname);
101         /*
102          * Now let's try to load the kernel !
103          */
104         switch(do_kernel_load(kernel, kd)) {
105                 case ELILO_LOAD_SUCCESS:
106                         break;
107
108                 case ELILO_LOAD_ERROR:
109                         /* XXX: add fallback support */
110                         return ELILO_LOAD_ERROR;
111                 
112                 case ELILO_LOAD_ABORTED:
113                         /* we drop initrd in case we aborted the load */
114                         elilo_opt.initrd[0] = CHAR_NULL;
115                         elilo_opt.vmcode[0] = CHAR_NULL;
116
117                         /* will go back to interactive selection */
118                         elilo_opt.prompt  = 1; 
119                         elilo_opt.timeout = ELILO_DEFAULT_TIMEOUT;
120                         elilo_opt.delay   = 0;
121
122                         return ELILO_LOAD_RETRY;        
123         }
124
125         VERB_PRT(3, Print(L"kernel loaded in [0x%lx-0x%lx] entry=0x%lx\n", 
126                           (unsigned long)kd->kstart, (unsigned long)kd->kend, (unsigned long)kd->kentry));
127
128         if (elilo_opt.initrd[0]) {
129
130                 if (sysdeps_initrd_get_addr(kd, imem) == -1) goto exit_error;
131
132                 switch(load_file(elilo_opt.initrd, imem)) {
133                         case ELILO_LOAD_SUCCESS:
134                                 break;
135                         case ELILO_LOAD_ERROR:
136                                 goto exit_error;
137                         case ELILO_LOAD_ABORTED:
138                                 free_kmem();
139                                 /* we drop initrd in case we aborted the load */
140                                 elilo_opt.initrd[0] = CHAR_NULL;
141                                 elilo_opt.vmcode[0] = CHAR_NULL;
142                                 elilo_opt.prompt    = 1; 
143                                 elilo_opt.timeout   = ELILO_DEFAULT_TIMEOUT;
144                                 elilo_opt.delay     = 0;
145
146                                 return ELILO_LOAD_RETRY;
147                 }
148         }
149
150         if (elilo_opt.vmcode[0]) {
151
152                 mmem->start_addr = 0; /* let the allocator decide */
153
154                 switch(load_file(kname, mmem)) {
155                         case ELILO_LOAD_SUCCESS:
156                                 break;
157                         case ELILO_LOAD_ERROR:
158                                 goto exit_error;
159                         case ELILO_LOAD_ABORTED:
160                                 if (imem->start_addr)
161                                         free(imem->start_addr);
162                                 free_kmem();
163                                 /* we drop initrd in case we aborted the load */
164                                 elilo_opt.initrd[0] = CHAR_NULL;
165                                 elilo_opt.vmcode[0] = CHAR_NULL;
166                                 elilo_opt.prompt    = 1; 
167                                 elilo_opt.timeout   = ELILO_DEFAULT_TIMEOUT;
168                                 elilo_opt.delay     = 0;
169
170                                 return ELILO_LOAD_RETRY;
171                 }
172
173                 /* Test for a compressed image and unzip if found */
174                 if (gzip_probe(mmem->start_addr, mmem->size) == 0 &&
175                     gunzip_image(mmem) != ELILO_LOAD_SUCCESS) {
176                         if (imem->start_addr)
177                                 free(imem->start_addr);
178                         free(mmem->start_addr);
179                         free_kmem();
180                         /* we drop initrd in case we aborted the load */
181                         elilo_opt.initrd[0] = CHAR_NULL;
182                         elilo_opt.vmcode[0] = CHAR_NULL;
183                         elilo_opt.prompt    = 1; 
184                         elilo_opt.timeout   = ELILO_DEFAULT_TIMEOUT;
185                         elilo_opt.delay     = 0;
186
187                         return ELILO_LOAD_RETRY;
188                 }
189         }
190         return ELILO_LOAD_SUCCESS;
191 exit_error:
192         free_kmem();
193         if (imem->start_addr) free(imem->start_addr);
194         if (mmem->start_addr) free(mmem->start_addr);
195
196         return ELILO_LOAD_ERROR;
197 }
198
199 static INTN
200 main_loop(EFI_HANDLE dev, CHAR16 **argv, INTN argc, INTN index, EFI_HANDLE image)
201 {
202         CHAR16 kname[FILENAME_MAXLEN];
203         CHAR16 cmdline_tmp[CMDLINE_MAXLEN];
204         CHAR16 cmdline[CMDLINE_MAXLEN];
205         VOID *bp;
206         UINTN cookie;
207         EFI_STATUS status = EFI_SUCCESS;
208         kdesc_t kd;
209         memdesc_t imem, mmem;
210         INTN r;
211
212         /*
213          * First place where we potentially do system dependent
214          * operations. It is a one time opportunity before entering
215          * the main loop
216          */
217         if (sysdeps_preloop_actions(dev, argv, argc, index, image) == -1) return -1;
218
219         for(;;) {
220                 kname[0] = cmdline_tmp[0] = cmdline[0] = CHAR_NULL;
221                 imem.start_addr = 0; imem.pgcnt = 0; imem.size = 0;
222                 elilo_opt.sys_img_opts = NULL;
223
224                 if (kernel_chooser(argv, argc, index, kname, cmdline_tmp) == -1) goto exit_error;
225
226                 switch (kernel_load(image, kname, &kd, &imem, &mmem)) {
227                         case ELILO_LOAD_SUCCESS: 
228                                 goto do_launch;
229                         case ELILO_LOAD_ERROR:
230                                 goto exit_error;
231                         /* otherwise we retry ! */
232                 }
233         } 
234
235 do_launch:
236         r =subst_vars(cmdline_tmp, cmdline, CMDLINE_MAXLEN);
237
238         VERB_PRT(3, Print(L"final cmdline(%d): %s\n", r, cmdline));
239
240         /* free resources associated with file accesses (before ExitBootServices) */
241         close_devices();
242
243         /* No console output permitted after create_boot_params()! */
244         if ((bp=create_boot_params(cmdline, &imem, &mmem, &cookie)) == 0) goto error;
245
246         /* terminate bootservices */
247         status = BS->ExitBootServices(image, cookie);
248         if (EFI_ERROR(status)) goto bad_exit;
249
250         start_kernel(kd.kentry, bp);
251         /* NOT REACHED */
252
253         ERR_PRT((L"start_kernel() return !"));
254 bad_exit:       
255         /*
256          * we are still in BootService mode
257          */
258         ERR_PRT((L"ExitBootServices failed %r", status));
259 error:
260         free_kmem();
261         if (imem.start_addr) free(imem.start_addr);
262         if (bp) free_boot_params(bp);
263 exit_error:
264         return ELILO_LOAD_ERROR;
265
266 }
267
268 static VOID
269 elilo_help(VOID)
270 {
271         
272         Print(L"-d secs   timeout in 10th of second before booting\n");
273         Print(L"-h        this help text\n");
274         Print(L"-V        print version\n");
275         Print(L"-v        verbose level(can appear multiple times)\n");
276         Print(L"-a        always check for alternate kernel image\n");
277         Print(L"-i file   load file as the initial ramdisk\n");
278         Print(L"-m file   load file as additional boot time vmm module\n");
279         Print(L"-C file   indicate the config file to use\n");
280         Print(L"-P        parse config file only (verify syntax)\n");
281         Print(L"-D        enable debug prints\n");
282         Print(L"-p        force interactive mode\n");
283         Print(L"-c name   image chooser to use\n");
284         Print(L"-E        do not force EDD30 variable\n");
285
286         sysdeps_print_cmdline_opts();
287
288         Print(L"\n");
289
290         print_config_options();
291 }
292
293 /*
294  * XXX: hack to work around a problem with EFI command line argument when booted
295  * from network. In this case, it looks like LoadOptions/LoadOptionsSize contain
296  * garbage
297  */
298 static CHAR16 *default_load_options;
299 static UINTN default_load_options_size;
300 static INTN done_fixups;
301
302 static VOID
303 fixupargs(EFI_LOADED_IMAGE *info)
304 {
305         EFI_STATUS status;
306         EFI_PXE_BASE_CODE *pxe;
307
308 #define FAKE_ELILONAME  L"elilo-forced"
309
310         status = BS->HandleProtocol (info->DeviceHandle, &PxeBaseCodeProtocol, (VOID **)&pxe);
311         if (EFI_ERROR(status)) return;
312
313         default_load_options      = info->LoadOptions;
314         default_load_options_size = info->LoadOptionsSize;
315
316         info->LoadOptions     = FAKE_ELILONAME;
317         info->LoadOptionsSize = StrLen(info->LoadOptions)*sizeof(CHAR16);
318
319         done_fixups = 1;
320 }
321
322 /*
323  * we restore the arguments in case we modified them just to make sure
324  * we don't confuse caller.
325  */
326 static VOID
327 unfixupargs(EFI_LOADED_IMAGE *info)
328 {
329         if (done_fixups == 0) return;
330
331         info->LoadOptions     = default_load_options;
332         info->LoadOptionsSize = default_load_options_size;
333 }
334
335
336 /*
337  * in order to get fully detailed EFI path names to devices, EDD3.0 specification must
338  * be turned on. On new versions of EFI, this is the default. An environment variable
339  * called EDD30 reflects the current settings. If true, then EDD3.0 is enabled 
340  * and device path names show the detailed device types. If false, then a default 
341  * generic name is used instead. This has some implications of ELILO's ability to 
342  * provide a better naming scheme for detected devices. If EDD3.0 is enabled
343  * then much more precise names can be used which makes it easy to use. 
344  * If EDD3.0 is nont enabled, ELILO will still work but will use very generic names
345  * for devices.
346  *
347  * ELILO will check the value of the variable. If not true, then it will force it to
348  * true. This will require a reboot for EFI to make use of the new value.
349  * Return:
350  *      EFI_SUCCESS: if variable is already true or was set to true
351  *      EFI error code: otherwise, like when could not forced variable or unrecognized variable content
352  */
353 #define EDD30_GUID \
354 {0x964e5b21, 0x6459, 0x11d2, { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
355
356 #define EDD30_ATTR (EFI_VARIABLE_RUNTIME_ACCESS|EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_NON_VOLATILE)
357
358 static EFI_GUID edd30_guid = EDD30_GUID;
359
360 static INTN
361 check_edd30(VOID)
362 {
363         EFI_STATUS      status;
364         UINTN           l = sizeof(BOOLEAN);
365         UINT8           bool = FALSE;
366         INTN            ret = -1;
367
368         status = RT->GetVariable(L"EDD30", &edd30_guid, NULL, &l, &bool);
369         if (status == EFI_BUFFER_TOO_SMALL || (bool != TRUE && bool != FALSE)) {
370                 ERR_PRT((L"Warning: EDD30 EFI variable is not boolean value: forcing it to TRUE"));
371                 return -1;
372         }
373         if (status == EFI_SUCCESS && bool == TRUE) {
374                 VERB_PRT(3, Print(L"EDD30 is TRUE\n"));
375                 elilo_opt.edd30_on = TRUE;
376                 ret = 0;
377         } else {
378                 VERB_PRT(4, 
379                         if (status != EFI_SUCCESS) {
380                                 Print(L"EDD30 EFI variable not defined\n");
381                         } else {
382                                 Print(L"EDD30 EFI variable is false\n");
383                         }
384                 );
385         }
386
387         return ret;
388 }
389
390 static INTN
391 force_edd30(VOID)
392 {
393         EFI_STATUS      status;
394         UINTN           l = sizeof(BOOLEAN);
395         UINT8           bool;
396
397         bool = TRUE;
398         status = RT->SetVariable(L"EDD30", &edd30_guid, EDD30_ATTR, l, &bool);
399         if (EFI_ERROR(status)) {
400                 ERR_PRT((L"can't set EDD30 variable: ignoring it"));
401                 return -1;
402         }
403
404         VERB_PRT(3, Print(L"EDD30 variable forced to TRUE. You should reboot to take advantage of EDD3.0.\n"));
405
406         return 0;
407 }
408
409 /*
410  * That's equivalent of main(): main entry point
411  */
412 EFI_STATUS
413 efi_main (EFI_HANDLE image, EFI_SYSTEM_TABLE *system_tab)
414 {
415         CHAR16 *argv[MAX_ARGS];
416         CHAR16 optstring[MAX_ARGS];
417         EFI_LOADED_IMAGE *info;
418         EFI_STATUS status, ret = EFI_LOAD_ERROR;
419         INTN argc = 0, c;
420         INTN edd30_status, retry;
421         CHAR16 *ptr, *arglist = NULL;
422         BOOLEAN devices_initialized = FALSE;
423         CHAR16 dpath[FILENAME_MAXLEN];
424         CHAR16 *devpath;
425
426         elilo_opt.verbose=0;
427         elilo_opt.debug=0;
428
429         /* initialize global variable */
430         systab = system_tab;
431         
432         /* initialize EFI library */
433         InitializeLib(image, systab);
434         /*
435          * disable the platform watchdog timer if we go interactive
436          * XXX: we should reinstate it once we're done
437          * It seems like with PXE, the timer is set to a few minutes
438          * and sometimes triggers if we stay too long in interactive
439          * mode.
440          * XXX: clean this up !
441          */
442        BS->SetWatchdogTimer(0, 0x0, 0, NULL);
443
444         /* initialize memory allocator */
445         if (alloc_init() == -1) return EFI_LOAD_ERROR;
446
447         status = BS->HandleProtocol(image, &LoadedImageProtocol, (VOID **) &info);
448         if (EFI_ERROR(status)) {
449                 ERR_PRT((L"image handle does not support LOADED_IMAGE protocol"));
450                 return EFI_LOAD_ERROR;
451         }
452
453         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));
454
455         /*
456          * verify EDD3.0 status. Users may have to reboot 
457          */
458         edd30_status = check_edd30();
459
460         /*
461          * initialize configuration empire
462          */
463         if (config_init() == -1) goto do_exit;
464
465         /* 
466          * architecture-specific initializations
467          */
468         if (sysdeps_init(info->DeviceHandle) == -1) goto do_exit;
469         if (sysdeps_register_options() == -1) goto do_exit;
470
471         /*
472          * This may be required in case Elilo was booted with absolutely no arguments
473          * Elilo's logic is that just like normal Linux programs at least one argument
474          * (argv[0]) exists at all times and that it usually gives the name of the program
475          * (the command used to start it).
476         ERR_PRT((L"LoadOptions=%x OpenSize=%d", info->LoadOptions, info->LoadOptionsSize));
477          */
478
479         /*
480          * in case there is something wrong with the default boot_device
481          * we default to basic fixups and we need to force interactive
482          * mode to make sure the user has a chance of specifying a kernel
483          */
484         fixupargs(info);
485
486 #if 0
487         Print(L"LoadOptions=%x OpenSize=%d\n", info->LoadOptions, info->LoadOptionsSize);
488         { INTN i; for (i=0; i< info->LoadOptionsSize>>1; i++) Print(L"options[%d]=%d (%c)\n", i, ((CHAR16 *)info->LoadOptions)[i], ((CHAR16 *)info->LoadOptions)[i]); }
489 #endif
490
491         /*
492          * we must copy argument because argify modifies the string.
493          * This caused problems when arguments are coming from NVRAM
494          * as passed by the EFI boot manager
495          *
496          * We add an extra character to the buffer in case the LoadOptions is not 
497          * NULL terminated. The extra space will be used to ADD the extra terminator.
498          */
499         arglist = alloc(info->LoadOptionsSize+sizeof(CHAR16), EfiLoaderData);
500         if (arglist == NULL) {
501                 ERR_PRT((L"cannot copy argument list"));
502                 return EFI_OUT_OF_RESOURCES;
503         }
504         Memcpy(arglist, info->LoadOptions, info->LoadOptionsSize);
505
506         argc = argify(arglist,info->LoadOptionsSize, argv); 
507
508         StrCpy(optstring, ELILO_SHARED_CMDLINE_OPTS);
509         StrCat(optstring, sysdeps_get_cmdline_opts());
510
511         while ((c=Getopt(argc, argv, optstring)) != -1 ) {
512                 switch(c) {
513                         case 'a':
514                                 elilo_opt.alt_check = 1;
515                                 break;
516                         case 'D':
517                                 elilo_opt.debug = 1;
518                                 break;
519                         case 'p':
520                                 elilo_opt.prompt = 1;
521                                 break;
522                         case 'v':
523                                 elilo_opt.verbose++;
524                                 if (elilo_opt.verbose > 5) elilo_opt.verbose = 5;
525                                 break;
526                         case 'h':
527                                 elilo_help();
528                                 ret = EFI_SUCCESS;
529                                 goto do_exit;
530                         case 'd':
531                                 /*
532                                  * zero is a valid value here, so we use the delay-set to mark the
533                                  * fact that the user specified a value on cmdline. See config.c
534                                  */
535                                 elilo_opt.delay = Atoi(Optarg);
536                                 elilo_opt.delay_set = 1;
537                                 break;
538                         case 'E':
539                                 /* don't force EDD30 EFI variable if not already set */
540                                 elilo_opt.edd30_no_force = 1;
541                                 break;
542                         case 'i':
543                                 if (StrLen(Optarg) >= FILENAME_MAXLEN-1) {
544                                         Print(L"initrd filename is limited to %d characters\n", FILENAME_MAXLEN);
545                                         goto do_exit;
546                                 }
547                                 StrCpy(elilo_opt.initrd, Optarg);
548                                 break;
549                         case 'm':
550                                 if (StrLen(Optarg) >= FILENAME_MAXLEN-1) {
551                                         Print(L"vmm module filename is limited to %d characters\n", FILENAME_MAXLEN);
552                                         goto do_exit;
553                                 }
554                                 StrCpy(elilo_opt.vmcode, Optarg);
555                                 break;
556                         case 'C':
557                                 if (StrLen(Optarg) >= FILENAME_MAXLEN-1) {
558                                         Print(L"config filename is limited to %d characters\n", FILENAME_MAXLEN);
559                                         goto do_exit;
560                                 }
561                                 StrCpy(elilo_opt.config, Optarg);
562                                 break;
563                         case 'M': /* builtin debug tool */
564                                 { mmap_desc_t mdesc; 
565                                         if (get_memmap(&mdesc) == -1) {
566                                                 Print(L"Cannot get memory map\n");
567                                                 return EFI_LOAD_ERROR;
568                                         }
569                                         print_memmap(&mdesc);
570                                         ret = EFI_SUCCESS;
571                                         goto do_exit;
572                                 }
573                         case 'V':
574                                 Print(L"ELILO v%s for EFI/%a\n", ELILO_VERSION, ELILO_ARCH);
575                                 ret = EFI_SUCCESS;
576                                 goto do_exit;
577                         case 'P':
578                                 /* cmdline only option */
579                                 elilo_opt.parse_only =  1;
580                                 break;
581                         case 'c':
582                                 if (StrLen(Optarg) >= FILENAME_MAXLEN-1) {
583                                         Print(L"chooser name is limited to %d characters\n", FILENAME_MAXLEN);
584                                         goto do_exit;
585                                 }
586                                 StrCpy(elilo_opt.chooser, Optarg);
587                                 break;
588                         default:
589                                 /*
590                                  * try system dependent options before declaring error
591                                  */
592                                 if (sysdeps_getopt(c, Optind, Optarg) == 0) continue;
593
594                                 Print(L"Unknown option -%c\n", (CHAR16)c);
595                                 goto do_exit;
596                 }
597         }
598         DBG_PRT((L"Optind=%d optarg=%x argc=%d", Optind, Optarg, argc));
599
600         /*
601          * we can't defer this phase any longer...
602          * Must be done after the elilo_opt are initialized (at least partially)
603          */
604         if (init_devices(info->DeviceHandle) == -1) goto do_exit;
605
606         devices_initialized = TRUE;
607
608         devpath = DevicePathToStr(info->FilePath);
609
610         /*
611          * set per fileops defaults files for configuration and kernel
612          */
613         fops_setdefaults(elilo_opt.default_configs, elilo_opt.default_kernel, FILENAME_MAXLEN, devpath);
614
615         /*
616          * XXX: won't be visible if verbose not required from command line
617          */
618         VERB_PRT(2,Print(L"Default config: %s\nDefault_kernel: %s\n",
619                         elilo_opt.default_configs[0].fname, elilo_opt.default_kernel));
620         /*
621          * use default config file if not specified by user
622          */
623         ptr = elilo_opt.config[0] == CHAR_NULL ?  (retry=1,elilo_opt.default_configs[0].fname) : (retry=0,elilo_opt.config);
624
625         /*
626          * parse config file (verbose becomes visible if set)
627          */
628         ret = read_config(ptr);
629         VERB_PRT(1,Print(L"read_config=%r\n", ret));
630
631         /* Only try the default config filenames if user did not specify a
632          * config filename on the command line */
633         if (elilo_opt.config[0] == CHAR_NULL) {
634                 while ((ret != EFI_SUCCESS) &&
635                        (retry < MAX_DEFAULT_CONFIGS) &&
636                        (elilo_opt.default_configs[retry].fname[0] != CHAR_NULL)) {
637
638                         ptr = elilo_opt.default_configs[retry].fname;
639                         ret = read_config(ptr);
640                         VERB_PRT(1,Print(L"read_config=%r\n", ret));
641                         retry += 1;
642                 }
643         }
644         /*
645          * when the config file is not found, we fail only if:
646          *      - the user did not specified interactive mode
647          *      - the user did not explicitely specify the config file
648          */
649         if (ret == EFI_NOT_FOUND || ret == EFI_TFTP_ERROR) {
650                 if (elilo_opt.prompt == 0 && elilo_opt.config[0] != CHAR_NULL) {
651                         Print(L"config file %s not found\n", ptr);
652                         goto do_exit;
653                 }
654                 fops_getdefault_path(dpath, FILENAME_MAXLEN);
655                 if (ret == EFI_TFTP_ERROR)
656                         Print(L"no config file found on TFTP server in %s\n", dpath);
657                 else
658                         Print(L"no config file found in %s\n", dpath);
659         }
660         /*
661          * stop if just doing parsing
662          */
663         if (elilo_opt.parse_only) {
664                 if (ret == EFI_SUCCESS)
665                         Print(L"Config file %s parsed successfully\n", ptr);
666                 goto do_exit;
667         }
668         /*
669          * if there was an error when parsing the config file, then
670          * we force interactive mode to give a chance to the user.
671          * We also clear the error. 
672          */
673         if (ret != EFI_SUCCESS) {
674                 Print(L"forcing interactive mode due to config file error(s)\n");
675                 elilo_opt.prompt = 1;
676         }
677         /*
678          * However, if the user specified a kernel on the command line
679          * then we don't go to interactive mode, even if there was an option in
680          * the config file telling us to do so.
681          */
682         if (argc > Optind) {
683             elilo_opt.prompt = 0;
684         }
685
686         /*
687          * If EDD30 EFI variable was not set to TRUE (or not defined), we
688          * we try to force it. This will take effect at the next reboot.
689          *
690          * Some controllers don't have EDD30 support, in this case forcing it 
691          * may cause problems, therefore we check the edd_no_force option
692          * before making the call.
693          */
694         if (edd30_status == -1 && elilo_opt.edd30_no_force == 0) {
695                 force_edd30();
696         }
697
698         ret = EFI_LOAD_ERROR;
699
700
701
702         /* set default timeout if going interactive */
703         if ((elilo_opt.prompt && elilo_opt.timeout == 0)) {
704                 elilo_opt.timeout = ELILO_DEFAULT_TIMEOUT;
705         }
706
707         /*
708          * which chooser we will use 
709          */
710         if (init_chooser(info->DeviceHandle) == -1) {
711                 ERR_PRT((L"Cannot find a decent chooser\n"));
712                 goto do_exit;
713         }
714
715         //if (elilo_opt.prompt == 0) VERB_PRT(1, print_devices());
716
717         main_loop(info->DeviceHandle, argv, argc, Optind, image);
718         /* should not return */
719 do_exit:
720         unfixupargs(info);
721
722         //if (arglist) free(arglist);
723
724         /* free all resources assiocated with file accesses */
725         if (devices_initialized) close_devices();
726
727         /* garbage collect all remaining allocations */
728         free_all_memory();
729
730         return ret;
731 }