Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 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 |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 8 | #include <sys/types.h> |
| 9 | #include <sys/stat.h> |
| 10 | #include <unistd.h> |
| 11 | #include <ctype.h> |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 12 | |
| 13 | #include "host_common.h" |
| 14 | |
| 15 | #include "crossystem.h" |
| 16 | #include "utility.h" |
| 17 | #include "vboot_common.h" |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 18 | #include "vboot_nvstorage.h" |
Randall Spangler | f4ba19d | 2011-03-17 16:10:21 -0700 | [diff] [blame^] | 19 | #include "vboot_struct.h" |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 20 | |
| 21 | /* ACPI constants from Chrome OS Main Processor Firmware Spec */ |
| 22 | /* GPIO signal types */ |
| 23 | #define GPIO_SIGNAL_TYPE_RECOVERY 1 |
| 24 | #define GPIO_SIGNAL_TYPE_DEV 2 |
| 25 | #define GPIO_SIGNAL_TYPE_WP 3 |
| 26 | /* CHSW bitflags */ |
| 27 | #define CHSW_RECOVERY_BOOT 0x00000002 |
| 28 | #define CHSW_RECOVERY_EC_BOOT 0x00000004 |
| 29 | #define CHSW_DEV_BOOT 0x00000020 |
| 30 | #define CHSW_WP_BOOT 0x00000200 |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 31 | /* CMOS reboot field bitflags */ |
| 32 | #define CMOSRF_RECOVERY 0x80 |
| 33 | #define CMOSRF_DEBUG_RESET 0x40 |
| 34 | #define CMOSRF_TRY_B 0x20 |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 35 | /* Boot reasons from BINF.0, from early H2C firmware */ |
| 36 | /* Unknown */ |
| 37 | #define BINF0_UNKNOWN 0 |
| 38 | /* Normal boot to Chrome OS */ |
| 39 | #define BINF0_NORMAL 1 |
| 40 | /* Developer mode boot (developer mode warning displayed) */ |
| 41 | #define BINF0_DEVELOPER 2 |
| 42 | /* Recovery initiated by user, using recovery button */ |
| 43 | #define BINF0_RECOVERY_BUTTON 3 |
| 44 | /* Recovery initiated by user pressing a key at developer mode warning |
| 45 | * screen */ |
| 46 | #define BINF0_RECOVERY_DEV_SCREEN_KEY 4 |
| 47 | /* Recovery caused by BIOS failed signature check (neither rewritable |
| 48 | * firmware was valid) */ |
| 49 | #define BINF0_RECOVERY_RW_FW_BAD 5 |
| 50 | /* Recovery caused by no OS kernel detected */ |
| 51 | #define BINF0_RECOVERY_NO_OS 6 |
| 52 | /* Recovery caused by OS kernel failed signature check */ |
| 53 | #define BINF0_RECOVERY_BAD_OS 7 |
| 54 | /* Recovery initiated by OS */ |
| 55 | #define BINF0_RECOVERY_OS_INITIATED 8 |
| 56 | /* OS-initiated S3 diagnostic path (debug mode boot) */ |
| 57 | #define BINF0_S3_DIAGNOSTIC_PATH 9 |
| 58 | /* S3 resume failed */ |
| 59 | #define BINF0_S3_RESUME_FAILED 10 |
| 60 | /* Recovery caused by TPM error */ |
| 61 | #define BINF0_RECOVERY_TPM_ERROR 11 |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 62 | /* Firmware types from BINF.3 */ |
| 63 | #define BINF3_RECOVERY 0 |
| 64 | #define BINF3_NORMAL 1 |
| 65 | #define BINF3_DEVELOPER 2 |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 66 | |
| 67 | /* Base name for ACPI files */ |
| 68 | #define ACPI_BASE_PATH "/sys/devices/platform/chromeos_acpi" |
| 69 | /* Paths for frequently used ACPI files */ |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 70 | #define ACPI_BINF_PATH ACPI_BASE_PATH "/BINF" |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 71 | #define ACPI_CHNV_PATH ACPI_BASE_PATH "/CHNV" |
| 72 | #define ACPI_CHSW_PATH ACPI_BASE_PATH "/CHSW" |
Randall Spangler | 2b59a07 | 2011-02-24 11:17:24 -0800 | [diff] [blame] | 73 | #define ACPI_FMAP_PATH ACPI_BASE_PATH "/FMAP" |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 74 | #define ACPI_GPIO_PATH ACPI_BASE_PATH "/GPIO" |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 75 | #define ACPI_VBNV_PATH ACPI_BASE_PATH "/VBNV" |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 76 | #define ACPI_VDAT_PATH ACPI_BASE_PATH "/VDAT" |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 77 | |
| 78 | /* Base name for GPIO files */ |
| 79 | #define GPIO_BASE_PATH "/sys/class/gpio" |
| 80 | #define GPIO_EXPORT_PATH GPIO_BASE_PATH "/export" |
| 81 | |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 82 | /* Filename for NVRAM file */ |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 83 | #define NVRAM_PATH "/dev/nvram" |
| 84 | |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 85 | /* Filename for kernel command line */ |
| 86 | #define KERNEL_CMDLINE_PATH "/proc/cmdline" |
| 87 | |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 88 | /* A structure to contain buffer data retrieved from the ACPI. */ |
| 89 | typedef struct { |
| 90 | int buffer_size; |
Randall Spangler | f4ba19d | 2011-03-17 16:10:21 -0700 | [diff] [blame^] | 91 | uint8_t* buffer; |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 92 | } AcpiBuffer; |
| 93 | |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 94 | |
Randall Spangler | f4ba19d | 2011-03-17 16:10:21 -0700 | [diff] [blame^] | 95 | /* Fields that GetVdatString() can get */ |
| 96 | typedef enum VdatStringField { |
| 97 | VDAT_STRING_TIMERS = 0, /* Timer values */ |
| 98 | VDAT_STRING_LOAD_FIRMWARE_DEBUG /* LoadFirmware() debug information */ |
| 99 | } VdatStringField; |
| 100 | |
| 101 | |
| 102 | /* Fields that GetVdatInt() can get */ |
| 103 | typedef enum VdatIntField { |
| 104 | VDAT_INT_FLAGS = 0 /* Flags */ |
| 105 | } VdatIntField; |
| 106 | |
| 107 | |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 108 | /* Copy up to dest_size-1 characters from src to dest, ensuring null |
| 109 | termination (which strncpy() doesn't do). Returns the destination |
| 110 | string. */ |
| 111 | char* StrCopy(char* dest, const char* src, int dest_size) { |
| 112 | strncpy(dest, src, dest_size); |
| 113 | dest[dest_size - 1] = '\0'; |
| 114 | return dest; |
| 115 | } |
| 116 | |
| 117 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 118 | /* Read a string from a file. Passed the destination, dest size, and |
| 119 | * filename to read. |
| 120 | * |
| 121 | * Returns the destination, or NULL if error. */ |
| 122 | char* ReadFileString(char* dest, int size, const char* filename) { |
| 123 | char* got; |
| 124 | FILE* f; |
| 125 | |
| 126 | f = fopen(filename, "rt"); |
| 127 | if (!f) |
| 128 | return NULL; |
| 129 | |
| 130 | got = fgets(dest, size, f); |
| 131 | fclose(f); |
| 132 | return got; |
| 133 | } |
| 134 | |
| 135 | |
| 136 | /* Read an integer from a file. |
| 137 | * |
| 138 | * Returns the parsed integer, or -1 if error. */ |
| 139 | int ReadFileInt(const char* filename) { |
| 140 | char buf[64]; |
| 141 | int value; |
| 142 | char* e = NULL; |
| 143 | |
| 144 | if (!ReadFileString(buf, sizeof(buf), filename)) |
| 145 | return -1; |
| 146 | |
| 147 | /* Convert to integer. Allow characters after the int ("123 blah"). */ |
| 148 | value = strtol(buf, &e, 0); |
| 149 | if (e == buf) |
| 150 | return -1; /* No characters consumed, so conversion failed */ |
| 151 | |
| 152 | return value; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | /* Check if a bit is set in a file which contains an integer. |
| 157 | * |
| 158 | * Returns 1 if the bit is set, 0 if clear, or -1 if error. */ |
| 159 | int ReadFileBit(const char* filename, int bitmask) { |
| 160 | int value = ReadFileInt(filename); |
| 161 | if (value == -1) |
| 162 | return -1; |
| 163 | else return (value & bitmask ? 1 : 0); |
| 164 | } |
| 165 | |
| 166 | |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 167 | /* Return true if the FWID starts with the specified string. */ |
| 168 | static int FwidStartsWith(const char *start) { |
| 169 | char fwid[128]; |
| 170 | if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid))) |
| 171 | return 0; |
| 172 | |
| 173 | return 0 == strncmp(fwid, start, strlen(start)); |
| 174 | } |
| 175 | |
| 176 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 177 | /* Read a GPIO of the specified signal type (see ACPI GPIO SignalType). |
| 178 | * |
| 179 | * Returns 1 if the signal is asserted, 0 if not asserted, or -1 if error. */ |
| 180 | int ReadGpio(int signal_type) { |
| 181 | char name[128]; |
| 182 | int index = 0; |
| 183 | int gpio_type; |
| 184 | int active_high; |
| 185 | int controller_offset; |
| 186 | char controller_name[128]; |
| 187 | int value; |
| 188 | |
| 189 | /* Scan GPIO.* to find a matching signal type */ |
| 190 | for (index = 0; ; index++) { |
| 191 | snprintf(name, sizeof(name), "%s.%d/GPIO.0", ACPI_GPIO_PATH, index); |
| 192 | gpio_type = ReadFileInt(name); |
| 193 | if (gpio_type == signal_type) |
| 194 | break; |
| 195 | else if (gpio_type == -1) |
| 196 | return -1; /* Ran out of GPIOs before finding a match */ |
| 197 | } |
| 198 | |
| 199 | /* Read attributes and controller info for the GPIO */ |
| 200 | snprintf(name, sizeof(name), "%s.%d/GPIO.1", ACPI_GPIO_PATH, index); |
| 201 | active_high = ReadFileBit(name, 0x00000001); |
| 202 | snprintf(name, sizeof(name), "%s.%d/GPIO.2", ACPI_GPIO_PATH, index); |
| 203 | controller_offset = ReadFileInt(name); |
| 204 | if (active_high == -1 || controller_offset == -1) |
| 205 | return -1; /* Missing needed info */ |
| 206 | |
| 207 | /* We only support the NM10 for now */ |
| 208 | snprintf(name, sizeof(name), "%s.%d/GPIO.3", ACPI_GPIO_PATH, index); |
| 209 | if (!ReadFileString(controller_name, sizeof(controller_name), name)) |
| 210 | return -1; |
| 211 | if (0 != strcmp(controller_name, "NM10")) |
| 212 | return -1; |
| 213 | |
| 214 | /* Assume the NM10 has offset 192 */ |
| 215 | /* TODO: should really check gpiochipNNN/label to see if it's the |
| 216 | * address we expect for the NM10, and then read the offset from |
| 217 | * gpiochipNNN/base. */ |
| 218 | controller_offset += 192; |
| 219 | |
| 220 | /* Try reading the GPIO value */ |
| 221 | snprintf(name, sizeof(name), "%s/gpio%d/value", |
| 222 | GPIO_BASE_PATH, controller_offset); |
| 223 | value = ReadFileInt(name); |
| 224 | |
| 225 | if (value == -1) { |
| 226 | /* Try exporting the GPIO */ |
| 227 | FILE* f = fopen(GPIO_EXPORT_PATH, "wt"); |
| 228 | if (!f) |
| 229 | return -1; |
| 230 | fprintf(f, "%d", controller_offset); |
| 231 | fclose(f); |
| 232 | |
| 233 | /* Try re-reading the GPIO value */ |
| 234 | value = ReadFileInt(name); |
| 235 | } |
| 236 | |
| 237 | if (value == -1) |
| 238 | return -1; |
| 239 | |
| 240 | /* Compare the GPIO value with the active value and return 1 if match. */ |
| 241 | return (value == active_high ? 1 : 0); |
| 242 | } |
| 243 | |
| 244 | |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 245 | /* Read the CMOS reboot field in NVRAM. |
| 246 | * |
| 247 | * Returns 0 if the mask is clear in the field, 1 if set, or -1 if error. */ |
| 248 | int VbGetCmosRebootField(uint8_t mask) { |
| 249 | FILE* f; |
| 250 | int chnv, nvbyte; |
| 251 | |
| 252 | /* Get the byte offset from CHNV */ |
| 253 | chnv = ReadFileInt(ACPI_CHNV_PATH); |
| 254 | if (chnv == -1) |
| 255 | return -1; |
| 256 | |
| 257 | f = fopen(NVRAM_PATH, "rb"); |
| 258 | if (!f) |
| 259 | return -1; |
| 260 | |
| 261 | if (0 != fseek(f, chnv, SEEK_SET) || EOF == (nvbyte = fgetc(f))) { |
| 262 | fclose(f); |
| 263 | return -1; |
| 264 | } |
| 265 | |
| 266 | fclose(f); |
| 267 | return (nvbyte & mask ? 1 : 0); |
| 268 | } |
| 269 | |
| 270 | |
| 271 | /* Write the CMOS reboot field in NVRAM. |
| 272 | * |
| 273 | * Sets (value=0) or clears (value!=0) the mask in the byte. |
| 274 | * |
| 275 | * Returns 0 if success, or -1 if error. */ |
| 276 | int VbSetCmosRebootField(uint8_t mask, int value) { |
| 277 | FILE* f; |
| 278 | int chnv, nvbyte; |
| 279 | |
| 280 | /* Get the byte offset from CHNV */ |
| 281 | chnv = ReadFileInt(ACPI_CHNV_PATH); |
| 282 | if (chnv == -1) |
| 283 | return -1; |
| 284 | |
| 285 | f = fopen(NVRAM_PATH, "w+b"); |
| 286 | if (!f) |
| 287 | return -1; |
| 288 | |
| 289 | /* Read the current value */ |
| 290 | if (0 != fseek(f, chnv, SEEK_SET) || EOF == (nvbyte = fgetc(f))) { |
| 291 | fclose(f); |
| 292 | return -1; |
| 293 | } |
| 294 | |
| 295 | /* Set/clear the mask */ |
| 296 | if (value) |
| 297 | nvbyte |= mask; |
| 298 | else |
| 299 | nvbyte &= ~mask; |
| 300 | |
| 301 | /* Write the byte back */ |
| 302 | if (0 != fseek(f, chnv, SEEK_SET) || EOF == (fputc(nvbyte, f))) { |
| 303 | fclose(f); |
| 304 | return -1; |
| 305 | } |
| 306 | |
| 307 | /* Success */ |
| 308 | fclose(f); |
| 309 | return 0; |
| 310 | } |
| 311 | |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 312 | /* |
| 313 | * Get buffer data from ACPI. |
| 314 | * |
| 315 | * Buffer data is expected to be represented by a file which is a text dump of |
| 316 | * the buffer, representing each byte by two hex numbers, space and newline |
| 317 | * separated. |
| 318 | * |
| 319 | * Input - ACPI file name to get data from. |
| 320 | * |
| 321 | * Output: a pointer to AcpiBuffer structure containing the binary |
| 322 | * representation of the data. The caller is responsible for |
| 323 | * deallocating the pointer, this will take care of both the structure |
| 324 | * and the buffer. Null in case of error. |
| 325 | */ |
| 326 | |
| 327 | AcpiBuffer* VbGetBuffer(const char* filename) |
| 328 | { |
| 329 | FILE* f = NULL; |
| 330 | char* file_buffer = NULL; |
| 331 | AcpiBuffer* acpi_buffer = NULL; |
| 332 | AcpiBuffer* return_value = NULL; |
| 333 | |
| 334 | do { |
| 335 | struct stat fs; |
Randall Spangler | f4ba19d | 2011-03-17 16:10:21 -0700 | [diff] [blame^] | 336 | uint8_t* output_ptr; |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 337 | int rv, i, real_size; |
| 338 | |
| 339 | rv = stat(filename, &fs); |
| 340 | if (rv || !S_ISREG(fs.st_mode)) |
| 341 | break; |
| 342 | |
| 343 | f = fopen(filename, "r"); |
| 344 | if (!f) |
| 345 | break; |
| 346 | |
| 347 | file_buffer = Malloc(fs.st_size + 1); |
| 348 | if (!file_buffer) |
| 349 | break; |
| 350 | |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 351 | real_size = fread(file_buffer, 1, fs.st_size, f); |
| 352 | if (!real_size) |
| 353 | break; |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 354 | file_buffer[real_size] = '\0'; |
| 355 | |
Randall Spangler | f4ba19d | 2011-03-17 16:10:21 -0700 | [diff] [blame^] | 356 | /* Each byte in the output will replace two characters and a space |
| 357 | * in the input, so the output size does not exceed input side/3 |
| 358 | * (a little less if account for newline characters). */ |
| 359 | acpi_buffer = Malloc(sizeof(AcpiBuffer) + real_size/3); |
| 360 | if (!acpi_buffer) |
| 361 | break; |
| 362 | acpi_buffer->buffer = (uint8_t*)(acpi_buffer + 1); |
Vadim Bendebury | 2008423 | 2011-03-15 09:29:48 -0700 | [diff] [blame] | 363 | acpi_buffer->buffer_size = 0; |
| 364 | output_ptr = acpi_buffer->buffer; |
| 365 | |
| 366 | /* process the file contents */ |
| 367 | for (i = 0; i < real_size; i++) { |
| 368 | char* base, *end; |
| 369 | |
| 370 | base = file_buffer + i; |
| 371 | |
| 372 | if (!isxdigit(*base)) |
| 373 | continue; |
| 374 | |
| 375 | output_ptr[acpi_buffer->buffer_size++] = strtol(base, &end, 16) & 0xff; |
| 376 | |
| 377 | if ((end - base) != 2) |
| 378 | /* Input file format error */ |
| 379 | break; |
| 380 | |
| 381 | i += 2; /* skip the second character and the following space */ |
| 382 | } |
| 383 | |
| 384 | if (i == real_size) { |
| 385 | /* all is well */ |
| 386 | return_value = acpi_buffer; |
| 387 | acpi_buffer = NULL; /* prevent it from deallocating */ |
| 388 | } |
| 389 | } while(0); |
| 390 | |
| 391 | /* wrap up */ |
| 392 | if (f) |
| 393 | fclose(f); |
| 394 | |
| 395 | if (file_buffer) |
| 396 | Free(file_buffer); |
| 397 | |
| 398 | if (acpi_buffer) |
| 399 | Free(acpi_buffer); |
| 400 | |
| 401 | return return_value; |
| 402 | } |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 403 | |
| 404 | /* Read an integer property from VbNvStorage. |
| 405 | * |
| 406 | * Returns the parameter value, or -1 if error. */ |
| 407 | int VbGetNvStorage(VbNvParam param) { |
| 408 | FILE* f; |
| 409 | VbNvContext vnc; |
| 410 | int offs; |
| 411 | uint32_t value; |
| 412 | int retval; |
| 413 | |
| 414 | /* Get the byte offset from VBNV */ |
| 415 | offs = ReadFileInt(ACPI_VBNV_PATH ".0"); |
| 416 | if (offs == -1) |
| 417 | return -1; |
| 418 | if (VBNV_BLOCK_SIZE > ReadFileInt(ACPI_VBNV_PATH ".1")) |
| 419 | return -1; /* NV storage block is too small */ |
| 420 | |
| 421 | /* TODO: locking around NV access */ |
| 422 | f = fopen(NVRAM_PATH, "rb"); |
| 423 | if (!f) |
| 424 | return -1; |
| 425 | |
| 426 | if (0 != fseek(f, offs, SEEK_SET) || |
| 427 | 1 != fread(vnc.raw, VBNV_BLOCK_SIZE, 1, f)) { |
| 428 | fclose(f); |
| 429 | return -1; |
| 430 | } |
| 431 | |
| 432 | fclose(f); |
| 433 | |
| 434 | if (0 != VbNvSetup(&vnc)) |
| 435 | return -1; |
| 436 | retval = VbNvGet(&vnc, param, &value); |
| 437 | if (0 != VbNvTeardown(&vnc)) |
| 438 | return -1; |
| 439 | if (0 != retval) |
| 440 | return -1; |
| 441 | |
| 442 | /* TODO: If vnc.raw_changed, attempt to reopen NVRAM for write and |
| 443 | * save the new defaults. If we're able to, log. */ |
| 444 | /* TODO: release lock */ |
| 445 | |
| 446 | return (int)value; |
| 447 | } |
| 448 | |
| 449 | |
| 450 | /* Write an integer property to VbNvStorage. |
| 451 | * |
| 452 | * Returns 0 if success, -1 if error. */ |
| 453 | int VbSetNvStorage(VbNvParam param, int value) { |
| 454 | FILE* f; |
| 455 | VbNvContext vnc; |
| 456 | int offs; |
| 457 | int retval = -1; |
| 458 | int i; |
| 459 | |
| 460 | /* Get the byte offset from VBNV */ |
| 461 | offs = ReadFileInt(ACPI_VBNV_PATH ".0"); |
| 462 | if (offs == -1) |
| 463 | return -1; |
| 464 | if (VBNV_BLOCK_SIZE > ReadFileInt(ACPI_VBNV_PATH ".1")) |
| 465 | return -1; /* NV storage block is too small */ |
| 466 | |
| 467 | /* TODO: locking around NV access */ |
| 468 | f = fopen(NVRAM_PATH, "w+b"); |
| 469 | if (!f) |
| 470 | return -1; |
| 471 | |
| 472 | if (0 != fseek(f, offs, SEEK_SET) || |
| 473 | 1 != fread(vnc.raw, VBNV_BLOCK_SIZE, 1, f)) { |
| 474 | goto VbSetNvCleanup; |
| 475 | } |
| 476 | |
| 477 | if (0 != VbNvSetup(&vnc)) |
| 478 | goto VbSetNvCleanup; |
| 479 | i = VbNvSet(&vnc, param, (uint32_t)value); |
| 480 | if (0 != VbNvTeardown(&vnc)) |
| 481 | goto VbSetNvCleanup; |
| 482 | if (0 != i) |
| 483 | goto VbSetNvCleanup; |
| 484 | |
| 485 | if (vnc.raw_changed) { |
| 486 | if (0 != fseek(f, offs, SEEK_SET) || |
| 487 | 1 != fwrite(vnc.raw, VBNV_BLOCK_SIZE, 1, f)) |
| 488 | goto VbSetNvCleanup; |
| 489 | } |
| 490 | |
| 491 | /* Success */ |
| 492 | retval = 0; |
| 493 | |
| 494 | VbSetNvCleanup: |
| 495 | fclose(f); |
| 496 | /* TODO: release lock */ |
| 497 | return retval; |
| 498 | } |
| 499 | |
| 500 | |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 501 | /* Read the recovery reason. Returns the reason code or -1 if error. */ |
| 502 | int VbGetRecoveryReason(void) { |
| 503 | int value; |
| 504 | |
| 505 | /* Try reading type from BINF.4 */ |
| 506 | value = ReadFileInt(ACPI_BINF_PATH ".4"); |
| 507 | if (-1 != value) |
| 508 | return value; |
| 509 | |
| 510 | /* Fall back to BINF.0 for legacy systems like Mario. */ |
| 511 | switch(ReadFileInt(ACPI_BINF_PATH ".0")) { |
| 512 | case BINF0_NORMAL: |
| 513 | case BINF0_DEVELOPER: |
| 514 | return VBNV_RECOVERY_NOT_REQUESTED; |
| 515 | case BINF0_RECOVERY_BUTTON: |
| 516 | return VBNV_RECOVERY_RO_MANUAL; |
| 517 | case BINF0_RECOVERY_DEV_SCREEN_KEY: |
| 518 | return VBNV_RECOVERY_RW_DEV_SCREEN; |
| 519 | case BINF0_RECOVERY_RW_FW_BAD: |
| 520 | case BINF0_RECOVERY_NO_OS: |
| 521 | return VBNV_RECOVERY_RW_NO_OS; |
| 522 | case BINF0_RECOVERY_BAD_OS: |
| 523 | return VBNV_RECOVERY_RW_INVALID_OS; |
| 524 | case BINF0_RECOVERY_OS_INITIATED: |
| 525 | return VBNV_RECOVERY_LEGACY; |
| 526 | default: |
| 527 | /* Other values don't map cleanly to firmware type. */ |
| 528 | return -1; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | |
| 533 | /* Read the active main firmware type into the destination buffer. |
| 534 | * Passed the destination and its size. Returns the destination, or |
| 535 | * NULL if error. */ |
| 536 | const char* VbReadMainFwType(char* dest, int size) { |
| 537 | |
| 538 | /* Try reading type from BINF.3 */ |
| 539 | switch(ReadFileInt(ACPI_BINF_PATH ".3")) { |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 540 | case BINF3_RECOVERY: |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 541 | return StrCopy(dest, "recovery", size); |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 542 | case BINF3_NORMAL: |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 543 | return StrCopy(dest, "normal", size); |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 544 | case BINF3_DEVELOPER: |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 545 | return StrCopy(dest, "developer", size); |
| 546 | default: |
| 547 | break; /* Fall through to legacy handling */ |
| 548 | } |
| 549 | |
| 550 | /* Fall back to BINF.0 for legacy systems like Mario. */ |
| 551 | switch(ReadFileInt(ACPI_BINF_PATH ".0")) { |
| 552 | case -1: |
| 553 | /* Both BINF.0 and BINF.3 are missing, so this isn't Chrome OS |
| 554 | * firmware. */ |
| 555 | return StrCopy(dest, "nonchrome", size); |
| 556 | case BINF0_NORMAL: |
| 557 | return StrCopy(dest, "normal", size); |
| 558 | case BINF0_DEVELOPER: |
| 559 | return StrCopy(dest, "developer", size); |
| 560 | case BINF0_RECOVERY_BUTTON: |
| 561 | case BINF0_RECOVERY_DEV_SCREEN_KEY: |
| 562 | case BINF0_RECOVERY_RW_FW_BAD: |
| 563 | case BINF0_RECOVERY_NO_OS: |
| 564 | case BINF0_RECOVERY_BAD_OS: |
| 565 | case BINF0_RECOVERY_OS_INITIATED: |
| 566 | case BINF0_RECOVERY_TPM_ERROR: |
| 567 | /* Assorted flavors of recovery boot reason. */ |
| 568 | return StrCopy(dest, "recovery", size); |
| 569 | default: |
| 570 | /* Other values don't map cleanly to firmware type. */ |
| 571 | return NULL; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 576 | /* Determine whether OS-level debugging should be allowed. Passed the |
| 577 | * destination and its size. Returns 1 if yes, 0 if no, -1 if error. */ |
| 578 | int VbGetCrosDebug(void) { |
| 579 | FILE* f = NULL; |
| 580 | char buf[4096] = ""; |
| 581 | int binf3; |
| 582 | char *t, *saveptr; |
| 583 | |
| 584 | /* Try reading firmware type from BINF.3. */ |
| 585 | binf3 = ReadFileInt(ACPI_BINF_PATH ".3"); |
| 586 | if (BINF3_RECOVERY == binf3) |
| 587 | return 0; /* Recovery mode never allows debug. */ |
| 588 | else if (BINF3_DEVELOPER == binf3) |
| 589 | return 1; /* Developer firmware always allows debug. */ |
| 590 | |
| 591 | /* Normal new firmware, older ChromeOS firmware, or non-Chrome firmware. |
Randall Spangler | 227f792 | 2011-03-11 13:34:56 -0800 | [diff] [blame] | 592 | * For all these cases, check /proc/cmdline for cros_[no]debug. */ |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 593 | f = fopen(KERNEL_CMDLINE_PATH, "rt"); |
| 594 | if (f) { |
| 595 | if (NULL == fgets(buf, sizeof(buf), f)) |
| 596 | *buf = 0; |
| 597 | fclose(f); |
| 598 | } |
| 599 | for (t = strtok_r(buf, " ", &saveptr); t; t=strtok_r(NULL, " ", &saveptr)) { |
| 600 | if (0 == strcmp(t, "cros_debug")) |
| 601 | return 1; |
Randall Spangler | 227f792 | 2011-03-11 13:34:56 -0800 | [diff] [blame] | 602 | else if (0 == strcmp(t, "cros_nodebug")) |
| 603 | return 0; |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /* Normal new firmware or older Chrome OS firmware allows debug if the |
| 607 | * dev switch is on. */ |
| 608 | if (1 == ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT)) |
| 609 | return 1; |
| 610 | |
| 611 | /* All other cases disallow debug. */ |
| 612 | return 0; |
| 613 | } |
| 614 | |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 615 | |
Randall Spangler | f4ba19d | 2011-03-17 16:10:21 -0700 | [diff] [blame^] | 616 | char* GetVdatString(char* dest, int size, VdatStringField field) |
| 617 | { |
| 618 | VbSharedDataHeader* sh; |
| 619 | AcpiBuffer* ab = VbGetBuffer(ACPI_VDAT_PATH); |
| 620 | if (!ab) |
| 621 | return NULL; |
| 622 | |
| 623 | sh = (VbSharedDataHeader*)ab->buffer; |
| 624 | |
| 625 | switch (field) { |
| 626 | case VDAT_STRING_TIMERS: |
| 627 | snprintf(dest, size, |
| 628 | "LFS=%" PRIu64 ",%" PRIu64 |
| 629 | " LF=%" PRIu64 ",%" PRIu64 |
| 630 | " LK=%" PRIu64 ",%" PRIu64, |
| 631 | sh->timer_load_firmware_start_enter, |
| 632 | sh->timer_load_firmware_start_exit, |
| 633 | sh->timer_load_firmware_enter, |
| 634 | sh->timer_load_firmware_exit, |
| 635 | sh->timer_load_kernel_enter, |
| 636 | sh->timer_load_kernel_exit); |
| 637 | break; |
| 638 | |
| 639 | case VDAT_STRING_LOAD_FIRMWARE_DEBUG: |
| 640 | snprintf(dest, size, |
| 641 | "check=%d,%d index=0x%02x tpmver=0x%x lowestver=0x%x", |
| 642 | sh->check_fw_a_result, |
| 643 | sh->check_fw_b_result, |
| 644 | sh->firmware_index, |
| 645 | sh->fw_version_tpm_start, |
| 646 | sh->fw_version_lowest); |
| 647 | break; |
| 648 | |
| 649 | default: |
| 650 | Free(ab); |
| 651 | return NULL; |
| 652 | } |
| 653 | |
| 654 | Free(ab); |
| 655 | return dest; |
| 656 | } |
| 657 | |
| 658 | |
| 659 | int GetVdatInt(VdatIntField field) { |
| 660 | VbSharedDataHeader* sh; |
| 661 | AcpiBuffer* ab = VbGetBuffer(ACPI_VDAT_PATH); |
| 662 | int value = -1; |
| 663 | |
| 664 | if (!ab) |
| 665 | return -1; |
| 666 | |
| 667 | sh = (VbSharedDataHeader*)ab->buffer; |
| 668 | |
| 669 | switch (field) { |
| 670 | case VDAT_INT_FLAGS: |
| 671 | value = (int)sh->flags; |
| 672 | break; |
| 673 | |
| 674 | } |
| 675 | |
| 676 | Free(ab); |
| 677 | return value; |
| 678 | } |
| 679 | |
| 680 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 681 | /* Read a system property integer. |
| 682 | * |
| 683 | * Returns the property value, or -1 if error. */ |
| 684 | int VbGetSystemPropertyInt(const char* name) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 685 | int value = -1; |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 686 | |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 687 | /* Switch positions */ |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 688 | if (!strcasecmp(name,"devsw_cur")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 689 | value = ReadGpio(GPIO_SIGNAL_TYPE_DEV); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 690 | } else if (!strcasecmp(name,"devsw_boot")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 691 | value = ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 692 | } else if (!strcasecmp(name,"recoverysw_cur")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 693 | value = ReadGpio(GPIO_SIGNAL_TYPE_RECOVERY); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 694 | } else if (!strcasecmp(name,"recoverysw_boot")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 695 | value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_BOOT); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 696 | } else if (!strcasecmp(name,"recoverysw_ec_boot")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 697 | value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_EC_BOOT); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 698 | } else if (!strcasecmp(name,"wpsw_cur")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 699 | value = ReadGpio(GPIO_SIGNAL_TYPE_WP); |
| 700 | if (-1 != value && FwidStartsWith("Mario.")) |
| 701 | value = 1 - value; /* Mario reports this backwards */ |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 702 | } else if (!strcasecmp(name,"wpsw_boot")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 703 | value = ReadFileBit(ACPI_CHSW_PATH, CHSW_WP_BOOT); |
| 704 | if (-1 != value && FwidStartsWith("Mario.")) |
| 705 | value = 1 - value; /* Mario reports this backwards */ |
| 706 | } |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 707 | /* Saved memory is at a fixed location for all H2C BIOS. If the CHSW |
| 708 | * path exists in sysfs, it's a H2C BIOS. */ |
| 709 | else if (!strcasecmp(name,"savedmem_base")) { |
| 710 | return (-1 == ReadFileInt(ACPI_CHSW_PATH) ? -1 : 0x00F00000); |
| 711 | } else if (!strcasecmp(name,"savedmem_size")) { |
| 712 | return (-1 == ReadFileInt(ACPI_CHSW_PATH) ? -1 : 0x00100000); |
| 713 | } |
Randall Spangler | 1726028 | 2011-02-25 12:06:26 -0800 | [diff] [blame] | 714 | /* NV storage values with no defaults for older BIOS. */ |
| 715 | else if (!strcasecmp(name,"tried_fwb")) { |
Randall Spangler | 92e378e | 2011-02-25 13:56:53 -0800 | [diff] [blame] | 716 | value = VbGetNvStorage(VBNV_TRIED_FIRMWARE_B); |
Randall Spangler | 618d17d | 2011-03-01 10:33:11 -0800 | [diff] [blame] | 717 | } else if (!strcasecmp(name,"kern_nv")) { |
| 718 | value = VbGetNvStorage(VBNV_KERNEL_FIELD); |
Randall Spangler | b416714 | 2011-03-01 13:04:22 -0800 | [diff] [blame] | 719 | } else if (!strcasecmp(name,"nvram_cleared")) { |
| 720 | value = VbGetNvStorage(VBNV_KERNEL_SETTINGS_RESET); |
Randall Spangler | b17e8d3 | 2011-03-15 09:50:38 -0700 | [diff] [blame] | 721 | } else if (!strcasecmp(name,"vbtest_errfunc")) { |
| 722 | value = VbGetNvStorage(VBNV_TEST_ERROR_FUNC); |
| 723 | } else if (!strcasecmp(name,"vbtest_errno")) { |
| 724 | value = VbGetNvStorage(VBNV_TEST_ERROR_NUM); |
Randall Spangler | 1726028 | 2011-02-25 12:06:26 -0800 | [diff] [blame] | 725 | } |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 726 | /* NV storage values. If unable to get from NV storage, fall back to the |
| 727 | * CMOS reboot field used by older BIOS. */ |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 728 | else if (!strcasecmp(name,"recovery_request")) { |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 729 | value = VbGetNvStorage(VBNV_RECOVERY_REQUEST); |
| 730 | if (-1 == value) |
| 731 | value = VbGetCmosRebootField(CMOSRF_RECOVERY); |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 732 | } else if (!strcasecmp(name,"dbg_reset")) { |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 733 | value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); |
| 734 | if (-1 == value) |
| 735 | value = VbGetCmosRebootField(CMOSRF_DEBUG_RESET); |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 736 | } else if (!strcasecmp(name,"fwb_tries")) { |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 737 | value = VbGetNvStorage(VBNV_TRY_B_COUNT); |
| 738 | if (-1 == value) |
| 739 | value = VbGetCmosRebootField(CMOSRF_TRY_B); |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 740 | } |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 741 | /* Other parameters */ |
| 742 | else if (!strcasecmp(name,"recovery_reason")) { |
| 743 | return VbGetRecoveryReason(); |
Randall Spangler | 2b59a07 | 2011-02-24 11:17:24 -0800 | [diff] [blame] | 744 | } else if (!strcasecmp(name,"fmap_base")) { |
| 745 | value = ReadFileInt(ACPI_FMAP_PATH); |
Randall Spangler | 196e177 | 2011-03-10 11:31:06 -0800 | [diff] [blame] | 746 | } else if (!strcasecmp(name,"cros_debug")) { |
| 747 | value = VbGetCrosDebug(); |
Randall Spangler | f4ba19d | 2011-03-17 16:10:21 -0700 | [diff] [blame^] | 748 | } else if (!strcasecmp(name,"vdat_flags")) { |
| 749 | value = GetVdatInt(VDAT_INT_FLAGS); |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 750 | } |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 751 | |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 752 | return value; |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 753 | } |
| 754 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 755 | /* Read a system property string into a destination buffer of the specified |
| 756 | * size. |
| 757 | * |
| 758 | * Returns the passed buffer, or NULL if error. */ |
| 759 | const char* VbGetSystemPropertyString(const char* name, char* dest, int size) { |
| 760 | |
| 761 | if (!strcasecmp(name,"hwid")) { |
| 762 | return ReadFileString(dest, size, ACPI_BASE_PATH "/HWID"); |
| 763 | } else if (!strcasecmp(name,"fwid")) { |
| 764 | return ReadFileString(dest, size, ACPI_BASE_PATH "/FWID"); |
| 765 | } else if (!strcasecmp(name,"ro_fwid")) { |
| 766 | return ReadFileString(dest, size, ACPI_BASE_PATH "/FRID"); |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 767 | } else if (!strcasecmp(name,"mainfw_act")) { |
| 768 | switch(ReadFileInt(ACPI_BINF_PATH ".1")) { |
| 769 | case 0: |
| 770 | return StrCopy(dest, "recovery", size); |
| 771 | case 1: |
| 772 | return StrCopy(dest, "A", size); |
| 773 | case 2: |
| 774 | return StrCopy(dest, "B", size); |
| 775 | default: |
| 776 | return NULL; |
| 777 | } |
| 778 | } else if (!strcasecmp(name,"mainfw_type")) { |
| 779 | return VbReadMainFwType(dest, size); |
| 780 | } else if (!strcasecmp(name,"ecfw_act")) { |
| 781 | switch(ReadFileInt(ACPI_BINF_PATH ".2")) { |
| 782 | case 0: |
| 783 | return StrCopy(dest, "RO", size); |
| 784 | case 1: |
| 785 | return StrCopy(dest, "RW", size); |
| 786 | default: |
| 787 | return NULL; |
| 788 | } |
Randall Spangler | 1726028 | 2011-02-25 12:06:26 -0800 | [diff] [blame] | 789 | } else if (!strcasecmp(name,"kernkey_vfy")) { |
| 790 | switch(VbGetNvStorage(VBNV_FW_VERIFIED_KERNEL_KEY)) { |
| 791 | case 0: |
| 792 | return "hash"; |
| 793 | case 1: |
| 794 | return "sig"; |
| 795 | default: |
| 796 | return NULL; |
| 797 | } |
Randall Spangler | f4ba19d | 2011-03-17 16:10:21 -0700 | [diff] [blame^] | 798 | } else if (!strcasecmp(name, "vdat_timers")) { |
| 799 | return GetVdatString(dest, size, VDAT_STRING_TIMERS); |
| 800 | } else if (!strcasecmp(name, "vdat_lfdebug")) { |
| 801 | return GetVdatString(dest, size, VDAT_STRING_LOAD_FIRMWARE_DEBUG); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 802 | } else |
| 803 | return NULL; |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | |
| 807 | /* Set a system property integer. |
| 808 | * |
| 809 | * Returns 0 if success, -1 if error. */ |
| 810 | int VbSetSystemPropertyInt(const char* name, int value) { |
| 811 | |
Randall Spangler | 618d17d | 2011-03-01 10:33:11 -0800 | [diff] [blame] | 812 | /* NV storage values with no defaults for older BIOS. */ |
Randall Spangler | b416714 | 2011-03-01 13:04:22 -0800 | [diff] [blame] | 813 | if (!strcasecmp(name,"nvram_cleared")) { |
| 814 | /* Can only clear this flag; it's set inside the NV storage library. */ |
| 815 | return VbSetNvStorage(VBNV_KERNEL_SETTINGS_RESET, 0); |
| 816 | } else if (!strcasecmp(name,"kern_nv")) { |
Randall Spangler | 618d17d | 2011-03-01 10:33:11 -0800 | [diff] [blame] | 817 | return VbSetNvStorage(VBNV_KERNEL_FIELD, value); |
Randall Spangler | b17e8d3 | 2011-03-15 09:50:38 -0700 | [diff] [blame] | 818 | } else if (!strcasecmp(name,"vbtest_errfunc")) { |
| 819 | return VbSetNvStorage(VBNV_TEST_ERROR_FUNC, value); |
| 820 | } else if (!strcasecmp(name,"vbtest_errno")) { |
| 821 | return VbSetNvStorage(VBNV_TEST_ERROR_NUM, value); |
Randall Spangler | 618d17d | 2011-03-01 10:33:11 -0800 | [diff] [blame] | 822 | } |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 823 | /* NV storage values. If unable to get from NV storage, fall back to the |
| 824 | * CMOS reboot field used by older BIOS. */ |
Randall Spangler | 618d17d | 2011-03-01 10:33:11 -0800 | [diff] [blame] | 825 | else if (!strcasecmp(name,"recovery_request")) { |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 826 | if (0 == VbSetNvStorage(VBNV_RECOVERY_REQUEST, value)) |
| 827 | return 0; |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 828 | return VbSetCmosRebootField(CMOSRF_RECOVERY, value); |
| 829 | } else if (!strcasecmp(name,"dbg_reset")) { |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 830 | if (0 == VbSetNvStorage(VBNV_DEBUG_RESET_MODE, value)) |
| 831 | return 0; |
| 832 | return VbSetCmosRebootField(CMOSRF_DEBUG_RESET, value); |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 833 | } else if (!strcasecmp(name,"fwb_tries")) { |
Randall Spangler | 0f8ffb1 | 2011-02-25 09:50:54 -0800 | [diff] [blame] | 834 | if (0 == VbSetNvStorage(VBNV_TRY_B_COUNT, value)) |
| 835 | return 0; |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 836 | return VbSetCmosRebootField(CMOSRF_TRY_B, value); |
| 837 | } |
| 838 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 839 | return -1; |
| 840 | } |
| 841 | |
| 842 | |
| 843 | /* Set a system property string. |
| 844 | * |
| 845 | * Returns 0 if success, -1 if error. */ |
| 846 | int VbSetSystemPropertyString(const char* name, const char* value) { |
| 847 | |
| 848 | /* TODO: support setting */ |
| 849 | return -1; |
| 850 | } |