2014-10-10 19:51:06 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 The ChromiumOS Authors. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 <boot/coreboot_tables.h>
|
2015-05-15 22:57:51 +02:00
|
|
|
#include <boot_device.h>
|
2014-10-10 19:51:06 +02:00
|
|
|
#include <cbmem.h>
|
2015-04-29 18:59:04 +02:00
|
|
|
#include <console/cbmem_console.h>
|
2015-03-29 06:56:22 +02:00
|
|
|
#include <fmap.h>
|
2018-04-26 03:15:44 +02:00
|
|
|
#include <gbb_header.h>
|
2015-04-11 02:50:11 +02:00
|
|
|
#include <reset.h>
|
|
|
|
#include <stddef.h>
|
2018-04-26 03:15:44 +02:00
|
|
|
#include <security/vboot/gbb.h>
|
2017-10-17 17:02:29 +02:00
|
|
|
#include <security/vboot/vboot_common.h>
|
2018-04-26 03:15:44 +02:00
|
|
|
#include <security/vboot/vbnv.h>
|
2014-10-10 19:51:06 +02:00
|
|
|
|
2015-05-16 06:25:46 +02:00
|
|
|
int vboot_named_region_device(const char *name, struct region_device *rdev)
|
2014-10-10 19:51:06 +02:00
|
|
|
{
|
2015-05-16 06:25:46 +02:00
|
|
|
return fmap_locate_area_as_rdev(name, rdev);
|
2014-10-10 19:51:06 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 19:46:07 +02:00
|
|
|
int vboot_named_region_device_rw(const char *name, struct region_device *rdev)
|
|
|
|
{
|
2016-08-23 20:19:14 +02:00
|
|
|
return fmap_locate_area_as_rdev_rw(name, rdev);
|
2016-08-12 19:46:07 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 03:15:44 +02:00
|
|
|
/* Check if it is okay to enable USB Device Controller (UDC). */
|
|
|
|
int vboot_can_enable_udc(void)
|
|
|
|
{
|
|
|
|
/* Always disable if not in developer mode */
|
|
|
|
if (!vboot_developer_mode_enabled())
|
|
|
|
return 0;
|
|
|
|
/* Enable if GBB flag is set */
|
|
|
|
if (gbb_is_flag_set(GBB_FLAG_ENABLE_UDC))
|
|
|
|
return 1;
|
|
|
|
/* Enable if VBNV flag is set */
|
|
|
|
if (vbnv_udc_enable_flag())
|
|
|
|
return 1;
|
|
|
|
/* Otherwise disable */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
/* ========================== VBOOT HANDOFF APIs =========================== */
|
2014-10-10 19:51:06 +02:00
|
|
|
int vboot_get_handoff_info(void **addr, uint32_t *size)
|
|
|
|
{
|
2016-07-22 15:59:40 +02:00
|
|
|
/*
|
|
|
|
* vboot_handoff is present only after cbmem comes online. If we are in
|
|
|
|
* pre-ram stage, then bail out early.
|
|
|
|
*/
|
|
|
|
if (ENV_BOOTBLOCK ||
|
2019-03-06 01:53:33 +01:00
|
|
|
(ENV_VERSTAGE && CONFIG(VBOOT_STARTS_IN_BOOTBLOCK)))
|
2016-01-25 23:39:56 +01:00
|
|
|
return -1;
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
struct vboot_handoff *vboot_handoff;
|
2014-10-10 19:51:06 +02:00
|
|
|
vboot_handoff = cbmem_find(CBMEM_ID_VBOOT_HANDOFF);
|
|
|
|
|
|
|
|
if (vboot_handoff == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*addr = vboot_handoff;
|
2016-07-22 15:59:40 +02:00
|
|
|
|
|
|
|
if (size)
|
|
|
|
*size = sizeof(*vboot_handoff);
|
2014-10-10 19:51:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
static int vboot_get_handoff_flag(uint32_t flag)
|
2015-09-03 11:41:14 +02:00
|
|
|
{
|
|
|
|
struct vboot_handoff *vbho;
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
/*
|
|
|
|
* If vboot_handoff cannot be found, return default value of flag as 0.
|
|
|
|
*/
|
|
|
|
if (vboot_get_handoff_info((void **)&vbho, NULL))
|
2015-09-03 11:41:14 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return !!(vbho->init_params.out_flags & flag);
|
|
|
|
}
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
int vboot_handoff_check_developer_flag(void)
|
2015-09-03 11:41:14 +02:00
|
|
|
{
|
2016-07-22 15:59:40 +02:00
|
|
|
return vboot_get_handoff_flag(VB_INIT_OUT_ENABLE_DEVELOPER);
|
2015-09-03 11:41:14 +02:00
|
|
|
}
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
int vboot_handoff_check_recovery_flag(void)
|
2015-09-03 11:41:14 +02:00
|
|
|
{
|
2016-07-22 15:59:40 +02:00
|
|
|
return vboot_get_handoff_flag(VB_INIT_OUT_ENABLE_RECOVERY);
|
2015-09-03 11:41:14 +02:00
|
|
|
}
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
int vboot_handoff_get_recovery_reason(void)
|
2015-09-28 11:42:08 +02:00
|
|
|
{
|
|
|
|
struct vboot_handoff *vbho;
|
|
|
|
VbSharedDataHeader *sd;
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
if (vboot_get_handoff_info((void **)&vbho, NULL))
|
2015-09-28 11:42:08 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
sd = (VbSharedDataHeader *)vbho->shared_data;
|
|
|
|
|
|
|
|
return sd->recovery_reason;
|
|
|
|
}
|
|
|
|
|
2016-07-22 15:59:40 +02:00
|
|
|
/* ============================ VBOOT REBOOT ============================== */
|
2018-04-21 22:45:32 +02:00
|
|
|
void __weak vboot_platform_prepare_reboot(void)
|
2016-01-22 23:33:57 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-11 02:50:11 +02:00
|
|
|
void vboot_reboot(void)
|
|
|
|
{
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(CONSOLE_CBMEM_DUMP_TO_UART))
|
2015-04-11 03:04:04 +02:00
|
|
|
cbmem_dump_console();
|
2016-01-22 23:33:57 +01:00
|
|
|
vboot_platform_prepare_reboot();
|
2018-10-05 23:40:21 +02:00
|
|
|
board_reset();
|
2015-04-11 02:50:11 +02:00
|
|
|
}
|