OLD | NEW |
---|---|
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 Loading... | |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 case VBNV_LOCALIZATION_INDEX: | 112 case VBNV_LOCALIZATION_INDEX: |
113 *dest = raw[LOCALIZATION_OFFSET]; | 113 *dest = raw[LOCALIZATION_OFFSET]; |
114 return 0; | 114 return 0; |
115 | 115 |
116 case VBNV_KERNEL_FIELD: | 116 case VBNV_KERNEL_FIELD: |
117 *dest = (raw[KERNEL_FIELD_OFFSET] | 117 *dest = (raw[KERNEL_FIELD_OFFSET] |
118 | (raw[KERNEL_FIELD_OFFSET + 1] << 8) | 118 | (raw[KERNEL_FIELD_OFFSET + 1] << 8) |
119 | (raw[KERNEL_FIELD_OFFSET + 2] << 16) | 119 | (raw[KERNEL_FIELD_OFFSET + 2] << 16) |
120 | (raw[KERNEL_FIELD_OFFSET + 3] << 24)); | 120 | (raw[KERNEL_FIELD_OFFSET + 3] << 24)); |
121 return 0; | 121 return 0; |
122 | 122 |
Luigi Semenzato
2011/02/18 23:51:50
Idle suggestion: since the header file mentions th
| |
123 default: | 123 default: |
124 return 1; | 124 return 1; |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 | 128 |
129 int VbNvSet(VbNvContext* context, VbNvParam param, uint32_t value) { | 129 int VbNvSet(VbNvContext* context, VbNvParam param, uint32_t value) { |
130 uint8_t* raw = context->raw; | 130 uint8_t* raw = context->raw; |
131 uint32_t current; | 131 uint32_t current; |
132 | 132 |
(...skipping 13 matching lines...) Expand all Loading... | |
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; |
Luigi Semenzato
2011/02/18 23:51:50
Missing negation?
| |
157 break; | 157 break; |
158 | 158 |
159 case VBNV_TRY_B_COUNT: | 159 case VBNV_TRY_B_COUNT: |
160 raw[BOOT_OFFSET] &= ~BOOT_TRY_B_COUNT; | 160 raw[BOOT_OFFSET] &= ~BOOT_TRY_B_COUNT; |
161 raw[BOOT_OFFSET] |= (uint8_t)(value & BOOT_TRY_B_COUNT); | 161 raw[BOOT_OFFSET] |= (uint8_t)(value & BOOT_TRY_B_COUNT); |
Luigi Semenzato
2011/02/18 23:51:50
Is it worth protecting from illegal values of VALU
| |
162 break; | 162 break; |
163 | 163 |
164 case VBNV_RECOVERY_REQUEST: | 164 case VBNV_RECOVERY_REQUEST: |
165 raw[RECOVERY_OFFSET] = (uint8_t)value; | 165 raw[RECOVERY_OFFSET] = (uint8_t)value; |
166 break; | 166 break; |
167 | 167 |
168 case VBNV_LOCALIZATION_INDEX: | 168 case VBNV_LOCALIZATION_INDEX: |
169 raw[LOCALIZATION_OFFSET] = (uint8_t)value; | 169 raw[LOCALIZATION_OFFSET] = (uint8_t)value; |
170 break; | 170 break; |
171 | 171 |
172 case VBNV_KERNEL_FIELD: | 172 case VBNV_KERNEL_FIELD: |
173 raw[KERNEL_FIELD_OFFSET] = (uint8_t)(value); | 173 raw[KERNEL_FIELD_OFFSET] = (uint8_t)(value); |
174 raw[KERNEL_FIELD_OFFSET + 1] = (uint8_t)(value >> 8); | 174 raw[KERNEL_FIELD_OFFSET + 1] = (uint8_t)(value >> 8); |
175 raw[KERNEL_FIELD_OFFSET + 2] = (uint8_t)(value >> 16); | 175 raw[KERNEL_FIELD_OFFSET + 2] = (uint8_t)(value >> 16); |
176 raw[KERNEL_FIELD_OFFSET + 3] = (uint8_t)(value >> 24); | 176 raw[KERNEL_FIELD_OFFSET + 3] = (uint8_t)(value >> 24); |
177 break; | 177 break; |
178 | 178 |
179 default: | 179 default: |
180 return 1; | 180 return 1; |
181 } | 181 } |
182 | 182 |
183 /* Need to regenerate CRC, since the value changed. */ | 183 /* Need to regenerate CRC, since the value changed. */ |
184 context->regenerate_crc = 1; | 184 context->regenerate_crc = 1; |
185 return 0; | 185 return 0; |
186 } | 186 } |
OLD | NEW |