Exemplo n.º 1
0
int main(void)
{
	void *rw_hash;

	hardware_init();
	debug_printf("%s started\n",
		is_ro_mode() ? "RO" : "RW");

	/* the RO partition protection is not enabled : do it */
	if (!flash_physical_is_permanently_protected())
		flash_physical_permanent_protect();

	/*
	 * calculate the hash of the RW partition
	 *
	 * Also pre-cache it so we can answer Discover Identity VDM
	 * fast enough (in less than 30ms).
	 */
	rw_hash = flash_hash_rw();

	/* Verify RW firmware and use it if valid */
	if (is_ro_mode() && check_rw_valid(rw_hash))
		jump_to_rw();

	/* background loop for PD events */
	pd_task();

	debug_printf("EXIT!\n");
	/* we should never reach that point */
	system_reset(0);
	return 0;
}
Exemplo n.º 2
0
Arquivo: board.c Projeto: longsleep/ec
uint32_t *board_get_info(void)
{
	if (rw_flash_changed) {
		/* re-calculate RW hash */
		rw_hash = flash_hash_rw();
		rw_flash_changed = 0;
	}

	/* copy first 20 bytes of RW hash */
	memcpy(info_data, rw_hash, 5 * sizeof(uint32_t));

	/* copy other info into data msg */
	info_data[5] = VDO_INFO(CONFIG_USB_PD_HW_DEV_ID_BOARD_MAJOR,
				CONFIG_USB_PD_HW_DEV_ID_BOARD_MINOR,
				ver_get_numcommits(), !is_ro_mode());

	return info_data;
}
Exemplo n.º 3
0
Arquivo: board.c Projeto: longsleep/ec
int main(void)
{
	hardware_init();
	debug_printf("Power supply started ... %s\n",
		is_ro_mode() ? "RO" : "RW");

	/* calculate hash of RW */
	rw_hash = flash_hash_rw();

	/* Verify RW firmware and use it if valid */
	if (is_ro_mode() && check_rw_valid())
		jump_to_rw();

	/* background loop for PD events */
	pd_task();

	debug_printf("background loop exited !\n");
	/* we should never reach that point */
	cpu_reset();
	return 0;
}
Exemplo n.º 4
0
static int check_rw_valid(void)
{
	uint32_t *hash;
	uint32_t *fw_hash = (uint32_t *)
		(CONFIG_FLASH_BASE + CONFIG_FLASH_SIZE - 32);

	/* Check if we have a RW firmware flashed */
	if (*rw_rst == 0xffffffff)
		return 0;

	hash = (uint32_t *)flash_hash_rw();
	/* TODO(crosbug.com/p/28336) use secret key to check RW */
	if (memcmp(hash, fw_hash, SHA1_DIGEST_SIZE) != 0) {
		/* Firmware doesn't match the recorded hash */
		debug_printf("SHA-1 %08x %08x %08x %08x %08x\n",
			hash[0], hash[1], hash[2], hash[3], hash[4]);
		debug_printf("FW SHA-1 %08x %08x %08x %08x %08x\n",
			fw_hash[0], fw_hash[1], fw_hash[2],
			fw_hash[3], fw_hash[4]);
		return 0;
	}

	return 1;
}