From nobody Wed Dec 25 01:18:33 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 1511762141503994.5380521551335; Sun, 26 Nov 2017 21:55:41 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9AFF721A1099D; Sun, 26 Nov 2017 21:51:18 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 0D8C421A1099A for ; Sun, 26 Nov 2017 21:51:15 -0800 (PST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Nov 2017 21:55:36 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.15]) by orsmga005.jf.intel.com with ESMTP; 26 Nov 2017 21:55:35 -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.31; helo=mga06.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,463,1505804400"; d="scan'208";a="178109689" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Mon, 27 Nov 2017 13:55:31 +0800 Message-Id: <20171127055532.320556-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.15.0.gvfs.1.preview.4 In-Reply-To: <20171127055532.320556-1-ruiyu.ni@intel.com> References: <20171127055532.320556-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH v2 2/3] ShellPkg/tftp: Convert from NULL class library to Dynamic Command 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 , Michael D Kinney 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" UEFI Shell spec defines Shell Dynamic Command protocol which is just for the purpose to extend internal command. So tftp command is changed from NULL class library to be a driver producing DynamicCommand protocol. The guideline is: 1. Only use NULL class library for Shell spec defined commands. 2. New commands can be provided as not only a standalone application but also a dynamic command. So it can be used either as an internal command, but also as a standalone application. TftpApp.inf is to provide a standalone application. TftpDynamicCommand.inf is to provide a standalone driver producing Dynamic Command protocol. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey Cc: Michael D Kinney --- .../TftpDynamicCommand}/Tftp.c | 92 +++++++++++---- .../TftpDynamicCommand/Tftp.h} | 40 +++++-- .../TftpDynamicCommand/Tftp.uni} | 0 .../DynamicCommand/TftpDynamicCommand/TftpApp.c | 54 +++++++++ .../TftpDynamicCommand/TftpApp.inf} | 34 +++--- .../TftpDynamicCommand/TftpDynamicCommand.c | 131 +++++++++++++++++= ++++ .../TftpDynamicCommand/TftpDynamicCommand.inf} | 39 +++--- .../UefiShellTftpCommandLib.c | 97 --------------- ShellPkg/ShellPkg.dsc | 11 +- 9 files changed, 325 insertions(+), 173 deletions(-) rename ShellPkg/{Library/UefiShellTftpCommandLib =3D> DynamicCommand/TftpD= ynamicCommand}/Tftp.c (91%) mode change 100755 =3D> 100644 rename ShellPkg/{Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.h= =3D> DynamicCommand/TftpDynamicCommand/Tftp.h} (56%) rename ShellPkg/{Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.u= ni =3D> DynamicCommand/TftpDynamicCommand/Tftp.uni} (100%) create mode 100644 ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.c copy ShellPkg/{Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf= =3D> DynamicCommand/TftpDynamicCommand/TftpApp.inf} (59%) create mode 100644 ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicC= ommand.c rename ShellPkg/{Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.i= nf =3D> DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf} (55%) delete mode 100644 ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpC= ommandLib.c diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c b/ShellPkg/Dyn= amicCommand/TftpDynamicCommand/Tftp.c old mode 100755 new mode 100644 similarity index 91% rename from ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c rename to ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c index fbde3bfe60..8569c966dd --- a/ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c @@ -2,7 +2,7 @@ The implementation for the 'tftp' Shell command. =20 Copyright (c) 2015, ARM Ltd. All rights reserved.
- Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
=20 This program and the accompanying materials @@ -14,9 +14,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. **/ =20 -#include "UefiShellTftpCommandLib.h" +#include "Tftp.h" =20 #define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH 32 +EFI_HANDLE mTftpHiiHandle; =20 /* Constant strings and definitions related to the message indicating the = amount of @@ -256,8 +257,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] =3D { =20 **/ SHELL_STATUS -EFIAPI -ShellCommandRunTftp ( +RunTftp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) @@ -315,7 +315,7 @@ ShellCommandRunTftp ( if ((Status =3D=3D EFI_VOLUME_CORRUPTED) && (ProblemParam !=3D NULL) ) { ShellPrintHiiEx ( - -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellTftpHiiHandle, + -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), mTftpHiiHandle, L"tftp", ProblemParam ); FreePool (ProblemParam); @@ -332,14 +332,14 @@ ShellCommandRunTftp ( if (ParamCount > 4) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), - gShellTftpHiiHandle, L"tftp" + mTftpHiiHandle, L"tftp" ); goto Error; } if (ParamCount < 3) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), - gShellTftpHiiHandle, L"tftp" + mTftpHiiHandle, L"tftp" ); goto Error; } @@ -354,7 +354,7 @@ ShellCommandRunTftp ( if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), - gShellTftpHiiHandle, L"tftp", ValueStr + mTftpHiiHandle, L"tftp", ValueStr ); goto Error; } @@ -416,7 +416,7 @@ ShellCommandRunTftp ( if (Mtftp4ConfigData.TimeoutValue =3D=3D 0) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), - gShellTftpHiiHandle, L"tftp", ValueStr + mTftpHiiHandle, L"tftp", ValueStr ); goto Error; } @@ -430,7 +430,7 @@ ShellCommandRunTftp ( if (BlockSize < MTFTP_MIN_BLKSIZE || BlockSize > MTFTP_MAX_BLKSIZE) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), - gShellTftpHiiHandle, L"tftp", ValueStr + mTftpHiiHandle, L"tftp", ValueStr ); goto Error; } @@ -450,7 +450,7 @@ ShellCommandRunTftp ( if (EFI_ERROR (Status) || (HandleCount =3D=3D 0)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NO_NIC), - gShellTftpHiiHandle + mTftpHiiHandle ); goto Error; } @@ -465,7 +465,7 @@ ShellCommandRunTftp ( if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NAME), - gShellTftpHiiHandle, NicNumber, Status + mTftpHiiHandle, NicNumber, Status ); continue; } @@ -487,7 +487,7 @@ ShellCommandRunTftp ( if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_OPEN_PROTOCOL), - gShellTftpHiiHandle, NicName, Status + mTftpHiiHandle, NicName, Status ); continue; } @@ -496,7 +496,7 @@ ShellCommandRunTftp ( if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_CONFIGURE), - gShellTftpHiiHandle, NicName, Status + mTftpHiiHandle, NicName, Status ); goto NextHandle; } @@ -505,7 +505,7 @@ ShellCommandRunTftp ( if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_FILE_SIZE), - gShellTftpHiiHandle, RemoteFilePath, NicName, Status + mTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } @@ -514,7 +514,7 @@ ShellCommandRunTftp ( if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD), - gShellTftpHiiHandle, RemoteFilePath, NicName, Status + mTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } @@ -534,7 +534,7 @@ ShellCommandRunTftp ( if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), - gShellTftpHiiHandle, L"tftp", LocalFilePath + mTftpHiiHandle, L"tftp", LocalFilePath ); goto NextHandle; } @@ -546,7 +546,7 @@ ShellCommandRunTftp ( } else { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_WRITE), - gShellTftpHiiHandle, LocalFilePath, Status + mTftpHiiHandle, LocalFilePath, Status ); } ShellCloseFile (&FileHandle); @@ -568,7 +568,7 @@ ShellCommandRunTftp ( if ((UserNicName !=3D NULL) && (!NicFound)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NOT_FOUND), - gShellTftpHiiHandle, UserNicName + mTftpHiiHandle, UserNicName ); } =20 @@ -607,7 +607,7 @@ StringToUint16 ( if (Val > MAX_UINT16) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), - gShellTftpHiiHandle, L"tftp", ValueStr + mTftpHiiHandle, L"tftp", ValueStr ); return FALSE; } @@ -948,13 +948,13 @@ DownloadFile ( =20 ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_DOWNLOADING), - gShellTftpHiiHandle, FilePath + mTftpHiiHandle, FilePath ); =20 Status =3D Mtftp4->ReadFile (Mtftp4, &Mtftp4Token); ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), - gShellTftpHiiHandle + mTftpHiiHandle ); =20 Error : @@ -1052,3 +1052,51 @@ CheckPacket ( =20 return EFI_SUCCESS; } + +/** + Retrive HII package list from ImageHandle and publish to HII database. + + @param ImageHandle The image handle of the process. + + @return HII handle. +**/ +EFI_HANDLE +InitializeHiiPackage ( + EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_HII_PACKAGE_LIST_HEADER *PackageList; + EFI_HANDLE HiiHandle; + + // + // Retrieve HII package list from ImageHandle + // + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gEfiHiiPackageListProtocolGuid, + (VOID **)&PackageList, + ImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + + // + // Publish HII package list to HII Database. + // + Status =3D gHiiDatabase->NewPackageList ( + gHiiDatabase, + PackageList, + NULL, + &HiiHandle + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + return HiiHandle; +} diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandL= ib.h b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.h similarity index 56% rename from ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLi= b.h rename to ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.h index 6767f95166..9963eab3eb 100644 --- a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.h +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.h @@ -1,7 +1,7 @@ /** @file - header file for NULL named library for 'tftp' Shell command functions. + Header file for 'tftp' command functions. =20 - Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
Copyright (c) 2015, ARM Ltd. All rights reserved.
=20 This program and the accompanying materials @@ -14,13 +14,12 @@ =20 **/ =20 -#ifndef _UEFI_SHELL_TFTP_COMMAND_LIB_H_ -#define _UEFI_SHELL_TFTP_COMMAND_LIB_H_ +#ifndef _TFTP_H_ +#define _TFTP_H_ =20 #include =20 -#include - +#include #include #include =20 @@ -28,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -36,8 +34,9 @@ #include #include #include +#include =20 -extern EFI_HANDLE gShellTftpHiiHandle; +extern EFI_HANDLE mTftpHiiHandle; =20 typedef struct { UINTN FileSize; @@ -48,14 +47,29 @@ typedef struct { /** Function for 'tftp' command. =20 - @param[in] ImageHandle Handle to the Image (NULL if Internal). - @param[in] SystemTable Pointer to the System Table (NULL if Internal). + @param[in] ImageHandle The image handle. + @param[in] SystemTable The system table. + + @retval SHELL_SUCCESS Command completed successfully. + @retval SHELL_INVALID_PARAMETER Command usage error. + @retval SHELL_ABORTED The user aborts the operation. + @retval value Unknown error. **/ SHELL_STATUS -EFIAPI -ShellCommandRunTftp ( +RunTftp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ); =20 -#endif /* _UEFI_SHELL_TFTP_COMMAND_LIB_H_ */ +/** + Retrive HII package list from ImageHandle and publish to HII database. + + @param ImageHandle The image handle of the process. + + @return HII handle. +**/ +EFI_HANDLE +InitializeHiiPackage ( + EFI_HANDLE ImageHandle + ); +#endif // _TFTP_H_ diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandL= ib.uni b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.uni similarity index 100% rename from ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLi= b.uni rename to ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.uni diff --git a/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.c b/ShellPk= g/DynamicCommand/TftpDynamicCommand/TftpApp.c new file mode 100644 index 0000000000..23f2bf7d9b --- /dev/null +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.c @@ -0,0 +1,54 @@ +/** @file + Entrypoint of "tftp" shell standalone application. + + Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2015, ARM Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ +#include "Tftp.h" + +// +// String token ID of help message text. +// Shell supports to find help message in the resource section of an appli= cation image if +// .MAN file is not found. This global variable is added to make build too= l recognizes +// that the help string is consumed by user and then build tool will add t= he string into +// the resource section. Thus the application can use '-?' option to show = help message in +// Shell. +// +GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mStringHelpTokenId =3D STRING_= TOKEN (STR_GET_HELP_TFTP); + +/** + Entry point of Tftp standalone application. + + @param ImageHandle The image handle of the process. + @param SystemTable The EFI System Table pointer. + + @retval EFI_SUCCESS Tftp command is executed sucessfully. + @retval EFI_ABORTED HII package was failed to initialize. + @retval others Other errors when executing tftp command. +**/ +EFI_STATUS +EFIAPI +TftpAppInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + mTftpHiiHandle =3D InitializeHiiPackage (ImageHandle); + if (mTftpHiiHandle =3D=3D NULL) { + return EFI_ABORTED; + } + + Status =3D (EFI_STATUS)RunTftp (ImageHandle, SystemTable); + HiiRemovePackages (mTftpHiiHandle); + return Status; +} diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandL= ib.inf b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf similarity index 59% copy from ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.= inf copy to ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf index 96db258920..185bd4557a 100644 --- a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf @@ -1,7 +1,7 @@ ## @file -# Provides Shell 'tftp' command functions +# Provides Shell 'tftp' standalone application. # -# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.
+# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
# Copyright (c) 2015, ARM Ltd. All rights reserved.
# # This program and the accompanying materials @@ -16,19 +16,21 @@ =20 [Defines] INF_VERSION =3D 0x00010006 - BASE_NAME =3D UefiShellTftpCommandLib - FILE_GUID =3D D2B61A25-9835-4E5D-906A-15615E1FF668 + BASE_NAME =3D tftp + FILE_GUID =3D 8DC58D0D-67F5-4B97-9DFC-E442BB9A5648 MODULE_TYPE =3D UEFI_APPLICATION VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D NULL|UEFI_APPLICATION UEFI_DRIVER - CONSTRUCTOR =3D ShellTftpCommandLibConstructor - DESTRUCTOR =3D ShellTftpCommandLibDestructor + ENTRY_POINT =3D TftpAppInitialize +# +# This flag specifies whether HII resource section is generated into PE i= mage. +# + UEFI_HII_RESOURCE_SECTION =3D TRUE =20 [Sources.common] - UefiShellTftpCommandLib.uni - UefiShellTftpCommandLib.c - UefiShellTftpCommandLib.h + Tftp.uni + Tftp.h Tftp.c + TftpApp.c =20 [Packages] MdePkg/MdePkg.dec @@ -40,22 +42,18 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib - ShellCommandLib ShellLib UefiLib UefiRuntimeServicesTableLib UefiBootServicesTableLib - PcdLib + UefiApplicationEntryPoint + UefiHiiServicesLib HiiLib FileHandleLib NetLib =20 -[Pcd] - gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask ## CONSUMES - [Protocols] gEfiManagedNetworkServiceBindingProtocolGuid ## CONSUMES gEfiMtftp4ServiceBindingProtocolGuid ## CONSUMES - -[Guids] - gShellTftpHiiGuid ## CONSUMES ## HII + gEfiMtftp4ProtocolGuid ## CONSUMES + gEfiHiiPackageListProtocolGuid ## CONSUMES diff --git a/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.= c b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c new file mode 100644 index 0000000000..928ef08468 --- /dev/null +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c @@ -0,0 +1,131 @@ +/** @file + Produce "tftp" shell dynamic command. + + Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2015, ARM Ltd. All rights reserved.
+ + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ +#include "Tftp.h" +#include + +/** + This is the shell command handler function pointer callback type. This + function handles the command when it is invoked in the shell. + + @param[in] This The instance of the EFI_SHELL_DYNAMIC_= COMMAND_PROTOCOL. + @param[in] SystemTable The pointer to the system table. + @param[in] ShellParameters The parameters associated with the com= mand. + @param[in] Shell The instance of the shell protocol use= d in the context + of processing this command. + + @return EFI_SUCCESS the operation was sucessful + @return other the operation failed. +**/ +SHELL_STATUS +EFIAPI +TftpCommandHandler ( + IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, + IN EFI_SYSTEM_TABLE *SystemTable, + IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, + IN EFI_SHELL_PROTOCOL *Shell + ) +{ + gEfiShellParametersProtocol =3D ShellParameters; + return RunTftp (gImageHandle, SystemTable); +} + +/** + This is the command help handler function pointer callback type. This + function is responsible for displaying help information for the associat= ed + command. + + @param[in] This The instance of the EFI_SHELL_DYNAMIC_= COMMAND_PROTOCOL. + @param[in] Language The pointer to the language string to = use. + + @return string Pool allocated help string, must be fr= eed by caller +**/ +CHAR16 * +EFIAPI +TftpCommandGetHelp ( + IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, + IN CONST CHAR8 *Language + ) +{ + return HiiGetString (mTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP), L= anguage); +} + +EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mTftpDynamicCommand =3D { + L"tftp", + TftpCommandHandler, + TftpCommandGetHelp +}; + +/** + Entry point of Tftp Dynamic Command. + + Produce the DynamicCommand protocol to handle "tftp" command. + + @param ImageHandle The image handle of the process. + @param SystemTable The EFI System Table pointer. + + @retval EFI_SUCCESS Tftp command is executed sucessfully. + @retval EFI_ABORTED HII package was failed to initialize. + @retval others Other errors when executing tftp command. +**/ +EFI_STATUS +EFIAPI +TftpCommandInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + mTftpHiiHandle =3D InitializeHiiPackage (ImageHandle); + if (mTftpHiiHandle =3D=3D NULL) { + return EFI_ABORTED; + } + + Status =3D gBS->InstallProtocolInterface ( + &ImageHandle, + &gEfiShellDynamicCommandProtocolGuid, + EFI_NATIVE_INTERFACE, + &mTftpDynamicCommand + ); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** + Tftp driver unload handler. + + @param ImageHandle The image handle of the process. + + @retval EFI_SUCCESS The image is unloaded. + @retval Others Failed to unload the image. +**/ +EFI_STATUS +EFIAPI +TftpUnload ( + IN EFI_HANDLE ImageHandle +) +{ + EFI_STATUS Status; + Status =3D gBS->UninstallProtocolInterface ( + ImageHandle, + &gEfiShellDynamicCommandProtocolGuid, + &mTftpDynamicCommand + ); + if (EFI_ERROR (Status)) { + return Status; + } + HiiRemovePackages (mTftpHiiHandle); + return EFI_SUCCESS; +} diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandL= ib.inf b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf similarity index 55% rename from ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLi= b.inf rename to ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf index 96db258920..85d04b77dc 100644 --- a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf +++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf @@ -1,7 +1,7 @@ ## @file -# Provides Shell 'tftp' command functions +# Provides Shell 'tftp' dynamic command. # -# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.
+# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
# Copyright (c) 2015, ARM Ltd. All rights reserved.
# # This program and the accompanying materials @@ -16,19 +16,22 @@ =20 [Defines] INF_VERSION =3D 0x00010006 - BASE_NAME =3D UefiShellTftpCommandLib - FILE_GUID =3D D2B61A25-9835-4E5D-906A-15615E1FF668 - MODULE_TYPE =3D UEFI_APPLICATION + BASE_NAME =3D tftpDynamicCommand + FILE_GUID =3D A487A478-51EF-48AA-8794-7BEE2A0562F1 + MODULE_TYPE =3D DXE_DRIVER VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D NULL|UEFI_APPLICATION UEFI_DRIVER - CONSTRUCTOR =3D ShellTftpCommandLibConstructor - DESTRUCTOR =3D ShellTftpCommandLibDestructor + ENTRY_POINT =3D TftpCommandInitialize + UNLOAD_IMAGE =3D TftpUnload +# +# This flag specifies whether HII resource section is generated into PE i= mage. +# + UEFI_HII_RESOURCE_SECTION =3D TRUE =20 [Sources.common] - UefiShellTftpCommandLib.uni - UefiShellTftpCommandLib.c - UefiShellTftpCommandLib.h + Tftp.uni + Tftp.h Tftp.c + TftpDynamicCommand.c =20 [Packages] MdePkg/MdePkg.dec @@ -40,22 +43,22 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib - ShellCommandLib ShellLib UefiLib UefiRuntimeServicesTableLib UefiBootServicesTableLib - PcdLib + UefiDriverEntryPoint + UefiHiiServicesLib HiiLib FileHandleLib NetLib =20 -[Pcd] - gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask ## CONSUMES - [Protocols] gEfiManagedNetworkServiceBindingProtocolGuid ## CONSUMES gEfiMtftp4ServiceBindingProtocolGuid ## CONSUMES + gEfiMtftp4ProtocolGuid ## CONSUMES + gEfiHiiPackageListProtocolGuid ## CONSUMES + gEfiShellDynamicCommandProtocolGuid ## PRODUCES =20 -[Guids] - gShellTftpHiiGuid ## CONSUMES ## HII +[DEPEX] + TRUE diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandL= ib.c b/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.c deleted file mode 100644 index 22c81b8d2a..0000000000 --- a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.c +++ /dev/null @@ -1,97 +0,0 @@ -/** @file - Main file for NULL named library for 'tftp' Shell command functions. - - Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
- Copyright (c) 2015, ARM Ltd. All rights reserved.
- - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BS= D License - which accompanies this distribution. The full text of the license may b= e found at - http://opensource.org/licenses/bsd-license.php - - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. - -**/ -#include "UefiShellTftpCommandLib.h" - -CONST CHAR16 gShellTftpFileName[] =3D L"ShellCommand"; -EFI_HANDLE gShellTftpHiiHandle =3D NULL; - -/** - Return the file name of the help text file if not using HII. - - @return The string pointer to the file name. -**/ -CONST CHAR16* -EFIAPI -ShellCommandGetManFileNameTftp ( - VOID - ) -{ - return gShellTftpFileName; -} - -/** - Constructor for the Shell Tftp Command library. - - Install the handlers for Tftp UEFI Shell command. - - @param ImageHandle The image handle of the process. - @param SystemTable The EFI System Table pointer. - - @retval EFI_SUCCESS The Shell command handlers were installed = sucessfully. - @retval EFI_UNSUPPORTED The Shell level required was not found. -**/ -EFI_STATUS -EFIAPI -ShellTftpCommandLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - gShellTftpHiiHandle =3D NULL; - - // - // check our bit of the profiles mask - // - if ((PcdGet8 (PcdShellProfileMask) & BIT3) =3D=3D 0) { - return EFI_SUCCESS; - } - - gShellTftpHiiHandle =3D HiiAddPackages ( - &gShellTftpHiiGuid, gImageHandle, - UefiShellTftpCommandLibStrings, NULL - ); - if (gShellTftpHiiHandle =3D=3D NULL) { - return EFI_DEVICE_ERROR; - } - // - // Install our Shell command handler - // - ShellCommandRegisterCommandName ( - L"tftp", ShellCommandRunTftp, ShellCommandGetManFileNameTftp, 0, - L"tftp", TRUE , gShellTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP) - ); - - return EFI_SUCCESS; -} - -/** - Destructor for the library. free any resources. - - @param ImageHandle The image handle of the process. - @param SystemTable The EFI System Table pointer. -**/ -EFI_STATUS -EFIAPI -ShellTftpCommandLibDestructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - if (gShellTftpHiiHandle !=3D NULL) { - HiiRemovePackages (gShellTftpHiiHandle); - } - return EFI_SUCCESS; -} diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc index ed6ac4356d..8fc20709f4 100644 --- a/ShellPkg/ShellPkg.dsc +++ b/ShellPkg/ShellPkg.dsc @@ -25,6 +25,7 @@ [Defines] =20 [LibraryClasses.common] UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiA= pplicationEntryPoint.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptional= DevicePathProtocol.inf !if $(TARGET) =3D=3D RELEASE @@ -79,7 +80,6 @@ [LibraryClasses.AARCH64] =20 [PcdsFixedAtBuild] gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF - gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|16000 !ifdef $(NO_SHELL_PROFILES) gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask|0x00 @@ -103,7 +103,6 @@ [Components] ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.i= nf ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsL= ib.inf ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsL= ib.inf - ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf =20 ShellPkg/Library/UefiDpLib/UefiDpLib.inf { @@ -112,6 +111,8 @@ [Components] } =20 ShellPkg/Application/Shell/Shell.inf { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2Comm= andsLib.inf NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1Comm= andsLib.inf @@ -125,11 +126,11 @@ [Components] !ifdef $(INCLUDE_DP) NULL|ShellPkg/Library/UefiDpLib/UefiDpLib.inf !endif #$(INCLUDE_DP) -!ifdef $(INCLUDE_TFTP_COMMAND) - NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLi= b.inf -!endif #$(INCLUDE_TFTP_COMMAND) !endif #$(NO_SHELL_PROFILES) } =20 + ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf + ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf + [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES --=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