gpt.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. *
  5. * Defines UEFI related structure. See more details in the UEFI spec.
  6. *
  7. * To download UEFI standard, please visit UEFI homepage:
  8. * http://www.uefi.org/
  9. */
  10. #ifndef VBOOT_REFERENCE_CGPTLIB_GPT_H_
  11. #define VBOOT_REFERENCE_CGPTLIB_GPT_H_
  12. #include <stdint.h>
  13. /* From the specification */
  14. #define GPT_HEADER_SIGNATURE_SIZE 8
  15. #define GPT_HEADER_REVISION 0x00010000
  16. #define GPT_HEADER_SIGNATURE "EFI PART"
  17. /* From https://chromium-review.googlesource.com/31264 */
  18. #define GPT_HEADER_SIGNATURE2 "CHROMEOS"
  19. /* From http://crosbug.com/p/52595 */
  20. #define GPT_HEADER_SIGNATURE_IGNORED "IGNOREME"
  21. /*
  22. * The first 3 numbers should be stored in network-endian format according to
  23. * the GUID RFC. The UEFI spec appendix A claims they should be stored in
  24. * little-endian format. But they need to be _displayed_ in network-endian
  25. * format, which is also how they're documented in the specs.
  26. *
  27. * Since what we have here are little-endian constants, they're byte-swapped
  28. * from the normal display order.
  29. */
  30. #define GPT_ENT_TYPE_UNUSED \
  31. {{{0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}}}}
  32. #define GPT_ENT_TYPE_EFI \
  33. {{{0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}}}}
  34. #define GPT_ENT_TYPE_CHROMEOS_FIRMWARE \
  35. {{{0xcab6e88e,0xabf3,0x4102,0xa0,0x7a,{0xd4,0xbb,0x9b,0xe3,0xc1,0xd3}}}}
  36. #define GPT_ENT_TYPE_CHROMEOS_KERNEL \
  37. {{{0xfe3a2a5d,0x4f32,0x41a7,0xb7,0x25,{0xac,0xcc,0x32,0x85,0xa3,0x09}}}}
  38. #define GPT_ENT_TYPE_CHROMEOS_ROOTFS \
  39. {{{0x3cb8e202,0x3b7e,0x47dd,0x8a,0x3c,{0x7f,0xf2,0xa1,0x3c,0xfc,0xec}}}}
  40. #define GPT_ENT_TYPE_CHROMEOS_RESERVED \
  41. {{{0x2e0a753d,0x9e48,0x43b0,0x83,0x37,{0xb1,0x51,0x92,0xcb,0x1b,0x5e}}}}
  42. #define GPT_ENT_TYPE_LINUX_DATA \
  43. {{{0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}}}}
  44. #define GPT_ENT_TYPE_LINUX_FS \
  45. {{{0x0fc63daf,0x8483,0x4772,0x8e,0x79,{0x3d,0x69,0xd8,0x47,0x7d,0xe4}}}}
  46. #define UUID_NODE_LEN 6
  47. #define GUID_SIZE 16
  48. /* GUID definition. Defined in appendix A of UEFI standard. */
  49. typedef struct {
  50. union {
  51. struct {
  52. uint32_t time_low;
  53. uint16_t time_mid;
  54. uint16_t time_high_and_version;
  55. uint8_t clock_seq_high_and_reserved;
  56. uint8_t clock_seq_low;
  57. uint8_t node[UUID_NODE_LEN];
  58. } Uuid;
  59. uint8_t raw[GUID_SIZE];
  60. } u;
  61. } __attribute__((packed)) Guid;
  62. #define GUID_EXPECTED_SIZE GUID_SIZE
  63. /*
  64. * GPT header defines how many partitions exist on a drive and sectors managed.
  65. * For every drive device, there are 2 headers, primary and secondary. Most of
  66. * the fields are duplicates except my_lba and entries_lba.
  67. *
  68. * You may find more details in chapter 5 of the UEFI standard.
  69. */
  70. typedef struct {
  71. char signature[GPT_HEADER_SIGNATURE_SIZE];
  72. uint32_t revision;
  73. uint32_t size;
  74. uint32_t header_crc32;
  75. uint32_t reserved_zero;
  76. uint64_t my_lba;
  77. uint64_t alternate_lba;
  78. uint64_t first_usable_lba;
  79. uint64_t last_usable_lba;
  80. Guid disk_uuid;
  81. uint64_t entries_lba;
  82. uint32_t number_of_entries;
  83. uint32_t size_of_entry;
  84. uint32_t entries_crc32;
  85. /* Remainder of sector is reserved and should be 0 */
  86. } __attribute__((packed)) GptHeader;
  87. #define GPTHEADER_EXPECTED_SIZE 92
  88. /*
  89. * GPT partition entry defines the starting and ending LBAs of a partition. It
  90. * also contains the unique GUID, type, and attribute bits.
  91. *
  92. * You may find more details in chapter 5 of the UEFI standard.
  93. */
  94. typedef struct {
  95. Guid type;
  96. Guid unique;
  97. uint64_t starting_lba;
  98. uint64_t ending_lba;
  99. union {
  100. struct {
  101. uint8_t system:1;
  102. uint8_t efi_ignore:1;
  103. uint8_t legacy_boot:1;
  104. uint8_t reserved1:5;
  105. uint8_t reserved2;
  106. uint16_t reserved[2];
  107. uint16_t gpt_att;
  108. } __attribute__((packed)) fields;
  109. uint64_t whole;
  110. } attrs;
  111. uint16_t name[36]; /* UTF-16 encoded partition name */
  112. /* Remainder of entry is reserved and should be 0 */
  113. } __attribute__((packed)) GptEntry;
  114. #define GPTENTRY_EXPECTED_SIZE 128
  115. #endif /* VBOOT_REFERENCE_CGPTLIB_GPT_H_ */