]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/boot/efi/boot1/boot1.c
MFC Loader Fixes 2017q2: r316437,r316577,r316578,r316585,r316590,r316612,
[FreeBSD/FreeBSD.git] / sys / boot / efi / boot1 / boot1.c
1 /*-
2  * Copyright (c) 1998 Robert Nordier
3  * All rights reserved.
4  * Copyright (c) 2001 Robert Drehmel
5  * All rights reserved.
6  * Copyright (c) 2014 Nathan Whitehorn
7  * All rights reserved.
8  * Copyright (c) 2015 Eric McCorkle
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms are freely
12  * permitted provided that the above copyright notice and this
13  * paragraph and the following disclaimer are duplicated in all
14  * such forms.
15  *
16  * This software is provided "AS IS" and without any express or
17  * implied warranties, including, without limitation, the implied
18  * warranties of merchantability and fitness for a particular
19  * purpose.
20  */
21
22 #include <sys/cdefs.h>
23 __FBSDID("$FreeBSD$");
24
25 #include <sys/param.h>
26 #include <machine/elf.h>
27 #include <machine/stdarg.h>
28 #include <stand.h>
29
30 #include <efi.h>
31 #include <eficonsctl.h>
32
33 #include "boot_module.h"
34 #include "paths.h"
35
36 static const boot_module_t *boot_modules[] =
37 {
38 #ifdef EFI_ZFS_BOOT
39         &zfs_module,
40 #endif
41 #ifdef EFI_UFS_BOOT
42         &ufs_module
43 #endif
44 };
45
46 #define NUM_BOOT_MODULES        nitems(boot_modules)
47 /* The initial number of handles used to query EFI for partitions. */
48 #define NUM_HANDLES_INIT        24
49
50 EFI_STATUS efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE* Xsystab);
51
52 EFI_SYSTEM_TABLE *systab;
53 EFI_BOOT_SERVICES *bs;
54 static EFI_HANDLE *image;
55
56 static EFI_GUID BlockIoProtocolGUID = BLOCK_IO_PROTOCOL;
57 static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL;
58 static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL;
59 static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
60
61 /*
62  * Provide Malloc / Free backed by EFIs AllocatePool / FreePool which ensures
63  * memory is correctly aligned avoiding EFI_INVALID_PARAMETER returns from
64  * EFI methods.
65  */
66 void *
67 Malloc(size_t len, const char *file __unused, int line __unused)
68 {
69         void *out;
70
71         if (bs->AllocatePool(EfiLoaderData, len, &out) == EFI_SUCCESS)
72                 return (out);
73
74         return (NULL);
75 }
76
77 void
78 Free(void *buf, const char *file __unused, int line __unused)
79 {
80         if (buf != NULL)
81                 (void)bs->FreePool(buf);
82 }
83
84 /*
85  * nodes_match returns TRUE if the imgpath isn't NULL and the nodes match,
86  * FALSE otherwise.
87  */
88 static BOOLEAN
89 nodes_match(EFI_DEVICE_PATH *imgpath, EFI_DEVICE_PATH *devpath)
90 {
91         int len;
92
93         if (imgpath == NULL || imgpath->Type != devpath->Type ||
94             imgpath->SubType != devpath->SubType)
95                 return (FALSE);
96
97         len = DevicePathNodeLength(imgpath);
98         if (len != DevicePathNodeLength(devpath))
99                 return (FALSE);
100
101         return (memcmp(imgpath, devpath, (size_t)len) == 0);
102 }
103
104 /*
105  * device_paths_match returns TRUE if the imgpath isn't NULL and all nodes
106  * in imgpath and devpath match up to their respective occurrences of a
107  * media node, FALSE otherwise.
108  */
109 static BOOLEAN
110 device_paths_match(EFI_DEVICE_PATH *imgpath, EFI_DEVICE_PATH *devpath)
111 {
112
113         if (imgpath == NULL)
114                 return (FALSE);
115
116         while (!IsDevicePathEnd(imgpath) && !IsDevicePathEnd(devpath)) {
117                 if (IsDevicePathType(imgpath, MEDIA_DEVICE_PATH) &&
118                     IsDevicePathType(devpath, MEDIA_DEVICE_PATH))
119                         return (TRUE);
120
121                 if (!nodes_match(imgpath, devpath))
122                         return (FALSE);
123
124                 imgpath = NextDevicePathNode(imgpath);
125                 devpath = NextDevicePathNode(devpath);
126         }
127
128         return (FALSE);
129 }
130
131 /*
132  * devpath_last returns the last non-path end node in devpath.
133  */
134 static EFI_DEVICE_PATH *
135 devpath_last(EFI_DEVICE_PATH *devpath)
136 {
137
138         while (!IsDevicePathEnd(NextDevicePathNode(devpath)))
139                 devpath = NextDevicePathNode(devpath);
140
141         return (devpath);
142 }
143
144 /*
145  * devpath_node_str is a basic output method for a devpath node which
146  * only understands a subset of the available sub types.
147  *
148  * If we switch to UEFI 2.x then we should update it to use:
149  * EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.
150  */
151 static int
152 devpath_node_str(char *buf, size_t size, EFI_DEVICE_PATH *devpath)
153 {
154
155         switch (devpath->Type) {
156         case MESSAGING_DEVICE_PATH:
157                 switch (devpath->SubType) {
158                 case MSG_ATAPI_DP: {
159                         ATAPI_DEVICE_PATH *atapi;
160
161                         atapi = (ATAPI_DEVICE_PATH *)(void *)devpath;
162                         return snprintf(buf, size, "ata(%s,%s,0x%x)",
163                             (atapi->PrimarySecondary == 1) ?  "Sec" : "Pri",
164                             (atapi->SlaveMaster == 1) ?  "Slave" : "Master",
165                             atapi->Lun);
166                 }
167                 case MSG_USB_DP: {
168                         USB_DEVICE_PATH *usb;
169
170                         usb = (USB_DEVICE_PATH *)devpath;
171                         return snprintf(buf, size, "usb(0x%02x,0x%02x)",
172                             usb->ParentPortNumber, usb->InterfaceNumber);
173                 }
174                 case MSG_SCSI_DP: {
175                         SCSI_DEVICE_PATH *scsi;
176
177                         scsi = (SCSI_DEVICE_PATH *)(void *)devpath;
178                         return snprintf(buf, size, "scsi(0x%02x,0x%02x)",
179                             scsi->Pun, scsi->Lun);
180                 }
181                 case MSG_SATA_DP: {
182                         SATA_DEVICE_PATH *sata;
183
184                         sata = (SATA_DEVICE_PATH *)(void *)devpath;
185                         return snprintf(buf, size, "sata(0x%x,0x%x,0x%x)",
186                             sata->HBAPortNumber, sata->PortMultiplierPortNumber,
187                             sata->Lun);
188                 }
189                 default:
190                         return snprintf(buf, size, "msg(0x%02x)",
191                             devpath->SubType);
192                 }
193                 break;
194         case HARDWARE_DEVICE_PATH:
195                 switch (devpath->SubType) {
196                 case HW_PCI_DP: {
197                         PCI_DEVICE_PATH *pci;
198
199                         pci = (PCI_DEVICE_PATH *)devpath;
200                         return snprintf(buf, size, "pci(0x%02x,0x%02x)",
201                             pci->Device, pci->Function);
202                 }
203                 default:
204                         return snprintf(buf, size, "hw(0x%02x)",
205                             devpath->SubType);
206                 }
207                 break;
208         case ACPI_DEVICE_PATH: {
209                 ACPI_HID_DEVICE_PATH *acpi;
210
211                 acpi = (ACPI_HID_DEVICE_PATH *)(void *)devpath;
212                 if ((acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
213                         switch (EISA_ID_TO_NUM(acpi->HID)) {
214                         case 0x0a03:
215                                 return snprintf(buf, size, "pciroot(0x%x)",
216                                     acpi->UID);
217                         case 0x0a08:
218                                 return snprintf(buf, size, "pcieroot(0x%x)",
219                                     acpi->UID);
220                         case 0x0604:
221                                 return snprintf(buf, size, "floppy(0x%x)",
222                                     acpi->UID);
223                         case 0x0301:
224                                 return snprintf(buf, size, "keyboard(0x%x)",
225                                     acpi->UID);
226                         case 0x0501:
227                                 return snprintf(buf, size, "serial(0x%x)",
228                                     acpi->UID);
229                         case 0x0401:
230                                 return snprintf(buf, size, "parallelport(0x%x)",
231                                     acpi->UID);
232                         default:
233                                 return snprintf(buf, size, "acpi(pnp%04x,0x%x)",
234                                     EISA_ID_TO_NUM(acpi->HID), acpi->UID);
235                         }
236                 }
237
238                 return snprintf(buf, size, "acpi(0x%08x,0x%x)", acpi->HID,
239                     acpi->UID);
240         }
241         case MEDIA_DEVICE_PATH:
242                 switch (devpath->SubType) {
243                 case MEDIA_CDROM_DP: {
244                         CDROM_DEVICE_PATH *cdrom;
245
246                         cdrom = (CDROM_DEVICE_PATH *)(void *)devpath;
247                         return snprintf(buf, size, "cdrom(%x)",
248                             cdrom->BootEntry);
249                 }
250                 case MEDIA_HARDDRIVE_DP: {
251                         HARDDRIVE_DEVICE_PATH *hd;
252
253                         hd = (HARDDRIVE_DEVICE_PATH *)(void *)devpath;
254                         return snprintf(buf, size, "hd(%x)",
255                             hd->PartitionNumber);
256                 }
257                 default:
258                         return snprintf(buf, size, "media(0x%02x)",
259                             devpath->SubType);
260                 }
261         case BBS_DEVICE_PATH:
262                 return snprintf(buf, size, "bbs(0x%02x)", devpath->SubType);
263         case END_DEVICE_PATH_TYPE:
264                 return (0);
265         }
266
267         return snprintf(buf, size, "type(0x%02x, 0x%02x)", devpath->Type,
268             devpath->SubType);
269 }
270
271 /*
272  * devpath_strlcat appends a text description of devpath to buf but not more
273  * than size - 1 characters followed by NUL-terminator.
274  */
275 int
276 devpath_strlcat(char *buf, size_t size, EFI_DEVICE_PATH *devpath)
277 {
278         size_t len, used;
279         const char *sep;
280
281         sep = "";
282         used = 0;
283         while (!IsDevicePathEnd(devpath)) {
284                 len = snprintf(buf, size - used, "%s", sep);
285                 used += len;
286                 if (used > size)
287                         return (used);
288                 buf += len;
289
290                 len = devpath_node_str(buf, size - used, devpath);
291                 used += len;
292                 if (used > size)
293                         return (used);
294                 buf += len;
295                 devpath = NextDevicePathNode(devpath);
296                 sep = ":";
297         }
298
299         return (used);
300 }
301
302 /*
303  * devpath_str is convenience method which returns the text description of
304  * devpath using a static buffer, so it isn't thread safe!
305  */
306 char *
307 devpath_str(EFI_DEVICE_PATH *devpath)
308 {
309         static char buf[256];
310
311         devpath_strlcat(buf, sizeof(buf), devpath);
312
313         return buf;
314 }
315
316 /*
317  * load_loader attempts to load the loader image data.
318  *
319  * It tries each module and its respective devices, identified by mod->probe,
320  * in order until a successful load occurs at which point it returns EFI_SUCCESS
321  * and EFI_NOT_FOUND otherwise.
322  *
323  * Only devices which have preferred matching the preferred parameter are tried.
324  */
325 static EFI_STATUS
326 load_loader(const boot_module_t **modp, dev_info_t **devinfop, void **bufp,
327     size_t *bufsize, BOOLEAN preferred)
328 {
329         UINTN i;
330         dev_info_t *dev;
331         const boot_module_t *mod;
332
333         for (i = 0; i < NUM_BOOT_MODULES; i++) {
334                 mod = boot_modules[i];
335                 for (dev = mod->devices(); dev != NULL; dev = dev->next) {
336                         if (dev->preferred != preferred)
337                                 continue;
338
339                         if (mod->load(PATH_LOADER_EFI, dev, bufp, bufsize) ==
340                             EFI_SUCCESS) {
341                                 *devinfop = dev;
342                                 *modp = mod;
343                                 return (EFI_SUCCESS);
344                         }
345                 }
346         }
347
348         return (EFI_NOT_FOUND);
349 }
350
351 /*
352  * try_boot only returns if it fails to load the loader. If it succeeds
353  * it simply boots, otherwise it returns the status of last EFI call.
354  */
355 static EFI_STATUS
356 try_boot(void)
357 {
358         size_t bufsize, loadersize, cmdsize;
359         void *buf, *loaderbuf;
360         char *cmd;
361         dev_info_t *dev;
362         const boot_module_t *mod;
363         EFI_HANDLE loaderhandle;
364         EFI_LOADED_IMAGE *loaded_image;
365         EFI_STATUS status;
366
367         status = load_loader(&mod, &dev, &loaderbuf, &loadersize, TRUE);
368         if (status != EFI_SUCCESS) {
369                 status = load_loader(&mod, &dev, &loaderbuf, &loadersize,
370                     FALSE);
371                 if (status != EFI_SUCCESS) {
372                         printf("Failed to load '%s'\n", PATH_LOADER_EFI);
373                         return (status);
374                 }
375         }
376
377         /*
378          * Read in and parse the command line from /boot.config or /boot/config,
379          * if present. We'll pass it the next stage via a simple ASCII
380          * string. loader.efi has a hack for ASCII strings, so we'll use that to
381          * keep the size down here. We only try to read the alternate file if
382          * we get EFI_NOT_FOUND because all other errors mean that the boot_module
383          * had troubles with the filesystem. We could return early, but we'll let
384          * loading the actual kernel sort all that out. Since these files are
385          * optional, we don't report errors in trying to read them.
386          */
387         cmd = NULL;
388         cmdsize = 0;
389         status = mod->load(PATH_DOTCONFIG, dev, &buf, &bufsize);
390         if (status == EFI_NOT_FOUND)
391                 status = mod->load(PATH_CONFIG, dev, &buf, &bufsize);
392         if (status == EFI_SUCCESS) {
393                 cmdsize = bufsize + 1;
394                 cmd = malloc(cmdsize);
395                 if (cmd == NULL)
396                         goto errout;
397                 memcpy(cmd, buf, bufsize);
398                 cmd[bufsize] = '\0';
399                 free(buf);
400                 buf = NULL;
401         }
402
403         if ((status = bs->LoadImage(TRUE, image, devpath_last(dev->devpath),
404             loaderbuf, loadersize, &loaderhandle)) != EFI_SUCCESS) {
405                 printf("Failed to load image provided by %s, size: %zu, (%lu)\n",
406                      mod->name, loadersize, EFI_ERROR_CODE(status));
407                 goto errout;
408         }
409
410         if ((status = bs->HandleProtocol(loaderhandle, &LoadedImageGUID,
411             (VOID**)&loaded_image)) != EFI_SUCCESS) {
412                 printf("Failed to query LoadedImage provided by %s (%lu)\n",
413                     mod->name, EFI_ERROR_CODE(status));
414                 goto errout;
415         }
416
417         if (cmd != NULL)
418                 printf("    command args: %s\n", cmd);
419
420         loaded_image->DeviceHandle = dev->devhandle;
421         loaded_image->LoadOptionsSize = cmdsize;
422         loaded_image->LoadOptions = cmd;
423
424         DPRINTF("Starting '%s' in 5 seconds...", PATH_LOADER_EFI);
425         DSTALL(1000000);
426         DPRINTF(".");
427         DSTALL(1000000);
428         DPRINTF(".");
429         DSTALL(1000000);
430         DPRINTF(".");
431         DSTALL(1000000);
432         DPRINTF(".");
433         DSTALL(1000000);
434         DPRINTF(".\n");
435
436         if ((status = bs->StartImage(loaderhandle, NULL, NULL)) !=
437             EFI_SUCCESS) {
438                 printf("Failed to start image provided by %s (%lu)\n",
439                     mod->name, EFI_ERROR_CODE(status));
440                 loaded_image->LoadOptionsSize = 0;
441                 loaded_image->LoadOptions = NULL;
442         }
443
444 errout:
445         if (cmd != NULL)
446                 free(cmd);
447         if (buf != NULL)
448                 free(buf);
449         if (loaderbuf != NULL)
450                 free(loaderbuf);
451
452         return (status);
453 }
454
455 /*
456  * probe_handle determines if the passed handle represents a logical partition
457  * if it does it uses each module in order to probe it and if successful it
458  * returns EFI_SUCCESS.
459  */
460 static EFI_STATUS
461 probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath, BOOLEAN *preferred)
462 {
463         dev_info_t *devinfo;
464         EFI_BLOCK_IO *blkio;
465         EFI_DEVICE_PATH *devpath;
466         EFI_STATUS status;
467         UINTN i;
468
469         /* Figure out if we're dealing with an actual partition. */
470         status = bs->HandleProtocol(h, &DevicePathGUID, (void **)&devpath);
471         if (status == EFI_UNSUPPORTED)
472                 return (status);
473
474         if (status != EFI_SUCCESS) {
475                 DPRINTF("\nFailed to query DevicePath (%lu)\n",
476                     EFI_ERROR_CODE(status));
477                 return (status);
478         }
479
480         DPRINTF("probing: %s\n", devpath_str(devpath));
481
482         status = bs->HandleProtocol(h, &BlockIoProtocolGUID, (void **)&blkio);
483         if (status == EFI_UNSUPPORTED)
484                 return (status);
485
486         if (status != EFI_SUCCESS) {
487                 DPRINTF("\nFailed to query BlockIoProtocol (%lu)\n",
488                     EFI_ERROR_CODE(status));
489                 return (status);
490         }
491
492         if (!blkio->Media->LogicalPartition)
493                 return (EFI_UNSUPPORTED);
494
495         *preferred = device_paths_match(imgpath, devpath);
496
497         /* Run through each module, see if it can load this partition */
498         for (i = 0; i < NUM_BOOT_MODULES; i++) {
499                 if ((status = bs->AllocatePool(EfiLoaderData,
500                     sizeof(*devinfo), (void **)&devinfo)) !=
501                     EFI_SUCCESS) {
502                         DPRINTF("\nFailed to allocate devinfo (%lu)\n",
503                             EFI_ERROR_CODE(status));
504                         continue;
505                 }
506                 devinfo->dev = blkio;
507                 devinfo->devpath = devpath;
508                 devinfo->devhandle = h;
509                 devinfo->devdata = NULL;
510                 devinfo->preferred = *preferred;
511                 devinfo->next = NULL;
512
513                 status = boot_modules[i]->probe(devinfo);
514                 if (status == EFI_SUCCESS)
515                         return (EFI_SUCCESS);
516                 (void)bs->FreePool(devinfo);
517         }
518
519         return (EFI_UNSUPPORTED);
520 }
521
522 /*
523  * probe_handle_status calls probe_handle and outputs the returned status
524  * of the call.
525  */
526 static void
527 probe_handle_status(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath)
528 {
529         EFI_STATUS status;
530         BOOLEAN preferred;
531
532         preferred = FALSE;
533         status = probe_handle(h, imgpath, &preferred);
534         
535         DPRINTF("probe: ");
536         switch (status) {
537         case EFI_UNSUPPORTED:
538                 printf(".");
539                 DPRINTF(" not supported\n");
540                 break;
541         case EFI_SUCCESS:
542                 if (preferred) {
543                         printf("%c", '*');
544                         DPRINTF(" supported (preferred)\n");
545                 } else {
546                         printf("%c", '+');
547                         DPRINTF(" supported\n");
548                 }
549                 break;
550         default:
551                 printf("x");
552                 DPRINTF(" error (%lu)\n", EFI_ERROR_CODE(status));
553                 break;
554         }
555         DSTALL(500000);
556 }
557
558 EFI_STATUS
559 efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab)
560 {
561         EFI_HANDLE *handles;
562         EFI_LOADED_IMAGE *img;
563         EFI_DEVICE_PATH *imgpath;
564         EFI_STATUS status;
565         EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
566         SIMPLE_TEXT_OUTPUT_INTERFACE *conout = NULL;
567         UINTN i, max_dim, best_mode, cols, rows, hsize, nhandles;
568
569         /* Basic initialization*/
570         systab = Xsystab;
571         image = Ximage;
572         bs = Xsystab->BootServices;
573
574         /* Set up the console, so printf works. */
575         status = bs->LocateProtocol(&ConsoleControlGUID, NULL,
576             (VOID **)&ConsoleControl);
577         if (status == EFI_SUCCESS)
578                 (void)ConsoleControl->SetMode(ConsoleControl,
579                     EfiConsoleControlScreenText);
580         /*
581          * Reset the console and find the best text mode.
582          */
583         conout = systab->ConOut;
584         conout->Reset(conout, TRUE);
585         max_dim = best_mode = 0;
586         for (i = 0; ; i++) {
587                 status = conout->QueryMode(conout, i, &cols, &rows);
588                 if (EFI_ERROR(status))
589                         break;
590                 if (cols * rows > max_dim) {
591                         max_dim = cols * rows;
592                         best_mode = i;
593                 }
594         }
595         if (max_dim > 0)
596                 conout->SetMode(conout, best_mode);
597         conout->EnableCursor(conout, TRUE);
598         conout->ClearScreen(conout);
599
600         printf("\n>> FreeBSD EFI boot block\n");
601         printf("   Loader path: %s\n\n", PATH_LOADER_EFI);
602         printf("   Initializing modules:");
603         for (i = 0; i < NUM_BOOT_MODULES; i++) {
604                 printf(" %s", boot_modules[i]->name);
605                 if (boot_modules[i]->init != NULL)
606                         boot_modules[i]->init();
607         }
608         putchar('\n');
609
610         /* Get all the device handles */
611         hsize = (UINTN)NUM_HANDLES_INIT * sizeof(EFI_HANDLE);
612         if ((status = bs->AllocatePool(EfiLoaderData, hsize, (void **)&handles))
613             != EFI_SUCCESS)
614                 panic("Failed to allocate %d handles (%lu)", NUM_HANDLES_INIT,
615                     EFI_ERROR_CODE(status));
616
617         status = bs->LocateHandle(ByProtocol, &BlockIoProtocolGUID, NULL,
618             &hsize, handles);
619         switch (status) {
620         case EFI_SUCCESS:
621                 break;
622         case EFI_BUFFER_TOO_SMALL:
623                 (void)bs->FreePool(handles);
624                 if ((status = bs->AllocatePool(EfiLoaderData, hsize,
625                     (void **)&handles)) != EFI_SUCCESS) {
626                         panic("Failed to allocate %zu handles (%lu)", hsize /
627                             sizeof(*handles), EFI_ERROR_CODE(status));
628                 }
629                 status = bs->LocateHandle(ByProtocol, &BlockIoProtocolGUID,
630                     NULL, &hsize, handles);
631                 if (status != EFI_SUCCESS)
632                         panic("Failed to get device handles (%lu)\n",
633                             EFI_ERROR_CODE(status));
634                 break;
635         default:
636                 panic("Failed to get device handles (%lu)",
637                     EFI_ERROR_CODE(status));
638         }
639
640         /* Scan all partitions, probing with all modules. */
641         nhandles = hsize / sizeof(*handles);
642         printf("   Probing %zu block devices...", nhandles);
643         DPRINTF("\n");
644
645         /* Determine the devpath of our image so we can prefer it. */
646         status = bs->HandleProtocol(image, &LoadedImageGUID, (VOID**)&img);
647         imgpath = NULL;
648         if (status == EFI_SUCCESS) {
649                 status = bs->HandleProtocol(img->DeviceHandle, &DevicePathGUID,
650                     (void **)&imgpath);
651                 if (status != EFI_SUCCESS)
652                         DPRINTF("Failed to get image DevicePath (%lu)\n",
653                             EFI_ERROR_CODE(status));
654                 DPRINTF("boot1 imagepath: %s\n", devpath_str(imgpath));
655         }
656
657         for (i = 0; i < nhandles; i++)
658                 probe_handle_status(handles[i], imgpath);
659         printf(" done\n");
660
661         /* Status summary. */
662         for (i = 0; i < NUM_BOOT_MODULES; i++) {
663                 printf("    ");
664                 boot_modules[i]->status();
665         }
666
667         try_boot();
668
669         /* If we get here, we're out of luck... */
670         panic("No bootable partitions found!");
671 }
672
673 /*
674  * add_device adds a device to the passed devinfo list.
675  */
676 void
677 add_device(dev_info_t **devinfop, dev_info_t *devinfo)
678 {
679         dev_info_t *dev;
680
681         if (*devinfop == NULL) {
682                 *devinfop = devinfo;
683                 return;
684         }
685
686         for (dev = *devinfop; dev->next != NULL; dev = dev->next)
687                 ;
688
689         dev->next = devinfo;
690 }
691
692 void
693 panic(const char *fmt, ...)
694 {
695         va_list ap;
696
697         printf("panic: ");
698         va_start(ap, fmt);
699         vprintf(fmt, ap);
700         va_end(ap);
701         printf("\n");
702
703         while (1) {}
704 }
705
706 void
707 putchar(int c)
708 {
709         CHAR16 buf[2];
710
711         if (c == '\n') {
712                 buf[0] = '\r';
713                 buf[1] = 0;
714                 systab->ConOut->OutputString(systab->ConOut, buf);
715         }
716         buf[0] = c;
717         buf[1] = 0;
718         systab->ConOut->OutputString(systab->ConOut, buf);
719 }