summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorArthur Heymans <arthur@aheymans.xyz>2021-05-29 08:10:49 +0200
committerFelix Held <felix-coreboot@felixheld.de>2023-11-09 13:20:18 +0000
commita2bc2540c2d004b475b401ccf0b162c2452857bb (patch)
tree902284670b43d9e06d7dccc64dbeec24073fca4e /src/lib
parent4ce52f622ed7fbac4bf5545fd7d39256203cdefe (diff)
Allow to build romstage sources inside the bootblock
Having a separate romstage is only desirable: - with advanced setups like vboot or normal/fallback - boot medium is slow at startup (some ARM SOCs) - bootblock is limited in size (Intel APL 32K) When this is not the case there is no need for the extra complexity that romstage brings. Including the romstage sources inside the bootblock substantially reduces the total code footprint. Often the resulting code is 10-20k smaller. This is controlled via a Kconfig option. TESTED: works on qemu x86, arm and aarch64 with and without VBOOT. Change-Id: Id68390edc1ba228b121cca89b80c64a92553e284 Signed-off-by: Arthur Heymans <arthur@aheymans.xyz> Reviewed-on: https://review.coreboot.org/c/coreboot/+/55068 Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/asan.c10
-rw-r--r--src/lib/cbfs.c25
-rw-r--r--src/lib/prog_loaders.c8
3 files changed, 28 insertions, 15 deletions
diff --git a/src/lib/asan.c b/src/lib/asan.c
index 9493b3b51a..8f92d5a759 100644
--- a/src/lib/asan.c
+++ b/src/lib/asan.c
@@ -16,7 +16,7 @@
static inline void *asan_mem_to_shadow(const void *addr)
{
-#if ENV_ROMSTAGE
+#if ENV_SEPARATE_ROMSTAGE
return (void *)((uintptr_t)&_asan_shadow + (((uintptr_t)addr -
(uintptr_t)&_car_region_start) >> ASAN_SHADOW_SCALE_SHIFT));
#elif ENV_RAMSTAGE
@@ -27,7 +27,7 @@ static inline void *asan_mem_to_shadow(const void *addr)
static inline const void *asan_shadow_to_mem(const void *shadow_addr)
{
-#if ENV_ROMSTAGE
+#if ENV_SEPARATE_ROMSTAGE
return (void *)((uintptr_t)&_car_region_start + (((uintptr_t)shadow_addr -
(uintptr_t)&_asan_shadow) << ASAN_SHADOW_SCALE_SHIFT));
#elif ENV_RAMSTAGE
@@ -237,7 +237,7 @@ static __always_inline void check_memory_region_inline(unsigned long addr,
size_t size, bool write,
unsigned long ret_ip)
{
-#if ENV_ROMSTAGE
+#if ENV_SEPARATE_ROMSTAGE
if (((uintptr_t)addr < (uintptr_t)&_car_region_start) ||
((uintptr_t)addr > (uintptr_t)&_ebss))
return;
@@ -269,7 +269,7 @@ void check_memory_region(unsigned long addr, size_t size, bool write,
uintptr_t __asan_shadow_offset(uintptr_t addr)
{
-#if ENV_ROMSTAGE
+#if ENV_SEPARATE_ROMSTAGE
return (uintptr_t)&_asan_shadow - (((uintptr_t)&_car_region_start) >>
ASAN_SHADOW_SCALE_SHIFT);
#elif ENV_RAMSTAGE
@@ -323,7 +323,7 @@ static void asan_ctors(void)
void asan_init(void)
{
-#if ENV_ROMSTAGE
+#if ENV_SEPARATE_ROMSTAGE
size_t size = (size_t)&_ebss - (size_t)&_car_region_start;
asan_unpoison_shadow((void *)&_car_region_start, size);
#elif ENV_RAMSTAGE
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index e5f232ca21..92a00e4418 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -141,16 +141,21 @@ static inline bool cbfs_lzma_enabled(void)
return true;
if (fspm_env() && CONFIG(FSP_COMPRESS_FSP_M_LZMA))
return true;
- /* We assume here romstage and postcar are never compressed. */
- if (ENV_BOOTBLOCK || ENV_SEPARATE_VERSTAGE)
- return false;
- if (ENV_ROMSTAGE && CONFIG(POSTCAR_STAGE))
- return false;
- if ((ENV_ROMSTAGE || ENV_POSTCAR) && !CONFIG(COMPRESS_RAMSTAGE_LZMA))
- return false;
- if (ENV_SMM)
+
+ /* Payload loader (ramstage) always needs LZMA. */
+ if (ENV_PAYLOAD_LOADER)
+ return true;
+ /* Only other use of LZMA is ramstage compression. */
+ if (!CONFIG(COMPRESS_RAMSTAGE_LZMA))
return false;
- return true;
+ /* If there is a postcar, it loads the ramstage. */
+ if (CONFIG(POSTCAR_STAGE))
+ return ENV_POSTCAR;
+ /* If there is no postcar but a separate romstage, it loads the ramstage. */
+ if (CONFIG(SEPARATE_ROMSTAGE))
+ return ENV_SEPARATE_ROMSTAGE;
+ /* Otherwise, the combined bootblock+romstage loads the ramstage. */
+ return ENV_BOOTBLOCK;
}
static bool cbfs_file_hash_mismatch(const void *buffer, size_t size,
@@ -333,7 +338,7 @@ void cbfs_preload(const char *name)
dead_code();
/* We don't want to cross the vboot boundary */
- if (ENV_ROMSTAGE && CONFIG(VBOOT_STARTS_IN_ROMSTAGE))
+ if (ENV_SEPARATE_ROMSTAGE && CONFIG(VBOOT_STARTS_IN_ROMSTAGE))
return;
DEBUG("%s(name='%s')\n", __func__, name);
diff --git a/src/lib/prog_loaders.c b/src/lib/prog_loaders.c
index 9e661c5956..b2abbff575 100644
--- a/src/lib/prog_loaders.c
+++ b/src/lib/prog_loaders.c
@@ -9,6 +9,7 @@
#include <program_loading.h>
#include <reset.h>
#include <rmodule.h>
+#include <romstage_common.h>
#include <security/vboot/vboot_common.h>
#include <stage_cache.h>
#include <symbols.h>
@@ -16,6 +17,13 @@
void run_romstage(void)
{
+ if (!CONFIG(SEPARATE_ROMSTAGE)) {
+ /* Call romstage instead of loading it as a cbfs file. */
+ timestamp_add_now(TS_ROMSTAGE_START);
+ romstage_main();
+ dead_code();
+ }
+
struct prog romstage =
PROG_INIT(PROG_ROMSTAGE, CONFIG_CBFS_PREFIX "/romstage");