blob: 57f3475adbc046a3b04831d8b16db5669e407ef9 [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>
Joel Kitching814c8652020-02-14 13:18:06 +080020#include <vb2_api.h>
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070021
Furquan Shaikh6d448e32016-07-22 08:28:57 -070022/*
23 * Function to check if there is a request to enter recovery mode. Returns
24 * reason code if request to enter recovery mode is present, otherwise 0.
25 */
26int vboot_check_recovery_request(void);
27
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070028/* ============================ VBOOT REBOOT ============================== */
29/*
30 * vboot_reboot handles the reboot requests made by vboot_reference library. It
31 * allows the platform to run any preparation steps before the reboot and then
32 * does a hard reset.
33 */
Paul Kocialkowski115360f2015-09-03 11:41:14 +020034void vboot_reboot(void);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070035
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070036/* Allow the platform to do any clean up work when vboot requests a reboot. */
37void vboot_platform_prepare_reboot(void);
38
39/* ============================ VBOOT RESUME ============================== */
Aaron Durbin87c9fae2016-01-22 15:26:04 -060040/*
41 * Save the provided hash digest to a secure location to check against in
42 * the resume path. Returns 0 on success, < 0 on error.
43 */
44int vboot_save_hash(void *digest, size_t digest_size);
45
46/*
47 * Retrieve the previously saved hash digest. Returns 0 on success,
48 * < 0 on error.
49 */
50int vboot_retrieve_hash(void *digest, size_t digest_size);
51
52/*
53 * Determine if the platform is resuming from suspend. Returns 0 when
54 * not resuming, > 0 if resuming, and < 0 on error.
55 */
56int vboot_platform_is_resuming(void);
57
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070058/* ============================= VERSTAGE ================================== */
59/*
Julius Werner94d94112017-03-16 19:21:51 -070060 * Main logic for verified boot. verstage_main() is just the core vboot logic.
61 * If the verstage is a separate stage, it should be entered via main().
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070062 */
Aaron Durbin588ad7b2015-09-29 17:56:59 -050063void verstage_main(void);
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070064void verstage_mainboard_init(void);
Aaron Durbin588ad7b2015-09-29 17:56:59 -050065
Furquan Shaikh0325dc62016-07-25 13:02:36 -070066/* Check boot modes */
Julius Wernercd49cce2019-03-05 16:53:33 -080067#if CONFIG(VBOOT)
Furquan Shaikh0325dc62016-07-25 13:02:36 -070068int vboot_developer_mode_enabled(void);
69int vboot_recovery_mode_enabled(void);
Furquan Shaikh470852b2016-11-05 23:52:08 -070070int vboot_recovery_mode_memory_retrain(void);
Furquan Shaikh95673af2018-04-25 18:15:44 -070071int vboot_can_enable_udc(void);
Wim Vervoorn1058dd82019-11-01 10:22:22 +010072void vboot_run_logic(void);
Julius Werner815611e2019-12-05 22:29:07 -080073int vboot_locate_cbfs(struct region_device *rdev);
Julius Werner5fc7c282017-03-17 14:29:10 -070074#else /* !CONFIG_VBOOT */
75static inline int vboot_developer_mode_enabled(void) { return 0; }
76static inline int vboot_recovery_mode_enabled(void) { return 0; }
77static inline int vboot_recovery_mode_memory_retrain(void) { return 0; }
Furquan Shaikh95673af2018-04-25 18:15:44 -070078/* If VBOOT is not enabled, we are okay enabling USB device controller (UDC). */
79static inline int vboot_can_enable_udc(void) { return 1; }
Wim Vervoorn1058dd82019-11-01 10:22:22 +010080static inline void vboot_run_logic(void) {}
Julius Werner815611e2019-12-05 22:29:07 -080081static inline int vboot_locate_cbfs(struct region_device *rdev) { return -1; }
Julius Werner5fc7c282017-03-17 14:29:10 -070082#endif
Furquan Shaikh0325dc62016-07-25 13:02:36 -070083
Tim Wawrzynczakd6fc5572019-10-25 14:58:15 -060084void vboot_save_nvdata_only(struct vb2_context *ctx);
85void vboot_save_data(struct vb2_context *ctx);
86
87/*
88 * The API for performing EC software sync. Does not support
89 * "slow" updates or Auxiliary FW sync.
90 */
91void vboot_sync_ec(void);
92
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070093#endif /* __VBOOT_VBOOT_COMMON_H__ */