blob: 448aad6db07a375c93d25a4414038b69c2a4d2b2 [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>
23#include <stddef.h>
24#include <string.h>
25
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070026#include "chromeos.h"
27#include "vboot_common.h"
Daisuke Nojiri24d4dae2015-02-03 14:44:55 -080028#include "vboot_handoff.h"
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070029
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050030int vboot_named_region_device(const char *name, struct region_device *rdev)
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070031{
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050032 return fmap_locate_area_as_rdev(name, rdev);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070033}
34
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050035int vboot_region_device(const struct region *reg, struct region_device *rdev)
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070036{
Aaron Durbin4e50cdd2015-05-15 23:25:46 -050037 return boot_device_ro_subregion(reg, rdev);
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070038}
39
40int vboot_get_handoff_info(void **addr, uint32_t *size)
41{
42 struct vboot_handoff *vboot_handoff;
43
44 vboot_handoff = cbmem_find(CBMEM_ID_VBOOT_HANDOFF);
45
46 if (vboot_handoff == NULL)
47 return -1;
48
49 *addr = vboot_handoff;
50 *size = sizeof(*vboot_handoff);
51 return 0;
52}
53
Paul Kocialkowski115360f2015-09-03 11:41:14 +020054static int vboot_handoff_flag(uint32_t flag)
55{
56 struct vboot_handoff *vbho;
Paul Kocialkowski3faea592015-09-03 11:44:56 +020057 uint32_t size;
Paul Kocialkowski115360f2015-09-03 11:41:14 +020058
Paul Kocialkowski3faea592015-09-03 11:44:56 +020059 if (vboot_get_handoff_info((void **)&vbho, &size))
Paul Kocialkowski115360f2015-09-03 11:41:14 +020060 return 0;
61
62 return !!(vbho->init_params.out_flags & flag);
63}
64
65int vboot_skip_display_init(void)
66{
67 return !vboot_handoff_flag(VB_INIT_OUT_ENABLE_DISPLAY);
68}
69
70int vboot_enable_developer(void)
71{
72 return vboot_handoff_flag(VB_INIT_OUT_ENABLE_DEVELOPER);
73}
74
75int vboot_enable_recovery(void)
76{
77 return vboot_handoff_flag(VB_INIT_OUT_ENABLE_RECOVERY);
78}
79
Subrata Banikdf13c312015-09-28 15:12:08 +053080int vboot_recovery_reason(void)
81{
82 struct vboot_handoff *vbho;
83 VbSharedDataHeader *sd;
84
85 vbho = cbmem_find(CBMEM_ID_VBOOT_HANDOFF);
86
87 if (vbho == NULL)
88 return 0;
89
90 sd = (VbSharedDataHeader *)vbho->shared_data;
91
92 return sd->recovery_reason;
93}
94
Vadim Bendeburyc83687d2015-04-10 17:50:11 -070095void vboot_reboot(void)
96{
Vadim Bendebury6e20e2f2015-04-10 18:04:04 -070097 if (IS_ENABLED(CONFIG_CONSOLE_CBMEM_DUMP_TO_UART))
98 cbmem_dump_console();
Vadim Bendeburyc83687d2015-04-10 17:50:11 -070099 hard_reset();
100 die("failed to reboot");
101}