blob: 28135a0d657eae8907f48adcd0706bb560aa7fc3 [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>
26
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070027#include "chromeos.h"
28#include "vboot_common.h"
Daisuke Nojiri24d4dae2015-02-03 14:44:55 -080029#include "vboot_handoff.h"
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070030
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050031int vboot_named_region_device(const char *name, struct region_device *rdev)
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070032{
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050033 return fmap_locate_area_as_rdev(name, rdev);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070034}
35
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050036int vboot_region_device(const struct region *reg, struct region_device *rdev)
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070037{
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050038 return boot_device_ro_subregion(reg, rdev);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070039}
40
41int vboot_get_handoff_info(void **addr, uint32_t *size)
42{
43 struct vboot_handoff *vboot_handoff;
44
Aaron Durbin5e291062016-01-25 16:39:56 -060045 /* No flags are available in a separate verstage or bootblock because
46 * cbmem only comes online when dram does. */
47 if ((ENV_VERSTAGE && IS_ENABLED(CONFIG_VBOOT_STARTS_IN_BOOTBLOCK)) ||
48 ENV_BOOTBLOCK)
49 return -1;
50
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070051 vboot_handoff = cbmem_find(CBMEM_ID_VBOOT_HANDOFF);
52
53 if (vboot_handoff == NULL)
54 return -1;
55
56 *addr = vboot_handoff;
57 *size = sizeof(*vboot_handoff);
58 return 0;
59}
60
Paul Kocialkowski115360f2015-09-03 11:41:14 +020061static int vboot_handoff_flag(uint32_t flag)
62{
63 struct vboot_handoff *vbho;
Paul Kocialkowski3faea592015-09-03 11:44:56 +020064 uint32_t size;
Paul Kocialkowski115360f2015-09-03 11:41:14 +020065
Paul Kocialkowski3faea592015-09-03 11:44:56 +020066 if (vboot_get_handoff_info((void **)&vbho, &size))
Paul Kocialkowski115360f2015-09-03 11:41:14 +020067 return 0;
68
69 return !!(vbho->init_params.out_flags & flag);
70}
71
72int vboot_skip_display_init(void)
73{
74 return !vboot_handoff_flag(VB_INIT_OUT_ENABLE_DISPLAY);
75}
76
77int vboot_enable_developer(void)
78{
79 return vboot_handoff_flag(VB_INIT_OUT_ENABLE_DEVELOPER);
80}
81
82int vboot_enable_recovery(void)
83{
84 return vboot_handoff_flag(VB_INIT_OUT_ENABLE_RECOVERY);
85}
86
Subrata Banikdf13c312015-09-28 15:12:08 +053087int vboot_recovery_reason(void)
88{
89 struct vboot_handoff *vbho;
90 VbSharedDataHeader *sd;
91
92 vbho = cbmem_find(CBMEM_ID_VBOOT_HANDOFF);
93
94 if (vbho == NULL)
95 return 0;
96
97 sd = (VbSharedDataHeader *)vbho->shared_data;
98
99 return sd->recovery_reason;
100}
101
Aaron Durbin5dbefd92016-01-22 16:33:57 -0600102void __attribute__((weak)) vboot_platform_prepare_reboot(void)
103{
104}
105
Vadim Bendeburyc83687d2015-04-10 17:50:11 -0700106void vboot_reboot(void)
107{
Vadim Bendebury6e20e2f2015-04-10 18:04:04 -0700108 if (IS_ENABLED(CONFIG_CONSOLE_CBMEM_DUMP_TO_UART))
109 cbmem_dump_console();
Aaron Durbin5dbefd92016-01-22 16:33:57 -0600110 vboot_platform_prepare_reboot();
Vadim Bendeburyc83687d2015-04-10 17:50:11 -0700111 hard_reset();
112 die("failed to reboot");
113}