Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010 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 EFI related structure. See more details in EFI 2.3 spec. |
| 6 | * |
| 7 | * To download EFI 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 | |
Randall Spangler | f302905 | 2010-06-16 13:42:58 -0700 | [diff] [blame] | 13 | #include "sysincludes.h" |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 14 | |
| 15 | #define GPT_HEADER_SIGNATURE "EFI PART" |
| 16 | #define GPT_HEADER_SIGNATURE_SIZE sizeof(GPT_HEADER_SIGNATURE) |
| 17 | #define GPT_HEADER_REVISION 0x00010000 |
| 18 | |
Randall Spangler | 3dcf9dc | 2010-06-02 12:46:17 -0700 | [diff] [blame] | 19 | /* The first 3 numbers should be stored in network-endian format |
| 20 | * according to the GUID RFC. The UEFI spec appendix A claims they |
| 21 | * should be stored in little-endian format. But they need to be |
| 22 | * _displayed_ in network-endian format, which is also how they're |
| 23 | * documented in the specs. |
| 24 | * |
| 25 | * Since what we have here are little-endian constants, they're |
| 26 | * byte-swapped from the normal display order. */ |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 27 | #define GPT_ENT_TYPE_UNUSED \ |
Louis Yung-Chieh Lo | 49fa8e5 | 2010-04-30 16:10:48 -0700 | [diff] [blame] | 28 | {{{0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}}}} |
Randall Spangler | 3dcf9dc | 2010-06-02 12:46:17 -0700 | [diff] [blame] | 29 | #define GPT_ENT_TYPE_EFI \ |
Randall Spangler | 40226c0 | 2010-06-02 15:01:03 -0700 | [diff] [blame] | 30 | {{{0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}}}} |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 31 | #define GPT_ENT_TYPE_CHROMEOS_KERNEL \ |
Randall Spangler | 40226c0 | 2010-06-02 15:01:03 -0700 | [diff] [blame] | 32 | {{{0xfe3a2a5d,0x4f32,0x41a7,0xb7,0x25,{0xac,0xcc,0x32,0x85,0xa3,0x09}}}} |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 33 | #define GPT_ENT_TYPE_CHROMEOS_ROOTFS \ |
Randall Spangler | 40226c0 | 2010-06-02 15:01:03 -0700 | [diff] [blame] | 34 | {{{0x3cb8e202,0x3b7e,0x47dd,0x8a,0x3c,{0x7f,0xf2,0xa1,0x3c,0xfc,0xec}}}} |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 35 | #define GPT_ENT_TYPE_CHROMEOS_RESERVED \ |
Randall Spangler | 40226c0 | 2010-06-02 15:01:03 -0700 | [diff] [blame] | 36 | {{{0x2e0a753d,0x9e48,0x43b0,0x83,0x37,{0xb1,0x51,0x92,0xcb,0x1b,0x5e}}}} |
Bill Richardson | 77d26e5 | 2010-06-04 12:26:42 -0700 | [diff] [blame] | 37 | #define GPT_ENT_TYPE_LINUX_DATA \ |
| 38 | {{{0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}}}} |
Randall Spangler | 40226c0 | 2010-06-02 15:01:03 -0700 | [diff] [blame] | 39 | |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 40 | |
| 41 | #define UUID_NODE_LEN 6 |
| 42 | #define GUID_SIZE 16 |
| 43 | |
| 44 | /* GUID definition. |
| 45 | * Defined in appendix A of EFI standard. |
| 46 | */ |
| 47 | typedef struct { |
| 48 | union { |
| 49 | struct { |
| 50 | uint32_t time_low; |
| 51 | uint16_t time_mid; |
| 52 | uint16_t time_high_and_version; |
| 53 | uint8_t clock_seq_high_and_reserved; |
| 54 | uint8_t clock_seq_low; |
| 55 | uint8_t node[UUID_NODE_LEN]; |
| 56 | } Uuid; |
| 57 | uint8_t raw[GUID_SIZE]; |
Louis Yung-Chieh Lo | 49fa8e5 | 2010-04-30 16:10:48 -0700 | [diff] [blame] | 58 | } u; |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 59 | } __attribute__((packed)) Guid; |
| 60 | |
Bill Richardson | 77d26e5 | 2010-06-04 12:26:42 -0700 | [diff] [blame] | 61 | /* Some constant values */ |
| 62 | extern const Guid guid_unused; |
| 63 | extern const Guid guid_chromeos_kernel; |
| 64 | |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 65 | /* GPT header defines how many partitions exist on a drive and sectors managed. |
| 66 | * For every drive device, there are 2 headers, primary and secondary. |
| 67 | * Most of fields are duplicated except my_lba and entries_lba. |
| 68 | * |
| 69 | * You may find more details in chapter 5 of EFI standard. |
| 70 | */ |
| 71 | typedef struct { |
| 72 | char signature[8]; |
| 73 | uint32_t revision; |
| 74 | uint32_t size; |
| 75 | uint32_t header_crc32; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 76 | uint32_t reserved_zero; |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 77 | uint64_t my_lba; |
| 78 | uint64_t alternate_lba; |
| 79 | uint64_t first_usable_lba; |
| 80 | uint64_t last_usable_lba; |
| 81 | Guid disk_uuid; |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 82 | uint64_t entries_lba; |
| 83 | uint32_t number_of_entries; |
| 84 | uint32_t size_of_entry; |
| 85 | uint32_t entries_crc32; |
Randall Spangler | d0dae7a | 2010-06-21 18:25:31 -0700 | [diff] [blame] | 86 | /* Remainder of sector is reserved and should be 0 */ |
Bill Richardson | 962483c | 2010-06-15 21:07:18 -0700 | [diff] [blame] | 87 | } __attribute__((packed)) GptHeader; |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 88 | |
| 89 | /* GPT partition entry defines the starting and ending LBAs of a partition. |
| 90 | * It also contains the unique GUID, type, and attribute bits. |
| 91 | * |
| 92 | * You may find more details in chapter 5 of EFI standard. |
| 93 | */ |
| 94 | typedef struct { |
| 95 | Guid type; |
| 96 | Guid unique; |
| 97 | uint64_t starting_lba; |
| 98 | uint64_t ending_lba; |
vbendeb | f7a45cc | 2010-06-21 08:44:16 -0700 | [diff] [blame] | 99 | union { |
| 100 | struct { |
| 101 | uint64_t : 48; |
| 102 | uint16_t gpt_att : 16; |
| 103 | } __attribute__((packed)) fields; |
| 104 | uint64_t whole; |
| 105 | } attrs; |
Bill Richardson | f1372d9 | 2010-06-11 09:15:55 -0700 | [diff] [blame] | 106 | uint16_t name[36]; /* UTF-16 encoded partition name */ |
Randall Spangler | d0dae7a | 2010-06-21 18:25:31 -0700 | [diff] [blame] | 107 | /* Remainder of entry is reserved and should be 0 */ |
Bill Richardson | 962483c | 2010-06-15 21:07:18 -0700 | [diff] [blame] | 108 | } __attribute__((packed)) GptEntry; |
Louis Yung-Chieh Lo | 37f6b55 | 2010-04-22 21:22:22 -0700 | [diff] [blame] | 109 | |
| 110 | #endif /* VBOOT_REFERENCE_CGPTLIB_GPT_H_ */ |