2020-04-02 23:48:53 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2015-05-01 23:48:54 +02:00
|
|
|
|
2019-12-12 02:09:39 +01:00
|
|
|
#include <boot_device.h>
|
2015-05-01 23:48:54 +02:00
|
|
|
#include <cbfs.h>
|
2021-02-08 10:02:56 +01:00
|
|
|
#include <cbmem.h>
|
2019-12-12 02:09:39 +01:00
|
|
|
#include <commonlib/bsd/cbfs_private.h>
|
2015-05-01 23:48:54 +02:00
|
|
|
#include <console/console.h>
|
2016-08-24 21:58:12 +02:00
|
|
|
#include <ec/google/chromeec/ec.h>
|
2015-05-12 23:43:10 +02:00
|
|
|
#include <rmodule.h>
|
2017-10-17 17:02:29 +02:00
|
|
|
#include <security/vboot/misc.h>
|
|
|
|
#include <security/vboot/symbols.h>
|
|
|
|
#include <security/vboot/vboot_common.h>
|
2015-05-01 23:48:54 +02:00
|
|
|
|
2017-03-18 00:54:48 +01:00
|
|
|
/* Ensure vboot configuration is valid: */
|
2019-03-06 01:53:33 +01:00
|
|
|
_Static_assert(CONFIG(VBOOT_STARTS_IN_BOOTBLOCK) +
|
2020-05-04 18:13:45 +02:00
|
|
|
CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK) +
|
2019-03-06 01:53:33 +01:00
|
|
|
CONFIG(VBOOT_STARTS_IN_ROMSTAGE) == 1,
|
2020-05-04 18:13:45 +02:00
|
|
|
"vboot must start in bootblock, PSP or romstage (but only one!)");
|
|
|
|
_Static_assert(!CONFIG(VBOOT_SEPARATE_VERSTAGE) || CONFIG(VBOOT_STARTS_IN_BOOTBLOCK) ||
|
|
|
|
CONFIG(VBOOT_STARTS_BEFORE_BOOTBLOCK),
|
|
|
|
"stand-alone verstage must start in or before bootblock ");
|
2019-03-06 01:53:33 +01:00
|
|
|
_Static_assert(!CONFIG(VBOOT_RETURN_FROM_VERSTAGE) ||
|
|
|
|
CONFIG(VBOOT_SEPARATE_VERSTAGE),
|
2017-03-18 00:54:48 +01:00
|
|
|
"return from verstage only makes sense for separate verstages");
|
|
|
|
|
2019-11-20 19:47:10 +01:00
|
|
|
int vboot_executed;
|
2015-12-09 00:00:23 +01:00
|
|
|
|
2020-05-07 02:06:35 +02:00
|
|
|
static void after_verstage(void)
|
2019-12-12 02:09:39 +01:00
|
|
|
{
|
2020-05-07 02:06:35 +02:00
|
|
|
vboot_executed = 1; /* Mark verstage execution complete. */
|
2019-12-12 02:09:39 +01:00
|
|
|
|
|
|
|
const struct cbfs_boot_device *cbd = vboot_get_cbfs_boot_device();
|
2020-05-07 02:06:35 +02:00
|
|
|
if (!cbd) /* Can't initialize RW CBFS in recovery mode. */
|
2019-12-12 02:09:39 +01:00
|
|
|
return;
|
2020-05-07 02:06:35 +02:00
|
|
|
|
|
|
|
cb_err_t err = cbfs_init_boot_device(cbd, NULL); /* TODO: RW hash */
|
|
|
|
if (err && err != CB_CBFS_CACHE_FULL) /* TODO: -> recovery? */
|
|
|
|
die("RW CBFS initialization failure: %d", err);
|
2019-12-12 02:09:39 +01:00
|
|
|
}
|
|
|
|
|
2019-11-01 10:22:22 +01:00
|
|
|
void vboot_run_logic(void)
|
2015-05-01 23:48:54 +02:00
|
|
|
{
|
2016-05-14 15:30:52 +02:00
|
|
|
if (verification_should_run()) {
|
2017-02-14 02:53:29 +01:00
|
|
|
/* Note: this path is not used for VBOOT_RETURN_FROM_VERSTAGE */
|
2015-05-01 23:48:54 +02:00
|
|
|
verstage_main();
|
2020-05-07 02:06:35 +02:00
|
|
|
after_verstage();
|
2015-05-01 23:48:54 +02:00
|
|
|
} else if (verstage_should_load()) {
|
2015-05-20 19:08:55 +02:00
|
|
|
struct prog verstage =
|
2015-12-08 21:34:35 +01:00
|
|
|
PROG_INIT(PROG_VERSTAGE,
|
2015-05-20 19:08:55 +02:00
|
|
|
CONFIG_CBFS_PREFIX "/verstage");
|
2015-05-01 23:48:54 +02:00
|
|
|
|
2015-05-13 20:33:27 +02:00
|
|
|
printk(BIOS_DEBUG, "VBOOT: Loading verstage.\n");
|
|
|
|
|
2015-09-17 23:09:30 +02:00
|
|
|
if (cbfs_prog_stage_load(&verstage))
|
2015-05-01 23:48:54 +02:00
|
|
|
die("failed to load verstage");
|
|
|
|
|
|
|
|
/* verify and select a slot */
|
|
|
|
prog_run(&verstage);
|
|
|
|
|
|
|
|
/* This is not actually possible to hit this condition at
|
|
|
|
* runtime, but this provides a hint to the compiler for dead
|
|
|
|
* code elimination below. */
|
2019-03-06 01:53:33 +01:00
|
|
|
if (!CONFIG(VBOOT_RETURN_FROM_VERSTAGE))
|
2015-12-09 00:00:23 +01:00
|
|
|
return;
|
|
|
|
|
2020-05-07 02:06:35 +02:00
|
|
|
after_verstage();
|
2015-05-01 23:48:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-12 02:09:39 +01:00
|
|
|
const struct cbfs_boot_device *vboot_get_cbfs_boot_device(void)
|
2015-05-01 23:48:54 +02:00
|
|
|
{
|
2015-12-09 00:00:23 +01:00
|
|
|
/* Don't honor vboot results until the vboot logic has run. */
|
2019-03-13 15:38:07 +01:00
|
|
|
if (!vboot_logic_executed())
|
2019-12-12 02:09:39 +01:00
|
|
|
return NULL;
|
2015-05-15 22:57:51 +02:00
|
|
|
|
2019-12-12 02:09:39 +01:00
|
|
|
static struct cbfs_boot_device cbd;
|
|
|
|
if (region_device_sz(&cbd.rdev))
|
|
|
|
return &cbd;
|
2019-11-14 08:42:25 +01:00
|
|
|
|
2019-12-12 02:09:39 +01:00
|
|
|
struct vb2_context *ctx = vboot_get_context();
|
2019-11-14 08:42:25 +01:00
|
|
|
if (ctx->flags & VB2_CONTEXT_RECOVERY_MODE)
|
2019-12-12 02:09:39 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
boot_device_init();
|
|
|
|
if (vboot_locate_firmware(ctx, &cbd.rdev))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cbfs_boot_device_find_mcache(&cbd, CBMEM_ID_CBFS_RW_MCACHE);
|
2019-11-14 08:42:25 +01:00
|
|
|
|
2019-12-12 02:09:39 +01:00
|
|
|
return &cbd;
|
2015-05-16 06:39:23 +02:00
|
|
|
}
|