blob: 8c92f7f131b04d04bced2949134e75eb931acd10 [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>
Stefan Reinauer6a001132017-07-13 02:20:27 +020020#include <compiler.h>
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070021#include <vboot_api.h>
22#include <vboot_struct.h>
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070023
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070024/* Locate vboot area by name. Returns 0 on success and -1 on error. */
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050025int vboot_named_region_device(const char *name, struct region_device *rdev);
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070026
Aaron Durbin5bb9e932016-08-12 12:46:07 -050027/* Like vboot_named_region_device() but provides a RW region device. */
28int vboot_named_region_device_rw(const char *name, struct region_device *rdev);
29
Furquan Shaikh6d448e32016-07-22 08:28:57 -070030/*
31 * Function to check if there is a request to enter recovery mode. Returns
32 * reason code if request to enter recovery mode is present, otherwise 0.
33 */
34int vboot_check_recovery_request(void);
35
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070036/* ========================== VBOOT HANDOFF APIs =========================== */
37/*
38 * The vboot_handoff structure contains the data to be consumed by downstream
39 * firmware after firmware selection has been completed. Namely it provides
40 * vboot shared data as well as the flags from VbInit.
41 */
42struct vboot_handoff {
43 VbInitParams init_params;
44 uint32_t selected_firmware;
45 char shared_data[VB_SHARED_DATA_MIN_SIZE];
Stefan Reinauer6a001132017-07-13 02:20:27 +020046} __packed;
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070047
48/*
49 * vboot_get_handoff_info returns pointer to the vboot_handoff structure if
50 * available. vboot_handoff is available only after CBMEM comes online. If size
51 * is not NULL, size of the vboot_handoff structure is returned in it.
52 * Returns 0 on success and -1 on error.
53 */
Paul Kocialkowski115360f2015-09-03 11:41:14 +020054int vboot_get_handoff_info(void **addr, uint32_t *size);
55
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070056/*
57 * The following functions read vboot_handoff structure to obtain requested
58 * information. If vboot handoff is not available, 0 is returned by default.
59 * If vboot handoff is available:
60 * Returns 1 for flag if true
61 * Returns 0 for flag if false
62 * Returns value read for other fields
63 */
64int vboot_handoff_skip_display_init(void);
65int vboot_handoff_check_recovery_flag(void);
66int vboot_handoff_check_developer_flag(void);
67int vboot_handoff_get_recovery_reason(void);
Paul Kocialkowski115360f2015-09-03 11:41:14 +020068
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070069/* ============================ VBOOT REBOOT ============================== */
70/*
71 * vboot_reboot handles the reboot requests made by vboot_reference library. It
72 * allows the platform to run any preparation steps before the reboot and then
73 * does a hard reset.
74 */
Paul Kocialkowski115360f2015-09-03 11:41:14 +020075void vboot_reboot(void);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070076
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070077/* Allow the platform to do any clean up work when vboot requests a reboot. */
78void vboot_platform_prepare_reboot(void);
79
80/* ============================ VBOOT RESUME ============================== */
Aaron Durbin87c9fae2016-01-22 15:26:04 -060081/*
82 * Save the provided hash digest to a secure location to check against in
83 * the resume path. Returns 0 on success, < 0 on error.
84 */
85int vboot_save_hash(void *digest, size_t digest_size);
86
87/*
88 * Retrieve the previously saved hash digest. Returns 0 on success,
89 * < 0 on error.
90 */
91int vboot_retrieve_hash(void *digest, size_t digest_size);
92
93/*
94 * Determine if the platform is resuming from suspend. Returns 0 when
95 * not resuming, > 0 if resuming, and < 0 on error.
96 */
97int vboot_platform_is_resuming(void);
98
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070099/* ============================= VERSTAGE ================================== */
100/*
Julius Werner94d94112017-03-16 19:21:51 -0700101 * Main logic for verified boot. verstage_main() is just the core vboot logic.
102 * If the verstage is a separate stage, it should be entered via main().
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -0700103 */
Aaron Durbin588ad7b2015-09-29 17:56:59 -0500104void verstage_main(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 */
Julius Werner5fc7c282017-03-17 14:29:10 -0700108#if IS_ENABLED(CONFIG_VBOOT)
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700109int vboot_developer_mode_enabled(void);
110int vboot_recovery_mode_enabled(void);
Furquan Shaikh470852b2016-11-05 23:52:08 -0700111int vboot_recovery_mode_memory_retrain(void);
Julius Werner5fc7c282017-03-17 14:29:10 -0700112#else /* !CONFIG_VBOOT */
113static inline int vboot_developer_mode_enabled(void) { return 0; }
114static inline int vboot_recovery_mode_enabled(void) { return 0; }
115static inline int vboot_recovery_mode_memory_retrain(void) { return 0; }
116#endif
Furquan Shaikh0325dc62016-07-25 13:02:36 -0700117
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -0700118#endif /* __VBOOT_VBOOT_COMMON_H__ */