2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-22 09:31:51 +00:00

[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 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_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
#define DBG_EFI_PROTOCOLS_IF( level, handle ) do { \
if ( DBG_ ## level ) { \
@ -159,30 +160,15 @@ extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
} \
} 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 { \
DBG_AC_IF ( level, id ); \
DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ ); \
DBG_DC_IF ( level ); \
} 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( ... ) \
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,
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/DevicePathToText.h>
/** Device path protocol GUID */
static EFI_GUID efi_device_path_protocol_guid
= EFI_DEVICE_PATH_PROTOCOL_GUID;
/** Device path to text protocol */
static 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
* @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_DEVICE_PATH_PROTOCOL *end;
CHAR16 *text;
size_t len;
static char text[256];
CHAR16 *wtext;
/* Convert path to a textual representation */
if ( ! efidpt )
goto err_no_efidpt;
text = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
if ( ! text )
goto err_convert;
return NULL;
wtext = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
if ( ! wtext )
return NULL;
/* Print path */
printf ( "%ls", text );
/* Store path in buffer */
snprintf ( text, sizeof ( text ), "%ls", wtext );
/* Free path */
bs->FreePool ( text );
bs->FreePool ( wtext );
return;
err_convert:
err_no_efidpt:
printf ( "<cannot convert>:\n" );
end = efi_devpath_end ( path );
len = ( ( ( void * ) end ) - ( ( void * ) path ) +
sizeof ( *end ) );
dbg_hex_dump_da ( 0, path, len );
return text;
}
/**
* Get textual representation of device path for a handle
*
* @v handle EFI handle
* @ret text Textual representation of device path, or NULL
*/
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;
}