From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.133]) by mx.groups.io with SMTP id smtpd.web08.5502.1622023963522233645 for ; Wed, 26 May 2021 03:12:43 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@os.amperecomputing.com header.s=selector2 header.b=TLaLi4fN; spf=pass (domain: os.amperecomputing.com, ip: 40.107.94.133, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VndOMmyzvFES2UU6qUqrdytGhmPr2gVSZErsyQCCYdG0jUbVE5QMsn9x65Y/H0TLW8/Dd5Dgfkd3rqbxMQjn5FDVp+4WX9CNoSCQfA7UsBDl5uFM8XaHnWQpqiKpqHllYoKtSJWvp7ovQgadCOUnhFiZpkZgU5oay656Zop7/xltIE3aNRFyVVvOC23r1dZtVPvk4j2lkuofsnB3pRMwNOg2IcA48Mjdw2r5ORwr4KAgWw/UX5x6jBs3S+2fZAn42pd6o4YRFuQPsvKIU8FYu8ylNpOOPU8L9xzYfTeSwkpZGWCqpzb+VCg1RXts8S8PtELK2gn4XasRdLCj2wRymw== 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-SenderADCheck; bh=VRdJMtMCKxXTTZXDt43G9+HdAhIEWFl1vRldhLh6Miw=; b=VIh+zwPkhhQPrcmAVLTjT+FpIySANo6IAY6BFu8SP2uABsmrLBPO8YUUPw/26STZDiHJijihC/xWuVyvMy7pmalWvBKal8unBvR0g/GZ7NH1rw7nTq/J6cG6nAfDE+Jh76LEdFxHDAGPL7pkds0okxcXs8rREwzh7Q9L3PW1aP64jRDXrigqx24a8uK8UOx4G9KZ4xC2SMiTayMsyri7GLLbVHtycQaEWuF3I7mAsJjk+4+cBhqBNAbbGvDYB+Ew0YzQI3qFgPPrOdaAsvjnkNdP4Wa18cTt8Wk7ZDTocuAi4CqdNOJmtdgDcdi7hlmxAlX/H/IDGjuRXOg/18Q8ig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VRdJMtMCKxXTTZXDt43G9+HdAhIEWFl1vRldhLh6Miw=; b=TLaLi4fNX66SJuJbIla8ImijcPxlaKQ7wFaaHsfKGIBBvrgO/EXmPVaEUFnsd3V1yD+JmaeacV6YRexOgRjoy0TTVgh3v9OXL5JX6H7eXuwhs08jnHM7loITzCAdoDQt++BRXabFUfC7O4POis+nNLQ86VPOE9f+UYby9i3oyjs= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM5PR01MB2426.prod.exchangelabs.com (2603:10b6:3:3b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Wed, 26 May 2021 10:12:42 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd%7]) with mapi id 15.20.4173.020; Wed, 26 May 2021 10:12:42 +0000 From: "Nhi Pham" To: devel@edk2.groups.io CC: Vu Nguyen , Thang Nguyen , Chuong Tran , Phong Vo , Leif Lindholm , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: [edk2-platforms][PATCH v2 29/32] JadePkg: Recover boot options when NVRAM cleared Date: Wed, 26 May 2021 17:07:21 +0700 Message-ID: <20210526100724.5359-31-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210526100724.5359-1-nhi@os.amperecomputing.com> References: <20210526100724.5359-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (118.69.219.201) by HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 26 May 2021 10:12:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c1bc7203-9a8a-4c5a-36ec-08d9202eccb2 X-MS-TrafficTypeDiagnostic: DM5PR01MB2426: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X1o9zqmoeWODelwOsaEYvDIhS8llfAtXKjBHfNDIyqIvJckwjIMWpD0iRcq6QKQ23+P0ovngbRpHPjRjYQPoyZxJy/6gUjxuq16xYafFHhARWYhEFwF8FzGrLsRW+oO55MUGsYOuPSbKBiWN0lkpdUzpGSS8zj+6m3GWRlZOHBjhh9zjQ4QQCYiZQlAJu7UouhXwMf+gIaIvhcgWwtTmOBV1ag7z0E+DxRrJxUrA0AuE77L9ZB3CJUdGc0yUm7jwBMZDyDNmAFQ2UDMzKV9O2hmpmpAOI7IdAkFY5Y4vmTTTD3hnPaHGN9/TJmA+nU387y4YibElFgyXMxNxCEC2QCxH+azyUyKMpbmRC+uxcap5sNYynXU7AScG7EC6wI39aATXrybfl1k3NpUf7Eex4L90Wlx3/EpclwGKD1GSMzpyL3IDuv1vHI3xS6iXYh8/ztWRXQdHzyNHiAc4i9mLxLrXDM/GRpYGGNiejJUEJ6D31vNuUyZKkDyT5FVJ9ehDK/PBzROc9oRKem9OmtdRjTX9TMZQ7iYiR2ipwShGVFd3/dHHPyoHHIdQFe3FwKmXdg7wKz/AuALeRiipnPsA10dXeG9OrS62Obt6PU0hrPLCNq50Usq1MS0aNxT5ke1xtHWWwSPA8drEN+Z2+FC3GOPqoSDX8rhbVtJSXCRQg6o+VCuVmbQ7xfkTKRIKnuc1 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39850400004)(136003)(346002)(366004)(376002)(186003)(66476007)(6506007)(2616005)(6486002)(66946007)(52116002)(6916009)(16526019)(38100700002)(38350700002)(1076003)(83380400001)(66556008)(6512007)(956004)(316002)(478600001)(6666004)(4326008)(8676002)(5660300002)(26005)(86362001)(2906002)(8936002)(54906003)(69590400013);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?FhWC+r8FQ0K0a9zyZsXwxQEPeiNffK6w9g7ImQW8pLwDgBWKddcJMLTSPdM7?= =?us-ascii?Q?cz8luUshPmIwXwigIU7XEuiKtg3JVhDi7juuhp1fSfISqZz67kzKgkH+seyJ?= =?us-ascii?Q?dcca0xuT2sOr81djbe5zFySavfFEj+e/XkECsnngaO4J3YFXe4FdeR7mnTdz?= =?us-ascii?Q?ZAqyW7r/bQ1Zs6DwNTx2FihxFn1vyc4sQ8heJ17krEG3qZGkBZHccGuPBq1z?= =?us-ascii?Q?BlNuUTCsX5aHaW6qh7ceOeKwrzzMSat6TvuYwb0JDyuPirh86DU4n8DZWUG7?= =?us-ascii?Q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akdG9Z3P/08hKj28pDW4SZScH?= =?us-ascii?Q?RxqA/yHUdGsqag/Nm9ZSQZqgVL+N6AGSvgMzoXHqzYgoCltER+Bszz0Osmo/?= =?us-ascii?Q?6RqiQ7zPnnjnTrQQcF3IiynlnzUo3SV7tD47hI1NFqo55GBgg5uHWMkVwC0z?= =?us-ascii?Q?sJ8a5foSFGEK1qLgyQgHktXg?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1bc7203-9a8a-4c5a-36ec-08d9202eccb2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 10:12:42.5801 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cS102xfVFncTGPVS+d0nOKNgDyYBOePWH+tfKCOxyF8i1AYcfiwls4obcOgjOIpJzrW1/Y8fSBw85gfWPSJhVMHrGjSYWZ4WKfDCEXj+wGc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR01MB2426 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Vu Nguyen Due to recent changes in EDK2, system without a valid boot options list in NVRAM will enter Platform Recovery mode. As ReadyToBoot event is not triggered in this mode, services like ACPI and PCIe won't be able to do some finalization settings and cause OS fails to boot. This change is to prevent the issue by recovery boot options list each time NVRAM is cleared. Cc: Thang Nguyen Cc: Chuong Tran Cc: Phong Vo Cc: Leif Lindholm Cc: Michael D Kinney Cc: Ard Biesheuvel Cc: Nate DeSimone Signed-off-by: Vu Nguyen --- Platform/Ampere/JadePkg/Jade.dsc = | 5 ++ Platform/Ampere/JadePkg/Jade.fdf = | 5 ++ Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/BootOptionsRecovery= Dxe.inf | 39 +++++++++++++ Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/BootOptionsRecovery= Dxe.c | 58 ++++++++++++++++++++ 4 files changed, 107 insertions(+) diff --git a/Platform/Ampere/JadePkg/Jade.dsc b/Platform/Ampere/JadePkg/Jad= e.dsc index 9d787113e3b5..023f2e898d7f 100755 --- a/Platform/Ampere/JadePkg/Jade.dsc +++ b/Platform/Ampere/JadePkg/Jade.dsc @@ -185,3 +185,8 @@ [Components.common] Silicon/Ampere/AmpereAltraPkg/Drivers/RasConfigDxe/RasConfigDxe.inf Silicon/Ampere/AmpereAltraPkg/Drivers/WatchdogConfigDxe/WatchdogConfigDx= e.inf Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceConf= igDxe.inf + + # + # Misc + # + Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/BootOptionsRecove= ryDxe.inf diff --git a/Platform/Ampere/JadePkg/Jade.fdf b/Platform/Ampere/JadePkg/Jad= e.fdf index b0c2894d00f8..edbead046572 100755 --- a/Platform/Ampere/JadePkg/Jade.fdf +++ b/Platform/Ampere/JadePkg/Jade.fdf @@ -361,4 +361,9 @@ [FV.FvMain] INF Silicon/Ampere/AmpereAltraPkg/Drivers/WatchdogConfigDxe/WatchdogConf= igDxe.inf INF Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDevice= ConfigDxe.inf =20 + # + # Misc + # + INF Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/BootOptionsRe= coveryDxe.inf + !include Platform/Ampere/AmperePlatformPkg/FvRules.fdf.inc diff --git a/Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/BootOpt= ionsRecoveryDxe.inf b/Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDx= e/BootOptionsRecoveryDxe.inf new file mode 100644 index 000000000000..624332339beb --- /dev/null +++ b/Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/BootOptionsRec= overyDxe.inf @@ -0,0 +1,39 @@ +# +# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D BootOptionsRecoveryDxe + FILE_GUID =3D FDCDDC91-4F9E-400C-9BB4-1FE4BE9565B3 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D BootOptionsRecoveryDxeEntry + +[Sources] + BootOptionsRecoveryDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec + +[LibraryClasses] + DebugLib + PcdLib + PrintLib + UefiBootManagerLib + UefiDriverEntryPoint + UefiLib + +[Guids] + gEfiEndOfDxeEventGroupGuid + +[Pcd] + gAmpereTokenSpaceGuid.PcdNvramErased + +[Depex] + gEfiFaultTolerantWriteProtocolGuid diff --git a/Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/BootOpt= ionsRecoveryDxe.c b/Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/= BootOptionsRecoveryDxe.c new file mode 100644 index 000000000000..cd9637ec704e --- /dev/null +++ b/Platform/Ampere/JadePkg/Drivers/BootOptionsRecoveryDxe/BootOptionsRec= overyDxe.c @@ -0,0 +1,58 @@ +/** @file + + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include + +VOID +EFIAPI +RecoveryCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + DEBUG ((DEBUG_INFO, "%a: Do recover boot options\n", __FUNCTION__)); + + EfiBootManagerConnectAll (); + EfiBootManagerRefreshAllBootOption (); + + gBS->CloseEvent (Event); +} + +EFI_STATUS +EFIAPI +BootOptionsRecoveryDxeEntry ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT EndOfDxeEvent; + + DEBUG ((DEBUG_INFO, "%a: NVRAM Clear is %d\n", PcdGetBool (PcdNvramErase= d), __FUNCTION__)); + + if (PcdGetBool (PcdNvramErased)) { + DEBUG ((DEBUG_INFO, "%a: Register event to recover boot options\n", __= FUNCTION__)); + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + RecoveryCallback, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &EndOfDxeEvent + ); + ASSERT_EFI_ERROR (Status); + } + + return Status; +} --=20 2.17.1