static int test_write_protect(void)
{
	/* Test we can control write protect GPIO */
	mock_wp = 0;
	ASSERT_WP_NO_FLAGS(EC_FLASH_PROTECT_GPIO_ASSERTED);

	mock_wp = 1;
	ASSERT_WP_FLAGS(EC_FLASH_PROTECT_GPIO_ASSERTED);

	/* Test software WP can be disable if nothing is actually protected */
	SET_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT, 1);
	SET_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT, 0);
	ASSERT_WP_NO_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT);

	/* Actually protect flash and test software WP cannot be disabled */
	SET_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT, 1);
	SET_WP_FLAGS(EC_FLASH_PROTECT_ALL_NOW, 1);
	SET_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT, 0);
	SET_WP_FLAGS(EC_FLASH_PROTECT_ALL_NOW, 0);
	ASSERT_WP_FLAGS(EC_FLASH_PROTECT_ALL_NOW | EC_FLASH_PROTECT_RO_AT_BOOT);

	/* Check we cannot erase anything */
	TEST_ASSERT(flash_physical_erase(CONFIG_RO_STORAGE_OFF,
			CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS);
	TEST_ASSERT(flash_physical_erase(CONFIG_RW_STORAGE_OFF,
			CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS);

	/* We should not even try to write/erase */
	VERIFY_NO_ERASE(CONFIG_RO_STORAGE_OFF, CONFIG_FLASH_ERASE_SIZE);
	VERIFY_NO_ERASE(CONFIG_RW_STORAGE_OFF, CONFIG_FLASH_ERASE_SIZE);
	VERIFY_NO_WRITE(CONFIG_RO_STORAGE_OFF, sizeof(testdata), testdata);
	VERIFY_NO_WRITE(CONFIG_RW_STORAGE_OFF, sizeof(testdata), testdata);

	return EC_SUCCESS;
}
Beispiel #2
0
/**
 * Write persistent state from pstate, erasing if necessary.
 *
 * @param pstate	Source persistent state
 * @return EC_SUCCESS, or nonzero if error.
 */
static int flash_write_pstate(const struct persist_state *pstate)
{
	struct persist_state current_pstate;
	int rv;

	/* Check if pstate has actually changed */
	flash_read_pstate(&current_pstate);
	if (!memcmp(&current_pstate, pstate, sizeof(*pstate)))
		return EC_SUCCESS;

	/* Erase pstate */
	rv = flash_physical_erase(PSTATE_OFFSET, PSTATE_SIZE);
	if (rv)
		return rv;

	/*
	 * Note that if we lose power in here, we'll lose the pstate contents.
	 * That's ok, because it's only possible to write the pstate before
	 * it's protected.
	 */

	/* Rewrite the data */
	return flash_physical_write(PSTATE_OFFSET, sizeof(*pstate),
				    (const char *)pstate);
}
static int test_boot_write_protect(void)
{
	/* Check write protect state persists through reboot */
	ASSERT_WP_FLAGS(EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_RO_AT_BOOT);
	TEST_ASSERT(flash_physical_erase(CONFIG_RO_STORAGE_OFF,
			CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS);

	return EC_SUCCESS;
}
Beispiel #4
0
int flash_erase(int offset, int size)
{
	if (flash_dataptr(offset, size, CONFIG_FLASH_ERASE_SIZE, NULL) < 0)
		return EC_ERROR_INVAL;  /* Invalid range */

#ifdef CONFIG_VBOOT_HASH
	vboot_hash_invalidate(offset, size);
#endif

	return flash_physical_erase(offset, size);
}