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