Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: src/platform/vboot_reference/cgptlib/cgpt.h

Issue 1922004: cgpt supports GptNextKernelEntry() and GptUpdateKernelEntry() (Closed)
Patch Set: Move cgpt attribute bits to bit [57,48] Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/platform/vboot_reference/cgptlib/cgpt.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "gpt.h" 9 #include "gpt.h"
10 #include <stdint.h> 10 #include <stdint.h>
11 11
12 enum { 12 enum {
13 GPT_SUCCESS = 0, 13 GPT_SUCCESS = 0,
14 GPT_ERROR_NO_VALID_KERNEL, 14 GPT_ERROR_NO_VALID_KERNEL,
15 GPT_ERROR_INVALID_HEADERS, 15 GPT_ERROR_INVALID_HEADERS,
16 GPT_ERROR_INVALID_ENTRIES, 16 GPT_ERROR_INVALID_ENTRIES,
17 GPT_ERROR_INVALID_SECTOR_SIZE, 17 GPT_ERROR_INVALID_SECTOR_SIZE,
18 GPT_ERROR_INVALID_SECTOR_NUMBER, 18 GPT_ERROR_INVALID_SECTOR_NUMBER,
19 GPT_ERROR_INVALID_UPDATE_TYPE,
19 }; 20 };
20 21
21 /* Bit masks for GptData.modified field. */ 22 /* Bit masks for GptData.modified field. */
22 #define GPT_MODIFIED_HEADER1 0x01 23 #define GPT_MODIFIED_HEADER1 0x01
23 #define GPT_MODIFIED_HEADER2 0x02 24 #define GPT_MODIFIED_HEADER2 0x02
24 #define GPT_MODIFIED_ENTRIES1 0x04 25 #define GPT_MODIFIED_ENTRIES1 0x04
25 #define GPT_MODIFIED_ENTRIES2 0x08 26 #define GPT_MODIFIED_ENTRIES2 0x08
26 27
27 #define GPT_UPDATE_ENTRY_TRY 1 28 /* The 'update_type' of GptUpdateKernelEntry()
29 * We expose TRY and BAD only because those are what verified boot needs.
30 * For more precise control on GPT attribute bits, please refer to
31 * gpt_internal.h */
32 enum {
33 GPT_UPDATE_ENTRY_TRY = 1,
28 /* System will be trying to boot the currently selected kernel partition. 34 /* System will be trying to boot the currently selected kernel partition.
29 * Update its try count if necessary. */ 35 * Update its try count if necessary. */
30 #define GPT_UPDATE_ENTRY_BAD 2 36 GPT_UPDATE_ENTRY_BAD = 2,
31 /* The currently selected kernel partition failed validation. Mark entry as 37 /* The currently selected kernel partition failed validation. Mark entry as
32 * invalid. */ 38 * invalid. */
39 };
33 40
34 /* Defines ChromeOS-specific limitation on GPT */ 41 /* Defines ChromeOS-specific limitation on GPT */
35 #define MIN_SIZE_OF_HEADER 92 42 #define MIN_SIZE_OF_HEADER 92
36 #define MAX_SIZE_OF_HEADER 512 43 #define MAX_SIZE_OF_HEADER 512
37 #define MIN_SIZE_OF_ENTRY 128 44 #define MIN_SIZE_OF_ENTRY 128
38 #define MAX_SIZE_OF_ENTRY 512 45 #define MAX_SIZE_OF_ENTRY 512
39 #define SIZE_OF_ENTRY_MULTIPLE 8 46 #define SIZE_OF_ENTRY_MULTIPLE 8
40 #define MIN_NUMBER_OF_ENTRIES 32 47 #define MIN_NUMBER_OF_ENTRIES 32
41 #define MAX_NUMBER_OF_ENTRIES 512 48 #define MAX_NUMBER_OF_ENTRIES 512
42 #define TOTAL_ENTRIES_SIZE 16384 /* usual case is 128 bytes * 128 entries */ 49 #define TOTAL_ENTRIES_SIZE 16384 /* usual case is 128 bytes * 128 entries */
(...skipping 29 matching lines...) Expand all
72 uint64_t drive_sectors; /* Size of drive in LBA sectors, in sectors */ 79 uint64_t drive_sectors; /* Size of drive in LBA sectors, in sectors */
73 80
74 /* Outputs */ 81 /* Outputs */
75 uint8_t modified; /* Which inputs have been modified? 82 uint8_t modified; /* Which inputs have been modified?
76 * 0x01 = header1 83 * 0x01 = header1
77 * 0x02 = header2 84 * 0x02 = header2
78 * 0x04 = table1 85 * 0x04 = table1
79 * 0x08 = table2 */ 86 * 0x08 = table2 */
80 87
81 /* Internal state */ 88 /* Internal state */
82 uint8_t current_kernel; /* the current kernel index */ 89 int current_kernel; /* the current chromeos kernel index in partition table.
90 * -1 means not found on drive. */
83 } GptData; 91 } GptData;
84 92
85 int GptInit(GptData *gpt); 93 int GptInit(GptData *gpt);
86 /* Initializes the GPT data structure's internal state. The header1, header2, 94 /* Initializes the GPT data structure's internal state. The following fields
87 * table1, table2, and drive_size fields should be filled in first. 95 * must be filled before calling this function:
96 *
97 * primary_header
98 * secondary_header
99 * primary_entries
100 * secondary_entries
101 * sector_bytes
102 * drive_sectors
88 * 103 *
89 * On return the modified field may be set, if the GPT data has been modified 104 * On return the modified field may be set, if the GPT data has been modified
90 * and should be written to disk. 105 * and should be written to disk.
91 * 106 *
92 * Returns 0 if successful, non-zero if error: 107 * Returns GPT_SUCCESS if successful, non-zero if error:
93 * GPT_ERROR_INVALID_HEADERS, both partition table headers are invalid, enters 108 * GPT_ERROR_INVALID_HEADERS, both partition table headers are invalid, enters
94 * recovery mode, 109 * recovery mode,
95 * GPT_ERROR_INVALID_ENTRIES, both partition table entries are invalid, enters 110 * GPT_ERROR_INVALID_ENTRIES, both partition table entries are invalid, enters
96 * recovery mode, 111 * recovery mode,
97 * GPT_ERROR_INVALID_SECTOR_SIZE, size of a sector is not supported, 112 * GPT_ERROR_INVALID_SECTOR_SIZE, size of a sector is not supported,
98 * GPT_ERROR_INVALID_SECTOR_NUMBER, number of sectors in drive is invalid (too 113 * GPT_ERROR_INVALID_SECTOR_NUMBER, number of sectors in drive is invalid (too
99 * small) */ 114 * small) */
100 115
101 int GptNextKernelEntry(GptData *gpt, uint64_t *start_sector, uint64_t *size); 116 int GptNextKernelEntry(GptData *gpt, uint64_t *start_sector, uint64_t *size);
102 /* Provides the location of the next kernel partition, in order of decreasing 117 /* Provides the location of the next kernel partition, in order of decreasing
103 * priority. On return the start_sector parameter contains the LBA sector 118 * priority. On return the start_sector parameter contains the LBA sector
104 * for the start of the kernel partition, and the size parameter contains the 119 * for the start of the kernel partition, and the size parameter contains the
105 * size of the kernel partition in LBA sectors. 120 * size of the kernel partition in LBA sectors.
106 * 121 *
107 * Returns 0 if successful, else 122 * Returns GPT_SUCCESS if successful, else
108 * GPT_ERROR_NO_VALID_KERNEL, no avaliable kernel, enters recovery mode */ 123 * GPT_ERROR_NO_VALID_KERNEL, no avaliable kernel, enters recovery mode */
109 124
110 int GptUpdateKernelEntry(GptData *gpt, uint32_t update_type); 125 int GptUpdateKernelEntry(GptData *gpt, uint32_t update_type);
111 /* Updates the kernel entry with the specified index, using the specified type 126 /* Updates the kernel entry with the specified index, using the specified type
112 * of update (GPT_UPDATE_ENTRY_*). 127 * of update (GPT_UPDATE_ENTRY_*).
113 * 128 *
114 * On return the modified field may be set, if the GPT data has been modified 129 * On return the modified field may be set, if the GPT data has been modified
115 * and should be written to disk. 130 * and should be written to disk.
116 * 131 *
117 * Returns 0 if successful, 1 if error. */ 132 * Returns GPT_SUCCESS if successful, else
133 * GPT_ERROR_INVALID_UPDATE_TYPE, invalid 'update_type' is given.
134 */
118 135
119 #endif /* VBOOT_REFERENCE_CGPT_H_ */ 136 #endif /* VBOOT_REFERENCE_CGPT_H_ */
OLDNEW
« no previous file with comments | « no previous file | src/platform/vboot_reference/cgptlib/cgpt.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698