]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Allow device paths to be easily included in debug messages
authorMichael Brown <mcb30@ipxe.org>
Wed, 25 Jun 2014 13:44:13 +0000 (14:44 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 25 Jun 2014 13:44:13 +0000 (14:44 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/efi/efi.h
src/interface/efi/efi_debug.c

index 05576f9da0832e4fe66f5176c1c1f9d487809978..38342f7319ebcfcc8c99bdd898300645f98bf299 100644 (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 );
 
index 6d834bc83ae28a399dc2eab2d660991d11f643e1..f1427f511846000d3bb4647cee42b7e77e3a4247 100644 (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 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 );
 
-       return;
+       /* Close device path */
+       bs->CloseProtocol ( handle, &efi_device_path_protocol_guid,
+                           efi_image_handle, handle );
 
- 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;
 }