Esempio n. 1
0
static void enable_graphics(void)
{
	if (!CONFIG_OPROM_MATTERS)
		return;

	int oprom_loaded = flag_fetch(FLAG_OPROM);

	// Manipulating vboot's internal data and calling its internal
	// functions is NOT NICE and will give you athlete's foot and make
	// you unpopular at parties. Right now it's the only way to ensure
	// graphics are enabled, though, so it's a necessary evil.
	if (!oprom_loaded) {
		printf("Enabling graphics.\n");

		VbNvContext context;

		VbExNvStorageRead(context.raw);
		VbNvSetup(&context);

		VbNvSet(&context, VBNV_OPROM_NEEDED, 1);

		VbNvTeardown(&context);
		VbExNvStorageWrite(context.raw);

		printf("Rebooting.\n");
		if (cold_reboot())
			halt();
	}
}
Esempio n. 2
0
/*
 * Return the state of the switches specified in request_mask.
 * TODO(semenzato): find a better interface than the INIT_FLAGS.
 */
uint32_t VbExGetSwitches(uint32_t request_mask)
{
	uint32_t result = 0;

	if ((request_mask & VB_INIT_FLAG_DEV_SWITCH_ON) &&
            flag_fetch(FLAG_DEVSW))
		result |= VB_INIT_FLAG_DEV_SWITCH_ON;

	if ((request_mask & VB_INIT_FLAG_REC_BUTTON_PRESSED) &&
	    flag_fetch(FLAG_RECSW))
		result |= VB_INIT_FLAG_REC_BUTTON_PRESSED;

	if ((request_mask & VB_INIT_FLAG_WP_ENABLED) &&
	    flag_fetch(FLAG_WPSW))
		result |= VB_INIT_FLAG_WP_ENABLED;

	return result;
}
Esempio n. 3
0
int VbExTrustEC(void)
{
	int val = flag_fetch(FLAG_ECINRW);
	if (val < 0) {
		printf("Couldn't tell if the EC is running RW firmware.\n");
		return 0;
	}
	// Trust the EC if it's NOT in its RW firmware.
	return !val;
}
Esempio n. 4
0
static int dakota_havekey(void)
{
	/*
	 * We want to react to the button press only, i.e. we need to
	 * catch the "unpressed -> pressed" transition.
	 */
	static uint32_t prev = 1;
	uint32_t rv = flag_fetch(FLAG_PHYS_PRESENCE);

	if (prev == rv)
		return kb_in != kb_out;

	prev = rv;
	if (!rv)
		return kb_in != kb_out;

	if (((kb_in + 1) % sizeof(kb_buffer)) == kb_out) {
		printf("%s: keyboard buffer overflow!\n", __func__);
		return 0;
	}

	/* Dev switch was pressed, what's the meaning of it? */
	if (vboot_in_recovery()) {
		/* This must mean ^D, the user wants to switch to dev mode. */
		kb_buffer[kb_in++] = 0x4;
		kb_in %= sizeof(kb_buffer);

		if (((kb_in + 1) % sizeof(kb_buffer)) != kb_out)
			kb_buffer[kb_in++] = 0xd;
		else
			/*
			 * Should never happen, but worse come to worse the
			 * user will lose the CR and will have to reboot in
			 * recovery mode again to enter dev mode.
			 */
			printf("%s: keyboard buffer overflow!\n", __func__);
	} else {
		/* This must mean ^U, the user wants to boot from USB. */
		kb_buffer[kb_in++] = 0x15;
	}

	kb_in %= sizeof(kb_buffer);

	return 1;
}
Esempio n. 5
0
int crossystem_setup(void)
{
	chromeos_acpi_t *acpi_table = (chromeos_acpi_t *)lib_sysinfo.vdat_addr;
	VbSharedDataHeader *vboot_handoff_shared_data;
	VbSharedDataHeader *vdat = (VbSharedDataHeader *)&acpi_table->vdat;
	int size;

	if (vdat->magic != VB_SHARED_DATA_MAGIC) {
		printf("Bad magic value in vboot shared data header.\n");
		return 1;
	}

	acpi_table->boot_reason = BOOT_REASON_OTHER;

	int main_fw;
	const char *fwid;
	int fwid_size;
	int fw_index = vdat->firmware_index;

	fwid = get_fw_id(fw_index);

	if (fwid == NULL) {
		printf("Unrecognized firmware index %d.\n", fw_index);
		return 1;
	}

	fwid_size = get_fw_size(fw_index);

	const struct {
		int vdat_fw_index;
		int main_fw_index;
	} main_fw_arr[] = {
		{ VDAT_RW_A, BINF_RW_A },
		{ VDAT_RW_B, BINF_RW_B },
		{ VDAT_RECOVERY, BINF_RECOVERY },
	};

	int i;
	for (i = 0; i < ARRAY_SIZE(main_fw_arr); i++) {
		if (fw_index == main_fw_arr[i].vdat_fw_index) {
			main_fw = main_fw_arr[i].main_fw_index;
			break;
		}
	}
	assert(i < ARRAY_SIZE(main_fw_arr));

	acpi_table->main_fw = main_fw;

	// Use the value set by coreboot if we don't want to change it.
	if (CONFIG_EC_SOFTWARE_SYNC) {
		int in_rw = 0;

		if (VbExEcRunningRW(0, &in_rw)) {
			printf("Couldn't tell if the EC firmware is RW.\n");
			return 1;
		}
		acpi_table->ec_fw = in_rw ? ACTIVE_ECFW_RW : ACTIVE_ECFW_RO;
	}

	uint16_t chsw = 0;
	if (flag_fetch(FLAG_WPSW))
		chsw |= CHSW_FIRMWARE_WP_DIS;
	if (flag_fetch(FLAG_RECSW))
		chsw |= CHSW_RECOVERY_X86;
	if (flag_fetch(FLAG_DEVSW))
		chsw |= CHSW_DEVELOPER_SWITCH;
	acpi_table->chsw = chsw;

	GoogleBinaryBlockHeader *gbb = cparams.gbb_data;
	if (memcmp(gbb->signature, GBB_SIGNATURE, GBB_SIGNATURE_SIZE)) {
		printf("Bad signature on GBB.\n");
		return 1;
	}
	char *hwid = (char *)((uintptr_t)cparams.gbb_data + gbb->hwid_offset);
	size = MIN(gbb->hwid_size, sizeof(acpi_table->hwid));
	memcpy(acpi_table->hwid, hwid, size);

	size = MIN(fwid_size, sizeof(acpi_table->fwid));
	memcpy(acpi_table->fwid, fwid, size);

	size = get_ro_fw_size();

	if (size) {
		size = MIN(size, sizeof(acpi_table->frid));
		memcpy(acpi_table->frid, get_ro_fw_id(), size);
	}

	if (main_fw == BINF_RECOVERY)
		acpi_table->main_fw_type = FIRMWARE_TYPE_RECOVERY;
	else if (vdat->flags & VBSD_BOOT_DEV_SWITCH_ON)
		acpi_table->main_fw_type = FIRMWARE_TYPE_DEVELOPER;
	else
		acpi_table->main_fw_type = FIRMWARE_TYPE_NORMAL;

	acpi_table->recovery_reason = vdat->recovery_reason;

	acpi_table->fmap_base = (uintptr_t)fmap_base();

	size = MIN(fwid_size, strnlen(fwid, ACPI_FWID_SIZE));
	uint8_t *dest = (uint8_t *)(uintptr_t)acpi_table->fwid_ptr;
	memcpy(dest, fwid, size);
	dest[size] = 0;

	// Synchronize the value in vboot_handoff back to acpi vdat.
	if (find_common_params((void**)(&vboot_handoff_shared_data), &size) == 0)
		memcpy(vdat, vboot_handoff_shared_data, size);
	else {
		printf("Can't find common params.\n");
		return 1;
	}

	return 0;
}