Kinson Chik | 66552a8 | 2011-03-29 15:59:06 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 2011, Code Aurora Forum. 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 Code Aurora Forum, Inc. 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 | /* Lookup Type */ |
| 30 | //TODO: Remove when merging MBR code to mmc_parser |
| 31 | #define PTN_OFFSET 0x01 |
| 32 | #define PTN_SIZE 0x02 |
| 33 | |
| 34 | /* GPT Signature should be 0x5452415020494645 */ |
| 35 | #define GPT_SIGNATURE_1 0x54524150 |
| 36 | #define GPT_SIGNATURE_2 0x20494645 |
| 37 | |
| 38 | /* GPT Offsets */ |
| 39 | #define PROTECTIVE_MBR_SIZE 512 |
| 40 | #define PARTITION_TABLE_SIZE 512 |
| 41 | #define PARTITION_ENTRY_SIZE 512 |
| 42 | #define HEADER_SIZE_OFFSET 12 |
| 43 | #define HEADER_CRC_OFFSET 16 |
| 44 | #define FIRST_USABLE_LBA_OFFSET 40 |
| 45 | #define LAST_USABLE_LBA_OFFSET 48 |
| 46 | #define PARTITION_ENTRIES_OFFSET 72 |
| 47 | #define PARTITION_COUNT_OFFSET 80 |
| 48 | #define PENTRY_SIZE_OFFSET 84 |
| 49 | #define PARTITION_CRC_OFFSET 88 |
| 50 | |
| 51 | #define UNIQUE_GUID_OFFSET 16 |
| 52 | #define FIRST_LBA_OFFSET 32 |
| 53 | #define LAST_LBA_OFFSET 40 |
| 54 | #define ATTRIBUTE_FLAG_OFFSET 48 |
| 55 | #define PARTITION_NAME_OFFSET 56 |
| 56 | |
| 57 | #define MAX_GPT_NAME_SIZE 72 |
| 58 | #define PARTITION_TYPE_GUID_SIZE 16 |
| 59 | #define UNIQUE_PARTITION_GUID_SIZE 16 |
| 60 | #define NUM_GPT_PARTITIONS 32 |
| 61 | |
| 62 | #define GET_LLWORD_FROM_BYTE(x) ((unsigned long long)*(x) | \ |
| 63 | ((unsigned long long)*(x+1) << 8) | \ |
| 64 | ((unsigned long long)*(x+2) << 16) | \ |
| 65 | ((unsigned long long)*(x+3) << 24) | \ |
| 66 | ((unsigned long long)*(x+4) << 32) | \ |
| 67 | ((unsigned long long)*(x+5) << 40) | \ |
| 68 | ((unsigned long long)*(x+6) << 48) | \ |
| 69 | ((unsigned long long)*(x+7) << 56)) |
| 70 | |
| 71 | struct gpt_entry |
| 72 | { |
| 73 | unsigned char partition_type_guid[PARTITION_TYPE_GUID_SIZE]; |
| 74 | unsigned char unique_partition_guid[UNIQUE_PARTITION_GUID_SIZE]; |
| 75 | unsigned long long first_lba; |
| 76 | unsigned long long last_lba; |
| 77 | unsigned long long attribute_flag; |
| 78 | unsigned char partition_name[MAX_GPT_NAME_SIZE]; |
| 79 | }; |
| 80 | |
| 81 | unsigned int mmc_boot_read_gpt(struct mmc_boot_host * mmc_host, |
| 82 | struct mmc_boot_card * mmc_card); |
| 83 | unsigned long long gpt_lookup(unsigned char * name, unsigned type); |