Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1m0gyT-0007qJ-W4 for mharc-grub-devel@gnu.org; Tue, 06 Jul 2021 05:02:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gyR-0007j8-Op for grub-devel@gnu.org; Tue, 06 Jul 2021 05:02:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39982) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gyM-00028S-4R for grub-devel@gnu.org; Tue, 06 Jul 2021 05:02:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625562148; 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=mnLHYgXHtt50Xs1ngR+e1+tNeXwjRrjGMXpMHRoF0QE=; b=ED6EzKCfe3MOLbyJslLce2dLL0lbFom2oXWOejYTdj3L2BpCxvdOzgKSfZ0hLFTZyqo9rh KcQTQMwDW05WCxt4WJSSIPoJx+BctPdiM+cIFzoGma4qDGD7UZ5avWQbfIGwqticGiAzGC Z6YkeTOBDLBPNqTcVp/Ai4+MavGBtFo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-PhzCTyQsNqS32Fy3gdMZRA-1; Tue, 06 Jul 2021 05:02:27 -0400 X-MC-Unique: PhzCTyQsNqS32Fy3gdMZRA-1 Received: by mail-wr1-f69.google.com with SMTP id l12-20020a5d410c0000b029012b4f055c9bso6701725wrp.4 for ; Tue, 06 Jul 2021 02:02:27 -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=mnLHYgXHtt50Xs1ngR+e1+tNeXwjRrjGMXpMHRoF0QE=; b=Pn8uZrWXzJgbVnglgDHS9Dxb39zFAHF4VKsRxxt60JgqaouzqQlLtLL8FjXAZUrVU0 +TvoNVdBgRfKkfCXsImUwtQ46L5LqYjLkeMm0D4NNeBo6s8HRvvXJ59VT/j+yz9JcXPO qNgoEPiNt9HJIDsuyvVC/rbeuhqddK+VhZuPrXAIxOVQ19WdOpNE0vqDTezzaac7PSpq NB6ZEw50/YKgYAWga+NRB+gCsDo/6pHQr5tln6XZncmPVgCsMUZs0sE7mGAfMJVWgrGt O0lBk4M777vqs4kXs3jDIBqihtmVhb8xBWKdSmytWWEpui2uLBc8/MIA/nh8R6tQ6Kmp Tj3g== X-Gm-Message-State: AOAM5301cieDn/jWhUa4EL9fU62zXqXVH/+t0yaH7g5/8zR8nVozNhB2 LtRs6+L9dUGXS156N3aoEP31F51MsdWFMBavFkgRnsxjZDuOnssANqoHz0A6ldlBRH34Yz8P077 KFJg72jqdUbkT7ij9Ha4Bv9E40+ajC13GbTDW4PTeclOR62li9eCirQsDKy/ggA== X-Received: by 2002:adf:d214:: with SMTP id j20mr15966752wrh.392.1625562146346; Tue, 06 Jul 2021 02:02:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRR6XmbokQIPykcr84N+ltEwu8YosK03EPMuzn05pTcr7h/uStUss5+hgHjhNaE1b+OTbQDA== X-Received: by 2002:adf:d214:: with SMTP id j20mr15966731wrh.392.1625562146118; Tue, 06 Jul 2021 02:02:26 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jul 2021 02:02:25 -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 1/2] templates: Check for EFI at runtime instead of config generation time Date: Tue, 6 Jul 2021 11:02:14 +0200 Message-Id: <20210706090215.3724658-2-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:36 -0000 The 30_uefi-firmware template checks if an OsIndicationsSupported UEFI var exists and EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, to decide whether a "fwsetup" menu entry would be added or not to the GRUB menu. But this has the problem that it will only work if the configuration file was created on an UEFI machine that supports booting to a firmware UI. This for example doesn't support creating GRUB config files when executing on systems that support both UEFI and legacy BIOS booting. Since creating the config file from legacy BIOS wouldn't allow to access the firmware UI. To prevent this, make the template to unconditionally create the grub.cfg snippet but check at runtime if was booted through UEFI to decide if this entry should be added. That way it won't be added when booting with BIOS. There's no need to check if EFI_OS_INDICATIONS_BOOT_TO_FW_UI bit is set, since that's already done by the "fwsetup" command when is executed. Signed-off-by: Javier Martinez Canillas --- util/grub.d/30_uefi-firmware.in | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/util/grub.d/30_uefi-firmware.in b/util/grub.d/30_uefi-firmware.in index d344d3883d7..b6041b55e2a 100644 --- a/util/grub.d/30_uefi-firmware.in +++ b/util/grub.d/30_uefi-firmware.in @@ -26,19 +26,14 @@ export TEXTDOMAINDIR="@localedir@" . "$pkgdatadir/grub-mkconfig_lib" -EFI_VARS_DIR=/sys/firmware/efi/efivars -EFI_GLOBAL_VARIABLE=8be4df61-93ca-11d2-aa0d-00e098032b8c -OS_INDICATIONS="$EFI_VARS_DIR/OsIndicationsSupported-$EFI_GLOBAL_VARIABLE" +LABEL="UEFI Firmware Settings" -if [ -e "$OS_INDICATIONS" ] && \ - [ "$(( $(printf 0x%x \'"$(cat $OS_INDICATIONS | cut -b5)"\') & 1 ))" = 1 ]; then - LABEL="UEFI Firmware Settings" +gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2 - gettext_printf "Adding boot menu entry for UEFI Firmware Settings ...\n" >&2 - - cat << EOF -menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { - fwsetup -} -EOF +cat << EOF +if [ "\$grub_platform" = "efi" ]; then + menuentry '$LABEL' \$menuentry_id_option 'uefi-firmware' { + fwsetup + } fi +EOF -- 2.31.1