treewide: Move device_tree to commonlib
[coreboot2.git] / payloads / libpayload / libc / lp_vboot.c
blobeddd317ba0feee746091f12907882310cd0a0057
1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <libpayload-config.h>
4 #include <arch/virtual.h>
5 #include <assert.h>
6 #include <libpayload.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sysinfo.h>
10 #include <vb2_api.h>
11 #include <lp_vboot.h>
13 struct vb2_context *vboot_get_context(void)
15 static struct vb2_context *ctx;
17 if (ctx)
18 return ctx;
20 die_if(lib_sysinfo.vboot_workbuf == 0, "vboot workbuf pointer is not set\n");
22 /* Use the firmware verification workbuf from coreboot. */
23 vb2_error_t rv = vb2api_reinit(phys_to_virt(lib_sysinfo.vboot_workbuf), &ctx);
25 die_if(rv, "vboot workbuf could not be initialized, error: %#x\n", rv);
27 return ctx;
30 void vboot_fail_and_reboot(struct vb2_context *ctx, uint8_t reason, uint8_t subcode)
32 if (reason)
33 vb2api_fail(ctx, reason, subcode);
35 printf("vboot: reboot requested (reason: %#x, subcode %#x)", reason, subcode);
36 vb2ex_commit_data(ctx);
37 reboot();
40 int vboot_recovery_mode_enabled(void)
42 return !!(vboot_get_context()->flags & VB2_CONTEXT_RECOVERY_MODE);