From 02b43aa2e01772556a6b18a40677bb2438ba8327 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Tue, 12 Dec 2017 14:56:41 -0700 Subject: vc/amd/pi/0067F00: add option to add AGESA binary PI as stage Stage addition to CBFS allows relocation to happen on the fly. Take advantage of that by adding AGESA binary PI as a stage file so that each instance will be relocated properly within CBFS. Without this patch Chrome OS having multiple CBFS instances just redirects the AGESA calls back into RO which is inappropriate. BUG=b:65442265,b:68141063 TEST=Enabled AGESA_BINARY_PI_AS_STAGE and used ELF file. Booted and noted each instance in Chrome OS build was relocated. Change-Id: Ic0141bc6436a30f855148ff205f28ac9bce30043 Signed-off-by: Aaron Durbin Reviewed-on: https://review.coreboot.org/22833 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth Reviewed-by: Paul Menzel Reviewed-by: Marshall Dawson --- src/soc/amd/common/block/pi/agesawrapper.c | 58 ++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) (limited to 'src/soc/amd') diff --git a/src/soc/amd/common/block/pi/agesawrapper.c b/src/soc/amd/common/block/pi/agesawrapper.c index b1f03cb178..cc572075af 100644 --- a/src/soc/amd/common/block/pi/agesawrapper.c +++ b/src/soc/amd/common/block/pi/agesawrapper.c @@ -381,22 +381,68 @@ AGESA_STATUS agesawrapper_amdreadeventlog (UINT8 HeapStatus) return Status; } +static int agesa_locate_file(const char *name, struct region_device *rdev, + uint32_t type) +{ + struct cbfsf fh; + + if (cbfs_boot_locate(&fh, name, &type)) + return -1; + + cbfs_file_data(rdev, &fh); + return 0; +} + +static int agesa_locate_raw_file(const char *name, struct region_device *rdev) +{ + return agesa_locate_file(name, rdev, CBFS_TYPE_RAW); +} + +static int agesa_locate_stage_file(const char *name, struct region_device *rdev) +{ + const size_t metadata_sz = sizeof(struct cbfs_stage); + + if (agesa_locate_file(name, rdev, CBFS_TYPE_STAGE)) + return -1; + + /* Peel off the cbfs stage metadata. */ + return rdev_chain(rdev, rdev, metadata_sz, + region_device_sz(rdev) - metadata_sz); +} + const void *agesawrapper_locate_module (const CHAR8 name[8]) { const void* agesa; const AMD_IMAGE_HEADER* image; - const AMD_MODULE_HEADER* module; + struct region_device rdev; size_t file_size; + const char *fname = CONFIG_AGESA_CBFS_NAME; + int ret; + + if (IS_ENABLED(CONFIG_AGESA_BINARY_PI_AS_STAGE)) + ret = agesa_locate_stage_file(fname, &rdev); + else + ret = agesa_locate_raw_file(fname, &rdev); + + if (ret) + return NULL; - agesa = cbfs_boot_map_with_leak((const char *)CONFIG_AGESA_CBFS_NAME, - CBFS_TYPE_RAW, &file_size); + file_size = region_device_sz(&rdev); + + /* Assume boot device is memory mapped so the mapping can leak. */ + assert(IS_ENABLED(CONFIG_BOOT_DEVICE_MEMORY_MAPPED)); + + agesa = rdev_mmap_full(&rdev); if (!agesa) return NULL; - image = LibAmdLocateImage(agesa, agesa + file_size - 1, 4096, name); - module = (AMD_MODULE_HEADER*)image->ModuleInfoOffset; - return module; + image = LibAmdLocateImage(agesa, agesa + file_size, 4096, name); + + if (!image) + return NULL; + + return (AMD_MODULE_HEADER *)image->ModuleInfoOffset; } static MODULE_ENTRY agesa_dispatcher CAR_GLOBAL; -- cgit v1.2.3