lsefisystab.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_efi_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_SAL_TABLE_GUID, "SAL"},
  38. { GRUB_EFI_SMBIOS_TABLE_GUID, "SMBIOS"},
  39. { GRUB_EFI_MPS_TABLE_GUID, "MPS"},
  40. { GRUB_EFI_HCDP_TABLE_GUID, "HCDP"}
  41. };
  42. static grub_err_t
  43. grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)),
  44. int argc __attribute__ ((unused)),
  45. char **args __attribute__ ((unused)))
  46. {
  47. const grub_efi_system_table_t *st = grub_efi_system_table;
  48. grub_efi_configuration_table_t *t;
  49. unsigned int i;
  50. grub_printf ("Signature: %016" PRIxGRUB_UINT64_T " revision: %08x\n",
  51. st->hdr.signature, st->hdr.revision);
  52. {
  53. char *vendor;
  54. grub_uint16_t *vendor_utf16;
  55. grub_printf ("Vendor: ");
  56. for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++);
  57. vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1);
  58. if (!vendor)
  59. return grub_errno;
  60. *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor,
  61. vendor_utf16 - st->firmware_vendor) = 0;
  62. grub_printf ("%s", vendor);
  63. grub_free (vendor);
  64. }
  65. grub_printf (", Version=%x\n", st->firmware_revision);
  66. grub_printf ("%ld tables:\n", st->num_table_entries);
  67. t = st->configuration_table;
  68. for (i = 0; i < st->num_table_entries; i++)
  69. {
  70. unsigned int j;
  71. grub_printf ("%p ", t->vendor_table);
  72. grub_printf ("%08x-%04x-%04x-",
  73. t->vendor_guid.data1, t->vendor_guid.data2,
  74. t->vendor_guid.data3);
  75. for (j = 0; j < 8; j++)
  76. grub_printf ("%02x", t->vendor_guid.data4[j]);
  77. for (j = 0; j < ARRAY_SIZE (guid_mappings); j++)
  78. if (grub_memcmp (&guid_mappings[j].guid, &t->vendor_guid,
  79. sizeof (grub_efi_guid_t)) == 0)
  80. grub_printf (" %s", guid_mappings[j].name);
  81. grub_printf ("\n");
  82. t++;
  83. }
  84. return GRUB_ERR_NONE;
  85. }
  86. static grub_command_t cmd;
  87. GRUB_MOD_INIT(lsefisystab)
  88. {
  89. cmd = grub_register_command ("lsefisystab", grub_cmd_lsefisystab,
  90. "", "Display EFI system tables.");
  91. }
  92. GRUB_MOD_FINI(lsefisystab)
  93. {
  94. grub_unregister_command (cmd);
  95. }