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

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

Issue 6469059: VbNvStorage cleanup and comments (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Fixes from code review Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « firmware/include/vboot_nvstorage.h ('k') | firmware/linktest/main.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) 2011 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2011 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 /* Non-volatile storage routines. 6 /* Non-volatile storage routines.
7 */ 7 */
8 8
9 #include "utility.h" 9 #include "utility.h"
10 #include "vboot_common.h" 10 #include "vboot_common.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 /* Nothing has changed yet. */ 55 /* Nothing has changed yet. */
56 context->raw_changed = 0; 56 context->raw_changed = 0;
57 context->regenerate_crc = 0; 57 context->regenerate_crc = 0;
58 58
59 /* Check data for consistency */ 59 /* Check data for consistency */
60 if ((HEADER_SIGNATURE != (raw[HEADER_OFFSET] & HEADER_MASK)) 60 if ((HEADER_SIGNATURE != (raw[HEADER_OFFSET] & HEADER_MASK))
61 || (Crc8(raw, CRC_OFFSET) != raw[CRC_OFFSET])) { 61 || (Crc8(raw, CRC_OFFSET) != raw[CRC_OFFSET])) {
62 62
63 /* Data is inconsistent (bad CRC or header), so reset defaults */ 63 /* Data is inconsistent (bad CRC or header), so reset defaults */
64 Memset(raw, 0, NV_BLOCK_SIZE); 64 Memset(raw, 0, VBNV_BLOCK_SIZE);
65 raw[HEADER_OFFSET] = (HEADER_SIGNATURE | HEADER_FIRMWARE_SETTINGS_RESET | 65 raw[HEADER_OFFSET] = (HEADER_SIGNATURE | HEADER_FIRMWARE_SETTINGS_RESET |
66 HEADER_KERNEL_SETTINGS_RESET); 66 HEADER_KERNEL_SETTINGS_RESET);
67 67
68 /* Regenerate CRC on exit */ 68 /* Regenerate CRC on exit */
69 context->regenerate_crc = 1; 69 context->regenerate_crc = 1;
70 } 70 }
71 71
72 return 0; 72 return 0;
73 } 73 }
74 74
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (value) 146 if (value)
147 raw[HEADER_OFFSET] |= HEADER_KERNEL_SETTINGS_RESET; 147 raw[HEADER_OFFSET] |= HEADER_KERNEL_SETTINGS_RESET;
148 else 148 else
149 raw[HEADER_OFFSET] &= ~HEADER_KERNEL_SETTINGS_RESET; 149 raw[HEADER_OFFSET] &= ~HEADER_KERNEL_SETTINGS_RESET;
150 break; 150 break;
151 151
152 case VBNV_DEBUG_RESET_MODE: 152 case VBNV_DEBUG_RESET_MODE:
153 if (value) 153 if (value)
154 raw[BOOT_OFFSET] |= BOOT_DEBUG_RESET_MODE; 154 raw[BOOT_OFFSET] |= BOOT_DEBUG_RESET_MODE;
155 else 155 else
156 raw[BOOT_OFFSET] &= BOOT_DEBUG_RESET_MODE; 156 raw[BOOT_OFFSET] &= ~BOOT_DEBUG_RESET_MODE;
157 break; 157 break;
158 158
159 case VBNV_TRY_B_COUNT: 159 case VBNV_TRY_B_COUNT:
160 /* Clip to valid range. */
161 if (value > BOOT_TRY_B_COUNT)
162 value = BOOT_TRY_B_COUNT - 1;
163
160 raw[BOOT_OFFSET] &= ~BOOT_TRY_B_COUNT; 164 raw[BOOT_OFFSET] &= ~BOOT_TRY_B_COUNT;
161 raw[BOOT_OFFSET] |= (uint8_t)(value & BOOT_TRY_B_COUNT); 165 raw[BOOT_OFFSET] |= (uint8_t)value;
162 break; 166 break;
163 167
164 case VBNV_RECOVERY_REQUEST: 168 case VBNV_RECOVERY_REQUEST:
169 /* Map values outside the valid range to the legacy reason, since we
170 * can't determine if we're called from kernel or user mode. */
171 if (value > 0xFF)
172 value = VBNV_RECOVERY_LEGACY;
165 raw[RECOVERY_OFFSET] = (uint8_t)value; 173 raw[RECOVERY_OFFSET] = (uint8_t)value;
166 break; 174 break;
167 175
168 case VBNV_LOCALIZATION_INDEX: 176 case VBNV_LOCALIZATION_INDEX:
177 /* Map values outside the valid range to the default index. */
178 if (value > 0xFF)
179 value = 0;
169 raw[LOCALIZATION_OFFSET] = (uint8_t)value; 180 raw[LOCALIZATION_OFFSET] = (uint8_t)value;
170 break; 181 break;
171 182
172 case VBNV_KERNEL_FIELD: 183 case VBNV_KERNEL_FIELD:
173 raw[KERNEL_FIELD_OFFSET] = (uint8_t)(value); 184 raw[KERNEL_FIELD_OFFSET] = (uint8_t)(value);
174 raw[KERNEL_FIELD_OFFSET + 1] = (uint8_t)(value >> 8); 185 raw[KERNEL_FIELD_OFFSET + 1] = (uint8_t)(value >> 8);
175 raw[KERNEL_FIELD_OFFSET + 2] = (uint8_t)(value >> 16); 186 raw[KERNEL_FIELD_OFFSET + 2] = (uint8_t)(value >> 16);
176 raw[KERNEL_FIELD_OFFSET + 3] = (uint8_t)(value >> 24); 187 raw[KERNEL_FIELD_OFFSET + 3] = (uint8_t)(value >> 24);
177 break; 188 break;
178 189
179 default: 190 default:
180 return 1; 191 return 1;
181 } 192 }
182 193
183 /* Need to regenerate CRC, since the value changed. */ 194 /* Need to regenerate CRC, since the value changed. */
184 context->regenerate_crc = 1; 195 context->regenerate_crc = 1;
185 return 0; 196 return 0;
186 } 197 }
OLDNEW
« no previous file with comments | « firmware/include/vboot_nvstorage.h ('k') | firmware/linktest/main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698