| OLD | NEW |
| (Empty) | |
| 1 /* Copyright (c) 2010 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 |
| 6 #ifndef VBOOT_REFERENCE_CGPT_H_ |
| 7 #define VBOOT_REFERENCE_CGPT_H_ |
| 8 |
| 9 #include <stdint.h> |
| 10 |
| 11 enum { |
| 12 GPT_ERROR_INVALID_HEADERS = 1, |
| 13 GPT_ERROR_INVALID_ENTRIES, |
| 14 GPT_ERROR_INVALID_SECTOR_SIZE, |
| 15 GPT_ERROR_INVALID_SECTOR_NUMBER, |
| 16 }; |
| 17 |
| 18 #define GPT_MODIFIED_HEADER1 0x01 |
| 19 #define GPT_MODIFIED_HEADER2 0x02 |
| 20 #define GPT_MODIFIED_ENTRIES1 0x04 |
| 21 #define GPT_MODIFIED_ENTRIES2 0x08 |
| 22 |
| 23 #define GPT_UPDATE_ENTRY_TRY 1 |
| 24 /* System will be trying to boot the currently selected kernel partition. |
| 25 * Update its try count if necessary. */ |
| 26 #define GPT_UPDATE_ENTRY_BAD 2 |
| 27 /* The currently selected kernel partition failed validation. Mark entry as |
| 28 * invalid. */ |
| 29 |
| 30 struct GPTData { |
| 31 /* Fill in the following fields before calling GPTInit() */ |
| 32 uint8_t *header1; /* GPT primary header, from sector 1 of disk |
| 33 * (size: 512 bytes) */ |
| 34 uint8_t *header2; /* GPT secondary header, from last sector of |
| 35 * disk (size: 512 bytes) */ |
| 36 uint8_t *entries1; /* primary GPT table, follows primary header |
| 37 * (size: 16 KB) */ |
| 38 uint8_t *entries2; /* secondary GPT table, precedes secondary |
| 39 * header (size: 16 KB) */ |
| 40 uint32_t sector_bytes; /* Size of a LBA sector, in bytes */ |
| 41 uint64_t drive_sectors; /* Size of drive in LBA sectors, in sectors */ |
| 42 |
| 43 /* Outputs */ |
| 44 uint8_t modified; /* Which inputs have been modified? |
| 45 * 0x01 = header1 |
| 46 * 0x02 = header2 |
| 47 * 0x04 = table1 |
| 48 * 0x08 = table2 */ |
| 49 |
| 50 /* Internal state */ |
| 51 uint8_t current_kernel; // the current kernel index |
| 52 }; |
| 53 typedef struct GPTData GPTData_t; |
| 54 |
| 55 int GPTInit(GPTData_t *gpt); |
| 56 /* Initializes the GPT data structure's internal state. The header1, header2, |
| 57 * table1, table2, and drive_size fields should be filled in first. |
| 58 * |
| 59 * On return the modified field may be set, if the GPT data has been modified |
| 60 * and should be written to disk. |
| 61 * |
| 62 * Returns 0 if successful, non-zero if error: |
| 63 * GPT_ERROR_INVALID_HEADERS, both partition table headers are invalid, enters |
| 64 * recovery mode, |
| 65 * GPT_ERROR_INVALID_ENTRIES, both partition table entries are invalid, enters |
| 66 * recovery mode, |
| 67 * GPT_ERROR_INVALID_SECTOR_SIZE, size of a sector is not supported, |
| 68 * GPT_ERROR_INVALID_SECTOR_NUMBER, number of sectors in drive is invalid (too |
| 69 * small) */ |
| 70 |
| 71 int GPTNextKernelEntry(GPTData_t *gpt, uint64_t *start_sector, uint64_t *size); |
| 72 /* Provides the location of the next kernel partition, in order of decreasing |
| 73 * priority. On return the start_sector parameter contains the LBA sector |
| 74 * for the start of the kernel partition, and the size parameter contains the |
| 75 * size of the kernel partition in LBA sectors. |
| 76 * |
| 77 * Returns 0 if successful, 1 if error or no more sectors. */ |
| 78 |
| 79 int GPTUpdateKernelEntry(GPTData_t *gpt, uint32_t update_type); |
| 80 /* Updates the kernel entry with the specified index, using the specified type |
| 81 * of update (GPT_UPDATE_ENTRY_*). |
| 82 * |
| 83 * On return the modified field may be set, if the GPT data has been modified |
| 84 * and should be written to disk. |
| 85 * |
| 86 * Returns 0 if successful, 1 if error. */ |
| 87 |
| 88 #endif // VBOOT_REFERENCE_CGPT_H_ |
| OLD | NEW |