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

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

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