lib/cbfs: Enable cbfs_cache for x86
The reason cbfs_cache was disabled on x86 was due to the lack of
.data sections in the pre-RAM stages. By using
ENV_STAGE_HAS_DATA_SECTION we enable x86 to start using the cbfs_cache.
We still need to add a cbfs_cache region into the memlayout for it to
be enabled.
BUG=b:179699789
TEST=Build guybrush and verify cbfs_cache.size == 0.
Suggested-by: Julius Werner <jwerner@chromium.org>
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: I74434ef9250ff059e7587147b1456aeabbee33aa
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56577
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c
index 52f7373..322f161 100644
--- a/src/lib/cbfs.c
+++ b/src/lib/cbfs.c
@@ -18,8 +18,11 @@
#include <symbols.h>
#include <timestamp.h>
-#if CBFS_CACHE_AVAILABLE
+#if ENV_STAGE_HAS_DATA_SECTION
struct mem_pool cbfs_cache = MEM_POOL_INIT(_cbfs_cache, REGION_SIZE(cbfs_cache));
+#else
+struct mem_pool cbfs_cache = MEM_POOL_INIT(NULL, 0);
+#endif
static void switch_to_postram_cache(int unused)
{
@@ -28,7 +31,6 @@
REGION_SIZE(postram_cbfs_cache));
}
ROMSTAGE_CBMEM_INIT_HOOK(switch_to_postram_cache);
-#endif
cb_err_t cbfs_boot_lookup(const char *name, bool force_ro,
union cbfs_mdata *mdata, struct region_device *rdev)
@@ -111,8 +113,7 @@
* that requires a free() for the boot_device, they need to implement it via the
* cbfs_cache mem_pool.
*/
- if (CBFS_CACHE_AVAILABLE)
- mem_pool_free(&cbfs_cache, mapping);
+ mem_pool_free(&cbfs_cache, mapping);
}
int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name,
@@ -319,8 +320,13 @@
}
return mapping;
- } else if (!CBFS_CACHE_AVAILABLE) {
- ERROR("Cannot map compressed file %s on x86\n", mdata.h.filename);
+ } else if (!cbfs_cache.size) {
+ /*
+ * In order to use the cbfs_cache you need to add a CBFS_CACHE to your
+ * memlayout. For stages that don't have .data sections (x86 pre-RAM),
+ * it is not possible to add a CBFS_CACHE.
+ */
+ ERROR("Cannot map compressed file %s without cbfs_cache\n", mdata.h.filename);
return NULL;
} else {
loc = mem_pool_alloc(&cbfs_cache, size);