summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Held <felix-coreboot@felixheld.de>2021-08-21 00:07:25 +0200
committerFelix Held <felix-coreboot@felixheld.de>2021-08-27 02:32:11 +0000
commit8d268e9bda1f3b9fe787c9d8592c68958c6ff480 (patch)
tree3776c0e0ef4c0a02795b3112402663796d2574d6 /src
parent2e0b5c40073a38080e7ee5ebc7e67cbf5d1f475a (diff)
soc/amd/common/fsp/fsp_validate: add runtime check for FSP-M binary size
When modules are added to the FSP and they won't fit into the FSP binary any more, the size can be increased in the FSP build. Especially in the case of debug builds the increased size might not fit into the memory region it gets decompressed into which starts at FSP_M_ADDR and has a size of FSP_M_SIZE. SoCs can implement the soc_validate_fspm_header function that ends up being called by the FSP driver in romstage to do some additional checks on the FSP binary's header that includes the version number and the image size. We can use the image size field to check if it fits into the reserved region. Since the FSP-M memory region is located after romstage loading it won't clobber the romstage code where we do the check. This runtime check is added in addition to the build-time check to also cover the case when the FSP binaries in CBFS get replaced with ones that don't fit into the reserved memory region after the coreboot build. BUG=b:186149011 TEST=Mandolin still boots fine with the patch applied. When as a test the FSP_M_SIZE Kconfig option in soc/amd/picasso is decreased to 0x10000 which is by far not enough for the decompressed FSP-M binary to fit into it prints the newly added error message on the console and then stops. Signed-off-by: Felix Held <felix-coreboot@felixheld.de> Change-Id: I9b74a2d03993ba50b166eb6e87d4e57b93afc069 Reviewed-on: https://review.coreboot.org/c/coreboot/+/57068 Reviewed-by: Furquan Shaikh <furquan@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src')
-rw-r--r--src/soc/amd/common/fsp/Makefile.inc1
-rw-r--r--src/soc/amd/common/fsp/fsp_validate.c15
2 files changed, 16 insertions, 0 deletions
diff --git a/src/soc/amd/common/fsp/Makefile.inc b/src/soc/amd/common/fsp/Makefile.inc
index 503d3bfc0e..2541f27754 100644
--- a/src/soc/amd/common/fsp/Makefile.inc
+++ b/src/soc/amd/common/fsp/Makefile.inc
@@ -1,5 +1,6 @@
ifeq ($(CONFIG_PLATFORM_USES_FSP2_0),y)
romstage-y += fsp_reset.c
+romstage-y += fsp_validate.c
ramstage-y += fsp_reset.c
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += fsp-acpi.c
ramstage-$(CONFIG_SOC_AMD_COMMON_FSP_DMI_TABLES) += dmi.c
diff --git a/src/soc/amd/common/fsp/fsp_validate.c b/src/soc/amd/common/fsp/fsp_validate.c
new file mode 100644
index 0000000000..4d6a8f72bc
--- /dev/null
+++ b/src/soc/amd/common/fsp/fsp_validate.c
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <console/console.h>
+#include <fsp/util.h>
+#include <types.h>
+
+/* Validate the FSP-M header in romstage */
+void soc_validate_fspm_header(const struct fsp_header *hdr)
+{
+ /* Check if the image fits into the reserved memory region */
+ if (hdr->image_size > CONFIG_FSP_M_SIZE)
+ die("The FSP-M binary is %u bytes larger than the memory region allocated for "
+ "it. Increase FSP_M_SIZE to make it fit.\n",
+ hdr->image_size - CONFIG_FSP_M_SIZE);
+}