lsefisystab.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* lsefisystab.c - Display EFI systab. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2008 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/types.h>
  20. #include <grub/mm.h>
  21. #include <grub/dl.h>
  22. #include <grub/misc.h>
  23. #include <grub/normal.h>
  24. #include <grub/charset.h>
  25. #include <grub/efi/api.h>
  26. #include <grub/efi/efi.h>
  27. GRUB_MOD_LICENSE ("GPLv3+");
  28. struct guid_mapping
  29. {
  30. grub_guid_t guid;
  31. const char *name;
  32. };
  33. static const struct guid_mapping guid_mappings[] =
  34. {
  35. { GRUB_EFI_ACPI_20_TABLE_GUID, "ACPI-2.0"},
  36. { GRUB_EFI_ACPI_TABLE_GUID, "ACPI-1.0"},
  37. { GRUB_EFI_CONFORMANCE_PROFILES_TABLE_GUID, "CONFORMANCE PROFILES"},
  38. { GRUB_EFI_CRC32_GUIDED_SECTION_EXTRACTION_GUID,
  39. "CRC32 GUIDED SECTION EXTRACTION"},
  40. { GRUB_EFI_DEBUG_IMAGE_INFO_TABLE_GUID, "DEBUG IMAGE INFO"},
  41. { GRUB_EFI_DEVICE_TREE_GUID, "DEVICE TREE"},
  42. { GRUB_EFI_DXE_SERVICES_TABLE_GUID, "DXE SERVICES"},
  43. { GRUB_EFI_HCDP_TABLE_GUID, "HCDP"},
  44. { GRUB_EFI_HOB_LIST_GUID, "HOB LIST"},
  45. { GRUB_EFI_IMAGE_SECURITY_DATABASE_GUID, "IMAGE EXECUTION INFORMATION"},
  46. { GRUB_EFI_LZMA_CUSTOM_DECOMPRESS_GUID, "LZMA CUSTOM DECOMPRESS"},
  47. { GRUB_EFI_MEMORY_TYPE_INFORMATION_GUID, "MEMORY TYPE INFO"},
  48. { GRUB_EFI_MPS_TABLE_GUID, "MPS"},
  49. { GRUB_EFI_RT_PROPERTIES_TABLE_GUID, "RT PROPERTIES"},
  50. { GRUB_EFI_SAL_TABLE_GUID, "SAL"},
  51. { GRUB_EFI_SMBIOS_TABLE_GUID, "SMBIOS"},
  52. { GRUB_EFI_SMBIOS3_TABLE_GUID, "SMBIOS3"},
  53. { GRUB_EFI_SYSTEM_RESOURCE_TABLE_GUID, "SYSTEM RESOURCE TABLE"},
  54. { GRUB_EFI_TIANO_CUSTOM_DECOMPRESS_GUID, "TIANO CUSTOM DECOMPRESS"},
  55. { GRUB_EFI_TSC_FREQUENCY_GUID, "TSC FREQUENCY"},
  56. };
  57. static grub_err_t
  58. grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),
  59. int argc __attribute__ ((unused)),
  60. char **args __attribute__ ((unused)))
  61. {
  62. const grub_efi_system_table_t *st = grub_efi_system_table;
  63. const grub_efi_uint32_t major_rev = st->hdr.revision >> 16;
  64. const grub_efi_uint32_t minor_rev_upper = (st->hdr.revision & 0xffff) / 10;
  65. const grub_efi_uint32_t minor_rev_lower = (st->hdr.revision & 0xffff) % 10;
  66. grub_efi_configuration_table_t *t;
  67. unsigned int i;
  68. grub_printf ("Address: %p\n", st);
  69. grub_printf ("Signature: %016" PRIxGRUB_UINT64_T " revision: %u.%u",
  70. st->hdr.signature, major_rev, minor_rev_upper);
  71. if (minor_rev_lower)
  72. grub_printf (".%u", minor_rev_lower);
  73. grub_printf ("\n");
  74. {
  75. char *vendor;
  76. grub_uint16_t *vendor_utf16;
  77. grub_printf ("Vendor: ");
  78. for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++);
  79. /* Allocate extra 3 bytes to simplify math. */
  80. vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1);
  81. if (!vendor)
  82. return grub_errno;
  83. *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor,
  84. vendor_utf16 - st->firmware_vendor) = 0;
  85. grub_printf ("%s", vendor);
  86. grub_free (vendor);
  87. }
  88. grub_printf (", Version=%x\n", st->firmware_revision);
  89. grub_printf ("%lld tables:\n", (long long) st->num_table_entries);
  90. t = st->configuration_table;
  91. for (i = 0; i < st->num_table_entries; i++)
  92. {
  93. unsigned int j;
  94. grub_printf ("%p ", t->vendor_table);
  95. grub_printf ("%pG", &t->vendor_guid);
  96. for (j = 0; j < ARRAY_SIZE (guid_mappings); j++)
  97. if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
  98. sizeof (grub_guid_t)) == 0)
  99. grub_printf (" %s", guid_mappings[j].name);
  100. grub_printf ("\n");
  101. t++;
  102. }
  103. return GRUB_ERR_NONE;
  104. }
  105. static grub_command_t cmd;
  106. GRUB_MOD_INIT(lsefisystab)
  107. {
  108. cmd = grub_register_command ("lsefisystab", grub_cmd_lsefisystab,
  109. "", "Display EFI system tables.");
  110. }
  111. GRUB_MOD_FINI(lsefisystab)
  112. {
  113. grub_unregister_command (cmd);
  114. }