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

Side by Side Diff: firmware/lib/cgptlib/cgptlib.c

Issue 2810026: Add VBDEBUG macro for debug output. (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Created 10 years, 6 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 | « firmware/include/utility.h ('k') | firmware/lib/cryptolib/rsa.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 #include "cgptlib.h" 6 #include "cgptlib.h"
7 #include "cgptlib_internal.h" 7 #include "cgptlib_internal.h"
8 #include "crc32.h" 8 #include "crc32.h"
9 #include "gpt.h" 9 #include "gpt.h"
10 #include "utility.h" 10 #include "utility.h"
11 11
12 /* global types to compare against */ 12 /* global types to compare against */
13 const Guid guid_unused = GPT_ENT_TYPE_UNUSED; 13 const Guid guid_unused = GPT_ENT_TYPE_UNUSED;
14 const Guid guid_chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL; 14 const Guid guid_chromeos_kernel = GPT_ENT_TYPE_CHROMEOS_KERNEL;
15 15
16 16
17 int GptInit(GptData *gpt) { 17 int GptInit(GptData *gpt) {
18 int retval; 18 int retval;
19 19
20 gpt->modified = 0; 20 gpt->modified = 0;
21 gpt->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND; 21 gpt->current_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND;
22 gpt->current_priority = 999; 22 gpt->current_priority = 999;
23 23
24 retval = GptSanityCheck(gpt); 24 retval = GptSanityCheck(gpt);
25 if (GPT_SUCCESS != retval) { 25 if (GPT_SUCCESS != retval) {
26 debug("GptInit() failed sanity check\n"); 26 VBDEBUG(("GptInit() failed sanity check\n"));
27 return retval; 27 return retval;
28 } 28 }
29 29
30 GptRepair(gpt); 30 GptRepair(gpt);
31 return GPT_SUCCESS; 31 return GPT_SUCCESS;
32 } 32 }
33 33
34 34
35 int GptNextKernelEntry(GptData* gpt, uint64_t* start_sector, uint64_t* size) { 35 int GptNextKernelEntry(GptData* gpt, uint64_t* start_sector, uint64_t* size) {
36 GptHeader* header = (GptHeader*)gpt->primary_header; 36 GptHeader* header = (GptHeader*)gpt->primary_header;
37 GptEntry* entries = (GptEntry*)gpt->primary_entries; 37 GptEntry* entries = (GptEntry*)gpt->primary_entries;
38 GptEntry* e; 38 GptEntry* e;
39 int new_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND; 39 int new_kernel = CGPT_KERNEL_ENTRY_NOT_FOUND;
40 int new_prio = 0; 40 int new_prio = 0;
41 uint32_t i; 41 uint32_t i;
42 42
43 /* If we already found a kernel, continue the scan at the current 43 /* If we already found a kernel, continue the scan at the current
44 * kernel's prioity, in case there is another kernel with the same 44 * kernel's prioity, in case there is another kernel with the same
45 * priority. */ 45 * priority. */
46 if (gpt->current_kernel != CGPT_KERNEL_ENTRY_NOT_FOUND) { 46 if (gpt->current_kernel != CGPT_KERNEL_ENTRY_NOT_FOUND) {
47 for (i = gpt->current_kernel + 1; i < header->number_of_entries; i++) { 47 for (i = gpt->current_kernel + 1; i < header->number_of_entries; i++) {
48 e = entries + i; 48 e = entries + i;
49 if (!IsKernelEntry(e)) 49 if (!IsKernelEntry(e))
50 continue; 50 continue;
51 debug("GptNextKernelEntry looking at same prio partition %d\n", i); 51 VBDEBUG(("GptNextKernelEntry looking at same prio partition %d\n", i));
52 debug("GptNextKernelEntry s%d t%d p%d\n", 52 VBDEBUG(("GptNextKernelEntry s%d t%d p%d\n",
53 GetEntrySuccessful(e), GetEntryTries(e), GetEntryPriority(e)); 53 GetEntrySuccessful(e), GetEntryTries(e), GetEntryPriority(e)));
54 if (!(GetEntrySuccessful(e) || GetEntryTries(e))) 54 if (!(GetEntrySuccessful(e) || GetEntryTries(e)))
55 continue; 55 continue;
56 if (GetEntryPriority(e) == gpt->current_priority) { 56 if (GetEntryPriority(e) == gpt->current_priority) {
57 gpt->current_kernel = i; 57 gpt->current_kernel = i;
58 *start_sector = e->starting_lba; 58 *start_sector = e->starting_lba;
59 *size = e->ending_lba - e->starting_lba + 1; 59 *size = e->ending_lba - e->starting_lba + 1;
60 debug("GptNextKernelEntry likes that one\n"); 60 VBDEBUG(("GptNextKernelEntry likes that one\n"));
61 return GPT_SUCCESS; 61 return GPT_SUCCESS;
62 } 62 }
63 } 63 }
64 } 64 }
65 65
66 /* We're still here, so scan for the remaining kernel with the 66 /* We're still here, so scan for the remaining kernel with the
67 * highest priority less than the previous attempt. */ 67 * highest priority less than the previous attempt. */
68 for (i = 0, e = entries; i < header->number_of_entries; i++, e++) { 68 for (i = 0, e = entries; i < header->number_of_entries; i++, e++) {
69 int current_prio = GetEntryPriority(e); 69 int current_prio = GetEntryPriority(e);
70 if (!IsKernelEntry(e)) 70 if (!IsKernelEntry(e))
71 continue; 71 continue;
72 debug("GptNextKernelEntry looking at new prio partition %d\n", i); 72 VBDEBUG(("GptNextKernelEntry looking at new prio partition %d\n", i));
73 debug("GptNextKernelEntry s%d t%d p%d\n", 73 VBDEBUG(("GptNextKernelEntry s%d t%d p%d\n",
74 GetEntrySuccessful(e), GetEntryTries(e), GetEntryPriority(e)); 74 GetEntrySuccessful(e), GetEntryTries(e), GetEntryPriority(e)));
75 if (!(GetEntrySuccessful(e) || GetEntryTries(e))) 75 if (!(GetEntrySuccessful(e) || GetEntryTries(e)))
76 continue; 76 continue;
77 if (current_prio >= gpt->current_priority) 77 if (current_prio >= gpt->current_priority)
78 continue; /* Already returned this kernel in a previous call */ 78 continue; /* Already returned this kernel in a previous call */
79 if (current_prio > new_prio) { 79 if (current_prio > new_prio) {
80 new_kernel = i; 80 new_kernel = i;
81 new_prio = current_prio; 81 new_prio = current_prio;
82 } 82 }
83 } 83 }
84 84
85 /* Save what we found. Note that if we didn't find a new kernel, 85 /* Save what we found. Note that if we didn't find a new kernel,
86 * new_prio will still be -1, so future calls to this function will 86 * new_prio will still be -1, so future calls to this function will
87 * also fail. */ 87 * also fail. */
88 gpt->current_kernel = new_kernel; 88 gpt->current_kernel = new_kernel;
89 gpt->current_priority = new_prio; 89 gpt->current_priority = new_prio;
90 90
91 if (CGPT_KERNEL_ENTRY_NOT_FOUND == new_kernel) { 91 if (CGPT_KERNEL_ENTRY_NOT_FOUND == new_kernel) {
92 debug("GptNextKernelEntry no more kernels\n"); 92 VBDEBUG(("GptNextKernelEntry no more kernels\n"));
93 return GPT_ERROR_NO_VALID_KERNEL; 93 return GPT_ERROR_NO_VALID_KERNEL;
94 } 94 }
95 95
96 debug("GptNextKernelEntry likes that one\n"); 96 VBDEBUG(("GptNextKernelEntry likes that one\n"));
97 e = entries + new_kernel; 97 e = entries + new_kernel;
98 *start_sector = e->starting_lba; 98 *start_sector = e->starting_lba;
99 *size = e->ending_lba - e->starting_lba + 1; 99 *size = e->ending_lba - e->starting_lba + 1;
100 return GPT_SUCCESS; 100 return GPT_SUCCESS;
101 } 101 }
102 102
103 103
104 int GptUpdateKernelEntry(GptData* gpt, uint32_t update_type) { 104 int GptUpdateKernelEntry(GptData* gpt, uint32_t update_type) {
105 GptHeader* header = (GptHeader*)gpt->primary_header; 105 GptHeader* header = (GptHeader*)gpt->primary_header;
106 GptEntry* entries = (GptEntry*)gpt->primary_entries; 106 GptEntry* entries = (GptEntry*)gpt->primary_entries;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 /* Use the repair function to update the other copy of the GPT. 153 /* Use the repair function to update the other copy of the GPT.
154 * This is a tad inefficient, but is much faster than the disk I/O 154 * This is a tad inefficient, but is much faster than the disk I/O
155 * to update the GPT on disk so it doesn't matter. */ 155 * to update the GPT on disk so it doesn't matter. */
156 gpt->valid_headers = MASK_PRIMARY; 156 gpt->valid_headers = MASK_PRIMARY;
157 gpt->valid_entries = MASK_PRIMARY; 157 gpt->valid_entries = MASK_PRIMARY;
158 GptRepair(gpt); 158 GptRepair(gpt);
159 159
160 return GPT_SUCCESS; 160 return GPT_SUCCESS;
161 } 161 }
OLDNEW
« no previous file with comments | « firmware/include/utility.h ('k') | firmware/lib/cryptolib/rsa.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698