Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google, Inc. |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 20 | #include <arch/stages.h> |
| 21 | #include <assert.h> |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 22 | #include <stdint.h> |
| 23 | #include <stddef.h> |
| 24 | #include <string.h> |
| 25 | #include <cbfs.h> |
| 26 | #include <cbmem.h> |
| 27 | #include <console/console.h> |
| 28 | #include <console/vtxprintf.h> |
Aaron Durbin | 0424c95 | 2015-03-28 23:56:22 -0500 | [diff] [blame^] | 29 | #include <fmap.h> |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 30 | #include <stdlib.h> |
| 31 | #include <timestamp.h> |
Randall Spangler | 144c228 | 2014-12-03 17:35:53 -0800 | [diff] [blame] | 32 | #define NEED_VB20_INTERNALS /* TODO: remove me! */ |
| 33 | #include <vb2_api.h> |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 34 | #include <vboot_struct.h> |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 35 | #include "../chromeos.h" |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 36 | #include "../vboot_handoff.h" |
| 37 | #include "misc.h" |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Sets vboot_handoff based on the information in vb2_shared_data |
| 41 | * |
Gediminas Ramanauskas | ceaabc9 | 2014-11-04 20:07:09 -0800 | [diff] [blame] | 42 | * TODO: Add VBSD_BOOT_FIRMWARE_SW_WP_ENABLED logic |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 43 | */ |
| 44 | static void fill_vboot_handoff(struct vboot_handoff *vboot_handoff, |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 45 | struct vb2_shared_data *vb2_sd) |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 46 | { |
| 47 | VbSharedDataHeader *vb_sd = |
| 48 | (VbSharedDataHeader *)vboot_handoff->shared_data; |
| 49 | uint32_t *oflags = &vboot_handoff->init_params.out_flags; |
| 50 | |
| 51 | vb_sd->flags |= VBSD_BOOT_FIRMWARE_VBOOT2; |
| 52 | |
| 53 | vboot_handoff->selected_firmware = vb2_sd->fw_slot; |
| 54 | |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 55 | vb_sd->firmware_index = vb2_sd->fw_slot; |
| 56 | |
| 57 | vb_sd->magic = VB_SHARED_DATA_MAGIC; |
| 58 | vb_sd->struct_version = VB_SHARED_DATA_VERSION; |
| 59 | vb_sd->struct_size = sizeof(VbSharedDataHeader); |
| 60 | vb_sd->data_size = VB_SHARED_DATA_MIN_SIZE; |
| 61 | vb_sd->data_used = sizeof(VbSharedDataHeader); |
Julius Werner | e319e48 | 2015-01-29 17:50:58 -0800 | [diff] [blame] | 62 | vb_sd->fw_version_tpm = vb2_sd->fw_version_secdata; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 63 | |
Gediminas Ramanauskas | ceaabc9 | 2014-11-04 20:07:09 -0800 | [diff] [blame] | 64 | if (get_write_protect_state()) |
| 65 | vb_sd->flags |= VBSD_BOOT_FIRMWARE_WP_ENABLED; |
| 66 | |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 67 | if (vb2_sd->recovery_reason) { |
| 68 | vb_sd->firmware_index = 0xFF; |
| 69 | if (vb2_sd->recovery_reason == VB2_RECOVERY_RO_MANUAL) |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 70 | vb_sd->flags |= VBSD_BOOT_REC_SWITCH_ON; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 71 | *oflags |= VB_INIT_OUT_ENABLE_RECOVERY; |
| 72 | *oflags |= VB_INIT_OUT_CLEAR_RAM; |
| 73 | *oflags |= VB_INIT_OUT_ENABLE_DISPLAY; |
| 74 | *oflags |= VB_INIT_OUT_ENABLE_USB_STORAGE; |
| 75 | } |
| 76 | if (vb2_sd->flags & VB2_SD_DEV_MODE_ENABLED) { |
| 77 | *oflags |= VB_INIT_OUT_ENABLE_DEVELOPER; |
| 78 | *oflags |= VB_INIT_OUT_CLEAR_RAM; |
| 79 | *oflags |= VB_INIT_OUT_ENABLE_DISPLAY; |
| 80 | *oflags |= VB_INIT_OUT_ENABLE_USB_STORAGE; |
| 81 | vb_sd->flags |= VBSD_BOOT_DEV_SWITCH_ON; |
| 82 | vb_sd->flags |= VBSD_LF_DEV_SWITCH_ON; |
| 83 | } |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 84 | /* TODO: Set these in depthcharge */ |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 85 | if (CONFIG_VIRTUAL_DEV_SWITCH) |
| 86 | vb_sd->flags |= VBSD_HONOR_VIRT_DEV_SWITCH; |
Daisuke Nojiri | 2624c8d | 2014-11-13 11:35:52 -0800 | [diff] [blame] | 87 | if (CONFIG_EC_SOFTWARE_SYNC) |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 88 | vb_sd->flags |= VBSD_EC_SOFTWARE_SYNC; |
Daisuke Nojiri | 2624c8d | 2014-11-13 11:35:52 -0800 | [diff] [blame] | 89 | if (!CONFIG_PHYSICAL_REC_SWITCH) |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 90 | vb_sd->flags |= VBSD_BOOT_REC_SWITCH_VIRTUAL; |
Daisuke Nojiri | 2624c8d | 2014-11-13 11:35:52 -0800 | [diff] [blame] | 91 | |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 92 | /* In vboot1, VBSD_FWB_TRIED is |
| 93 | * set only if B is booted as explicitly requested. Therefore, if B is |
| 94 | * booted because A was found bad, the flag should not be set. It's |
| 95 | * better not to touch it if we can only ambiguously control it. */ |
| 96 | /* if (vb2_sd->fw_slot) |
| 97 | vb_sd->flags |= VBSD_FWB_TRIED; */ |
| 98 | |
| 99 | /* copy kernel subkey if it's found */ |
| 100 | if (vb2_sd->workbuf_preamble_size) { |
| 101 | struct vb2_fw_preamble *fp; |
| 102 | uintptr_t dst, src; |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 103 | printk(BIOS_INFO, "Copying FW preamble\n"); |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 104 | fp = (struct vb2_fw_preamble *)((uintptr_t)vb2_sd + |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 105 | vb2_sd->workbuf_preamble_offset); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 106 | src = (uintptr_t)&fp->kernel_subkey + |
| 107 | fp->kernel_subkey.key_offset; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 108 | dst = (uintptr_t)vb_sd + sizeof(VbSharedDataHeader); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 109 | assert(dst + fp->kernel_subkey.key_size <= |
| 110 | (uintptr_t)vboot_handoff + sizeof(*vboot_handoff)); |
| 111 | memcpy((void *)dst, (void *)src, |
| 112 | fp->kernel_subkey.key_size); |
| 113 | vb_sd->data_used += fp->kernel_subkey.key_size; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 114 | vb_sd->kernel_subkey.key_offset = |
| 115 | dst - (uintptr_t)&vb_sd->kernel_subkey; |
| 116 | vb_sd->kernel_subkey.key_size = fp->kernel_subkey.key_size; |
| 117 | vb_sd->kernel_subkey.algorithm = fp->kernel_subkey.algorithm; |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 118 | vb_sd->kernel_subkey.key_version = |
| 119 | fp->kernel_subkey.key_version; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | vb_sd->recovery_reason = vb2_sd->recovery_reason; |
| 123 | } |
| 124 | |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 125 | void vboot_fill_handoff(void) |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 126 | { |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 127 | int i; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 128 | struct vboot_handoff *vh; |
| 129 | struct vb2_shared_data *sd; |
Aaron Durbin | b6981c0 | 2015-05-15 15:57:51 -0500 | [diff] [blame] | 130 | struct region fw_main; |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 131 | struct vboot_components *fw_info; |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 132 | struct vb2_working_data *wd = vboot_get_working_data(); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 133 | |
Daisuke Nojiri | e5d1378 | 2014-12-18 11:59:06 -0800 | [diff] [blame] | 134 | sd = vboot_get_work_buffer(wd); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 135 | sd->workbuf_hash_offset = 0; |
| 136 | sd->workbuf_hash_size = 0; |
| 137 | |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 138 | printk(BIOS_INFO, "creating vboot_handoff structure\n"); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 139 | vh = cbmem_add(CBMEM_ID_VBOOT_HANDOFF, sizeof(*vh)); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 140 | if (vh == NULL) |
| 141 | /* we don't need to failover gracefully here because this |
| 142 | * shouldn't happen with the image that has passed QA. */ |
| 143 | die("failed to allocate vboot_handoff structure\n"); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 144 | |
| 145 | memset(vh, 0, sizeof(*vh)); |
| 146 | |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 147 | /* needed until we finish transtion to vboot2 for kernel verification */ |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 148 | fill_vboot_handoff(vh, sd); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 149 | |
Aaron Durbin | 3dc60c5 | 2015-05-13 14:00:28 -0500 | [diff] [blame] | 150 | /* Nothing left to do in readonly path. */ |
| 151 | if (vboot_is_readonly_path(wd)) |
| 152 | return; |
| 153 | |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 154 | vb2_get_selected_region(wd, &fw_main); |
| 155 | fw_info = vboot_locate_components(&fw_main); |
| 156 | if (fw_info == NULL) |
| 157 | die("failed to locate firmware components\n"); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 158 | |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 159 | /* these offset & size are used to load a rw boot loader */ |
| 160 | for (i = 0; i < fw_info->num_components; i++) { |
| 161 | vh->components[i].address = |
Aaron Durbin | b6981c0 | 2015-05-15 15:57:51 -0500 | [diff] [blame] | 162 | region_offset(&fw_main) + fw_info->entries[i].offset; |
Aaron Durbin | 17200ad | 2015-05-01 16:48:54 -0500 | [diff] [blame] | 163 | vh->components[i].size = fw_info->entries[i].size; |
Vadim Bendebury | 42001a7 | 2014-12-25 15:34:32 -0800 | [diff] [blame] | 164 | } |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 165 | } |