| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | #ifndef __VBOOT_VBOOT_COMMON_H__ |
| 3 | #define __VBOOT_VBOOT_COMMON_H__ |
| 4 | |
| 5 | #include <commonlib/region.h> |
| 6 | #include <cbfs.h> |
| 7 | #include <vb2_api.h> |
| 8 | |
| 9 | /* |
| 10 | * Function to check if there is a request to enter recovery mode. Returns |
| 11 | * reason code if request to enter recovery mode is present, otherwise 0. |
| 12 | */ |
| 13 | int vboot_check_recovery_request(void); |
| 14 | |
| 15 | /* ============================ VBOOT REBOOT ============================== */ |
| 16 | /* |
| 17 | * vboot_reboot handles the reboot requests made by vboot_reference library. It |
| 18 | * allows the platform to run any preparation steps before the reboot and then |
| 19 | * does a hard reset. |
| 20 | */ |
| 21 | void vboot_reboot(void); |
| 22 | |
| 23 | /* |
| 24 | * Save vboot data and reboot device. Subcode will only be printed. To store |
| 25 | * failure reason and subcode vb2api_fail() should be called before this |
| 26 | * function or vboot_fail_and_reboot() should be used instead. |
| 27 | */ |
| 28 | void vboot_save_and_reboot(struct vb2_context *ctx, uint8_t subcode); |
| 29 | |
| 30 | /* Call vb2api_fail() with reason and subcode, save vboot data and reboot. */ |
| 31 | void vboot_fail_and_reboot(struct vb2_context *ctx, uint8_t reason, uint8_t subcode); |
| 32 | |
| 33 | /* Allow the platform to do any clean up work when vboot requests a reboot. */ |
| 34 | void vboot_platform_prepare_reboot(void); |
| 35 | |
| 36 | /* ============================ VBOOT RESUME ============================== */ |
| 37 | /* |
| 38 | * Save the provided hash digest to a secure location to check against in |
| 39 | * the resume path. Returns 0 on success, < 0 on error. |
| 40 | */ |
| 41 | int vboot_save_hash(void *digest, size_t digest_size); |
| 42 | |
| 43 | /* |
| 44 | * Retrieve the previously saved hash digest. Returns 0 on success, |
| 45 | * < 0 on error. |
| 46 | */ |
| 47 | int vboot_retrieve_hash(void *digest, size_t digest_size); |
| 48 | |
| 49 | /* ============================= VERSTAGE ================================== */ |
| 50 | /* |
| 51 | * Main logic for verified boot. verstage_main() is just the core vboot logic. |
| 52 | * If the verstage is a separate stage, it should be entered via main(). |
| 53 | */ |
| 54 | void verstage_main(void); |
| 55 | void verstage_mainboard_early_init(void); |
| 56 | void verstage_mainboard_init(void); |
| 57 | |
| 58 | /* Check boot modes */ |
| 59 | #if CONFIG(VBOOT) && !ENV_SMM |
| 60 | int vboot_developer_mode_enabled(void); |
| 61 | int vboot_recovery_mode_enabled(void); |
| 62 | int vboot_can_enable_udc(void); |
| 63 | void vboot_run_logic(void); |
| 64 | const struct cbfs_boot_device *vboot_get_cbfs_boot_device(void); |
| 65 | #else /* !CONFIG_VBOOT */ |
| 66 | static inline int vboot_developer_mode_enabled(void) { return 0; } |
| 67 | static inline int vboot_recovery_mode_enabled(void) { return 0; } |
| 68 | /* If VBOOT is not enabled, we are okay enabling USB device controller (UDC). */ |
| 69 | static inline int vboot_can_enable_udc(void) { return 1; } |
| 70 | static inline void vboot_run_logic(void) {} |
| 71 | static inline const struct cbfs_boot_device *vboot_get_cbfs_boot_device(void) |
| 72 | { |
| 73 | return NULL; |
| 74 | } |
| 75 | #endif |
| 76 | |
| 77 | /* |
| 78 | * This function is called before updating the EC firmware image. |
| 79 | * This API must be implemented in the SoC/mainboard code to enable |
| 80 | * early sign-of-life (eSOL) during EC firmware update. |
| 81 | */ |
| 82 | #if CONFIG(VBOOT_EC_SYNC_ESOL) |
| 83 | void vboot_show_ec_sync_esol(void); |
| 84 | #else |
| 85 | static inline void vboot_show_ec_sync_esol(void) |
| 86 | { |
| 87 | /* nop */ |
| 88 | } |
| 89 | #endif |
| 90 | |
| 91 | void vboot_save_data(struct vb2_context *ctx); |
| 92 | |
| 93 | /* |
| 94 | * The API for performing EC software sync. Does not support |
| 95 | * "slow" updates or Auxiliary FW sync. |
| 96 | */ |
| 97 | void vboot_sync_ec(void); |
| 98 | |
| 99 | #endif /* __VBOOT_VBOOT_COMMON_H__ */ |