Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

efi_debug.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 <string.h>
  28. #include <errno.h>
  29. #include <ipxe/uuid.h>
  30. #include <ipxe/efi/efi.h>
  31. #include <ipxe/efi/efi_driver.h>
  32. #include <ipxe/efi/Protocol/DevicePath.h>
  33. #include <ipxe/efi/Protocol/DevicePathToText.h>
  34. /** Device path to text protocol */
  35. static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt;
  36. EFI_REQUIRE_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt );
  37. /**
  38. * Convert GUID to a printable string
  39. *
  40. * @v guid GUID
  41. * @ret string Printable string
  42. */
  43. const char * efi_guid_ntoa ( EFI_GUID *guid ) {
  44. union {
  45. union uuid uuid;
  46. EFI_GUID guid;
  47. } u;
  48. /* Convert GUID to standard endianness */
  49. memcpy ( &u.guid, guid, sizeof ( u.guid ) );
  50. uuid_mangle ( &u.uuid );
  51. return uuid_ntoa ( &u.uuid );
  52. }
  53. /**
  54. * Print list of protocol handlers attached to a handle
  55. *
  56. * @v handle EFI handle
  57. */
  58. void dbg_efi_protocols ( EFI_HANDLE handle ) {
  59. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  60. EFI_GUID **protocols;
  61. UINTN count;
  62. unsigned int i;
  63. EFI_STATUS efirc;
  64. int rc;
  65. /* Retrieve list of protocols */
  66. if ( ( efirc = bs->ProtocolsPerHandle ( handle, &protocols,
  67. &count ) ) != 0 ) {
  68. rc = -EEFI ( efirc );
  69. printf ( "EFI could not retrieve protocols for %p: %s\n",
  70. handle, strerror ( rc ) );
  71. return;
  72. }
  73. /* Dump list of protocols */
  74. for ( i = 0 ; i < count ; i++ )
  75. printf ( "%s\n", efi_guid_ntoa ( protocols[i] ) );
  76. /* Free list */
  77. bs->FreePool ( protocols );
  78. }
  79. /**
  80. * Print device path
  81. *
  82. * @v path Device path
  83. */
  84. void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path ) {
  85. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  86. EFI_DEVICE_PATH_PROTOCOL *end;
  87. CHAR16 *text;
  88. size_t len;
  89. /* Convert path to a textual representation */
  90. text = efidpt->ConvertDevicePathToText ( path, TRUE, FALSE );
  91. if ( ! text ) {
  92. printf ( "<cannot convert>:\n" );
  93. end = efi_devpath_end ( path );
  94. len = ( ( ( void * ) end ) - ( ( void * ) path ) +
  95. sizeof ( *end ) );
  96. dbg_hex_dump_da ( 0, path, len );
  97. return;
  98. }
  99. /* Print path */
  100. printf ( "%ls", text );
  101. /* Free path */
  102. bs->FreePool ( text );
  103. }