diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index 35f2bd735b..e3c60ac189 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -414,6 +414,13 @@ void mouse_cursor_add_input_driver(struct mouse_cursor_input_driver *in); * @{ */ int exec(long addr, int argc, char **argv); + +/* + * reboot() handles reboot requests made by libpayload. It has weak implementation + * which should be overridden by payload. + */ +void __noreturn reboot(void); + /** @} */ /** diff --git a/payloads/libpayload/include/lp_vboot.h b/payloads/libpayload/include/lp_vboot.h index 56ec46024e..bdbdc74c37 100644 --- a/payloads/libpayload/include/lp_vboot.h +++ b/payloads/libpayload/include/lp_vboot.h @@ -7,4 +7,13 @@ struct vb2_context *vboot_get_context(void); +/* + * Call vb2api_fail() with reason and subcode, save vboot data with vb2ex_commit_data() + * and reboot with vboot_reboot(). + */ +void vboot_fail_and_reboot(struct vb2_context *ctx, uint8_t reason, uint8_t subcode); + +/* Returns non-zero if recovery mode is enabled. */ +int vboot_recovery_mode_enabled(void); + #endif /* _LP_VBOOT_H_ */ diff --git a/payloads/libpayload/libc/lib.c b/payloads/libpayload/libc/lib.c index 77e213c7e0..dc212e71a1 100644 --- a/payloads/libpayload/libc/lib.c +++ b/payloads/libpayload/libc/lib.c @@ -174,3 +174,8 @@ void buffer_to_fifo32_prefix(const void *buffer, u32 prefix, int prefsz, size_t } } + +__weak void reboot(void) +{ + fatal("Reboot requested but not implemented\n"); +} diff --git a/payloads/libpayload/libc/lp_vboot.c b/payloads/libpayload/libc/lp_vboot.c index b7717c7e78..eddd317ba0 100644 --- a/payloads/libpayload/libc/lp_vboot.c +++ b/payloads/libpayload/libc/lp_vboot.c @@ -26,3 +26,18 @@ struct vb2_context *vboot_get_context(void) return ctx; } + +void vboot_fail_and_reboot(struct vb2_context *ctx, uint8_t reason, uint8_t subcode) +{ + if (reason) + vb2api_fail(ctx, reason, subcode); + + printf("vboot: reboot requested (reason: %#x, subcode %#x)", reason, subcode); + vb2ex_commit_data(ctx); + reboot(); +} + +int vboot_recovery_mode_enabled(void) +{ + return !!(vboot_get_context()->flags & VB2_CONTEXT_RECOVERY_MODE); +}