blob: e9386d6f8d912debcf01a2800a18fef40d552683 [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 Durbin31be2c92016-12-03 22:08:20 -060018#include <assert.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050019#include <cbfs.h>
Aaron Durbin27928682016-07-15 22:32:28 -050020#include <cbmem.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080021#include <console/console.h>
Furquan Shaikh5aea5882016-07-30 18:10:05 -070022#include <elog.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080023#include <fsp/api.h>
24#include <fsp/util.h>
25#include <memrange.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050026#include <program_loading.h>
Aaron Durbinb4302502016-07-17 17:04:37 -050027#include <reset.h>
28#include <romstage_handoff.h>
29#include <soc/intel/common/mrc_cache.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080030#include <string.h>
Aaron Durbind04639b2016-07-17 23:23:59 -050031#include <symbols.h>
Andrey Petrov465fc132016-02-25 14:16:33 -080032#include <timestamp.h>
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080033#include <tpm_lite/tlcl.h>
Furquan Shaikh0325dc62016-07-25 13:02:36 -070034#include <vboot/vboot_common.h>
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080035#include <vb2_api.h>
36
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080037static void mrc_cache_update_tpm_hash(const uint8_t *data, size_t size)
38{
39 uint8_t data_hash[VB2_SHA256_DIGEST_SIZE];
40 static const uint8_t dead_hash[VB2_SHA256_DIGEST_SIZE] = {
41 0xba, 0xad, 0xda, 0x1a, /* BAADDA1A */
42 0xde, 0xad, 0xde, 0xad, /* DEADDEAD */
43 0xde, 0xad, 0xda, 0x1a, /* DEADDA1A */
44 0xba, 0xad, 0xba, 0xad, /* BAADBAAD */
45 0xba, 0xad, 0xda, 0x1a, /* BAADDA1A */
46 0xde, 0xad, 0xde, 0xad, /* DEADDEAD */
47 0xde, 0xad, 0xda, 0x1a, /* DEADDA1A */
48 0xba, 0xad, 0xba, 0xad, /* BAADBAAD */
49 };
50 const uint8_t *hash_ptr = data_hash;
51
52 /* We do not store normal mode data hash in TPM. */
53 if (!vboot_recovery_mode_enabled())
54 return;
55
56 /* Bail out early if no mrc hash space is supported in TPM. */
57 if (!IS_ENABLED(CONFIG_FSP2_0_USES_TPM_MRC_HASH))
58 return;
59
60 /* Initialize TPM driver. */
Furquan Shaikh8b5d04e2016-11-10 09:49:05 -080061 if (tlcl_lib_init() != VB2_SUCCESS) {
Furquan Shaikh2db5bac2016-11-07 23:57:48 -080062 printk(BIOS_ERR, "MRC: TPM driver initialization failed.\n");
63 return;
64 }
65
66 /* Calculate hash of data generated by MRC. */
67 if (vb2_digest_buffer(data, size, VB2_HASH_SHA256, data_hash,
68 sizeof(data_hash))) {
69 printk(BIOS_ERR, "MRC: SHA-256 calculation failed for data. "
70 "Not updating TPM hash space.\n");
71 /*
72 * Since data is being updated in recovery cache, the hash
73 * currently stored in TPM recovery hash space is no longer
74 * valid. If we are not able to calculate hash of the data being
75 * updated, reset all the bits in TPM recovery hash space to
76 * pre-defined hash pattern.
77 */
78 hash_ptr = dead_hash;
79 }
80
81 /* Write hash of data to TPM space. */
82 if (antirollback_write_space_rec_hash(hash_ptr, VB2_SHA256_DIGEST_SIZE)
83 != TPM_SUCCESS) {
84 printk(BIOS_ERR, "MRC: Could not save hash to TPM.\n");
85 return;
86 }
87
88 printk(BIOS_INFO, "MRC: TPM MRC hash updated successfully.\n");
89}
Andrey Petrov465fc132016-02-25 14:16:33 -080090
Aaron Durbinf0ec8242016-07-18 11:24:36 -050091static void save_memory_training_data(bool s3wake, uint32_t fsp_version)
Aaron Durbinb4302502016-07-17 17:04:37 -050092{
Aaron Durbinb4302502016-07-17 17:04:37 -050093 size_t mrc_data_size;
94 const void *mrc_data;
Aaron Durbinf0ec8242016-07-18 11:24:36 -050095
96 if (!IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS) || s3wake)
97 return;
98
99 mrc_data = fsp_find_nv_storage_data(&mrc_data_size);
100 if (!mrc_data) {
101 printk(BIOS_ERR, "Couldn't find memory training data HOB.\n");
102 return;
103 }
104
105 /*
106 * Save MRC Data to CBMEM. By always saving the data this forces
107 * a retrain after a trip through Chrome OS recovery path. The
108 * code which saves the data to flash doesn't write if the latest
109 * training data matches this one.
110 */
Aaron Durbin31be2c92016-12-03 22:08:20 -0600111 if (mrc_cache_stash_data(MRC_TRAINING_DATA, fsp_version, mrc_data,
112 mrc_data_size) < 0)
113 printk(BIOS_ERR, "Failed to stash MRC data\n");
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800114
115 mrc_cache_update_tpm_hash(mrc_data, mrc_data_size);
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500116}
117
Lee Leahy9671faa2016-07-24 18:18:52 -0700118static void do_fsp_post_memory_init(bool s3wake, uint32_t fsp_version)
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500119{
120 struct range_entry fsp_mem;
Aaron Durbinb4302502016-07-17 17:04:37 -0500121
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 */
Aaron Durbin77e13992016-11-29 17:43:04 -0600147 romstage_handoff_init(s3wake);
Aaron Durbinb4302502016-07-17 17:04:37 -0500148}
149
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800150static int mrc_cache_verify_tpm_hash(const uint8_t *data, size_t size)
151{
152 uint8_t data_hash[VB2_SHA256_DIGEST_SIZE];
153 uint8_t tpm_hash[VB2_SHA256_DIGEST_SIZE];
154
155 /* We do not store normal mode data hash in TPM. */
156 if (!vboot_recovery_mode_enabled())
157 return 1;
158
159 if (!IS_ENABLED(CONFIG_FSP2_0_USES_TPM_MRC_HASH))
160 return 1;
161
162 /* Calculate hash of data read from RECOVERY_MRC_CACHE. */
163 if (vb2_digest_buffer(data, size, VB2_HASH_SHA256, data_hash,
164 sizeof(data_hash))) {
165 printk(BIOS_ERR, "MRC: SHA-256 calculation failed for data.\n");
166 return 0;
167 }
168
169 /* Initialize TPM driver. */
Furquan Shaikh8b5d04e2016-11-10 09:49:05 -0800170 if (tlcl_lib_init() != VB2_SUCCESS) {
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800171 printk(BIOS_ERR, "MRC: TPM driver initialization failed.\n");
172 return 0;
173 }
174
175 /* Read hash of MRC data saved in TPM. */
176 if (antirollback_read_space_rec_hash(tpm_hash, sizeof(tpm_hash))
177 != TPM_SUCCESS) {
178 printk(BIOS_ERR, "MRC: Could not read hash from TPM.\n");
179 return 0;
180 }
181
182 if (memcmp(tpm_hash, data_hash, sizeof(tpm_hash))) {
183 printk(BIOS_ERR, "MRC: Hash comparison failed.\n");
184 return 0;
185 }
186
187 printk(BIOS_INFO, "MRC: Hash comparison successful. "
188 "Using data from RECOVERY_MRC_CACHE\n");
189 return 1;
190}
191
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700192static void fsp_fill_mrc_cache(FSPM_ARCH_UPD *arch_upd, bool s3wake,
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500193 uint32_t fsp_version)
Aaron Durbinb4302502016-07-17 17:04:37 -0500194{
Aaron Durbin31be2c92016-12-03 22:08:20 -0600195 struct region_device rdev;
196 void *data;
Aaron Durbinb4302502016-07-17 17:04:37 -0500197
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500198 arch_upd->NvsBufferPtr = NULL;
199
200 if (!IS_ENABLED(CONFIG_CACHE_MRC_SETTINGS))
201 return;
202
Aaron Durbin31be2c92016-12-03 22:08:20 -0600203 /*
204 * In recovery mode, force retraining:
205 * 1. Recovery cache is not supported, or
206 * 2. Memory retrain switch is set.
207 */
208 if (vboot_recovery_mode_enabled()) {
209 if (!IS_ENABLED(CONFIG_HAS_RECOVERY_MRC_CACHE))
210 return;
211 if (vboot_recovery_mode_memory_retrain())
212 return;
213 }
Aaron Durbin98ea6362016-07-18 11:31:53 -0500214
Aaron Durbin31be2c92016-12-03 22:08:20 -0600215 if (mrc_cache_get_current(MRC_TRAINING_DATA, fsp_version, &rdev) < 0)
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500216 return;
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500217
Aaron Durbin31be2c92016-12-03 22:08:20 -0600218 /* Assume boot device is memory mapped. */
219 assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED));
220 data = rdev_mmap_full(&rdev);
221
222 if (data == NULL)
223 return;
224
225 if (!mrc_cache_verify_tpm_hash(data, region_device_sz(&rdev)))
Furquan Shaikh2db5bac2016-11-07 23:57:48 -0800226 return;
227
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500228 /* MRC cache found */
Aaron Durbin31be2c92016-12-03 22:08:20 -0600229 arch_upd->NvsBufferPtr = data;
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500230 arch_upd->BootMode = s3wake ?
231 FSP_BOOT_ON_S3_RESUME:
232 FSP_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES;
Aaron Durbin31be2c92016-12-03 22:08:20 -0600233 printk(BIOS_SPEW, "MRC cache found, size %zx bootmode:%d\n",
234 region_device_sz(&rdev), arch_upd->BootMode);
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500235}
236
Aaron Durbin02e504c2016-07-18 11:53:10 -0500237static enum cb_err check_region_overlap(const struct memranges *ranges,
238 const char *description,
239 uintptr_t begin, uintptr_t end)
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500240{
Aaron Durbin02e504c2016-07-18 11:53:10 -0500241 const struct range_entry *r;
242
243 memranges_each_entry(r, ranges) {
244 if (end <= range_entry_base(r))
245 continue;
246 if (begin >= range_entry_end(r))
247 continue;
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700248 printk(BIOS_CRIT, "'%s' overlaps currently running program: "
Aaron Durbin02e504c2016-07-18 11:53:10 -0500249 "[%p, %p)\n", description, (void *)begin, (void *)end);
250 return CB_ERR;
251 }
252
253 return CB_SUCCESS;
254}
255
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700256static enum cb_err fsp_fill_common_arch_params(FSPM_ARCH_UPD *arch_upd,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500257 bool s3wake, uint32_t fsp_version,
258 const struct memranges *memmap)
259{
260 uintptr_t stack_begin;
261 uintptr_t stack_end;
262
Aaron Durbinb4302502016-07-17 17:04:37 -0500263 /*
264 * FSPM_UPD passed here is populated with default values provided by
265 * the blob itself. We let FSPM use top of CAR region of the size it
266 * requests.
Aaron Durbinb4302502016-07-17 17:04:37 -0500267 */
Aaron Durbin02e504c2016-07-18 11:53:10 -0500268 stack_end = (uintptr_t)_car_region_end;
269 stack_begin = stack_end - arch_upd->StackSize;
270
271 if (check_region_overlap(memmap, "FSPM stack", stack_begin,
272 stack_end) != CB_SUCCESS)
273 return CB_ERR;
274
275 arch_upd->StackBase = (void *)stack_begin;
Aaron Durbinb4302502016-07-17 17:04:37 -0500276
277 arch_upd->BootMode = FSP_BOOT_WITH_FULL_CONFIGURATION;
278
Aaron Durbinf0ec8242016-07-18 11:24:36 -0500279 fsp_fill_mrc_cache(arch_upd, s3wake, fsp_version);
Aaron Durbin02e504c2016-07-18 11:53:10 -0500280
281 return CB_SUCCESS;
Aaron Durbinb4302502016-07-17 17:04:37 -0500282}
283
Lee Leahy9671faa2016-07-24 18:18:52 -0700284static void do_fsp_memory_init(struct fsp_header *hdr, bool s3wake,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500285 const struct memranges *memmap)
Andrey Petrov465fc132016-02-25 14:16:33 -0800286{
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700287 uint32_t status;
Andrey Petrov465fc132016-02-25 14:16:33 -0800288 fsp_memory_init_fn fsp_raminit;
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700289 FSPM_UPD fspm_upd, *upd;
290 FSPM_ARCH_UPD *arch_upd;
Andrey Petrov465fc132016-02-25 14:16:33 -0800291
292 post_code(0x34);
293
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700294 upd = (FSPM_UPD *)(hdr->cfg_region_offset + hdr->image_base);
Andrey Petrov465fc132016-02-25 14:16:33 -0800295
296 if (upd->FspUpdHeader.Signature != FSPM_UPD_SIGNATURE) {
Lee Leahy9671faa2016-07-24 18:18:52 -0700297 die("Invalid FSPM signature!\n");
Andrey Petrov465fc132016-02-25 14:16:33 -0800298 }
299
300 /* Copy the default values from the UPD area */
301 memcpy(&fspm_upd, upd, sizeof(fspm_upd));
302
Aaron Durbin02e504c2016-07-18 11:53:10 -0500303 arch_upd = &fspm_upd.FspmArchUpd;
304
Aaron Durbin27928682016-07-15 22:32:28 -0500305 /* Reserve enough memory under TOLUD to save CBMEM header */
Aaron Durbin02e504c2016-07-18 11:53:10 -0500306 arch_upd->BootLoaderTolumSize = cbmem_overhead_size();
Aaron Durbin27928682016-07-15 22:32:28 -0500307
Aaron Durbinb4302502016-07-17 17:04:37 -0500308 /* Fill common settings on behalf of chipset. */
Aaron Durbin02e504c2016-07-18 11:53:10 -0500309 if (fsp_fill_common_arch_params(arch_upd, s3wake, hdr->fsp_revision,
310 memmap) != CB_SUCCESS)
Lee Leahy9671faa2016-07-24 18:18:52 -0700311 die("FSPM_ARCH_UPD not found!\n");
Aaron Durbinb4302502016-07-17 17:04:37 -0500312
Andrey Petrov465fc132016-02-25 14:16:33 -0800313 /* Give SoC and mainboard a chance to update the UPD */
Andrey Petrovf796c6e2016-11-18 14:57:51 -0800314 platform_fsp_memory_init_params_cb(&fspm_upd, hdr->fsp_revision);
Andrey Petrov465fc132016-02-25 14:16:33 -0800315
Pratik Prajapatiffc934d2016-11-18 14:36:34 -0800316 if (IS_ENABLED(CONFIG_MMA))
317 setup_mma(&fspm_upd.FspmConfig);
318
Andrey Petrov465fc132016-02-25 14:16:33 -0800319 /* Call FspMemoryInit */
320 fsp_raminit = (void *)(hdr->image_base + hdr->memory_init_entry_offset);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700321 fsp_debug_before_memory_init(fsp_raminit, upd, &fspm_upd);
Andrey Petrov465fc132016-02-25 14:16:33 -0800322
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -0700323 post_code(POST_FSP_MEMORY_INIT);
Andrey Petrov465fc132016-02-25 14:16:33 -0800324 timestamp_add_now(TS_FSP_MEMORY_INIT_START);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700325 status = fsp_raminit(&fspm_upd, fsp_get_hob_list_ptr());
Alexandru Gagniucc4ea8f72016-05-23 12:16:58 -0700326 post_code(POST_FSP_MEMORY_INIT);
Andrey Petrov465fc132016-02-25 14:16:33 -0800327 timestamp_add_now(TS_FSP_MEMORY_INIT_END);
328
Lee Leahyac3b0a62016-07-27 07:40:25 -0700329 fsp_debug_after_memory_init(status);
Andrey Petrov465fc132016-02-25 14:16:33 -0800330
Lee Leahy9671faa2016-07-24 18:18:52 -0700331 /* Handle any errors returned by FspMemoryInit */
Aaron Durbinf41f2aa2016-07-18 12:03:58 -0500332 fsp_handle_reset(status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700333 if (status != FSP_SUCCESS) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700334 printk(BIOS_CRIT, "FspMemoryInit returned 0x%08x\n", status);
Lee Leahy9671faa2016-07-24 18:18:52 -0700335 die("FspMemoryInit returned an error!\n");
336 }
Aaron Durbinf41f2aa2016-07-18 12:03:58 -0500337
Lee Leahy9671faa2016-07-24 18:18:52 -0700338 do_fsp_post_memory_init(s3wake, hdr->fsp_revision);
Andrey Petrov465fc132016-02-25 14:16:33 -0800339}
340
Aaron Durbind04639b2016-07-17 23:23:59 -0500341/* Load the binary into the memory specified by the info header. */
342static enum cb_err load_fspm_mem(struct fsp_header *hdr,
Aaron Durbin02e504c2016-07-18 11:53:10 -0500343 const struct region_device *rdev,
344 const struct memranges *memmap)
Aaron Durbind04639b2016-07-17 23:23:59 -0500345{
Aaron Durbind04639b2016-07-17 23:23:59 -0500346 uintptr_t fspm_begin;
347 uintptr_t fspm_end;
348
349 if (fsp_validate_component(hdr, rdev) != CB_SUCCESS)
350 return CB_ERR;
351
352 fspm_begin = hdr->image_base;
353 fspm_end = fspm_begin + hdr->image_size;
354
Aaron Durbin02e504c2016-07-18 11:53:10 -0500355 if (check_region_overlap(memmap, "FSPM", fspm_begin, fspm_end) !=
356 CB_SUCCESS)
Aaron Durbind04639b2016-07-17 23:23:59 -0500357 return CB_ERR;
Aaron Durbind04639b2016-07-17 23:23:59 -0500358
359 /* Load binary into memory at provided address. */
360 if (rdev_readat(rdev, (void *)fspm_begin, 0, fspm_end - fspm_begin) < 0)
361 return CB_ERR;
362
363 return CB_SUCCESS;
364}
365
366/* Handle the case when FSPM is running XIP. */
367static enum cb_err load_fspm_xip(struct fsp_header *hdr,
368 const struct region_device *rdev)
369{
370 void *base;
371
372 if (fsp_validate_component(hdr, rdev) != CB_SUCCESS)
373 return CB_ERR;
374
375 base = rdev_mmap_full(rdev);
376 if ((uintptr_t)base != hdr->image_base) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700377 printk(BIOS_CRIT, "FSPM XIP base does not match: %p vs %p\n",
Aaron Durbind04639b2016-07-17 23:23:59 -0500378 (void *)(uintptr_t)hdr->image_base, base);
379 return CB_ERR;
380 }
381
382 /*
383 * Since the component is XIP it's already in the address space. Thus,
384 * there's no need to rdev_munmap().
385 */
386 return CB_SUCCESS;
387}
388
Lee Leahy9671faa2016-07-24 18:18:52 -0700389void fsp_memory_init(bool s3wake)
Andrey Petrov465fc132016-02-25 14:16:33 -0800390{
391 struct fsp_header hdr;
Aaron Durbind04639b2016-07-17 23:23:59 -0500392 enum cb_err status;
393 struct cbfsf file_desc;
394 struct region_device file_data;
395 const char *name = CONFIG_FSP_M_CBFS;
Aaron Durbin02e504c2016-07-18 11:53:10 -0500396 struct memranges memmap;
397 struct range_entry freeranges[2];
Andrey Petrov465fc132016-02-25 14:16:33 -0800398
Furquan Shaikh5aea5882016-07-30 18:10:05 -0700399 if (IS_ENABLED(CONFIG_ELOG_BOOT_COUNT) && !s3wake)
400 boot_count_increment();
401
Aaron Durbind04639b2016-07-17 23:23:59 -0500402 if (cbfs_boot_locate(&file_desc, name, NULL)) {
Lee Leahyb20d4ba2016-07-31 16:49:28 -0700403 printk(BIOS_CRIT, "Could not locate %s in CBFS\n", name);
Lee Leahy9671faa2016-07-24 18:18:52 -0700404 die("FSPM not available!\n");
Aaron Durbind04639b2016-07-17 23:23:59 -0500405 }
406
407 cbfs_file_data(&file_data, &file_desc);
408
Aaron Durbin02e504c2016-07-18 11:53:10 -0500409 /* Build up memory map of romstage address space including CAR. */
410 memranges_init_empty(&memmap, &freeranges[0], ARRAY_SIZE(freeranges));
411 memranges_insert(&memmap, (uintptr_t)_car_region_start,
412 _car_relocatable_data_end - _car_region_start, 0);
413 memranges_insert(&memmap, (uintptr_t)_program, _program_size, 0);
414
Lee Leahy27cd96a2016-07-21 11:16:39 -0700415 if (!IS_ENABLED(CONFIG_FSP_M_XIP))
Aaron Durbin02e504c2016-07-18 11:53:10 -0500416 status = load_fspm_mem(&hdr, &file_data, &memmap);
Aaron Durbind04639b2016-07-17 23:23:59 -0500417 else
418 status = load_fspm_xip(&hdr, &file_data);
419
420 if (status != CB_SUCCESS) {
Lee Leahy9671faa2016-07-24 18:18:52 -0700421 die("Loading FSPM failed!\n");
Aaron Durbind04639b2016-07-17 23:23:59 -0500422 }
423
424 /* Signal that FSP component has been loaded. */
425 prog_segment_loaded(hdr.image_base, hdr.image_size, SEG_FINAL);
Andrey Petrov465fc132016-02-25 14:16:33 -0800426
Lee Leahy9671faa2016-07-24 18:18:52 -0700427 do_fsp_memory_init(&hdr, s3wake, &memmap);
Andrey Petrov465fc132016-02-25 14:16:33 -0800428}