/* Print all parameters with descriptions. If force_all!=0, prints even * parameters that specify the NO_PRINT_ALL flag. * * Returns 0 if success, non-zero if error. */ int PrintAllParams(int force_all) { const Param* p; int retval = 0; char buf[VB_MAX_STRING_PROPERTY]; const char* value; for (p = sys_param_list; p->name; p++) { if (0 == force_all && (p->flags & NO_PRINT_ALL)) continue; if (p->flags & IS_STRING) { value = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); } else { int v = VbGetSystemPropertyInt(p->name); if (v == -1) value = NULL; else { snprintf(buf, sizeof(buf), p->format ? p->format : "%d", v); value = buf; } } printf("%-22s = %-30s # %s\n", p->name, (value ? value : "(error)"), p->desc); } return retval; }
/* Print the specified parameter. * * Returns 0 if success, non-zero if error. */ int PrintParam(const Param* p) { if (p->flags & IS_STRING) { char buf[VB_MAX_STRING_PROPERTY]; const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); if (!v) return 1; printf("%s", v); } else { int v = VbGetSystemPropertyInt(p->name); if (v == -1) return 1; printf(p->format ? p->format : "%d", v); } return 0; }
/* Compares the parameter with the expected value. * * Returns 0 if success (match), non-zero if error (mismatch). */ int CheckParam(const Param* p, char* expect) { if (p->flags & IS_STRING) { char buf[VB_MAX_STRING_PROPERTY]; const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); if (!v || 0 != strcmp(v, expect)) return 1; } else { char* e; int i = (int)strtol(expect, &e, 0); int v = VbGetSystemPropertyInt(p->name); if (!*expect || (e && *e)) return 1; if (v == -1 || i != v) return 1; } return 0; }
/* Determine whether OS-level debugging should be allowed. * Returns 1 if yes, 0 if no or indeterminate. */ int VbGetCrosDebug(void) { /* If the currently running system specifies its debug status, use * that in preference to other indicators. */ VbBuildOption option = VbScanBuildOption(); if (VB_BUILD_OPTION_DEBUG == option) { return 1; } else if (VB_BUILD_OPTION_NODEBUG == option) { return 0; } /* Command line is silent; allow debug if the dev switch is on. */ if (1 == VbGetSystemPropertyInt("devsw_boot")) return 1; /* All other cases disallow debug. */ return 0; }
int VbGetArchPropertyInt(const char* name) { int value = -1; /* Values from ACPI */ if (!strcasecmp(name,"fmap_base")) { unsigned fmap_base; if (ReadFileInt(ACPI_FMAP_PATH, &fmap_base) < 0) return -1; else value = (int)fmap_base; } /* Switch positions */ if (!strcasecmp(name,"devsw_cur")) { /* Systems with virtual developer switches return at-boot value */ int flags = VbGetSystemPropertyInt("vdat_flags"); if ((flags != -1) && (flags & VBSD_HONOR_VIRT_DEV_SWITCH)) value = VbGetSystemPropertyInt("devsw_boot"); else value = ReadGpio(GPIO_SIGNAL_TYPE_DEV); } else if (!strcasecmp(name,"recoverysw_cur")) { value = ReadGpio(GPIO_SIGNAL_TYPE_RECOVERY); } else if (!strcasecmp(name,"wpsw_cur")) { value = ReadGpio(GPIO_SIGNAL_TYPE_WP); if (-1 != value && FwidStartsWith("Mario.")) value = 1 - value; /* Mario reports this backwards */ } else if (!strcasecmp(name,"recoverysw_ec_boot")) { value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_EC_BOOT); } /* Fields for old systems which don't have VbSharedData */ if (VbSharedDataVersion() < 2) { if (!strcasecmp(name,"recovery_reason")) { value = VbGetRecoveryReason(); } else if (!strcasecmp(name,"devsw_boot")) { value = ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT); } else if (!strcasecmp(name,"recoverysw_boot")) { value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_BOOT); } else if (!strcasecmp(name,"wpsw_boot")) { value = ReadFileBit(ACPI_CHSW_PATH, CHSW_WP_BOOT); if (-1 != value && FwidStartsWith("Mario.")) value = 1 - value; /* Mario reports this backwards */ } } /* Saved memory is at a fixed location for all H2C BIOS. If the CHSW * path exists in sysfs, it's a H2C BIOS. */ if (!strcasecmp(name,"savedmem_base")) { unsigned savedmem_base; if (ReadFileInt(ACPI_CHSW_PATH, &savedmem_base) < 0) return -1; else return 0x00F00000; } else if (!strcasecmp(name,"savedmem_size")) { unsigned savedmem_size; if (ReadFileInt(ACPI_CHSW_PATH, &savedmem_size) < 0) return -1; else return 0x00100000; } /* NV storage values. If unable to get from NV storage, fall back to the * CMOS reboot field used by older BIOS (e.g. Mario). */ if (!strcasecmp(name,"recovery_request")) { value = VbGetNvStorage(VBNV_RECOVERY_REQUEST); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_RECOVERY); } else if (!strcasecmp(name,"dbg_reset")) { value = VbGetNvStorage(VBNV_DEBUG_RESET_MODE); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_DEBUG_RESET); } else if (!strcasecmp(name,"fwb_tries")) { value = VbGetNvStorage(VBNV_TRY_B_COUNT); if (-1 == value) value = VbGetCmosRebootField(CMOSRF_TRY_B); } /* Firmware update tries is now stored in the kernel field. On * older systems where it's not, it was stored in a file in the * stateful partition. */ if (!strcasecmp(name,"fwupdate_tries")) { unsigned fwupdate_value; if (-1 != VbGetNvStorage(VBNV_KERNEL_FIELD)) return -1; /* NvStorage supported; fail through arch-specific * implementation to normal implementation. */ /* Read value from file; missing file means value=0. */ if (ReadFileInt(NEED_FWUPDATE_PATH, &fwupdate_value) < 0) value = 0; else value = (int)fwupdate_value; } return value; }