From 91ac713b646de667ac149be7dfe06adba4ce55cc Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 1 May 2023 09:26:31 -0600 Subject: [PATCH] stand/boot1.efi: Allow modules to add env variables Sometimes filesystem modules need to pass details of the state of the filesystem to later stages of a boot. Provide a generic method to do so. We'll add them after any env variables set in our config files. Sponsored by: Netflix Reviewed by: tsoome, kevans Differential Revision: https://reviews.freebsd.org/D39407 --- stand/efi/boot1/boot1.c | 20 ++++++++++++++++++++ stand/efi/boot1/boot_module.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/stand/efi/boot1/boot1.c b/stand/efi/boot1/boot1.c index 088821ecd1f8..2f9801c8ea92 100644 --- a/stand/efi/boot1/boot1.c +++ b/stand/efi/boot1/boot1.c @@ -96,6 +96,26 @@ try_boot(const boot_module_t *mod, dev_info_t *dev, void *loaderbuf, size_t load buf = NULL; } + /* + * See if there's any env variables the module wants to set. If so, + * append it to any config present. + */ + if (mod->extra_env != NULL) { + const char *env = mod->extra_env(); + if (env != NULL) { + size_t newlen = cmdsize + strlen(env) + 1; + + cmd = realloc(cmd, newlen); + if (cmd == NULL) + goto errout; + if (cmdsize > 0) + strlcat(cmd, " ", newlen); + strlcat(cmd, env, newlen); + cmdsize = strlen(cmd); + free(__DECONST(char *, env)); + } + } + if ((status = BS->LoadImage(TRUE, IH, efi_devpath_last_node(dev->devpath), loaderbuf, loadersize, &loaderhandle)) != EFI_SUCCESS) { printf("Failed to load image provided by %s, size: %zu, (%lu)\n", diff --git a/stand/efi/boot1/boot_module.h b/stand/efi/boot1/boot_module.h index 99046fb53577..4ecfa4c72a83 100644 --- a/stand/efi/boot1/boot_module.h +++ b/stand/efi/boot1/boot_module.h @@ -94,6 +94,9 @@ typedef struct boot_module_t /* valid devices as found by probe. */ dev_info_t *(*devices)(void); + + /* return any environment variables to pass to next stage */ + const char *(*extra_env)(void); } boot_module_t; extern const boot_module_t *boot_modules[];