blob: fa537397417831cbd890f15fc8d5cc9d671e4fd2 [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 *
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_
Bill Richardson0c3ba242013-03-29 11:09:30 -070012#include <stdint.h>
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070013
Stefan Reinauerb7b865c2012-08-23 15:06:25 -070014#define GPT_HEADER_SIGNATURE "EFI PART"
15#define GPT_HEADER_SIGNATURE2 "CHROMEOS"
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070016#define GPT_HEADER_SIGNATURE_SIZE sizeof(GPT_HEADER_SIGNATURE)
17#define GPT_HEADER_REVISION 0x00010000
18
Randall Spanglercefe12c2013-01-30 12:52:02 -080019/*
20 * The first 3 numbers should be stored in network-endian format according to
21 * the GUID RFC. The UEFI spec appendix A claims they should be stored in
22 * little-endian format. But they need to be _displayed_ in network-endian
23 * format, which is also how they're documented in the specs.
Randall Spangler3dcf9dc2010-06-02 12:46:17 -070024 *
Randall Spanglercefe12c2013-01-30 12:52:02 -080025 * Since what we have here are little-endian constants, they're byte-swapped
26 * from the normal display order.
27 */
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070028#define GPT_ENT_TYPE_UNUSED \
Randall Spanglercefe12c2013-01-30 12:52:02 -080029 {{{0x00000000,0x0000,0x0000,0x00,0x00,{0x00,0x00,0x00,0x00,0x00,0x00}}}}
Randall Spangler3dcf9dc2010-06-02 12:46:17 -070030#define GPT_ENT_TYPE_EFI \
Randall Spanglercefe12c2013-01-30 12:52:02 -080031 {{{0xc12a7328,0xf81f,0x11d2,0xba,0x4b,{0x00,0xa0,0xc9,0x3e,0xc9,0x3b}}}}
Gabe Black93cf15e2011-07-07 16:00:00 -070032#define GPT_ENT_TYPE_CHROMEOS_FIRMWARE \
Randall Spanglercefe12c2013-01-30 12:52:02 -080033 {{{0xcab6e88e,0xabf3,0x4102,0xa0,0x7a,{0xd4,0xbb,0x9b,0xe3,0xc1,0xd3}}}}
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070034#define GPT_ENT_TYPE_CHROMEOS_KERNEL \
Randall Spanglercefe12c2013-01-30 12:52:02 -080035 {{{0xfe3a2a5d,0x4f32,0x41a7,0xb7,0x25,{0xac,0xcc,0x32,0x85,0xa3,0x09}}}}
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070036#define GPT_ENT_TYPE_CHROMEOS_ROOTFS \
Randall Spanglercefe12c2013-01-30 12:52:02 -080037 {{{0x3cb8e202,0x3b7e,0x47dd,0x8a,0x3c,{0x7f,0xf2,0xa1,0x3c,0xfc,0xec}}}}
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070038#define GPT_ENT_TYPE_CHROMEOS_RESERVED \
Randall Spanglercefe12c2013-01-30 12:52:02 -080039 {{{0x2e0a753d,0x9e48,0x43b0,0x83,0x37,{0xb1,0x51,0x92,0xcb,0x1b,0x5e}}}}
Bill Richardson77d26e52010-06-04 12:26:42 -070040#define GPT_ENT_TYPE_LINUX_DATA \
Randall Spanglercefe12c2013-01-30 12:52:02 -080041 {{{0xebd0a0a2,0xb9e5,0x4433,0x87,0xc0,{0x68,0xb6,0xb7,0x26,0x99,0xc7}}}}
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070042
43#define UUID_NODE_LEN 6
44#define GUID_SIZE 16
45
Randall Spanglercefe12c2013-01-30 12:52:02 -080046/* GUID definition. Defined in appendix A of EFI standard. */
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070047typedef struct {
Randall Spanglercefe12c2013-01-30 12:52:02 -080048 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];
58 } u;
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070059} __attribute__((packed)) Guid;
60
Randall Spangler81d09962010-06-23 10:15:38 -070061#define GUID_EXPECTED_SIZE GUID_SIZE
62
Randall Spanglercefe12c2013-01-30 12:52:02 -080063/*
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 * fields are duplicated except my_lba and entries_lba.
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070067 *
68 * You may find more details in chapter 5 of EFI standard.
69 */
70typedef struct {
Randall Spanglercefe12c2013-01-30 12:52:02 -080071 char signature[8];
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 */
Bill Richardson962483c2010-06-15 21:07:18 -070086} __attribute__((packed)) GptHeader;
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070087
Randall Spangler81d09962010-06-23 10:15:38 -070088#define GPTHEADER_EXPECTED_SIZE 92
89
Randall Spanglercefe12c2013-01-30 12:52:02 -080090/*
91 * GPT partition entry defines the starting and ending LBAs of a partition. It
92 * also contains the unique GUID, type, and attribute bits.
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -070093 *
94 * You may find more details in chapter 5 of EFI standard.
95 */
96typedef struct {
Randall Spanglercefe12c2013-01-30 12:52:02 -080097 Guid type;
98 Guid unique;
99 uint64_t starting_lba;
100 uint64_t ending_lba;
101 union {
102 struct {
103 uint16_t reserved[3];
104 uint16_t gpt_att;
105 } __attribute__((packed)) fields;
106 uint64_t whole;
107 } attrs;
108 uint16_t name[36]; /* UTF-16 encoded partition name */
109 /* Remainder of entry is reserved and should be 0 */
Bill Richardson962483c2010-06-15 21:07:18 -0700110} __attribute__((packed)) GptEntry;
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -0700111
Randall Spangler81d09962010-06-23 10:15:38 -0700112#define GPTENTRY_EXPECTED_SIZE 128
113
Louis Yung-Chieh Lo37f6b552010-04-22 21:22:22 -0700114#endif /* VBOOT_REFERENCE_CGPTLIB_GPT_H_ */