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 |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <2recovery_reasons.h> |
| 21 | #include <2struct.h> |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 22 | #include <arch/stages.h> |
| 23 | #include <assert.h> |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 24 | #include <stdint.h> |
| 25 | #include <stddef.h> |
| 26 | #include <string.h> |
| 27 | #include <cbfs.h> |
| 28 | #include <cbmem.h> |
| 29 | #include <console/console.h> |
| 30 | #include <console/vtxprintf.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <timestamp.h> |
| 33 | #include "chromeos.h" |
| 34 | #include "fmap.h" |
| 35 | #include "vboot_handoff.h" |
| 36 | #include <vboot_struct.h> |
| 37 | |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 38 | static void *load_ramstage(struct vboot_handoff *vboot_handoff, |
| 39 | struct vboot_region *fw_main) |
| 40 | { |
| 41 | struct vboot_components *fw_info; |
| 42 | int i; |
| 43 | |
| 44 | fw_info = vboot_locate_components(fw_main); |
| 45 | if (fw_info == NULL) |
| 46 | die("failed to locate firmware components\n"); |
| 47 | |
| 48 | /* these offset & size are used to load a rw boot loader */ |
| 49 | for (i = 0; i < fw_info->num_components; i++) { |
| 50 | vboot_handoff->components[i].address = |
| 51 | fw_main->offset_addr + fw_info->entries[i].offset; |
| 52 | vboot_handoff->components[i].size = fw_info->entries[i].size; |
| 53 | } |
| 54 | |
| 55 | return vboot_load_stage(CONFIG_VBOOT_RAMSTAGE_INDEX, fw_main, fw_info); |
| 56 | } |
| 57 | |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Sets vboot_handoff based on the information in vb2_shared_data |
| 60 | * |
| 61 | * TODO: Read wp switch to set VBSD_BOOT_FIRMWARE_WP_ENABLED |
| 62 | */ |
| 63 | static void fill_vboot_handoff(struct vboot_handoff *vboot_handoff, |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 64 | struct vb2_shared_data *vb2_sd) |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 65 | { |
| 66 | VbSharedDataHeader *vb_sd = |
| 67 | (VbSharedDataHeader *)vboot_handoff->shared_data; |
| 68 | uint32_t *oflags = &vboot_handoff->init_params.out_flags; |
| 69 | |
| 70 | vb_sd->flags |= VBSD_BOOT_FIRMWARE_VBOOT2; |
| 71 | |
| 72 | vboot_handoff->selected_firmware = vb2_sd->fw_slot; |
| 73 | |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 74 | vb_sd->firmware_index = vb2_sd->fw_slot; |
| 75 | |
| 76 | vb_sd->magic = VB_SHARED_DATA_MAGIC; |
| 77 | vb_sd->struct_version = VB_SHARED_DATA_VERSION; |
| 78 | vb_sd->struct_size = sizeof(VbSharedDataHeader); |
| 79 | vb_sd->data_size = VB_SHARED_DATA_MIN_SIZE; |
| 80 | vb_sd->data_used = sizeof(VbSharedDataHeader); |
| 81 | |
| 82 | if (vb2_sd->recovery_reason) { |
| 83 | vb_sd->firmware_index = 0xFF; |
| 84 | if (vb2_sd->recovery_reason == VB2_RECOVERY_RO_MANUAL) |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 85 | vb_sd->flags |= VBSD_BOOT_REC_SWITCH_ON; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 86 | *oflags |= VB_INIT_OUT_ENABLE_RECOVERY; |
| 87 | *oflags |= VB_INIT_OUT_CLEAR_RAM; |
| 88 | *oflags |= VB_INIT_OUT_ENABLE_DISPLAY; |
| 89 | *oflags |= VB_INIT_OUT_ENABLE_USB_STORAGE; |
| 90 | } |
| 91 | if (vb2_sd->flags & VB2_SD_DEV_MODE_ENABLED) { |
| 92 | *oflags |= VB_INIT_OUT_ENABLE_DEVELOPER; |
| 93 | *oflags |= VB_INIT_OUT_CLEAR_RAM; |
| 94 | *oflags |= VB_INIT_OUT_ENABLE_DISPLAY; |
| 95 | *oflags |= VB_INIT_OUT_ENABLE_USB_STORAGE; |
| 96 | vb_sd->flags |= VBSD_BOOT_DEV_SWITCH_ON; |
| 97 | vb_sd->flags |= VBSD_LF_DEV_SWITCH_ON; |
| 98 | } |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 99 | /* TODO: Set these in depthcharge */ |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 100 | if (CONFIG_VIRTUAL_DEV_SWITCH) |
| 101 | vb_sd->flags |= VBSD_HONOR_VIRT_DEV_SWITCH; |
| 102 | if (CONFIG_EC_SOFTWARE_SYNC) { |
| 103 | vb_sd->flags |= VBSD_EC_SOFTWARE_SYNC; |
| 104 | vb_sd->flags |= VBSD_BOOT_REC_SWITCH_VIRTUAL; |
| 105 | } |
| 106 | /* In vboot1, VBSD_FWB_TRIED is |
| 107 | * set only if B is booted as explicitly requested. Therefore, if B is |
| 108 | * booted because A was found bad, the flag should not be set. It's |
| 109 | * better not to touch it if we can only ambiguously control it. */ |
| 110 | /* if (vb2_sd->fw_slot) |
| 111 | vb_sd->flags |= VBSD_FWB_TRIED; */ |
| 112 | |
| 113 | /* copy kernel subkey if it's found */ |
| 114 | if (vb2_sd->workbuf_preamble_size) { |
| 115 | struct vb2_fw_preamble *fp; |
| 116 | uintptr_t dst, src; |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 117 | printk(BIOS_INFO, "Copying FW preamble\n"); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 118 | fp = (struct vb2_fw_preamble *)( (uintptr_t)vb2_sd + |
| 119 | vb2_sd->workbuf_preamble_offset); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 120 | src = (uintptr_t)&fp->kernel_subkey + |
| 121 | fp->kernel_subkey.key_offset; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 122 | dst = (uintptr_t)vb_sd + sizeof(VbSharedDataHeader); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 123 | assert(dst + fp->kernel_subkey.key_size <= |
| 124 | (uintptr_t)vboot_handoff + sizeof(*vboot_handoff)); |
| 125 | memcpy((void *)dst, (void *)src, |
| 126 | fp->kernel_subkey.key_size); |
| 127 | vb_sd->data_used += fp->kernel_subkey.key_size; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 128 | vb_sd->kernel_subkey.key_offset = |
| 129 | dst - (uintptr_t)&vb_sd->kernel_subkey; |
| 130 | vb_sd->kernel_subkey.key_size = fp->kernel_subkey.key_size; |
| 131 | vb_sd->kernel_subkey.algorithm = fp->kernel_subkey.algorithm; |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 132 | vb_sd->kernel_subkey.key_version = |
| 133 | fp->kernel_subkey.key_version; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | vb_sd->recovery_reason = vb2_sd->recovery_reason; |
| 137 | } |
| 138 | |
| 139 | /** |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 140 | * Load ramstage and return the entry point |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 141 | */ |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 142 | void *vboot_load_ramstage(void) |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 143 | { |
| 144 | struct vboot_handoff *vh; |
| 145 | struct vb2_shared_data *sd; |
Daisuke Nojiri | 1bbac3f | 2014-09-12 09:59:46 -0700 | [diff] [blame^] | 146 | struct vboot_region fw_main; |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 147 | struct vb2_working_data *wd = vboot_get_working_data(); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 148 | |
Daisuke Nojiri | 1bbac3f | 2014-09-12 09:59:46 -0700 | [diff] [blame^] | 149 | sd = (struct vb2_shared_data *)(uintptr_t)wd->buffer; |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 150 | sd->workbuf_hash_offset = 0; |
| 151 | sd->workbuf_hash_size = 0; |
| 152 | |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 153 | printk(BIOS_INFO, "creating vboot_handoff structure\n"); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 154 | vh = cbmem_add(CBMEM_ID_VBOOT_HANDOFF, sizeof(*vh)); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 155 | if (vh == NULL) |
| 156 | /* we don't need to failover gracefully here because this |
| 157 | * shouldn't happen with the image that has passed QA. */ |
| 158 | die("failed to allocate vboot_handoff structure\n"); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 159 | |
| 160 | memset(vh, 0, sizeof(*vh)); |
| 161 | |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 162 | /* needed until we finish transtion to vboot2 for kernel verification */ |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 163 | fill_vboot_handoff(vh, sd); |
Daisuke Nojiri | efddcfb | 2014-09-04 09:55:34 -0700 | [diff] [blame] | 164 | |
| 165 | if (vboot_is_readonly_path(wd)) |
| 166 | /* we're on recovery path. continue to ro-ramstage. */ |
| 167 | return NULL; |
| 168 | |
| 169 | printk(BIOS_INFO, |
| 170 | "loading ramstage from Slot %c\n", sd->fw_slot ? 'B' : 'A'); |
Daisuke Nojiri | 1bbac3f | 2014-09-12 09:59:46 -0700 | [diff] [blame^] | 171 | vb2_get_selected_region(wd, &fw_main); |
| 172 | |
| 173 | return load_ramstage(vh, &fw_main); |
Daisuke Nojiri | 79cac09 | 2014-06-30 08:51:39 -0700 | [diff] [blame] | 174 | } |