From nobody Mon May 01 21:04:11 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q9G0q2vk1z491J4; Mon, 1 May 2023 21:04:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q9G0q2Rkyz3HkX; Mon, 1 May 2023 21:04:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682975051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HMtSs3ABBn7HI15+LTQTbaR3b0XVROrcanyWpONxqZQ=; b=kq2uvsmjpqXw/p4naAkybydQe4A4ImbYdhFWY4vWV3CkHvGOCCACrUY0t4TUbFsr02vWT5 ctiDY08y5wedu2m2V8JpNfA4j7m9/+wx2Ggz2BJvKqWQj3Ckp5rhGpWwgl5lvvaT60ATOB cOaFP2TrIuZL1QvvFaCiHBAvtf/YLLBN5Of50wGCVGNKy4ia4He+RhvL2yU3qmHQanvD1n uQu68e8rbZvddfFgVeJdXa1ONRy6ik6N7DhWIt/FVVV4OiWx9zjOs35cXnPBRXgxS28zgA vQK5f5+49m3fu7fEnFa45PT06yWwaI4ATSXo97TKyiTttLIW4M1kuX3Ag3YNng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682975051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=HMtSs3ABBn7HI15+LTQTbaR3b0XVROrcanyWpONxqZQ=; b=OGsCy5oHAm0RwXk+l1BlZnmCwyB4vw6Z9VVqKlBvVlS/AZis9yXwI1wny8Ruq3pzK1okd2 ft2EqgvoHA/EKMq8+7Z2lIt4rl0zfG/wtgsReMzmUzhilJijobIHDy0tIa5EGnZtrohtn3 5P6LWZi3aAFLyS0ZIKePG+YuUYCn2CN8lNsdRqRO5hvi9LnX+FUXXBlxAfV2+4VBSyafqH p8NgYpHEP4+EooXYX5IYYp5lTcNbMR0cM6YVCzq7esVh0N5t1pfftRF3t+qlL8v6STSodY Trrw1091cKn4bXba3kauOwAIhM/tCA87tadOn1ib9IGLBrkbG8E04+kzkoHtdg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682975051; a=rsa-sha256; cv=none; b=eChHSkOdSA5/MgMqMjuWoq0tkpIwk4cyvWkXFH0PxySPqHPlNXDT29C+64aksWX/6VUxmL wu2KfRdWer4O3MY6Cxv5SnZ8L6c438dugY+VBD+k/cBuOSA8+ipESEpVvKTso2tK+XLuO/ XzCTSxqbEl35Z9y9jZ/4MaEl0v1NNP8AicCtsDogBcNAzbvYg8u7mT9teNDLol7oxU/tdB rD1F6TfDPwKpMoo4kRDGcWWgTDz9XoN0nNUJ4VyZUk6wHNt7iIHNQBT8O6UNk0pJqJietd tHFF0zBqWztZw0Q4v7Uj/wWF7iCl/V1SFRH6hQXKbMThSQvgt3ZTch3bm0O15A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q9G0q1WCzzLWq; Mon, 1 May 2023 21:04:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 341L4BrU051715; Mon, 1 May 2023 21:04:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 341L4Br9051714; Mon, 1 May 2023 21:04:11 GMT (envelope-from git) Date: Mon, 1 May 2023 21:04:11 GMT Message-Id: <202305012104.341L4Br9051714@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 91ac713b646d - main - stand/boot1.efi: Allow modules to add env variables List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 91ac713b646de667ac149be7dfe06adba4ce55cc Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=91ac713b646de667ac149be7dfe06adba4ce55cc commit 91ac713b646de667ac149be7dfe06adba4ce55cc Author: Warner Losh AuthorDate: 2023-05-01 15:26:31 +0000 Commit: Warner Losh CommitDate: 2023-05-01 21:02:52 +0000 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[];