From nobody Sun Feb 19 06:48:28 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 4PKGND51Hnz3srCC; Sun, 19 Feb 2023 06:48:28 +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 4PKGND1m3cz3jZy; Sun, 19 Feb 2023 06:48:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676789308; 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=bvndZf6lbtAxtDi+srG0IfMRcU57l5Wzz3pWdyA+/UA=; b=t7hlbddPRfsoM29QZgYvDBzmbLDGd05LSSFF8ZUGvg4BDZmzSL0sfwWs3i2Fuizi9rDAsI qwuhybTxcZJRtk3y5yuzEIV+46DoV7RmjGOTHEUcacnL/NcsFAYqBoyuu6+Uvpd1qURRbs IX2Mz5v+t+9XUxqlVH8UADFcEOnQWFBG4mPjw4VU64WEnWfVY8zQXE5UQWXdRP+bjTYl4R fPDA5M3YVbqVJ1APzaeWRiVOKif5Ga8D7dvqQdI5NbwRvZgDw6grZzryjh8Nw5oqYBoWYe jKh+UNaJhBOVW6r3U5oLl3tY3qyQxYsabvM9jKrgXbaj5kwgw4CeUjrllR125g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676789308; 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=bvndZf6lbtAxtDi+srG0IfMRcU57l5Wzz3pWdyA+/UA=; b=ShDnm+JMR+r9cFjUphtEHpw28j6Vh3Lzm/nmHahdXQOW+A62tGSSyZ56iNFECl7CEqHmft 14OGGhLmr4l0QM7FFZ5imJ3ph60aclbjj4dNFL2UNxWIZNpi0JoIz6+hgAiSxGrrOtNl48 f4DkMM3aNUf+7Lf/BZ6ROLANmd/vrxkRmOnQDSaBixf5cLxuJ/EiHfBxh5gecqFIuNDQ8/ Wi3+Gjc6UwBCegkB87+itpdNnuNGGzxEXTKdyaVK1qc5ga8KztVufRnY827Jm2peEjPlw5 jU30So01og0UDme2eopOYT1LcJ6cq2nK5PN5E8FeUOMoXhxQtOrDPXUgEg0USA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676789308; a=rsa-sha256; cv=none; b=nEvrVslTjgNZrv+zL7nOBwxYoXjKGS1A6itqBxN9izX9BWeRwYjptLy+DbDocUNr89k9yR eZJ7Gupe8nQCJ4b3Mirb0eNeKZkWG7Wf6e0XONhG3c0XfkpmnzW8as6KosXLMv7NP4+J4i extMCKDcDCiCUbCp9MWT/zOKk64VuP6iQkKPR7YMgvyfaTIgll1cchqkSDfHjBEmp4VGCZ 00nzgD9Z57A4E1U1+RPVaLO+Bnwpcz4zEyDkad9S3qIKoQMHjc8je6folPy6UZuZkOjYeF RxLvtyuxwnzhSJwgLM+KW24NGMpKIChRbUOe8ikr43AtAJaMmSjJO7CwHm8rIg== 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 4PKGND0rvyzsLf; Sun, 19 Feb 2023 06:48:28 +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 31J6mSD7082649; Sun, 19 Feb 2023 06:48:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31J6mSvI082648; Sun, 19 Feb 2023 06:48:28 GMT (envelope-from git) Date: Sun, 19 Feb 2023 06:48:28 GMT Message-Id: <202302190648.31J6mSvI082648@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 1a492583b50e - releng/13.2 - efibootmgr: Add --efidev (-u) to discover UEFI's device path to a dev or file 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/releng/13.2 X-Git-Reftype: branch X-Git-Commit: 1a492583b50e8f74a5834c1c4c5f030162190a85 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.2 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=1a492583b50e8f74a5834c1c4c5f030162190a85 commit 1a492583b50e8f74a5834c1c4c5f030162190a85 Author: Warner Losh AuthorDate: 2023-02-16 16:36:03 +0000 Commit: Warner Losh CommitDate: 2023-02-19 06:47:19 +0000 efibootmgr: Add --efidev (-u) to discover UEFI's device path to a dev or file "efibootmgr --efidev unix-path" will return the UEFI device-path to the file or device specified by unix-path. It's useful for debugging, but may also be useful for scripting. Sponsored by: Netflix Reviewed by: corvink, manu Differential Revision: https://reviews.freebsd.org/D38617 Approved by: re@ (cperciva) (cherry picked from commit 9a7915299484a767fbffc7234b8dc45c29954cca) (cherry picked from commit 8ab17c6dd1d8e8056e5354390f29e0f36cf4e406) --- usr.sbin/efibootmgr/efibootmgr.8 | 6 +++++- usr.sbin/efibootmgr/efibootmgr.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/usr.sbin/efibootmgr/efibootmgr.8 b/usr.sbin/efibootmgr/efibootmgr.8 index 6b53de33db56..0aa70fe63da7 100644 --- a/usr.sbin/efibootmgr/efibootmgr.8 +++ b/usr.sbin/efibootmgr/efibootmgr.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 3, 2022 +.Dd February 15, 2023 .Dt EFIBOOTMGR 8 .Os .Sh NAME @@ -69,6 +69,7 @@ .Fl t Ar timeout .Nm .Fl T +.Nm Fl u Ar unix-path .Sh "DESCRIPTION" The .Nm @@ -174,6 +175,9 @@ Set the bootmenu timeout value. Delete the .Cm BootTimeout variable. +.It Fl u -efidev Ar unix-path +Displays the UEFI device path of +.Ar unix-path . .It Fl v -verbose Display the device path of boot entries in the output. .El diff --git a/usr.sbin/efibootmgr/efibootmgr.c b/usr.sbin/efibootmgr/efibootmgr.c index 53bc417c4e07..58d83d28d6e5 100644 --- a/usr.sbin/efibootmgr/efibootmgr.c +++ b/usr.sbin/efibootmgr/efibootmgr.c @@ -70,6 +70,7 @@ __FBSDID("$FreeBSD$"); #define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001 typedef struct _bmgr_opts { + char *dev; char *env; char *loader; char *label; @@ -85,6 +86,7 @@ typedef struct _bmgr_opts { bool dry_run; bool device_path; bool esp_device; + bool find_dev; bool fw_ui; bool no_fw_ui; bool has_bootnum; @@ -114,6 +116,7 @@ static struct option lopts[] = { {"dry-run", no_argument, NULL, 'D'}, {"env", required_argument, NULL, 'e'}, {"esp", no_argument, NULL, 'E'}, + {"efidev", required_argument, NULL, 'u'}, {"fw-ui", no_argument, NULL, 'f'}, {"no-fw-ui", no_argument, NULL, 'F'}, {"help", no_argument, NULL, 'h'}, @@ -284,6 +287,9 @@ parse_args(int argc, char *argv[]) opts.set_timeout = true; opts.timeout = strtoul(optarg, NULL, 10); break; + case 'u': + opts.find_dev = true; + opts.dev = strdup(optarg); case 'v': opts.verbose = true; break; @@ -996,7 +1002,7 @@ report_esp_device(bool do_dp, bool do_unix) char *name, *dev, *relpath, *abspath; uint8_t *walker, *ep; efi_char *descr; - efidp dp, edp; + efidp dp; char buf[PATH_MAX]; if (do_dp && do_unix) @@ -1026,7 +1032,6 @@ report_esp_device(bool do_dp, bool do_unix) // Now we have fplen bytes worth of file path stuff dp = (efidp)walker; walker += fplen; - edp = (efidp)walker; if (walker > ep) errx(1, "malformed boot variable %s", name); if (do_dp) { @@ -1068,6 +1073,26 @@ set_boot_to_fw_ui(bool to_fw) errx(1, "failed to set boot to fw ui"); } +static void +find_efi_device(const char *path) +{ + efidp dp = NULL; + size_t len; + int ret; + char buf[1024]; + + ret = efivar_unix_path_to_device_path(path, &dp); + if (ret != 0) + errc(1, ret, + "Cannot translate path '%s' to UEFI", path); + len = efidp_size(dp); + if (len > MAX_DP_LEN) + errx(1, "Resulting device path too long."); + efidp_format_device_path(buf, sizeof(buf), dp, len); + printf("%s -> %s\n", path, buf); + exit (0); +} + int main(int argc, char *argv[]) { @@ -1075,7 +1100,10 @@ main(int argc, char *argv[]) memset(&opts, 0, sizeof (bmgr_opts_t)); parse_args(argc, argv); - if (!efi_variables_supported()) + /* + * find_dev can operate without any efi variables + */ + if (!efi_variables_supported() && !opts.find_dev) errx(1, "efi variables not supported on this system. root? kldload efirt?"); read_vars(); @@ -1107,6 +1135,8 @@ main(int argc, char *argv[]) set_boot_to_fw_ui(true); else if (opts.no_fw_ui) set_boot_to_fw_ui(false); + else if (opts.find_dev) + find_efi_device(opts.dev); print_boot_vars(opts.verbose); }