From owner-svn-src-all@freebsd.org Wed Aug 26 02:05:59 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 39D653C5539; Wed, 26 Aug 2020 02:05:59 +0000 (UTC) (envelope-from scottph@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Bbq2v0pq7z4VNB; Wed, 26 Aug 2020 02:05:59 +0000 (UTC) (envelope-from scottph@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 003B4BD95; Wed, 26 Aug 2020 02:05:59 +0000 (UTC) (envelope-from scottph@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 07Q25wTQ027680; Wed, 26 Aug 2020 02:05:58 GMT (envelope-from scottph@FreeBSD.org) Received: (from scottph@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07Q25wFp027678; Wed, 26 Aug 2020 02:05:58 GMT (envelope-from scottph@FreeBSD.org) Message-Id: <202008260205.07Q25wFp027678@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: scottph set sender to scottph@FreeBSD.org using -f From: D Scott Phillips Date: Wed, 26 Aug 2020 02:05:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r364795 - head/usr.sbin/efibootmgr X-SVN-Group: head X-SVN-Commit-Author: scottph X-SVN-Commit-Paths: head/usr.sbin/efibootmgr X-SVN-Commit-Revision: 364795 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Aug 2020 02:05:59 -0000 Author: scottph Date: Wed Aug 26 02:05:58 2020 New Revision: 364795 URL: https://svnweb.freebsd.org/changeset/base/364795 Log: efibootmgr: Add option to request booting to the firmware user interface The OsIndications UEFI variable can request the firware to stop at its UI instead of continuing with boot. Add flags for setting and clearing this request. Reviewed by: manu, bcr (manpages) Approved by: scottl (implicit) MFC after: 1 week Sponsored by: Ampere Computing, Inc. Differential Revision: https://reviews.freebsd.org/D25839 Modified: head/usr.sbin/efibootmgr/efibootmgr.8 head/usr.sbin/efibootmgr/efibootmgr.c Modified: head/usr.sbin/efibootmgr/efibootmgr.8 ============================================================================== --- head/usr.sbin/efibootmgr/efibootmgr.8 Wed Aug 26 02:04:04 2020 (r364794) +++ head/usr.sbin/efibootmgr/efibootmgr.8 Wed Aug 26 02:05:58 2020 (r364795) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 23, 2020 +.Dd August 25, 2020 .Dt EFIBOOTMGR 8 .Os .Sh NAME @@ -55,6 +55,10 @@ .Op Fl d .Op Fl p .Nm +.Fl F +.Nm +.Fl f +.Nm .Fl n .Fl b Ar bootnum .Nm @@ -137,6 +141,9 @@ is specified, the UEFI device path to the ESP is repor If .Fl p -unix-path is specified, the mount point of the ESP is reported instead. +.It Fl f -fw-ui , Fl F -no-fw-ui +Set or clear the request to the system firmware to stop in its user +interface on the next boot. .It Fl k -kernel Ar kernel The path to and name of the kernel. .It Fl l -loader Ar loader Modified: head/usr.sbin/efibootmgr/efibootmgr.c ============================================================================== --- head/usr.sbin/efibootmgr/efibootmgr.c Wed Aug 26 02:04:04 2020 (r364794) +++ head/usr.sbin/efibootmgr/efibootmgr.c Wed Aug 26 02:05:58 2020 (r364795) @@ -67,6 +67,8 @@ __FBSDID("$FreeBSD$"); #define BAD_LENGTH ((size_t)-1) +#define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001 + typedef struct _bmgr_opts { char *env; char *loader; @@ -83,6 +85,8 @@ typedef struct _bmgr_opts { bool dry_run; bool device_path; bool esp_device; + bool fw_ui; + bool no_fw_ui; bool has_bootnum; bool once; int cp_src; @@ -110,6 +114,8 @@ static struct option lopts[] = { {"dry-run", no_argument, NULL, 'D'}, {"env", required_argument, NULL, 'e'}, {"esp", no_argument, NULL, 'E'}, + {"fw-ui", no_argument, NULL, 'f'}, + {"no-fw-ui", no_argument, NULL, 'F'}, {"help", no_argument, NULL, 'h'}, {"kernel", required_argument, NULL, 'k'}, {"label", required_argument, NULL, 'L'}, @@ -197,7 +203,7 @@ parse_args(int argc, char *argv[]) { int ch; - while ((ch = getopt_long(argc, argv, "AaBb:C:cdDe:Ehk:L:l:NnOo:pTt:v", + while ((ch = getopt_long(argc, argv, "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:v", lopts, NULL)) != -1) { switch (ch) { case 'A': @@ -232,6 +238,12 @@ parse_args(int argc, char *argv[]) case 'E': opts.esp_device = true; break; + case 'F': + opts.no_fw_ui = true; + break; + case 'f': + opts.fw_ui = true; + break; case 'h': default: errx(1, "%s", USAGE); @@ -825,6 +837,45 @@ print_boot_var(const char *name, bool verbose, bool cu } +static bool +os_indication_supported(uint64_t indication) +{ + uint8_t *data; + size_t size; + uint32_t attrs; + int ret; + + ret = efi_get_variable(EFI_GLOBAL_GUID, "OsIndicationsSupported", &data, + &size, &attrs); + if (ret < 0) + return false; + return (le64dec(data) & indication) == indication; +} + +static uint64_t +os_indications(void) +{ + uint8_t *data; + size_t size; + uint32_t attrs; + int ret; + + ret = efi_get_variable(EFI_GLOBAL_GUID, "OsIndications", &data, &size, + &attrs); + if (ret < 0) + return 0; + return le64dec(data); +} + +static int +os_indications_set(uint64_t mask, uint64_t val) +{ + uint8_t new[sizeof(uint64_t)]; + + le64enc(&new, (os_indications() & ~mask) | (val & mask)); + return set_bootvar("OsIndications", new, sizeof(new)); +} + /* Cmd epilogue, or just the default with no args. * The order is [bootnext] bootcurrent, timeout, order, and the bootvars [-v] */ @@ -841,7 +892,15 @@ print_boot_vars(bool verbose) uint32_t attrs; int ret, bolen; uint16_t *boot_order = NULL, current; + bool boot_to_fw_ui; + if (os_indication_supported(EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) { + boot_to_fw_ui = + (os_indications() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0; + printf("Boot to FW : %s\n", boot_to_fw_ui != 0 ? + "true" : "false"); + } + ret = efi_get_variable(EFI_GLOBAL_GUID, "BootNext", &data, &size, &attrs); if (ret > 0) { printf("BootNext : %04x\n", le16dec(data)); @@ -987,6 +1046,23 @@ report_esp_device(bool do_dp, bool do_unix) exit(0); } +static void +set_boot_to_fw_ui(bool to_fw) +{ + int ret; + + if (!os_indication_supported(EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) { + if (to_fw) + errx(1, "boot to fw ui not supported"); + else + return; + } + ret = os_indications_set(EFI_OS_INDICATIONS_BOOT_TO_FW_UI, + to_fw ? ~0 : 0); + if (ret < 0) + errx(1, "failed to set boot to fw ui"); +} + int main(int argc, char *argv[]) { @@ -1021,6 +1097,10 @@ main(int argc, char *argv[]) handle_timeout(opts.timeout); else if (opts.esp_device) report_esp_device(opts.device_path, opts.unix_path); + else if (opts.fw_ui) + set_boot_to_fw_ui(true); + else if (opts.no_fw_ui) + set_boot_to_fw_ui(false); print_boot_vars(opts.verbose); }