blob: 2363bf9588b05d8e38e77a0f7adb41f934b11d7d [file] [log] [blame]
Furquan Shaikh6d448e32016-07-22 08:28:57 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2016 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <assert.h>
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070017#include <bootmode.h>
Furquan Shaikh85aa1352016-07-22 08:56:43 -070018#include <bootstate.h>
Aaron Durbinb2a5f482016-12-14 14:40:43 -060019#include <cbmem.h>
Furquan Shaikh6d448e32016-07-22 08:28:57 -070020#include <vb2_api.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020021#include <security/vboot/misc.h>
22#include <security/vboot/vbnv.h>
23#include <security/vboot/vboot_common.h>
Furquan Shaikh6d448e32016-07-22 08:28:57 -070024
Furquan Shaikh85aa1352016-07-22 08:56:43 -070025/*
Joel Kitching56e2f132020-02-08 11:17:57 +080026 * Functions which check vboot information should only be called after verstage
27 * has run. Otherwise, they will hit the assertion in vboot_get_context().
Furquan Shaikh85aa1352016-07-22 08:56:43 -070028 */
Furquan Shaikh85aa1352016-07-22 08:56:43 -070029
Furquan Shaikh6d448e32016-07-22 08:28:57 -070030int vboot_check_recovery_request(void)
31{
Joel Kitching338e9dc2020-02-14 15:41:11 +080032 return vb2api_get_recovery_reason(vboot_get_context());
Furquan Shaikh6d448e32016-07-22 08:28:57 -070033}
Furquan Shaikh0325dc62016-07-25 13:02:36 -070034
35int vboot_recovery_mode_enabled(void)
36{
Joel Kitching56e2f132020-02-08 11:17:57 +080037 return vboot_get_context()->flags & VB2_CONTEXT_RECOVERY_MODE;
38}
39
40int vboot_developer_mode_enabled(void)
41{
42 return vboot_get_context()->flags & VB2_CONTEXT_DEVELOPER_MODE;
Furquan Shaikh0325dc62016-07-25 13:02:36 -070043}
44
Aaron Durbin64031672018-04-21 14:45:32 -060045int __weak clear_recovery_mode_switch(void)
Julius Werner58c39382017-02-13 17:53:29 -080046{
Julius Werner58c39382017-02-13 17:53:29 -080047 return 0;
48}
49
Joel Kitching81726662020-02-08 12:23:23 +080050static void do_clear_recovery_mode_switch(void *unused)
Julius Werner58c39382017-02-13 17:53:29 -080051{
Joel Kitching81726662020-02-08 12:23:23 +080052 if (vboot_get_context()->flags & VB2_CONTEXT_FORCE_RECOVERY_MODE)
53 clear_recovery_mode_switch();
Julius Werner58c39382017-02-13 17:53:29 -080054}
Joel Kitching81726662020-02-08 12:23:23 +080055/*
56 * The recovery mode switch (typically backed by EC) is not cleared until
57 * BS_WRITE_TABLES for two reasons:
58 *
59 * (1) On some platforms, FSP initialization may cause a reboot. Push clearing
60 * the recovery mode switch until after FSP code runs, so that a manual recovery
61 * request (three-finger salute) will function correctly under this condition.
62 *
63 * (2) To give the implementation of clear_recovery_mode_switch a chance to
64 * add an event to elog. See the function in chromeec/switches.c.
65 */
66BOOT_STATE_INIT_ENTRY(BS_WRITE_TABLES, BS_ON_ENTRY,
67 do_clear_recovery_mode_switch, NULL);
Julius Werner58c39382017-02-13 17:53:29 -080068
Aaron Durbin64031672018-04-21 14:45:32 -060069int __weak get_recovery_mode_retrain_switch(void)
Furquan Shaikh470852b2016-11-05 23:52:08 -070070{
71 return 0;
72}
73
74int vboot_recovery_mode_memory_retrain(void)
75{
76 return get_recovery_mode_retrain_switch();
77}
78
Julius Wernercd49cce2019-03-05 16:53:33 -080079#if CONFIG(VBOOT_NO_BOARD_SUPPORT)
Philipp Deppenwiese7410f8b2017-10-18 15:29:26 +020080/**
81 * TODO: Create flash protection interface which implements get_write_protect_state.
82 * get_recovery_mode_switch should be implemented as default function.
83 */
Aaron Durbin64031672018-04-21 14:45:32 -060084int __weak get_write_protect_state(void)
Philipp Deppenwiese7410f8b2017-10-18 15:29:26 +020085{
86 return 0;
87}
88
Aaron Durbin64031672018-04-21 14:45:32 -060089int __weak get_recovery_mode_switch(void)
Philipp Deppenwiese7410f8b2017-10-18 15:29:26 +020090{
91 return 0;
92}
93
94#endif