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. |
| 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 | |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 20 | #include <boot/coreboot_tables.h> |
| 21 | #include <cbfs.h> |
| 22 | #include <cbmem.h> |
| 23 | #include <console/console.h> |
Vadim Bendebury | c83687d | 2015-04-10 17:50:11 -0700 | [diff] [blame^] | 24 | #include <reset.h> |
| 25 | #include <stddef.h> |
| 26 | #include <string.h> |
| 27 | |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 28 | #include "chromeos.h" |
| 29 | #include "vboot_common.h" |
Daisuke Nojiri | 24d4dae | 2015-02-03 14:44:55 -0800 | [diff] [blame] | 30 | #include "vboot_handoff.h" |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 31 | |
| 32 | void vboot_locate_region(const char *name, struct vboot_region *region) |
| 33 | { |
| 34 | region->size = find_fmap_entry(name, (void **)®ion->offset_addr); |
| 35 | } |
| 36 | |
| 37 | void *vboot_get_region(uintptr_t offset_addr, size_t size, void *dest) |
| 38 | { |
| 39 | if (IS_ENABLED(CONFIG_SPI_FLASH_MEMORY_MAPPED)) { |
| 40 | if (dest != NULL) |
| 41 | return memcpy(dest, (void *)offset_addr, size); |
| 42 | else |
| 43 | return (void *)offset_addr; |
| 44 | } else { |
| 45 | struct cbfs_media default_media, *media = &default_media; |
| 46 | void *cache; |
| 47 | |
| 48 | init_default_cbfs_media(media); |
| 49 | media->open(media); |
| 50 | if (dest != NULL) { |
| 51 | cache = dest; |
| 52 | if (media->read(media, dest, offset_addr, size) != size) |
| 53 | cache = NULL; |
| 54 | } else { |
| 55 | cache = media->map(media, offset_addr, size); |
| 56 | if (cache == CBFS_MEDIA_INVALID_MAP_ADDRESS) |
| 57 | cache = NULL; |
| 58 | } |
| 59 | media->close(media); |
| 60 | return cache; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | int vboot_get_handoff_info(void **addr, uint32_t *size) |
| 65 | { |
| 66 | struct vboot_handoff *vboot_handoff; |
| 67 | |
| 68 | vboot_handoff = cbmem_find(CBMEM_ID_VBOOT_HANDOFF); |
| 69 | |
| 70 | if (vboot_handoff == NULL) |
| 71 | return -1; |
| 72 | |
| 73 | *addr = vboot_handoff; |
| 74 | *size = sizeof(*vboot_handoff); |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | /* This will leak a mapping of a fw region */ |
| 79 | struct vboot_components *vboot_locate_components(struct vboot_region *region) |
| 80 | { |
| 81 | size_t req_size; |
| 82 | struct vboot_components *vbc; |
| 83 | |
| 84 | req_size = sizeof(*vbc); |
| 85 | req_size += sizeof(struct vboot_component_entry) * |
| 86 | MAX_PARSED_FW_COMPONENTS; |
| 87 | |
| 88 | vbc = vboot_get_region(region->offset_addr, req_size, NULL); |
| 89 | if (vbc && vbc->num_components > MAX_PARSED_FW_COMPONENTS) |
| 90 | vbc = NULL; |
| 91 | |
| 92 | return vbc; |
| 93 | } |
| 94 | |
| 95 | void *vboot_get_payload(int *len) |
| 96 | { |
| 97 | struct vboot_handoff *vboot_handoff; |
| 98 | struct firmware_component *fwc; |
| 99 | |
Vadim Bendebury | 42001a7 | 2014-12-25 15:34:32 -0800 | [diff] [blame] | 100 | if (IS_ENABLED(CONFIG_MULTIPLE_CBFS_INSTANCES)) |
| 101 | return NULL; /* Let CBFS figure it out. */ |
| 102 | |
Daisuke Nojiri | 742fc8d | 2014-10-10 10:51:06 -0700 | [diff] [blame] | 103 | vboot_handoff = cbmem_find(CBMEM_ID_VBOOT_HANDOFF); |
| 104 | |
| 105 | if (vboot_handoff == NULL) |
| 106 | return NULL; |
| 107 | |
| 108 | if (CONFIG_VBOOT_BOOT_LOADER_INDEX >= MAX_PARSED_FW_COMPONENTS) { |
| 109 | printk(BIOS_ERR, "Invalid boot loader index: %d\n", |
| 110 | CONFIG_VBOOT_BOOT_LOADER_INDEX); |
| 111 | return NULL; |
| 112 | } |
| 113 | |
| 114 | fwc = &vboot_handoff->components[CONFIG_VBOOT_BOOT_LOADER_INDEX]; |
| 115 | |
| 116 | /* If payload size is zero fall back to cbfs path. */ |
| 117 | if (fwc->size == 0) |
| 118 | return NULL; |
| 119 | |
| 120 | if (len != NULL) |
| 121 | *len = fwc->size; |
| 122 | |
| 123 | printk(BIOS_DEBUG, "Booting 0x%x byte verified payload at 0x%08x.\n", |
| 124 | fwc->size, fwc->address); |
| 125 | |
| 126 | /* This will leak a mapping. */ |
| 127 | return vboot_get_region(fwc->address, fwc->size, NULL); |
| 128 | } |
Vadim Bendebury | c83687d | 2015-04-10 17:50:11 -0700 | [diff] [blame^] | 129 | |
| 130 | void vboot_reboot(void) |
| 131 | { |
| 132 | hard_reset(); |
| 133 | die("failed to reboot"); |
| 134 | } |