blob: 56de0ef6a4c65524d3b493e5f95f7d759a9e54aa [file] [log] [blame]
Andrey Petrov465fc132016-02-25 14:16:33 -08001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy47bd2d92016-07-24 18:12:16 -07004 * Copyright (C) 2015-2016 Intel Corp.
Andrey Petrov465fc132016-02-25 14:16:33 -08005 * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.)
6 * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080014#include <antirollback.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080015#include <arch/io.h>
16#include <arch/cpu.h>
Aaron Durbinb4302502016-07-17 17:04:37 -050017#include <arch/symbols.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050018#include <cbfs.h>
Aaron Durbin27928682016-07-15 22:32:28 -050019#include <cbmem.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080020#include <console/console.h>
Furquan Shaikh5aea5882016-07-30 18:10:05 -070021#include <elog.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080022#include <fsp/api.h>
23#include <fsp/util.h>
24#include <memrange.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050025#include <program_loading.h>
Aaron Durbinb4302502016-07-17 17:04:37 -050026#include <reset.h>
27#include <romstage_handoff.h>
28#include <soc/intel/common/mrc_cache.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080029#include <string.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050030#include <symbols.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080031#include <timestamp.h>
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080032#include <tpm_lite/tlcl.h>
Furquan Shaikh0325dc62016-07-25 13:02:36 -070033#include <vboot/vboot_common.h>
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080034#include <vb2_api.h>
35
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080036static void mrc_cache_update_tpm_hash(const uint8_t *data, size_t size)
37{
38 uint8_t data_hash[VB2_SHA256_DIGEST_SIZE];
39 static const uint8_t dead_hash[VB2_SHA256_DIGEST_SIZE] = {
40 0xba, 0xad, 0xda, 0x1a, /* BAADDA1A */
41 0xde, 0xad, 0xde, 0xad, /* DEADDEAD */
42 0xde, 0xad, 0xda, 0x1a, /* DEADDA1A */
43 0xba, 0xad, 0xba, 0xad, /* BAADBAAD */
44 0xba, 0xad, 0xda, 0x1a, /* BAADDA1A */
45 0xde, 0xad, 0xde, 0xad, /* DEADDEAD */
46 0xde, 0xad, 0xda, 0x1a, /* DEADDA1A */
47 0xba, 0xad, 0xba, 0xad, /* BAADBAAD */
48 };
49 const uint8_t *hash_ptr = data_hash;
50
51 /* We do not store normal mode data hash in TPM. */
52 if (!vboot_recovery_mode_enabled())
53 return;
54
55 /* Bail out early if no mrc hash space is supported in TPM. */
56 if (!IS_ENABLED(CONFIG_FSP2_0_USES_TPM_MRC_HASH))
57 return;
58
59 /* Initialize TPM driver. */
Furquan Shaikh8b5d04e2016-11-10 09:49:05 -080060 if (tlcl_lib_init() != VB2_SUCCESS) {
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080061 printk(BIOS_ERR, "MRC: TPM driver initialization failed.\n");
62 return;
63 }
64
65 /* Calculate hash of data generated by MRC. */
66 if (vb2_digest_buffer(data, size, VB2_HASH_SHA256, data_hash,
67 sizeof(data_hash))) {
68 printk(BIOS_ERR, "MRC: SHA-256 calculation failed for data. "
69 "Not updating TPM hash space.\n");
70 /*
71 * Since data is being updated in recovery cache, the hash
72 * currently stored in TPM recovery hash space is no longer
73 * valid. If we are not able to calculate hash of the data being
74 * updated, reset all the bits in TPM recovery hash space to
75 * pre-defined hash pattern.
76 */
77 hash_ptr = dead_hash;
78 }
79
80 /* Write hash of data to TPM space. */
81 if (antirollback_write_space_rec_hash(hash_ptr, VB2_SHA256_DIGEST_SIZE)
82 != TPM_SUCCESS) {
83 printk(BIOS_ERR, "MRC: Could not save hash to TPM.\n");
84 return;
85 }
86
87 printk(BIOS_INFO, "MRC: TPM MRC hash updated successfully.\n");
88}
Andrey Petrov465fc132016-02-25 14:16:33 -080089
Aaron Durbinf0ec8242016-07-18 11:24:36 -050090static void save_memory_training_data(bool s3wake, uint32_t fsp_version)
Aaron Durbinb4302502016-07-17 17:04:37 -050091{
Aaron Durbinb4302502016-07-17 17:04:37 -050092 size_t mrc_data_size;
93 const void *mrc_data;
Aaron Durbinf0ec8242016-07-18 11:24:36 -050094
95 if (!IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS) || s3wake)
96 return;
97
98 mrc_data = fsp_find_nv_storage_data(&mrc_data_size);
99 if (!mrc_data) {
100 printk(BIOS_ERR, "Couldn't find memory training data HOB.\n");
101 return;
102 }
103
104 /*
105 * Save MRC Data to CBMEM. By always saving the data this forces
106 * a retrain after a trip through Chrome OS recovery path. The
107 * code which saves the data to flash doesn't write if the latest
108 * training data matches this one.
109 */
110 if (mrc_cache_stash_data_with_version(mrc_data, mrc_data_size,
111 fsp_version) < 0)
112 printk(BIOS_ERR, "Failed to stash MRC data\n");
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800113
114 mrc_cache_update_tpm_hash(mrc_data, mrc_data_size);
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500115}
116
Lee Leahy9671faa2016-07-24 18:18:52 -0700117static void do_fsp_post_memory_init(bool s3wake, uint32_t fsp_version)
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500118{
119 struct range_entry fsp_mem;
Aaron Durbinb4302502016-07-17 17:04:37 -0500120 struct romstage_handoff *handoff;
121
Lee Leahy52d0c682016-08-01 15:47:42 -0700122 if (fsp_find_reserved_memory(&fsp_mem))
123 die("Failed to find FSP_RESERVED_MEMORY_RESOURCE_HOB!\n");
Aaron Durbinb4302502016-07-17 17:04:37 -0500124
125 /* initialize cbmem by adding FSP reserved memory first thing */
126 if (!s3wake) {
127 cbmem_initialize_empty_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
128 range_entry_size(&fsp_mem));
129 } else if (cbmem_initialize_id_size(CBMEM_ID_FSP_RESERVED_MEMORY,
130 range_entry_size(&fsp_mem))) {
131 if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700132 printk(BIOS_ERR,
Lee Leahyac3b0a62016-07-27 07:40:25 -0700133 "Failed to recover CBMEM in S3 resume.\n");
Aaron Durbinb4302502016-07-17 17:04:37 -0500134 /* Failed S3 resume, reset to come up cleanly */
135 hard_reset();
136 }
137 }
138
139 /* make sure FSP memory is reserved in cbmem */
140 if (range_entry_base(&fsp_mem) !=
141 (uintptr_t)cbmem_find(CBMEM_ID_FSP_RESERVED_MEMORY))
Lee Leahy9671faa2016-07-24 18:18:52 -0700142 die("Failed to accommodate FSP reserved memory request!\n");
Aaron Durbinb4302502016-07-17 17:04:37 -0500143
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500144 save_memory_training_data(s3wake, fsp_version);
Aaron Durbinb4302502016-07-17 17:04:37 -0500145
146 /* Create romstage handof information */
147 handoff = romstage_handoff_find_or_add();
148 if (handoff != NULL)
149 handoff->s3_resume = s3wake;
150 else
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700151 printk(BIOS_SPEW, "Romstage handoff structure not added!\n");
Aaron Durbinb4302502016-07-17 17:04:37 -0500152}
153
Furquan Shaikhcab1c012016-11-05 23:57:02 -0700154static const char *mrc_cache_get_region_name(void)
155{
156 /* In normal mode, always use DEFAULT_MRC_CACHE */
157 if (!vboot_recovery_mode_enabled())
158 return DEFAULT_MRC_CACHE;
159
160 /*
161 * In recovery mode, force retraining by returning NULL if:
162 * 1. Recovery cache is not supported, or
163 * 2. Memory retrain switch is set.
164 */
165 if (!IS_ENABLED(CONFIG_HAS_RECOVERY_MRC_CACHE) ||
166 vboot_recovery_mode_memory_retrain())
167 return NULL;
168
169 return RECOVERY_MRC_CACHE;
170}
171
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800172static int mrc_cache_verify_tpm_hash(const uint8_t *data, size_t size)
173{
174 uint8_t data_hash[VB2_SHA256_DIGEST_SIZE];
175 uint8_t tpm_hash[VB2_SHA256_DIGEST_SIZE];
176
177 /* We do not store normal mode data hash in TPM. */
178 if (!vboot_recovery_mode_enabled())
179 return 1;
180
181 if (!IS_ENABLED(CONFIG_FSP2_0_USES_TPM_MRC_HASH))
182 return 1;
183
184 /* Calculate hash of data read from RECOVERY_MRC_CACHE. */
185 if (vb2_digest_buffer(data, size, VB2_HASH_SHA256, data_hash,
186 sizeof(data_hash))) {
187 printk(BIOS_ERR, "MRC: SHA-256 calculation failed for data.\n");
188 return 0;
189 }
190
191 /* Initialize TPM driver. */
Furquan Shaikh8b5d04e2016-11-10 09:49:05 -0800192 if (tlcl_lib_init() != VB2_SUCCESS) {
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800193 printk(BIOS_ERR, "MRC: TPM driver initialization failed.\n");
194 return 0;
195 }
196
197 /* Read hash of MRC data saved in TPM. */
198 if (antirollback_read_space_rec_hash(tpm_hash, sizeof(tpm_hash))
199 != TPM_SUCCESS) {
200 printk(BIOS_ERR, "MRC: Could not read hash from TPM.\n");
201 return 0;
202 }
203
204 if (memcmp(tpm_hash, data_hash, sizeof(tpm_hash))) {
205 printk(BIOS_ERR, "MRC: Hash comparison failed.\n");
206 return 0;
207 }
208
209 printk(BIOS_INFO, "MRC: Hash comparison successful. "
210 "Using data from RECOVERY_MRC_CACHE\n");
211 return 1;
212}
213
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700214static void fsp_fill_mrc_cache(FSPM_ARCH_UPD *arch_upd, bool s3wake,
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500215 uint32_t fsp_version)
Aaron Durbinb4302502016-07-17 17:04:37 -0500216{
217 const struct mrc_saved_data *mrc_cache;
Furquan Shaikhcab1c012016-11-05 23:57:02 -0700218 const char *name;
Aaron Durbinb4302502016-07-17 17:04:37 -0500219
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500220 arch_upd->NvsBufferPtr = NULL;
221
222 if (!IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS))
223 return;
224
Furquan Shaikhcab1c012016-11-05 23:57:02 -0700225 name = mrc_cache_get_region_name();
Aaron Durbin98ea6362016-07-18 11:31:53 -0500226
Furquan Shaikhcab1c012016-11-05 23:57:02 -0700227 if (mrc_cache_get_current_from_region(&mrc_cache, fsp_version, name))
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500228 return;
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500229
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800230 if (!mrc_cache_verify_tpm_hash(mrc_cache->data, mrc_cache->size))
231 return;
232
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500233 /* MRC cache found */
234 arch_upd->NvsBufferPtr = (void *)mrc_cache->data;
235 arch_upd->BootMode = s3wake ?
236 FSP_BOOT_ON_S3_RESUME:
237 FSP_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700238 printk(BIOS_SPEW, "MRC cache found, size %x bootmode:%d\n",
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500239 mrc_cache->size, arch_upd->BootMode);
240}
241
Aaron Durbin02e504c2016-07-18 11:53:10 -0500242static enum cb_err check_region_overlap(const struct memranges *ranges,
243 const char *description,
244 uintptr_t begin, uintptr_t end)
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500245{
Aaron Durbin02e504c2016-07-18 11:53:10 -0500246 const struct range_entry *r;
247
248 memranges_each_entry(r, ranges) {
249 if (end <= range_entry_base(r))
250 continue;
251 if (begin >= range_entry_end(r))
252 continue;
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700253 printk(BIOS_CRIT, "'%s' overlaps currently running program: "
Aaron Durbin02e504c2016-07-18 11:53:10 -0500254 "[%p, %p)\n", description, (void *)begin, (void *)end);
255 return CB_ERR;
256 }
257
258 return CB_SUCCESS;
259}
260
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700261static enum cb_err fsp_fill_common_arch_params(FSPM_ARCH_UPD *arch_upd,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500262 bool s3wake, uint32_t fsp_version,
263 const struct memranges *memmap)
264{
265 uintptr_t stack_begin;
266 uintptr_t stack_end;
267
Aaron Durbinb4302502016-07-17 17:04:37 -0500268 /*
269 * FSPM_UPD passed here is populated with default values provided by
270 * the blob itself. We let FSPM use top of CAR region of the size it
271 * requests.
Aaron Durbinb4302502016-07-17 17:04:37 -0500272 */
Aaron Durbin02e504c2016-07-18 11:53:10 -0500273 stack_end = (uintptr_t)_car_region_end;
274 stack_begin = stack_end - arch_upd->StackSize;
275
276 if (check_region_overlap(memmap, "FSPM stack", stack_begin,
277 stack_end) != CB_SUCCESS)
278 return CB_ERR;
279
280 arch_upd->StackBase = (void *)stack_begin;
Aaron Durbinb4302502016-07-17 17:04:37 -0500281
282 arch_upd->BootMode = FSP_BOOT_WITH_FULL_CONFIGURATION;
283
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500284 fsp_fill_mrc_cache(arch_upd, s3wake, fsp_version);
Aaron Durbin02e504c2016-07-18 11:53:10 -0500285
286 return CB_SUCCESS;
Aaron Durbinb4302502016-07-17 17:04:37 -0500287}
288
Lee Leahy9671faa2016-07-24 18:18:52 -0700289static void do_fsp_memory_init(struct fsp_header *hdr, bool s3wake,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500290 const struct memranges *memmap)
Andrey Petrov465fc132016-02-25 14:16:33 -0800291{
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700292 uint32_t status;
Andrey Petrov465fc132016-02-25 14:16:33 -0800293 fsp_memory_init_fn fsp_raminit;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700294 FSPM_UPD fspm_upd, *upd;
295 FSPM_ARCH_UPD *arch_upd;
Andrey Petrov465fc132016-02-25 14:16:33 -0800296
297 post_code(0x34);
298
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700299 upd = (FSPM_UPD *)(hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov465fc132016-02-25 14:16:33 -0800300
301 if (upd->FspUpdHeader.Signature != FSPM_UPD_SIGNATURE) {
Lee Leahy9671faa2016-07-24 18:18:52 -0700302 die("Invalid FSPM signature!\n");
Andrey Petrov465fc132016-02-25 14:16:33 -0800303 }
304
305 /* Copy the default values from the UPD area */
306 memcpy(&fspm_upd, upd, sizeof(fspm_upd));
307
Aaron Durbin02e504c2016-07-18 11:53:10 -0500308 arch_upd = &fspm_upd.FspmArchUpd;
309
Aaron Durbin27928682016-07-15 22:32:28 -0500310 /* Reserve enough memory under TOLUD to save CBMEM header */
Aaron Durbin02e504c2016-07-18 11:53:10 -0500311 arch_upd->BootLoaderTolumSize = cbmem_overhead_size();
Aaron Durbin27928682016-07-15 22:32:28 -0500312
Aaron Durbinb4302502016-07-17 17:04:37 -0500313 /* Fill common settings on behalf of chipset. */
Aaron Durbin02e504c2016-07-18 11:53:10 -0500314 if (fsp_fill_common_arch_params(arch_upd, s3wake, hdr->fsp_revision,
315 memmap) != CB_SUCCESS)
Lee Leahy9671faa2016-07-24 18:18:52 -0700316 die("FSPM_ARCH_UPD not found!\n");
Aaron Durbinb4302502016-07-17 17:04:37 -0500317
Andrey Petrov465fc132016-02-25 14:16:33 -0800318 /* Give SoC and mainboard a chance to update the UPD */
Andrey Petrovf796c6e2016-11-18 14:57:51 -0800319 platform_fsp_memory_init_params_cb(&fspm_upd, hdr->fsp_revision);
Andrey Petrov465fc132016-02-25 14:16:33 -0800320
321 /* Call FspMemoryInit */
322 fsp_raminit = (void *)(hdr->image_base + hdr->memory_init_entry_offset);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700323 fsp_debug_before_memory_init(fsp_raminit, upd, &fspm_upd);
Andrey Petrov465fc132016-02-25 14:16:33 -0800324
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -0700325 post_code(POST_FSP_MEMORY_INIT);
Andrey Petrov465fc132016-02-25 14:16:33 -0800326 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700327 status = fsp_raminit(&fspm_upd, fsp_get_hob_list_ptr());
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -0700328 post_code(POST_FSP_MEMORY_INIT);
Andrey Petrov465fc132016-02-25 14:16:33 -0800329 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
330
Lee Leahyac3b0a62016-07-27 07:40:25 -0700331 fsp_debug_after_memory_init(status);
Andrey Petrov465fc132016-02-25 14:16:33 -0800332
Lee Leahy9671faa2016-07-24 18:18:52 -0700333 /* Handle any errors returned by FspMemoryInit */
Aaron Durbinf41f2aa2016-07-18 12:03:58 -0500334 fsp_handle_reset(status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700335 if (status != FSP_SUCCESS) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700336 printk(BIOS_CRIT, "FspMemoryInit returned 0x%08x\n", status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700337 die("FspMemoryInit returned an error!\n");
338 }
Aaron Durbinf41f2aa2016-07-18 12:03:58 -0500339
Lee Leahy9671faa2016-07-24 18:18:52 -0700340 do_fsp_post_memory_init(s3wake, hdr->fsp_revision);
Andrey Petrov465fc132016-02-25 14:16:33 -0800341}
342
Aaron Durbind04639b2016-07-17 23:23:59 -0500343/* Load the binary into the memory specified by the info header. */
344static enum cb_err load_fspm_mem(struct fsp_header *hdr,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500345 const struct region_device *rdev,
346 const struct memranges *memmap)
Aaron Durbind04639b2016-07-17 23:23:59 -0500347{
Aaron Durbind04639b2016-07-17 23:23:59 -0500348 uintptr_t fspm_begin;
349 uintptr_t fspm_end;
350
351 if (fsp_validate_component(hdr, rdev) != CB_SUCCESS)
352 return CB_ERR;
353
354 fspm_begin = hdr->image_base;
355 fspm_end = fspm_begin + hdr->image_size;
356
Aaron Durbin02e504c2016-07-18 11:53:10 -0500357 if (check_region_overlap(memmap, "FSPM", fspm_begin, fspm_end) !=
358 CB_SUCCESS)
Aaron Durbind04639b2016-07-17 23:23:59 -0500359 return CB_ERR;
Aaron Durbind04639b2016-07-17 23:23:59 -0500360
361 /* Load binary into memory at provided address. */
362 if (rdev_readat(rdev, (void *)fspm_begin, 0, fspm_end - fspm_begin) < 0)
363 return CB_ERR;
364
365 return CB_SUCCESS;
366}
367
368/* Handle the case when FSPM is running XIP. */
369static enum cb_err load_fspm_xip(struct fsp_header *hdr,
370 const struct region_device *rdev)
371{
372 void *base;
373
374 if (fsp_validate_component(hdr, rdev) != CB_SUCCESS)
375 return CB_ERR;
376
377 base = rdev_mmap_full(rdev);
378 if ((uintptr_t)base != hdr->image_base) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700379 printk(BIOS_CRIT, "FSPM XIP base does not match: %p vs %p\n",
Aaron Durbind04639b2016-07-17 23:23:59 -0500380 (void *)(uintptr_t)hdr->image_base, base);
381 return CB_ERR;
382 }
383
384 /*
385 * Since the component is XIP it's already in the address space. Thus,
386 * there's no need to rdev_munmap().
387 */
388 return CB_SUCCESS;
389}
390
Lee Leahy9671faa2016-07-24 18:18:52 -0700391void fsp_memory_init(bool s3wake)
Andrey Petrov465fc132016-02-25 14:16:33 -0800392{
393 struct fsp_header hdr;
Aaron Durbind04639b2016-07-17 23:23:59 -0500394 enum cb_err status;
395 struct cbfsf file_desc;
396 struct region_device file_data;
397 const char *name = CONFIG_FSP_M_CBFS;
Aaron Durbin02e504c2016-07-18 11:53:10 -0500398 struct memranges memmap;
399 struct range_entry freeranges[2];
Andrey Petrov465fc132016-02-25 14:16:33 -0800400
Furquan Shaikh5aea5882016-07-30 18:10:05 -0700401 if (IS_ENABLED(CONFIG_ELOG_BOOT_COUNT) && !s3wake)
402 boot_count_increment();
403
Aaron Durbind04639b2016-07-17 23:23:59 -0500404 if (cbfs_boot_locate(&file_desc, name, NULL)) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700405 printk(BIOS_CRIT, "Could not locate %s in CBFS\n", name);
Lee Leahy9671faa2016-07-24 18:18:52 -0700406 die("FSPM not available!\n");
Aaron Durbind04639b2016-07-17 23:23:59 -0500407 }
408
409 cbfs_file_data(&file_data, &file_desc);
410
Aaron Durbin02e504c2016-07-18 11:53:10 -0500411 /* Build up memory map of romstage address space including CAR. */
412 memranges_init_empty(&memmap, &freeranges[0], ARRAY_SIZE(freeranges));
413 memranges_insert(&memmap, (uintptr_t)_car_region_start,
414 _car_relocatable_data_end - _car_region_start, 0);
415 memranges_insert(&memmap, (uintptr_t)_program, _program_size, 0);
416
Lee Leahy27cd96a2016-07-21 11:16:39 -0700417 if (!IS_ENABLED(CONFIG_FSP_M_XIP))
Aaron Durbin02e504c2016-07-18 11:53:10 -0500418 status = load_fspm_mem(&hdr, &file_data, &memmap);
Aaron Durbind04639b2016-07-17 23:23:59 -0500419 else
420 status = load_fspm_xip(&hdr, &file_data);
421
422 if (status != CB_SUCCESS) {
Lee Leahy9671faa2016-07-24 18:18:52 -0700423 die("Loading FSPM failed!\n");
Aaron Durbind04639b2016-07-17 23:23:59 -0500424 }
425
426 /* Signal that FSP component has been loaded. */
427 prog_segment_loaded(hdr.image_base, hdr.image_size, SEG_FINAL);
Andrey Petrov465fc132016-02-25 14:16:33 -0800428
Lee Leahy9671faa2016-07-24 18:18:52 -0700429 do_fsp_memory_init(&hdr, s3wake, &memmap);
Andrey Petrov465fc132016-02-25 14:16:33 -0800430}