public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/3] Convert from NULL class library to Dynamic Command
@ 2017-11-27  0:58 Ruiyu Ni
  2017-11-27  0:58 ` [PATCH 1/3] ShellPkg/ShellLib: Constructor doesn't depend on ShellParameters Ruiyu Ni
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ruiyu Ni @ 2017-11-27  0:58 UTC (permalink / raw)
  To: edk2-devel

UEFI Shell spec defines Shell Dynamic Command protocol which is just
for the purpose to extend internal command.
So tftp and dp are changed from NULL class library to be drivers
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.

Ruiyu Ni (3):
  ShellPkg/ShellLib: Constructor doesn't depend on ShellParameters
  ShellPkg/tftp: Convert from NULL class library to Dynamic Command
  ShellPkg/dp: Convert from NULL class library to Dynamic Command

 .../DpDynamicCommand}/Dp.c                         | 100 +++++++----
 .../DpDynamicCommand}/Dp.h                         |  63 ++++++-
 .../DpDynamicCommand/Dp.uni}                       |   0
 ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.c   |  53 ++++++
 ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf |  73 +++++++++
 .../DpDynamicCommand/DpDynamicCommand.c            | 130 +++++++++++++++
 .../DpDynamicCommand/DpDynamicCommand.inf          |  78 +++++++++
 .../DpDynamicCommand}/DpInternal.h                 |   2 +-
 .../DpDynamicCommand}/DpProfile.c                  |  34 ++--
 .../DpDynamicCommand}/DpTrace.c                    | 182 ++++++++++-----------
 .../DpDynamicCommand}/DpUtilities.c                |  44 +++--
 .../DpDynamicCommand}/Literals.c                   |   0
 .../DpDynamicCommand}/Literals.h                   |   0
 .../DpDynamicCommand}/PerformanceTokens.h          |   0
 .../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 +++--
 ShellPkg/Library/UefiDpLib/Readme.txt              |   2 -
 ShellPkg/Library/UefiDpLib/UefiDpLib.c             | 101 ------------
 ShellPkg/Library/UefiDpLib/UefiDpLib.h             |  64 --------
 ShellPkg/Library/UefiDpLib/UefiDpLib.inf           |  77 ---------
 ShellPkg/Library/UefiShellLib/UefiShellLib.c       |  12 +-
 .../UefiShellTftpCommandLib.c                      |  97 -----------
 ShellPkg/ShellPkg.dsc                              |  20 ++-
 28 files changed, 936 insertions(+), 585 deletions(-)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/Dp.c (84%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/Dp.h (70%)
 rename ShellPkg/{Library/UefiDpLib/UefiDpLib.uni => DynamicCommand/DpDynamicCommand/Dp.uni} (100%)
 create mode 100644 ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.c
 create mode 100644 ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf
 create mode 100644 ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c
 create mode 100644 ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/DpInternal.h (96%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/DpProfile.c (87%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/DpTrace.c (89%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/DpUtilities.c (87%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/Literals.c (100%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/Literals.h (100%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/PerformanceTokens.h (100%)
 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/UefiDpLib/Readme.txt
 delete mode 100644 ShellPkg/Library/UefiDpLib/UefiDpLib.c
 delete mode 100644 ShellPkg/Library/UefiDpLib/UefiDpLib.h
 delete mode 100644 ShellPkg/Library/UefiDpLib/UefiDpLib.inf
 delete mode 100644 ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.c

-- 
2.15.0.gvfs.1.preview.4



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] ShellPkg/ShellLib: Constructor doesn't depend on ShellParameters
  2017-11-27  0:58 [PATCH 0/3] Convert from NULL class library to Dynamic Command Ruiyu Ni
@ 2017-11-27  0:58 ` Ruiyu Ni
  2017-11-27  0:58 ` [PATCH 2/3] ShellPkg/tftp: Convert from NULL class library to Dynamic Command Ruiyu Ni
  2017-11-27  0:58 ` [PATCH 3/3] ShellPkg/dp: " Ruiyu Ni
  2 siblings, 0 replies; 4+ messages in thread
From: Ruiyu Ni @ 2017-11-27  0:58 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jaben Carsey, Michael D Kinney

When ShellLib is linked to a driver producing DynamicCommand
protocol, ShellParameters protocol is set by
DynamicCommand.Handler().
The driver image handle doesn't have ShellParameters protocol
installed.

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>
---
 ShellPkg/Library/UefiShellLib/UefiShellLib.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index 677791c67f..00f58ca0c1 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -215,7 +215,7 @@ ShellLibConstructorWorker (
     gEfiShellParametersProtocol = NULL;
   }
 
-  if (gEfiShellParametersProtocol == NULL || gEfiShellProtocol == NULL) {
+  if (gEfiShellProtocol == NULL) {
     //
     // Moved to seperate function due to complexity
     //
@@ -238,10 +238,14 @@ ShellLibConstructorWorker (
   }
 
   //
-  // only success getting 2 of either the old or new, but no 1/2 and 1/2
+  // Getting either EDK Shell's ShellEnvironment2 and ShellInterface protocol
+  //  or UEFI Shell's Shell protocol.
+  // When ShellLib is linked to a driver producing DynamicCommand protocol,
+  //  ShellParameters protocol is set by DynamicCommand.Handler().
   //
-  if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface          != NULL) ||
-      (gEfiShellProtocol     != NULL && gEfiShellParametersProtocol != NULL)   ) {
+  if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) ||
+      (gEfiShellProtocol     != NULL)
+      ) {
     if (gEfiShellProtocol != NULL) {
       FileFunctionMap.GetFileInfo     = gEfiShellProtocol->GetFileInfo;
       FileFunctionMap.SetFileInfo     = gEfiShellProtocol->SetFileInfo;
-- 
2.15.0.gvfs.1.preview.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] ShellPkg/tftp: Convert from NULL class library to Dynamic Command
  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
  2017-11-27  0:58 ` [PATCH 3/3] ShellPkg/dp: " Ruiyu Ni
  2 siblings, 0 replies; 4+ messages in thread
From: Ruiyu Ni @ 2017-11-27  0:58 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jaben Carsey, Michael D Kinney

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



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] ShellPkg/dp: Convert from NULL class library to Dynamic Command
  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 ` [PATCH 2/3] ShellPkg/tftp: Convert from NULL class library to Dynamic Command Ruiyu Ni
@ 2017-11-27  0:58 ` Ruiyu Ni
  2 siblings, 0 replies; 4+ messages in thread
From: Ruiyu Ni @ 2017-11-27  0:58 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jaben Carsey, Michael D Kinney

UEFI Shell spec defines Shell Dynamic Command protocol which is just
for the purpose to extend internal command.
So dp 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.

DpApp.inf is to provide a standalone application.
DpDynamicCommand.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>
---
 .../DpDynamicCommand}/Dp.c                         | 100 +++++++----
 .../DpDynamicCommand}/Dp.h                         |  63 ++++++-
 .../DpDynamicCommand/Dp.uni}                       |   0
 ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.c   |  53 ++++++
 ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf |  73 +++++++++
 .../DpDynamicCommand/DpDynamicCommand.c            | 130 +++++++++++++++
 .../DpDynamicCommand/DpDynamicCommand.inf          |  78 +++++++++
 .../DpDynamicCommand}/DpInternal.h                 |   2 +-
 .../DpDynamicCommand}/DpProfile.c                  |  34 ++--
 .../DpDynamicCommand}/DpTrace.c                    | 182 ++++++++++-----------
 .../DpDynamicCommand}/DpUtilities.c                |  44 +++--
 .../DpDynamicCommand}/Literals.c                   |   0
 .../DpDynamicCommand}/Literals.h                   |   0
 .../DpDynamicCommand}/PerformanceTokens.h          |   0
 ShellPkg/Library/UefiDpLib/Readme.txt              |   2 -
 ShellPkg/Library/UefiDpLib/UefiDpLib.c             | 101 ------------
 ShellPkg/Library/UefiDpLib/UefiDpLib.h             |  64 --------
 ShellPkg/Library/UefiDpLib/UefiDpLib.inf           |  77 ---------
 ShellPkg/ShellPkg.dsc                              |  12 +-
 19 files changed, 605 insertions(+), 410 deletions(-)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/Dp.c (84%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/Dp.h (70%)
 rename ShellPkg/{Library/UefiDpLib/UefiDpLib.uni => DynamicCommand/DpDynamicCommand/Dp.uni} (100%)
 create mode 100644 ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.c
 create mode 100644 ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf
 create mode 100644 ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c
 create mode 100644 ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/DpInternal.h (96%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/DpProfile.c (87%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/DpTrace.c (89%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/DpUtilities.c (87%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/Literals.c (100%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/Literals.h (100%)
 rename ShellPkg/{Library/UefiDpLib => DynamicCommand/DpDynamicCommand}/PerformanceTokens.h (100%)
 delete mode 100644 ShellPkg/Library/UefiDpLib/Readme.txt
 delete mode 100644 ShellPkg/Library/UefiDpLib/UefiDpLib.c
 delete mode 100644 ShellPkg/Library/UefiDpLib/UefiDpLib.h
 delete mode 100644 ShellPkg/Library/UefiDpLib/UefiDpLib.inf

diff --git a/ShellPkg/Library/UefiDpLib/Dp.c b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
similarity index 84%
rename from ShellPkg/Library/UefiDpLib/Dp.c
rename to ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
index 94fa61c710..3ecc753d0c 100644
--- a/ShellPkg/Library/UefiDpLib/Dp.c
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.c
@@ -24,20 +24,13 @@
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/
 
-#include "UefiDpLib.h"
-#include <Library/ShellLib.h>
-#include <Library/BaseLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/DebugLib.h>
-#include <Library/UefiLib.h>
-
-#include <Guid/Performance.h>
-
 #include "PerformanceTokens.h"
 #include "Dp.h"
 #include "Literals.h"
 #include "DpInternal.h"
 
+EFI_HANDLE   mDpHiiHandle;
+
 //
 /// Module-Global Variables
 ///@{
@@ -89,18 +82,18 @@ DumpStatistics( void )
 {
   EFI_STRING                StringPtr;
   EFI_STRING                StringPtrUnknown;
-  StringPtr        = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_STATISTICS), NULL);
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,
+  StringPtr        = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_STATISTICS), NULL);
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown : StringPtr);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMTRACE), gDpHiiHandle,      SummaryData.NumTrace);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE), gDpHiiHandle, SummaryData.NumIncomplete);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPHASES), gDpHiiHandle,     SummaryData.NumSummary);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMHANDLES), gDpHiiHandle,    SummaryData.NumHandles, SummaryData.NumTrace - SummaryData.NumHandles);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPEIMS), gDpHiiHandle,      SummaryData.NumPEIMs);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMGLOBALS), gDpHiiHandle,    SummaryData.NumGlobal);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMTRACE), mDpHiiHandle,      SummaryData.NumTrace);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMINCOMPLETE), mDpHiiHandle, SummaryData.NumIncomplete);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPHASES), mDpHiiHandle,     SummaryData.NumSummary);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMHANDLES), mDpHiiHandle,    SummaryData.NumHandles, SummaryData.NumTrace - SummaryData.NumHandles);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPEIMS), mDpHiiHandle,      SummaryData.NumPEIMs);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMGLOBALS), mDpHiiHandle,    SummaryData.NumGlobal);
 #if PROFILING_IMPLEMENTED
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPROFILE), gDpHiiHandle,    SummaryData.NumProfile);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_STATS_NUMPROFILE), mDpHiiHandle,    SummaryData.NumProfile);
 #endif // PROFILING_IMPLEMENTED
   SHELL_FREE_NON_NULL (StringPtr);
   SHELL_FREE_NON_NULL (StringPtrUnknown);
@@ -137,8 +130,7 @@ InitCumulativeData (
   @retval value                    Unknown error.
 **/
 SHELL_STATUS
-EFIAPI
-ShellCommandRunDp (
+RunDp (
   IN EFI_HANDLE               ImageHandle,
   IN EFI_SYSTEM_TABLE         *SystemTable
   )
@@ -182,15 +174,12 @@ ShellCommandRunDp (
   Status = ShellInitialize();
   ASSERT_EFI_ERROR(Status);
 
-  Status = CommandInit();
-  ASSERT_EFI_ERROR(Status);
-
   //
   // Process Command Line arguments
   //
   Status = ShellCommandLineParse (ParamList, &ParamPackage, NULL, TRUE);
   if (EFI_ERROR(Status)) {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_INVALID_ARG), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_INVALID_ARG), mDpHiiHandle);
     return SHELL_INVALID_PARAMETER;
   }
 
@@ -273,7 +262,7 @@ ShellCommandRunDp (
   //
   Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);
   if (EFI_ERROR (Status) || (PerformanceProperty == NULL)) {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PERF_PROPERTY_NOT_FOUND), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PERF_PROPERTY_NOT_FOUND), mDpHiiHandle);
     goto Done;
   }
 
@@ -288,22 +277,22 @@ ShellCommandRunDp (
   // Print header
   //
   // print DP's build version
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_BUILD_REVISION), gDpHiiHandle, DP_MAJOR_VERSION, DP_MINOR_VERSION);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_BUILD_REVISION), mDpHiiHandle, DP_MAJOR_VERSION, DP_MINOR_VERSION);
 
   // print performance timer characteristics
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_KHZ), gDpHiiHandle, TimerInfo.Frequency);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_KHZ), mDpHiiHandle, TimerInfo.Frequency);
 
   if (VerboseMode && !RawMode) {
-    StringPtr = HiiGetString (gDpHiiHandle,
+    StringPtr = HiiGetString (mDpHiiHandle,
                   (EFI_STRING_ID) (TimerInfo.CountUp ? STRING_TOKEN (STR_DP_UP) : STRING_TOKEN (STR_DP_DOWN)), NULL);
     ASSERT (StringPtr != NULL);
     // Print Timer count range and direction
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TIMER_PROPERTIES), gDpHiiHandle,
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TIMER_PROPERTIES), mDpHiiHandle,
                 StringPtr,
                 TimerInfo.StartCount,
                 TimerInfo.EndCount
                 );
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), gDpHiiHandle, mInterestThreshold);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), mDpHiiHandle, mInterestThreshold);
   }
 
 /****************************************************************************
@@ -398,3 +387,52 @@ Done:
 
   return ShellStatus;
 }
+
+
+/**
+  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/UefiDpLib/Dp.h b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.h
similarity index 70%
rename from ShellPkg/Library/UefiDpLib/Dp.h
rename to ShellPkg/DynamicCommand/DpDynamicCommand/Dp.h
index 06fee3bcf4..4027b6b84e 100644
--- a/ShellPkg/Library/UefiDpLib/Dp.h
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.h
@@ -1,7 +1,7 @@
 /** @file
-  Common declarations for the Dp Performance Reporting Utility.
+  Header file for 'dp' command functions.
 
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
   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
@@ -9,12 +9,37 @@
 
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
 **/
 
-#ifndef _EFI_APP_DP_H_
-#define _EFI_APP_DP_H_
+#ifndef _DP_H_
+#define _DP_H_
+
+
+#include <Uefi.h>
+
+#include <Guid/Performance.h>
 
+#include <Protocol/HiiPackageList.h>
+#include <Protocol/DevicePath.h>
+#include <Protocol/LoadedImage.h>
+#include <Protocol/UnicodeCollation.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
 #include <Library/ShellLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/PcdLib.h>
+#include <Library/SortLib.h>
+#include <Library/HiiLib.h>
+#include <Library/FileHandleLib.h>
+#include <Library/UefiHiiServicesLib.h>
+
+extern EFI_HANDLE mDpHiiHandle;
 
 #define DP_MAJOR_VERSION        2
 #define DP_MINOR_VERSION        4
@@ -94,4 +119,32 @@ typedef struct {
   UINT32                Count;            ///< Number of measurements accumulated.
 } PROFILE_RECORD;
 
-#endif  // _EFI_APP_DP_H_
+/**
+  Dump performance data.
+
+  @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
+RunDp (
+  IN EFI_HANDLE               ImageHandle,
+  IN EFI_SYSTEM_TABLE         *SystemTable
+  );
+
+/**
+  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  // _DP_H_
diff --git a/ShellPkg/Library/UefiDpLib/UefiDpLib.uni b/ShellPkg/DynamicCommand/DpDynamicCommand/Dp.uni
similarity index 100%
rename from ShellPkg/Library/UefiDpLib/UefiDpLib.uni
rename to ShellPkg/DynamicCommand/DpDynamicCommand/Dp.uni
diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.c b/ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.c
new file mode 100644
index 0000000000..f96209b27a
--- /dev/null
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.c
@@ -0,0 +1,53 @@
+/** @file
+  Entrypoint of "dp" shell standalone application.
+
+  Copyright (c) 2017, Intel Corporation. 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 "Dp.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_DP);
+
+/**
+  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
+DpAppInitialize (
+  IN EFI_HANDLE               ImageHandle,
+  IN EFI_SYSTEM_TABLE         *SystemTable
+  )
+{
+  EFI_STATUS                  Status;
+  mDpHiiHandle = InitializeHiiPackage (ImageHandle);
+  if (mDpHiiHandle == NULL) {
+    return EFI_ABORTED;
+  }
+
+  Status = (EFI_STATUS)RunDp (ImageHandle, SystemTable);
+  HiiRemovePackages (mDpHiiHandle);
+  return Status;
+}
diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf b/ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf
new file mode 100644
index 0000000000..b0ed229b49
--- /dev/null
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf
@@ -0,0 +1,73 @@
+##  @file
+# Provides Shell 'dp' standalone application.
+#
+# Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+#  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.
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010006
+  BASE_NAME                      = dp
+  FILE_GUID                      = 1831A379-2D48-45BD-9744-D4059D93815D
+  MODULE_TYPE                    = UEFI_APPLICATION
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = DpAppInitialize
+#
+#  This flag specifies whether HII resource section is generated into PE image.
+#
+  UEFI_HII_RESOURCE_SECTION      = TRUE
+
+[Sources.common]
+  PerformanceTokens.h
+  Dp.uni
+  Dp.c
+  Dp.h
+  Literals.h
+  Literals.c
+  DpInternal.h
+  DpUtilities.c
+  DpTrace.c
+  DpProfile.c
+  DpApp.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  ShellPkg/ShellPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  MemoryAllocationLib
+  BaseLib
+  BaseMemoryLib
+  DebugLib
+  ShellLib
+  UefiLib
+  UefiRuntimeServicesTableLib
+  UefiBootServicesTableLib
+  UefiApplicationEntryPoint
+  SortLib
+  PrintLib
+  DevicePathLib
+  PerformanceLib
+  DxeServicesLib
+  PeCoffGetEntryPointLib
+
+[Guids]
+  gPerformanceProtocolGuid                                ## CONSUMES ## SystemTable
+
+[Protocols]
+  gEfiLoadedImageProtocolGuid                             ## CONSUMES
+  gEfiDriverBindingProtocolGuid                           ## SOMETIMES_CONSUMES
+  gEfiComponentName2ProtocolGuid                          ## SOMETIMES_CONSUMES
+  gEfiLoadedImageDevicePathProtocolGuid                   ## SOMETIMES_CONSUMES
+  gEfiHiiPackageListProtocolGuid                          ## CONSUMES
+
+[Pcd]
+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize   ## CONSUMES
diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c b/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c
new file mode 100644
index 0000000000..6f3997fff4
--- /dev/null
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.c
@@ -0,0 +1,130 @@
+/** @file
+  Produce "dp" shell dynamic command.
+
+  Copyright (c) 2017, Intel Corporation. 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 "Dp.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
+DpCommandHandler (
+  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 RunDp (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
+DpCommandGetHelp (
+  IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL    *This,
+  IN CONST CHAR8                           *Language
+  )
+{
+  return HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_GET_HELP_DP), Language);
+}
+
+EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mDpDynamicCommand = {
+  L"dp",
+  DpCommandHandler,
+  DpCommandGetHelp
+};
+
+/**
+  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
+DpCommandInitialize (
+  IN EFI_HANDLE               ImageHandle,
+  IN EFI_SYSTEM_TABLE         *SystemTable
+  )
+{
+  EFI_STATUS                  Status;
+  mDpHiiHandle = InitializeHiiPackage (ImageHandle);
+  if (mDpHiiHandle == NULL) {
+    return EFI_ABORTED;
+  }
+
+  Status = gBS->InstallProtocolInterface (
+                  &ImageHandle,
+                  &gEfiShellDynamicCommandProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  &mDpDynamicCommand
+                  );
+  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
+DpUnload (
+  IN EFI_HANDLE               ImageHandle
+)
+{
+  EFI_STATUS                  Status;
+  Status = gBS->UninstallProtocolInterface (
+                  ImageHandle,
+                  &gEfiShellDynamicCommandProtocolGuid,
+                  &mDpDynamicCommand
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+  HiiRemovePackages (mDpHiiHandle);
+  return EFI_SUCCESS;
+}
diff --git a/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf b/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf
new file mode 100644
index 0000000000..3164561958
--- /dev/null
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf
@@ -0,0 +1,78 @@
+##  @file
+# Provides Shell 'dp' dynamic command.
+#
+# Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
+#  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.
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010006
+  BASE_NAME                      = dpDynamicCommand
+  FILE_GUID                      = 0253F9FA-129A-4A8D-B12E-7DC2B6376302
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = DpCommandInitialize
+  UNLOAD_IMAGE                   = DpUnload
+#
+#  This flag specifies whether HII resource section is generated into PE image.
+#
+  UEFI_HII_RESOURCE_SECTION      = TRUE
+
+[Sources.common]
+  PerformanceTokens.h
+  Dp.uni
+  Dp.c
+  Dp.h
+  Literals.h
+  Literals.c
+  DpInternal.h
+  DpUtilities.c
+  DpTrace.c
+  DpProfile.c
+  DpDynamicCommand.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  ShellPkg/ShellPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  MemoryAllocationLib
+  BaseLib
+  BaseMemoryLib
+  DebugLib
+  ShellLib
+  UefiLib
+  UefiRuntimeServicesTableLib
+  UefiBootServicesTableLib
+  UefiDriverEntryPoint
+  SortLib
+  PrintLib
+  DevicePathLib
+  PerformanceLib
+  DxeServicesLib
+  PeCoffGetEntryPointLib
+
+[Guids]
+  gPerformanceProtocolGuid                                ## CONSUMES ## SystemTable
+
+[Protocols]
+  gEfiLoadedImageProtocolGuid                             ## CONSUMES
+  gEfiDriverBindingProtocolGuid                           ## SOMETIMES_CONSUMES
+  gEfiComponentName2ProtocolGuid                          ## SOMETIMES_CONSUMES
+  gEfiLoadedImageDevicePathProtocolGuid                   ## SOMETIMES_CONSUMES
+  gEfiHiiPackageListProtocolGuid                          ## CONSUMES
+  gEfiShellDynamicCommandProtocolGuid                     ## PRODUCES
+
+[Pcd]
+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize   ## CONSUMES
+
+[DEPEX]
+  TRUE
diff --git a/ShellPkg/Library/UefiDpLib/DpInternal.h b/ShellPkg/DynamicCommand/DpDynamicCommand/DpInternal.h
similarity index 96%
rename from ShellPkg/Library/UefiDpLib/DpInternal.h
rename to ShellPkg/DynamicCommand/DpDynamicCommand/DpInternal.h
index 6de194aaaa..ece1c23aaf 100644
--- a/ShellPkg/Library/UefiDpLib/DpInternal.h
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpInternal.h
@@ -24,7 +24,7 @@
 //
 /// Module-Global Variables
 ///@{
-extern EFI_HII_HANDLE     gDpHiiHandle;
+extern EFI_HII_HANDLE     mDpHiiHandle;
 extern CHAR16             mGaugeString[DP_GAUGE_STRING_LENGTH + 1];
 extern CHAR16             mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE];
 extern UINT64             mInterestThreshold;
diff --git a/ShellPkg/Library/UefiDpLib/DpProfile.c b/ShellPkg/DynamicCommand/DpDynamicCommand/DpProfile.c
similarity index 87%
rename from ShellPkg/Library/UefiDpLib/DpProfile.c
rename to ShellPkg/DynamicCommand/DpDynamicCommand/DpProfile.c
index e4434034c6..af25217dae 100644
--- a/ShellPkg/Library/UefiDpLib/DpProfile.c
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpProfile.c
@@ -28,23 +28,23 @@
 #include "Literals.h"
 #include "DpInternal.h"
 
-/** 
+/**
   Gather and print ALL Profiling Records.
-  
+
   Displays all "interesting" Profile measurements in order.
   The number of records displayed is controlled by:
      - records with a duration less than mInterestThreshold microseconds are not displayed.
      - No more than Limit records are displayed.  A Limit of zero will not limit the output.
      - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
        displayed.
-  
+
   @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
            The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.
            They must not be in use by a calling function.
-  
+
   @param[in]    Limit         The number of records to print.  Zero is ALL.
   @param[in]    ExcludeFlag   TRUE to exclude individual Cumulative items from display.
-  
+
 **/
 VOID
 DumpAllProfile(
@@ -55,32 +55,32 @@ DumpAllProfile(
   EFI_STRING    StringPtr;
   EFI_STRING    StringPtrUnknown;
 
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);   
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PROFILE), NULL);
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PROFILE), NULL);
 
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle, 
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown: StringPtr);
   FreePool (StringPtr);
   FreePool (StringPtrUnknown);
 }
 
-/** 
+/**
   Gather and print Raw Profile Records.
-  
+
   All Profile measurements with a duration greater than or equal to
   mInterestThreshold are printed without interpretation.
-  
+
   The number of records displayed is controlled by:
      - records with a duration less than mInterestThreshold microseconds are not displayed.
      - No more than Limit records are displayed.  A Limit of zero will not limit the output.
      - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
        displayed.
-  
+
   @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
-  
+
   @param[in]    Limit         The number of records to print.  Zero is ALL.
   @param[in]    ExcludeFlag   TRUE to exclude individual Cumulative items from display.
-  
+
 **/
 VOID
 DumpRawProfile(
@@ -91,9 +91,9 @@ DumpRawProfile(
   EFI_STRING    StringPtr;
   EFI_STRING    StringPtrUnknown;
 
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWPROFILE), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle, 
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWPROFILE), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown: StringPtr);
   FreePool (StringPtr);
   FreePool (StringPtrUnknown);
diff --git a/ShellPkg/Library/UefiDpLib/DpTrace.c b/ShellPkg/DynamicCommand/DpDynamicCommand/DpTrace.c
similarity index 89%
rename from ShellPkg/Library/UefiDpLib/DpTrace.c
rename to ShellPkg/DynamicCommand/DpDynamicCommand/DpTrace.c
index 90a71ad91b..bc882be622 100644
--- a/ShellPkg/Library/UefiDpLib/DpTrace.c
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpTrace.c
@@ -29,17 +29,17 @@
 #include "Literals.h"
 #include "DpInternal.h"
 
-/** 
+/**
   Collect verbose statistics about the logged performance measurements.
-  
+
   General Summary information for all Trace measurements is gathered and
   stored within the SummaryData structure.  This information is both
   used internally by subsequent reporting functions, and displayed
   at the end of verbose reports.
-  
+
   @pre  The SummaryData and CumData structures must be initialized
         prior to calling this function.
-  
+
   @post The SummaryData and CumData structures contain statistics for the
         current performance logs.
 
@@ -118,23 +118,23 @@ GatherStatistics(
   }
 }
 
-/** 
+/**
   Gather and print ALL Trace Records.
-  
+
   Displays all "interesting" Trace measurements in order.<BR>
   The number of records displayed is controlled by:
      - records with a duration less than mInterestThreshold microseconds are not displayed.
      - No more than Limit records are displayed.  A Limit of zero will not limit the output.
      - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
        displayed.
-  
+
   @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
            The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.
            They must not be in use by a calling function.
-  
+
   @param[in]    Limit       The number of records to print.  Zero is ALL.
   @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display.
-  
+
   @retval EFI_SUCCESS           The operation was successful.
   @retval EFI_ABORTED           The user aborts the operation.
   @return Others                from a call to gBS->LocateHandleBuffer().
@@ -159,9 +159,9 @@ DumpAllTrace(
   EFI_STATUS                Status;
   EFI_STRING                StringPtrUnknown;
 
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
-  IncFlag = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_ALL), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_ALL), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (IncFlag == NULL) ? StringPtrUnknown : IncFlag);
   FreePool (StringPtrUnknown);
 
@@ -169,7 +169,7 @@ DumpAllTrace(
   //
   Status  = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);
   if (EFI_ERROR (Status)) {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), gDpHiiHandle, Status);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), mDpHiiHandle, Status);
   }
   else {
     // We have successfully populated the HandleBuffer
@@ -179,11 +179,11 @@ DumpAllTrace(
     //    Display driver names in Module field for records with Handles.
     //
     if (mShowId) {
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_HEADR2), gDpHiiHandle);
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_DASHES2), gDpHiiHandle);
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_HEADR2), mDpHiiHandle);
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_DASHES2), mDpHiiHandle);
     } else {
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_HEADR), gDpHiiHandle);
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), gDpHiiHandle);
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_HEADR), mDpHiiHandle);
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
     }
 
     LogEntryKey = 0;
@@ -206,10 +206,10 @@ DumpAllTrace(
       if (Measurement.EndTimeStamp != 0) {
         Duration = GetDuration (&Measurement);
         ElapsedTime = DurationInMicroSeconds ( Duration );
-        IncFlag = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_COMPLETE), NULL);
+        IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_COMPLETE), NULL);
       }
       else {
-        IncFlag = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL);  // Mark incomplete records
+        IncFlag = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_INCOMPLETE), NULL);  // Mark incomplete records
       }
       if (((Measurement.EndTimeStamp != 0) && (ElapsedTime < mInterestThreshold)) ||
           ((ExcludeFlag) && (GetCumulativeItem(&Measurement) >= 0))
@@ -240,7 +240,7 @@ DumpAllTrace(
       mUnicodeToken[13] = 0;
 
       if (mShowId) {
-        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_VARS2), gDpHiiHandle,
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_VARS2), mDpHiiHandle,
           Index,      // 1 based, Which measurement record is being printed
           IncFlag,
           Measurement.Handle,
@@ -250,7 +250,7 @@ DumpAllTrace(
           Measurement.Identifier
         );
       } else {
-        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_VARS), gDpHiiHandle,
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_ALL_VARS), mDpHiiHandle,
           Index,      // 1 based, Which measurement record is being printed
           IncFlag,
           Measurement.Handle,
@@ -273,20 +273,20 @@ DumpAllTrace(
   return Status;
 }
 
-/** 
+/**
   Gather and print Raw Trace Records.
-  
+
   All Trace measurements with a duration greater than or equal to
   mInterestThreshold are printed without interpretation.
-  
+
   The number of records displayed is controlled by:
      - records with a duration less than mInterestThreshold microseconds are not displayed.
      - No more than Limit records are displayed.  A Limit of zero will not limit the output.
      - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
        displayed.
-  
+
   @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
-  
+
   @param[in]    Limit       The number of records to print.  Zero is ALL.
   @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display.
 
@@ -312,19 +312,19 @@ DumpRawTrace(
 
   Status = EFI_SUCCESS;
 
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWTRACE), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_RAWTRACE), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown : StringPtr);
   FreePool (StringPtr);
   FreePool (StringPtrUnknown);
 
   if (mShowId) {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_HEADR2), gDpHiiHandle);
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_DASHES2), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_HEADR2), mDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_DASHES2), mDpHiiHandle);
   } else {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_HEADR), gDpHiiHandle);
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_DASHES), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_HEADR), mDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_DASHES), mDpHiiHandle);
   }
 
   LogEntryKey = 0;
@@ -355,7 +355,7 @@ DumpRawTrace(
     ++Count;    // Count the number of records printed
 
     if (mShowId) {
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_VARS2), gDpHiiHandle,
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_VARS2), mDpHiiHandle,
         Index,      // 1 based, Which measurement record is being printed
         Measurement.Handle,
         Measurement.StartTimeStamp,
@@ -365,7 +365,7 @@ DumpRawTrace(
         Measurement.Identifier
       );
     } else {
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_VARS), gDpHiiHandle,
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_RAW_VARS), mDpHiiHandle,
         Index,      // 1 based, Which measurement record is being printed
         Measurement.Handle,
         Measurement.StartTimeStamp,
@@ -382,9 +382,9 @@ DumpRawTrace(
   return Status;
 }
 
-/** 
+/**
   Gather and print Major Phase metrics.
-  
+
 **/
 VOID
 ProcessPhases(
@@ -412,9 +412,9 @@ ProcessPhases(
   //
   // Get Execution Phase Statistics
   //
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);   
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PHASES), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PHASES), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown : StringPtr);
   FreePool (StringPtr);
   FreePool (StringPtrUnknown);
@@ -456,7 +456,7 @@ ProcessPhases(
   if (SecTime > 0) {
     ElapsedTime = DurationInMicroSeconds ( SecTime );     // Calculate elapsed time in microseconds
     Total += DivU64x32 (ElapsedTime, 1000);   // Accumulate time in milliseconds
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SEC_PHASE), gDpHiiHandle, ElapsedTime);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SEC_PHASE), mDpHiiHandle, ElapsedTime);
   }
 
   // print PEI phase duration time
@@ -467,7 +467,7 @@ ProcessPhases(
                     (UINT32)TimerInfo.Frequency
                     );
     Total += ElapsedTime;
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), gDpHiiHandle, ALit_PEI, ElapsedTime);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_PEI, ElapsedTime);
   }
 
   // print DXE phase duration time
@@ -478,7 +478,7 @@ ProcessPhases(
                     (UINT32)TimerInfo.Frequency
                     );
     Total += ElapsedTime;
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), gDpHiiHandle, ALit_DXE, ElapsedTime);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_DXE, ElapsedTime);
   }
 
   // print BDS phase duration time
@@ -489,7 +489,7 @@ ProcessPhases(
                     (UINT32)TimerInfo.Frequency
                     );
     Total += ElapsedTime;
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), gDpHiiHandle, ALit_BDS, ElapsedTime);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_DURATION), mDpHiiHandle, ALit_BDS, ElapsedTime);
   }
 
   if (BdsTimeoutValue > 0) {
@@ -497,17 +497,17 @@ ProcessPhases(
                     BdsTimeoutValue,
                     (UINT32)TimerInfo.Frequency
                     );
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_BDSTO), gDpHiiHandle, ALit_BdsTO, ElapsedTime);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PHASE_BDSTO), mDpHiiHandle, ALit_BdsTO, ElapsedTime);
   }
 
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOTAL_DURATION), gDpHiiHandle, Total);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_TOTAL_DURATION), mDpHiiHandle, Total);
 }
 
-/** 
+/**
   Gather and print Handle data.
-  
+
   @param[in]    ExcludeFlag   TRUE to exclude individual Cumulative items from display.
-  
+
   @retval EFI_SUCCESS             The operation was successful.
   @retval EFI_ABORTED             The user aborts the operation.
   @return Others                  from a call to gBS->LocateHandleBuffer().
@@ -529,16 +529,16 @@ ProcessHandles(
   EFI_STATUS                Status;
   EFI_STRING                StringPtrUnknown;
 
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_DRIVERS), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_DRIVERS), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown : StringPtr);
   FreePool (StringPtr);
   FreePool (StringPtrUnknown);
 
   Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, &HandleCount, &HandleBuffer);
   if (EFI_ERROR (Status)) {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), gDpHiiHandle, Status);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLES_ERROR), mDpHiiHandle, Status);
   }
   else {
 #if DP_DEBUG == 2
@@ -546,11 +546,11 @@ ProcessHandles(
 #endif
 
     if (mShowId) {
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_SECTION2), gDpHiiHandle);
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_SECTION2), mDpHiiHandle);
     } else {
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_SECTION), gDpHiiHandle);
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_SECTION), mDpHiiHandle);
     }
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
 
     LogEntryKey = 0;
     Count   = 0;
@@ -588,7 +588,7 @@ ProcessHandles(
       if (mGaugeString[0] != 0) {
         // Display the record if it has a valid handle.
         if (mShowId) {
-          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_VARS2), gDpHiiHandle,
+          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_VARS2), mDpHiiHandle,
             Count,      // 1 based, Which measurement record is being printed
             Index + 1,  // 1 based, Which handle is being printed
             mGaugeString,
@@ -597,7 +597,7 @@ ProcessHandles(
             Measurement.Identifier
           );
         } else {
-          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_VARS), gDpHiiHandle,
+          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_HANDLE_VARS), mDpHiiHandle,
             Count,      // 1 based, Which measurement record is being printed
             Index + 1,  // 1 based, Which handle is being printed
             mGaugeString,
@@ -618,11 +618,11 @@ ProcessHandles(
   return Status;
 }
 
-/** 
+/**
   Gather and print PEIM data.
-  
+
   Only prints complete PEIM records
-  
+
   @retval EFI_SUCCESS           The operation was successful.
   @retval EFI_ABORTED           The user aborts the operation.
 **/
@@ -642,19 +642,19 @@ ProcessPeims(
 
   Status = EFI_SUCCESS;
 
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PEIMS), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_PEIMS), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown : StringPtr);
   FreePool (StringPtr);
   FreePool (StringPtrUnknown);
 
   if (mShowId) {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_SECTION2), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_SECTION2), mDpHiiHandle);
   } else {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_SECTION), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_SECTION), mDpHiiHandle);
   }
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), gDpHiiHandle);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
   TIndex  = 0;
   LogEntryKey = 0;
   while ((LogEntryKey = GetPerformanceMeasurementEx (
@@ -678,7 +678,7 @@ ProcessPeims(
     if (ElapsedTime >= mInterestThreshold) {
       // PEIM FILE Handle is the start address of its FFS file that contains its file guid.
       if (mShowId) {
-        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_VARS2), gDpHiiHandle,
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_VARS2), mDpHiiHandle,
               TIndex,   // 1 based, Which measurement record is being printed
               Measurement.Handle,  // base address
               Measurement.Handle,  // file guid
@@ -686,7 +686,7 @@ ProcessPeims(
               Measurement.Identifier
         );
       } else {
-        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_VARS), gDpHiiHandle,
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_PEIM_VARS), mDpHiiHandle,
               TIndex,   // 1 based, Which measurement record is being printed
               Measurement.Handle,  // base address
               Measurement.Handle,  // file guid
@@ -702,14 +702,14 @@ ProcessPeims(
   return Status;
 }
 
-/** 
+/**
   Gather and print global data.
-  
+
   Strips out incomplete or "Execution Phase" records
   Only prints records where Handle is NULL
   Increment TIndex for every record, even skipped ones, so that we have an
   indication of every measurement record taken.
-  
+
   @retval EFI_SUCCESS           The operation was successful.
   @retval EFI_ABORTED           The user aborts the operation.
 **/
@@ -729,19 +729,19 @@ ProcessGlobal(
 
   Status = EFI_SUCCESS;
 
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_GENERAL), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_GENERAL), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown: StringPtr);
   FreePool (StringPtr);
   FreePool (StringPtrUnknown);
 
   if (mShowId) {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_SECTION2), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_SECTION2), mDpHiiHandle);
   } else {
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_SECTION), gDpHiiHandle);
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_SECTION), mDpHiiHandle);
   }
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), gDpHiiHandle);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
 
   Index = 1;
   LogEntryKey = 0;
@@ -768,7 +768,7 @@ ProcessGlobal(
       ElapsedTime = DurationInMicroSeconds ( Duration );
       if (ElapsedTime >= mInterestThreshold) {
         if (mShowId) {
-          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_VARS2), gDpHiiHandle,
+          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_VARS2), mDpHiiHandle,
             Index,
             mGaugeString,
             mUnicodeToken,
@@ -776,7 +776,7 @@ ProcessGlobal(
             Measurement.Identifier
             );
         } else {
-           ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_VARS), gDpHiiHandle,
+           ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_GLOBAL_VARS), mDpHiiHandle,
             Index,
             mGaugeString,
             mUnicodeToken,
@@ -794,9 +794,9 @@ ProcessGlobal(
   return Status;
 }
 
-/** 
+/**
   Gather and print cumulative data.
-  
+
   Traverse the measurement records and:<BR>
   For each record with a Token listed in the CumData array:<BR>
      - Update the instance count and the total, minimum, and maximum durations.
@@ -818,16 +818,16 @@ ProcessCumulative(
   UINTN                     TIndex;
   EFI_STRING                StringPtrUnknown;
 
-  StringPtrUnknown = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);  
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_CUMULATIVE), NULL);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), gDpHiiHandle,
+  StringPtrUnknown = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_ALIT_UNKNOWN), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_SECTION_CUMULATIVE), NULL);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_SECTION_HEADER), mDpHiiHandle,
               (StringPtr == NULL) ? StringPtrUnknown: StringPtr);
   FreePool (StringPtr);
   FreePool (StringPtrUnknown);
 
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_1), gDpHiiHandle);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_2), gDpHiiHandle);
-  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), gDpHiiHandle);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_1), mDpHiiHandle);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_SECT_2), mDpHiiHandle);
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_DASHES), mDpHiiHandle);
 
   for ( TIndex = 0; TIndex < NumCum; ++TIndex) {
     if (CumData[TIndex].Count != 0) {
@@ -836,8 +836,8 @@ ProcessCumulative(
       Dur    = DurationInMicroSeconds(CumData[TIndex].Duration);
       MaxDur = DurationInMicroSeconds(CumData[TIndex].MaxDur);
       MinDur = DurationInMicroSeconds(CumData[TIndex].MinDur);
-    
-      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_STATS), gDpHiiHandle,
+
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_STATS), mDpHiiHandle,
                   CumData[TIndex].Name,
                   CumData[TIndex].Count,
                   Dur,
@@ -864,7 +864,7 @@ ProcessCumulative(
       MaxDur = 0;
       MinDur = 0;
     }
-    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_STATS), gDpHiiHandle,
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DP_CUMULATIVE_STATS), mDpHiiHandle,
                 CustomCumulativeData->Name,
                 CustomCumulativeData->Count,
                 Dur,
diff --git a/ShellPkg/Library/UefiDpLib/DpUtilities.c b/ShellPkg/DynamicCommand/DpDynamicCommand/DpUtilities.c
similarity index 87%
rename from ShellPkg/Library/UefiDpLib/DpUtilities.c
rename to ShellPkg/DynamicCommand/DpDynamicCommand/DpUtilities.c
index c60d27d861..b98ec4b5bd 100644
--- a/ShellPkg/Library/UefiDpLib/DpUtilities.c
+++ b/ShellPkg/DynamicCommand/DpDynamicCommand/DpUtilities.c
@@ -196,18 +196,19 @@ DpGetNameFromHandle (
   IN EFI_HANDLE   Handle
   )
 {
-  EFI_STATUS                  Status;
-  EFI_LOADED_IMAGE_PROTOCOL   *Image;
-  CHAR8                       *PdbFileName;
-  EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;
-  EFI_STRING                  StringPtr;
-  EFI_DEVICE_PATH_PROTOCOL    *LoadedImageDevicePath;
-  EFI_DEVICE_PATH_PROTOCOL    *DevicePath;
-  EFI_GUID                    *NameGuid;
-  CHAR16                      *NameString;
-  UINTN                       StringSize;
-  CHAR8                       *PlatformLanguage;
-  EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;
+  EFI_STATUS                   Status;
+  EFI_LOADED_IMAGE_PROTOCOL    *Image;
+  CHAR8                        *PdbFileName;
+  EFI_DRIVER_BINDING_PROTOCOL  *DriverBinding;
+  EFI_STRING                   StringPtr;
+  EFI_DEVICE_PATH_PROTOCOL     *LoadedImageDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL     *DevicePath;
+  EFI_GUID                     *NameGuid;
+  CHAR16                       *NameString;
+  UINTN                        StringSize;
+  CHAR8                        *PlatformLanguage;
+  CHAR8                        *BestLanguage;
+  EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;
 
   Image = NULL;
   LoadedImageDevicePath = NULL;
@@ -259,16 +260,25 @@ DpGetNameFromHandle (
                   );
   if (!EFI_ERROR (Status)) {
     //
-    // Get the current platform language setting
+    // Firstly use platform language setting, secondly use driver's first supported language.
     //
-    PlatformLanguage = GetBestLanguageForDriver(ComponentName2->SupportedLanguages, NULL, FALSE);
+    GetVariable2 (L"PlatformLang", &gEfiGlobalVariableGuid, (VOID**)&PlatformLanguage, NULL);
+    BestLanguage = GetBestLanguage(
+                     ComponentName2->SupportedLanguages,
+                     FALSE,
+                     (PlatformLanguage != NULL) ? PlatformLanguage : "",
+                     ComponentName2->SupportedLanguages,
+                     NULL
+                     );
+    SHELL_FREE_NON_NULL (PlatformLanguage);
+
     Status = ComponentName2->GetDriverName (
                                ComponentName2,
-                               PlatformLanguage != NULL ? PlatformLanguage : "en-US",
+                               BestLanguage != NULL ? BestLanguage : "en-US",
                                &StringPtr
                                );
     if (!EFI_ERROR (Status)) {
-      SHELL_FREE_NON_NULL (PlatformLanguage);
+      SHELL_FREE_NON_NULL (BestLanguage);
       StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr, DP_GAUGE_STRING_LENGTH);
       mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;
       return;
@@ -344,7 +354,7 @@ DpGetNameFromHandle (
   //
   // Method 6: Unknown Driver Name
   //
-  StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);
+  StringPtr = HiiGetString (mDpHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);
   ASSERT (StringPtr != NULL);
   StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr, DP_GAUGE_STRING_LENGTH);
   FreePool (StringPtr);
diff --git a/ShellPkg/Library/UefiDpLib/Literals.c b/ShellPkg/DynamicCommand/DpDynamicCommand/Literals.c
similarity index 100%
rename from ShellPkg/Library/UefiDpLib/Literals.c
rename to ShellPkg/DynamicCommand/DpDynamicCommand/Literals.c
diff --git a/ShellPkg/Library/UefiDpLib/Literals.h b/ShellPkg/DynamicCommand/DpDynamicCommand/Literals.h
similarity index 100%
rename from ShellPkg/Library/UefiDpLib/Literals.h
rename to ShellPkg/DynamicCommand/DpDynamicCommand/Literals.h
diff --git a/ShellPkg/Library/UefiDpLib/PerformanceTokens.h b/ShellPkg/DynamicCommand/DpDynamicCommand/PerformanceTokens.h
similarity index 100%
rename from ShellPkg/Library/UefiDpLib/PerformanceTokens.h
rename to ShellPkg/DynamicCommand/DpDynamicCommand/PerformanceTokens.h
diff --git a/ShellPkg/Library/UefiDpLib/Readme.txt b/ShellPkg/Library/UefiDpLib/Readme.txt
deleted file mode 100644
index 849efa4360..0000000000
--- a/ShellPkg/Library/UefiDpLib/Readme.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-from PerformancePkg\Dp_App
-SVN 13406
diff --git a/ShellPkg/Library/UefiDpLib/UefiDpLib.c b/ShellPkg/Library/UefiDpLib/UefiDpLib.c
deleted file mode 100644
index f3ecfeac7f..0000000000
--- a/ShellPkg/Library/UefiDpLib/UefiDpLib.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/** @file
-  Main file for NULL named library for install1 shell command functions.
-
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.
-  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 "UefiDpLib.h"
-
-STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
-EFI_HANDLE gDpHiiHandle = NULL;
-
-#define DP_HII_GUID \
-  { \
-  0xeb832fd9, 0x9089, 0x4898, { 0x83, 0xc9, 0x41, 0x61, 0x8f, 0x5c, 0x48, 0xb9 } \
-  }
-
-EFI_GUID gDpHiiGuid = DP_HII_GUID;
-
-/**
-  Function to get the filename with help context if HII will not be used.
-
-  @return   The filename with help text in it.
-**/
-CONST CHAR16*
-EFIAPI
-UefiDpLibGetManFileName (
-  VOID
-  )
-{
-  return (mFileName);
-}
-
-/**
-  Constructor for the Shell Level 1 Commands library.
-
-  Install the handlers for level 1 UEFI Shell 2.0 commands.
-
-  @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
-UefiDpLibConstructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
-  )
-{
-  //
-  // check our bit of the profiles mask
-  //
-  if ((PcdGet8(PcdShellProfileMask) & BIT2) == 0) {
-    return (EFI_SUCCESS);
-  }
-
-  //
-  // 3rd parameter 'HII strings array' must be name of .uni strings file followed by 'Strings', e.g. mycommands.uni must be
-  // specified as 'mycommandsStrings' because the build Autogen process defines this as a string array for the strings in your
-  // .uni file.  Examine your Build folder under your package's DEBUG folder and you will find it defined in a xxxStrDefs.h file.
-  //
-  gDpHiiHandle = HiiAddPackages (&gDpHiiGuid, gImageHandle, UefiDpLibStrings, NULL);
-  if (gDpHiiHandle == NULL) {
-    return (EFI_DEVICE_ERROR);
-  }
-
-  //
-  // install our shell command handlers that are always installed
-  //
-  ShellCommandRegisterCommandName(L"dp", ShellCommandRunDp , UefiDpLibGetManFileName, 0, L"", FALSE, gDpHiiHandle, STRING_TOKEN(STR_GET_HELP_DP));
-
-  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
-UefiDpLibDestructor (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
-  )
-{
-  if (gDpHiiHandle != NULL) {
-    HiiRemovePackages(gDpHiiHandle);
-  }
-  return (EFI_SUCCESS);
-}
diff --git a/ShellPkg/Library/UefiDpLib/UefiDpLib.h b/ShellPkg/Library/UefiDpLib/UefiDpLib.h
deleted file mode 100644
index 283f8337ff..0000000000
--- a/ShellPkg/Library/UefiDpLib/UefiDpLib.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/** @file
-  Main file for NULL named library for dp command functions.
-
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
-  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<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.
-
-**/
-
-#ifndef _UEFI_DP_LIB_H_
-#define _UEFI_DP_LIB_H_
-
-#include <Uefi.h>
-
-extern EFI_GUID gDpHiiGuid;
-
-#include <Protocol/Shell.h>
-#include <Protocol/ShellParameters.h>
-#include <Protocol/DevicePath.h>
-#include <Protocol/LoadedImage.h>
-#include <Protocol/UnicodeCollation.h>
-
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/PcdLib.h>
-#include <Library/ShellCommandLib.h>
-#include <Library/ShellLib.h>
-#include <Library/SortLib.h>
-#include <Library/UefiLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/HiiLib.h>
-#include <Library/FileHandleLib.h>
-
-extern        EFI_HANDLE                        gDpHiiHandle;
-
-/**
-  Function for 'dp' command.
-
-  @param[in] ImageHandle  Handle to the Image (NULL if Internal).
-  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
-
-  @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
-ShellCommandRunDp (
-  IN EFI_HANDLE        ImageHandle,
-  IN EFI_SYSTEM_TABLE  *SystemTable
-  );
-
-#endif
-
diff --git a/ShellPkg/Library/UefiDpLib/UefiDpLib.inf b/ShellPkg/Library/UefiDpLib/UefiDpLib.inf
deleted file mode 100644
index 0bce0ce6c9..0000000000
--- a/ShellPkg/Library/UefiDpLib/UefiDpLib.inf
+++ /dev/null
@@ -1,77 +0,0 @@
-##  @file
-#  Display Performance Application, Module information file.
-#
-# Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
-# 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.
-#
-##
-
-[Defines]
-  INF_VERSION                    = 0x00010006
-  BASE_NAME                      = UefiDpLib
-  FILE_GUID                      = 9DF262F7-CF81-4294-B5A5-B2E3CAFE5618
-  MODULE_TYPE                    = UEFI_DRIVER
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = NULL|UEFI_APPLICATION UEFI_DRIVER
-  CONSTRUCTOR                    = UefiDpLibConstructor
-  DESTRUCTOR                     = UefiDpLibDestructor
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
-#
-
-[Sources.common]
-  PerformanceTokens.h
-  UefiDpLib.c
-  UefiDpLib.h
-  UefiDpLib.uni
-  Dp.c
-  Dp.h
-  Literals.h
-  Literals.c
-  DpInternal.h
-  DpUtilities.c
-  DpTrace.c
-  DpProfile.c
-
-[Packages]
-  MdePkg/MdePkg.dec
-  ShellPkg/ShellPkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-
-[LibraryClasses]
-  PerformanceLib
-  DxeServicesLib
-  MemoryAllocationLib
-  BaseLib
-  BaseMemoryLib
-  DebugLib
-  ShellCommandLib
-  ShellLib
-  UefiLib
-  UefiRuntimeServicesTableLib
-  UefiBootServicesTableLib
-  SortLib
-  PrintLib
-  DevicePathLib
-
-[Guids]
-  gPerformanceProtocolGuid                                ## CONSUMES ## SystemTable
-
-[Protocols]
-  gEfiLoadedImageProtocolGuid                             ## CONSUMES
-  gEfiDriverBindingProtocolGuid                           ## SOMETIMES_CONSUMES
-  gEfiComponentName2ProtocolGuid                          ## SOMETIMES_CONSUMES
-  gEfiLoadedImageDevicePathProtocolGuid                   ## SOMETIMES_CONSUMES
-
-[Pcd]
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize   ## UNDEFINED
-  gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask          ## CONSUMES
diff --git a/ShellPkg/ShellPkg.dsc b/ShellPkg/ShellPkg.dsc
index 7eaecedb56..548d4bd8b9 100644
--- a/ShellPkg/ShellPkg.dsc
+++ b/ShellPkg/ShellPkg.dsc
@@ -108,7 +108,6 @@ [Components]
   ShellPkg/Library/UefiDpLib/UefiDpLib.inf {
     <LibraryClasses>
       PerformanceLib|MdeModulePkg/Library/DxeSmmPerformanceLib/DxeSmmPerformanceLib.inf
-      DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
   }
 
   ShellPkg/Application/Shell/Shell.inf {
@@ -122,14 +121,19 @@ [Components]
       NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
       NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
       NULL|ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf
-!ifdef $(INCLUDE_DP)
-      NULL|ShellPkg/Library/UefiDpLib/UefiDpLib.inf
-!endif #$(INCLUDE_DP)
 !endif #$(NO_SHELL_PROFILES)
   }
 
   ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
   ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf
+  ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf {
+    <LibraryClasses>
+      PerformanceLib|MdeModulePkg/Library/DxeSmmPerformanceLib/DxeSmmPerformanceLib.inf
+  }
+  ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf {
+    <LibraryClasses>
+      PerformanceLib|MdeModulePkg/Library/DxeSmmPerformanceLib/DxeSmmPerformanceLib.inf
+  }
 
 [BuildOptions]
   *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
-- 
2.15.0.gvfs.1.preview.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-27  0:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/3] ShellPkg/tftp: Convert from NULL class library to Dynamic Command Ruiyu Ni
2017-11-27  0:58 ` [PATCH 3/3] ShellPkg/dp: " Ruiyu Ni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox