blob: 956b54c196438504dcb6565e29c5bc917e713079 [file] [log] [blame]
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 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.
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070014 */
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070015#ifndef __VBOOT_VBOOT_COMMON_H__
16#define __VBOOT_VBOOT_COMMON_H__
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070017
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050018#include <commonlib/region.h>
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070019#include <stdint.h>
20#include <vboot_api.h>
21#include <vboot_struct.h>
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070022
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070023/* Locate vboot area by name. Returns 0 on success and -1 on error. */
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050024int vboot_named_region_device(const char *name, struct region_device *rdev);
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070025
Aaron Durbin5bb9e932016-08-12 12:46:07 -050026/* Like vboot_named_region_device() but provides a RW region device. */
27int vboot_named_region_device_rw(const char *name, struct region_device *rdev);
28
Furquan Shaikh6d448e32016-07-22 08:28:57 -070029/*
30 * Function to check if there is a request to enter recovery mode. Returns
31 * reason code if request to enter recovery mode is present, otherwise 0.
32 */
33int vboot_check_recovery_request(void);
34
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070035/* ========================== VBOOT HANDOFF APIs =========================== */
36/*
37 * The vboot_handoff structure contains the data to be consumed by downstream
38 * firmware after firmware selection has been completed. Namely it provides
39 * vboot shared data as well as the flags from VbInit.
40 */
41struct vboot_handoff {
42 VbInitParams init_params;
43 uint32_t selected_firmware;
44 char shared_data[VB_SHARED_DATA_MIN_SIZE];
45} __attribute__((packed));
46
47/*
48 * vboot_get_handoff_info returns pointer to the vboot_handoff structure if
49 * available. vboot_handoff is available only after CBMEM comes online. If size
50 * is not NULL, size of the vboot_handoff structure is returned in it.
51 * Returns 0 on success and -1 on error.
52 */
Paul Kocialkowski115360f2015-09-03 11:41:14 +020053int vboot_get_handoff_info(void **addr, uint32_t *size);
54
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070055/*
56 * The following functions read vboot_handoff structure to obtain requested
57 * information. If vboot handoff is not available, 0 is returned by default.
58 * If vboot handoff is available:
59 * Returns 1 for flag if true
60 * Returns 0 for flag if false
61 * Returns value read for other fields
62 */
63int vboot_handoff_skip_display_init(void);
64int vboot_handoff_check_recovery_flag(void);
65int vboot_handoff_check_developer_flag(void);
66int vboot_handoff_get_recovery_reason(void);
Paul Kocialkowski115360f2015-09-03 11:41:14 +020067
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070068/* ============================ VBOOT REBOOT ============================== */
69/*
70 * vboot_reboot handles the reboot requests made by vboot_reference library. It
71 * allows the platform to run any preparation steps before the reboot and then
72 * does a hard reset.
73 */
Paul Kocialkowski115360f2015-09-03 11:41:14 +020074void vboot_reboot(void);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070075
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070076/* Allow the platform to do any clean up work when vboot requests a reboot. */
77void vboot_platform_prepare_reboot(void);
78
79/* ============================ VBOOT RESUME ============================== */
Aaron Durbin87c9fae2016-01-22 15:26:04 -060080/*
81 * Save the provided hash digest to a secure location to check against in
82 * the resume path. Returns 0 on success, < 0 on error.
83 */
84int vboot_save_hash(void *digest, size_t digest_size);
85
86/*
87 * Retrieve the previously saved hash digest. Returns 0 on success,
88 * < 0 on error.
89 */
90int vboot_retrieve_hash(void *digest, size_t digest_size);
91
92/*
93 * Determine if the platform is resuming from suspend. Returns 0 when
94 * not resuming, > 0 if resuming, and < 0 on error.
95 */
96int vboot_platform_is_resuming(void);
97
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070098/* ============================= VERSTAGE ================================== */
99/*
100 * Main logic for verified boot. verstage() is the stage entry point
101 * while the verstage_main() is just the core logic.
102 */
Aaron Durbin588ad7b2015-09-29 17:56:59 -0500103void verstage_main(void);
Aaron Durbin588ad7b2015-09-29 17:56:59 -0500104void verstage(void);
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -0700105void verstage_mainboard_init(void);
Aaron Durbin588ad7b2015-09-29 17:56:59 -0500106
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700107/* Check boot modes */
108int vboot_developer_mode_enabled(void);
109int vboot_recovery_mode_enabled(void);
Furquan Shaikh470852b2016-11-05 23:52:08 -0700110int vboot_recovery_mode_memory_retrain(void);
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700111
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -0700112#endif /* __VBOOT_VBOOT_COMMON_H__ */