From 3b069d320cccb93e01f090f435e1ddd5c67d57ff Mon Sep 17 00:00:00 2001 From: Jeremy Compostella Date: Wed, 16 Jul 2025 14:58:09 -0700 Subject: [PATCH] cbfs: Add a function to wait for all CBFS preload operations to complete Introduce cbfs_preload_wait_for_all() to guarantee that all CBFS preload contexts complete their tasks before moving forward. This function goes through each preload context and waits for the corresponding thread to finish by using thread_join(). If any preload thread runs into an issue, it records an error message along with the context name. This addition provides a synchronization point during the boot process which platform code can leverage, typically when the storage backend supporting asynchronous file transfer is about to be deactivated. Change-Id: I3ee27ef2fbfdc19bd75532713966f333ad975861 Signed-off-by: Jeremy Compostella Reviewed-on: https://review.coreboot.org/c/coreboot/+/88457 Reviewed-by: Julius Werner Tested-by: build bot (Jenkins) --- src/include/cbfs.h | 2 ++ src/lib/cbfs.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/include/cbfs.h b/src/include/cbfs.h index f0ae7a80ef..27a285e51d 100644 --- a/src/include/cbfs.h +++ b/src/include/cbfs.h @@ -126,6 +126,8 @@ static inline void *cbfs_unverified_area_cbmem_alloc(const char *area, const cha * method succeeds or fails. */ void cbfs_preload(const char *name); +/* Wait for all preloaded CBFS contexts to complete their operations. */ +void cbfs_preload_wait_for_all(void); /* Removes a previously allocated CBFS mapping. Should try to unmap mappings in strict LIFO order where possible, since mapping backends often don't support more complicated cases. */ diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index f25030491e..fab64d3b7b 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -376,6 +376,14 @@ out: free_cbfs_preload_context(context); } +void cbfs_preload_wait_for_all(void) +{ + struct cbfs_preload_context *context; + + list_for_each(context, cbfs_preload_context_list, list_node) + thread_join(&context->handle); +} + static struct cbfs_preload_context *find_cbfs_preload_context(const char *name) { struct cbfs_preload_context *context;