From nobody Sun May 5 09:03:10 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 151187053504687.1256648392789; Tue, 28 Nov 2017 04:02:15 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 97CCD203564CF; Tue, 28 Nov 2017 03:57:50 -0800 (PST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1C8EF203564BE for ; Tue, 28 Nov 2017 03:57:49 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Nov 2017 04:02:12 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.50]) by fmsmga002.fm.intel.com with ESMTP; 28 Nov 2017 04:02:11 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,468,1505804400"; d="scan'208";a="1249439444" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 28 Nov 2017 20:02:06 +0800 Message-Id: <20171128120207.186068-2-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.15.0.gvfs.1.preview.4 In-Reply-To: <20171128120207.186068-1-ruiyu.ni@intel.com> References: <20171128120207.186068-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 1/2] ShellPkg/ShellLib: Fix dynamic command fails to start during boot X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben Carsey MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The previous change in ShellLib: "commit 3d29f8c5e361525a0d2accfa7f5bb0a7210b8927 * ShellPkg/ShellLib: Constructor doesn't depend on ShellParameters" resolved the issue when loading dynamic command driver from Shell environment. But when dynamic command driver is built into FV and started during boot, the driver still fails to start because Shell protocol doesn't exist at that time. The patch changes ShellLib to: 1. Do not look for Shell and ShellParameters protocol when they are non-NULL in ShellLibConstructorWorker(); The two protocols are assumed to be set by DynamicCommand.Handler. When ShellInitialize() is called in DynamicCommand.Handler, this change can prevent the two protocols to be changed to NULL by the locating logic. 2. Do not reset the Shell and ShellParameters protocol to NULL in ShellLibDestructor() when CloseProtocol() fails; Dynamic command driver needs to set the PcdShellLibAutoInitialize to FALSE in order to skip the constructor. Current logic calls ShellLibDestructor() when the PCD is FALSE when ShellInitialize() is called. The change prevent the two protocols to be changed to NULL. The two changes don't impact existing usage case so they are backward compatible. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey Reviewed-by: Jaben Carsey --- ShellPkg/Library/UefiShellLib/UefiShellLib.c | 89 ++++++++++++++++--------= ---- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Librar= y/UefiShellLib/UefiShellLib.c index 00f58ca0c1..7f6389f655 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -179,40 +179,45 @@ ShellLibConstructorWorker ( { EFI_STATUS Status; =20 - // - // UEFI 2.0 shell interfaces (used preferentially) - // - Status =3D gBS->OpenProtocol( - ImageHandle, - &gEfiShellProtocolGuid, - (VOID **)&gEfiShellProtocol, - ImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR(Status)) { + if (gEfiShellProtocol =3D=3D NULL) { // - // Search for the shell protocol + // UEFI 2.0 shell interfaces (used preferentially) // - Status =3D gBS->LocateProtocol( + Status =3D gBS->OpenProtocol ( + ImageHandle, &gEfiShellProtocolGuid, + (VOID **)&gEfiShellProtocol, + ImageHandle, NULL, - (VOID **)&gEfiShellProtocol - ); - if (EFI_ERROR(Status)) { - gEfiShellProtocol =3D NULL; + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + // + // Search for the shell protocol + // + Status =3D gBS->LocateProtocol ( + &gEfiShellProtocolGuid, + NULL, + (VOID **)&gEfiShellProtocol + ); + if (EFI_ERROR (Status)) { + gEfiShellProtocol =3D NULL; + } } } - Status =3D gBS->OpenProtocol( - ImageHandle, - &gEfiShellParametersProtocolGuid, - (VOID **)&gEfiShellParametersProtocol, - ImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR(Status)) { - gEfiShellParametersProtocol =3D NULL; + + if (gEfiShellParametersProtocol =3D=3D NULL) { + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gEfiShellParametersProtocolGuid, + (VOID **)&gEfiShellParametersProtocol, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + gEfiShellParametersProtocol =3D NULL; + } } =20 if (gEfiShellProtocol =3D=3D NULL) { @@ -324,35 +329,45 @@ ShellLibDestructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { + EFI_STATUS Status; + if (mEfiShellEnvironment2 !=3D NULL) { - gBS->CloseProtocol(mEfiShellEnvironment2Handle=3D=3DNULL?ImageHandle:m= EfiShellEnvironment2Handle, + Status =3D gBS->CloseProtocol(mEfiShellEnvironment2Handle=3D=3DNULL?Im= ageHandle:mEfiShellEnvironment2Handle, &gEfiShellEnvironment2Guid, ImageHandle, NULL); - mEfiShellEnvironment2 =3D NULL; + if (!EFI_ERROR (Status)) { + mEfiShellEnvironment2 =3D NULL; + mEfiShellEnvironment2Handle =3D NULL; + } } if (mEfiShellInterface !=3D NULL) { - gBS->CloseProtocol(ImageHandle, + Status =3D gBS->CloseProtocol(ImageHandle, &gEfiShellInterfaceGuid, ImageHandle, NULL); - mEfiShellInterface =3D NULL; + if (!EFI_ERROR (Status)) { + mEfiShellInterface =3D NULL; + } } if (gEfiShellProtocol !=3D NULL) { - gBS->CloseProtocol(ImageHandle, + Status =3D gBS->CloseProtocol(ImageHandle, &gEfiShellProtocolGuid, ImageHandle, NULL); - gEfiShellProtocol =3D NULL; + if (!EFI_ERROR (Status)) { + gEfiShellProtocol =3D NULL; + } } if (gEfiShellParametersProtocol !=3D NULL) { - gBS->CloseProtocol(ImageHandle, + Status =3D gBS->CloseProtocol(ImageHandle, &gEfiShellParametersProtocolGuid, ImageHandle, NULL); - gEfiShellParametersProtocol =3D NULL; + if (!EFI_ERROR (Status)) { + gEfiShellParametersProtocol =3D NULL; + } } - mEfiShellEnvironment2Handle =3D NULL; =20 return (EFI_SUCCESS); } --=20 2.15.0.gvfs.1.preview.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sun May 5 09:03:10 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511870537971831.2849025307925; Tue, 28 Nov 2017 04:02:17 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DCA37203564C5; Tue, 28 Nov 2017 03:57:53 -0800 (PST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E0389203564C5 for ; Tue, 28 Nov 2017 03:57:49 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Nov 2017 04:02:12 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.50]) by fmsmga002.fm.intel.com with ESMTP; 28 Nov 2017 04:02:12 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,468,1505804400"; d="scan'208";a="1249439453" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Tue, 28 Nov 2017 20:02:07 +0800 Message-Id: <20171128120207.186068-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.15.0.gvfs.1.preview.4 In-Reply-To: <20171128120207.186068-1-ruiyu.ni@intel.com> References: <20171128120207.186068-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 2/2] ShellPkg/DynamicCommand: Fix bug that cannot start in boot X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben Carsey MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When dynamic command drivers are built into FV and start during boot, they fails. Because Shell protocol doesn't exist during boot. The patch sets Shell protocol and also set PcdShellLibAutoInitialize to FALSE to ensure that 1. Shell protocol check doesn't happen in driver's entry point. 2. Driver can get the Shell protocol in DynamicCommand.Handler(). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey Reviewed-by: Jaben Carsey --- ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c | 1 + ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c | 1 + ShellPkg/ShellPkg.dsc | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c b/= ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c index 6f3997fff4..b10c59f49c 100644 --- a/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c +++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c @@ -38,6 +38,7 @@ DpCommandHandler ( ) { gEfiShellParametersProtocol =3D ShellParameters; + gEfiShellProtocol =3D Shell; return RunDp (gImageHandle, SystemTable); } =20 diff --git a/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.= c b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c index 928ef08468..9e6489dd6f 100644 --- a/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c @@ -39,6 +39,7 @@ TftpCommandHandler ( ) { gEfiShellParametersProtocol =3D ShellParameters; + gEfiShellProtocol =3D Shell; return RunTftp (gImageHandle, SystemTable); } =20 diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc index 65e8959455..86382139a5 100644 --- a/ShellPkg/ShellPkg.dsc +++ b/ShellPkg/ShellPkg.dsc @@ -120,9 +120,14 @@ [Components] !endif #$(NO_SHELL_PROFILES) } =20 - ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf + ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE PerformanceLib|MdeModulePkg/Library/DxeSmmPerformanceLib/DxeSmmPerfo= rmanceLib.inf } --=20 2.15.0.gvfs.1.preview.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel