[efi] Allow device paths to be easily included in debug messages

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2014-06-25 14:44:13 +01:00
parent 8290a95513
commit 44338bfd22
2 changed files with 53 additions and 37 deletions

View File

@@ -149,9 +149,10 @@ extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
extern EFI_SYSTEM_TABLE *efi_systab; extern EFI_SYSTEM_TABLE *efi_systab;
extern const char * efi_guid_ntoa ( EFI_GUID *guid ); extern const char * efi_guid_ntoa ( EFI_GUID *guid );
extern const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
extern const char * efi_handle_devpath_text ( EFI_HANDLE handle );
extern void dbg_efi_protocols ( EFI_HANDLE handle ); extern void dbg_efi_protocols ( EFI_HANDLE handle );
extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
#define DBG_EFI_PROTOCOLS_IF( level, handle ) do { \ #define DBG_EFI_PROTOCOLS_IF( level, handle ) do { \
if ( DBG_ ## level ) { \ if ( DBG_ ## level ) { \
@@ -159,30 +160,15 @@ extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
} \ } \
} while ( 0 ) } while ( 0 )
#define DBG_EFI_DEVPATH_IF( level, path ) do { \
if ( DBG_ ## level ) { \
dbg_efi_devpath ( path ); \
} \
} while ( 0 )
#define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do { \ #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do { \
DBG_AC_IF ( level, id ); \ DBG_AC_IF ( level, id ); \
DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ ); \ DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ ); \
DBG_DC_IF ( level ); \ DBG_DC_IF ( level ); \
} while ( 0 ) } while ( 0 )
#define DBGC_EFI_DEVPATH_IF( level, id, ... ) do { \
DBG_AC_IF ( level, id ); \
DBG_EFI_DEVPATH_IF ( level, __VA_ARGS__ ); \
DBG_DC_IF ( level ); \
} while ( 0 )
#define DBGC_EFI_PROTOCOLS( ... ) \ #define DBGC_EFI_PROTOCOLS( ... ) \
DBGC_EFI_PROTOCOLS_IF( LOG, ##__VA_ARGS__ ) DBGC_EFI_PROTOCOLS_IF( LOG, ##__VA_ARGS__ )
#define DBGC_EFI_DEVPATH( ... ) \
DBGC_EFI_DEVPATH_IF( LOG, ##__VA_ARGS__ )
extern EFI_STATUS efi_init ( EFI_HANDLE image_handle, extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
EFI_SYSTEM_TABLE *systab ); EFI_SYSTEM_TABLE *systab );

View File

@@ -35,6 +35,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/efi/Protocol/DevicePath.h> #include <ipxe/efi/Protocol/DevicePath.h>
#include <ipxe/efi/Protocol/DevicePathToText.h> #include <ipxe/efi/Protocol/DevicePathToText.h>
/** Device path protocol GUID */
static EFI_GUID efi_device_path_protocol_guid
= EFI_DEVICE_PATH_PROTOCOL_GUID;
/** Device path to text protocol */ /** Device path to text protocol */
static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt; static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt ); EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
@@ -88,36 +92,62 @@ void dbg_efi_protocols ( EFI_HANDLE handle ) {
} }
/** /**
* Print device path * Get textual representation of device path
* *
* @v path Device path * @v path Device path
* @ret text Textual representation of device path, or NULL
*/ */
void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ) { const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_DEVICE_PATH_PROTOCOL *end; static char text[256];
CHAR16 *text; CHAR16 *wtext;
size_t len;
/* Convert path to a textual representation */ /* Convert path to a textual representation */
if ( ! efidpt ) if ( ! efidpt )
goto err_no_efidpt; return NULL;
text = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE ); wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
if ( ! text ) if ( ! wtext )
goto err_convert; return NULL;
/* Print path */ /* Store path in buffer */
printf ( "%ls", text ); snprintf ( text, sizeof ( text ), "%ls", wtext );
/* Free path */ /* Free path */
bs->FreePool ( text ); bs->FreePool ( wtext );
return; return text;
}
err_convert:
err_no_efidpt: /**
printf ( "<cannot convert>:\n" ); * Get textual representation of device path for a handle
end = efi_devpath_end ( path ); *
len = ( ( ( void * ) end ) - ( ( void * ) path ) + * @v handle EFI handle
sizeof ( *end ) ); * @ret text Textual representation of device path, or NULL
dbg_hex_dump_da ( 0, path, len ); */
const char * efi_handle_devpath_text ( EFI_HANDLE handle ) {
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
union {
EFI_DEVICE_PATH_PROTOCOL *path;
void *interface;
} path;
const char *text;
EFI_STATUS efirc;
/* Obtain device path, if any */
if ( ( efirc = bs->OpenProtocol ( handle,
&efi_device_path_protocol_guid,
&path.interface, efi_image_handle,
handle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
return NULL;
}
/* Format device path */
text = efi_devpath_text ( path.path );
/* Close device path */
bs->CloseProtocol ( handle, &efi_device_path_protocol_guid,
efi_image_handle, handle );
return text;
} }