Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 1 | /* |
| 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 Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 16 | #include <boot/coreboot_tables.h> |
Aaron Durbin | b6981c0 | 2015-05-15 15:57:51 -0500 | [diff] [blame] | 17 | #include <boot_device.h> |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 18 | #include <cbmem.h> |
Patrick Georgi | 3e18aca | 2015-04-29 18:59:04 +0200 | [diff] [blame] | 19 | #include <console/cbmem_console.h> |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 20 | #include <console/console.h> |
Aaron Durbin | 0424c95 | 2015-03-28 23:56:22 -0500 | [diff] [blame] | 21 | #include <fmap.h> |
Vadim Bendebury | c83687d | 2015-04-10 17:50:11 -0700 | [diff] [blame] | 22 | #include <reset.h> |
| 23 | #include <stddef.h> |
| 24 | #include <string.h> |
| 25 | |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 26 | #include "chromeos.h" |
| 27 | #include "vboot_common.h" |
Daisuke Nojiri | 24d4dae | 2015-02-03 14:44:55 -0800 | [diff] [blame] | 28 | #include "vboot_handoff.h" |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 29 | |
Aaron Durbin | 4e50cdd | 2015-05-15 23:25:46 -0500 | [diff] [blame] | 30 | int vboot_named_region_device(const char *name, struct region_device *rdev) |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 31 | { |
Aaron Durbin | 4e50cdd | 2015-05-15 23:25:46 -0500 | [diff] [blame] | 32 | return fmap_locate_area_as_rdev(name, rdev); |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Aaron Durbin | 4e50cdd | 2015-05-15 23:25:46 -0500 | [diff] [blame] | 35 | int vboot_region_device(const struct region *reg, struct region_device *rdev) |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 36 | { |
Aaron Durbin | 4e50cdd | 2015-05-15 23:25:46 -0500 | [diff] [blame] | 37 | return boot_device_ro_subregion(reg, rdev); |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int 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 Kocialkowski | 115360f | 2015-09-03 11:41:14 +0200 | [diff] [blame] | 54 | static int vboot_handoff_flag(uint32_t flag) |
| 55 | { |
| 56 | struct vboot_handoff *vbho; |
Paul Kocialkowski | 3faea59 | 2015-09-03 11:44:56 +0200 | [diff] [blame] | 57 | uint32_t size; |
Paul Kocialkowski | 115360f | 2015-09-03 11:41:14 +0200 | [diff] [blame] | 58 | |
Paul Kocialkowski | 3faea59 | 2015-09-03 11:44:56 +0200 | [diff] [blame] | 59 | if (vboot_get_handoff_info((void **)&vbho, &size)) |
Paul Kocialkowski | 115360f | 2015-09-03 11:41:14 +0200 | [diff] [blame] | 60 | return 0; |
| 61 | |
| 62 | return !!(vbho->init_params.out_flags & flag); |
| 63 | } |
| 64 | |
| 65 | int vboot_skip_display_init(void) |
| 66 | { |
| 67 | return !vboot_handoff_flag(VB_INIT_OUT_ENABLE_DISPLAY); |
| 68 | } |
| 69 | |
| 70 | int vboot_enable_developer(void) |
| 71 | { |
| 72 | return vboot_handoff_flag(VB_INIT_OUT_ENABLE_DEVELOPER); |
| 73 | } |
| 74 | |
| 75 | int vboot_enable_recovery(void) |
| 76 | { |
| 77 | return vboot_handoff_flag(VB_INIT_OUT_ENABLE_RECOVERY); |
| 78 | } |
| 79 | |
Vadim Bendebury | c83687d | 2015-04-10 17:50:11 -0700 | [diff] [blame] | 80 | void vboot_reboot(void) |
| 81 | { |
Vadim Bendebury | 6e20e2f | 2015-04-10 18:04:04 -0700 | [diff] [blame] | 82 | if (IS_ENABLED(CONFIG_CONSOLE_CBMEM_DUMP_TO_UART)) |
| 83 | cbmem_dump_console(); |
Vadim Bendebury | c83687d | 2015-04-10 17:50:11 -0700 | [diff] [blame] | 84 | hard_reset(); |
| 85 | die("failed to reboot"); |
| 86 | } |