From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.41]) by mx.groups.io with SMTP id smtpd.web11.52080.1674149765892891345 for ; Thu, 19 Jan 2023 09:36:06 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=bwYXSjls; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.236.41, mailfrom: jeshuas@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OfipYmz7s6C1DKQlGcqYnxYUMHLk/7vC0YvMaHimFuedNLBCn41OFjgQChXLvE0DWC5tDafVafHNYqZq8yGB0SXukGY2Q3JNPA0rx5tVC4nIi5QqqSr3DVGLqnkPKUgynpLSq4qo0uu8TadYPaZee6yM4CfsQrHyti5lPtf33CJ5tU9b6T898MlqJ1GvTMQiBNJyskJcCZKqD7Mkrn+bQL4cu6XDyhLAva+Uoijkm5MRngfhLmghyT7cSuLxbQSZ7CiVdGFewe+n0Sae16v3ZjV48Wnm1fISrgrVuoUmf5UAFRe8MLe82FStKFwDeRzNPdXkfdXCI6TRH4KJ3H1a6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+34G/hRp7+wHcgnHygKh8RtDwGmNaLu1YmQRbww5c/k=; b=WtBbRSq99CkG1V/3h/CzA9qUF7LMlQ3d0zoF6dzVbHKce/mgMNt+bFJ5buRTt0zqXBkIFoWnpv3xcU+0NA7rmW9J2hERJWgfGgd/CodI5tYLbUhPSa1Q+wpmh0njIqMwnpP815v5R+gwtMVPU5n5Xva416Xqj422jbeFkO7bBJBTFC30hAzy/qjurc8yExJO2OtgotIOgAo4jkQDhdvqE9HJwaLPbvbqsKsHxvDTNYf0zFEGA9IZfd+CdP2ZkuhtFTTHs2AZzdDiNd5W0VCxjAExN3NHBxPYnUrZ4DJNQca+/CvKkMyg8TRdMyY9HnF473ZGjLe/Wnw05Ok9fq8Elw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+34G/hRp7+wHcgnHygKh8RtDwGmNaLu1YmQRbww5c/k=; b=bwYXSjlsl+QFF9oFRyxxF8joIQzDfpxCekP80a5Q+wHLDyRfBnL1XuYZGtnnuvQo5vlhR48iDgDs7GFL9rKduaySfBU7/e8eNz+Kjv+wlJmrQ23hiYGsDaLj9XpKwAePUYJuhX/GeSAmXQ447EVBXDqS86s5cXIQ1t3LhBjYJ6L7T71XeRex5mZOmywexVbhdlO6kXnvIU2PuNojcUjzIKB0XBx8sI6PRyiIinxpZ/RRgyxPf3iaDE9HFGBQDO3BTorR8WXK19lc8f2bTyOk8fr53PrSaiJGRZvHQfTN6328b7+mmixCyghCEgRsatAdo8vvZnLEWMNnWuF976KUUg== Received: from DS7PR03CA0181.namprd03.prod.outlook.com (2603:10b6:5:3b6::6) by CH0PR12MB5041.namprd12.prod.outlook.com (2603:10b6:610:e0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.26; Thu, 19 Jan 2023 17:36:03 +0000 Received: from DM6NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b6:cafe::ab) by DS7PR03CA0181.outlook.office365.com (2603:10b6:5:3b6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.19 via Frontend Transport; Thu, 19 Jan 2023 17:36:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT050.mail.protection.outlook.com (10.13.173.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6023.16 via Frontend Transport; Thu, 19 Jan 2023 17:36:03 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 19 Jan 2023 09:35:51 -0800 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 19 Jan 2023 09:35:51 -0800 Received: from build-jeshuas-20221215T071333555.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Thu, 19 Jan 2023 09:35:50 -0800 From: "Jeshua Smith" To: CC: , , , , Jeshua Smith Subject: [PATCH] MdeModulePkg: allow PlatformBootManagerLib to use BootNext Date: Thu, 19 Jan 2023 17:35:33 +0000 Message-ID: <35e417f3ded0035bb51371bed3627393672a57d2.1674149644.git.jeshuas@nvidia.com> X-Mailer: git-send-email 2.17.1 X-NVConfidentiality: public Return-Path: jeshuas@nvidia.com MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT050:EE_|CH0PR12MB5041:EE_ X-MS-Office365-Filtering-Correlation-Id: 90fb738e-eb48-46f3-2400-08dafa43a317 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tXYGyF/sOvERMlTywGVshJLsX+0UILk+qbQdjeUCm3gk9c5xNbIXf4TzsFeAE1Zyfa4pJ3bMMEJuKccXSdXFrDTqekrZbhrfBj/jkyifq8UxA5hl+y5CgBJHnr5PIU3yWdOOhHkN11pzgkGkETV2NCzvSzPPj5Rsl9UZY2U3eGlarGf99Nzv7EVqjY8SNXVReAboLUPr3sbpnyrO55dZVkJPO7+ZeLHmKb5DpQvUUJRVanmh54r9SlPwi/+9RZdIzuZVEpagIDuO+9GAQv9nMoh3g1sAecySmq0b/ASJ01VfVU+QGMOx86LHzKGJXXC0SCrYLYS30ivST76Ow1B5k60jdhx5a2UCk9vBDQKwUebIxb1kLXU7dyp3LoEDP6uR5btgD6og4TLyTD18096+1Mn6Pj4LHP46hS0xAN+q3PX7wtfnOGRR2YKA5YD3NS3mju4tpdVnb04Qh7e5FfsBigDg6MxR0TekZFUHqpJimnnBl+LaAm6fzJIsg5CxxnuxecLFLUiuRkMpyfFrMGGcvBHA5SVYEEgV1J9vMeETRqjOJR5iMFpxsSM3cbuJDhEVwg8Fzv06AIn6SWdIJ6uqbB7rlEX3cVqV7IOocbJBzNtx9a4YGIxgQV/NhXcYgqy2k4F/0ypE4UbG5Fgin/PnUPg+UNzb3CTpuYdj+lXTsnlBPXvSe9pKcL1Kqtkmk/+/xWn0YrA9n1biNZpNlVziWA== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(346002)(39860400002)(136003)(451199015)(36840700001)(46966006)(40470700004)(19627235002)(54906003)(316002)(7636003)(82740400003)(2616005)(4326008)(5660300002)(8936002)(426003)(6916009)(41300700001)(8676002)(36756003)(26005)(186003)(83380400001)(47076005)(70586007)(70206006)(40460700003)(107886003)(40480700001)(6666004)(82310400005)(356005)(336012)(86362001)(2906002)(36860700001)(478600001)(7696005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jan 2023 17:36:03.0739 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90fb738e-eb48-46f3-2400-08dafa43a317 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5041 Content-Type: text/plain Currently BdsEntry caches BootNext before calling PlatformBootManagerLib APIs, with the result that: - If BootNext is already set, a BootNext value written by the APIs will be ignored and deleted, and the current boot will use the cached BootNext value. - If BootNext is not present, a BootNext value written by the APIs will have no effect on the current boot, but will be used by the next boot. This patch adds PcdAllowBootNextFromPlatformBootManagerLib so that a platform can enable PlatformBootManagerLib API calls to set BootNext to control the current boot. - If the PCD is FALSE (default), there is no change. - If the PCD is TRUE, then a BootNext value written by the PlatformBootManagerLib APIs will affect the current boot. Signed-off-by: Jeshua Smith --- MdeModulePkg/MdeModulePkg.dec | 7 +++++ MdeModulePkg/Universal/BdsDxe/BdsDxe.inf | 27 ++++++++++--------- MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 34 ++++++++++++++++++------ 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 9605c617b7..0e74131712 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -1093,6 +1093,13 @@ # @Prompt Enable UEFI Stack Guard. gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055 + ## Indicates whether PlatformBootManagerLib code can set BootNext for the current boot. + # If enabled, setting BootNext in PlatformBootManagerLib controls the current boot.

+ # TRUE - BootNext value from PlatformBootManagerLib will affect the current boot.
+ # FALSE - BootNext value from PlatformBootManagerLib will affect the subsequent boot (or be ignored if already set).
+ # @Prompt Allow PlatformBootManagerLib to set BootNext for the current boot. + gEfiMdeModulePkgTokenSpaceGuid.PcdAllowBootNextFromPlatformBootManagerLib|FALSE|BOOLEAN|0x30001056 + [PcdsFixedAtBuild, PcdsPatchableInModule] ## Dynamic type PCD can be registered callback function for Pcd setting action. # PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum number of callback function diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf index 5bac635def..b7a3560f5f 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf @@ -85,19 +85,20 @@ gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES [Pcd] - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangCodes ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLang ## SOMETIMES_CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLangCodes ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdHardwareErrorRecordLevel ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareRevision ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable ## SOMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangCodes ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLang ## SOMETIMES_CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLangCodes ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdHardwareErrorRecordLevel ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareRevision ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdConInConnectOnDemand ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleOnDiskSupport ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdPlatformRecoverySupport ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdAllowBootNextFromPlatformBootManagerLib ## CONSUMES [Depex] TRUE diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c index 766dde3aae..6450406cce 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c @@ -787,15 +787,19 @@ BdsEntry ( // // Cache the "BootNext" NV variable before calling any PlatformBootManagerLib APIs - // This could avoid the "BootNext" set by PlatformBootManagerLib be consumed in this boot. - // - GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **)&BootNext, &DataSize); - if (DataSize != sizeof (UINT16)) { - if (BootNext != NULL) { - FreePool (BootNext); - } + // if the Platform isn't allowed to override BootNext. + // If "BootNext" was already set, a "BootNext" value set in PlatformBootManagerLib APIs + // will be ignored; otherwise it will not take effect until the next boot. + // + if (!PcdGetBool (PcdAllowBootNextFromPlatformBootManagerLib)) { + GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **)&BootNext, &DataSize); + if (DataSize != sizeof (UINT16)) { + if (BootNext != NULL) { + FreePool (BootNext); + } - BootNext = NULL; + BootNext = NULL; + } } // @@ -1048,6 +1052,20 @@ BdsEntry ( EfiBootManagerHotkeyBoot (); + // + // If PlatformBootManagerLib APIs are allowed to override BootNext, read it just before use + // + if (PcdGetBool (PcdAllowBootNextFromPlatformBootManagerLib)) { + GetEfiGlobalVariable2 (EFI_BOOT_NEXT_VARIABLE_NAME, (VOID **)&BootNext, &DataSize); + if (DataSize != sizeof (UINT16)) { + if (BootNext != NULL) { + FreePool (BootNext); + } + + BootNext = NULL; + } + } + if (BootNext != NULL) { // // Delete "BootNext" NV variable before transferring control to it to prevent loops. -- 2.17.1