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