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
This commit is contained in:
Warner Losh 2023-05-01 09:26:31 -06:00
parent 5f2e84015d
commit 91ac713b64
2 changed files with 23 additions and 0 deletions

View File

@ -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",

View File

@ -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[];