blob: 3c1a9c3444860f18b766779d631c0a69a706d847 [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.
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 Nojiri742fc8d2014-10-10 10:51:06 -070020#include <boot/coreboot_tables.h>
21#include <cbfs.h>
22#include <cbmem.h>
23#include <console/console.h>
Vadim Bendeburyc83687d2015-04-10 17:50:11 -070024#include <reset.h>
25#include <stddef.h>
26#include <string.h>
27
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070028#include "chromeos.h"
29#include "vboot_common.h"
Daisuke Nojiri24d4dae2015-02-03 14:44:55 -080030#include "vboot_handoff.h"
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -070031
32void vboot_locate_region(const char *name, struct vboot_region *region)
33{
34 region->size = find_fmap_entry(name, (void **)&region->offset_addr);
35}
36
37void *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
64int 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 */
79struct 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
95void *vboot_get_payload(int *len)
96{
97 struct vboot_handoff *vboot_handoff;
98 struct firmware_component *fwc;
99
Vadim Bendebury42001a72014-12-25 15:34:32 -0800100 if (IS_ENABLED(CONFIG_MULTIPLE_CBFS_INSTANCES))
101 return NULL; /* Let CBFS figure it out. */
102
Daisuke Nojiri742fc8d2014-10-10 10:51:06 -0700103 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 Bendeburyc83687d2015-04-10 17:50:11 -0700129
130void vboot_reboot(void)
131{
132 hard_reset();
133 die("failed to reboot");
134}