blob: 8aadf9e42085d61b58f68654b29f13dfb136cd78 [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 REBOOT ============================== */
36/*
37 * vboot_reboot handles the reboot requests made by vboot_reference library. It
38 * allows the platform to run any preparation steps before the reboot and then
39 * does a hard reset.
40 */
Paul Kocialkowski115360f2015-09-03 11:41:14 +020041void vboot_reboot(void);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070042
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070043/* Allow the platform to do any clean up work when vboot requests a reboot. */
44void vboot_platform_prepare_reboot(void);
45
46/* ============================ VBOOT RESUME ============================== */
Aaron Durbin87c9fae2016-01-22 15:26:04 -060047/*
48 * Save the provided hash digest to a secure location to check against in
49 * the resume path. Returns 0 on success, < 0 on error.
50 */
51int vboot_save_hash(void *digest, size_t digest_size);
52
53/*
54 * Retrieve the previously saved hash digest. Returns 0 on success,
55 * < 0 on error.
56 */
57int vboot_retrieve_hash(void *digest, size_t digest_size);
58
59/*
60 * Determine if the platform is resuming from suspend. Returns 0 when
61 * not resuming, > 0 if resuming, and < 0 on error.
62 */
63int vboot_platform_is_resuming(void);
64
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070065/* ============================= VERSTAGE ================================== */
66/*
Julius Werner94d94112017-03-16 19:21:51 -070067 * Main logic for verified boot. verstage_main() is just the core vboot logic.
68 * If the verstage is a separate stage, it should be entered via main().
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070069 */
Aaron Durbin588ad7b2015-09-29 17:56:59 -050070void verstage_main(void);
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070071void verstage_mainboard_init(void);
Aaron Durbin588ad7b2015-09-29 17:56:59 -050072
Furquan Shaikh0325dc62016-07-25 13:02:36 -070073/* Check boot modes */
Julius Wernercd49cce2019-03-05 16:53:33 -080074#if CONFIG(VBOOT)
Furquan Shaikh0325dc62016-07-25 13:02:36 -070075int vboot_developer_mode_enabled(void);
76int vboot_recovery_mode_enabled(void);
Furquan Shaikh470852b2016-11-05 23:52:08 -070077int vboot_recovery_mode_memory_retrain(void);
Furquan Shaikh95673af2018-04-25 18:15:44 -070078int vboot_can_enable_udc(void);
Julius Werner5fc7c282017-03-17 14:29:10 -070079#else /* !CONFIG_VBOOT */
80static inline int vboot_developer_mode_enabled(void) { return 0; }
81static inline int vboot_recovery_mode_enabled(void) { return 0; }
82static inline int vboot_recovery_mode_memory_retrain(void) { return 0; }
Furquan Shaikh95673af2018-04-25 18:15:44 -070083/* If VBOOT is not enabled, we are okay enabling USB device controller (UDC). */
84static inline int vboot_can_enable_udc(void) { return 1; }
Julius Werner5fc7c282017-03-17 14:29:10 -070085#endif
Furquan Shaikh0325dc62016-07-25 13:02:36 -070086
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070087#endif /* __VBOOT_VBOOT_COMMON_H__ */