blob: 3ef90706ed8e030c100dc45de01eb22e71b89a8f [file] [log] [blame]
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 The ChromiumOS Authors. All rights reserved.
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 Nojiri742fc8d2014-10-10 10:51:06 -070014 */
15
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070016#include <boot/coreboot_tables.h>
Aaron Durbinb6981c02015-05-15 15:57:51 -050017#include <boot_device.h>
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070018#include <cbmem.h>
Patrick Georgi3e18aca2015-04-29 18:59:04 +020019#include <console/cbmem_console.h>
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070020#include <console/console.h>
Aaron Durbin0424c952015-03-28 23:56:22 -050021#include <fmap.h>
Vadim Bendeburyc83687d2015-04-10 17:50:11 -070022#include <reset.h>
Aaron Durbin5e291062016-01-25 16:39:56 -060023#include <rules.h>
Vadim Bendeburyc83687d2015-04-10 17:50:11 -070024#include <stddef.h>
25#include <string.h>
Philipp Deppenwiesefea24292017-10-17 17:02:29 +020026#include <security/vboot/vboot_common.h>
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070027
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050028int vboot_named_region_device(const char *name, struct region_device *rdev)
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070029{
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050030 return fmap_locate_area_as_rdev(name, rdev);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070031}
32
Aaron Durbin5bb9e932016-08-12 12:46:07 -050033int vboot_named_region_device_rw(const char *name, struct region_device *rdev)
34{
Aaron Durbina73a8032016-08-23 13:19:14 -050035 return fmap_locate_area_as_rdev_rw(name, rdev);
Aaron Durbin5bb9e932016-08-12 12:46:07 -050036}
37
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070038/* ========================== VBOOT HANDOFF APIs =========================== */
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070039int vboot_get_handoff_info(void **addr, uint32_t *size)
40{
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070041 /*
42 * vboot_handoff is present only after cbmem comes online. If we are in
43 * pre-ram stage, then bail out early.
44 */
45 if (ENV_BOOTBLOCK ||
46 (ENV_VERSTAGE && IS_ENABLED(CONFIG_VBOOT_STARTS_IN_BOOTBLOCK)))
Aaron Durbin5e291062016-01-25 16:39:56 -060047 return -1;
48
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070049 struct vboot_handoff *vboot_handoff;
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070050 vboot_handoff = cbmem_find(CBMEM_ID_VBOOT_HANDOFF);
51
52 if (vboot_handoff == NULL)
53 return -1;
54
55 *addr = vboot_handoff;
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070056
57 if (size)
58 *size = sizeof(*vboot_handoff);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070059 return 0;
60}
61
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070062static int vboot_get_handoff_flag(uint32_t flag)
Paul Kocialkowski115360f2015-09-03 11:41:14 +020063{
64 struct vboot_handoff *vbho;
65
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070066 /*
67 * If vboot_handoff cannot be found, return default value of flag as 0.
68 */
69 if (vboot_get_handoff_info((void **)&vbho, NULL))
Paul Kocialkowski115360f2015-09-03 11:41:14 +020070 return 0;
71
72 return !!(vbho->init_params.out_flags & flag);
73}
74
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070075int vboot_handoff_skip_display_init(void)
Paul Kocialkowski115360f2015-09-03 11:41:14 +020076{
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070077 return !vboot_get_handoff_flag(VB_INIT_OUT_ENABLE_DISPLAY);
Paul Kocialkowski115360f2015-09-03 11:41:14 +020078}
79
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070080int vboot_handoff_check_developer_flag(void)
Paul Kocialkowski115360f2015-09-03 11:41:14 +020081{
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070082 return vboot_get_handoff_flag(VB_INIT_OUT_ENABLE_DEVELOPER);
Paul Kocialkowski115360f2015-09-03 11:41:14 +020083}
84
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070085int vboot_handoff_check_recovery_flag(void)
Paul Kocialkowski115360f2015-09-03 11:41:14 +020086{
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070087 return vboot_get_handoff_flag(VB_INIT_OUT_ENABLE_RECOVERY);
Paul Kocialkowski115360f2015-09-03 11:41:14 +020088}
89
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070090int vboot_handoff_get_recovery_reason(void)
Subrata Banikdf13c312015-09-28 15:12:08 +053091{
92 struct vboot_handoff *vbho;
93 VbSharedDataHeader *sd;
94
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -070095 if (vboot_get_handoff_info((void **)&vbho, NULL))
Subrata Banikdf13c312015-09-28 15:12:08 +053096 return 0;
97
98 sd = (VbSharedDataHeader *)vbho->shared_data;
99
100 return sd->recovery_reason;
101}
102
Furquan Shaikha6c5ddd2016-07-22 06:59:40 -0700103/* ============================ VBOOT REBOOT ============================== */
Aaron Durbin5dbefd92016-01-22 16:33:57 -0600104void __attribute__((weak)) vboot_platform_prepare_reboot(void)
105{
106}
107
Vadim Bendeburyc83687d2015-04-10 17:50:11 -0700108void vboot_reboot(void)
109{
Vadim Bendebury6e20e2f2015-04-10 18:04:04 -0700110 if (IS_ENABLED(CONFIG_CONSOLE_CBMEM_DUMP_TO_UART))
111 cbmem_dump_console();
Aaron Durbin5dbefd92016-01-22 16:33:57 -0600112 vboot_platform_prepare_reboot();
Vadim Bendeburyc83687d2015-04-10 17:50:11 -0700113 hard_reset();
114 die("failed to reboot");
115}