| /* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. |
| |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are |
| * met: |
| * * Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * * Redistributions in binary form must reproduce the above |
| * copyright notice, this list of conditions and the following |
| * disclaimer in the documentation and/or other materials provided |
| * with the distribution. |
| * * Neither the name of The Linux Foundation nor the names of its |
| * contributors may be used to endorse or promote products derived |
| * from this software without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #ifndef __LIB_PARTITION_GPT_H |
| #define __LIB_PARTITION_GPT_H |
| |
| #include <stdbool.h> |
| |
| #define PARTITION_TYPE_MBR 0 |
| #define PARTITION_TYPE_GPT 1 |
| #define PARTITION_TYPE_GPT_BACKUP 2 |
| |
| /* GPT Signature should be 0x5452415020494645 */ |
| #define GPT_SIGNATURE_1 0x54524150 |
| #define GPT_SIGNATURE_2 0x20494645 |
| |
| #define MMC_MBR_SIGNATURE_BYTE_0 0x55 |
| #define MMC_MBR_SIGNATURE_BYTE_1 0xAA |
| |
| /* GPT Offsets */ |
| #define PROTECTIVE_MBR_SIZE BLOCK_SIZE |
| #define HEADER_SIZE_OFFSET 12 |
| #define HEADER_CRC_OFFSET 16 |
| #define PRIMARY_HEADER_OFFSET 24 |
| #define BACKUP_HEADER_OFFSET 32 |
| #define FIRST_USABLE_LBA_OFFSET 40 |
| #define LAST_USABLE_LBA_OFFSET 48 |
| #define PARTITION_ENTRIES_OFFSET 72 |
| #define PARTITION_COUNT_OFFSET 80 |
| #define PENTRY_SIZE_OFFSET 84 |
| #define PARTITION_CRC_OFFSET 88 |
| |
| #define MIN_PARTITION_ARRAY_SIZE 0x4000 |
| |
| #define PARTITION_ENTRY_FIRST_LBA 32 |
| #define PARTITION_ENTRY_LAST_LBA 40 |
| |
| #define ENTRY_SIZE 0x080 |
| |
| #define UNIQUE_GUID_OFFSET 16 |
| #define FIRST_LBA_OFFSET 32 |
| #define LAST_LBA_OFFSET 40 |
| #define ATTRIBUTE_FLAG_OFFSET 48 |
| #define PARTITION_NAME_OFFSET 56 |
| |
| #define MAX_GPT_NAME_SIZE 72 |
| #define PARTITION_TYPE_GUID_SIZE 16 |
| #define UNIQUE_PARTITION_GUID_SIZE 16 |
| #define NUM_PARTITIONS 128 |
| |
| /* Some useful define used to access the MBR/EBR table */ |
| #define BLOCK_SIZE 0x200 |
| #define TABLE_ENTRY_0 0x1BE |
| #define TABLE_ENTRY_1 0x1CE |
| #define TABLE_ENTRY_2 0x1DE |
| #define TABLE_ENTRY_3 0x1EE |
| #define TABLE_SIGNATURE 0x1FE |
| #define TABLE_ENTRY_SIZE 0x010 |
| |
| #define OFFSET_STATUS 0x00 |
| #define OFFSET_TYPE 0x04 |
| #define OFFSET_FIRST_SEC 0x08 |
| #define OFFSET_SIZE 0x0C |
| #define COPYBUFF_SIZE (1024 * 16) |
| #define BINARY_IN_TABLE_SIZE (16 * 512) |
| #define MAX_FILE_ENTRIES 20 |
| |
| #define MBR_EBR_TYPE 0x05 |
| #define MBR_MODEM_TYPE 0x06 |
| #define MBR_MODEM_TYPE2 0x0C |
| #define MBR_SBL1_TYPE 0x4D |
| #define MBR_SBL2_TYPE 0x51 |
| #define MBR_SBL3_TYPE 0x45 |
| #define MBR_RPM_TYPE 0x47 |
| #define MBR_TZ_TYPE 0x46 |
| #define MBR_MODEM_ST1_TYPE 0x4A |
| #define MBR_MODEM_ST2_TYPE 0x4B |
| #define MBR_EFS2_TYPE 0x4E |
| |
| #define MBR_ABOOT_TYPE 0x4C |
| #define MBR_BOOT_TYPE 0x48 |
| #define MBR_SYSTEM_TYPE 0x82 |
| #define MBR_USERDATA_TYPE 0x83 |
| #define MBR_RECOVERY_TYPE 0x60 |
| #define MBR_MISC_TYPE 0x63 |
| #define MBR_PROTECTED_TYPE 0xEE |
| #define MBR_SSD_TYPE 0x5D |
| |
| #define GET_LWORD_FROM_BYTE(x) (*(unsigned *)(x)) |
| #define GET_LLWORD_FROM_BYTE(x) ({unsigned long long *__ret = (unsigned long long *)(x); *__ret;}) |
| #define GET_LONG(x) (*(uint32_t *)(x)) |
| #define PUT_LONG(x, y) *((uint32_t *)(x)) = y |
| #define PUT_LONG_LONG(x,y) *((unsigned long long *)(x)) = y |
| |
| #endif |