fsp1_1: fsp_relocate: use struct region_device and struct prog
Using struct prog and struct region_device allows for the
caller to be none-the-wiser about where FSP gets placed. It
also allows for the source location to be abstracted away
such that it doesn't require a large mapping up front to
do the relocation. Lastly, it allows for simplifying the
intel/commmon FSP support in that it can pass around a
struct prog.
BUG=chrome-os-partner:43636
BRANCH=None
TEST=Built, booted, suspended, and resumed on glados.
Original-Change-Id: I034b04ab2b7e9e01f5ee14fcc190f04b90517d30
Original-Signed-off-by: Aaron Durbin <adurbin@chroumium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/290830
Original-Tested-by: Aaron Durbin <adurbin@chromium.org>
Original-Reviewed-by: Leroy P Leahy <leroy.p.leahy@intel.com>
Original-Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Original-Commit-Queue: Aaron Durbin <adurbin@chromium.org>
Change-Id: Ibe1f206a9541902103551afaf212418fcc90e73c
Signed-off-by: Aaron Durbin <adurbin@chroumium.org>
Reviewed-on: http://review.coreboot.org/11193
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
diff --git a/src/drivers/intel/fsp1_1/fsp_relocate.c b/src/drivers/intel/fsp1_1/fsp_relocate.c
index 08e1eb8..3e52608 100644
--- a/src/drivers/intel/fsp1_1/fsp_relocate.c
+++ b/src/drivers/intel/fsp1_1/fsp_relocate.c
@@ -482,15 +482,33 @@
return relocate_remaining_items(fsp, size, fih_offset);
}
-FSP_INFO_HEADER *fsp_relocate(void *fsp_src, size_t size)
+int fsp_relocate(struct prog *fsp_relocd, const struct region_device *fsp_src)
{
void *new_loc;
+ void *fih;
+ size_t size = region_device_sz(fsp_src);
new_loc = cbmem_add(CBMEM_ID_REFCODE, size);
+
if (new_loc == NULL) {
- printk(BIOS_ERR, "Unable to load FSP into memory.\n");
- return NULL;
+ printk(BIOS_ERR, "ERROR: Unable to load FSP into memory.\n");
+ return -1;
}
- memcpy(new_loc, fsp_src, size);
- return fsp_relocate_in_place(new_loc, size);
+
+ if (rdev_readat(fsp_src, new_loc, 0, size) != size) {
+ printk(BIOS_ERR, "ERROR: Can't read FSP's region device.\n");
+ return -1;
+ }
+
+ fih = fsp_relocate_in_place(new_loc, size);
+
+ if (fih == NULL) {
+ printk(BIOS_ERR, "ERROR: FSP relocation faiulre.\n");
+ return -1;
+ }
+
+ prog_set_area(fsp_relocd, new_loc, size);
+ prog_set_entry(fsp_relocd, fih, NULL);
+
+ return 0;
}