Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / interface / efi / efi_debug.c
1 /*
2  * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 /**
23  * @file
24  *
25  * EFI debugging utilities
26  *
27  */
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <ipxe/uuid.h>
33 #include <ipxe/base16.h>
34 #include <ipxe/efi/efi.h>
35 #include <ipxe/efi/efi_utils.h>
36 #include <ipxe/efi/Protocol/ComponentName.h>
37 #include <ipxe/efi/Protocol/ComponentName2.h>
38 #include <ipxe/efi/Protocol/DevicePathToText.h>
39 #include <ipxe/efi/IndustryStandard/PeImage.h>
40
41 /** Device path to text protocol */
42 static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
43 EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
44
45 /** Iscsi4Dxe module GUID */
46 static EFI_GUID efi_iscsi4_dxe_guid = {
47         0x4579b72d, 0x7ec4, 0x4dd4,
48         { 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7 }
49 };
50
51 /** VlanConfigDxe module GUID */
52 static EFI_GUID efi_vlan_config_dxe_guid = {
53         0xe4f61863, 0xfe2c, 0x4b56,
54         { 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf }
55 };
56
57 /** A well-known GUID */
58 struct efi_well_known_guid {
59         /** GUID */
60         EFI_GUID *guid;
61         /** Name */
62         const char *name;
63 };
64
65 /** Well-known GUIDs */
66 static struct efi_well_known_guid efi_well_known_guids[] = {
67         { &efi_arp_protocol_guid,
68           "Arp" },
69         { &efi_arp_service_binding_protocol_guid,
70           "ArpSb" },
71         { &efi_block_io_protocol_guid,
72           "BlockIo" },
73         { &efi_bus_specific_driver_override_protocol_guid,
74           "BusSpecificDriverOverride" },
75         { &efi_component_name_protocol_guid,
76           "ComponentName" },
77         { &efi_component_name2_protocol_guid,
78           "ComponentName2" },
79         { &efi_device_path_protocol_guid,
80           "DevicePath" },
81         { &efi_driver_binding_protocol_guid,
82           "DriverBinding" },
83         { &efi_dhcp4_protocol_guid,
84           "Dhcp4" },
85         { &efi_dhcp4_service_binding_protocol_guid,
86           "Dhcp4Sb" },
87         { &efi_disk_io_protocol_guid,
88           "DiskIo" },
89         { &efi_graphics_output_protocol_guid,
90           "GraphicsOutput" },
91         { &efi_hii_config_access_protocol_guid,
92           "HiiConfigAccess" },
93         { &efi_ip4_protocol_guid,
94           "Ip4" },
95         { &efi_ip4_config_protocol_guid,
96           "Ip4Config" },
97         { &efi_ip4_service_binding_protocol_guid,
98           "Ip4Sb" },
99         { &efi_iscsi4_dxe_guid,
100           "IScsi4Dxe" },
101         { &efi_load_file_protocol_guid,
102           "LoadFile" },
103         { &efi_load_file2_protocol_guid,
104           "LoadFile2" },
105         { &efi_loaded_image_protocol_guid,
106           "LoadedImage" },
107         { &efi_loaded_image_device_path_protocol_guid,
108           "LoadedImageDevicePath"},
109         { &efi_managed_network_protocol_guid,
110           "ManagedNetwork" },
111         { &efi_managed_network_service_binding_protocol_guid,
112           "ManagedNetworkSb" },
113         { &efi_mtftp4_protocol_guid,
114           "Mtftp4" },
115         { &efi_mtftp4_service_binding_protocol_guid,
116           "Mtftp4Sb" },
117         { &efi_nii_protocol_guid,
118           "Nii" },
119         { &efi_nii31_protocol_guid,
120           "Nii31" },
121         { &efi_pci_io_protocol_guid,
122           "PciIo" },
123         { &efi_pci_root_bridge_io_protocol_guid,
124           "PciRootBridgeIo" },
125         { &efi_pxe_base_code_protocol_guid,
126           "PxeBaseCode" },
127         { &efi_simple_file_system_protocol_guid,
128           "SimpleFileSystem" },
129         { &efi_simple_network_protocol_guid,
130           "SimpleNetwork" },
131         { &efi_tcg_protocol_guid,
132           "Tcg" },
133         { &efi_tcp4_protocol_guid,
134           "Tcp4" },
135         { &efi_tcp4_service_binding_protocol_guid,
136           "Tcp4Sb" },
137         { &efi_udp4_protocol_guid,
138           "Udp4" },
139         { &efi_udp4_service_binding_protocol_guid,
140           "Udp4Sb" },
141         { &efi_vlan_config_protocol_guid,
142           "VlanConfig" },
143         { &efi_vlan_config_dxe_guid,
144           "VlanConfigDxe" },
145 };
146
147 /**
148  * Convert GUID to a printable string
149  *
150  * @v guid              GUID
151  * @ret string          Printable string
152  */
153 const char * efi_guid_ntoa ( EFI_GUID *guid ) {
154         union {
155                 union uuid uuid;
156                 EFI_GUID guid;
157         } u;
158         unsigned int i;
159
160         /* Sanity check */
161         if ( ! guid )
162                 return NULL;
163
164         /* Check for a match against well-known GUIDs */
165         for ( i = 0 ; i < ( sizeof ( efi_well_known_guids ) /
166                             sizeof ( efi_well_known_guids[0] ) ) ; i++ ) {
167                 if ( memcmp ( guid, efi_well_known_guids[i].guid,
168                               sizeof ( *guid ) ) == 0 ) {
169                         return efi_well_known_guids[i].name;
170                 }
171         }
172
173         /* Convert GUID to standard endianness */
174         memcpy ( &u.guid, guid, sizeof ( u.guid ) );
175         uuid_mangle ( &u.uuid );
176         return uuid_ntoa ( &u.uuid );
177 }
178
179 /**
180  * Name protocol open attributes
181  *
182  * @v attributes        Protocol open attributes
183  * @ret name            Protocol open attributes name
184  *
185  * Returns a (static) string with characters for each set bit
186  * corresponding to BY_(H)ANDLE_PROTOCOL, (G)ET_PROTOCOL,
187  * (T)EST_PROTOCOL, BY_(C)HILD_CONTROLLER, BY_(D)RIVER, and
188  * E(X)CLUSIVE.
189  */
190 static const char * efi_open_attributes_name ( unsigned int attributes ) {
191         static char attribute_chars[] = "HGTCDX";
192         static char name[ sizeof ( attribute_chars ) ];
193         char *tmp = name;
194         unsigned int i;
195
196         for ( i = 0 ; i < ( sizeof ( attribute_chars ) - 1 ) ; i++ ) {
197                 if ( attributes & ( 1 << i ) )
198                         *(tmp++) = attribute_chars[i];
199         }
200         *tmp = '\0';
201
202         return name;
203 }
204
205 /**
206  * Print list of openers of a given protocol on a given handle
207  *
208  * @v handle            EFI handle
209  * @v protocol          Protocol GUID
210  */
211 void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ) {
212         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
213         EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *openers;
214         EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener;
215         UINTN count;
216         unsigned int i;
217         EFI_STATUS efirc;
218         int rc;
219
220         /* Sanity check */
221         if ( ( ! handle ) || ( ! protocol ) ) {
222                 printf ( "EFI could not retrieve openers for %s on %p\n",
223                          efi_guid_ntoa ( protocol ), handle );
224                 return;
225         }
226
227         /* Retrieve list of openers */
228         if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
229                                                      &count ) ) != 0 ) {
230                 rc = -EEFI ( efirc );
231                 printf ( "EFI could not retrieve openers for %s on %p: %s\n",
232                          efi_guid_ntoa ( protocol ), handle, strerror ( rc ) );
233                 return;
234         }
235
236         /* Dump list of openers */
237         for ( i = 0 ; i < count ; i++ ) {
238                 opener = &openers[i];
239                 printf ( "HANDLE %p %s %s opened %dx (%s)",
240                          handle, efi_handle_name ( handle ),
241                          efi_guid_ntoa ( protocol ), opener->OpenCount,
242                          efi_open_attributes_name ( opener->Attributes ) );
243                 printf ( " by %p %s", opener->AgentHandle,
244                          efi_handle_name ( opener->AgentHandle ) );
245                 if ( opener->ControllerHandle == handle ) {
246                         printf ( "\n" );
247                 } else {
248                         printf ( " for %p %s\n", opener->ControllerHandle,
249                                  efi_handle_name ( opener->ControllerHandle ) );
250                 }
251         }
252
253         /* Free list */
254         bs->FreePool ( openers );
255 }
256
257 /**
258  * Print list of protocol handlers attached to a handle
259  *
260  * @v handle            EFI handle
261  */
262 void dbg_efi_protocols ( EFI_HANDLE handle ) {
263         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
264         EFI_GUID **protocols;
265         EFI_GUID *protocol;
266         UINTN count;
267         unsigned int i;
268         EFI_STATUS efirc;
269         int rc;
270
271         /* Sanity check */
272         if ( ! handle ) {
273                 printf ( "EFI could not retrieve protocols for %p\n", handle );
274                 return;
275         }
276
277         /* Retrieve list of protocols */
278         if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
279                                                 &count ) ) != 0 ) {
280                 rc = -EEFI ( efirc );
281                 printf ( "EFI could not retrieve protocols for %p: %s\n",
282                          handle, strerror ( rc ) );
283                 return;
284         }
285
286         /* Dump list of protocols */
287         for ( i = 0 ; i < count ; i++ ) {
288                 protocol = protocols[i];
289                 printf ( "HANDLE %p %s %s supported\n",
290                          handle, efi_handle_name ( handle ),
291                          efi_guid_ntoa ( protocol ) );
292                 dbg_efi_openers ( handle, protocol );
293         }
294
295         /* Free list */
296         bs->FreePool ( protocols );
297 }
298
299 /**
300  * Get textual representation of device path
301  *
302  * @v path              Device path
303  * @ret text            Textual representation of device path, or NULL
304  */
305 const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
306         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
307         static char text[256];
308         void *start;
309         void *end;
310         size_t max_len;
311         size_t len;
312         CHAR16 *wtext;
313
314         /* Sanity checks */
315         if ( ! path ) {
316                 DBG ( "[NULL DevicePath]" );
317                 return NULL;
318         }
319
320         /* If we have no DevicePathToText protocol then use a raw hex string */
321         if ( ! efidpt ) {
322                 DBG ( "[No DevicePathToText]" );
323                 start = path;
324                 end = efi_devpath_end ( path );
325                 len = ( end - start );
326                 max_len = ( ( sizeof ( text ) - 1 /* NUL */ ) / 2 /* "xx" */ );
327                 if ( len > max_len )
328                         len = max_len;
329                 base16_encode ( start, len, text );
330                 return text;
331         }
332
333         /* Convert path to a textual representation */
334         wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
335         if ( ! wtext )
336                 return NULL;
337
338         /* Store path in buffer */
339         snprintf ( text, sizeof ( text ), "%ls", wtext );
340
341         /* Free path */
342         bs->FreePool ( wtext );
343
344         return text;
345 }
346
347 /**
348  * Get driver name
349  *
350  * @v wtf               Component name protocol
351  * @ret name            Driver name, or NULL
352  */
353 static const char * efi_driver_name ( EFI_COMPONENT_NAME_PROTOCOL *wtf ) {
354         static char name[64];
355         CHAR16 *driver_name;
356         EFI_STATUS efirc;
357
358         /* Sanity check */
359         if ( ! wtf ) {
360                 DBG ( "[NULL ComponentName]" );
361                 return NULL;
362         }
363
364         /* Try "eng" first; if that fails then try the first language */
365         if ( ( ( efirc = wtf->GetDriverName ( wtf, "eng",
366                                               &driver_name ) ) != 0 ) &&
367              ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
368                                               &driver_name ) ) != 0 ) ) {
369                 return NULL;
370         }
371
372         /* Convert name from CHAR16 to char */
373         snprintf ( name, sizeof ( name ), "%ls", driver_name );
374         return name;
375 }
376
377 /**
378  * Get driver name
379  *
380  * @v wtf               Component name protocol
381  * @ret name            Driver name, or NULL
382  */
383 static const char * efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *wtf ) {
384         static char name[64];
385         CHAR16 *driver_name;
386         EFI_STATUS efirc;
387
388         /* Sanity check */
389         if ( ! wtf ) {
390                 DBG ( "[NULL ComponentName2]" );
391                 return NULL;
392         }
393
394         /* Try "en" first; if that fails then try the first language */
395         if ( ( ( efirc = wtf->GetDriverName ( wtf, "en",
396                                               &driver_name ) ) != 0 ) &&
397              ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
398                                               &driver_name ) ) != 0 ) ) {
399                 return NULL;
400         }
401
402         /* Convert name from CHAR16 to char */
403         snprintf ( name, sizeof ( name ), "%ls", driver_name );
404         return name;
405 }
406
407 /**
408  * Get PE/COFF debug filename
409  *
410  * @v loaded            Loaded image
411  * @ret name            PE/COFF debug filename, or NULL
412  */
413 static const char *
414 efi_pecoff_debug_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
415         static char buf[32];
416         EFI_IMAGE_DOS_HEADER *dos;
417         EFI_IMAGE_OPTIONAL_HEADER_UNION *pe;
418         EFI_IMAGE_OPTIONAL_HEADER32 *opt32;
419         EFI_IMAGE_OPTIONAL_HEADER64 *opt64;
420         EFI_IMAGE_DATA_DIRECTORY *datadir;
421         EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *debug;
422         EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *codeview_nb10;
423         EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY *codeview_rsds;
424         EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY *codeview_mtoc;
425         uint16_t dos_magic;
426         uint32_t pe_magic;
427         uint16_t opt_magic;
428         uint32_t codeview_magic;
429         size_t max_len;
430         char *name;
431         char *tmp;
432
433         /* Sanity check */
434         if ( ! loaded ) {
435                 DBG ( "[NULL LoadedImage]" );
436                 return NULL;
437         }
438
439         /* Parse DOS header */
440         dos = loaded->ImageBase;
441         if ( ! dos ) {
442                 DBG ( "[Missing DOS header]" );
443                 return NULL;
444         }
445         dos_magic = dos->e_magic;
446         if ( dos_magic != EFI_IMAGE_DOS_SIGNATURE ) {
447                 DBG ( "[Bad DOS signature %#04x]", dos_magic );
448                 return NULL;
449         }
450         pe = ( loaded->ImageBase + dos->e_lfanew );
451
452         /* Parse PE header */
453         pe_magic = pe->Pe32.Signature;
454         if ( pe_magic != EFI_IMAGE_NT_SIGNATURE ) {
455                 DBG ( "[Bad PE signature %#08x]", pe_magic );
456                 return NULL;
457         }
458         opt32 = &pe->Pe32.OptionalHeader;
459         opt64 = &pe->Pe32Plus.OptionalHeader;
460         opt_magic = opt32->Magic;
461         if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ) {
462                 datadir = opt32->DataDirectory;
463         } else if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC ) {
464                 datadir = opt64->DataDirectory;
465         } else {
466                 DBG ( "[Bad optional header signature %#04x]", opt_magic );
467                 return NULL;
468         }
469
470         /* Parse data directory entry */
471         if ( ! datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress ) {
472                 DBG ( "[Empty debug directory entry]" );
473                 return NULL;
474         }
475         debug = ( loaded->ImageBase +
476                   datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress );
477
478         /* Parse debug directory entry */
479         if ( debug->Type != EFI_IMAGE_DEBUG_TYPE_CODEVIEW ) {
480                 DBG ( "[Not a CodeView debug directory entry (type %d)]",
481                       debug->Type );
482                 return NULL;
483         }
484         codeview_nb10 = ( loaded->ImageBase + debug->RVA );
485         codeview_rsds = ( loaded->ImageBase + debug->RVA );
486         codeview_mtoc = ( loaded->ImageBase + debug->RVA );
487         codeview_magic = codeview_nb10->Signature;
488
489         /* Parse CodeView entry */
490         if ( codeview_magic == CODEVIEW_SIGNATURE_NB10 ) {
491                 name = ( ( void * ) ( codeview_nb10 + 1 ) );
492         } else if ( codeview_magic == CODEVIEW_SIGNATURE_RSDS ) {
493                 name = ( ( void * ) ( codeview_rsds + 1 ) );
494         } else if ( codeview_magic == CODEVIEW_SIGNATURE_MTOC ) {
495                 name = ( ( void * ) ( codeview_mtoc + 1 ) );
496         } else {
497                 DBG ( "[Bad CodeView signature %#08x]", codeview_magic );
498                 return NULL;
499         }
500
501         /* Sanity check - avoid scanning endlessly through memory */
502         max_len = EFI_PAGE_SIZE; /* Reasonably sane */
503         if ( strnlen ( name, max_len ) == max_len ) {
504                 DBG ( "[Excessively long or invalid CodeView name]" );
505                 return NULL;
506         }
507
508         /* Skip any directory components.  We cannot modify this data
509          * or create a temporary buffer, so do not use basename().
510          */
511         while ( ( ( tmp = strchr ( name, '/' ) ) != NULL ) ||
512                 ( ( tmp = strchr ( name, '\\' ) ) != NULL ) ) {
513                 name = ( tmp + 1 );
514         }
515
516         /* Copy base name to buffer */
517         snprintf ( buf, sizeof ( buf ), "%s", name );
518
519         /* Strip file suffix, if present */
520         if ( ( tmp = strrchr ( name, '.' ) ) != NULL )
521                 *tmp = '\0';
522
523         return name;
524 }
525
526 /**
527  * Get initial loaded image name
528  *
529  * @v loaded            Loaded image
530  * @ret name            Initial loaded image name, or NULL
531  */
532 static const char *
533 efi_first_loaded_image_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
534
535         /* Sanity check */
536         if ( ! loaded ) {
537                 DBG ( "[NULL LoadedImage]" );
538                 return NULL;
539         }
540
541         return ( ( loaded->ParentHandle == NULL ) ? "DxeCore(?)" : NULL );
542 }
543
544 /**
545  * Get loaded image name from file path
546  *
547  * @v loaded            Loaded image
548  * @ret name            Loaded image name, or NULL
549  */
550 static const char *
551 efi_loaded_image_filepath_name ( EFI_LOADED_IMAGE_PROTOCOL *loaded ) {
552
553         /* Sanity check */
554         if ( ! loaded ) {
555                 DBG ( "[NULL LoadedImage]" );
556                 return NULL;
557         }
558
559         return efi_devpath_text ( loaded->FilePath );
560 }
561
562 /** An EFI handle name type */
563 struct efi_handle_name_type {
564         /** Protocol */
565         EFI_GUID *protocol;
566         /**
567          * Get name
568          *
569          * @v interface         Protocol interface
570          * @ret name            Name of handle, or NULL on failure
571          */
572         const char * ( * name ) ( void *interface );
573 };
574
575 /**
576  * Define an EFI handle name type
577  *
578  * @v protocol          Protocol interface
579  * @v name              Method to get name
580  * @ret type            EFI handle name type
581  */
582 #define EFI_HANDLE_NAME_TYPE( protocol, name ) {        \
583         (protocol),                                     \
584         ( const char * ( * ) ( void * ) ) (name),       \
585         }
586
587 /** EFI handle name types */
588 static struct efi_handle_name_type efi_handle_name_types[] = {
589         /* Device path */
590         EFI_HANDLE_NAME_TYPE ( &efi_device_path_protocol_guid,
591                                efi_devpath_text ),
592         /* Driver name (for driver image handles) */
593         EFI_HANDLE_NAME_TYPE ( &efi_component_name2_protocol_guid,
594                                efi_driver_name2 ),
595         /* Driver name (via obsolete original ComponentName protocol) */
596         EFI_HANDLE_NAME_TYPE ( &efi_component_name_protocol_guid,
597                                efi_driver_name ),
598         /* PE/COFF debug filename (for image handles) */
599         EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid,
600                                efi_pecoff_debug_name ),
601         /* Loaded image device path (for image handles) */
602         EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_device_path_protocol_guid,
603                                efi_devpath_text ),
604         /* First loaded image name (for the DxeCore image) */
605         EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid,
606                                efi_first_loaded_image_name ),
607         /* Handle's loaded image file path (for image handles) */
608         EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid,
609                                efi_loaded_image_filepath_name ),
610 };
611
612 /**
613  * Get name of an EFI handle
614  *
615  * @v handle            EFI handle
616  * @ret text            Name of handle, or NULL
617  */
618 const char * efi_handle_name ( EFI_HANDLE handle ) {
619         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
620         struct efi_handle_name_type *type;
621         unsigned int i;
622         void *interface;
623         const char *name;
624         EFI_STATUS efirc;
625
626         /* Fail immediately for NULL handles */
627         if ( ! handle )
628                 return NULL;
629
630         /* Try each name type in turn */
631         for ( i = 0 ; i < ( sizeof ( efi_handle_name_types ) /
632                             sizeof ( efi_handle_name_types[0] ) ) ; i++ ) {
633                 type = &efi_handle_name_types[i];
634                 DBG2 ( "<%d", i );
635
636                 /* Try to open the applicable protocol */
637                 efirc = bs->OpenProtocol ( handle, type->protocol, &interface,
638                                            efi_image_handle, handle,
639                                            EFI_OPEN_PROTOCOL_GET_PROTOCOL );
640                 if ( efirc != 0 ) {
641                         DBG2 ( ">" );
642                         continue;
643                 }
644
645                 /* Try to get name from this protocol */
646                 DBG2 ( "-" );
647                 name = type->name ( interface );
648                 DBG2 ( "%c", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) );
649
650                 /* Close protocol */
651                 bs->CloseProtocol ( handle, type->protocol,
652                                     efi_image_handle, handle );
653                 DBG2 ( ">" );
654
655                 /* Use this name, if possible */
656                 if ( name && name[0] )
657                         return name;
658         }
659
660         return "UNKNOWN";
661 }