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> |
| 8 | |
| 9 | #include "host_common.h" |
| 10 | |
| 11 | #include "crossystem.h" |
| 12 | #include "utility.h" |
| 13 | #include "vboot_common.h" |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 14 | #include "vboot_nvstorage.h" |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 15 | |
| 16 | /* ACPI constants from Chrome OS Main Processor Firmware Spec */ |
| 17 | /* GPIO signal types */ |
| 18 | #define GPIO_SIGNAL_TYPE_RECOVERY 1 |
| 19 | #define GPIO_SIGNAL_TYPE_DEV 2 |
| 20 | #define GPIO_SIGNAL_TYPE_WP 3 |
| 21 | /* CHSW bitflags */ |
| 22 | #define CHSW_RECOVERY_BOOT 0x00000002 |
| 23 | #define CHSW_RECOVERY_EC_BOOT 0x00000004 |
| 24 | #define CHSW_DEV_BOOT 0x00000020 |
| 25 | #define CHSW_WP_BOOT 0x00000200 |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 26 | /* CMOS reboot field bitflags */ |
| 27 | #define CMOSRF_RECOVERY 0x80 |
| 28 | #define CMOSRF_DEBUG_RESET 0x40 |
| 29 | #define CMOSRF_TRY_B 0x20 |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 30 | /* Boot reasons from BINF.0, from early H2C firmware */ |
| 31 | /* Unknown */ |
| 32 | #define BINF0_UNKNOWN 0 |
| 33 | /* Normal boot to Chrome OS */ |
| 34 | #define BINF0_NORMAL 1 |
| 35 | /* Developer mode boot (developer mode warning displayed) */ |
| 36 | #define BINF0_DEVELOPER 2 |
| 37 | /* Recovery initiated by user, using recovery button */ |
| 38 | #define BINF0_RECOVERY_BUTTON 3 |
| 39 | /* Recovery initiated by user pressing a key at developer mode warning |
| 40 | * screen */ |
| 41 | #define BINF0_RECOVERY_DEV_SCREEN_KEY 4 |
| 42 | /* Recovery caused by BIOS failed signature check (neither rewritable |
| 43 | * firmware was valid) */ |
| 44 | #define BINF0_RECOVERY_RW_FW_BAD 5 |
| 45 | /* Recovery caused by no OS kernel detected */ |
| 46 | #define BINF0_RECOVERY_NO_OS 6 |
| 47 | /* Recovery caused by OS kernel failed signature check */ |
| 48 | #define BINF0_RECOVERY_BAD_OS 7 |
| 49 | /* Recovery initiated by OS */ |
| 50 | #define BINF0_RECOVERY_OS_INITIATED 8 |
| 51 | /* OS-initiated S3 diagnostic path (debug mode boot) */ |
| 52 | #define BINF0_S3_DIAGNOSTIC_PATH 9 |
| 53 | /* S3 resume failed */ |
| 54 | #define BINF0_S3_RESUME_FAILED 10 |
| 55 | /* Recovery caused by TPM error */ |
| 56 | #define BINF0_RECOVERY_TPM_ERROR 11 |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 57 | |
| 58 | /* Base name for ACPI files */ |
| 59 | #define ACPI_BASE_PATH "/sys/devices/platform/chromeos_acpi" |
| 60 | /* Paths for frequently used ACPI files */ |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 61 | #define ACPI_BINF_PATH ACPI_BASE_PATH "/BINF" |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 62 | #define ACPI_CHNV_PATH ACPI_BASE_PATH "/CHNV" |
| 63 | #define ACPI_CHSW_PATH ACPI_BASE_PATH "/CHSW" |
Randall Spangler | 2b59a07 | 2011-02-24 11:17:24 -0800 | [diff] [blame^] | 64 | #define ACPI_FMAP_PATH ACPI_BASE_PATH "/FMAP" |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 65 | #define ACPI_GPIO_PATH ACPI_BASE_PATH "/GPIO" |
| 66 | |
| 67 | /* Base name for GPIO files */ |
| 68 | #define GPIO_BASE_PATH "/sys/class/gpio" |
| 69 | #define GPIO_EXPORT_PATH GPIO_BASE_PATH "/export" |
| 70 | |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 71 | /* Base name for NVRAM file */ |
| 72 | #define NVRAM_PATH "/dev/nvram" |
| 73 | |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 74 | |
| 75 | /* Copy up to dest_size-1 characters from src to dest, ensuring null |
| 76 | termination (which strncpy() doesn't do). Returns the destination |
| 77 | string. */ |
| 78 | char* StrCopy(char* dest, const char* src, int dest_size) { |
| 79 | strncpy(dest, src, dest_size); |
| 80 | dest[dest_size - 1] = '\0'; |
| 81 | return dest; |
| 82 | } |
| 83 | |
| 84 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 85 | /* Read a string from a file. Passed the destination, dest size, and |
| 86 | * filename to read. |
| 87 | * |
| 88 | * Returns the destination, or NULL if error. */ |
| 89 | char* ReadFileString(char* dest, int size, const char* filename) { |
| 90 | char* got; |
| 91 | FILE* f; |
| 92 | |
| 93 | f = fopen(filename, "rt"); |
| 94 | if (!f) |
| 95 | return NULL; |
| 96 | |
| 97 | got = fgets(dest, size, f); |
| 98 | fclose(f); |
| 99 | return got; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | /* Read an integer from a file. |
| 104 | * |
| 105 | * Returns the parsed integer, or -1 if error. */ |
| 106 | int ReadFileInt(const char* filename) { |
| 107 | char buf[64]; |
| 108 | int value; |
| 109 | char* e = NULL; |
| 110 | |
| 111 | if (!ReadFileString(buf, sizeof(buf), filename)) |
| 112 | return -1; |
| 113 | |
| 114 | /* Convert to integer. Allow characters after the int ("123 blah"). */ |
| 115 | value = strtol(buf, &e, 0); |
| 116 | if (e == buf) |
| 117 | return -1; /* No characters consumed, so conversion failed */ |
| 118 | |
| 119 | return value; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /* Check if a bit is set in a file which contains an integer. |
| 124 | * |
| 125 | * Returns 1 if the bit is set, 0 if clear, or -1 if error. */ |
| 126 | int ReadFileBit(const char* filename, int bitmask) { |
| 127 | int value = ReadFileInt(filename); |
| 128 | if (value == -1) |
| 129 | return -1; |
| 130 | else return (value & bitmask ? 1 : 0); |
| 131 | } |
| 132 | |
| 133 | |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 134 | /* Return true if the FWID starts with the specified string. */ |
| 135 | static int FwidStartsWith(const char *start) { |
| 136 | char fwid[128]; |
| 137 | if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid))) |
| 138 | return 0; |
| 139 | |
| 140 | return 0 == strncmp(fwid, start, strlen(start)); |
| 141 | } |
| 142 | |
| 143 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 144 | /* Read a GPIO of the specified signal type (see ACPI GPIO SignalType). |
| 145 | * |
| 146 | * Returns 1 if the signal is asserted, 0 if not asserted, or -1 if error. */ |
| 147 | int ReadGpio(int signal_type) { |
| 148 | char name[128]; |
| 149 | int index = 0; |
| 150 | int gpio_type; |
| 151 | int active_high; |
| 152 | int controller_offset; |
| 153 | char controller_name[128]; |
| 154 | int value; |
| 155 | |
| 156 | /* Scan GPIO.* to find a matching signal type */ |
| 157 | for (index = 0; ; index++) { |
| 158 | snprintf(name, sizeof(name), "%s.%d/GPIO.0", ACPI_GPIO_PATH, index); |
| 159 | gpio_type = ReadFileInt(name); |
| 160 | if (gpio_type == signal_type) |
| 161 | break; |
| 162 | else if (gpio_type == -1) |
| 163 | return -1; /* Ran out of GPIOs before finding a match */ |
| 164 | } |
| 165 | |
| 166 | /* Read attributes and controller info for the GPIO */ |
| 167 | snprintf(name, sizeof(name), "%s.%d/GPIO.1", ACPI_GPIO_PATH, index); |
| 168 | active_high = ReadFileBit(name, 0x00000001); |
| 169 | snprintf(name, sizeof(name), "%s.%d/GPIO.2", ACPI_GPIO_PATH, index); |
| 170 | controller_offset = ReadFileInt(name); |
| 171 | if (active_high == -1 || controller_offset == -1) |
| 172 | return -1; /* Missing needed info */ |
| 173 | |
| 174 | /* We only support the NM10 for now */ |
| 175 | snprintf(name, sizeof(name), "%s.%d/GPIO.3", ACPI_GPIO_PATH, index); |
| 176 | if (!ReadFileString(controller_name, sizeof(controller_name), name)) |
| 177 | return -1; |
| 178 | if (0 != strcmp(controller_name, "NM10")) |
| 179 | return -1; |
| 180 | |
| 181 | /* Assume the NM10 has offset 192 */ |
| 182 | /* TODO: should really check gpiochipNNN/label to see if it's the |
| 183 | * address we expect for the NM10, and then read the offset from |
| 184 | * gpiochipNNN/base. */ |
| 185 | controller_offset += 192; |
| 186 | |
| 187 | /* Try reading the GPIO value */ |
| 188 | snprintf(name, sizeof(name), "%s/gpio%d/value", |
| 189 | GPIO_BASE_PATH, controller_offset); |
| 190 | value = ReadFileInt(name); |
| 191 | |
| 192 | if (value == -1) { |
| 193 | /* Try exporting the GPIO */ |
| 194 | FILE* f = fopen(GPIO_EXPORT_PATH, "wt"); |
| 195 | if (!f) |
| 196 | return -1; |
| 197 | fprintf(f, "%d", controller_offset); |
| 198 | fclose(f); |
| 199 | |
| 200 | /* Try re-reading the GPIO value */ |
| 201 | value = ReadFileInt(name); |
| 202 | } |
| 203 | |
| 204 | if (value == -1) |
| 205 | return -1; |
| 206 | |
| 207 | /* Compare the GPIO value with the active value and return 1 if match. */ |
| 208 | return (value == active_high ? 1 : 0); |
| 209 | } |
| 210 | |
| 211 | |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 212 | /* Read the CMOS reboot field in NVRAM. |
| 213 | * |
| 214 | * Returns 0 if the mask is clear in the field, 1 if set, or -1 if error. */ |
| 215 | int VbGetCmosRebootField(uint8_t mask) { |
| 216 | FILE* f; |
| 217 | int chnv, nvbyte; |
| 218 | |
| 219 | /* Get the byte offset from CHNV */ |
| 220 | chnv = ReadFileInt(ACPI_CHNV_PATH); |
| 221 | if (chnv == -1) |
| 222 | return -1; |
| 223 | |
| 224 | f = fopen(NVRAM_PATH, "rb"); |
| 225 | if (!f) |
| 226 | return -1; |
| 227 | |
| 228 | if (0 != fseek(f, chnv, SEEK_SET) || EOF == (nvbyte = fgetc(f))) { |
| 229 | fclose(f); |
| 230 | return -1; |
| 231 | } |
| 232 | |
| 233 | fclose(f); |
| 234 | return (nvbyte & mask ? 1 : 0); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* Write the CMOS reboot field in NVRAM. |
| 239 | * |
| 240 | * Sets (value=0) or clears (value!=0) the mask in the byte. |
| 241 | * |
| 242 | * Returns 0 if success, or -1 if error. */ |
| 243 | int VbSetCmosRebootField(uint8_t mask, int value) { |
| 244 | FILE* f; |
| 245 | int chnv, nvbyte; |
| 246 | |
| 247 | /* Get the byte offset from CHNV */ |
| 248 | chnv = ReadFileInt(ACPI_CHNV_PATH); |
| 249 | if (chnv == -1) |
| 250 | return -1; |
| 251 | |
| 252 | f = fopen(NVRAM_PATH, "w+b"); |
| 253 | if (!f) |
| 254 | return -1; |
| 255 | |
| 256 | /* Read the current value */ |
| 257 | if (0 != fseek(f, chnv, SEEK_SET) || EOF == (nvbyte = fgetc(f))) { |
| 258 | fclose(f); |
| 259 | return -1; |
| 260 | } |
| 261 | |
| 262 | /* Set/clear the mask */ |
| 263 | if (value) |
| 264 | nvbyte |= mask; |
| 265 | else |
| 266 | nvbyte &= ~mask; |
| 267 | |
| 268 | /* Write the byte back */ |
| 269 | if (0 != fseek(f, chnv, SEEK_SET) || EOF == (fputc(nvbyte, f))) { |
| 270 | fclose(f); |
| 271 | return -1; |
| 272 | } |
| 273 | |
| 274 | /* Success */ |
| 275 | fclose(f); |
| 276 | return 0; |
| 277 | } |
| 278 | |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 279 | /* Read the recovery reason. Returns the reason code or -1 if error. */ |
| 280 | int VbGetRecoveryReason(void) { |
| 281 | int value; |
| 282 | |
| 283 | /* Try reading type from BINF.4 */ |
| 284 | value = ReadFileInt(ACPI_BINF_PATH ".4"); |
| 285 | if (-1 != value) |
| 286 | return value; |
| 287 | |
| 288 | /* Fall back to BINF.0 for legacy systems like Mario. */ |
| 289 | switch(ReadFileInt(ACPI_BINF_PATH ".0")) { |
| 290 | case BINF0_NORMAL: |
| 291 | case BINF0_DEVELOPER: |
| 292 | return VBNV_RECOVERY_NOT_REQUESTED; |
| 293 | case BINF0_RECOVERY_BUTTON: |
| 294 | return VBNV_RECOVERY_RO_MANUAL; |
| 295 | case BINF0_RECOVERY_DEV_SCREEN_KEY: |
| 296 | return VBNV_RECOVERY_RW_DEV_SCREEN; |
| 297 | case BINF0_RECOVERY_RW_FW_BAD: |
| 298 | case BINF0_RECOVERY_NO_OS: |
| 299 | return VBNV_RECOVERY_RW_NO_OS; |
| 300 | case BINF0_RECOVERY_BAD_OS: |
| 301 | return VBNV_RECOVERY_RW_INVALID_OS; |
| 302 | case BINF0_RECOVERY_OS_INITIATED: |
| 303 | return VBNV_RECOVERY_LEGACY; |
| 304 | default: |
| 305 | /* Other values don't map cleanly to firmware type. */ |
| 306 | return -1; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | |
| 311 | /* Read the active main firmware type into the destination buffer. |
| 312 | * Passed the destination and its size. Returns the destination, or |
| 313 | * NULL if error. */ |
| 314 | const char* VbReadMainFwType(char* dest, int size) { |
| 315 | |
| 316 | /* Try reading type from BINF.3 */ |
| 317 | switch(ReadFileInt(ACPI_BINF_PATH ".3")) { |
| 318 | case 0: |
| 319 | return StrCopy(dest, "recovery", size); |
| 320 | case 1: |
| 321 | return StrCopy(dest, "normal", size); |
| 322 | case 2: |
| 323 | return StrCopy(dest, "developer", size); |
| 324 | default: |
| 325 | break; /* Fall through to legacy handling */ |
| 326 | } |
| 327 | |
| 328 | /* Fall back to BINF.0 for legacy systems like Mario. */ |
| 329 | switch(ReadFileInt(ACPI_BINF_PATH ".0")) { |
| 330 | case -1: |
| 331 | /* Both BINF.0 and BINF.3 are missing, so this isn't Chrome OS |
| 332 | * firmware. */ |
| 333 | return StrCopy(dest, "nonchrome", size); |
| 334 | case BINF0_NORMAL: |
| 335 | return StrCopy(dest, "normal", size); |
| 336 | case BINF0_DEVELOPER: |
| 337 | return StrCopy(dest, "developer", size); |
| 338 | case BINF0_RECOVERY_BUTTON: |
| 339 | case BINF0_RECOVERY_DEV_SCREEN_KEY: |
| 340 | case BINF0_RECOVERY_RW_FW_BAD: |
| 341 | case BINF0_RECOVERY_NO_OS: |
| 342 | case BINF0_RECOVERY_BAD_OS: |
| 343 | case BINF0_RECOVERY_OS_INITIATED: |
| 344 | case BINF0_RECOVERY_TPM_ERROR: |
| 345 | /* Assorted flavors of recovery boot reason. */ |
| 346 | return StrCopy(dest, "recovery", size); |
| 347 | default: |
| 348 | /* Other values don't map cleanly to firmware type. */ |
| 349 | return NULL; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | |
| 354 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 355 | /* Read a system property integer. |
| 356 | * |
| 357 | * Returns the property value, or -1 if error. */ |
| 358 | int VbGetSystemPropertyInt(const char* name) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 359 | int value = -1; |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 360 | |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 361 | /* Switch positions */ |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 362 | if (!strcasecmp(name,"devsw_cur")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 363 | value = ReadGpio(GPIO_SIGNAL_TYPE_DEV); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 364 | } else if (!strcasecmp(name,"devsw_boot")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 365 | value = ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 366 | } else if (!strcasecmp(name,"recoverysw_cur")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 367 | value = ReadGpio(GPIO_SIGNAL_TYPE_RECOVERY); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 368 | } else if (!strcasecmp(name,"recoverysw_boot")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 369 | value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_BOOT); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 370 | } else if (!strcasecmp(name,"recoverysw_ec_boot")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 371 | value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_EC_BOOT); |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 372 | } else if (!strcasecmp(name,"wpsw_cur")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 373 | value = ReadGpio(GPIO_SIGNAL_TYPE_WP); |
| 374 | if (-1 != value && FwidStartsWith("Mario.")) |
| 375 | value = 1 - value; /* Mario reports this backwards */ |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 376 | } else if (!strcasecmp(name,"wpsw_boot")) { |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 377 | value = ReadFileBit(ACPI_CHSW_PATH, CHSW_WP_BOOT); |
| 378 | if (-1 != value && FwidStartsWith("Mario.")) |
| 379 | value = 1 - value; /* Mario reports this backwards */ |
| 380 | } |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 381 | /* Saved memory is at a fixed location for all H2C BIOS. If the CHSW |
| 382 | * path exists in sysfs, it's a H2C BIOS. */ |
| 383 | else if (!strcasecmp(name,"savedmem_base")) { |
| 384 | return (-1 == ReadFileInt(ACPI_CHSW_PATH) ? -1 : 0x00F00000); |
| 385 | } else if (!strcasecmp(name,"savedmem_size")) { |
| 386 | return (-1 == ReadFileInt(ACPI_CHSW_PATH) ? -1 : 0x00100000); |
| 387 | } |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 388 | /* NV storage values for older H2C BIOS */ |
| 389 | else if (!strcasecmp(name,"recovery_request")) { |
| 390 | value = VbGetCmosRebootField(CMOSRF_RECOVERY); |
| 391 | } else if (!strcasecmp(name,"dbg_reset")) { |
| 392 | value = VbGetCmosRebootField(CMOSRF_DEBUG_RESET); |
| 393 | } else if (!strcasecmp(name,"fwb_tries")) { |
| 394 | value = VbGetCmosRebootField(CMOSRF_TRY_B); |
| 395 | } |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 396 | /* Other parameters */ |
| 397 | else if (!strcasecmp(name,"recovery_reason")) { |
| 398 | return VbGetRecoveryReason(); |
Randall Spangler | 2b59a07 | 2011-02-24 11:17:24 -0800 | [diff] [blame^] | 399 | } else if (!strcasecmp(name,"fmap_base")) { |
| 400 | value = ReadFileInt(ACPI_FMAP_PATH); |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 401 | } |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 402 | |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 403 | /* TODO: implement the following properties: |
| 404 | * nvram_cleared |
| 405 | */ |
Randall Spangler | c80fe65 | 2011-02-17 11:06:47 -0800 | [diff] [blame] | 406 | |
| 407 | return value; |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
| 411 | /* Read a system property string into a destination buffer of the specified |
| 412 | * size. |
| 413 | * |
| 414 | * Returns the passed buffer, or NULL if error. */ |
| 415 | const char* VbGetSystemPropertyString(const char* name, char* dest, int size) { |
| 416 | |
| 417 | if (!strcasecmp(name,"hwid")) { |
| 418 | return ReadFileString(dest, size, ACPI_BASE_PATH "/HWID"); |
| 419 | } else if (!strcasecmp(name,"fwid")) { |
| 420 | return ReadFileString(dest, size, ACPI_BASE_PATH "/FWID"); |
| 421 | } else if (!strcasecmp(name,"ro_fwid")) { |
| 422 | return ReadFileString(dest, size, ACPI_BASE_PATH "/FRID"); |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 423 | } else if (!strcasecmp(name,"mainfw_act")) { |
| 424 | switch(ReadFileInt(ACPI_BINF_PATH ".1")) { |
| 425 | case 0: |
| 426 | return StrCopy(dest, "recovery", size); |
| 427 | case 1: |
| 428 | return StrCopy(dest, "A", size); |
| 429 | case 2: |
| 430 | return StrCopy(dest, "B", size); |
| 431 | default: |
| 432 | return NULL; |
| 433 | } |
| 434 | } else if (!strcasecmp(name,"mainfw_type")) { |
| 435 | return VbReadMainFwType(dest, size); |
| 436 | } else if (!strcasecmp(name,"ecfw_act")) { |
| 437 | switch(ReadFileInt(ACPI_BINF_PATH ".2")) { |
| 438 | case 0: |
| 439 | return StrCopy(dest, "RO", size); |
| 440 | case 1: |
| 441 | return StrCopy(dest, "RW", size); |
| 442 | default: |
| 443 | return NULL; |
| 444 | } |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 445 | } else |
| 446 | return NULL; |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | |
| 450 | /* Set a system property integer. |
| 451 | * |
| 452 | * Returns 0 if success, -1 if error. */ |
| 453 | int VbSetSystemPropertyInt(const char* name, int value) { |
| 454 | |
Randall Spangler | e73302c | 2011-02-18 14:53:01 -0800 | [diff] [blame] | 455 | /* NV storage values for older H2C BIOS */ |
| 456 | if (!strcasecmp(name,"recovery_request")) { |
| 457 | return VbSetCmosRebootField(CMOSRF_RECOVERY, value); |
| 458 | } else if (!strcasecmp(name,"dbg_reset")) { |
| 459 | return VbSetCmosRebootField(CMOSRF_DEBUG_RESET, value); |
| 460 | } else if (!strcasecmp(name,"fwb_tries")) { |
| 461 | return VbSetCmosRebootField(CMOSRF_TRY_B, value); |
| 462 | } |
| 463 | |
Randall Spangler | b47ed5a | 2011-02-23 13:05:40 -0800 | [diff] [blame] | 464 | /* TODO: implement the following: |
| 465 | * nvram_cleared |
| 466 | */ |
| 467 | |
Randall Spangler | 5421866 | 2011-02-07 11:20:20 -0800 | [diff] [blame] | 468 | return -1; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | /* Set a system property string. |
| 473 | * |
| 474 | * Returns 0 if success, -1 if error. */ |
| 475 | int VbSetSystemPropertyString(const char* name, const char* value) { |
| 476 | |
| 477 | /* TODO: support setting */ |
| 478 | return -1; |
| 479 | } |