Werner Zeh has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/62751 )
Change subject: lib/cbfs: Enable payload mirroring into RAM ......................................................................
lib/cbfs: Enable payload mirroring into RAM
Since commit 7e7cc1a8c9a87e33bd772e8526734c7a82ec2db7 the measuring of the payload has been refactored with the assumption that access to a memory mapped flash region is comparably fast to a RAM region. This is not necessarily true for all platforms, especially when the flash region is not cached. On this platforms, measuring the payload can be very slow which will slow down the overall boot process a lot.
For example, on Elkhart Lake loading and measuring a 4.5 MB payload with a 20 MHz single SPI interface takes ~12 seconds:
90:starting to load payload 1,133,387 (1,770) 958:calling FspNotify(ReadyToBoot) 12,879,028 (11,745,640)
To speed this up mirroring the payload into DRAM can help a lot. The same mainboard with this patch applied needs just ~3.5 seconds to load the payload:
90:starting to load payload 1,119,405 (1,803) 958:calling FspNotify(ReadyToBoot) 4,661,876 (3,542,471)
On a mainboard based on Apollo Lake (mc_apl5) this patch speeds up payload loading by ~1 seconds (1.5 sec without this patch, 0,6 with this patch applied):
90:load payload 2,119,183 (67) 958:calling FspNotify(ReadyToBoot) 3,635,886 (1,516,702)
vs:
90:load payload 2,108,146 (68) 958:calling FspNotify(ReadyToBoot) 2,773,016 (664,869)
Since mirroring the payload just improves the boot time when TPM_MEASURED_BOOT is enabled, the new introduced Kconfig switch can only be selected if TPM_MEASURED_BOOT is selected, too. Enabling it will load the payload into RAM before it is used.
Change-Id: I94fc1a6d7c2543a7f1612314011dca47d29b79d0 Signed-off-by: Werner Zeh werner.zeh@siemens.com --- M payloads/Kconfig M src/lib/cbfs.c 2 files changed, 20 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/51/62751/1
diff --git a/payloads/Kconfig b/payloads/Kconfig index 386b207..d0d0ee3 100644 --- a/payloads/Kconfig +++ b/payloads/Kconfig @@ -104,6 +104,14 @@ Enables FIT parser and devicetree patching. The FIT is non self-extracting and needs to have a compatible compression format.
+config PAYLOAD_MIRROR_TO_RAM + def_bool n + depends on TPM_MEASURED_BOOT + help + When this option is selected, the payload will be mirrored into RAM + before it is being measured. Copying the payload to RAM can speed up the + boot process a lot. + config COMPRESS_SECONDARY_PAYLOAD bool "Use LZMA compression for secondary payloads" default y @@ -111,6 +119,7 @@ In order to reduce the size secondary payloads take up in the ROM chip they can be compressed using the LZMA algorithm.
+ menu "Secondary Payloads"
config COREINFO_SECONDARY_PAYLOAD diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index c8ca14c..4944e62 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -474,6 +474,17 @@ if (!force_ro && get_preload_rdev(&rdev, name) == CB_SUCCESS) preload_successful = true;
+ /* Mirror the payload to RAM to speed up booting. */ + if (CONFIG(PAYLOAD_MIRROR_TO_RAM) && ENV_RAMSTAGE && + !strcmp(name, CONFIG_CBFS_PREFIX "/payload")) { + size_t size = region_device_sz(&rdev); + void *buf = bootmem_allocate_buffer(size); + if (!buf || + rdev_read_full(&rdev, buf) != size || + rdev_chain_mem(&rdev, buf, size) != 0) + printk(BIOS_ERR, "Not able to mirror the payload to RAM\n"); + } + void *ret = do_alloc(&mdata, &rdev, allocator, arg, size_out, false);
/* When using cbfs_preload we need to free the preload buffer after populating the