public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Jaben Carsey <jaben.carsey@intel.com>,
	Michael D Kinney <michael.d.kinney@intel.com>
Subject: [PATCH 2/3] ShellPkg/tftp: Convert from NULL class library to Dynamic Command
Date: Mon, 27 Nov 2017 08:58:09 +0800	[thread overview]
Message-ID: <20171127005810.274328-3-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20171127005810.274328-1-ruiyu.ni@intel.com>

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 <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
---
 .../TftpDynamicCommand}/Tftp.c                     |  91 ++++++++++----
 .../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                              |   8 +-
 9 files changed, 323 insertions(+), 171 deletions(-)
 rename ShellPkg/{Library/UefiShellTftpCommandLib => DynamicCommand/TftpDynamicCommand}/Tftp.c (91%)
 mode change 100755 => 100644
 rename ShellPkg/{Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.h => DynamicCommand/TftpDynamicCommand/Tftp.h} (56%)
 rename ShellPkg/{Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.uni => DynamicCommand/TftpDynamicCommand/Tftp.uni} (100%)
 create mode 100644 ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.c
 copy ShellPkg/{Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf => DynamicCommand/TftpDynamicCommand/TftpApp.inf} (59%)
 create mode 100644 ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c
 rename ShellPkg/{Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf => DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf} (55%)
 delete mode 100644 ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.c

diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c b/ShellPkg/DynamicCommand/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..bf847bc992
--- a/ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c
+++ b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.c
@@ -2,7 +2,7 @@
   The implementation for the 'tftp' Shell command.
 
   Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
-  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved. <BR>
+  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved. <BR>
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
 
   This program and the accompanying materials
@@ -14,9 +14,10 @@
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/
 
-#include "UefiShellTftpCommandLib.h"
+#include "Tftp.h"
 
 #define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH 32
+EFI_HANDLE   mTftpHiiHandle;
 
 /*
    Constant strings and definitions related to the message indicating the amount of
@@ -257,7 +258,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
 **/
 SHELL_STATUS
 EFIAPI
-ShellCommandRunTftp (
+RunTftp (
   IN EFI_HANDLE        ImageHandle,
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
@@ -315,7 +316,7 @@ ShellCommandRunTftp (
     if ((Status == EFI_VOLUME_CORRUPTED) &&
         (ProblemParam != 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 +333,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 +355,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 +417,7 @@ ShellCommandRunTftp (
     if (Mtftp4ConfigData.TimeoutValue == 0) {
       ShellPrintHiiEx (
         -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),
-        gShellTftpHiiHandle, L"tftp", ValueStr
+        mTftpHiiHandle, L"tftp", ValueStr
       );
       goto Error;
     }
@@ -430,7 +431,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 +451,7 @@ ShellCommandRunTftp (
   if (EFI_ERROR (Status) || (HandleCount == 0)) {
     ShellPrintHiiEx (
       -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NO_NIC),
-      gShellTftpHiiHandle
+      mTftpHiiHandle
     );
     goto Error;
   }
@@ -465,7 +466,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 +488,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 +497,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 +506,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 +515,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 +535,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 +547,7 @@ ShellCommandRunTftp (
     } else {
       ShellPrintHiiEx (
         -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_WRITE),
-        gShellTftpHiiHandle, LocalFilePath, Status
+        mTftpHiiHandle, LocalFilePath, Status
       );
     }
     ShellCloseFile (&FileHandle);
@@ -568,7 +569,7 @@ ShellCommandRunTftp (
   if ((UserNicName != NULL) && (!NicFound)) {
     ShellPrintHiiEx (
       -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NOT_FOUND),
-      gShellTftpHiiHandle, UserNicName
+      mTftpHiiHandle, UserNicName
     );
   }
 
@@ -607,7 +608,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 +949,13 @@ DownloadFile (
 
   ShellPrintHiiEx (
     -1, -1, NULL, STRING_TOKEN (STR_TFTP_DOWNLOADING),
-    gShellTftpHiiHandle, FilePath
+    mTftpHiiHandle, FilePath
     );
 
   Status = Mtftp4->ReadFile (Mtftp4, &Mtftp4Token);
   ShellPrintHiiEx (
     -1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF),
-    gShellTftpHiiHandle
+    mTftpHiiHandle
     );
 
 Error :
@@ -1052,3 +1053,51 @@ CheckPacket (
 
   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 = 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 = gHiiDatabase->NewPackageList (
+                           gHiiDatabase,
+                           PackageList,
+                           NULL,
+                           &HiiHandle
+                           );
+  ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+    return NULL;
+  }
+  return HiiHandle;
+}
diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.h b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.h
similarity index 56%
rename from ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.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.
 
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved. <BR>
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
   Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
 
   This program and the accompanying materials
@@ -14,13 +14,12 @@
 
 **/
 
-#ifndef _UEFI_SHELL_TFTP_COMMAND_LIB_H_
-#define _UEFI_SHELL_TFTP_COMMAND_LIB_H_
+#ifndef _TFTP_H_
+#define _TFTP_H_
 
 #include <Uefi.h>
 
-#include <Guid/ShellLibHiiGuid.h>
-
+#include <Protocol/HiiPackageList.h>
 #include <Protocol/ServiceBinding.h>
 #include <Protocol/Mtftp4.h>
 
@@ -28,7 +27,6 @@
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
 #include <Library/MemoryAllocationLib.h>
-#include <Library/ShellCommandLib.h>
 #include <Library/ShellLib.h>
 #include <Library/UefiLib.h>
 #include <Library/UefiRuntimeServicesTableLib.h>
@@ -36,8 +34,9 @@
 #include <Library/HiiLib.h>
 #include <Library/NetLib.h>
 #include <Library/PrintLib.h>
+#include <Library/UefiHiiServicesLib.h>
 
-extern EFI_HANDLE gShellTftpHiiHandle;
+extern EFI_HANDLE mTftpHiiHandle;
 
 typedef struct {
   UINTN  FileSize;
@@ -48,14 +47,29 @@ typedef struct {
 /**
   Function for 'tftp' command.
 
-  @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
   );
 
-#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/UefiShellTftpCommandLib.uni b/ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.uni
similarity index 100%
rename from ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.uni
rename to ShellPkg/DynamicCommand/TftpDynamicCommand/Tftp.uni
diff --git a/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.c b/ShellPkg/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. <BR>
+  Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be 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 IMPLIED.
+
+**/
+#include "Tftp.h"
+
+//
+// String token ID of help message text.
+// Shell supports to find help message in the resource section of an application image if
+// .MAN file is not found. This global variable is added to make build tool recognizes
+// that the help string is consumed by user and then build tool will add the 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 = 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 = InitializeHiiPackage (ImageHandle);
+  if (mTftpHiiHandle == NULL) {
+    return EFI_ABORTED;
+  }
+
+  Status = (EFI_STATUS)RunTftp (ImageHandle, SystemTable);
+  HiiRemovePackages (mTftpHiiHandle);
+  return Status;
+}
diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.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. <BR>
+# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
 # Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
@@ -16,19 +16,21 @@
 
 [Defines]
   INF_VERSION                    = 0x00010006
-  BASE_NAME                      = UefiShellTftpCommandLib
-  FILE_GUID                      = D2B61A25-9835-4E5D-906A-15615E1FF668
+  BASE_NAME                      = tftp
+  FILE_GUID                      = 8DC58D0D-67F5-4B97-9DFC-E442BB9A5648
   MODULE_TYPE                    = UEFI_APPLICATION
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = NULL|UEFI_APPLICATION UEFI_DRIVER
-  CONSTRUCTOR                    = ShellTftpCommandLibConstructor
-  DESTRUCTOR                     = ShellTftpCommandLibDestructor
+  ENTRY_POINT                    = TftpAppInitialize
+#
+#  This flag specifies whether HII resource section is generated into PE image.
+#
+  UEFI_HII_RESOURCE_SECTION      = TRUE
 
 [Sources.common]
-  UefiShellTftpCommandLib.uni
-  UefiShellTftpCommandLib.c
-  UefiShellTftpCommandLib.h
+  Tftp.uni
+  Tftp.h
   Tftp.c
+  TftpApp.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -40,22 +42,18 @@ [LibraryClasses]
   BaseLib
   BaseMemoryLib
   DebugLib
-  ShellCommandLib
   ShellLib
   UefiLib
   UefiRuntimeServicesTableLib
   UefiBootServicesTableLib
-  PcdLib
+  UefiApplicationEntryPoint
+  UefiHiiServicesLib
   HiiLib
   FileHandleLib
   NetLib
 
-[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. <BR>
+  Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be 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 IMPLIED.
+
+**/
+#include "Tftp.h"
+#include <Protocol/ShellDynamicCommand.h>
+
+/**
+  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 command.
+  @param[in] Shell                  The instance of the shell protocol used 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 = 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 associated
+  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 freed 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), Language);
+}
+
+EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mTftpDynamicCommand = {
+  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 = InitializeHiiPackage (ImageHandle);
+  if (mTftpHiiHandle == NULL) {
+    return EFI_ABORTED;
+  }
+
+  Status = 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 = gBS->UninstallProtocolInterface (
+                  ImageHandle,
+                  &gEfiShellDynamicCommandProtocolGuid,
+                  &mTftpDynamicCommand
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+  HiiRemovePackages (mTftpHiiHandle);
+  return EFI_SUCCESS;
+}
diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf b/ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
similarity index 55%
rename from ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.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. <BR>
+# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
 # Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
@@ -16,19 +16,22 @@
 
 [Defines]
   INF_VERSION                    = 0x00010006
-  BASE_NAME                      = UefiShellTftpCommandLib
-  FILE_GUID                      = D2B61A25-9835-4E5D-906A-15615E1FF668
-  MODULE_TYPE                    = UEFI_APPLICATION
+  BASE_NAME                      = tftpDynamicCommand
+  FILE_GUID                      = A487A478-51EF-48AA-8794-7BEE2A0562F1
+  MODULE_TYPE                    = DXE_DRIVER
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = NULL|UEFI_APPLICATION UEFI_DRIVER
-  CONSTRUCTOR                    = ShellTftpCommandLibConstructor
-  DESTRUCTOR                     = ShellTftpCommandLibDestructor
+  ENTRY_POINT                    = TftpCommandInitialize
+  UNLOAD_IMAGE                   = TftpUnload
+#
+#  This flag specifies whether HII resource section is generated into PE image.
+#
+  UEFI_HII_RESOURCE_SECTION      = TRUE
 
 [Sources.common]
-  UefiShellTftpCommandLib.uni
-  UefiShellTftpCommandLib.c
-  UefiShellTftpCommandLib.h
+  Tftp.uni
+  Tftp.h
   Tftp.c
+  TftpDynamicCommand.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -40,22 +43,22 @@ [LibraryClasses]
   BaseLib
   BaseMemoryLib
   DebugLib
-  ShellCommandLib
   ShellLib
   UefiLib
   UefiRuntimeServicesTableLib
   UefiBootServicesTableLib
-  PcdLib
+  UefiDriverEntryPoint
+  UefiHiiServicesLib
   HiiLib
   FileHandleLib
   NetLib
 
-[Pcd]
-  gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask ## CONSUMES
-
 [Protocols]
   gEfiManagedNetworkServiceBindingProtocolGuid   ## CONSUMES
   gEfiMtftp4ServiceBindingProtocolGuid           ## CONSUMES
+  gEfiMtftp4ProtocolGuid                         ## CONSUMES
+  gEfiHiiPackageListProtocolGuid                 ## CONSUMES
+  gEfiShellDynamicCommandProtocolGuid            ## PRODUCES
 
-[Guids]
-  gShellTftpHiiGuid                              ## CONSUMES ## HII
+[DEPEX]
+  TRUE
diff --git a/ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.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. <BR>
-  Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
-
-  This program and the accompanying materials
-  are licensed and made available under the terms and conditions of the BSD License
-  which accompanies this distribution.  The full text of the license may be 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 IMPLIED.
-
-**/
-#include "UefiShellTftpCommandLib.h"
-
-CONST CHAR16 gShellTftpFileName[] = L"ShellCommand";
-EFI_HANDLE gShellTftpHiiHandle = 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 = NULL;
-
-  //
-  // check our bit of the profiles mask
-  //
-  if ((PcdGet8 (PcdShellProfileMask) & BIT3) == 0) {
-    return EFI_SUCCESS;
-  }
-
-  gShellTftpHiiHandle = HiiAddPackages (
-                          &gShellTftpHiiGuid, gImageHandle,
-                          UefiShellTftpCommandLibStrings, NULL
-                          );
-  if (gShellTftpHiiHandle == 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 != NULL) {
-    HiiRemovePackages (gShellTftpHiiHandle);
-  }
-  return EFI_SUCCESS;
-}
diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc
index ed6ac4356d..7eaecedb56 100644
--- a/ShellPkg/ShellPkg.dsc
+++ b/ShellPkg/ShellPkg.dsc
@@ -25,6 +25,7 @@ [Defines]
 
 [LibraryClasses.common]
   UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
   UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
   DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
 !if $(TARGET) == RELEASE
@@ -103,7 +104,6 @@ [Components]
   ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
   ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
   ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf
-  ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf
 
   ShellPkg/Library/UefiDpLib/UefiDpLib.inf {
     <LibraryClasses>
@@ -125,11 +125,11 @@ [Components]
 !ifdef $(INCLUDE_DP)
       NULL|ShellPkg/Library/UefiDpLib/UefiDpLib.inf
 !endif #$(INCLUDE_DP)
-!ifdef $(INCLUDE_TFTP_COMMAND)
-      NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf
-!endif #$(INCLUDE_TFTP_COMMAND)
 !endif #$(NO_SHELL_PROFILES)
   }
 
+  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
+  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf
+
 [BuildOptions]
   *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
-- 
2.15.0.gvfs.1.preview.4



  parent reply	other threads:[~2017-11-27  0:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27  0:58 [PATCH 0/3] Convert from NULL class library to Dynamic Command Ruiyu Ni
2017-11-27  0:58 ` [PATCH 1/3] ShellPkg/ShellLib: Constructor doesn't depend on ShellParameters Ruiyu Ni
2017-11-27  0:58 ` Ruiyu Ni [this message]
2017-11-27  0:58 ` [PATCH 3/3] ShellPkg/dp: Convert from NULL class library to Dynamic Command Ruiyu Ni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171127005810.274328-3-ruiyu.ni@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox