]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg/ShellLib: Fix dynamic command fails to start during boot
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index d131f9b189ea920b1455f43713940cff03c0ffe1..7f6389f655783a7a68156490c2118b9c0e8cf5d7 100644 (file)
@@ -1,7 +1,9 @@
 /** @file\r
   Provides interface to shell functionality for shell commands and applications.\r
 \r
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+  Copyright 2016 Dell Inc.\r
+  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 **/\r
 \r
 #include "UefiShellLib.h"\r
-#include <ShellBase.h>\r
 #include <Library/SortLib.h>\r
-\r
-#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)\r
+#include <Library/BaseLib.h>\r
 \r
 //\r
 // globals...\r
@@ -34,6 +34,7 @@ EFI_SHELL_PROTOCOL            *gEfiShellProtocol;
 EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol;\r
 EFI_HANDLE                    mEfiShellEnvironment2Handle;\r
 FILE_HANDLE_FUNCTION_MAP      FileFunctionMap;\r
+EFI_UNICODE_COLLATION_PROTOCOL  *mUnicodeCollationProtocol;\r
 \r
 /**\r
   Check if a Unicode character is a hexadecimal character.\r
@@ -88,7 +89,6 @@ ShellIsDecimalDigitCharacter (
   @retval EFI_OUT_OF_RESOURCES    Memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ShellFindSE2 (\r
   IN EFI_HANDLE        ImageHandle\r
   )\r
@@ -163,7 +163,7 @@ ShellFindSE2 (
 }\r
 \r
 /**\r
-  Function to do most of the work of the constructor.  Allows for calling \r
+  Function to do most of the work of the constructor.  Allows for calling\r
   multiple times without complete re-initialization.\r
 \r
   @param[in] ImageHandle  A copy of the ImageHandle.\r
@@ -172,7 +172,6 @@ ShellFindSE2 (
   @retval EFI_SUCCESS   The operationw as successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ShellLibConstructorWorker (\r
   IN EFI_HANDLE        ImageHandle,\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
@@ -180,43 +179,48 @@ ShellLibConstructorWorker (
 {\r
   EFI_STATUS  Status;\r
 \r
-  //\r
-  // UEFI 2.0 shell interfaces (used preferentially)\r
-  //\r
-  Status = gBS->OpenProtocol(\r
-    ImageHandle,\r
-    &gEfiShellProtocolGuid,\r
-    (VOID **)&gEfiShellProtocol,\r
-    ImageHandle,\r
-    NULL,\r
-    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-   );\r
-  if (EFI_ERROR(Status)) {\r
+  if (gEfiShellProtocol == NULL) {\r
     //\r
-    // Search for the shell protocol\r
+    // UEFI 2.0 shell interfaces (used preferentially)\r
     //\r
-    Status = gBS->LocateProtocol(\r
+    Status = gBS->OpenProtocol (\r
+      ImageHandle,\r
       &gEfiShellProtocolGuid,\r
+      (VOID **)&gEfiShellProtocol,\r
+      ImageHandle,\r
       NULL,\r
-      (VOID **)&gEfiShellProtocol\r
-     );\r
-    if (EFI_ERROR(Status)) {\r
-      gEfiShellProtocol = NULL;\r
+      EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+    );\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Search for the shell protocol\r
+      //\r
+      Status = gBS->LocateProtocol (\r
+        &gEfiShellProtocolGuid,\r
+        NULL,\r
+        (VOID **)&gEfiShellProtocol\r
+      );\r
+      if (EFI_ERROR (Status)) {\r
+        gEfiShellProtocol = NULL;\r
+      }\r
     }\r
   }\r
-  Status = gBS->OpenProtocol(\r
-    ImageHandle,\r
-    &gEfiShellParametersProtocolGuid,\r
-    (VOID **)&gEfiShellParametersProtocol,\r
-    ImageHandle,\r
-    NULL,\r
-    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-   );\r
-  if (EFI_ERROR(Status)) {\r
-    gEfiShellParametersProtocol = NULL;\r
+\r
+  if (gEfiShellParametersProtocol == NULL) {\r
+    Status = gBS->OpenProtocol (\r
+      ImageHandle,\r
+      &gEfiShellParametersProtocolGuid,\r
+      (VOID **)&gEfiShellParametersProtocol,\r
+      ImageHandle,\r
+      NULL,\r
+      EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+    );\r
+    if (EFI_ERROR (Status)) {\r
+      gEfiShellParametersProtocol = NULL;\r
+    }\r
   }\r
 \r
-  if (gEfiShellParametersProtocol == NULL || gEfiShellProtocol == NULL) {\r
+  if (gEfiShellProtocol == NULL) {\r
     //\r
     // Moved to seperate function due to complexity\r
     //\r
@@ -239,10 +243,14 @@ ShellLibConstructorWorker (
   }\r
 \r
   //\r
-  // only success getting 2 of either the old or new, but no 1/2 and 1/2\r
+  // Getting either EDK Shell's ShellEnvironment2 and ShellInterface protocol\r
+  //  or UEFI Shell's Shell protocol.\r
+  // When ShellLib is linked to a driver producing DynamicCommand protocol,\r
+  //  ShellParameters protocol is set by DynamicCommand.Handler().\r
   //\r
-  if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface          != NULL) ||\r
-      (gEfiShellProtocol     != NULL && gEfiShellParametersProtocol != NULL)   ) {\r
+  if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) ||\r
+      (gEfiShellProtocol     != NULL)\r
+      ) {\r
     if (gEfiShellProtocol != NULL) {\r
       FileFunctionMap.GetFileInfo     = gEfiShellProtocol->GetFileInfo;\r
       FileFunctionMap.SetFileInfo     = gEfiShellProtocol->SetFileInfo;\r
@@ -293,6 +301,7 @@ ShellLibConstructor (
   gEfiShellParametersProtocol = NULL;\r
   mEfiShellInterface          = NULL;\r
   mEfiShellEnvironment2Handle = NULL;\r
+  mUnicodeCollationProtocol   = NULL;\r
 \r
   //\r
   // verify that auto initialize is not set false\r
@@ -320,35 +329,45 @@ ShellLibDestructor (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
+  EFI_STATUS           Status;\r
+\r
   if (mEfiShellEnvironment2 != NULL) {\r
-    gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle,\r
+    Status = gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle,\r
                        &gEfiShellEnvironment2Guid,\r
                        ImageHandle,\r
                        NULL);\r
-    mEfiShellEnvironment2 = NULL;\r
+    if (!EFI_ERROR (Status)) {\r
+      mEfiShellEnvironment2       = NULL;\r
+      mEfiShellEnvironment2Handle = NULL;\r
+    }\r
   }\r
   if (mEfiShellInterface != NULL) {\r
-    gBS->CloseProtocol(ImageHandle,\r
+    Status = gBS->CloseProtocol(ImageHandle,\r
                        &gEfiShellInterfaceGuid,\r
                        ImageHandle,\r
                        NULL);\r
-    mEfiShellInterface = NULL;\r
+    if (!EFI_ERROR (Status)) {\r
+      mEfiShellInterface = NULL;\r
+    }\r
   }\r
   if (gEfiShellProtocol != NULL) {\r
-    gBS->CloseProtocol(ImageHandle,\r
+    Status = gBS->CloseProtocol(ImageHandle,\r
                        &gEfiShellProtocolGuid,\r
                        ImageHandle,\r
                        NULL);\r
-    gEfiShellProtocol = NULL;\r
+    if (!EFI_ERROR (Status)) {\r
+      gEfiShellProtocol = NULL;\r
+    }\r
   }\r
   if (gEfiShellParametersProtocol != NULL) {\r
-    gBS->CloseProtocol(ImageHandle,\r
+    Status = gBS->CloseProtocol(ImageHandle,\r
                        &gEfiShellParametersProtocolGuid,\r
                        ImageHandle,\r
                        NULL);\r
-    gEfiShellParametersProtocol = NULL;\r
+    if (!EFI_ERROR (Status)) {\r
+      gEfiShellParametersProtocol = NULL;\r
+    }\r
   }\r
-  mEfiShellEnvironment2Handle = NULL;\r
 \r
   return (EFI_SUCCESS);\r
 }\r
@@ -369,8 +388,11 @@ ShellLibDestructor (
 EFI_STATUS\r
 EFIAPI\r
 ShellInitialize (\r
+  VOID\r
   )\r
 {\r
+  EFI_STATUS Status;\r
+\r
   //\r
   // if auto initialize is not false then skip\r
   //\r
@@ -381,7 +403,8 @@ ShellInitialize (
   //\r
   // deinit the current stuff\r
   //\r
-  ASSERT_EFI_ERROR(ShellLibDestructor(gImageHandle, gST));\r
+  Status = ShellLibDestructor (gImageHandle, gST);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // init the new stuff\r
@@ -421,20 +444,20 @@ ShellGetFileInfo (
 \r
   @param[in]  FileInfo          The information to set.\r
 \r
-  @retval EFI_SUCCESS                  The information was set.\r
+  @retval EFI_SUCCESS           The information was set.\r
   @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
   @retval EFI_UNSUPPORTED       The FileHandle does not support FileInfo.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
   @retval EFI_ACCESS_DENIED     The file was opened read only.\r
   @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFileInfo (\r
-  IN SHELL_FILE_HANDLE                         FileHandle,\r
+  IN SHELL_FILE_HANDLE                    FileHandle,\r
   IN EFI_FILE_INFO              *FileInfo\r
   )\r
 {\r
@@ -447,38 +470,38 @@ ShellSetFileInfo (
   This function opens a file with the open mode according to the file path. The\r
   Attributes is valid only for EFI_FILE_MODE_CREATE.\r
 \r
-  @param  FilePath                 on input the device path to the file.  On output\r
+  @param  FilePath        on input the device path to the file.  On output\r
                           the remaining device path.\r
-  @param  DeviceHandle         pointer to the system device handle.\r
-  @param  FileHandle             pointer to the file handle.\r
-  @param  OpenMode                 the mode to open the file with.\r
-  @param  Attributes             the file's file attributes.\r
-\r
-  @retval EFI_SUCCESS                  The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED            Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @param  DeviceHandle    pointer to the system device handle.\r
+  @param  FileHandle      pointer to the file handle.\r
+  @param  OpenMode        the mode to open the file with.\r
+  @param  Attributes      the file's file attributes.\r
+\r
+  @retval EFI_SUCCESS           The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED       Could not open the file path.\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device or the file system could not be found on\r
                                 the device.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED        The device has a different medium in it or the\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED        The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED     The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
-  @retval EFI_VOLUME_FULL            The volume is full.\r
+  @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellOpenFileByDevicePath(\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL        **FilePath,\r
-  OUT EFI_HANDLE                       *DeviceHandle,\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL     **FilePath,\r
+  OUT EFI_HANDLE                      *DeviceHandle,\r
   OUT SHELL_FILE_HANDLE               *FileHandle,\r
-  IN UINT64                            OpenMode,\r
-  IN UINT64                            Attributes\r
+  IN UINT64                           OpenMode,\r
+  IN UINT64                           Attributes\r
   )\r
 {\r
   CHAR16                          *FileName;\r
@@ -486,6 +509,8 @@ ShellOpenFileByDevicePath(
   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
   EFI_FILE_PROTOCOL               *Handle1;\r
   EFI_FILE_PROTOCOL               *Handle2;\r
+  CHAR16                          *FnafPathName;\r
+  UINTN                           PathLen;\r
 \r
   if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
@@ -551,13 +576,36 @@ ShellOpenFileByDevicePath(
     Handle2  = Handle1;\r
     Handle1 = NULL;\r
 \r
+    //\r
+    // File Name Alignment Fix (FNAF)\r
+    // Handle2->Open may be incapable of handling a unaligned CHAR16 data.\r
+    // The structure pointed to by FilePath may be not CHAR16 aligned.\r
+    // This code copies the potentially unaligned PathName data from the\r
+    // FilePath structure to the aligned FnafPathName for use in the\r
+    // calls to Handl2->Open.\r
+    //\r
+\r
+    //\r
+    // Determine length of PathName, in bytes.\r
+    //\r
+    PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;\r
+\r
+    //\r
+    // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment\r
+    // Copy bytes from possibly unaligned location to aligned location\r
+    //\r
+    FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName);\r
+    if (FnafPathName == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
     //\r
     // Try to test opening an existing file\r
     //\r
     Status = Handle2->Open (\r
                           Handle2,\r
                           &Handle1,\r
-                          ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
+                          FnafPathName,\r
                           OpenMode &~EFI_FILE_MODE_CREATE,\r
                           0\r
                          );\r
@@ -569,11 +617,17 @@ ShellOpenFileByDevicePath(
       Status = Handle2->Open (\r
                             Handle2,\r
                             &Handle1,\r
-                            ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
+                            FnafPathName,\r
                             OpenMode,\r
                             Attributes\r
                            );\r
     }\r
+\r
+    //\r
+    // Free the alignment buffer\r
+    //\r
+    FreePool(FnafPathName);\r
+\r
     //\r
     // Close the last node\r
     //\r
@@ -605,41 +659,43 @@ ShellOpenFileByDevicePath(
 \r
   if FileName is NULL then ASSERT()\r
 \r
-  @param  FileName               pointer to file name\r
-  @param  FileHandle           pointer to the file handle.\r
-  @param  OpenMode               the mode to open the file with.\r
-  @param  Attributes           the file's file attributes.\r
+  @param  FileName      pointer to file name\r
+  @param  FileHandle    pointer to the file handle.\r
+  @param  OpenMode      the mode to open the file with.\r
+  @param  Attributes    the file's file attributes.\r
 \r
-  @retval EFI_SUCCESS                  The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED            Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @retval EFI_SUCCESS           The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED       Could not open the file path.\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device or the file system could not be found\r
                                 on the device.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED        The device has a different medium in it or the\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED        The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED     The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
-  @retval EFI_VOLUME_FULL            The volume is full.\r
+  @retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellOpenFileByName(\r
-  IN CONST CHAR16                          *FileName,\r
+  IN CONST CHAR16               *FileName,\r
   OUT SHELL_FILE_HANDLE         *FileHandle,\r
   IN UINT64                     OpenMode,\r
-  IN UINT64                            Attributes\r
+  IN UINT64                     Attributes\r
   )\r
 {\r
   EFI_HANDLE                    DeviceHandle;\r
   EFI_DEVICE_PATH_PROTOCOL      *FilePath;\r
   EFI_STATUS                    Status;\r
   EFI_FILE_INFO                 *FileInfo;\r
+  CHAR16                        *FileNameCopy;\r
+  EFI_STATUS                    Status2;\r
 \r
   //\r
   // ASSERT if FileName is NULL\r
@@ -651,21 +707,61 @@ ShellOpenFileByName(
   }\r
 \r
   if (gEfiShellProtocol != NULL) {\r
-    if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE && (Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {\r
-      return ShellCreateDirectory(FileName, FileHandle);\r
+    if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE) {\r
+\r
+      //\r
+      // Create only a directory\r
+      //\r
+      if ((Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {\r
+        return ShellCreateDirectory(FileName, FileHandle);\r
+      }\r
+\r
+      //\r
+      // Create the directory to create the file in\r
+      //\r
+      FileNameCopy = AllocateCopyPool (StrSize (FileName), FileName);\r
+      if (FileNameCopy == NULL) {\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
+      PathCleanUpDirectories (FileNameCopy);\r
+      if (PathRemoveLastItem (FileNameCopy)) {\r
+        if (!EFI_ERROR(ShellCreateDirectory (FileNameCopy, FileHandle))) {\r
+          ShellCloseFile (FileHandle);\r
+        }\r
+      }\r
+      SHELL_FREE_NON_NULL (FileNameCopy);\r
     }\r
+\r
     //\r
-    // Use UEFI Shell 2.0 method\r
+    // Use UEFI Shell 2.0 method to create the file\r
     //\r
     Status = gEfiShellProtocol->OpenFileByName(FileName,\r
                                                FileHandle,\r
                                                OpenMode);\r
-    if (StrCmp(FileName, L"NUL") != 0 && !EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){\r
+    if (EFI_ERROR(Status)) {\r
+      return Status;\r
+    }\r
+\r
+    if (mUnicodeCollationProtocol == NULL) {\r
+      Status = gBS->LocateProtocol (&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&mUnicodeCollationProtocol);\r
+      if (EFI_ERROR (Status)) {\r
+        gEfiShellProtocol->CloseFile (*FileHandle);\r
+        return Status;\r
+      }\r
+    }\r
+\r
+    if ((mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16*)FileName, L"NUL") != 0) &&\r
+        (mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16*)FileName, L"NULL") != 0) &&\r
+         !EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){\r
       FileInfo = FileFunctionMap.GetFileInfo(*FileHandle);\r
       ASSERT(FileInfo != NULL);\r
       FileInfo->Attribute = Attributes;\r
-      Status = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo);\r
+      Status2 = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo);\r
       FreePool(FileInfo);\r
+      if (EFI_ERROR (Status2)) {\r
+        gEfiShellProtocol->CloseFile(*FileHandle);\r
+      }\r
+      Status = Status2;\r
     }\r
     return (Status);\r
   }\r
@@ -692,25 +788,25 @@ ShellOpenFileByName(
   otherwise, the Filehandle is NULL. If the directory already existed, this\r
   function opens the existing directory.\r
 \r
-  @param  DirectoryName                pointer to directory name\r
-  @param  FileHandle             pointer to the file handle.\r
+  @param  DirectoryName   pointer to directory name\r
+  @param  FileHandle      pointer to the file handle.\r
 \r
-  @retval EFI_SUCCESS                  The information was set.\r
-  @retval EFI_INVALID_PARAMETER        One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED            Could not open the file path.\r
-  @retval EFI_NOT_FOUND                The specified file could not be found on the\r
+  @retval EFI_SUCCESS           The information was set.\r
+  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
+  @retval EFI_UNSUPPORTED       Could not open the file path.\r
+  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
                                 device or the file system could not be found\r
                                 on the device.\r
-  @retval EFI_NO_MEDIA               The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED        The device has a different medium in it or the\r
+  @retval EFI_NO_MEDIA          The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
                                 medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR         The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED    The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED        The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the\r
+  @retval EFI_DEVICE_ERROR      The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED     The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
                                 file.\r
-  @retval EFI_VOLUME_FULL            The volume is full.\r
+  @retval EFI_VOLUME_FULL       The volume is full.\r
   @sa ShellOpenFileByName\r
 **/\r
 EFI_STATUS\r
@@ -758,11 +854,11 @@ ShellCreateDirectory(
                                 the number of bytes written.\r
   @param Buffer                 the buffer to put read data into.\r
 \r
-  @retval EFI_SUCCESS            Data was read.\r
-  @retval EFI_NO_MEDIA         The device has no media.\r
-  @retval EFI_DEVICE_ERROR     The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_BUFFER_TO_SMALL  Buffer is too small. ReadSize contains required\r
+  @retval EFI_SUCCESS           Data was read.\r
+  @retval EFI_NO_MEDIA          The device has no media.\r
+  @retval EFI_DEVICE_ERROR  The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+  @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required\r
                                 size.\r
 \r
 **/\r
@@ -793,14 +889,14 @@ ShellReadFile(
                               the number of bytes written.\r
   @param Buffer               the buffer containing data to write is stored.\r
 \r
- @retval EFI_SUCCESS           Data was written.\r
- @retval EFI_UNSUPPORTED           Writes to an open directory are not supported.\r
- @retval EFI_NO_MEDIA          The device has no media.\r
- @retval EFI_DEVICE_ERROR          The device reported an error.\r
- @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
- @retval EFI_WRITE_PROTECTED   The device is write-protected.\r
- @retval EFI_ACCESS_DENIED       The file was open for read only.\r
- @retval EFI_VOLUME_FULL           The volume is full.\r
+ @retval EFI_SUCCESS          Data was written.\r
+ @retval EFI_UNSUPPORTED      Writes to an open directory are not supported.\r
+ @retval EFI_NO_MEDIA         The device has no media.\r
+ @retval EFI_DEVICE_ERROR     The device reported an error.\r
+ @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+ @retval EFI_WRITE_PROTECTED  The device is write-protected.\r
+ @retval EFI_ACCESS_DENIED    The file was open for read only.\r
+ @retval EFI_VOLUME_FULL      The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -845,12 +941,12 @@ ShellCloseFile (
   @retval EFI_SUCCESS           the file was closed sucessfully\r
   @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
                                 deleted\r
-  @retval INVALID_PARAMETER            One of the parameters has an invalid value.\r
+  @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 ShellDeleteFile (\r
-  IN SHELL_FILE_HANDLE                         *FileHandle\r
+  IN SHELL_FILE_HANDLE            *FileHandle\r
   )\r
 {\r
   return (FileFunctionMap.DeleteFile(*FileHandle));\r
@@ -878,8 +974,8 @@ ShellDeleteFile (
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFilePosition (\r
-  IN SHELL_FILE_HANDLE                 FileHandle,\r
-  IN UINT64            Position\r
+  IN SHELL_FILE_HANDLE              FileHandle,\r
+  IN UINT64             Position\r
   )\r
 {\r
   return (FileFunctionMap.SetFilePosition(FileHandle, Position));\r
@@ -932,15 +1028,19 @@ ShellFlushFile (
   return (FileFunctionMap.FlushFile(FileHandle));\r
 }\r
 \r
-/**\r
-  Retrieves the first file from a directory\r
+/** Retrieve first entry from a directory.\r
+\r
+  This function takes an open directory handle and gets information from the\r
+  first entry in the directory.  A buffer is allocated to contain\r
+  the information and a pointer to the buffer is returned in *Buffer.  The\r
+  caller can use ShellFindNextFile() to get subsequent directory entries.\r
 \r
-  This function opens a directory and gets the first file's info in the\r
-  directory. Caller can use ShellFindNextFile() to get other files.  When\r
-  complete the caller is responsible for calling FreePool() on Buffer.\r
+  The buffer will be freed by ShellFindNextFile() when the last directory\r
+  entry is read.  Otherwise, the caller must free the buffer, using FreePool,\r
+  when finished with it.\r
 \r
-  @param DirHandle              The file handle of the directory to search\r
-  @param Buffer                 Pointer to buffer for file's information\r
+  @param[in]  DirHandle         The file handle of the directory to search.\r
+  @param[out] Buffer            The pointer to the buffer for the file's information.\r
 \r
   @retval EFI_SUCCESS           Found the first file.\r
   @retval EFI_NOT_FOUND         Cannot find the directory.\r
@@ -962,19 +1062,18 @@ ShellFindFirstFile (
   //\r
   return (FileHandleFindFirstFile(DirHandle, Buffer));\r
 }\r
-/**\r
-  Retrieves the next file in a directory.\r
+/** Retrieve next entries from a directory.\r
 \r
-  To use this function, caller must call the ShellFindFirstFile() to get the\r
-  first file, and then use this function get other files. This function can be\r
-  called for several times to get each file's information in the directory. If\r
-  the call of ShellFindNextFile() got the last file in the directory, the next\r
-  call of this function has no file to get. *NoFile will be set to TRUE and the\r
-  Buffer memory will be automatically freed.\r
+  To use this function, the caller must first call the ShellFindFirstFile()\r
+  function to get the first directory entry.  Subsequent directory entries are\r
+  retrieved by using the ShellFindNextFile() function.  This function can\r
+  be called several times to get each entry from the directory.  If the call of\r
+  ShellFindNextFile() retrieved the last directory entry, the next call of\r
+  this function will set *NoFile to TRUE and free the buffer.\r
 \r
-  @param DirHandle              the file handle of the directory\r
-  @param Buffer                                    pointer to buffer for file's information\r
-  @param NoFile                                    pointer to boolean when last file is found\r
+  @param[in]  DirHandle         The file handle of the directory.\r
+  @param[out] Buffer            The pointer to buffer for file's information.\r
+  @param[out] NoFile            The pointer to boolean when last file is found.\r
 \r
   @retval EFI_SUCCESS           Found the next file, or reached last file\r
   @retval EFI_NO_MEDIA          The device has no media.\r
@@ -1141,7 +1240,7 @@ ShellSetEnvironmentVariable (
   The CommandLine is executed from the current working directory on the current\r
   device.\r
 \r
-  The EnvironmentVariables and Status parameters are ignored in a pre-UEFI Shell 2.0\r
+  The EnvironmentVariables pararemeter is ignored in a pre-UEFI Shell 2.0\r
   environment.  The values pointed to by the parameters will be unchanged by the\r
   ShellExecute() function.  The Output parameter has no effect in a\r
   UEFI Shell 2.0 environment.\r
@@ -1169,6 +1268,7 @@ ShellExecute (
   OUT EFI_STATUS                *Status OPTIONAL\r
   )\r
 {\r
+  EFI_STATUS                CmdStatus;\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
@@ -1187,16 +1287,29 @@ ShellExecute (
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
     //\r
-    // Call EFI Shell version (not using EnvironmentVariables or Status parameters)\r
+    // Call EFI Shell version.\r
     // Due to oddity in the EFI shell we want to dereference the ParentHandle here\r
     //\r
-    return (mEfiShellEnvironment2->Execute(*ParentHandle,\r
+    CmdStatus = (mEfiShellEnvironment2->Execute(*ParentHandle,\r
                                           CommandLine,\r
                                           Output));\r
+    //\r
+    // No Status output parameter so just use the returned status\r
+    //\r
+    if (Status != NULL) {\r
+      *Status = CmdStatus;\r
+    }\r
+    //\r
+    // If there was an error, we can't tell if it was from the command or from\r
+    // the Execute() function, so we'll just assume the shell ran successfully\r
+    // and the error came from the command.\r
+    //\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   return (EFI_UNSUPPORTED);\r
 }\r
+\r
 /**\r
   Retreives the current directory path\r
 \r
@@ -1204,6 +1317,8 @@ ShellExecute (
   name. If the DeviceName is not NULL, it returns the current directory name\r
   on specified drive.\r
 \r
+  Note that the current directory string should exclude the tailing backslash character.\r
+\r
   @param DeviceName             the name of the drive to get directory on\r
 \r
   @retval NULL                  the directory does not exist\r
@@ -1323,7 +1438,6 @@ typedef struct {
   @retval the resultant head of the double linked new format list;\r
 **/\r
 LIST_ENTRY*\r
-EFIAPI\r
 InternalShellConvertFileListType (\r
   IN LIST_ENTRY                 *FileList,\r
   IN OUT LIST_ENTRY             *ListHead\r
@@ -1382,26 +1496,30 @@ InternalShellConvertFileListType (
     //\r
     // allocate new space to copy strings and structure\r
     //\r
-    NewInfo->FullName     = AllocateZeroPool(StrSize(OldInfo->FullName));\r
-    NewInfo->FileName     = AllocateZeroPool(StrSize(OldInfo->FileName));\r
-    NewInfo->Info         = AllocateZeroPool((UINTN)OldInfo->Info->Size);\r
+    NewInfo->FullName     = AllocateCopyPool(StrSize(OldInfo->FullName), OldInfo->FullName);\r
+    NewInfo->FileName     = AllocateCopyPool(StrSize(OldInfo->FileName), OldInfo->FileName);\r
+    NewInfo->Info         = AllocateCopyPool((UINTN)OldInfo->Info->Size, OldInfo->Info);\r
 \r
     //\r
     // make sure all the memory allocations were sucessful\r
     //\r
     if (NULL == NewInfo->FullName || NewInfo->FileName == NULL || NewInfo->Info == NULL) {\r
+      //\r
+      // Free the partially allocated new node\r
+      //\r
+      SHELL_FREE_NON_NULL(NewInfo->FullName);\r
+      SHELL_FREE_NON_NULL(NewInfo->FileName);\r
+      SHELL_FREE_NON_NULL(NewInfo->Info);\r
+      SHELL_FREE_NON_NULL(NewInfo);\r
+\r
+      //\r
+      // Free the previously converted stuff\r
+      //\r
       ShellCloseFileMetaArg((EFI_SHELL_FILE_INFO**)(&ListHead));\r
       ListHead = NULL;\r
       break;\r
     }\r
 \r
-    //\r
-    // Copt the strings and structure\r
-    //\r
-    StrCpy(NewInfo->FullName, OldInfo->FullName);\r
-    StrCpy(NewInfo->FileName, OldInfo->FileName);\r
-    gBS->CopyMem (NewInfo->Info, OldInfo->Info, (UINTN)OldInfo->Info->Size);\r
-\r
     //\r
     // add that to the list\r
     //\r
@@ -1413,8 +1531,8 @@ InternalShellConvertFileListType (
   Opens a group of files based on a path.\r
 \r
   This function uses the Arg to open all the matching files. Each matched\r
-  file has a SHELL_FILE_ARG structure to record the file information. These\r
-  structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG\r
+  file has a SHELL_FILE_INFO structure to record the file information. These\r
+  structures are placed on the list ListHead. Users can get the SHELL_FILE_INFO\r
   structures from ListHead to access each file. This function supports wildcards\r
   and will process '?' and '*' as such.  the list must be freed with a call to\r
   ShellCloseFileMetaArg().\r
@@ -1442,6 +1560,7 @@ ShellOpenFileMetaArg (
 {\r
   EFI_STATUS                    Status;\r
   LIST_ENTRY                    mOldStyleFileList;\r
+  CHAR16                        *CleanFilePathStr;\r
 \r
   //\r
   // ASSERT that Arg and ListHead are not NULL\r
@@ -1449,6 +1568,13 @@ ShellOpenFileMetaArg (
   ASSERT(Arg      != NULL);\r
   ASSERT(ListHead != NULL);\r
 \r
+  CleanFilePathStr = NULL;\r
+\r
+  Status = InternalShellStripQuotes (Arg, &CleanFilePathStr);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
@@ -1456,11 +1582,12 @@ ShellOpenFileMetaArg (
     if (*ListHead == NULL) {\r
       *ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
       if (*ListHead == NULL) {\r
+        FreePool(CleanFilePathStr);\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
       InitializeListHead(&((*ListHead)->Link));\r
     }\r
-    Status = gEfiShellProtocol->OpenFileList(Arg,\r
+    Status = gEfiShellProtocol->OpenFileList(CleanFilePathStr,\r
                                            OpenMode,\r
                                            ListHead);\r
     if (EFI_ERROR(Status)) {\r
@@ -1470,9 +1597,11 @@ ShellOpenFileMetaArg (
     }\r
     if (*ListHead != NULL && IsListEmpty(&(*ListHead)->Link)) {\r
       FreePool(*ListHead);\r
+      FreePool(CleanFilePathStr);\r
       *ListHead = NULL;\r
       return (EFI_NOT_FOUND);\r
     }\r
+    FreePool(CleanFilePathStr);\r
     return (Status);\r
   }\r
 \r
@@ -1488,15 +1617,17 @@ ShellOpenFileMetaArg (
     //\r
     // Get the EFI Shell list of files\r
     //\r
-    Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList);\r
+    Status = mEfiShellEnvironment2->FileMetaArg(CleanFilePathStr, &mOldStyleFileList);\r
     if (EFI_ERROR(Status)) {\r
       *ListHead = NULL;\r
+      FreePool(CleanFilePathStr);\r
       return (Status);\r
     }\r
 \r
     if (*ListHead == NULL) {\r
       *ListHead = (EFI_SHELL_FILE_INFO    *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
       if (*ListHead == NULL) {\r
+        FreePool(CleanFilePathStr);\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
       InitializeListHead(&((*ListHead)->Link));\r
@@ -1517,9 +1648,11 @@ ShellOpenFileMetaArg (
       *ListHead = NULL;\r
       Status = EFI_NOT_FOUND;\r
     }\r
+    FreePool(CleanFilePathStr);\r
     return (Status);\r
   }\r
 \r
+  FreePool(CleanFilePathStr);\r
   return (EFI_UNSUPPORTED);\r
 }\r
 /**\r
@@ -1564,6 +1697,7 @@ ShellCloseFileMetaArg (
       FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Info);\r
       FreePool((EFI_SHELL_FILE_INFO_NO_CONST*)Node);\r
     }\r
+    SHELL_FREE_NON_NULL(*ListHead);\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -1616,14 +1750,15 @@ ShellFindFilePath (
 \r
   Path = ShellGetEnvironmentVariable(L"cwd");\r
   if (Path != NULL) {\r
-    Size = StrSize(Path);\r
+    Size = StrSize(Path) + sizeof(CHAR16);\r
     Size += StrSize(FileName);\r
     TestPath = AllocateZeroPool(Size);\r
     if (TestPath == NULL) {\r
       return (NULL);\r
     }\r
-    StrCpy(TestPath, Path);\r
-    StrCat(TestPath, FileName);\r
+    StrCpyS(TestPath, Size/sizeof(CHAR16), Path);\r
+    StrCatS(TestPath, Size/sizeof(CHAR16), L"\\");\r
+    StrCatS(TestPath, Size/sizeof(CHAR16), FileName);\r
     Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
     if (!EFI_ERROR(Status)){\r
       if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
@@ -1655,12 +1790,12 @@ ShellFindFilePath (
           *TempChar = CHAR_NULL;\r
         }\r
         if (TestPath[StrLen(TestPath)-1] != L'\\') {\r
-          StrCat(TestPath, L"\\");\r
+          StrCatS(TestPath, Size/sizeof(CHAR16), L"\\");\r
         }\r
         if (FileName[0] == L'\\') {\r
           FileName++;\r
         }\r
-        StrCat(TestPath, FileName);\r
+        StrCatS(TestPath, Size/sizeof(CHAR16), FileName);\r
         if (StrStr(Walker, L";") != NULL) {\r
           Walker = StrStr(Walker, L";") + 1;\r
         } else {\r
@@ -1729,9 +1864,9 @@ ShellFindFilePathEx (
     return (NULL);\r
   }\r
   for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension;  TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){\r
-    StrCpy(TestPath, FileName);\r
+    StrCpyS(TestPath, Size/sizeof(CHAR16), FileName);\r
     if (ExtensionWalker != NULL) {\r
-      StrCat(TestPath, ExtensionWalker);\r
+      StrCatS(TestPath, Size/sizeof(CHAR16), ExtensionWalker);\r
     }\r
     TempChar = StrStr(TestPath, L";");\r
     if (TempChar != NULL) {\r
@@ -1772,7 +1907,6 @@ typedef struct {
   @retval FALSE                 the Parameter was not found.  Type is not valid.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 InternalIsOnCheckList (\r
   IN CONST CHAR16               *Name,\r
   IN CONST SHELL_PARAM_ITEM     *CheckList,\r
@@ -1807,7 +1941,7 @@ InternalIsOnCheckList (
     // If the Type is TypeStart only check the first characters of the passed in param\r
     // If it matches set the type and return TRUE\r
     //\r
-    if (TempListItem->Type == TypeStart) { \r
+    if (TempListItem->Type == TypeStart) {\r
       if (StrnCmp(Name, TempListItem->Name, StrLen(TempListItem->Name)) == 0) {\r
         *Type = TempListItem->Type;\r
         return (TRUE);\r
@@ -1835,15 +1969,16 @@ InternalIsOnCheckList (
 \r
   @param[in] Name               pointer to Name of parameter found\r
   @param[in] AlwaysAllowNumbers TRUE to allow numbers, FALSE to not.\r
+  @param[in] TimeNumbers        TRUE to allow numbers with ":", FALSE otherwise.\r
 \r
   @retval TRUE                  the Parameter is a flag.\r
   @retval FALSE                 the Parameter not a flag.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 InternalIsFlag (\r
   IN CONST CHAR16               *Name,\r
-  IN BOOLEAN                    AlwaysAllowNumbers\r
+  IN CONST BOOLEAN              AlwaysAllowNumbers,\r
+  IN CONST BOOLEAN              TimeNumbers\r
   )\r
 {\r
   //\r
@@ -1854,7 +1989,7 @@ InternalIsFlag (
   //\r
   // If we accept numbers then dont return TRUE. (they will be values)\r
   //\r
-  if (((Name[0] == L'-' || Name[0] == L'+') && ShellIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers) {\r
+  if (((Name[0] == L'-' || Name[0] == L'+') && InternalShellIsHexOrDecimalNumber(Name+1, FALSE, FALSE, TimeNumbers)) && AlwaysAllowNumbers) {\r
     return (FALSE);\r
   }\r
 \r
@@ -1896,7 +2031,6 @@ InternalIsFlag (
                                 ProblemParam if provided.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalCommandLineParse (\r
   IN CONST SHELL_PARAM_ITEM     *CheckList,\r
   OUT LIST_ENTRY                **CheckPackage,\r
@@ -1914,6 +2048,8 @@ InternalCommandLineParse (
   UINTN                         ValueSize;\r
   UINTN                         Count;\r
   CONST CHAR16                  *TempPointer;\r
+  UINTN                         CurrentValueSize;\r
+  CHAR16                        *NewValue;\r
 \r
   CurrentItemPackage = NULL;\r
   GetItemValue = 0;\r
@@ -1969,13 +2105,12 @@ InternalCommandLineParse (
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      CurrentItemPackage->Name  = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
+      CurrentItemPackage->Name  = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]);\r
       if (CurrentItemPackage->Name == NULL) {\r
         ShellCommandLineFreeVarList(*CheckPackage);\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      StrCpy(CurrentItemPackage->Name,  Argv[LoopCounter]);\r
       CurrentItemPackage->Type  = CurrentItemType;\r
       CurrentItemPackage->OriginalPosition = (UINTN)(-1);\r
       CurrentItemPackage->Value = NULL;\r
@@ -1988,6 +2123,7 @@ InternalCommandLineParse (
         // possibly trigger the next loop(s) to populate the value of this item\r
         //\r
         case TypeValue:\r
+        case TypeTimeValue:\r
           GetItemValue = 1;\r
           ValueSize = 0;\r
           break;\r
@@ -2007,31 +2143,48 @@ InternalCommandLineParse (
           ASSERT(GetItemValue == 0);\r
           break;\r
       }\r
-    } else if (GetItemValue != 0 && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers)) {\r
-      ASSERT(CurrentItemPackage != NULL);\r
+    } else if (GetItemValue != 0 && CurrentItemPackage != NULL && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, (BOOLEAN)(CurrentItemPackage->Type == TypeTimeValue))) {\r
       //\r
       // get the item VALUE for a previous flag\r
       //\r
-      CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16), CurrentItemPackage->Value);\r
-      ASSERT(CurrentItemPackage->Value != NULL);\r
+      CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
+      NewValue = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);\r
+      if (NewValue == NULL) {\r
+        SHELL_FREE_NON_NULL (CurrentItemPackage->Value);\r
+        SHELL_FREE_NON_NULL (CurrentItemPackage);\r
+        ShellCommandLineFreeVarList (*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      CurrentItemPackage->Value = NewValue;\r
       if (ValueSize == 0) {\r
-        StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
+        StrCpyS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  Argv[LoopCounter]\r
+                  );\r
       } else {\r
-        StrCat(CurrentItemPackage->Value, L" ");\r
-        StrCat(CurrentItemPackage->Value, Argv[LoopCounter]);\r
+        StrCatS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  L" "\r
+                  );\r
+        StrCatS( CurrentItemPackage->Value, \r
+                  CurrentValueSize/sizeof(CHAR16), \r
+                  Argv[LoopCounter]\r
+                  );\r
       }\r
       ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
+      \r
       GetItemValue--;\r
       if (GetItemValue == 0) {\r
         InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
       }\r
-    } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) ){ //|| ProblemParam == NULL) {\r
+    } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, FALSE)){\r
       //\r
       // add this one as a non-flag\r
       //\r
 \r
       TempPointer = Argv[LoopCounter];\r
-      if ((*TempPointer == L'^' && *(TempPointer+1) == L'-') \r
+      if ((*TempPointer == L'^' && *(TempPointer+1) == L'-')\r
        || (*TempPointer == L'^' && *(TempPointer+1) == L'/')\r
        || (*TempPointer == L'^' && *(TempPointer+1) == L'+')\r
       ){\r
@@ -2045,13 +2198,12 @@ InternalCommandLineParse (
       }\r
       CurrentItemPackage->Name  = NULL;\r
       CurrentItemPackage->Type  = TypePosition;\r
-      CurrentItemPackage->Value = AllocateZeroPool(StrSize(TempPointer));\r
+      CurrentItemPackage->Value = AllocateCopyPool(StrSize(TempPointer), TempPointer);\r
       if (CurrentItemPackage->Value == NULL) {\r
         ShellCommandLineFreeVarList(*CheckPackage);\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      StrCpy(CurrentItemPackage->Value, TempPointer);\r
       CurrentItemPackage->OriginalPosition = Count++;\r
       InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
     } else {\r
@@ -2059,10 +2211,7 @@ InternalCommandLineParse (
       // this was a non-recognised flag... error!\r
       //\r
       if (ProblemParam != NULL) {\r
-        *ProblemParam = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
-        if (*ProblemParam != NULL) {\r
-          StrCpy(*ProblemParam, Argv[LoopCounter]);      \r
-        }\r
+        *ProblemParam = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]);\r
       }\r
       ShellCommandLineFreeVarList(*CheckPackage);\r
       *CheckPackage = NULL;\r
@@ -2421,7 +2570,7 @@ ShellCommandLineGetCount(
 }\r
 \r
 /**\r
-  Determins if a parameter is duplicated.\r
+  Determines if a parameter is duplicated.\r
 \r
   If Param is not NULL then it will point to a callee allocated string buffer\r
   with the parameter value if a duplicate is found.\r
@@ -2529,7 +2678,7 @@ ShellCopySearchAndReplace(
   if (Replace == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  NewString = SetMem16(NewString, NewSize, CHAR_NULL);\r
+  NewString = ZeroMem(NewString, NewSize);\r
   while (*SourceString != CHAR_NULL) {\r
     //\r
     // if we find the FindTarget and either Skip == FALSE or Skip  and we\r
@@ -2544,14 +2693,14 @@ ShellCopySearchAndReplace(
         FreePool(Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrCat(NewString, Replace);\r
+      StrCatS(NewString, NewSize/sizeof(CHAR16), Replace);\r
     } else {\r
       Size = StrSize(NewString);\r
       if (Size + sizeof(CHAR16) > NewSize) {\r
         FreePool(Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrnCat(NewString, SourceString, 1);\r
+      StrnCatS(NewString, NewSize/sizeof(CHAR16), SourceString, 1);\r
       SourceString++;\r
     }\r
   }\r
@@ -2570,7 +2719,6 @@ ShellCopySearchAndReplace(
   @retval !EFI_SUCCESS    The operation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalPrintTo (\r
   IN CONST CHAR16 *String\r
   )\r
@@ -2584,10 +2732,12 @@ InternalPrintTo (
     return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
   }\r
   if (mEfiShellInterface          != NULL) {\r
+    if (mEfiShellInterface->RedirArgc == 0) { \r
     //\r
     // Divide in half for old shell.  Must be string length not size.\r
-    //\r
-    Size /= 2;\r
+      // \r
+      Size /=2;  // Divide in half only when no redirection.\r
+    }\r
     return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut,          &Size, (VOID*)String));\r
   }\r
   ASSERT(FALSE);\r
@@ -2624,7 +2774,6 @@ InternalPrintTo (
   @return EFI_DEVICE_ERROR      The console device reported an error.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalShellPrintWorker(\r
   IN INT32                Col OPTIONAL,\r
   IN INT32                Row OPTIONAL,\r
@@ -2697,7 +2846,12 @@ InternalShellPrintWorker(
     // update the attribute\r
     //\r
     if (ResumeLocation != NULL) {\r
-      if (*(ResumeLocation-1) == L'^') {\r
+      if ((ResumeLocation != mPostReplaceFormat2) && (*(ResumeLocation-1) == L'^')) {\r
+        //\r
+        // Move cursor back 1 position to overwrite the ^\r
+        //\r
+        gST->ConOut->SetCursorPosition(gST->ConOut, gST->ConOut->Mode->CursorColumn - 1, gST->ConOut->Mode->CursorRow);\r
+\r
         //\r
         // Print a simple '%' symbol\r
         //\r
@@ -2715,10 +2869,10 @@ InternalShellPrintWorker(
             gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_WHITE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
             break;\r
           case (L'B'):\r
-            gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_BLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
+            gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_LIGHTBLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
             break;\r
           case (L'V'):\r
-            gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
+            gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_LIGHTGREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
             break;\r
           default:\r
             //\r
@@ -2848,13 +3002,14 @@ ShellPrintHiiEx(
   CHAR16            *HiiFormatString;\r
   EFI_STATUS        RetVal;\r
 \r
+  RetVal = EFI_DEVICE_ERROR;\r
+\r
   VA_START (Marker, HiiFormatHandle);\r
   HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, Language);\r
-  ASSERT(HiiFormatString != NULL);\r
-\r
-  RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker);\r
-\r
-  SHELL_FREE_NON_NULL(HiiFormatString);\r
+  if (HiiFormatString != NULL) {\r
+    RetVal = InternalShellPrintWorker (Col, Row, HiiFormatString, Marker);\r
+    SHELL_FREE_NON_NULL (HiiFormatString);\r
+  }\r
   VA_END(Marker);\r
 \r
   return (RetVal);\r
@@ -2996,9 +3151,35 @@ ShellIsFileInPath(
   return (Status);\r
 }\r
 \r
+/**\r
+  Function return the number converted from a hex representation of a number.\r
+\r
+  Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid\r
+  result.  Use ShellConvertStringToUint64 instead.\r
+\r
+  @param[in] String   String representation of a number.\r
+\r
+  @return             The unsigned integer result of the conversion.\r
+  @retval (UINTN)(-1) An error occured.\r
+**/\r
+UINTN\r
+EFIAPI\r
+ShellHexStrToUintn(\r
+  IN CONST CHAR16 *String\r
+  )\r
+{\r
+  UINT64        RetVal;\r
+\r
+  if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) {\r
+    return ((UINTN)RetVal);\r
+  }\r
+  \r
+  return ((UINTN)(-1));\r
+}\r
+\r
 /**\r
   Function to determine whether a string is decimal or hex representation of a number\r
-  and return the number converted from the string.\r
+  and return the number converted from the string.  Spaces are always skipped.\r
 \r
   @param[in] String   String representation of a number\r
 \r
@@ -3016,7 +3197,7 @@ ShellStrToUintn(
 \r
   Hex = FALSE;\r
 \r
-  if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE)) {\r
+  if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE, FALSE)) {\r
     Hex = TRUE;\r
   }\r
 \r
@@ -3113,13 +3294,16 @@ StrnCatGrow (
   //\r
   if (CurrentSize != NULL) {\r
     NewSize = *CurrentSize;\r
-    while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
-      NewSize += 2 * Count * sizeof(CHAR16);\r
+    if (NewSize < DestinationStartSize + (Count * sizeof(CHAR16))) {\r
+      while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
+        NewSize += 2 * Count * sizeof(CHAR16);\r
+      }\r
+      *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
+      *CurrentSize = NewSize;\r
     }\r
-    *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
-    *CurrentSize = NewSize;\r
   } else {\r
-    *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));\r
+    NewSize = (Count+1)*sizeof(CHAR16);\r
+    *Destination = AllocateZeroPool(NewSize);\r
   }\r
 \r
   //\r
@@ -3128,14 +3312,16 @@ StrnCatGrow (
   if (*Destination == NULL) {\r
     return (NULL);\r
   }\r
-  return StrnCat(*Destination, Source, Count);\r
+  \r
+  StrnCatS(*Destination, NewSize/sizeof(CHAR16), Source, Count);\r
+  return *Destination;\r
 }\r
 \r
 /**\r
   Prompt the user and return the resultant answer to the requestor.\r
 \r
   This function will display the requested question on the shell prompt and then\r
-  wait for an apropriate answer to be input from the console.\r
+  wait for an appropriate answer to be input from the console.\r
 \r
   if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue\r
   or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.\r
@@ -3191,7 +3377,9 @@ ShellPromptForResponse (
       //\r
       gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
       Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-      ASSERT_EFI_ERROR(Status);\r
+      if (EFI_ERROR(Status)) {\r
+        break;\r
+      }\r
       ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
       if (Key.UnicodeChar == L'Q' || Key.UnicodeChar ==L'q') {\r
         *Resp = ShellPromptResponseQuit;\r
@@ -3208,9 +3396,15 @@ ShellPromptForResponse (
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
+        if (EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
         ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
@@ -3227,7 +3421,8 @@ ShellPromptForResponse (
             break;\r
         }\r
       }\r
-      break;    case ShellPromptResponseTypeYesNoAllCancel:\r
+      break;\r
+      case ShellPromptResponseTypeYesNoAllCancel:\r
        if (Prompt != NULL) {\r
         ShellPrintEx(-1, -1, L"%s", Prompt);\r
       }\r
@@ -3236,10 +3431,20 @@ ShellPromptForResponse (
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
-        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+        if (EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
+\r
+        if (Key.UnicodeChar <= 127 && Key.UnicodeChar >= 32) {\r
+          ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);\r
+        }\r
+\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
           case L'y':\r
@@ -3270,10 +3475,16 @@ ShellPromptForResponse (
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         if (Type == ShellPromptResponseTypeEnterContinue) {\r
           Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-          ASSERT_EFI_ERROR(Status);\r
+          if (EFI_ERROR(Status)) {\r
+            break;\r
+          }\r
           ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
           if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
             *Resp = ShellPromptResponseContinue;\r
@@ -3297,9 +3508,15 @@ ShellPromptForResponse (
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
+        if (EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
         ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
@@ -3318,9 +3535,15 @@ ShellPromptForResponse (
         ShellPrintEx(-1, -1, L"%s", Prompt);\r
       }\r
       while(1) {\r
+        if (ShellGetExecutionBreakFlag()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
+        if (EFI_ERROR(Status)) {\r
+          break;\r
+        }\r
         ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
         if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
           break;\r
@@ -3331,6 +3554,7 @@ ShellPromptForResponse (
       break;\r
     //\r
     // This is the location to add new prompt types.\r
+    // If your new type loops remember to add ExecutionBreak support.\r
     //\r
     default:\r
       ASSERT(FALSE);\r
@@ -3398,16 +3622,17 @@ ShellPromptForResponseHii (
   @param[in] String       The string to evaluate.\r
   @param[in] ForceHex     TRUE - always assume hex.\r
   @param[in] StopAtSpace  TRUE to halt upon finding a space, FALSE to keep going.\r
+  @param[in] TimeNumbers        TRUE to allow numbers with ":", FALSE otherwise.\r
 \r
   @retval TRUE        It is all numeric (dec/hex) characters.\r
   @retval FALSE       There is a non-numeric character.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 InternalShellIsHexOrDecimalNumber (\r
   IN CONST CHAR16   *String,\r
   IN CONST BOOLEAN  ForceHex,\r
-  IN CONST BOOLEAN  StopAtSpace\r
+  IN CONST BOOLEAN  StopAtSpace,\r
+  IN CONST BOOLEAN  TimeNumbers\r
   )\r
 {\r
   BOOLEAN Hex;\r
@@ -3418,7 +3643,7 @@ InternalShellIsHexOrDecimalNumber (
   if (String != NULL && *String == L'-') {\r
     String++;\r
   }\r
-  \r
+\r
   if (String == NULL) {\r
     return (FALSE);\r
   }\r
@@ -3451,6 +3676,9 @@ InternalShellIsHexOrDecimalNumber (
   // loop through the remaining characters and use the lib function\r
   //\r
   for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r
+    if (TimeNumbers && (String[0] == L':')) {\r
+      continue;\r
+    }\r
     if (Hex) {\r
       if (!ShellIsHexaDecimalDigitCharacter(*String)) {\r
         return (FALSE);\r
@@ -3497,7 +3725,7 @@ ShellFileExists(
 }\r
 \r
 /**\r
-  Convert a Unicode character to upper case only if \r
+  Convert a Unicode character to upper case only if\r
   it maps to a valid small-case ASCII character.\r
 \r
   This internal function only deal with Unicode character\r
@@ -3512,7 +3740,6 @@ ShellFileExists(
 \r
 **/\r
 CHAR16\r
-EFIAPI\r
 InternalShellCharToUpper (\r
   IN      CHAR16                    Char\r
   )\r
@@ -3529,7 +3756,7 @@ InternalShellCharToUpper (
 \r
   This internal function only deal with Unicode character\r
   which maps to a valid hexadecimal ASII character, i.e.\r
-  L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other \r
+  L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r
   Unicode character, the value returned does not make sense.\r
 \r
   @param  Char  The character to convert.\r
@@ -3538,7 +3765,6 @@ InternalShellCharToUpper (
 \r
 **/\r
 UINTN\r
-EFIAPI\r
 InternalShellHexCharToUintn (\r
   IN      CHAR16                    Char\r
   )\r
@@ -3547,13 +3773,13 @@ InternalShellHexCharToUintn (
     return Char - L'0';\r
   }\r
 \r
-  return (UINTN) (10 + InternalShellCharToUpper (Char) - L'A');\r
+  return (10 + InternalShellCharToUpper (Char) - L'A');\r
 }\r
 \r
 /**\r
   Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.\r
 \r
-  This function returns a value of type UINTN by interpreting the contents\r
+  This function returns a value of type UINT64 by interpreting the contents\r
   of the Unicode string specified by String as a hexadecimal number.\r
   The format of the input Unicode string String is:\r
 \r
@@ -3581,7 +3807,6 @@ InternalShellHexCharToUintn (
   @retval EFI_DEVICE_ERROR        An overflow occured.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalShellStrHexToUint64 (\r
   IN CONST CHAR16   *String,\r
      OUT   UINT64   *Value,\r
@@ -3593,9 +3818,9 @@ InternalShellStrHexToUint64 (
   if (String == NULL || StrSize(String) == 0 || Value == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
-  \r
+\r
   //\r
-  // Ignore the pad spaces (space or tab) \r
+  // Ignore the pad spaces (space or tab)\r
   //\r
   while ((*String == L' ') || (*String == L'\t')) {\r
     String++;\r
@@ -3619,18 +3844,18 @@ InternalShellStrHexToUint64 (
   }\r
 \r
   Result = 0;\r
-  \r
+\r
   //\r
-  // Skip spaces if requested\r
+  // there is a space where there should't be\r
   //\r
-  while (StopAtSpace && *String == L' ') {\r
-    String++;\r
+  if (*String == L' ') {\r
+    return (EFI_INVALID_PARAMETER);\r
   }\r
-  \r
+\r
   while (ShellIsHexaDecimalDigitCharacter (*String)) {\r
     //\r
-    // If the Hex Number represented by String overflows according \r
-    // to the range defined by UINTN, then ASSERT().\r
+    // If the Hex Number represented by String overflows according\r
+    // to the range defined by UINT64, then return EFI_DEVICE_ERROR.\r
     //\r
     if (!(Result <= (RShiftU64((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) {\r
 //    if (!(Result <= ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)) >> 4))) {\r
@@ -3642,10 +3867,10 @@ InternalShellStrHexToUint64 (
     String++;\r
 \r
     //\r
-    // Skip spaces if requested\r
+    // stop at spaces if requested\r
     //\r
-    while (StopAtSpace && *String == L' ') {\r
-      String++;\r
+    if (StopAtSpace && *String == L' ') {\r
+      break;\r
     }\r
   }\r
 \r
@@ -3683,7 +3908,6 @@ InternalShellStrHexToUint64 (
   @retval EFI_DEVICE_ERROR        An overflow occured.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalShellStrDecimalToUint64 (\r
   IN CONST CHAR16 *String,\r
      OUT   UINT64 *Value,\r
@@ -3713,17 +3937,20 @@ InternalShellStrDecimalToUint64 (
   Result = 0;\r
 \r
   //\r
-  // Skip spaces if requested\r
+  // Stop upon space if requested \r
+  // (if the whole value was 0)\r
   //\r
-  while (StopAtSpace && *String == L' ') {\r
-    String++;\r
+  if (StopAtSpace && *String == L' ') {\r
+    *Value = Result;\r
+    return (EFI_SUCCESS);\r
   }\r
+\r
   while (ShellIsDecimalDigitCharacter (*String)) {\r
     //\r
-    // If the number represented by String overflows according \r
-    // to the range defined by UINT64, then ASSERT().\r
+    // If the number represented by String overflows according\r
+    // to the range defined by UINT64, then return EFI_DEVICE_ERROR.\r
     //\r
-    \r
+\r
     if (!(Result <= (DivU64x32((((UINT64) ~0) - (*String - L'0')),10)))) {\r
       return (EFI_DEVICE_ERROR);\r
     }\r
@@ -3740,7 +3967,7 @@ InternalShellStrDecimalToUint64 (
   }\r
 \r
   *Value = Result;\r
-  \r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -3753,7 +3980,7 @@ InternalShellStrDecimalToUint64 (
   @param[out] Value       Upon a successful return the value of the conversion.\r
   @param[in] ForceHex     TRUE - always assume hex.\r
   @param[in] StopAtSpace  FALSE to skip spaces.\r
-  \r
+\r
   @retval EFI_SUCCESS             The conversion was successful.\r
   @retval EFI_INVALID_PARAMETER   String contained an invalid character.\r
   @retval EFI_NOT_FOUND           String was a number, but Value was NULL.\r
@@ -3774,10 +4001,10 @@ ShellConvertStringToUint64(
 \r
   Hex = ForceHex;\r
 \r
-  if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) {\r
+  if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) {\r
     if (!Hex) {\r
       Hex = TRUE;\r
-      if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) {\r
+      if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) {\r
         return (EFI_INVALID_PARAMETER);\r
       }\r
     } else {\r
@@ -3793,9 +4020,9 @@ ShellConvertStringToUint64(
   //\r
   // make sure we have something left that is numeric.\r
   //\r
-  if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace)) {\r
+  if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace, FALSE)) {\r
     return (EFI_INVALID_PARAMETER);\r
-  } \r
+  }\r
 \r
   //\r
   // do the conversion.\r
@@ -3880,7 +4107,10 @@ ShellFileHandleReturnLine(
       return (NULL);\r
     }\r
     Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
-    \r
+\r
+  }\r
+  if (Status == EFI_END_OF_FILE && RetVal != NULL && *RetVal != CHAR_NULL) {\r
+    Status = EFI_SUCCESS;\r
   }\r
   if (EFI_ERROR(Status) && (RetVal != NULL)) {\r
     FreePool(RetVal);\r
@@ -3895,9 +4125,20 @@ ShellFileHandleReturnLine(
   If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
   maintained and not changed for all operations with the same file.\r
 \r
+  NOTE: LINES THAT ARE RETURNED BY THIS FUNCTION ARE UCS2, EVEN IF THE FILE BEING READ\r
+        IS IN ASCII FORMAT.\r
+\r
   @param[in]       Handle        SHELL_FILE_HANDLE to read from.\r
-  @param[in, out]  Buffer        The pointer to buffer to read into.\r
-  @param[in, out]  Size          The pointer to number of bytes in Buffer.\r
+  @param[in, out]  Buffer        The pointer to buffer to read into. If this function\r
+                                 returns EFI_SUCCESS, then on output Buffer will\r
+                                 contain a UCS2 string, even if the file being\r
+                                 read is ASCII.\r
+  @param[in, out]  Size          On input, pointer to number of bytes in Buffer.\r
+                                 On output, unchanged unless Buffer is too small\r
+                                 to contain the next line of the file. In that\r
+                                 case Size is set to the number of bytes needed\r
+                                 to hold the next line of the file (as a UCS2\r
+                                 string, even if it is an ASCII file).\r
   @param[in]       Truncate      If the buffer is large enough, this has no effect.\r
                                  If the buffer is is too small and Truncate is TRUE,\r
                                  the line will be truncated.\r
@@ -3909,6 +4150,7 @@ ShellFileHandleReturnLine(
 \r
   @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
                                 Buffer.\r
+  @retval EFI_END_OF_FILE       There are no more lines in the file.\r
   @retval EFI_INVALID_PARAMETER Handle was NULL.\r
   @retval EFI_INVALID_PARAMETER Size was NULL.\r
   @retval EFI_BUFFER_TOO_SMALL  Size was not large enough to store the line.\r
@@ -3954,19 +4196,22 @@ ShellFileHandleReadLine(
     }\r
   }\r
 \r
+  if (*Ascii) {\r
+    CharSize = sizeof(CHAR8);\r
+  } else {\r
+    CharSize = sizeof(CHAR16);\r
+  }\r
   for (CountSoFar = 0;;CountSoFar++){\r
     CharBuffer = 0;\r
-    if (*Ascii) {\r
-      CharSize = sizeof(CHAR8);\r
-    } else {\r
-      CharSize = sizeof(CHAR16);\r
-    }\r
     Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);\r
     if (  EFI_ERROR(Status)\r
        || CharSize == 0\r
        || (CharBuffer == L'\n' && !(*Ascii))\r
        || (CharBuffer ==  '\n' && *Ascii)\r
      ){\r
+      if (CharSize == 0) {\r
+        Status = EFI_END_OF_FILE;\r
+      }\r
       break;\r
     }\r
     //\r
@@ -3997,3 +4242,145 @@ ShellFileHandleReadLine(
 \r
   return (Status);\r
 }\r
+\r
+/**\r
+  Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function.\r
+\r
+  @param[in] CommandToGetHelpOn  Pointer to a string containing the command name of help file to be printed.\r
+  @param[in] SectionToGetHelpOn  Pointer to the section specifier(s).\r
+  @param[in] PrintCommandText    If TRUE, prints the command followed by the help content, otherwise prints \r
+                                 the help content only.\r
+  @retval EFI_DEVICE_ERROR       The help data format was incorrect.\r
+  @retval EFI_NOT_FOUND          The help data could not be found.\r
+  @retval EFI_SUCCESS            The operation was successful.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellPrintHelp (\r
+  IN CONST CHAR16     *CommandToGetHelpOn,\r
+  IN CONST CHAR16     *SectionToGetHelpOn,\r
+  IN BOOLEAN          PrintCommandText\r
+  )\r
+{\r
+       EFI_STATUS          Status;\r
+       CHAR16              *OutText;\r
+         \r
+       OutText = NULL;\r
+       \r
+  //\r
+  // Get the string to print based\r
+  //\r
+       Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r
+  \r
+  //\r
+  // make sure we got a valid string\r
+  //\r
+  if (EFI_ERROR(Status)){\r
+    return Status;\r
+       } \r
+  if (OutText == NULL || StrLen(OutText) == 0) {\r
+    return EFI_NOT_FOUND;  \r
+       }\r
+  \r
+  //\r
+  // Chop off trailing stuff we dont need\r
+  //\r
+  while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {\r
+    OutText[StrLen(OutText)-1] = CHAR_NULL;\r
+  }\r
+  \r
+  //\r
+  // Print this out to the console\r
+  //\r
+  if (PrintCommandText) {\r
+    ShellPrintEx(-1, -1, L"%H%-14s%N- %s\r\n", CommandToGetHelpOn, OutText);\r
+  } else {\r
+    ShellPrintEx(-1, -1, L"%N%s\r\n", OutText);\r
+  }\r
+  \r
+  SHELL_FREE_NON_NULL(OutText);\r
+\r
+       return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Function to delete a file by name\r
+  \r
+  @param[in]       FileName       Pointer to file name to delete.\r
+  \r
+  @retval EFI_SUCCESS             the file was deleted sucessfully\r
+  @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
+                                  deleted\r
+  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
+  @retval EFI_NOT_FOUND           The specified file could not be found on the\r
+                                  device or the file system could not be found\r
+                                  on the device.\r
+  @retval EFI_NO_MEDIA            The device has no medium.\r
+  @retval EFI_MEDIA_CHANGED       The device has a different medium in it or the\r
+                                  medium is no longer supported.\r
+  @retval EFI_DEVICE_ERROR        The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED     The file or medium is write protected.\r
+  @retval EFI_ACCESS_DENIED       The file was opened read only.\r
+  @retval EFI_OUT_OF_RESOURCES    Not enough resources were available to open the\r
+                                  file.\r
+  @retval other                   The file failed to open\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellDeleteFileByName(\r
+  IN CONST CHAR16               *FileName\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  SHELL_FILE_HANDLE         FileHandle;\r
+  \r
+  Status = ShellFileExists(FileName);\r
+  \r
+  if (Status == EFI_SUCCESS){\r
+    Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);\r
+    if (Status == EFI_SUCCESS){\r
+      Status = ShellDeleteFile(&FileHandle);\r
+    }\r
+  } \r
+\r
+  return(Status);\r
+  \r
+}\r
+\r
+/**\r
+  Cleans off all the quotes in the string.\r
+\r
+  @param[in]     OriginalString   pointer to the string to be cleaned.\r
+  @param[out]   CleanString      The new string with all quotes removed. \r
+                                                  Memory allocated in the function and free \r
+                                                  by caller.\r
+\r
+  @retval EFI_SUCCESS   The operation was successful.\r
+**/\r
+EFI_STATUS\r
+InternalShellStripQuotes (\r
+  IN  CONST CHAR16     *OriginalString,\r
+  OUT CHAR16           **CleanString\r
+  )\r
+{\r
+  CHAR16            *Walker;\r
+  \r
+  if (OriginalString == NULL || CleanString == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);\r
+  if (*CleanString == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r
+    if (*Walker == L'\"') {\r
+      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r