Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1m0gyS-0007kp-9S for mharc-grub-devel@gnu.org; Tue, 06 Jul 2021 05:02:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gyP-0007dy-Uf for grub-devel@gnu.org; Tue, 06 Jul 2021 05:02:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gyM-00028f-GY for grub-devel@gnu.org; Tue, 06 Jul 2021 05:02:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625562149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MqfiJ1PaInSGkkh9ryodhkRdAuVr5emXt28vX8Y3rHo=; b=VgxMh30GPpfZPUWX6ExHJiSHQuy4d/2eQU4ark1/y609JW4LxFldPEKqPcskb8lGznViEL Iqp+E0vjXUGWnJ1Z2RC1f6fAUyk2j/NDYpP3BRs/ARzkDlHqltZafm74zfRTx8jKi1gkUF CVwn+x4cslL78zzNbWaDvO8mK+a9gmY= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-112-E-EMHe_LMY-mHkH2DdpRUw-1; Tue, 06 Jul 2021 05:02:28 -0400 X-MC-Unique: E-EMHe_LMY-mHkH2DdpRUw-1 Received: by mail-wm1-f72.google.com with SMTP id m5-20020a05600c3b05b029020c34fd31cfso832899wms.4 for ; Tue, 06 Jul 2021 02:02:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MqfiJ1PaInSGkkh9ryodhkRdAuVr5emXt28vX8Y3rHo=; b=M7n5JSmiuD3A9JDz3qyuLDaJbwRA5FspLHONOWmInRL+pHjCkQxeqH9VjMHjdR1XsH LVyokd9GrpR2YkkVIQLOSC01zWCmi2AMW5IcF9tu5X/sjqjH3ilAur/FYaX4/+zhSoZt IyqgxYJKuXhMsBuKDIewOHvugu6kPyxleMOxVrkIh3cckRVwr96umRpoFR/a7yeUgeij gYwOF91p1vatzdADX4U56QYS1qUq5IUurw78u3dS7LnExxvzM/PSk+D1XH/5x90zIEFx fzs4xe00D0xZoZ4S6MlcM+OO55Wwa50ktX6bya5I9HewkQ4rPJ8cE8p0MJy2VyZuDfiJ lK9Q== X-Gm-Message-State: AOAM532qZhDNudiun38cK9FfEh9pD8HX+xfps8Ysxt+Glylo0rd3aqWb TXgC9mwtBcS63f9uxabyy9UHborf5cYcZFOWavSX0Yamtu1BJarcCAxRE/T6AyF+elqam6H6JI8 w19iRhb0obxQ/bfB6pV80d5zUeQFjOXNhNbA0SDfd7OsH3vhXsN6VF2/az22pNQ== X-Received: by 2002:a05:6000:1a8f:: with SMTP id f15mr20703011wry.260.1625562147416; Tue, 06 Jul 2021 02:02:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0pkrbZAP17RMaAWpz6B7CxirEbw+WmkG6RGxjkV75anzBdkT29LbeofuNCFktyXGqlvCw8g== X-Received: by 2002:a05:6000:1a8f:: with SMTP id f15mr20702985wry.260.1625562147249; Tue, 06 Jul 2021 02:02:27 -0700 (PDT) Received: from minerva.redhat.com ([92.176.231.106]) by smtp.gmail.com with ESMTPSA id g15sm12224705wmh.16.2021.07.06.02.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 02:02:26 -0700 (PDT) From: Javier Martinez Canillas To: grub-devel@gnu.org Cc: Peter Robinson , Alberto Ruiz , Daniel Kiper , Paul Whalen , Javier Martinez Canillas Subject: [PATCH 2/2] efi: Print an error if boot to firmware setup is not supported Date: Tue, 6 Jul 2021 11:02:15 +0200 Message-Id: <20210706090215.3724658-3-javierm@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210706090215.3724658-1-javierm@redhat.com> References: <20210706090215.3724658-1-javierm@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=javierm@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=170.10.133.124; envelope-from=javierm@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jul 2021 09:02:34 -0000 The "fwsetup" command is only registered if the firmware supports booting to the firmware setup UI. But it could be possible that the GRUB config already contains a "fwsetup" entry, because it was generated in a machine that has support for this feature. To prevent users getting a "can't find command `fwsetup`" error if it is not supported by the firmware, let's just always register the command but print a more accurate message if the firmware doesn't support this option. Signed-off-by: Javier Martinez Canillas --- grub-core/commands/efi/efifwsetup.c | 43 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c index eaca0328388..328c45e82e0 100644 --- a/grub-core/commands/efi/efifwsetup.c +++ b/grub-core/commands/efi/efifwsetup.c @@ -27,6 +27,25 @@ GRUB_MOD_LICENSE ("GPLv3+"); +static grub_efi_boolean_t +efifwsetup_is_supported (void) +{ + grub_efi_uint64_t *os_indications_supported = NULL; + grub_size_t oi_size = 0; + grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; + + grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size, + (void **) &os_indications_supported); + + if (!os_indications_supported) + return 0; + + if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI) + return 1; + + return 0; +} + static grub_err_t grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), @@ -38,6 +57,10 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), grub_size_t oi_size; grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; + if (!efifwsetup_is_supported ()) + return grub_error (GRUB_ERR_INVALID_COMMAND, + N_("Reboot to firmware setup is not supported")); + grub_efi_get_variable ("OsIndications", &global, &oi_size, (void **) &old_os_indications); @@ -56,28 +79,8 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), static grub_command_t cmd = NULL; -static grub_efi_boolean_t -efifwsetup_is_supported (void) -{ - grub_efi_uint64_t *os_indications_supported = NULL; - grub_size_t oi_size = 0; - grub_efi_guid_t global = GRUB_EFI_GLOBAL_VARIABLE_GUID; - - grub_efi_get_variable ("OsIndicationsSupported", &global, &oi_size, - (void **) &os_indications_supported); - - if (!os_indications_supported) - return 0; - - if (*os_indications_supported & GRUB_EFI_OS_INDICATIONS_BOOT_TO_FW_UI) - return 1; - - return 0; -} - GRUB_MOD_INIT (efifwsetup) { - if (efifwsetup_is_supported ()) cmd = grub_register_command ("fwsetup", grub_cmd_fwsetup, NULL, N_("Reboot into firmware setup menu.")); -- 2.31.1