diff options
author | Julius Werner <jwerner@chromium.org> | 2023-11-02 16:20:17 -0700 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2023-11-07 22:30:12 +0000 |
commit | ca71588620b9f4a3c37d10f133febe5d2026921f (patch) | |
tree | 152de9db0e81fad76b059250838bd1b40a1b200f /src | |
parent | 682cb3b56419a242b54605cc734b99ffdcab8213 (diff) |
fmap: Eliminate some impossible code paths
When the FMAP cache is enabled, it cannot fail in pre-RAM stages unless
flash I/O in general doesn't work. Therefore, it is unnecessary and a
waste of binary size to also link a fallback path for this case.
Similarly, once the cache is written to CAR/SRAM/CBMEM there should be
no way for it to become magically corrupted between boot stages. Many
other parts of coreboot blindly assume that persistent memory stays
valid between stages so there is no reason why this code should link in
extra fallback paths in case it doesn't.
This saves a little over 200 bytes per affected (uncompressed) stage on
aarch64.
Change-Id: I7b8251dd6b34fe4f63865ebc44b9a8a103f32a57
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/78904
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/fmap.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/lib/fmap.c b/src/lib/fmap.c index 8d7b6a8f71..77817d1e60 100644 --- a/src/lib/fmap.c +++ b/src/lib/fmap.c @@ -31,8 +31,11 @@ uint64_t get_fmap_flash_offset(void) static int verify_fmap(const struct fmap *fmap) { - if (memcmp(fmap->signature, FMAP_SIGNATURE, sizeof(fmap->signature))) + if (memcmp(fmap->signature, FMAP_SIGNATURE, sizeof(fmap->signature))) { + if (ENV_INITIAL_STAGE) + printk(BIOS_ERR, "Invalid FMAP at %#x\n", FMAP_OFFSET); return -1; + } static bool done = false; if (!CONFIG(CBFS_VERIFICATION) || !ENV_INITIAL_STAGE || done) @@ -82,9 +85,8 @@ static void setup_preram_cache(struct region_device *cache_rdev) if (!verify_fmap(fmap)) goto register_cache; - printk(BIOS_ERR, "FMAP cache corrupted?!\n"); - if (CONFIG(TOCTOU_SAFETY)) - die("TOCTOU safety relies on FMAP cache"); + /* This shouldn't happen, so no point providing a fallback path here. */ + die("FMAP cache corrupted?!\n"); } /* In case we fail below, make sure the cache is invalid. */ @@ -118,6 +120,10 @@ static int find_fmap_directory(struct region_device *fmrd) if (region_device_sz(&fmap_cache)) return rdev_chain_full(fmrd, &fmap_cache); + /* Cache setup in pre-RAM stages can't fail, unless flash I/O in general failed. */ + if (!CONFIG(NO_FMAP_CACHE) && ENV_ROMSTAGE_OR_BEFORE) + return -1; + boot_device_init(); boot = boot_device_ro(); @@ -130,8 +136,6 @@ static int find_fmap_directory(struct region_device *fmrd) return -1; if (verify_fmap(fmap)) { - printk(BIOS_ERR, "FMAP missing or corrupted at offset 0x%zx!\n", - offset); rdev_munmap(boot, fmap); return -1; } |