2015-05-01 23:48:54 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright 2015 Google, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2015-12-09 00:00:23 +01:00
|
|
|
#include <arch/early_variables.h>
|
2015-05-01 23:48:54 +02:00
|
|
|
#include <cbfs.h>
|
|
|
|
#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) +
|
|
|
|
CONFIG(VBOOT_STARTS_IN_ROMSTAGE) == 1,
|
2017-03-18 00:54:48 +01:00
|
|
|
"vboot must either start in bootblock or romstage (not both!)");
|
2019-02-11 08:37:49 +01:00
|
|
|
_Static_assert(CONFIG(VBOOT_STARTS_IN_BOOTBLOCK) ||
|
|
|
|
!CONFIG(VBOOT_MIGRATE_WORKING_DATA),
|
|
|
|
"no need to migrate working data after CBMEM is already up!");
|
2019-03-06 01:53:33 +01:00
|
|
|
_Static_assert(!CONFIG(VBOOT_SEPARATE_VERSTAGE) ||
|
|
|
|
CONFIG(VBOOT_STARTS_IN_BOOTBLOCK),
|
2017-03-18 00:54:48 +01:00
|
|
|
"stand-alone verstage must start in (i.e. after) 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");
|
|
|
|
|
2015-05-01 23:48:54 +02:00
|
|
|
/* The stage loading code is compiled and entered from multiple stages. The
|
|
|
|
* helper functions below attempt to provide more clarity on when certain
|
|
|
|
* code should be called. */
|
|
|
|
|
|
|
|
static int verification_should_run(void)
|
|
|
|
{
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(VBOOT_SEPARATE_VERSTAGE))
|
2017-03-18 00:54:48 +01:00
|
|
|
return ENV_VERSTAGE;
|
2019-03-06 01:53:33 +01:00
|
|
|
else if (CONFIG(VBOOT_STARTS_IN_ROMSTAGE))
|
2017-03-18 00:54:48 +01:00
|
|
|
return ENV_ROMSTAGE;
|
2019-03-06 01:53:33 +01:00
|
|
|
else if (CONFIG(VBOOT_STARTS_IN_BOOTBLOCK))
|
2017-03-18 00:54:48 +01:00
|
|
|
return ENV_BOOTBLOCK;
|
|
|
|
else
|
|
|
|
die("impossible!");
|
2015-05-01 23:48:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int verstage_should_load(void)
|
|
|
|
{
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(VBOOT_SEPARATE_VERSTAGE))
|
2017-03-18 00:54:48 +01:00
|
|
|
return ENV_BOOTBLOCK;
|
|
|
|
else
|
2015-05-01 23:48:54 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-09 00:00:23 +01:00
|
|
|
static int vboot_executed CAR_GLOBAL;
|
|
|
|
|
2019-03-13 15:38:07 +01:00
|
|
|
int vboot_logic_executed(void)
|
2015-12-09 00:00:23 +01:00
|
|
|
{
|
2019-05-09 22:40:23 +02:00
|
|
|
/* If we are in the stage that runs verification, or in the stage that
|
|
|
|
both loads the verstage and is returned to from it afterwards, we
|
|
|
|
need to check a global to see if verfication has run. */
|
|
|
|
if (verification_should_run() ||
|
|
|
|
(verstage_should_load() && CONFIG(VBOOT_RETURN_FROM_VERSTAGE)))
|
2017-03-18 00:54:48 +01:00
|
|
|
return car_get_var(vboot_executed);
|
|
|
|
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(VBOOT_STARTS_IN_BOOTBLOCK)) {
|
2017-03-18 00:54:48 +01:00
|
|
|
/* All other stages are "after the bootblock" */
|
|
|
|
return !ENV_BOOTBLOCK;
|
2019-03-06 01:53:33 +01:00
|
|
|
} else if (CONFIG(VBOOT_STARTS_IN_ROMSTAGE)) {
|
2017-03-18 00:54:48 +01:00
|
|
|
/* Post-RAM stages are "after the romstage" */
|
|
|
|
#ifdef __PRE_RAM__
|
|
|
|
return 0;
|
|
|
|
#else
|
2015-12-09 00:00:23 +01:00
|
|
|
return 1;
|
2017-03-18 00:54:48 +01:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
die("impossible!");
|
2015-12-09 00:00:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vboot_prepare(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();
|
2015-12-09 00:00:23 +01:00
|
|
|
car_set_var(vboot_executed, 1);
|
2019-03-13 15:38:07 +01:00
|
|
|
vboot_save_recovery_reason_vbnv();
|
2015-05-01 23:48:54 +02:00
|
|
|
} else if (verstage_should_load()) {
|
2015-09-17 23:09:30 +02:00
|
|
|
struct cbfsf file;
|
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-05-01 23:48:54 +02:00
|
|
|
/* load verstage from RO */
|
2015-09-17 23:09:30 +02:00
|
|
|
if (cbfs_boot_locate(&file, prog_name(&verstage), NULL))
|
|
|
|
die("failed to load verstage");
|
|
|
|
|
|
|
|
cbfs_file_data(prog_rdev(&verstage), &file);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
car_set_var(vboot_executed, 1);
|
2015-05-01 23:48:54 +02:00
|
|
|
}
|
|
|
|
|
2015-10-07 23:03:41 +02:00
|
|
|
/*
|
|
|
|
* Fill in vboot cbmem objects before moving to ramstage so all
|
|
|
|
* downstream users have access to vboot results. This path only
|
2017-03-17 03:32:48 +01:00
|
|
|
* applies to platforms employing VBOOT_STARTS_IN_ROMSTAGE because
|
2015-10-07 23:03:41 +02:00
|
|
|
* cbmem comes online prior to vboot verification taking place. For
|
|
|
|
* other platforms the vboot cbmem objects are initialized when
|
|
|
|
* cbmem comes online.
|
|
|
|
*/
|
2019-02-11 08:37:49 +01:00
|
|
|
if (ENV_ROMSTAGE && CONFIG(VBOOT_STARTS_IN_ROMSTAGE))
|
2015-05-01 23:48:54 +02:00
|
|
|
vboot_fill_handoff();
|
|
|
|
}
|
|
|
|
|
2015-12-09 00:00:23 +01:00
|
|
|
static int vboot_locate(struct cbfs_props *props)
|
2015-05-01 23:48:54 +02:00
|
|
|
{
|
2015-12-09 00:00:23 +01:00
|
|
|
struct region selected_region;
|
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())
|
2015-05-15 22:57:51 +02:00
|
|
|
return -1;
|
|
|
|
|
2019-03-13 15:38:07 +01:00
|
|
|
if (vboot_get_selected_region(&selected_region))
|
2015-05-15 22:57:51 +02:00
|
|
|
return -1;
|
2015-05-01 23:48:54 +02:00
|
|
|
|
2015-12-09 00:00:23 +01:00
|
|
|
props->offset = region_offset(&selected_region);
|
|
|
|
props->size = region_sz(&selected_region);
|
2015-09-17 23:09:30 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-05-16 06:39:23 +02:00
|
|
|
}
|
|
|
|
|
2015-12-09 00:00:23 +01:00
|
|
|
const struct cbfs_locator vboot_locator = {
|
2015-05-01 23:48:54 +02:00
|
|
|
.name = "VBOOT",
|
2015-12-09 00:00:23 +01:00
|
|
|
.prepare = vboot_prepare,
|
2015-05-16 06:39:23 +02:00
|
|
|
.locate = vboot_locate,
|
2015-05-01 23:48:54 +02:00
|
|
|
};
|