[coreboot-gerrit] New patch to review for coreboot: drivers/intel/fsp2_0: Verify HOBs returned by FspMemoryInit

Lee Leahy (leroy.p.leahy@intel.com) gerrit at coreboot.org
Mon Jul 25 21:39:31 CEST 2016


Lee Leahy (leroy.p.leahy at intel.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15850

-gerrit

commit f4f17ad0cfc9e663d389ba65404712f882315490
Author: Lee Leahy <leroy.p.leahy at intel.com>
Date:   Sun Jul 24 09:52:38 2016 -0700

    drivers/intel/fsp2_0: Verify HOBs returned by FspMemoryInit
    
    Verify that FSP is properly returning:
    * HOB list pointer
    * FSP_BOOTLOADER_TOLUM_HOB
    * FSP_RESERVED_MEMORY_RESOURCE_HOB
    
    TEST=Build and run on Galileo Gen2
    
    Change-Id: I23005d10f7f3ccf06a2e29dab5fa11c7ed79f187
    Signed-off-by: Lee Leahy <leroy.p.leahy at intel.com>
---
 src/drivers/intel/fsp2_0/hand_off_block.c   | 15 +++++++++++--
 src/drivers/intel/fsp2_0/include/fsp/util.h |  3 +++
 src/drivers/intel/fsp2_0/memory_init.c      | 35 ++++++++++++++++++++++++++++-
 3 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/src/drivers/intel/fsp2_0/hand_off_block.c b/src/drivers/intel/fsp2_0/hand_off_block.c
index c9d5b8e..276e49d 100644
--- a/src/drivers/intel/fsp2_0/hand_off_block.c
+++ b/src/drivers/intel/fsp2_0/hand_off_block.c
@@ -214,13 +214,14 @@ struct hob_resource *find_resource_hob_by_uuid(const struct hob_header *hob,
 	return NULL;
 }
 
-void fsp_find_reserved_memory(struct range_entry *re, const void *hob_list)
+void fsp_find_range_hob(struct range_entry *re, const void *hob_list,
+						const uint8_t uuid[16])
 {
 	const struct hob_resource *fsp_mem;
 
 	range_entry_init(re, 0, 0, 0);
 
-	fsp_mem = find_resource_hob_by_uuid(hob_list, uuid_owner_fsp);
+	fsp_mem = find_resource_hob_by_uuid(hob_list, uuid);
 
 	if (!fsp_mem) {
 		return;
@@ -229,6 +230,16 @@ void fsp_find_reserved_memory(struct range_entry *re, const void *hob_list)
 	range_entry_init(re, fsp_mem->addr, fsp_mem->addr + fsp_mem->length, 0);
 }
 
+void fsp_find_bootloader_tolum(struct range_entry *re, const void *hob_list)
+{
+	fsp_find_range_hob(re, hob_list, uuid_owner_bootloader_tolum);
+}
+
+void fsp_find_reserved_memory(struct range_entry *re, const void *hob_list)
+{
+	fsp_find_range_hob(re, hob_list, uuid_owner_fsp);
+}
+
 /*
  * Utilities for printing HOB information
  */
diff --git a/src/drivers/intel/fsp2_0/include/fsp/util.h b/src/drivers/intel/fsp2_0/include/fsp/util.h
index 63ef53e..03cea09 100644
--- a/src/drivers/intel/fsp2_0/include/fsp/util.h
+++ b/src/drivers/intel/fsp2_0/include/fsp/util.h
@@ -32,6 +32,9 @@ enum cb_err fsp_fill_lb_framebuffer(struct lb_framebuffer *framebuffer);
  * Hand-off-block utilities which do not depend on CBMEM, but need to be passed
  * the HOB list explicitly.
  */
+void fsp_find_range_hob(struct range_entry *re, const void *hob_list,
+						const uint8_t uuid[16]);
+void fsp_find_bootloader_tolum(struct range_entry *re, const void *hob_list);
 void fsp_find_reserved_memory(struct range_entry *re, const void *hob_list);
 void fsp_print_memory_resource_hobs(const void *hob_list);
 
diff --git a/src/drivers/intel/fsp2_0/memory_init.c b/src/drivers/intel/fsp2_0/memory_init.c
index fdcde7c..6950038 100644
--- a/src/drivers/intel/fsp2_0/memory_init.c
+++ b/src/drivers/intel/fsp2_0/memory_init.c
@@ -59,13 +59,45 @@ static void save_memory_training_data(bool s3wake, uint32_t fsp_version)
 			printk(BIOS_ERR, "Failed to stash MRC data\n");
 }
 
+static void verify_hobs(struct range_entry *fsp_mem,
+	void *hob_list_ptr)
+{
+	struct range_entry tolum;
+
+	/* Lookup the FSP_BOOTLOADER_TOLUM_HOB */
+	fsp_find_bootloader_tolum(&tolum, hob_list_ptr);
+	if ((tolum.begin == 0) && (tolum.begin == (tolum.end + 1)))
+		die("9.3: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
+	if (range_entry_size(&tolum) < cbmem_overhead_size()) {
+		printk(BIOS_ERR, "FSP_BOOTLOADER_TOLUM_SIZE: 0x%08llx < 0x%08lx\n",
+			range_entry_size(&tolum), cbmem_overhead_size());
+		die("ERROR: FSP_BOOTLOADER_TOLUM_HOB too small!\n");
+	}
+
+	/* Locate the FSP reserved memory area */
+	fsp_find_reserved_memory(fsp_mem, hob_list_ptr);
+	if ((fsp_mem->begin == 0) && (fsp_mem->begin == (fsp_mem->end + 1)))
+		die("9.1: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
+
+	/* Verify the the bootloader tolum is above the FSP reserved area */
+	if (tolum.end <= fsp_mem->begin)
+		die("ERROR - FSP reserved region after BIOS TOLUM!\n");
+	if (tolum.begin <= fsp_mem->end)
+		die("ERROR - FSP reserved region overlaps BIOS TOLUM!\n");
+	if (tolum.begin != (fsp_mem->end + 1))
+		die("ERROR - Space between FSP reserved region and BIOS TOLUM!\n");
+}
+
 static enum fsp_status do_fsp_post_memory_init(void *hob_list_ptr, bool s3wake,
 						uint32_t fsp_version)
 {
 	struct range_entry fsp_mem;
 	struct romstage_handoff *handoff;
 
-	fsp_find_reserved_memory(&fsp_mem, hob_list_ptr);
+	/* Verify that the HOB list pointer was set */
+	if (hob_list_ptr == NULL)
+		die("ERROR - HOB list pointer was not returned!\n");
+	verify_hobs(&fsp_mem, hob_list_ptr);
 
 	/* initialize cbmem by adding FSP reserved memory first thing */
 	if (!s3wake) {
@@ -220,6 +252,7 @@ static enum fsp_status do_fsp_memory_init(struct fsp_header *hdr, bool s3wake,
 
 	/* Call FspMemoryInit */
 	fsp_raminit = (void *)(hdr->image_base + hdr->memory_init_entry_offset);
+	hob_list_ptr = NULL;
 	printk(BIOS_DEBUG, "Calling FspMemoryInit: 0x%p\n", fsp_raminit);
 	printk(BIOS_SPEW, "\t%p: raminit_upd\n", &fspm_upd);
 	printk(BIOS_SPEW, "\t%p: hob_list ptr\n", &hob_list_ptr);



More information about the coreboot-gerrit mailing list