]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Improve efi_wrap debugging
authorMichael Brown <mcb30@ipxe.org>
Thu, 27 Aug 2015 09:36:52 +0000 (10:36 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 27 Aug 2015 14:54:25 +0000 (15:54 +0100)
Add debug wrappers for more boot services functions, and print
symbolic values rather than raw numbers where possible.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/efi/efi.h
src/interface/efi/efi_debug.c
src/interface/efi/efi_wrap.c

index f3f1d1acc9dc40381883be1dc2c1b91205e17392..ced88286f18d213962c7d5483d328d3196382c41 100644 (file)
@@ -202,6 +202,10 @@ extern EFI_SYSTEM_TABLE *efi_systab;
 
 extern const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid );
 extern const __attribute__ (( pure )) char *
+efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type );
+extern const __attribute__ (( pure )) char *
+efi_open_attributes_name ( unsigned int attributes );
+extern const __attribute__ (( pure )) char *
 efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern const __attribute__ (( pure )) char *
 efi_handle_name ( EFI_HANDLE handle );
index ed8818137ed4e65310f7e6b7cbcf59ffd164efe3..bcf45cffee737ae9179299c2f541cf275ddbaf61 100644 (file)
@@ -189,6 +189,26 @@ const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid ) {
        return uuid_ntoa ( &u.uuid );
 }
 
+/**
+ * Name locate search type
+ *
+ * @v search_type      Locate search type
+ * @ret name           Locate search type name
+ */
+const __attribute__ (( pure )) char *
+efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type ) {
+       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;
+       }
+}
+
 /**
  * Name protocol open attributes
  *
@@ -200,7 +220,8 @@ const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid ) {
  * (T)EST_PROTOCOL, BY_(C)HILD_CONTROLLER, BY_(D)RIVER, and
  * E(X)CLUSIVE.
  */
-static const char * efi_open_attributes_name ( unsigned int attributes ) {
+const __attribute__ (( pure )) char *
+efi_open_attributes_name ( unsigned int attributes ) {
        static char attribute_chars[] = "HGTCDX";
        static char name[ sizeof ( attribute_chars ) ];
        char *tmp = name;
index e94e8d9fc7eede87007de779c56a6d3adb6fdf35..c0c40eec61c6d369a05053b55999c4cb9bd815b3 100644 (file)
@@ -100,6 +100,81 @@ static const char * efi_status ( EFI_STATUS efirc ) {
        }
 }
 
+/**
+ * Convert EFI boolean to text
+ *
+ * @v boolean          Boolean value
+ * @ret text           Boolean value text
+ */
+static const char * efi_boolean ( BOOLEAN boolean ) {
+
+       return ( boolean ? "TRUE" : "FALSE" );
+}
+
+/**
+ * Wrap InstallProtocolInterface()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_install_protocol_interface_wrapper ( EFI_HANDLE *handle, EFI_GUID *protocol,
+                                        EFI_INTERFACE_TYPE interface_type,
+                                        VOID *interface ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "InstallProtocolInterface ( %s, %s, %d, %p ) ",
+              efi_handle_name ( *handle ), efi_guid_ntoa ( protocol ),
+              interface_type, interface );
+       efirc = bs->InstallProtocolInterface ( handle, protocol, interface_type,
+                                              interface );
+       DBGC ( colour, "= %s ( %s ) -> %p\n",
+              efi_status ( efirc ), efi_handle_name ( *handle ), retaddr );
+       return efirc;
+}
+
+/**
+ * Wrap ReinstallProtocolInterface()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_reinstall_protocol_interface_wrapper ( EFI_HANDLE handle,
+                                          EFI_GUID *protocol,
+                                          VOID *old_interface,
+                                          VOID *new_interface ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "ReinstallProtocolInterface ( %s, %s, %p, %p ) ",
+              efi_handle_name ( handle ), efi_guid_ntoa ( protocol ),
+              old_interface, new_interface );
+       efirc = bs->ReinstallProtocolInterface ( handle, protocol,
+                                                old_interface, new_interface );
+       DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+       return efirc;
+}
+
+/**
+ * Wrap UninstallProtocolInterface()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_uninstall_protocol_interface_wrapper ( EFI_HANDLE handle,
+                                          EFI_GUID *protocol,
+                                          VOID *interface ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "UninstallProtocolInterface ( %s, %s, %p ) ",
+              efi_handle_name ( handle ), efi_guid_ntoa ( protocol ),
+              interface );
+       efirc = bs->UninstallProtocolInterface ( handle, protocol, interface );
+       DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+       return efirc;
+}
+
 /**
  * Wrap HandleProtocol()
  *
@@ -111,7 +186,7 @@ efi_handle_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol,
        void *retaddr = __builtin_return_address ( 0 );
        EFI_STATUS efirc;
 
-       DBGC ( colour, "HandleProtocol ( %s, %s, ... ) ",
+       DBGC ( colour, "HandleProtocol ( %s, %s ) ",
               efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) );
        efirc = bs->HandleProtocol ( handle, protocol, interface );
        DBGC ( colour, "= %s ( %p ) -> %p\n",
@@ -129,14 +204,26 @@ efi_locate_handle_wrapper ( EFI_LOCATE_SEARCH_TYPE search_type,
                            UINTN *buffer_size, EFI_HANDLE *buffer ) {
        EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
        void *retaddr = __builtin_return_address ( 0 );
+       unsigned int i;
        EFI_STATUS efirc;
 
-       DBGC ( colour, "LocateHandle ( %d, %s, ..., %zd, ... ) ", search_type,
-              efi_guid_ntoa ( protocol ), ( ( size_t ) *buffer_size ) );
+       DBGC ( colour, "LocateHandle ( %s, %s, %p, %zd ) ",
+              efi_locate_search_type_name ( search_type ),
+              efi_guid_ntoa ( protocol ), search_key,
+              ( ( size_t ) *buffer_size ) );
        efirc = bs->LocateHandle ( search_type, protocol, search_key,
                                   buffer_size, buffer );
-       DBGC ( colour, "= %s ( %zd ) -> %p\n",
-              efi_status ( efirc ), ( ( size_t ) *buffer_size ), retaddr );
+       DBGC ( colour, "= %s ( %zd", efi_status ( efirc ),
+              ( ( size_t ) *buffer_size ) );
+       if ( efirc == 0 ) {
+               DBGC ( colour, ", {" );
+               for ( i = 0; i < ( *buffer_size / sizeof ( buffer[0] ) ); i++ ){
+                       DBGC ( colour, "%s%s", ( i ? ", " : " " ),
+                              efi_handle_name ( buffer[i] ) );
+               }
+               DBGC ( colour, " }" );
+       }
+       DBGC ( colour, " ) -> %p\n", retaddr );
        return efirc;
 }
 
@@ -152,7 +239,7 @@ efi_locate_device_path_wrapper ( EFI_GUID *protocol,
        void *retaddr = __builtin_return_address ( 0 );
        EFI_STATUS efirc;
 
-       DBGC ( colour, "LocateDevicePath ( %s, %s, ... ) ",
+       DBGC ( colour, "LocateDevicePath ( %s, %s ) ",
               efi_guid_ntoa ( protocol ), efi_devpath_text ( *device_path ) );
        efirc = bs->LocateDevicePath ( protocol, device_path, device );
        DBGC ( colour, "= %s ( %s, ",
@@ -174,9 +261,9 @@ efi_load_image_wrapper ( BOOLEAN boot_policy, EFI_HANDLE parent_image_handle,
        void *retaddr = __builtin_return_address ( 0 );
        EFI_STATUS efirc;
 
-       DBGC ( colour, "LoadImage ( %d, %s, ", boot_policy,
+       DBGC ( colour, "LoadImage ( %s, %s, ", efi_boolean ( boot_policy ),
               efi_handle_name ( parent_image_handle ) );
-       DBGC ( colour, "%s, %p, %#llx, ... ) ",
+       DBGC ( colour, "%s, %p, %#llx ) ",
               efi_devpath_text ( device_path ), source_buffer,
               ( ( unsigned long long ) source_size ) );
        efirc = bs->LoadImage ( boot_policy, parent_image_handle, device_path,
@@ -193,6 +280,69 @@ efi_load_image_wrapper ( BOOLEAN boot_policy, EFI_HANDLE parent_image_handle,
        return efirc;
 }
 
+/**
+ * Wrap StartImage()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_start_image_wrapper ( EFI_HANDLE image_handle, UINTN *exit_data_size,
+                         CHAR16 **exit_data ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "StartImage ( %s ) ", efi_handle_name ( image_handle ) );
+       efirc = bs->StartImage ( image_handle, exit_data_size, exit_data );
+       DBGC ( colour, "= %s", efi_status ( efirc ) );
+       if ( ( efirc != 0 ) && exit_data && *exit_data_size )
+               DBGC ( colour, " ( \"%ls\" )", *exit_data );
+       DBGC ( colour, " -> %p\n", retaddr );
+       if ( ( efirc != 0 ) && exit_data && *exit_data_size )
+               DBGC_HD ( colour, *exit_data, *exit_data_size );
+       return efirc;
+}
+
+/**
+ * Wrap Exit()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_exit_wrapper ( EFI_HANDLE image_handle, EFI_STATUS exit_status,
+                  UINTN exit_data_size, CHAR16 *exit_data ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_STATUS efirc;
+
+       if ( ( exit_status != 0 ) && exit_data && exit_data_size )
+               DBGC_HD ( colour, exit_data, exit_data_size );
+       DBGC ( colour, "Exit ( %s, %s",
+              efi_handle_name ( image_handle ), efi_status ( exit_status ) );
+       if ( ( exit_status != 0 ) && exit_data && exit_data_size )
+               DBGC ( colour, ", \"%ls\"", exit_data );
+       DBGC ( colour, " ) " );
+       efirc = bs->Exit ( image_handle, exit_status, exit_data_size,
+                          exit_data );
+       DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+       return efirc;
+}
+
+/**
+ * Wrap UnloadImage()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_unload_image_wrapper ( EFI_HANDLE image_handle ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "UnloadImage ( %s ) ",
+              efi_handle_name ( image_handle ) );
+       efirc = bs->UnloadImage ( image_handle );
+       DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+       return efirc;
+}
+
 /**
  * Wrap ExitBootServices()
  *
@@ -211,6 +361,60 @@ efi_exit_boot_services_wrapper ( EFI_HANDLE image_handle, UINTN map_key ) {
        return efirc;
 }
 
+/**
+ * Wrap ConnectController()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_connect_controller_wrapper ( EFI_HANDLE controller_handle,
+                                EFI_HANDLE *driver_image_handle,
+                                EFI_DEVICE_PATH_PROTOCOL *remaining_path,
+                                BOOLEAN recursive ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_HANDLE *tmp;
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "ConnectController ( %s, {",
+              efi_handle_name ( controller_handle ) );
+       if ( driver_image_handle ) {
+               for ( tmp = driver_image_handle ; *tmp ; tmp++ ) {
+                       DBGC ( colour, "%s%s",
+                              ( ( tmp == driver_image_handle ) ? " " : ", " ),
+                              efi_handle_name ( *tmp ) );
+               }
+       }
+       DBGC ( colour, " }, %s, %s ) ", efi_devpath_text ( remaining_path ),
+              efi_boolean ( recursive ) );
+       efirc = bs->ConnectController ( controller_handle, driver_image_handle,
+                                       remaining_path, recursive );
+       DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+       return efirc;
+}
+
+/**
+ * Wrap DisconnectController()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_disconnect_controller_wrapper ( EFI_HANDLE controller_handle,
+                                   EFI_HANDLE driver_image_handle,
+                                   EFI_HANDLE child_handle ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "DisconnectController ( %s",
+              efi_handle_name ( controller_handle ) );
+       DBGC ( colour, ", %s", efi_handle_name ( driver_image_handle ) );
+       DBGC ( colour, ", %s ) ", efi_handle_name ( child_handle ) );
+       efirc = bs->DisconnectController ( controller_handle,
+                                          driver_image_handle,
+                                          child_handle );
+       DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr );
+       return efirc;
+}
+
 /**
  * Wrap OpenProtocol()
  *
@@ -223,11 +427,11 @@ efi_open_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol,
        void *retaddr = __builtin_return_address ( 0 );
        EFI_STATUS efirc;
 
-       DBGC ( colour, "OpenProtocol ( %s, %s, ..., ",
+       DBGC ( colour, "OpenProtocol ( %s, %s, ",
               efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) );
        DBGC ( colour, "%s, ", efi_handle_name ( agent_handle ) );
-       DBGC ( colour, "%s, %#x ) ",
-              efi_handle_name ( controller_handle ), attributes );
+       DBGC ( colour, "%s, %s ) ", efi_handle_name ( controller_handle ),
+              efi_open_attributes_name ( attributes ) );
        efirc = bs->OpenProtocol ( handle, protocol, interface, agent_handle,
                                   controller_handle, attributes );
        DBGC ( colour, "= %s ( %p ) -> %p\n",
@@ -235,6 +439,90 @@ efi_open_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol,
        return efirc;
 }
 
+/**
+ * Wrap CloseProtocol()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_close_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol,
+                            EFI_HANDLE agent_handle,
+                            EFI_HANDLE controller_handle ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "CloseProtocol ( %s, %s, ",
+              efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) );
+       DBGC ( colour, "%s, ", efi_handle_name ( agent_handle ) );
+       DBGC ( colour, "%s ) ", efi_handle_name ( controller_handle ) );
+       efirc = bs->CloseProtocol ( handle, protocol, agent_handle,
+                                   controller_handle );
+       DBGC ( colour, "= %s -> %p\n",
+              efi_status ( efirc ), retaddr );
+       return efirc;
+}
+
+/**
+ * Wrap ProtocolsPerHandle()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_protocols_per_handle_wrapper ( EFI_HANDLE handle,
+                                  EFI_GUID ***protocol_buffer,
+                                  UINTN *protocol_buffer_count ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       unsigned int i;
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "ProtocolsPerHandle ( %s ) ",
+              efi_handle_name ( handle ) );
+       efirc = bs->ProtocolsPerHandle ( handle, protocol_buffer,
+                                        protocol_buffer_count );
+       DBGC ( colour, "= %s", efi_status ( efirc ) );
+       if ( efirc == 0 ) {
+               DBGC ( colour, " ( {" );
+               for ( i = 0 ; i < *protocol_buffer_count ; i++ ) {
+                       DBGC ( colour, "%s%s", ( i ? ", " : " " ),
+                              efi_guid_ntoa ( (*protocol_buffer)[i] ) );
+               }
+               DBGC ( colour, " } )" );
+       }
+       DBGC ( colour, " -> %p\n", retaddr );
+       return efirc;
+}
+
+/**
+ * Wrap LocateHandleBuffer()
+ *
+ */
+static EFI_STATUS EFIAPI
+efi_locate_handle_buffer_wrapper ( EFI_LOCATE_SEARCH_TYPE search_type,
+                                  EFI_GUID *protocol, VOID *search_key,
+                                  UINTN *no_handles, EFI_HANDLE **buffer ) {
+       EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
+       void *retaddr = __builtin_return_address ( 0 );
+       unsigned int i;
+       EFI_STATUS efirc;
+
+       DBGC ( colour, "LocateHandleBuffer ( %s, %s, %p ) ",
+              efi_locate_search_type_name ( search_type ),
+              efi_guid_ntoa ( protocol ), search_key );
+       efirc = bs->LocateHandleBuffer ( search_type, protocol, search_key,
+                                        no_handles, buffer );
+       DBGC ( colour, "= %s", efi_status ( efirc ) );
+       if ( efirc == 0 ) {
+               DBGC ( colour, " ( %d, {", ( ( unsigned int ) *no_handles ) );
+               for ( i = 0 ; i < *no_handles ; i++ ) {
+                       DBGC ( colour, "%s%s", ( i ? ", " : " " ),
+                              efi_handle_name ( (*buffer)[i] ) );
+               }
+               DBGC ( colour, " } )" );
+       }
+       DBGC ( colour, " -> %p\n", retaddr );
+       return efirc;
+}
+
 /**
  * Wrap LocateProtocol()
  *
@@ -246,7 +534,7 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration,
        void *retaddr = __builtin_return_address ( 0 );
        EFI_STATUS efirc;
 
-       DBGC ( colour, "LocateProtocol ( %s, %p, ... ) ",
+       DBGC ( colour, "LocateProtocol ( %s, %p ) ",
               efi_guid_ntoa ( protocol ), registration );
        efirc = bs->LocateProtocol ( protocol, registration, interface );
        DBGC ( colour, "= %s ( %p ) -> %p\n",
@@ -277,12 +565,30 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration,
                 sizeof ( efi_systab_wrapper ) );
        memcpy ( &efi_bs_wrapper, bs, sizeof ( efi_bs_wrapper ) );
        efi_systab_wrapper.BootServices = &efi_bs_wrapper;
+       efi_bs_wrapper.InstallProtocolInterface
+               = efi_install_protocol_interface_wrapper;
+       efi_bs_wrapper.ReinstallProtocolInterface
+               = efi_reinstall_protocol_interface_wrapper;
+       efi_bs_wrapper.UninstallProtocolInterface
+               = efi_uninstall_protocol_interface_wrapper;
        efi_bs_wrapper.HandleProtocol   = efi_handle_protocol_wrapper;
        efi_bs_wrapper.LocateHandle     = efi_locate_handle_wrapper;
        efi_bs_wrapper.LocateDevicePath = efi_locate_device_path_wrapper;
        efi_bs_wrapper.LoadImage        = efi_load_image_wrapper;
+       efi_bs_wrapper.StartImage       = efi_start_image_wrapper;
+       efi_bs_wrapper.Exit             = efi_exit_wrapper;
+       efi_bs_wrapper.UnloadImage      = efi_unload_image_wrapper;
        efi_bs_wrapper.ExitBootServices = efi_exit_boot_services_wrapper;
+       efi_bs_wrapper.ConnectController
+               = efi_connect_controller_wrapper;
+       efi_bs_wrapper.DisconnectController
+               = efi_disconnect_controller_wrapper;
        efi_bs_wrapper.OpenProtocol     = efi_open_protocol_wrapper;
+       efi_bs_wrapper.CloseProtocol    = efi_close_protocol_wrapper;
+       efi_bs_wrapper.ProtocolsPerHandle
+               = efi_protocols_per_handle_wrapper;
+       efi_bs_wrapper.LocateHandleBuffer
+               = efi_locate_handle_buffer_wrapper;
        efi_bs_wrapper.LocateProtocol   = efi_locate_protocol_wrapper;
 
        /* Open loaded image protocol */