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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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-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");
|
|
|
|
|
2019-11-20 19:47:10 +01:00
|
|
|
int vboot_executed;
|
2015-12-09 00:00:23 +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();
|
2019-11-20 19:47:10 +01:00
|
|
|
vboot_executed = 1;
|
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;
|
|
|
|
|
2019-11-20 19:47:10 +01:00
|
|
|
vboot_executed = 1;
|
2015-05-01 23:48:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-18 20:35:21 +01:00
|
|
|
static int vboot_locate(struct region_device *rdev)
|
2015-05-01 23:48:54 +02:00
|
|
|
{
|
2019-12-12 22:23:06 +01:00
|
|
|
struct vb2_context *ctx;
|
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-11-14 08:42:25 +01:00
|
|
|
ctx = vboot_get_context();
|
|
|
|
|
|
|
|
if (ctx->flags & VB2_CONTEXT_RECOVERY_MODE)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-18 20:35:21 +01:00
|
|
|
return vboot_locate_firmware(ctx, rdev);
|
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-05-16 06:39:23 +02:00
|
|
|
.locate = vboot_locate,
|
2015-05-01 23:48:54 +02:00
|
|
|
};
|