vboot/vboot_common: actually provide a writable region_device
[coreboot.git] / src / vboot / vboot_common.c
blob515b368f910f94cc3e2e6053ec0bdefbc394694a
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2014 The ChromiumOS Authors. All rights reserved.
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.
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.
16 #include <boot/coreboot_tables.h>
17 #include <boot_device.h>
18 #include <cbmem.h>
19 #include <console/cbmem_console.h>
20 #include <console/console.h>
21 #include <fmap.h>
22 #include <reset.h>
23 #include <rules.h>
24 #include <stddef.h>
25 #include <string.h>
26 #include <vboot/vboot_common.h>
28 int vboot_named_region_device(const char *name, struct region_device *rdev)
30 return fmap_locate_area_as_rdev(name, rdev);
33 int vboot_named_region_device_rw(const char *name, struct region_device *rdev)
35 return fmap_locate_area_as_rdev_rw(name, rdev);
38 /* ========================== VBOOT HANDOFF APIs =========================== */
39 int vboot_get_handoff_info(void **addr, uint32_t *size)
42 * vboot_handoff is present only after cbmem comes online. If we are in
43 * pre-ram stage, then bail out early.
45 if (ENV_BOOTBLOCK ||
46 (ENV_VERSTAGE && IS_ENABLED(CONFIG_VBOOT_STARTS_IN_BOOTBLOCK)))
47 return -1;
49 struct vboot_handoff *vboot_handoff;
50 vboot_handoff = cbmem_find(CBMEM_ID_VBOOT_HANDOFF);
52 if (vboot_handoff == NULL)
53 return -1;
55 *addr = vboot_handoff;
57 if (size)
58 *size = sizeof(*vboot_handoff);
59 return 0;
62 static int vboot_get_handoff_flag(uint32_t flag)
64 struct vboot_handoff *vbho;
67 * If vboot_handoff cannot be found, return default value of flag as 0.
69 if (vboot_get_handoff_info((void **)&vbho, NULL))
70 return 0;
72 return !!(vbho->init_params.out_flags & flag);
75 int vboot_handoff_skip_display_init(void)
77 return !vboot_get_handoff_flag(VB_INIT_OUT_ENABLE_DISPLAY);
80 int vboot_handoff_check_developer_flag(void)
82 return vboot_get_handoff_flag(VB_INIT_OUT_ENABLE_DEVELOPER);
85 int vboot_handoff_check_recovery_flag(void)
87 return vboot_get_handoff_flag(VB_INIT_OUT_ENABLE_RECOVERY);
90 int vboot_handoff_get_recovery_reason(void)
92 struct vboot_handoff *vbho;
93 VbSharedDataHeader *sd;
95 if (vboot_get_handoff_info((void **)&vbho, NULL))
96 return 0;
98 sd = (VbSharedDataHeader *)vbho->shared_data;
100 return sd->recovery_reason;
103 /* ============================ VBOOT REBOOT ============================== */
104 void __attribute__((weak)) vboot_platform_prepare_reboot(void)
108 void vboot_reboot(void)
110 if (IS_ENABLED(CONFIG_CONSOLE_CBMEM_DUMP_TO_UART))
111 cbmem_dump_console();
112 vboot_platform_prepare_reboot();
113 hard_reset();
114 die("failed to reboot");