blob: 20dced839da21cf2f5a71930aa0cd434c619bb97 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
2
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __LIB_PARTITION_GPT_H
30#define __LIB_PARTITION_GPT_H
31
32#include <stdbool.h>
33
34#define PARTITION_TYPE_MBR 0
35#define PARTITION_TYPE_GPT 1
36#define PARTITION_TYPE_GPT_BACKUP 2
37
38/* GPT Signature should be 0x5452415020494645 */
39#define GPT_SIGNATURE_1 0x54524150
40#define GPT_SIGNATURE_2 0x20494645
41
42#define MMC_MBR_SIGNATURE_BYTE_0 0x55
43#define MMC_MBR_SIGNATURE_BYTE_1 0xAA
44
45/* GPT Offsets */
46#define PROTECTIVE_MBR_SIZE BLOCK_SIZE
47#define HEADER_SIZE_OFFSET 12
48#define HEADER_CRC_OFFSET 16
49#define PRIMARY_HEADER_OFFSET 24
50#define BACKUP_HEADER_OFFSET 32
51#define FIRST_USABLE_LBA_OFFSET 40
52#define LAST_USABLE_LBA_OFFSET 48
53#define PARTITION_ENTRIES_OFFSET 72
54#define PARTITION_COUNT_OFFSET 80
55#define PENTRY_SIZE_OFFSET 84
56#define PARTITION_CRC_OFFSET 88
57
58#define MIN_PARTITION_ARRAY_SIZE 0x4000
59
60#define PARTITION_ENTRY_FIRST_LBA 32
61#define PARTITION_ENTRY_LAST_LBA 40
62
63#define ENTRY_SIZE 0x080
64
65#define UNIQUE_GUID_OFFSET 16
66#define FIRST_LBA_OFFSET 32
67#define LAST_LBA_OFFSET 40
68#define ATTRIBUTE_FLAG_OFFSET 48
69#define PARTITION_NAME_OFFSET 56
70
71#define MAX_GPT_NAME_SIZE 72
72#define PARTITION_TYPE_GUID_SIZE 16
73#define UNIQUE_PARTITION_GUID_SIZE 16
74#define NUM_PARTITIONS 128
75
76/* Some useful define used to access the MBR/EBR table */
77#define BLOCK_SIZE 0x200
78#define TABLE_ENTRY_0 0x1BE
79#define TABLE_ENTRY_1 0x1CE
80#define TABLE_ENTRY_2 0x1DE
81#define TABLE_ENTRY_3 0x1EE
82#define TABLE_SIGNATURE 0x1FE
83#define TABLE_ENTRY_SIZE 0x010
84
85#define OFFSET_STATUS 0x00
86#define OFFSET_TYPE 0x04
87#define OFFSET_FIRST_SEC 0x08
88#define OFFSET_SIZE 0x0C
89#define COPYBUFF_SIZE (1024 * 16)
90#define BINARY_IN_TABLE_SIZE (16 * 512)
91#define MAX_FILE_ENTRIES 20
92
93#define MBR_EBR_TYPE 0x05
94#define MBR_MODEM_TYPE 0x06
95#define MBR_MODEM_TYPE2 0x0C
96#define MBR_SBL1_TYPE 0x4D
97#define MBR_SBL2_TYPE 0x51
98#define MBR_SBL3_TYPE 0x45
99#define MBR_RPM_TYPE 0x47
100#define MBR_TZ_TYPE 0x46
101#define MBR_MODEM_ST1_TYPE 0x4A
102#define MBR_MODEM_ST2_TYPE 0x4B
103#define MBR_EFS2_TYPE 0x4E
104
105#define MBR_ABOOT_TYPE 0x4C
106#define MBR_BOOT_TYPE 0x48
107#define MBR_SYSTEM_TYPE 0x82
108#define MBR_USERDATA_TYPE 0x83
109#define MBR_RECOVERY_TYPE 0x60
110#define MBR_MISC_TYPE 0x63
111#define MBR_PROTECTED_TYPE 0xEE
112#define MBR_SSD_TYPE 0x5D
113
114#define GET_LWORD_FROM_BYTE(x) (*(unsigned *)(x))
115#define GET_LLWORD_FROM_BYTE(x) ({unsigned long long *__ret = (unsigned long long *)(x); *__ret;})
116#define GET_LONG(x) (*(uint32_t *)(x))
117#define PUT_LONG(x, y) *((uint32_t *)(x)) = y
118#define PUT_LONG_LONG(x,y) *((unsigned long long *)(x)) = y
119
120#endif