Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oOjZl-0004Ls-CN for mharc-grub-devel@gnu.org; Thu, 18 Aug 2022 13:45:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOjZi-0004JA-IK for grub-devel@gnu.org; Thu, 18 Aug 2022 13:44:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOjZf-0000ti-Qy for grub-devel@gnu.org; Thu, 18 Aug 2022 13:44:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660844695; 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=ZYhMJzjsfA0L5LNZkzgJg5imDu5gecko5Ft48AhdEOs=; b=FL8MtOgvF8qPyDYxc/Y4NYGuspFbUqocxW9AwbfTD/N3v8Zb3sH9HDpWhgjb/WK1VwZh4m nxyD2buZi34BFeWtmqSSBXCogr5cxt4jJixTYqJNhtZaEdU2Up6awrFarhavztW+Fmlt/H /aJ3b0MDWVFQ6SwtGj6srWZ02oYosbQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-156-y9kXgZPyMe2v3LbbDUYGdg-1; Thu, 18 Aug 2022 13:44:51 -0400 X-MC-Unique: y9kXgZPyMe2v3LbbDUYGdg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EFAB8811E81; Thu, 18 Aug 2022 17:44:50 +0000 (UTC) Received: from eesha.redhat.com (unknown [10.22.10.250]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1573492CA4; Thu, 18 Aug 2022 17:44:50 +0000 (UTC) From: Robbie Harwood To: grub-devel@gnu.org Cc: dkiper@net-space.pl, pmenzel@molgen.mpg.de, javierm@redhat.com, development@efficientek.com, Robbie Harwood Subject: [PATCH v3 4/5] efi: Print an error if boot to firmware setup is not supported Date: Thu, 18 Aug 2022 13:44:36 -0400 Message-Id: <20220818174437.82289-4-rharwood@redhat.com> In-Reply-To: <20220818174437.82289-1-rharwood@redhat.com> References: <20220818174027.25516-1-rharwood@redhat.com> <20220818174437.82289-1-rharwood@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Received-SPF: pass client-ip=170.10.133.124; envelope-from=rharwood@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2022 17:44:59 -0000 From: Javier Martinez Canillas 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 an error like: error: ../../grub-core/script/function.c:109:can't find command `fwsetup'. 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 Signed-off-by: Robbie Harwood --- grub-core/commands/efi/efifwsetup.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/grub-core/commands/efi/efifwsetup.c b/grub-core/commands/efi/efifwsetup.c index 51bb2ace3b..cb4b6ff18c 100644 --- a/grub-core/commands/efi/efifwsetup.c +++ b/grub-core/commands/efi/efifwsetup.c @@ -27,6 +27,8 @@ GRUB_MOD_LICENSE ("GPLv3+"); +static grub_efi_boolean_t efifwsetup_is_supported (void); + static grub_err_t grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), @@ -38,6 +40,10 @@ grub_cmd_fwsetup (grub_command_t cmd __attribute__ ((unused)), grub_size_t oi_size; static 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 by the current firmware")); + grub_efi_get_variable ("OsIndications", &global, &oi_size, (void **) &old_os_indications); @@ -82,10 +88,8 @@ efifwsetup_is_supported (void) GRUB_MOD_INIT (efifwsetup) { - if (efifwsetup_is_supported ()) - cmd = grub_register_command ("fwsetup", grub_cmd_fwsetup, NULL, - N_("Reboot into firmware setup menu.")); - + cmd = grub_register_command ("fwsetup", grub_cmd_fwsetup, NULL, + N_("Reboot into firmware setup menu.")); } GRUB_MOD_FINI (efifwsetup) -- 2.35.1