2020-04-02 23:48:53 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2016-07-22 17:28:57 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
2016-07-25 20:48:03 +02:00
|
|
|
#include <bootmode.h>
|
2016-07-22 17:56:43 +02:00
|
|
|
#include <bootstate.h>
|
2016-07-22 17:28:57 +02:00
|
|
|
#include <vb2_api.h>
|
2017-10-17 17:02:29 +02:00
|
|
|
#include <security/vboot/misc.h>
|
|
|
|
#include <security/vboot/vbnv.h>
|
|
|
|
#include <security/vboot/vboot_common.h>
|
2016-07-22 17:28:57 +02:00
|
|
|
|
2016-07-22 17:56:43 +02:00
|
|
|
/*
|
2020-02-08 04:17:57 +01:00
|
|
|
* Functions which check vboot information should only be called after verstage
|
|
|
|
* has run. Otherwise, they will hit the assertion in vboot_get_context().
|
2016-07-22 17:56:43 +02:00
|
|
|
*/
|
|
|
|
|
2016-07-22 17:28:57 +02:00
|
|
|
int vboot_check_recovery_request(void)
|
|
|
|
{
|
2020-02-14 08:41:11 +01:00
|
|
|
return vb2api_get_recovery_reason(vboot_get_context());
|
2016-07-22 17:28:57 +02:00
|
|
|
}
|
2016-07-25 22:02:36 +02:00
|
|
|
|
|
|
|
int vboot_recovery_mode_enabled(void)
|
|
|
|
{
|
2020-02-08 04:17:57 +01:00
|
|
|
return vboot_get_context()->flags & VB2_CONTEXT_RECOVERY_MODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vboot_developer_mode_enabled(void)
|
|
|
|
{
|
|
|
|
return vboot_get_context()->flags & VB2_CONTEXT_DEVELOPER_MODE;
|
2016-07-25 22:02:36 +02:00
|
|
|
}
|
|
|
|
|
2018-04-21 22:45:32 +02:00
|
|
|
int __weak clear_recovery_mode_switch(void)
|
2017-02-14 02:53:29 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-08 05:23:23 +01:00
|
|
|
static void do_clear_recovery_mode_switch(void *unused)
|
2017-02-14 02:53:29 +01:00
|
|
|
{
|
2020-02-08 05:23:23 +01:00
|
|
|
if (vboot_get_context()->flags & VB2_CONTEXT_FORCE_RECOVERY_MODE)
|
|
|
|
clear_recovery_mode_switch();
|
2017-02-14 02:53:29 +01:00
|
|
|
}
|
2020-02-08 05:23:23 +01:00
|
|
|
/*
|
|
|
|
* The recovery mode switch (typically backed by EC) is not cleared until
|
|
|
|
* BS_WRITE_TABLES for two reasons:
|
|
|
|
*
|
|
|
|
* (1) On some platforms, FSP initialization may cause a reboot. Push clearing
|
|
|
|
* the recovery mode switch until after FSP code runs, so that a manual recovery
|
|
|
|
* request (three-finger salute) will function correctly under this condition.
|
|
|
|
*
|
|
|
|
* (2) To give the implementation of clear_recovery_mode_switch a chance to
|
|
|
|
* add an event to elog. See the function in chromeec/switches.c.
|
|
|
|
*/
|
|
|
|
BOOT_STATE_INIT_ENTRY(BS_WRITE_TABLES, BS_ON_ENTRY,
|
|
|
|
do_clear_recovery_mode_switch, NULL);
|
2017-02-14 02:53:29 +01:00
|
|
|
|
2018-04-21 22:45:32 +02:00
|
|
|
int __weak get_recovery_mode_retrain_switch(void)
|
2016-11-06 07:52:08 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-27 12:59:41 +02:00
|
|
|
int __weak get_ec_is_trusted(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If board doesn't override this, by default we always assume EC is in
|
|
|
|
* RW and untrusted. However, newer platforms are supposed to use cr50
|
|
|
|
* BOOT_MODE to report this and won't need to override this anymore.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-06 01:53:33 +01:00
|
|
|
#if CONFIG(VBOOT_NO_BOARD_SUPPORT)
|
2017-10-18 15:29:26 +02:00
|
|
|
/**
|
|
|
|
* TODO: Create flash protection interface which implements get_write_protect_state.
|
|
|
|
* get_recovery_mode_switch should be implemented as default function.
|
|
|
|
*/
|
2018-04-21 22:45:32 +02:00
|
|
|
int __weak get_write_protect_state(void)
|
2017-10-18 15:29:26 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-21 22:45:32 +02:00
|
|
|
int __weak get_recovery_mode_switch(void)
|
2017-10-18 15:29:26 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-06 00:45:16 +01:00
|
|
|
void __weak fill_lb_gpios(struct lb_gpios *gpios)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-18 15:29:26 +02:00
|
|
|
#endif
|