You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

efi_debug.c 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /**
  21. * @file
  22. *
  23. * EFI debugging utilities
  24. *
  25. */
  26. #include <stdio.h>
  27. #include <ipxe/efi/efi.h>
  28. #include <ipxe/efi/efi_driver.h>
  29. #include <ipxe/efi/Protocol/DevicePath.h>
  30. #include <ipxe/efi/Protocol/DevicePathToText.h>
  31. /** Device path to text protocol */
  32. static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
  33. EFI_REQUIRE_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
  34. /**
  35. * Print list of protocol handlers attached to a handle
  36. *
  37. * @v handle EFI handle
  38. */
  39. void dbg_efi_protocols ( EFI_HANDLE handle ) {
  40. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  41. EFI_GUID **protocols;
  42. UINTN count;
  43. unsigned int i;
  44. EFI_STATUS efirc;
  45. /* Retrieve list of protocols */
  46. if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
  47. &count ) ) != 0 ) {
  48. printf ( "EFI could not retrieve protocols for %p: %s\n",
  49. handle, efi_strerror ( efirc ) );
  50. return;
  51. }
  52. /* Dump list of protocols */
  53. for ( i = 0 ; i < count ; i++ ) {
  54. printf ( "%s\n", uuid_ntoa ( ( union uuid * ) protocols[i] ) );
  55. }
  56. /* Free list */
  57. bs->FreePool ( protocols );
  58. }
  59. /**
  60. * Print device path
  61. *
  62. * @v path Device path
  63. */
  64. void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ) {
  65. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  66. EFI_DEVICE_PATH_PROTOCOL *end;
  67. CHAR16 *text;
  68. size_t len;
  69. /* Convert path to a textual representation */
  70. text = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
  71. if ( ! text ) {
  72. printf ( "<cannot convert>:\n" );
  73. end = efi_devpath_end ( path );
  74. len = ( ( ( void * ) end ) - ( ( void * ) path ) +
  75. sizeof ( *end ) );
  76. dbg_hex_dump_da ( 0, path, len );
  77. return;
  78. }
  79. /* Print path */
  80. printf ( "%ls", text );
  81. /* Free path */
  82. bs->FreePool ( text );
  83. }