Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 1 | /* |
| 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 Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 14 | */ |
Furquan Shaikh | 2a12e2e | 2016-07-25 11:48:03 -0700 | [diff] [blame] | 15 | #ifndef __VBOOT_VBOOT_COMMON_H__ |
| 16 | #define __VBOOT_VBOOT_COMMON_H__ |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 17 | |
Aaron Durbin | dc9f5cd | 2015-09-08 13:34:43 -0500 | [diff] [blame] | 18 | #include <commonlib/region.h> |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <vboot_api.h> |
| 21 | #include <vboot_struct.h> |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 22 | |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 23 | /* Locate vboot area by name. Returns 0 on success and -1 on error. */ |
Aaron Durbin | 4e50cdd | 2015-05-15 23:25:46 -0500 | [diff] [blame] | 24 | int vboot_named_region_device(const char *name, struct region_device *rdev); |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 25 | |
Aaron Durbin | 5bb9e93 | 2016-08-12 12:46:07 -0500 | [diff] [blame] | 26 | /* Like vboot_named_region_device() but provides a RW region device. */ |
| 27 | int vboot_named_region_device_rw(const char *name, struct region_device *rdev); |
| 28 | |
Furquan Shaikh | 6d448e3 | 2016-07-22 08:28:57 -0700 | [diff] [blame] | 29 | /* |
| 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 | */ |
| 33 | int vboot_check_recovery_request(void); |
| 34 | |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 35 | /* ========================== 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 | */ |
| 41 | struct vboot_handoff { |
| 42 | VbInitParams init_params; |
| 43 | uint32_t selected_firmware; |
| 44 | char shared_data[VB_SHARED_DATA_MIN_SIZE]; |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 45 | } __packed; |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 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 Kocialkowski | 115360f | 2015-09-03 11:41:14 +0200 | [diff] [blame] | 53 | int vboot_get_handoff_info(void **addr, uint32_t *size); |
| 54 | |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 55 | /* |
| 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 | */ |
| 63 | int vboot_handoff_skip_display_init(void); |
| 64 | int vboot_handoff_check_recovery_flag(void); |
| 65 | int vboot_handoff_check_developer_flag(void); |
| 66 | int vboot_handoff_get_recovery_reason(void); |
Paul Kocialkowski | 115360f | 2015-09-03 11:41:14 +0200 | [diff] [blame] | 67 | |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 68 | /* ============================ 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 Kocialkowski | 115360f | 2015-09-03 11:41:14 +0200 | [diff] [blame] | 74 | void vboot_reboot(void); |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 75 | |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 76 | /* Allow the platform to do any clean up work when vboot requests a reboot. */ |
| 77 | void vboot_platform_prepare_reboot(void); |
| 78 | |
| 79 | /* ============================ VBOOT RESUME ============================== */ |
Aaron Durbin | 87c9fae | 2016-01-22 15:26:04 -0600 | [diff] [blame] | 80 | /* |
| 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 | */ |
| 84 | int 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 | */ |
| 90 | int 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 | */ |
| 96 | int vboot_platform_is_resuming(void); |
| 97 | |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 98 | /* ============================= VERSTAGE ================================== */ |
| 99 | /* |
Julius Werner | 94d9411 | 2017-03-16 19:21:51 -0700 | [diff] [blame] | 100 | * Main logic for verified boot. verstage_main() is just the core vboot logic. |
| 101 | * If the verstage is a separate stage, it should be entered via main(). |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 102 | */ |
Aaron Durbin | 588ad7b | 2015-09-29 17:56:59 -0500 | [diff] [blame] | 103 | void verstage_main(void); |
Furquan Shaikh | a6c5ddd | 2016-07-22 06:59:40 -0700 | [diff] [blame] | 104 | void verstage_mainboard_init(void); |
Aaron Durbin | 588ad7b | 2015-09-29 17:56:59 -0500 | [diff] [blame] | 105 | |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 106 | /* Check boot modes */ |
Julius Werner | 5fc7c28 | 2017-03-17 14:29:10 -0700 | [diff] [blame] | 107 | #if IS_ENABLED(CONFIG_VBOOT) |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 108 | int vboot_developer_mode_enabled(void); |
| 109 | int vboot_recovery_mode_enabled(void); |
Furquan Shaikh | 470852b | 2016-11-05 23:52:08 -0700 | [diff] [blame] | 110 | int vboot_recovery_mode_memory_retrain(void); |
Furquan Shaikh | 95673af | 2018-04-25 18:15:44 -0700 | [diff] [blame] | 111 | int vboot_can_enable_udc(void); |
Julius Werner | 5fc7c28 | 2017-03-17 14:29:10 -0700 | [diff] [blame] | 112 | #else /* !CONFIG_VBOOT */ |
| 113 | static inline int vboot_developer_mode_enabled(void) { return 0; } |
| 114 | static inline int vboot_recovery_mode_enabled(void) { return 0; } |
| 115 | static inline int vboot_recovery_mode_memory_retrain(void) { return 0; } |
Furquan Shaikh | 95673af | 2018-04-25 18:15:44 -0700 | [diff] [blame] | 116 | /* If VBOOT is not enabled, we are okay enabling USB device controller (UDC). */ |
| 117 | static inline int vboot_can_enable_udc(void) { return 1; } |
Julius Werner | 5fc7c28 | 2017-03-17 14:29:10 -0700 | [diff] [blame] | 118 | #endif |
Furquan Shaikh | 0325dc6 | 2016-07-25 13:02:36 -0700 | [diff] [blame] | 119 | |
Furquan Shaikh | 2a12e2e | 2016-07-25 11:48:03 -0700 | [diff] [blame] | 120 | #endif /* __VBOOT_VBOOT_COMMON_H__ */ |