blob: ae957cf70a481ae2d49618607475a92fead3d9f0 [file] [log] [blame]
Randall Spanglercefe12c2013-01-30 12:52:02 -08001/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -07002 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
Bill Richardson864fae22015-02-06 15:35:34 -08005 * Defines UEFI related structure. See more details in the UEFI spec.
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -07006 *
Bill Richardson864fae22015-02-06 15:35:34 -08007 * To download UEFI standard, please visit UEFI homepage:
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -07008 * http://www.uefi.org/
9 */
10#ifndef VBOOT_REFERENCE_CGPTLIB_GPT_H_
11#define VBOOT_REFERENCE_CGPTLIB_GPT_H_
Bill Richardson0c3ba242013-03-29 11:09:30 -070012#include <stdint.h>
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070013
Bill Richardson864fae22015-02-06 15:35:34 -080014/* From the specification */
15#define GPT_HEADER_SIGNATURE_SIZE 8
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070016#define GPT_HEADER_REVISION 0x00010000
Bill Richardson864fae22015-02-06 15:35:34 -080017#define GPT_HEADER_SIGNATURE "EFI PART"
18
19/* From https://chromium-review.googlesource.com/31264 */
20#define GPT_HEADER_SIGNATURE2 "CHROMEOS"
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070021
Julius Werner39910d02016-04-19 16:55:36 -070022/* From http://crosbug.com/p/52595 */
23#define GPT_HEADER_SIGNATURE_IGNORED "IGNOREME"
24
Randall Spanglercefe12c2013-01-30 12:52:02 -080025/*
26 * The first 3 numbers should be stored in network-endian format according to
27 * the GUID RFC. The UEFI spec appendix A claims they should be stored in
28 * little-endian format. But they need to be _displayed_ in network-endian
29 * format, which is also how they're documented in the specs.
Randall Spangler3dcf9dc2010-06-02 12:46:17 -070030 *
Randall Spanglercefe12c2013-01-30 12:52:02 -080031 * Since what we have here are little-endian constants, they're byte-swapped
32 * from the normal display order.
33 */
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070034#define GPT_ENT_TYPE_UNUSED \
Randall Spanglercefe12c2013-01-30 12:52:02 -080035 {{{0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}}}}
Randall Spangler3dcf9dc2010-06-02 12:46:17 -070036#define GPT_ENT_TYPE_EFI \
Randall Spanglercefe12c2013-01-30 12:52:02 -080037 {{{0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}}}}
Gabe Black93cf15e2011-07-07 16:00:00 -070038#define GPT_ENT_TYPE_CHROMEOS_FIRMWARE \
Randall Spanglercefe12c2013-01-30 12:52:02 -080039 {{{0xcab6e88e,0xabf3,0x4102,0xa0,0x7a,{0xd4,0xbb,0x9b,0xe3,0xc1,0xd3}}}}
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070040#define GPT_ENT_TYPE_CHROMEOS_KERNEL \
Randall Spanglercefe12c2013-01-30 12:52:02 -080041 {{{0xfe3a2a5d,0x4f32,0x41a7,0xb7,0x25,{0xac,0xcc,0x32,0x85,0xa3,0x09}}}}
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070042#define GPT_ENT_TYPE_CHROMEOS_ROOTFS \
Randall Spanglercefe12c2013-01-30 12:52:02 -080043 {{{0x3cb8e202,0x3b7e,0x47dd,0x8a,0x3c,{0x7f,0xf2,0xa1,0x3c,0xfc,0xec}}}}
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070044#define GPT_ENT_TYPE_CHROMEOS_RESERVED \
Randall Spanglercefe12c2013-01-30 12:52:02 -080045 {{{0x2e0a753d,0x9e48,0x43b0,0x83,0x37,{0xb1,0x51,0x92,0xcb,0x1b,0x5e}}}}
Bill Richardson77d26e52010-06-04 12:26:42 -070046#define GPT_ENT_TYPE_LINUX_DATA \
Randall Spanglercefe12c2013-01-30 12:52:02 -080047 {{{0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}}}}
Furquan Shaikh2b0dc162015-01-23 11:26:18 -080048#define GPT_ENT_TYPE_LINUX_FS \
49 {{{0x0fc63daf,0x8483,0x4772,0x8e,0x79,{0x3d,0x69,0xd8,0x47,0x7d,0xe4}}}}
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070050
51#define UUID_NODE_LEN 6
52#define GUID_SIZE 16
53
Bill Richardson864fae22015-02-06 15:35:34 -080054/* GUID definition. Defined in appendix A of UEFI standard. */
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070055typedef struct {
Randall Spanglercefe12c2013-01-30 12:52:02 -080056 union {
57 struct {
58 uint32_t time_low;
59 uint16_t time_mid;
60 uint16_t time_high_and_version;
61 uint8_t clock_seq_high_and_reserved;
62 uint8_t clock_seq_low;
63 uint8_t node[UUID_NODE_LEN];
64 } Uuid;
65 uint8_t raw[GUID_SIZE];
66 } u;
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070067} __attribute__((packed)) Guid;
68
Randall Spangler81d09962010-06-23 10:15:38 -070069#define GUID_EXPECTED_SIZE GUID_SIZE
70
Randall Spanglercefe12c2013-01-30 12:52:02 -080071/*
72 * GPT header defines how many partitions exist on a drive and sectors managed.
73 * For every drive device, there are 2 headers, primary and secondary. Most of
Bill Richardson864fae22015-02-06 15:35:34 -080074 * the fields are duplicates except my_lba and entries_lba.
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070075 *
Bill Richardson864fae22015-02-06 15:35:34 -080076 * You may find more details in chapter 5 of the UEFI standard.
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070077 */
78typedef struct {
Bill Richardson864fae22015-02-06 15:35:34 -080079 char signature[GPT_HEADER_SIGNATURE_SIZE];
Randall Spanglercefe12c2013-01-30 12:52:02 -080080 uint32_t revision;
81 uint32_t size;
82 uint32_t header_crc32;
83 uint32_t reserved_zero;
84 uint64_t my_lba;
85 uint64_t alternate_lba;
86 uint64_t first_usable_lba;
87 uint64_t last_usable_lba;
88 Guid disk_uuid;
89 uint64_t entries_lba;
90 uint32_t number_of_entries;
91 uint32_t size_of_entry;
92 uint32_t entries_crc32;
93 /* Remainder of sector is reserved and should be 0 */
Bill Richardson962483c2010-06-15 21:07:18 -070094} __attribute__((packed)) GptHeader;
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070095
Randall Spangler81d09962010-06-23 10:15:38 -070096#define GPTHEADER_EXPECTED_SIZE 92
97
Randall Spanglercefe12c2013-01-30 12:52:02 -080098/*
99 * GPT partition entry defines the starting and ending LBAs of a partition. It
100 * also contains the unique GUID, type, and attribute bits.
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -0700101 *
Bill Richardson864fae22015-02-06 15:35:34 -0800102 * You may find more details in chapter 5 of the UEFI standard.
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -0700103 */
104typedef struct {
Randall Spanglercefe12c2013-01-30 12:52:02 -0800105 Guid type;
106 Guid unique;
107 uint64_t starting_lba;
108 uint64_t ending_lba;
109 union {
110 struct {
Mike Frysinger6c18af52016-09-07 16:45:48 -0400111 uint8_t system:1;
112 uint8_t efi_ignore:1;
113 uint8_t legacy_boot:1;
114 uint8_t reserved1:5;
115 uint8_t reserved2;
116 uint16_t reserved[2];
Randall Spanglercefe12c2013-01-30 12:52:02 -0800117 uint16_t gpt_att;
118 } __attribute__((packed)) fields;
119 uint64_t whole;
120 } attrs;
121 uint16_t name[36]; /* UTF-16 encoded partition name */
122 /* Remainder of entry is reserved and should be 0 */
Bill Richardson962483c2010-06-15 21:07:18 -0700123} __attribute__((packed)) GptEntry;
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -0700124
Randall Spangler81d09962010-06-23 10:15:38 -0700125#define GPTENTRY_EXPECTED_SIZE 128
126
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -0700127#endif /* VBOOT_REFERENCE_CGPTLIB_GPT_H_ */