iPXE
Data Structures | Defines | Functions | Variables
efi_debug.c File Reference

EFI debugging utilities. More...

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/uuid.h>
#include <ipxe/base16.h>
#include <ipxe/vsprintf.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/Protocol/ComponentName.h>
#include <ipxe/efi/Protocol/ComponentName2.h>
#include <ipxe/efi/Protocol/DevicePathToText.h>
#include <ipxe/efi/IndustryStandard/PeImage.h>

Go to the source code of this file.

Data Structures

struct  efi_well_known_guid
 A well-known GUID. More...
struct  efi_handle_name_type
 An EFI handle name type. More...

Defines

#define EFI_HANDLE_NAME_TYPE(protocol, name)
 Define an EFI handle name type.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 EFI_REQUEST_PROTOCOL (EFI_DEVICE_PATH_TO_TEXT_PROTOCOL,&efidpt)
const char * efi_guid_ntoa (EFI_GUID *guid)
 Convert GUID to a printable string.
const char * efi_locate_search_type_name (EFI_LOCATE_SEARCH_TYPE search_type)
 Name locate search type.
const char * efi_open_attributes_name (unsigned int attributes)
 Name protocol open attributes.
void dbg_efi_openers (EFI_HANDLE handle, EFI_GUID *protocol)
 Print list of openers of a given protocol on a given handle.
void dbg_efi_protocols (EFI_HANDLE handle)
 Print list of protocol handlers attached to a handle.
const char * efi_devpath_text (EFI_DEVICE_PATH_PROTOCOL *path)
 Get textual representation of device path.
static const char * efi_driver_name (EFI_COMPONENT_NAME_PROTOCOL *wtf)
 Get driver name.
static const char * efi_driver_name2 (EFI_COMPONENT_NAME2_PROTOCOL *wtf)
 Get driver name.
static const char * efi_pecoff_debug_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get PE/COFF debug filename.
static const char * efi_first_loaded_image_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get initial loaded image name.
static const char * efi_loaded_image_filepath_name (EFI_LOADED_IMAGE_PROTOCOL *loaded)
 Get loaded image name from file path.
static const char * efi_conin_name (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *input)
 Get console input handle name.
static const char * efi_conout_name (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *output)
 Get console output handle name.
const char * efi_handle_name (EFI_HANDLE handle)
 Get name of an EFI handle.

Variables

static
EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
efidpt
 Device path to text protocol.
static EFI_GUID efi_iscsi4_dxe_guid
 Iscsi4Dxe module GUID.
static EFI_GUID efi_vlan_config_dxe_guid
 VlanConfigDxe module GUID.
static struct efi_well_known_guid efi_well_known_guids []
 Well-known GUIDs.
static struct efi_handle_name_type efi_handle_name_types []
 EFI handle name types.

Detailed Description

EFI debugging utilities.

Definition in file efi_debug.c.


Define Documentation

#define EFI_HANDLE_NAME_TYPE (   protocol,
  name 
)
Value:
{       \
        (protocol),                                     \
        ( const char * ( * ) ( void * ) ) (name),       \
        }

Define an EFI handle name type.

Parameters:
protocolProtocol interface
nameMethod to get name
Return values:
typeEFI handle name type

Definition at line 672 of file efi_debug.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
const char* efi_guid_ntoa ( EFI_GUID guid)

Convert GUID to a printable string.

Parameters:
guidGUID
Return values:
stringPrintable string

Definition at line 192 of file efi_debug.c.

References efi_well_known_guids, efi_well_known_guid::guid, memcmp(), memcpy(), efi_well_known_guid::name, NULL, u, uuid_mangle(), and uuid_ntoa().

Referenced by chained_locate(), chained_supported(), dbg_efi_openers(), dbg_efi_protocols(), efi_close_protocol_wrapper(), efi_file_get_info(), efi_file_set_info(), efi_handle_name(), efi_handle_protocol_wrapper(), efi_init(), efi_install_protocol_interface_wrapper(), efi_locate_device(), efi_locate_device_path_wrapper(), efi_locate_handle_buffer_wrapper(), efi_locate_handle_wrapper(), efi_locate_protocol_wrapper(), efi_open_protocol_wrapper(), efi_protocols_per_handle_wrapper(), efi_reinstall_protocol_interface_wrapper(), and efi_uninstall_protocol_interface_wrapper().

                                                                       {
        union {
                union uuid uuid;
                EFI_GUID guid;
        } u;
        unsigned int i;

        /* Sanity check */
        if ( ! guid )
                return NULL;

        /* Check for a match against well-known GUIDs */
        for ( i = 0 ; i < ( sizeof ( efi_well_known_guids ) /
                            sizeof ( efi_well_known_guids[0] ) ) ; i++ ) {
                if ( memcmp ( guid, efi_well_known_guids[i].guid,
                              sizeof ( *guid ) ) == 0 ) {
                        return efi_well_known_guids[i].name;
                }
        }

        /* Convert GUID to standard endianness */
        memcpy ( &u.guid, guid, sizeof ( u.guid ) );
        uuid_mangle ( &u.uuid );
        return uuid_ntoa ( &u.uuid );
}

Name locate search type.

Parameters:
search_typeLocate search type
Return values:
nameLocate search type name

Definition at line 225 of file efi_debug.c.

References AllHandles, ByProtocol, ByRegisterNotify, and snprintf().

Referenced by efi_locate_handle_buffer_wrapper(), and efi_locate_handle_wrapper().

                                                                   {
        static char buf[16];

        switch ( search_type ) {
        case AllHandles :       return "AllHandles";
        case ByRegisterNotify:  return "ByRegisterNotify";
        case ByProtocol:        return "ByProtocol";
        default:
                snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", search_type );
                return buf;
        }
}
const char* efi_open_attributes_name ( unsigned int  attributes)

Name protocol open attributes.

Parameters:
attributesProtocol open attributes
Return values:
nameProtocol open attributes name

Returns a (static) string with characters for each set bit corresponding to BY_(H)ANDLE_PROTOCOL, (G)ET_PROTOCOL, (T)EST_PROTOCOL, BY_(C)HILD_CONTROLLER, BY_(D)RIVER, and E(X)CLUSIVE.

Definition at line 250 of file efi_debug.c.

References name.

Referenced by dbg_efi_openers(), and efi_open_protocol_wrapper().

                                                     {
        static char attribute_chars[] = "HGTCDX";
        static char name[ sizeof ( attribute_chars ) ];
        char *tmp = name;
        unsigned int i;

        for ( i = 0 ; i < ( sizeof ( attribute_chars ) - 1 ) ; i++ ) {
                if ( attributes & ( 1 << i ) )
                        *(tmp++) = attribute_chars[i];
        }
        *tmp = '\0';

        return name;
}
void dbg_efi_openers ( EFI_HANDLE  handle,
EFI_GUID protocol 
)

Print list of openers of a given protocol on a given handle.

Parameters:
handleEFI handle
protocolProtocol GUID

Definition at line 271 of file efi_debug.c.

References EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::AgentHandle, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::Attributes, EFI_SYSTEM_TABLE::BootServices, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::ControllerHandle, count, EEFI, efi_guid_ntoa(), efi_handle_name(), efi_open_attributes_name(), efi_systab, EFI_BOOT_SERVICES::FreePool, EFI_OPEN_PROTOCOL_INFORMATION_ENTRY::OpenCount, EFI_BOOT_SERVICES::OpenProtocolInformation, printf(), rc, and strerror().

Referenced by dbg_efi_protocols().

                                                               {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *openers;
        EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *opener;
        UINTN count;
        unsigned int i;
        EFI_STATUS efirc;
        int rc;

        /* Sanity check */
        if ( ( ! handle ) || ( ! protocol ) ) {
                printf ( "HANDLE %s could not retrieve openers for %s\n",
                         efi_handle_name ( handle ),
                         efi_guid_ntoa ( protocol ) );
                return;
        }

        /* Retrieve list of openers */
        if ( ( efirc = bs->OpenProtocolInformation ( handle, protocol, &openers,
                                                     &count ) ) != 0 ) {
                rc = -EEFI ( efirc );
                printf ( "HANDLE %s could not retrieve openers for %s: %s\n",
                         efi_handle_name ( handle ),
                         efi_guid_ntoa ( protocol ), strerror ( rc ) );
                return;
        }

        /* Dump list of openers */
        for ( i = 0 ; i < count ; i++ ) {
                opener = &openers[i];
                printf ( "HANDLE %s %s opened %dx (%s)",
                         efi_handle_name ( handle ),
                         efi_guid_ntoa ( protocol ), opener->OpenCount,
                         efi_open_attributes_name ( opener->Attributes ) );
                printf ( " by %s", efi_handle_name ( opener->AgentHandle ) );
                if ( opener->ControllerHandle == handle ) {
                        printf ( "\n" );
                } else {
                        printf ( " for %s\n",
                                 efi_handle_name ( opener->ControllerHandle ) );
                }
        }

        /* Free list */
        bs->FreePool ( openers );
}
void dbg_efi_protocols ( EFI_HANDLE  handle)

Print list of protocol handlers attached to a handle.

Parameters:
handleEFI handle

Definition at line 323 of file efi_debug.c.

References EFI_SYSTEM_TABLE::BootServices, count, dbg_efi_openers(), EEFI, efi_guid_ntoa(), efi_handle_name(), efi_systab, EFI_BOOT_SERVICES::FreePool, printf(), protocol, EFI_BOOT_SERVICES::ProtocolsPerHandle, rc, and strerror().

                                             {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        EFI_GUID **protocols;
        EFI_GUID *protocol;
        UINTN count;
        unsigned int i;
        EFI_STATUS efirc;
        int rc;

        /* Sanity check */
        if ( ! handle ) {
                printf ( "HANDLE %s could not retrieve protocols\n",
                         efi_handle_name ( handle ) );
                return;
        }

        /* Retrieve list of protocols */
        if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
                                                &count ) ) != 0 ) {
                rc = -EEFI ( efirc );
                printf ( "HANDLE %s could not retrieve protocols: %s\n",
                         efi_handle_name ( handle ), strerror ( rc ) );
                return;
        }

        /* Dump list of protocols */
        for ( i = 0 ; i < count ; i++ ) {
                protocol = protocols[i];
                printf ( "HANDLE %s %s supported\n", efi_handle_name ( handle ),
                         efi_guid_ntoa ( protocol ) );
                dbg_efi_openers ( handle, protocol );
        }

        /* Free list */
        bs->FreePool ( protocols );
}
const char* efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL path)

Get textual representation of device path.

Parameters:
pathDevice path
Return values:
textTextual representation of device path, or NULL

Definition at line 367 of file efi_debug.c.

References EFI_SYSTEM_TABLE::BootServices, EFI_DEVICE_PATH_TO_TEXT_PROTOCOL::ConvertDevicePathToText, DBG, efi_devpath_len(), efi_systab, FALSE, EFI_BOOT_SERVICES::FreePool, len, NULL, snprintf(), and TRUE.

Referenced by efi_block_boot_image(), efi_block_hook(), efi_connect_controller_wrapper(), efi_driver_start(), efi_driver_supported(), efi_load_image_wrapper(), efi_loaded_image_filepath_name(), efi_locate_device_path_wrapper(), efi_wrap(), usbio_open(), and usbio_path().

                                                    {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        static char text[256];
        size_t len;
        CHAR16 *wtext;

        /* Sanity checks */
        if ( ! path ) {
                DBG ( "[NULL DevicePath]" );
                return NULL;
        }

        /* If we have no DevicePathToText protocol then use a raw hex string */
        if ( ! efidpt ) {
                DBG ( "[No DevicePathToText]" );
                len = efi_devpath_len ( path );
                base16_encode ( path, len, text, sizeof ( text ) );
                return text;
        }

        /* Convert path to a textual representation */
        wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
        if ( ! wtext )
                return NULL;

        /* Store path in buffer */
        snprintf ( text, sizeof ( text ), "%ls", wtext );

        /* Free path */
        bs->FreePool ( wtext );

        return text;
}
static const char* efi_driver_name ( EFI_COMPONENT_NAME_PROTOCOL wtf) [static]

Get driver name.

Parameters:
wtfComponent name protocol
Return values:
nameDriver name, or NULL

Definition at line 407 of file efi_debug.c.

References DBG, _EFI_COMPONENT_NAME_PROTOCOL::GetDriverName, name, NULL, snprintf(), and _EFI_COMPONENT_NAME_PROTOCOL::SupportedLanguages.

                                                                         {
        static char name[64];
        CHAR16 *driver_name;
        EFI_STATUS efirc;

        /* Sanity check */
        if ( ! wtf ) {
                DBG ( "[NULL ComponentName]" );
                return NULL;
        }

        /* Try "eng" first; if that fails then try the first language */
        if ( ( ( efirc = wtf->GetDriverName ( wtf, "eng",
                                              &driver_name ) ) != 0 ) &&
             ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
                                              &driver_name ) ) != 0 ) ) {
                return NULL;
        }

        /* Convert name from CHAR16 to char */
        snprintf ( name, sizeof ( name ), "%ls", driver_name );
        return name;
}
static const char* efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL wtf) [static]

Get driver name.

Parameters:
wtfComponent name protocol
Return values:
nameDriver name, or NULL

Definition at line 437 of file efi_debug.c.

References DBG, _EFI_COMPONENT_NAME2_PROTOCOL::GetDriverName, name, NULL, snprintf(), and _EFI_COMPONENT_NAME2_PROTOCOL::SupportedLanguages.

                                                                           {
        static char name[64];
        CHAR16 *driver_name;
        EFI_STATUS efirc;

        /* Sanity check */
        if ( ! wtf ) {
                DBG ( "[NULL ComponentName2]" );
                return NULL;
        }

        /* Try "en" first; if that fails then try the first language */
        if ( ( ( efirc = wtf->GetDriverName ( wtf, "en",
                                              &driver_name ) ) != 0 ) &&
             ( ( efirc = wtf->GetDriverName ( wtf, wtf->SupportedLanguages,
                                              &driver_name ) ) != 0 ) ) {
                return NULL;
        }

        /* Convert name from CHAR16 to char */
        snprintf ( name, sizeof ( name ), "%ls", driver_name );
        return name;
}
static const char* efi_pecoff_debug_name ( EFI_LOADED_IMAGE_PROTOCOL loaded) [static]

Get PE/COFF debug filename.

Parameters:
loadedLoaded image
Return values:
namePE/COFF debug filename, or NULL

Definition at line 468 of file efi_debug.c.

References CODEVIEW_SIGNATURE_MTOC, CODEVIEW_SIGNATURE_NB10, CODEVIEW_SIGNATURE_RSDS, EFI_IMAGE_OPTIONAL_HEADER32::DataDirectory, EFI_IMAGE_OPTIONAL_HEADER64::DataDirectory, DBG, EFI_IMAGE_DOS_HEADER::e_lfanew, EFI_IMAGE_DOS_HEADER::e_magic, EFI_IMAGE_DEBUG_TYPE_CODEVIEW, EFI_IMAGE_DIRECTORY_ENTRY_DEBUG, EFI_IMAGE_DOS_SIGNATURE, EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC, EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC, EFI_IMAGE_NT_SIGNATURE, EFI_PAGE_SIZE, EFI_LOADED_IMAGE_PROTOCOL::ImageBase, EFI_IMAGE_OPTIONAL_HEADER32::Magic, max_len, name, NULL, EFI_IMAGE_NT_HEADERS32::OptionalHeader, EFI_IMAGE_NT_HEADERS64::OptionalHeader, EFI_IMAGE_OPTIONAL_HEADER_UNION::Pe32, EFI_IMAGE_OPTIONAL_HEADER_UNION::Pe32Plus, EFI_IMAGE_DEBUG_DIRECTORY_ENTRY::RVA, EFI_IMAGE_NT_HEADERS32::Signature, EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY::Signature, snprintf(), strchr(), strnlen(), strrchr(), EFI_IMAGE_DEBUG_DIRECTORY_ENTRY::Type, and EFI_IMAGE_DATA_DIRECTORY::VirtualAddress.

                                                            {
        static char buf[32];
        EFI_IMAGE_DOS_HEADER *dos;
        EFI_IMAGE_OPTIONAL_HEADER_UNION *pe;
        EFI_IMAGE_OPTIONAL_HEADER32 *opt32;
        EFI_IMAGE_OPTIONAL_HEADER64 *opt64;
        EFI_IMAGE_DATA_DIRECTORY *datadir;
        EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *debug;
        EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *codeview_nb10;
        EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY *codeview_rsds;
        EFI_IMAGE_DEBUG_CODEVIEW_MTOC_ENTRY *codeview_mtoc;
        uint16_t dos_magic;
        uint32_t pe_magic;
        uint16_t opt_magic;
        uint32_t codeview_magic;
        size_t max_len;
        char *name;
        char *tmp;

        /* Sanity check */
        if ( ! loaded ) {
                DBG ( "[NULL LoadedImage]" );
                return NULL;
        }

        /* Parse DOS header */
        dos = loaded->ImageBase;
        if ( ! dos ) {
                DBG ( "[Missing DOS header]" );
                return NULL;
        }
        dos_magic = dos->e_magic;
        if ( dos_magic != EFI_IMAGE_DOS_SIGNATURE ) {
                DBG ( "[Bad DOS signature %#04x]", dos_magic );
                return NULL;
        }
        pe = ( loaded->ImageBase + dos->e_lfanew );

        /* Parse PE header */
        pe_magic = pe->Pe32.Signature;
        if ( pe_magic != EFI_IMAGE_NT_SIGNATURE ) {
                DBG ( "[Bad PE signature %#08x]", pe_magic );
                return NULL;
        }
        opt32 = &pe->Pe32.OptionalHeader;
        opt64 = &pe->Pe32Plus.OptionalHeader;
        opt_magic = opt32->Magic;
        if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC ) {
                datadir = opt32->DataDirectory;
        } else if ( opt_magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC ) {
                datadir = opt64->DataDirectory;
        } else {
                DBG ( "[Bad optional header signature %#04x]", opt_magic );
                return NULL;
        }

        /* Parse data directory entry */
        if ( ! datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress ) {
                DBG ( "[Empty debug directory entry]" );
                return NULL;
        }
        debug = ( loaded->ImageBase +
                  datadir[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress );

        /* Parse debug directory entry */
        if ( debug->Type != EFI_IMAGE_DEBUG_TYPE_CODEVIEW ) {
                DBG ( "[Not a CodeView debug directory entry (type %d)]",
                      debug->Type );
                return NULL;
        }
        codeview_nb10 = ( loaded->ImageBase + debug->RVA );
        codeview_rsds = ( loaded->ImageBase + debug->RVA );
        codeview_mtoc = ( loaded->ImageBase + debug->RVA );
        codeview_magic = codeview_nb10->Signature;

        /* Parse CodeView entry */
        if ( codeview_magic == CODEVIEW_SIGNATURE_NB10 ) {
                name = ( ( void * ) ( codeview_nb10 + 1 ) );
        } else if ( codeview_magic == CODEVIEW_SIGNATURE_RSDS ) {
                name = ( ( void * ) ( codeview_rsds + 1 ) );
        } else if ( codeview_magic == CODEVIEW_SIGNATURE_MTOC ) {
                name = ( ( void * ) ( codeview_mtoc + 1 ) );
        } else {
                DBG ( "[Bad CodeView signature %#08x]", codeview_magic );
                return NULL;
        }

        /* Sanity check - avoid scanning endlessly through memory */
        max_len = EFI_PAGE_SIZE; /* Reasonably sane */
        if ( strnlen ( name, max_len ) == max_len ) {
                DBG ( "[Excessively long or invalid CodeView name]" );
                return NULL;
        }

        /* Skip any directory components.  We cannot modify this data
         * or create a temporary buffer, so do not use basename().
         */
        while ( ( ( tmp = strchr ( name, '/' ) ) != NULL ) ||
                ( ( tmp = strchr ( name, '\\' ) ) != NULL ) ) {
                name = ( tmp + 1 );
        }

        /* Copy base name to buffer */
        snprintf ( buf, sizeof ( buf ), "%s", name );

        /* Strip file suffix, if present */
        if ( ( tmp = strrchr ( name, '.' ) ) != NULL )
                *tmp = '\0';

        return name;
}
static const char* efi_first_loaded_image_name ( EFI_LOADED_IMAGE_PROTOCOL loaded) [static]

Get initial loaded image name.

Parameters:
loadedLoaded image
Return values:
nameInitial loaded image name, or NULL

Definition at line 587 of file efi_debug.c.

References DBG, NULL, and EFI_LOADED_IMAGE_PROTOCOL::ParentHandle.

                                                                  {

        /* Sanity check */
        if ( ! loaded ) {
                DBG ( "[NULL LoadedImage]" );
                return NULL;
        }

        return ( ( loaded->ParentHandle == NULL ) ? "DxeCore(?)" : NULL );
}
static const char* efi_loaded_image_filepath_name ( EFI_LOADED_IMAGE_PROTOCOL loaded) [static]

Get loaded image name from file path.

Parameters:
loadedLoaded image
Return values:
nameLoaded image name, or NULL

Definition at line 605 of file efi_debug.c.

References DBG, efi_devpath_text(), EFI_LOADED_IMAGE_PROTOCOL::FilePath, and NULL.

                                                                     {

        /* Sanity check */
        if ( ! loaded ) {
                DBG ( "[NULL LoadedImage]" );
                return NULL;
        }

        return efi_devpath_text ( loaded->FilePath );
}
static const char* efi_conin_name ( EFI_SIMPLE_TEXT_INPUT_PROTOCOL input) [static]

Get console input handle name.

Parameters:
inputSimple text input protocol
Return values:
nameConsole input handle name, or NULL

Definition at line 623 of file efi_debug.c.

References EFI_SYSTEM_TABLE::ConIn, efi_systab, and NULL.

                                                         {

        /* Check for match against ConIn */
        if ( input == efi_systab->ConIn )
                return "ConIn";

        return NULL;
}
static const char* efi_conout_name ( EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL output) [static]

Get console output handle name.

Parameters:
outputSimple text output protocol
Return values:
nameConsole output handle name, or NULL

Definition at line 639 of file efi_debug.c.

References EFI_SYSTEM_TABLE::ConOut, efi_systab, NULL, and EFI_SYSTEM_TABLE::StdErr.

                                                            {

        /* Check for match against ConOut */
        if ( output == efi_systab->ConOut )
                return "ConOut";

        /* Check for match against StdErr (if different from ConOut) */
        if ( output == efi_systab->StdErr )
                return "StdErr";

        return NULL;
}
const char* efi_handle_name ( EFI_HANDLE  handle)

Get name of an EFI handle.

Parameters:
handleEFI handle
Return values:
textName of handle, or NULL

Definition at line 714 of file efi_debug.c.

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, count, DBG2, efi_guid_ntoa(), efi_handle_name_types, efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_systab, EFI_BOOT_SERVICES::FreePool, efi_handle_name_type::name, name, NULL, EFI_BOOT_SERVICES::OpenProtocol, efi_handle_name_type::protocol, EFI_BOOT_SERVICES::ProtocolsPerHandle, ssnprintf(), and type.

Referenced by chained_locate(), chained_supported(), dbg_efi_openers(), dbg_efi_protocols(), efi_bofm_start(), efi_bofm_supported(), efi_child_add(), efi_child_del(), efi_close_protocol_wrapper(), efi_connect_controller_wrapper(), efi_device_info(), efi_disconnect_controller_wrapper(), efi_driver_connect(), efi_driver_start(), efi_driver_stop(), efi_driver_supported(), efi_exit_boot_services_wrapper(), efi_exit_wrapper(), efi_handle_protocol_wrapper(), efi_install_protocol_interface_wrapper(), efi_load_image_wrapper(), efi_local_check_volume_name(), efi_local_open_root(), efi_local_open_volume(), efi_locate_device(), efi_locate_device_path_wrapper(), efi_locate_handle_buffer_wrapper(), efi_locate_handle_wrapper(), efi_open_protocol_wrapper(), efi_pci_info(), efi_protocols_per_handle_wrapper(), efi_pxe_install(), efi_pxe_uninstall(), efi_reinstall_protocol_interface_wrapper(), efi_snp_probe(), efi_start_image_wrapper(), efi_uninstall_protocol_interface_wrapper(), efi_unload_image_wrapper(), efi_usb_install(), efi_wrap(), efipci_open(), efipci_root(), efipci_start(), nii_start(), nii_supported(), snp_supported(), snpnet_start(), snpnet_stop(), usbio_bulk_in_poll(), usbio_bulk_out_poll(), usbio_config(), usbio_control_poll(), usbio_endpoint_open(), usbio_interface(), usbio_interfaces(), usbio_interrupt_callback(), usbio_interrupt_open(), usbio_open(), usbio_path(), usbio_start(), and usbio_supported().

                                                                            {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        struct efi_handle_name_type *type;
        static char buf[256];
        size_t used = 0;
        EFI_GUID **protocols;
        UINTN count;
        unsigned int i;
        void *interface;
        const char *name;
        EFI_STATUS efirc;

        /* Fail immediately for NULL handles */
        if ( ! handle )
                return NULL;

        /* Try each name type in turn */
        for ( i = 0 ; i < ( sizeof ( efi_handle_name_types ) /
                            sizeof ( efi_handle_name_types[0] ) ) ; i++ ) {
                type = &efi_handle_name_types[i];
                DBG2 ( "<%d", i );

                /* Try to open the applicable protocol */
                efirc = bs->OpenProtocol ( handle, type->protocol, &interface,
                                           efi_image_handle, handle,
                                           EFI_OPEN_PROTOCOL_GET_PROTOCOL );
                if ( efirc != 0 ) {
                        DBG2 ( ">" );
                        continue;
                }

                /* Try to get name from this protocol */
                DBG2 ( "-" );
                name = type->name ( interface );
                DBG2 ( "%c", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) );

                /* Close protocol */
                bs->CloseProtocol ( handle, type->protocol,
                                    efi_image_handle, handle );
                DBG2 ( ">" );

                /* Use this name, if possible */
                if ( name && name[0] )
                        return name;
        }

        /* If no name is found, then use the raw handle value and a
         * list of installed protocols.
         */
        used = ssnprintf ( buf, sizeof ( buf ), "UNKNOWN<%p", handle );
        if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
                                                &count ) ) == 0 ) {
                for ( i = 0 ; i < count ; i++ ) {
                        used += ssnprintf ( ( buf + used ),
                                            ( sizeof ( buf ) - used ), ",%s",
                                            efi_guid_ntoa ( protocols[i] ) );
                }
                bs->FreePool ( protocols );
        }
        used += ssnprintf ( ( buf + used ), ( sizeof ( buf ) - used ), ">" );
        return buf;
}

Variable Documentation

Device path to text protocol.

Definition at line 47 of file efi_debug.c.

Initial value:
 {
        0x4579b72d, 0x7ec4, 0x4dd4,
        { 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7 }
}

Iscsi4Dxe module GUID.

Definition at line 51 of file efi_debug.c.

Initial value:
 {
        0xe4f61863, 0xfe2c, 0x4b56,
        { 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf }
}

VlanConfigDxe module GUID.

Definition at line 57 of file efi_debug.c.

Well-known GUIDs.

Definition at line 71 of file efi_debug.c.

Referenced by efi_guid_ntoa().