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