VirtualBox

Ignore:
Timestamp:
Oct 28, 2015 8:17:18 PM (9 years ago)
Author:
vboxsync
Message:

EFI/Firmware: 'svn merge /vendor/edk2/UDK2010.SR1 /vendor/edk2/current .', reverting and removing files+dirs listed in ReadMe.vbox, resolving conflicts with help from ../UDK2014.SP1/. This is a raw untested merge.

Location:
trunk/src/VBox/Devices/EFI/Firmware
Files:
6 deleted
135 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/Firmware

  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ConsoleLogger.c

    r48674 r58459  
    22  Provides interface to shell console logger.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    1213**/
    1314
    14 #include "ConsoleLogger.h"
    1515#include "Shell.h"
    16 
    17 STATIC CONST CHAR16                     mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };
    1816
    1917/**
     
    474472            ; Index++
    475473           ){
    476           *(ConsoleInfo->Attributes + (CopySize/sizeof(ConsoleInfo->Attributes)) + Index) = ConsoleInfo->HistoryMode.Attribute;
     474          *(ConsoleInfo->Attributes + (CopySize/sizeof(ConsoleInfo->Attributes[0])) + Index) = ConsoleInfo->HistoryMode.Attribute;
    477475        }
    478476
     
    644642    FreePool(Resp);
    645643    ShellInfoObject.ConsoleInfo->Enabled = FALSE;
     644    //
     645    // When user wants to quit, the shell should stop running the command.
     646    //
     647    gBS->SignalEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);
    646648    return (EFI_DEVICE_ERROR);
    647649  } else {
     
    818820  )
    819821{
    820   EFI_INPUT_KEY               Key;
    821   UINTN                       EventIndex;
    822   CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo;
     822  EFI_STATUS                        Status;
     823  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TxtInEx;
     824  EFI_KEY_DATA                      KeyData;
     825  UINTN                             EventIndex;
     826  CONSOLE_LOGGER_PRIVATE_DATA       *ConsoleInfo;
     827
    823828  ConsoleInfo = CONSOLE_LOGGER_PRIVATE_DATA_FROM_THIS(This);
    824829  if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut) {
     
    826831  }
    827832  ASSERT(ShellInfoObject.ConsoleInfo == ConsoleInfo);
    828   if (ShellInfoObject.HaltOutput) {
    829     //
    830     // just get some key
    831     //
    832     gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
    833     gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
    834     ShellInfoObject.HaltOutput = FALSE;
    835   }
     833
     834  Status = gBS->HandleProtocol (gST->ConsoleInHandle, &gEfiSimpleTextInputExProtocolGuid, (VOID **) &TxtInEx);
     835  if (!EFI_ERROR (Status)) {
     836    while (ShellInfoObject.HaltOutput) {
     837
     838      ShellInfoObject.HaltOutput = FALSE;
     839      //
     840      // just get some key
     841      //
     842      Status = gBS->WaitForEvent (1, &TxtInEx->WaitForKeyEx, &EventIndex);
     843      ASSERT_EFI_ERROR (Status);
     844      Status = TxtInEx->ReadKeyStrokeEx (TxtInEx, &KeyData);
     845      if (EFI_ERROR(Status)) {
     846        break;
     847      }
     848
     849      if ((KeyData.Key.UnicodeChar == L's') && (KeyData.Key.ScanCode == SCAN_NULL) &&
     850          ((KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_LEFT_CONTROL_PRESSED)) ||
     851           (KeyData.KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID | EFI_RIGHT_CONTROL_PRESSED))
     852          )
     853         ) {
     854        ShellInfoObject.HaltOutput = TRUE;
     855      }
     856    }
     857  }
     858
    836859  if (!ShellInfoObject.ConsoleInfo->Enabled) {
    837860    return (EFI_DEVICE_ERROR);
     
    10291052  //
    10301053  if (!EFI_ERROR (Status)) {
    1031     Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 1) * ConsoleInfo->CurrentStartRow];
     1054    Screen = &ConsoleInfo->Buffer[(ConsoleInfo->ColsPerScreen + 2) * ConsoleInfo->CurrentStartRow];
    10321055    Attributes = &ConsoleInfo->Attributes[ConsoleInfo->ColsPerScreen * ConsoleInfo->CurrentStartRow];
    10331056    for ( Row = ConsoleInfo->OriginalStartRow
     
    10471070      // Skip the NULL on each column end in text buffer only
    10481071      //
    1049       Screen++;
     1072      Screen += 2;
    10501073    }
    10511074    ConsoleInfo->HistoryMode.CursorColumn = 0;
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ConsoleLogger.h

    r48674 r58459  
    1515#define _CONSOLE_LOGGER_HEADER_
    1616
    17 #include <Uefi.h>
    18 
    19 #include <Protocol/SimpleTextOut.h>
    20 #include <Protocol/EfiShell.h>
    21 #include <Protocol/EfiShellParameters.h>
    22 
    23 #include <Library/DebugLib.h>
    24 #include <Library/BaseLib.h>
    25 #include <Library/BaseMemoryLib.h>
    26 #include <Library/MemoryAllocationLib.h>
    27 #include <Library/UefiBootServicesTableLib.h>
    28 #include <Library/HiiLib.h>
    29 #include <Library/ShellLib.h>
     17#include "Shell.h"
    3018
    3119#define CONSOLE_LOGGER_PRIVATE_DATA_SIGNATURE  SIGNATURE_32 ('c', 'o', 'P', 'D')
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ConsoleWrappers.c

    r48674 r58459  
    22  Function definitions for shell simple text in and out on top of file handles.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    1314**/
    1415
    15 #include <Uefi.h>
    16 #include <ShellBase.h>
    17 
    18 #include "ConsoleWrappers.h"
    1916#include "Shell.h"
    2017
     
    2320  SHELL_FILE_HANDLE               FileHandle;
    2421  EFI_HANDLE                      TheHandle;
     22  UINT64                          RemainingBytesOfInputFile;
    2523} SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
    2624
     
    2927  SHELL_FILE_HANDLE               FileHandle;
    3028  EFI_HANDLE                      TheHandle;
     29  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalSimpleTextOut;
    3130} SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
    3231
     
    4645  )
    4746{
    48   UINT64 Position;
    49   UINT64 Size;
    50   //
    51   // Someone is waiting on the keystroke event, if there's
    52   // a key pending, signal the event
    53   //
    54   // Context is the pointer to EFI_SIMPLE_TEXT_INPUT_PROTOCOL
    55   //
    56   ShellInfoObject.NewEfiShellProtocol->GetFilePosition(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Context)->FileHandle, &Position);
    57   ShellInfoObject.NewEfiShellProtocol->GetFileSize    (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Context)->FileHandle, &Size    );
    58   if (Position < Size) {
    59     gBS->SignalEvent (Event);
    60   }
     47  gBS->SignalEvent (Event);
    6148}
    6249
     
    9582{
    9683  UINTN Size;
    97   Size = sizeof(CHAR16);
     84
     85  //
     86  // Verify the parameters
     87  //
    9888  if (Key == NULL || This == NULL) {
    9989    return (EFI_INVALID_PARAMETER);
    10090  }
     91
     92  //
     93  // Check if we have any characters left in the stream.
     94  //
     95  if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile == 0) {
     96    return (EFI_NOT_READY);
     97  }
     98
     99  Size = sizeof(CHAR16);
     100
     101  //
     102  // Decrement the amount of free space by Size or set to zero (for odd length files)
     103  //
     104  if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > Size) {
     105    ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= Size;
     106  } else {
     107    ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile = 0;
     108  }
     109
    101110  Key->ScanCode = 0;
    102111  return (ShellInfoObject.NewEfiShellProtocol->ReadFile(
     
    125134  SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *ProtocolToReturn;
    126135  EFI_STATUS                            Status;
     136  UINT64                                CurrentPosition;
     137  UINT64                                FileSize;
    127138
    128139  if (HandleLocation == NULL || FileHandleToUse == NULL) {
     
    134145    return (NULL);
    135146  }
    136   ProtocolToReturn->FileHandle                  = FileHandleToUse;
     147
     148  ShellGetFileSize    (FileHandleToUse, &FileSize);
     149  ShellGetFilePosition(FileHandleToUse, &CurrentPosition);
     150
     151  //
     152  // Initialize the protocol members
     153  //
     154  ProtocolToReturn->RemainingBytesOfInputFile  = FileSize - CurrentPosition;
     155  ProtocolToReturn->FileHandle                 = FileHandleToUse;
    137156  ProtocolToReturn->SimpleTextIn.Reset         = FileBasedSimpleTextInReset;
    138157  ProtocolToReturn->SimpleTextIn.ReadKeyStroke = FileBasedSimpleTextInReadKeyStroke;
     
    258277  )
    259278{
    260   return (EFI_UNSUPPORTED);
     279  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol;
     280 
     281  PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut;
     282 
     283  // Pass the QueryMode call thru to the original SimpleTextOutProtocol
     284  return (PassThruProtocol->QueryMode(
     285    PassThruProtocol,
     286    ModeNumber,
     287    Columns,
     288    Rows));
    261289}
    262290
     
    391419  SHELL_FILE_HANDLE to support redirecting output from a file.
    392420
    393   @param[in]  FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
    394   @param[in]  HandleLocation  The pointer of a location to copy handle with protocol to.
     421  @param[in]  FileHandleToUse  The pointer to the SHELL_FILE_HANDLE to use.
     422  @param[in]  HandleLocation   The pointer of a location to copy handle with protocol to.
     423  @param[in]  OriginalProtocol The pointer to the original output protocol for pass thru of functions.
    395424
    396425  @retval NULL                There was insufficient memory available.
     
    400429EFIAPI
    401430CreateSimpleTextOutOnFile(
    402   IN SHELL_FILE_HANDLE  FileHandleToUse,
    403   IN EFI_HANDLE         *HandleLocation
     431  IN SHELL_FILE_HANDLE               FileHandleToUse,
     432  IN EFI_HANDLE                      *HandleLocation,
     433  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol
    404434  )
    405435{
     
    416446  }
    417447  ProtocolToReturn->FileHandle                      = FileHandleToUse;
     448  ProtocolToReturn->OriginalSimpleTextOut           = OriginalProtocol;
    418449  ProtocolToReturn->SimpleTextOut.Reset             = FileBasedSimpleTextOutReset;
    419450  ProtocolToReturn->SimpleTextOut.TestString        = FileBasedSimpleTextOutTestString;
     
    430461    return (NULL);
    431462  }
    432   ProtocolToReturn->SimpleTextOut.Mode->MaxMode       = 0;
    433   ProtocolToReturn->SimpleTextOut.Mode->Mode          = 0;
    434   ProtocolToReturn->SimpleTextOut.Mode->Attribute     = 0;
    435   ProtocolToReturn->SimpleTextOut.Mode->CursorColumn  = 0;
    436   ProtocolToReturn->SimpleTextOut.Mode->CursorRow     = 0;
    437   ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = FALSE;
     463  ProtocolToReturn->SimpleTextOut.Mode->MaxMode       = OriginalProtocol->Mode->MaxMode;
     464  ProtocolToReturn->SimpleTextOut.Mode->Mode          = OriginalProtocol->Mode->Mode;
     465  ProtocolToReturn->SimpleTextOut.Mode->Attribute     = OriginalProtocol->Mode->Attribute;
     466  ProtocolToReturn->SimpleTextOut.Mode->CursorColumn  = OriginalProtocol->Mode->CursorColumn;
     467  ProtocolToReturn->SimpleTextOut.Mode->CursorRow     = OriginalProtocol->Mode->CursorRow;
     468  ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = OriginalProtocol->Mode->CursorVisible;
    438469
    439470  Status = gBS->InstallProtocolInterface(
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ConsoleWrappers.h

    r48674 r58459  
    22  Function definitions for shell simple text in and out on top of file handles.
    33
     4  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
    45  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
     
    5152  SHELL_FILE_HANDLE to support redirecting output from a file.
    5253
    53   @param[in]  FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.
    54   @param[in]  HandleLocation  The pointer of a location to copy handle with protocol to.
     54  @param[in]  FileHandleToUse  The pointer to the SHELL_FILE_HANDLE to use.
     55  @param[in]  HandleLocation   The pointer of a location to copy handle with protocol to.
     56  @param[in]  OriginalProtocol The pointer to the original output protocol for pass thru of functions.
    5557
    5658  @retval NULL                There was insufficient memory available.
     
    6062EFIAPI
    6163CreateSimpleTextOutOnFile(
    62   IN SHELL_FILE_HANDLE  FileHandleToUse,
    63   IN EFI_HANDLE         *HandleLocation
     64  IN SHELL_FILE_HANDLE               FileHandleToUse,
     65  IN EFI_HANDLE                      *HandleLocation,
     66  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol
    6467  );
    6568
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/FileHandleWrappers.c

    r48674 r58459  
    33  StdIn, StdOut, StdErr, etc...).
    44
    5   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     5  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
     6  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
    67  This program and the accompanying materials
    78  are licensed and made available under the terms and conditions of the BSD License
     
    417418    Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
    418419    if (EFI_ERROR (Status)) {
    419       continue;
     420      break;
    420421    }
    421422
     
    509510          Cwd = ShellInfoObject.NewEfiShellProtocol->GetCurDir(NULL);
    510511          if (Cwd != NULL) {
    511             StrCpy(TabStr, Cwd);
     512            StrnCpy(TabStr, Cwd, (*BufferSize)/sizeof(CHAR16) - 1);
    512513            if (TabStr[StrLen(TabStr)-1] == L'\\' && *(CurrentString + TabPos) == L'\\' ) {
    513514              TabStr[StrLen(TabStr)-1] = CHAR_NULL;
     
    515516            StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));
    516517          } else {
    517             StrCpy(TabStr, L"");
     518            *TabStr = CHAR_NULL;
    518519            StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));
    519520          }
    520521        } else {
    521           StrCpy(TabStr, CurrentString + TabPos);
     522          StrnCpy(TabStr, CurrentString + TabPos, (*BufferSize)/sizeof(CHAR16) - 1);
    522523        }
    523         StrCat(TabStr, L"*");
     524        StrnCat(TabStr, L"*", (*BufferSize)/sizeof(CHAR16) - 1 - StrLen(TabStr));
    524525        FoundFileList = NULL;
    525 //        TabStr = PathCleanUpDirectories(TabStr);
    526526        Status  = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FoundFileList);
    527527        for ( TempStr = CurrentString
     
    849849  ASSERT(FoundFileList == NULL);
    850850
    851   return EFI_SUCCESS;
     851  return Status;
    852852}
    853853
     
    951951  )
    952952{
     953  VOID*       NewBuffer;
     954  UINTN       NewSize;
     955  EFI_STATUS  Status;
     956
     957  //
     958  // Most if not all UEFI commands will have an '\r\n' at the end of any output.
     959  // Since the output was redirected to a variable, it does not make sense to
     960  // keep this.  So, before closing, strip the trailing '\r\n' from the variable
     961  // if it exists.
     962  //
     963  NewBuffer   = NULL;
     964  NewSize     = 0;
     965
     966  Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);
     967  if (Status == EFI_BUFFER_TOO_SMALL) {
     968    NewBuffer = AllocateZeroPool(NewSize + sizeof(CHAR16));
     969    if (NewBuffer == NULL) {
     970      return EFI_OUT_OF_RESOURCES;
     971    } 
     972    Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);
     973  }
     974 
     975  if (!EFI_ERROR(Status) && NewBuffer != NULL) {
     976   
     977    if (StrSize(NewBuffer) > 6)
     978    {
     979      if ((((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 2] == CHAR_LINEFEED)
     980           && (((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] == CHAR_CARRIAGE_RETURN)) {
     981        ((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] = CHAR_NULL;   
     982      }
     983   
     984      if (IsVolatileEnv(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name)) {
     985        Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);
     986      } else {
     987        Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);
     988      }
     989    }
     990  }
     991 
     992  SHELL_FREE_NON_NULL(NewBuffer);
    953993  FreePool((EFI_FILE_PROTOCOL_ENVIRONMENT*)This);
    954   return (EFI_SUCCESS);
     994  return (Status);
    955995}
    956996
     
    11011141{
    11021142  EFI_FILE_PROTOCOL_ENVIRONMENT  *EnvFileInterface;
     1143  UINTN                          EnvNameSize;
    11031144
    11041145  if (EnvName == NULL) {
     
    11091150  // Get some memory
    11101151  //
    1111   EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+StrSize(EnvName));
     1152  EnvNameSize = StrSize(EnvName);
     1153  EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+EnvNameSize);
    11121154  if (EnvFileInterface == NULL){
    11131155    return (NULL);
     
    11271169  EnvFileInterface->Delete      = FileInterfaceEnvDelete;
    11281170  EnvFileInterface->Read        = FileInterfaceEnvRead;
    1129 
    1130   StrCpy(EnvFileInterface->Name, EnvName);
     1171 
     1172  CopyMem(EnvFileInterface->Name, EnvName, EnvNameSize);
    11311173
    11321174  //
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/Shell.c

    r48674 r58459  
    22  This is THE shell (application)
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
     5  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    2425  FALSE,
    2526  {
    26     0,
    27     0,
    28     0,
    29     0,
    30     0,
    31     0,
    32     0,
    33     0,
    34     0,
     27    {{
     28      0,
     29      0,
     30      0,
     31      0,
     32      0,
     33      0,
     34      0,
     35      0,
     36      0
     37    }},
    3538    0,
    3639    NULL,
    3740    NULL
    3841  },
    39   {0,0},
     42  {{NULL, NULL}, NULL},
    4043  {
    41     {0,0},
     44    {{NULL, NULL}, NULL},
    4245    0,
    4346    0,
     
    5154  NULL,
    5255  NULL,
    53   {0,0,NULL,NULL},
    54   {0,0},
     56  {{NULL, NULL}, NULL, NULL},
     57  {{NULL, NULL}, NULL, NULL},
     58  NULL,
     59  NULL,
     60  NULL,
     61  NULL,
    5562  NULL,
    5663  NULL,
     
    6370STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";
    6471STATIC CONST CHAR16 mStartupScript[]        = L"startup.nsh";
     72
     73/**
     74  Cleans off leading and trailing spaces and tabs.
     75
     76  @param[in] String pointer to the string to trim them off.
     77**/
     78EFI_STATUS
     79EFIAPI
     80TrimSpaces(
     81  IN CHAR16 **String
     82  )
     83{
     84  ASSERT(String != NULL);
     85  ASSERT(*String!= NULL);
     86  //
     87  // Remove any spaces and tabs at the beginning of the (*String).
     88  //
     89  while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) {
     90    CopyMem((*String), (*String)+1, StrSize((*String)) - sizeof((*String)[0]));
     91  }
     92
     93  //
     94  // Remove any spaces and tabs at the end of the (*String).
     95  //
     96  while ((StrLen (*String) > 0) && (((*String)[StrLen((*String))-1] == L' ') || ((*String)[StrLen((*String))-1] == L'\t'))) {
     97    (*String)[StrLen((*String))-1] = CHAR_NULL;
     98  }
     99
     100  return (EFI_SUCCESS);
     101}
     102
     103/**
     104  Parse for the next instance of one string within another string. Can optionally make sure that
     105  the string was not escaped (^ character) per the shell specification.
     106
     107  @param[in] SourceString             The string to search within
     108  @param[in] FindString               The string to look for
     109  @param[in] CheckForEscapeCharacter  TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances
     110**/
     111CHAR16*
     112EFIAPI
     113FindNextInstance(
     114  IN CONST CHAR16   *SourceString,
     115  IN CONST CHAR16   *FindString,
     116  IN CONST BOOLEAN  CheckForEscapeCharacter
     117  )
     118{
     119  CHAR16 *Temp;
     120  if (SourceString == NULL) {
     121    return (NULL);
     122  }
     123  Temp = StrStr(SourceString, FindString);
     124
     125  //
     126  // If nothing found, or we dont care about escape characters
     127  //
     128  if (Temp == NULL || !CheckForEscapeCharacter) {
     129    return (Temp);
     130  }
     131
     132  //
     133  // If we found an escaped character, try again on the remainder of the string
     134  //
     135  if ((Temp > (SourceString)) && *(Temp-1) == L'^') {
     136    return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);
     137  }
     138
     139  //
     140  // we found the right character
     141  //
     142  return (Temp);
     143}
     144
     145/**
     146  Check whether the string between a pair of % is a valid envifronment variable name.
     147
     148  @param[in] BeginPercent       pointer to the first percent.
     149  @param[in] EndPercent          pointer to the last percent.
     150
     151  @retval TRUE                          is a valid environment variable name.
     152  @retval FALSE                         is NOT a valid environment variable name.
     153**/
     154BOOLEAN
     155IsValidEnvironmentVariableName(
     156  IN CONST CHAR16     *BeginPercent,
     157  IN CONST CHAR16     *EndPercent
     158  )
     159{
     160  CONST CHAR16    *Walker;
     161 
     162  Walker = NULL;
     163
     164  ASSERT (BeginPercent != NULL);
     165  ASSERT (EndPercent != NULL);
     166  ASSERT (BeginPercent < EndPercent);
     167 
     168  if ((BeginPercent + 1) == EndPercent) {
     169    return FALSE;
     170  }
     171
     172  for (Walker = BeginPercent + 1; Walker < EndPercent; Walker++) {
     173    if (
     174        (*Walker >= L'0' && *Walker <= L'9') ||
     175        (*Walker >= L'A' && *Walker <= L'Z') ||
     176        (*Walker >= L'a' && *Walker <= L'z') ||
     177        (*Walker == L'_')
     178      ) {
     179      if (Walker == BeginPercent + 1 && (*Walker >= L'0' && *Walker <= L'9')) {
     180        return FALSE;
     181      } else {
     182        continue;
     183      }
     184    } else {
     185      return FALSE;
     186    }
     187  }
     188
     189  return TRUE;
     190}
     191
     192/**
     193  Determine if a command line contains a split operation
     194
     195  @param[in] CmdLine      The command line to parse.
     196
     197  @retval TRUE            CmdLine has a valid split.
     198  @retval FALSE           CmdLine does not have a valid split.
     199**/
     200BOOLEAN
     201EFIAPI
     202ContainsSplit(
     203  IN CONST CHAR16 *CmdLine
     204  )
     205{
     206  CONST CHAR16 *TempSpot;
     207  CONST CHAR16 *FirstQuote;
     208  CONST CHAR16 *SecondQuote;
     209
     210  FirstQuote    = FindNextInstance (CmdLine, L"\"", TRUE);
     211  SecondQuote   = NULL;
     212  TempSpot      = FindFirstCharacter(CmdLine, L"|", L'^');
     213
     214  if (FirstQuote == NULL    ||
     215      TempSpot == NULL      ||
     216      TempSpot == CHAR_NULL ||
     217      FirstQuote > TempSpot
     218      ) {
     219    return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));
     220  }
     221
     222  while ((TempSpot != NULL) && (*TempSpot != CHAR_NULL)) {
     223    if (FirstQuote == NULL || FirstQuote > TempSpot) {
     224      break;
     225    }   
     226    SecondQuote = FindNextInstance (FirstQuote + 1, L"\"", TRUE);
     227    if (SecondQuote == NULL) {
     228      break;
     229    }
     230    if (SecondQuote < TempSpot) {
     231      FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);
     232      continue;
     233    } else {
     234      FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);
     235      TempSpot = FindFirstCharacter(TempSpot + 1, L"|", L'^');
     236      continue;
     237    }
     238  }
     239 
     240  return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));
     241}
    65242
    66243/**
     
    125302      &KeyData,
    126303      NotificationFunction,
    127       &ShellInfoObject.CtrlSNotifyHandle2);
     304      &ShellInfoObject.CtrlSNotifyHandle3);
    128305  } 
    129306  KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;
     
    133310      &KeyData,
    134311      NotificationFunction,
    135       &ShellInfoObject.CtrlSNotifyHandle2);
     312      &ShellInfoObject.CtrlSNotifyHandle4);
    136313  }
    137314  return (Status);
     
    237414      }
    238415      if (ShellInfoObject.HiiHandle == NULL) {
    239         return (EFI_NOT_STARTED);
     416        Status = EFI_NOT_STARTED;
     417        goto FreeResources;
    240418      }
    241419    }
     
    267445    // Check the command line
    268446    //
    269     Status = ProcessCommandLine();
     447    Status = ProcessCommandLine ();
     448    if (EFI_ERROR (Status)) {
     449      goto FreeResources;
     450    }
    270451
    271452    //
     
    291472        gST->ConOut->Mode->CursorRow,
    292473        NULL,
    293         STRING_TOKEN (STR_VER_OUTPUT_MAIN),
     474        STRING_TOKEN (STR_VER_OUTPUT_MAIN_SHELL),
    294475        ShellInfoObject.HiiHandle,
    295476        SupportLevel[PcdGet8(PcdShellSupportLevel)],
    296477        gEfiShellProtocol->MajorVersion,
    297         gEfiShellProtocol->MinorVersion,
     478        gEfiShellProtocol->MinorVersion
     479       );
     480
     481      ShellPrintHiiEx (
     482        -1,
     483        -1,
     484        NULL,
     485        STRING_TOKEN (STR_VER_OUTPUT_MAIN_SUPPLIER),
     486        ShellInfoObject.HiiHandle,
     487        (CHAR16 *) PcdGetPtr (PcdShellSupplier)
     488       );
     489
     490      ShellPrintHiiEx (
     491        -1,
     492        -1,
     493        NULL,
     494        STRING_TOKEN (STR_VER_OUTPUT_MAIN_UEFI),
     495        ShellInfoObject.HiiHandle,
    298496        (gST->Hdr.Revision&0xffff0000)>>16,
    299497        (gST->Hdr.Revision&0x0000ffff),
     
    376574      }
    377575
    378       if (!ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
     576      if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
    379577        //
    380578        // begin the UI waiting loop
     
    393591          //
    394592          ShellInfoObject.PageBreakEnabled        = PcdGetBool(PcdShellPageBreakDefault);
     593          ASSERT (ShellInfoObject.ConsoleInfo != NULL);
    395594          ShellInfoObject.ConsoleInfo->Enabled    = TRUE;
    396595          ShellInfoObject.ConsoleInfo->RowCounter = 0;
     
    415614  }
    416615
     616FreeResources:
    417617  //
    418618  // uninstall protocols / free memory / etc...
     
    436636  if (ShellInfoObject.NewEfiShellProtocol != NULL){
    437637    if (ShellInfoObject.NewEfiShellProtocol->IsRootShell()){
    438       ShellInfoObject.NewEfiShellProtocol->SetEnv(L"cwd", L"", TRUE);
     638      InternalEfiShellSetEnv(L"cwd", NULL, TRUE);
    439639    }
    440640    CleanUpShellProtocol(ShellInfoObject.NewEfiShellProtocol);
     
    627827}
    628828
    629 STATIC CONST SHELL_PARAM_ITEM mShellParamList[] = {
    630   {L"-nostartup",     TypeFlag},
    631   {L"-startup",       TypeFlag},
    632   {L"-noconsoleout",  TypeFlag},
    633   {L"-noconsolein",   TypeFlag},
    634   {L"-nointerrupt",   TypeFlag},
    635   {L"-nomap",         TypeFlag},
    636   {L"-noversion",     TypeFlag},
    637   {L"-startup",       TypeFlag},
    638   {L"-delay",         TypeValue},
    639   {NULL, TypeMax}
    640   };
    641 
    642829/**
    643830  Process all Uefi Shell 2.0 command line options.
     
    673860  )
    674861{
    675   EFI_STATUS    Status;
    676   LIST_ENTRY    *Package;
    677   UINTN         Size;
    678   CONST CHAR16  *TempConst;
    679   UINTN         Count;
    680   UINTN         LoopVar;
    681   CHAR16        *ProblemParam;
    682   UINT64        Intermediate;
    683 
    684   Package       = NULL;
    685   ProblemParam  = NULL;
    686  
    687   Status = ShellCommandLineParse (mShellParamList, &Package, NULL, FALSE);
    688 
    689   Count = 1;
    690   Size = 0;
    691   TempConst = ShellCommandLineGetRawValue(Package, Count++);
    692   if (TempConst != NULL && StrLen(TempConst)) {
    693     ShellInfoObject.ShellInitSettings.FileName = AllocateZeroPool(StrSize(TempConst));
    694     if (ShellInfoObject.ShellInitSettings.FileName == NULL) {
    695       return (EFI_OUT_OF_RESOURCES);
    696     }
    697     StrCpy(ShellInfoObject.ShellInitSettings.FileName, TempConst);
    698     ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;
    699     for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
    700       if (StrCmp(gEfiShellParametersProtocol->Argv[LoopVar], ShellInfoObject.ShellInitSettings.FileName)==0) {
    701         LoopVar++;
    702         //
    703         // We found the file... add the rest of the params...
    704         //
    705         for ( ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
    706           ASSERT((ShellInfoObject.ShellInitSettings.FileOptions == NULL && Size == 0) || (ShellInfoObject.ShellInitSettings.FileOptions != NULL));
    707           StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,
    708                       &Size,
    709                       L" ",
    710                       0);
    711           if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {
    712             SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);
    713             return (EFI_OUT_OF_RESOURCES);
    714           }
    715           StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,
    716                       &Size,
    717                       gEfiShellParametersProtocol->Argv[LoopVar],
    718                       0);
    719           if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {
    720             SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);
    721             return (EFI_OUT_OF_RESOURCES);
    722           }
     862  UINTN                           Size;
     863  UINTN                           LoopVar;
     864  CHAR16                          *CurrentArg;
     865  CHAR16                          *DelayValueStr;
     866  UINT64                          DelayValue;
     867  EFI_STATUS                      Status;
     868  EFI_UNICODE_COLLATION_PROTOCOL  *UnicodeCollation;
     869
     870  // `file-name-options` will contain arguments to `file-name` that we don't
     871  // know about. This would cause ShellCommandLineParse to error, so we parse
     872  // arguments manually, ignoring those after the first thing that doesn't look
     873  // like a shell option (which is assumed to be `file-name`).
     874
     875  Status = gBS->LocateProtocol (
     876                  &gEfiUnicodeCollationProtocolGuid,
     877                  NULL,
     878                  (VOID **) &UnicodeCollation
     879                  );
     880  if (EFI_ERROR (Status)) {
     881    return Status;
     882  }
     883
     884  // Set default options
     885  ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup      = FALSE;
     886  ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup    = FALSE;
     887  ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut = FALSE;
     888  ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn  = FALSE;
     889  ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt  = FALSE;
     890  ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap        = FALSE;
     891  ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion    = FALSE;
     892  ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay        = FALSE;
     893  ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit         = FALSE;
     894  ShellInfoObject.ShellInitSettings.Delay = 5;
     895
     896  //
     897  // Start LoopVar at 0 to parse only optional arguments at Argv[0]
     898  // and parse other parameters from Argv[1].  This is for use case that
     899  // UEFI Shell boot option is created, and OptionalData is provided
     900  // that starts with shell command-line options.
     901  //
     902  for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
     903    CurrentArg = gEfiShellParametersProtocol->Argv[LoopVar];
     904    if (UnicodeCollation->StriColl (
     905                            UnicodeCollation,
     906                            L"-startup",
     907                            CurrentArg
     908                            ) == 0) {
     909      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup      = TRUE;
     910    }
     911    else if (UnicodeCollation->StriColl (
     912                                 UnicodeCollation,
     913                                 L"-nostartup",
     914                                 CurrentArg
     915                                 ) == 0) {
     916      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup    = TRUE;
     917    }
     918    else if (UnicodeCollation->StriColl (
     919                                 UnicodeCollation,
     920                                 L"-noconsoleout",
     921                                 CurrentArg
     922                                 ) == 0) {
     923      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut = TRUE;
     924    }
     925    else if (UnicodeCollation->StriColl (
     926                                 UnicodeCollation,
     927                                 L"-noconsolein",
     928                                 CurrentArg
     929                                 ) == 0) {
     930      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn  = TRUE;
     931    }
     932    else if (UnicodeCollation->StriColl (
     933                                 UnicodeCollation,
     934                                 L"-nointerrupt",
     935                                 CurrentArg
     936                                 ) == 0) {
     937      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt  = TRUE;
     938    }
     939    else if (UnicodeCollation->StriColl (
     940                                 UnicodeCollation,
     941                                 L"-nomap",
     942                                 CurrentArg
     943                                 ) == 0) {
     944      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap        = TRUE;
     945    }
     946    else if (UnicodeCollation->StriColl (
     947                                 UnicodeCollation,
     948                                 L"-noversion",
     949                                 CurrentArg
     950                                 ) == 0) {
     951      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion    = TRUE;
     952    }
     953    else if (UnicodeCollation->StriColl (
     954                                 UnicodeCollation,
     955                                 L"-delay",
     956                                 CurrentArg
     957                                 ) == 0) {
     958      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay        = TRUE;
     959      // Check for optional delay value following "-delay"
     960      DelayValueStr = gEfiShellParametersProtocol->Argv[LoopVar + 1];
     961      if (DelayValueStr != NULL){
     962        if (*DelayValueStr == L':') {
     963          DelayValueStr++;
    723964        }
    724       }
    725     }
    726   } else {
    727     ShellCommandLineFreeVarList(Package);
    728     Package = NULL;
    729     Status = ShellCommandLineParse (mShellParamList, &Package, &ProblemParam, FALSE);
    730     if (EFI_ERROR(Status)) {
    731       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), ShellInfoObject.HiiHandle, ProblemParam);
    732       FreePool(ProblemParam);
    733       ShellCommandLineFreeVarList(Package);
    734       return (EFI_INVALID_PARAMETER);
    735     }
    736   }
    737 
    738   ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup      = ShellCommandLineGetFlag(Package, L"-startup");
    739   ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup    = ShellCommandLineGetFlag(Package, L"-nostartup");
    740   ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut = ShellCommandLineGetFlag(Package, L"-noconsoleout");
    741   ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn  = ShellCommandLineGetFlag(Package, L"-noconsolein");
    742   ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt  = ShellCommandLineGetFlag(Package, L"-nointerrupt");
    743   ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap        = ShellCommandLineGetFlag(Package, L"-nomap");
    744   ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion    = ShellCommandLineGetFlag(Package, L"-noversion");
    745   ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay        = ShellCommandLineGetFlag(Package, L"-delay");
    746 
    747   ShellInfoObject.ShellInitSettings.Delay = 5;
    748 
     965        if (!EFI_ERROR(ShellConvertStringToUint64 (
     966                        DelayValueStr,
     967                        &DelayValue,
     968                        FALSE,
     969                        FALSE
     970                        ))) {
     971          ShellInfoObject.ShellInitSettings.Delay = (UINTN)DelayValue;
     972          LoopVar++;
     973        }
     974      }
     975    } else if (UnicodeCollation->StriColl (
     976                                   UnicodeCollation,
     977                                   L"-_exit",
     978                                   CurrentArg
     979                                   ) == 0) {
     980      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit         = TRUE;
     981    } else if (StrnCmp (L"-", CurrentArg, 1) == 0) {
     982      // Unrecognised option
     983      ShellPrintHiiEx(-1, -1, NULL,
     984        STRING_TOKEN (STR_GEN_PROBLEM),
     985        ShellInfoObject.HiiHandle,
     986        CurrentArg
     987        );
     988      return EFI_INVALID_PARAMETER;
     989    } else {
     990      //
     991      // First argument should be Shell.efi image name
     992      //
     993      if (LoopVar == 0) {
     994        continue;
     995      }
     996
     997      ShellInfoObject.ShellInitSettings.FileName = AllocateCopyPool(StrSize(CurrentArg), CurrentArg);
     998      if (ShellInfoObject.ShellInitSettings.FileName == NULL) {
     999        return (EFI_OUT_OF_RESOURCES);
     1000      }
     1001      //
     1002      // We found `file-name`.
     1003      //
     1004      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;
     1005      LoopVar++;
     1006
     1007      // Add `file-name-options`
     1008      for (Size = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
     1009        ASSERT((ShellInfoObject.ShellInitSettings.FileOptions == NULL && Size == 0) || (ShellInfoObject.ShellInitSettings.FileOptions != NULL));
     1010        StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,
     1011                    &Size,
     1012                    L" ",
     1013                    0);
     1014        if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {
     1015          SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);
     1016          return (EFI_OUT_OF_RESOURCES);
     1017        }
     1018        StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,
     1019                    &Size,
     1020                    gEfiShellParametersProtocol->Argv[LoopVar],
     1021                    0);
     1022        if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {
     1023          SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);
     1024          return (EFI_OUT_OF_RESOURCES);
     1025        }
     1026      }
     1027    }
     1028  }
     1029
     1030  // "-nointerrupt" overrides "-delay"
    7491031  if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {
    7501032    ShellInfoObject.ShellInitSettings.Delay = 0;
    751   } else if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay) {
    752     TempConst = ShellCommandLineGetValue(Package, L"-delay");
    753     if (TempConst != NULL && *TempConst == L':') {
    754       TempConst++;
    755     }
    756     if (TempConst != NULL && !EFI_ERROR(ShellConvertStringToUint64(TempConst, &Intermediate, FALSE, FALSE))) {
    757       ShellInfoObject.ShellInitSettings.Delay = (UINTN)Intermediate;
    758     }
    759   }
    760   ShellCommandLineFreeVarList(Package);
    761 
    762   return (Status);
     1033  }
     1034
     1035  return EFI_SUCCESS;
    7631036}
    7641037
     
    7761049EFIAPI
    7771050DoStartupScript(
    778   EFI_DEVICE_PATH_PROTOCOL *ImagePath,
    779   EFI_DEVICE_PATH_PROTOCOL *FilePath
     1051  IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,
     1052  IN EFI_DEVICE_PATH_PROTOCOL *FilePath
    7801053  )
    7811054{
     
    8071080      return (EFI_OUT_OF_RESOURCES);
    8081081    }
    809     StrCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName);
     1082    StrnCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName, NewSize/sizeof(CHAR16) -1);
    8101083    if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {
    811       StrCat(FileStringPath, L" ");
    812       StrCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions);
     1084      StrnCat(FileStringPath, L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
     1085      StrnCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);
    8131086    }
    8141087    Status = RunCommand(FileStringPath);
     
    8281101  }
    8291102
     1103  gST->ConOut->EnableCursor(gST->ConOut, FALSE);
    8301104  //
    8311105  // print out our warning and see if they press a key
    8321106  //
    833   for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay * 10
     1107  for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay
    8341108      ; Delay != 0 && EFI_ERROR(Status)
    8351109      ; Delay--
    8361110     ){
    837     ShellPrintHiiEx(0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay/10);
    838     gBS->Stall (100000);
     1111    ShellPrintHiiEx(0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay);
     1112    gBS->Stall (1000000);
    8391113    if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {
    8401114      Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
     
    8421116  }
    8431117  ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle);
     1118  gST->ConOut->EnableCursor(gST->ConOut, TRUE);
    8441119
    8451120  //
     
    8871162  //
    8881163  if (!EFI_ERROR(Status) && FileHandle != NULL) {
    889     Status = RunScriptFileHandle (FileHandle, mStartupScript);
     1164    Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);
    8901165    ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);
    8911166  } else {
     
    8981173      ASSERT(FileHandle == NULL);
    8991174    } else {
    900       Status = RunScriptFile(FileStringPath);
     1175      Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);
    9011176      FreePool(FileStringPath);
    9021177    }
     
    9641239    CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;
    9651240    Status = RunCommand(CmdLine);
    966   }
     1241    }
    9671242
    9681243  //
     
    10131288  Node = AllocateZeroPool(sizeof(BUFFER_LIST));
    10141289  ASSERT(Node != NULL);
    1015   Node->Buffer = AllocateZeroPool(StrSize(Buffer));
     1290  Node->Buffer = AllocateCopyPool(StrSize(Buffer), Buffer);
    10161291  ASSERT(Node->Buffer != NULL);
    1017   StrCpy(Node->Buffer, Buffer);
    10181292
    10191293  InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);
     
    10461320  }
    10471321  FreePool(*CommandString);
    1048   *CommandString = AllocateZeroPool(StrSize(NewString));
     1322  *CommandString = AllocateCopyPool(StrSize(NewString), NewString);
    10491323  if (*CommandString == NULL) {
    10501324    return (EFI_OUT_OF_RESOURCES);
    10511325  }
    1052   StrCpy(*CommandString, NewString);
     1326  return (EFI_SUCCESS);
     1327}
     1328
     1329/**
     1330  This function will eliminate unreplaced (and therefore non-found) environment variables.
     1331
     1332  @param[in,out] CmdLine   The command line to update.
     1333**/
     1334EFI_STATUS
     1335EFIAPI
     1336StripUnreplacedEnvironmentVariables(
     1337  IN OUT CHAR16 *CmdLine
     1338  )
     1339{
     1340  CHAR16 *FirstPercent;
     1341  CHAR16 *FirstQuote;
     1342  CHAR16 *SecondPercent;
     1343  CHAR16 *SecondQuote;
     1344  CHAR16 *CurrentLocator;
     1345
     1346  for (CurrentLocator = CmdLine ; CurrentLocator != NULL ; ) {
     1347    FirstQuote = FindNextInstance(CurrentLocator, L"\"", TRUE);
     1348    FirstPercent = FindNextInstance(CurrentLocator, L"%", TRUE);
     1349    SecondPercent = FirstPercent!=NULL?FindNextInstance(FirstPercent+1, L"%", TRUE):NULL;
     1350    if (FirstPercent == NULL || SecondPercent == NULL) {
     1351      //
     1352      // If we ever dont have 2 % we are done.
     1353      //
     1354      break;
     1355    }
     1356
     1357    if (FirstQuote!= NULL && FirstQuote < FirstPercent) {
     1358      SecondQuote = FindNextInstance(FirstQuote+1, L"\"", TRUE);
     1359      //
     1360      // Quote is first found
     1361      //
     1362
     1363      if (SecondQuote < FirstPercent) {
     1364        //
     1365        // restart after the pair of "
     1366        //
     1367        CurrentLocator = SecondQuote + 1;
     1368      } else /* FirstPercent < SecondQuote */{
     1369        //
     1370        // Restart on the first percent
     1371        //
     1372        CurrentLocator = FirstPercent;
     1373      }
     1374      continue;
     1375    }
     1376   
     1377    if (FirstQuote == NULL || SecondPercent < FirstQuote) {
     1378      if (IsValidEnvironmentVariableName(FirstPercent, SecondPercent)) {
     1379        //
     1380        // We need to remove from FirstPercent to SecondPercent
     1381        //
     1382        CopyMem(FirstPercent, SecondPercent + 1, StrSize(SecondPercent + 1));
     1383        //
     1384        // dont need to update the locator.  both % characters are gone.
     1385        //
     1386      } else {
     1387        CurrentLocator = SecondPercent + 1;
     1388      }
     1389      continue;
     1390    }
     1391    CurrentLocator = FirstQuote;
     1392  }
    10531393  return (EFI_SUCCESS);
    10541394}
     
    11341474
    11351475  //
    1136   // Quick out if none were found...
    1137   //
    1138   if (NewSize == StrSize(OriginalCommandLine)) {
    1139     ASSERT(Temp == NULL);
    1140     Temp = StrnCatGrow(&Temp, NULL, OriginalCommandLine, 0);
    1141     return (Temp);
    1142   }
    1143 
    1144   //
    11451476  // now do the replacements...
    11461477  //
    1147   NewCommandLine1 = AllocateZeroPool(NewSize);
     1478  NewCommandLine1 = AllocateCopyPool(NewSize, OriginalCommandLine);
    11481479  NewCommandLine2 = AllocateZeroPool(NewSize);
    11491480  ItemTemp        = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));
     
    11541485    return (NULL);
    11551486  }
    1156   StrCpy(NewCommandLine1, OriginalCommandLine);
    11571487  for (MasterEnvList = EfiShellGetEnv(NULL)
    1158     ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL
     1488    ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL
    11591489    ;  MasterEnvList += StrLen(MasterEnvList) + 1
    11601490   ){
    1161     StrCpy(ItemTemp, L"%");
    1162     StrCat(ItemTemp, MasterEnvList);
    1163     StrCat(ItemTemp, L"%");
     1491    StrnCpy(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1);
     1492    StrnCat(ItemTemp, MasterEnvList, ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));
     1493    StrnCat(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));
    11641494    ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);
    1165     StrCpy(NewCommandLine1, NewCommandLine2);
     1495    StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
    11661496  }
    11671497  if (CurrentScriptFile != NULL) {
     
    11711501   ){
    11721502    ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);
    1173     StrCpy(NewCommandLine1, NewCommandLine2);
    1174     }
    1175   }
    1176 
     1503    StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
     1504    }
     1505  }
     1506
     1507  //
     1508  // Remove non-existant environment variables
     1509  //
     1510  StripUnreplacedEnvironmentVariables(NewCommandLine1);
     1511
     1512  //
     1513  // Now cleanup any straggler intentionally ignored "%" characters
     1514  //
     1515  ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);
     1516  StrnCpy(NewCommandLine1, NewCommandLine2, NewSize/sizeof(CHAR16)-1);
     1517 
    11771518  FreePool(NewCommandLine2);
    11781519  FreePool(ItemTemp);
     
    12251566    SHELL_FREE_NON_NULL(NextCommandLine);
    12261567    return (EFI_OUT_OF_RESOURCES);
    1227   }
    1228   if (NextCommandLine[0] != CHAR_NULL &&
     1568  } else if (StrStr(OurCommandLine, L"|") != NULL || Size1 == 0 || Size2 == 0) {
     1569    SHELL_FREE_NON_NULL(OurCommandLine);
     1570    SHELL_FREE_NON_NULL(NextCommandLine);
     1571    return (EFI_INVALID_PARAMETER);
     1572  } else if (NextCommandLine[0] != CHAR_NULL &&
    12291573      NextCommandLine[0] == L'a' &&
    12301574      NextCommandLine[1] == L' '
     
    12471591  InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);
    12481592
    1249   ASSERT(StrStr(OurCommandLine, L"|") == NULL);
    12501593  Status = RunCommand(OurCommandLine);
    12511594
     
    12901633
    12911634/**
    1292   Function will process and run a command line.
    1293 
    1294   This will determine if the command line represents an internal shell
    1295   command or dispatch an external application.
     1635  Take the original command line, substitute any variables, free
     1636  the original string, return the modified copy.
     1637
     1638  @param[in] CmdLine  pointer to the command line to update.
     1639
     1640  @retval EFI_SUCCESS           the function was successful.
     1641  @retval EFI_OUT_OF_RESOURCES  a memory allocation failed.
     1642**/
     1643EFI_STATUS
     1644EFIAPI
     1645ShellSubstituteVariables(
     1646  IN CHAR16 **CmdLine
     1647  )
     1648{
     1649  CHAR16      *NewCmdLine;
     1650  NewCmdLine = ShellConvertVariables(*CmdLine);
     1651  SHELL_FREE_NON_NULL(*CmdLine);
     1652  if (NewCmdLine == NULL) {
     1653    return (EFI_OUT_OF_RESOURCES);
     1654  }
     1655  *CmdLine = NewCmdLine;
     1656  return (EFI_SUCCESS);
     1657}
     1658
     1659/**
     1660  Take the original command line, substitute any alias in the first group of space delimited characters, free
     1661  the original string, return the modified copy.
     1662
     1663  @param[in] CmdLine  pointer to the command line to update.
     1664
     1665  @retval EFI_SUCCESS           the function was successful.
     1666  @retval EFI_OUT_OF_RESOURCES  a memory allocation failed.
     1667**/
     1668EFI_STATUS
     1669EFIAPI
     1670ShellSubstituteAliases(
     1671  IN CHAR16 **CmdLine
     1672  )
     1673{
     1674  CHAR16      *NewCmdLine;
     1675  CHAR16      *CommandName;
     1676  EFI_STATUS  Status;
     1677  UINTN       PostAliasSize;
     1678  ASSERT(CmdLine != NULL);
     1679  ASSERT(*CmdLine!= NULL);
     1680
     1681
     1682  CommandName = NULL;
     1683  if (StrStr((*CmdLine), L" ") == NULL){
     1684    StrnCatGrow(&CommandName, NULL, (*CmdLine), 0);
     1685  } else {
     1686    StrnCatGrow(&CommandName, NULL, (*CmdLine), StrStr((*CmdLine), L" ") - (*CmdLine));
     1687  }
     1688
     1689  //
     1690  // This cannot happen 'inline' since the CmdLine can need extra space.
     1691  //
     1692  NewCmdLine = NULL;
     1693  if (!ShellCommandIsCommandOnList(CommandName)) {
     1694    //
     1695    // Convert via alias
     1696    //
     1697    Status = ShellConvertAlias(&CommandName);
     1698    if (EFI_ERROR(Status)){
     1699      return (Status);
     1700    }
     1701    PostAliasSize = 0;
     1702    NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, CommandName, 0);
     1703    if (NewCmdLine == NULL) {
     1704      SHELL_FREE_NON_NULL(CommandName);
     1705      SHELL_FREE_NON_NULL(*CmdLine);
     1706      return (EFI_OUT_OF_RESOURCES);
     1707    }
     1708    NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, StrStr((*CmdLine), L" "), 0);
     1709    if (NewCmdLine == NULL) {
     1710      SHELL_FREE_NON_NULL(CommandName);
     1711      SHELL_FREE_NON_NULL(*CmdLine);
     1712      return (EFI_OUT_OF_RESOURCES);
     1713    }
     1714  } else {
     1715    NewCmdLine = StrnCatGrow(&NewCmdLine, NULL, (*CmdLine), 0);
     1716  }
     1717
     1718  SHELL_FREE_NON_NULL(*CmdLine);
     1719  SHELL_FREE_NON_NULL(CommandName);
     1720 
     1721  //
     1722  // re-assign the passed in double pointer to point to our newly allocated buffer
     1723  //
     1724  *CmdLine = NewCmdLine;
     1725
     1726  return (EFI_SUCCESS);
     1727}
     1728
     1729/**
     1730  Takes the Argv[0] part of the command line and determine the meaning of it.
     1731
     1732  @param[in] CmdName  pointer to the command line to update.
     1733 
     1734  @retval Internal_Command    The name is an internal command.
     1735  @retval File_Sys_Change     the name is a file system change.
     1736  @retval Script_File_Name    the name is a NSH script file.
     1737  @retval Unknown_Invalid     the name is unknown.
     1738  @retval Efi_Application     the name is an application (.EFI).
     1739**/
     1740SHELL_OPERATION_TYPES
     1741EFIAPI
     1742GetOperationType(
     1743  IN CONST CHAR16 *CmdName
     1744  )
     1745{
     1746        CHAR16* FileWithPath;
     1747  CONST CHAR16* TempLocation;
     1748  CONST CHAR16* TempLocation2;
     1749
     1750  FileWithPath = NULL;
     1751  //
     1752  // test for an internal command.
     1753  //
     1754  if (ShellCommandIsCommandOnList(CmdName)) {
     1755    return (Internal_Command);
     1756  }
     1757
     1758  //
     1759  // Test for file system change request.  anything ending with first : and cant have spaces.
     1760  //
     1761  if (CmdName[(StrLen(CmdName)-1)] == L':') {
     1762    if ( StrStr(CmdName, L" ") != NULL
     1763      || StrLen(StrStr(CmdName, L":")) > 1
     1764      ) {
     1765      return (Unknown_Invalid);
     1766    }
     1767    return (File_Sys_Change);
     1768  }
     1769
     1770  //
     1771  // Test for a file
     1772  //
     1773  if ((FileWithPath = ShellFindFilePathEx(CmdName, mExecutableExtensions)) != NULL) {
     1774    //
     1775    // See if that file has a script file extension
     1776    //
     1777    if (StrLen(FileWithPath) > 4) {
     1778      TempLocation = FileWithPath+StrLen(FileWithPath)-4;
     1779      TempLocation2 = mScriptExtension;
     1780      if (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0) {
     1781        SHELL_FREE_NON_NULL(FileWithPath);
     1782        return (Script_File_Name);
     1783      }
     1784    }
     1785
     1786    //
     1787    // Was a file, but not a script.  we treat this as an application.
     1788    //
     1789    SHELL_FREE_NON_NULL(FileWithPath);
     1790    return (Efi_Application);
     1791  }
     1792 
     1793  SHELL_FREE_NON_NULL(FileWithPath);
     1794  //
     1795  // No clue what this is... return invalid flag...
     1796  //
     1797  return (Unknown_Invalid);
     1798}
     1799
     1800/**
     1801  Determine if the first item in a command line is valid.
     1802
     1803  @param[in] CmdLine            The command line to parse.
     1804
     1805  @retval EFI_SUCCESS           The item is valid.
     1806  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.
     1807  @retval EFI_NOT_FOUND         The operation type is unknown or invalid.
     1808**/
     1809EFI_STATUS
     1810EFIAPI
     1811IsValidSplit(
     1812  IN CONST CHAR16 *CmdLine
     1813  )
     1814{
     1815  CHAR16        *Temp;
     1816  CHAR16        *FirstParameter;
     1817  CHAR16        *TempWalker;
     1818  EFI_STATUS    Status;
     1819
     1820  Temp           = NULL;
     1821
     1822  Temp = StrnCatGrow(&Temp, NULL, CmdLine, 0);
     1823  if (Temp == NULL) {
     1824    return (EFI_OUT_OF_RESOURCES);
     1825  }
     1826
     1827  FirstParameter = StrStr(Temp, L"|");
     1828  if (FirstParameter != NULL) {
     1829    *FirstParameter = CHAR_NULL;
     1830  }
     1831
     1832  FirstParameter = NULL;
     1833
     1834  //
     1835  // Process the command line
     1836  //
     1837  Status = ProcessCommandLineToFinal(&Temp);
     1838
     1839  if (!EFI_ERROR(Status)) {
     1840    FirstParameter = AllocateZeroPool(StrSize(CmdLine));
     1841    if (FirstParameter == NULL) {
     1842      SHELL_FREE_NON_NULL(Temp);
     1843      return (EFI_OUT_OF_RESOURCES);
     1844    }
     1845    TempWalker = (CHAR16*)Temp;
     1846    if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine)))) {
     1847      if (GetOperationType(FirstParameter) == Unknown_Invalid) {
     1848        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
     1849        SetLastError(SHELL_NOT_FOUND);
     1850        Status = EFI_NOT_FOUND;
     1851      }
     1852    }
     1853  }
     1854
     1855  SHELL_FREE_NON_NULL(Temp);
     1856  SHELL_FREE_NON_NULL(FirstParameter);
     1857  return Status;
     1858}
     1859
     1860/**
     1861  Determine if a command line contains with a split contains only valid commands.
    12961862
    12971863  @param[in] CmdLine      The command line to parse.
     1864
     1865  @retval EFI_SUCCESS     CmdLine has only valid commands, application, or has no split.
     1866  @retval EFI_ABORTED     CmdLine has at least one invalid command or application.
     1867**/
     1868EFI_STATUS
     1869EFIAPI
     1870VerifySplit(
     1871  IN CONST CHAR16 *CmdLine
     1872  )
     1873{
     1874  CONST CHAR16  *TempSpot;
     1875  EFI_STATUS    Status;
     1876
     1877  //
     1878  // Verify up to the pipe or end character
     1879  //
     1880  Status = IsValidSplit(CmdLine);
     1881  if (EFI_ERROR(Status)) {
     1882    return (Status);
     1883  }
     1884
     1885  //
     1886  // If this was the only item, then get out
     1887  //
     1888  if (!ContainsSplit(CmdLine)) {
     1889    return (EFI_SUCCESS);
     1890  }
     1891
     1892  //
     1893  // recurse to verify the next item
     1894  //
     1895  TempSpot = FindFirstCharacter(CmdLine, L"|", L'^') + 1;
     1896  return (VerifySplit(TempSpot));
     1897}
     1898
     1899/**
     1900  Process a split based operation.
     1901
     1902  @param[in] CmdLine    pointer to the command line to process
     1903
     1904  @retval EFI_SUCCESS   The operation was successful
     1905  @return               an error occured.
     1906**/
     1907EFI_STATUS
     1908EFIAPI
     1909ProcessNewSplitCommandLine(
     1910  IN CONST CHAR16 *CmdLine
     1911  )
     1912{
     1913  SPLIT_LIST                *Split;
     1914  EFI_STATUS                Status;
     1915
     1916  Status = VerifySplit(CmdLine);
     1917  if (EFI_ERROR(Status)) {
     1918    return (Status);
     1919  }
     1920
     1921  Split = NULL;
     1922
     1923  //
     1924  // are we in an existing split???
     1925  //
     1926  if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
     1927    Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
     1928  }
     1929
     1930  if (Split == NULL) {
     1931    Status = RunSplitCommand(CmdLine, NULL, NULL);
     1932  } else {
     1933    Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);
     1934  }
     1935  if (EFI_ERROR(Status)) {
     1936    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);
     1937  }
     1938  return (Status);
     1939}
     1940
     1941/**
     1942  Handle a request to change the current file system.
     1943
     1944  @param[in] CmdLine  The passed in command line.
     1945
     1946  @retval EFI_SUCCESS The operation was successful.
     1947**/
     1948EFI_STATUS
     1949EFIAPI
     1950ChangeMappedDrive(
     1951  IN CONST CHAR16 *CmdLine
     1952  )
     1953{
     1954  EFI_STATUS Status;
     1955  Status = EFI_SUCCESS;
     1956
     1957  //
     1958  // make sure we are the right operation
     1959  //
     1960  ASSERT(CmdLine[(StrLen(CmdLine)-1)] == L':' && StrStr(CmdLine, L" ") == NULL);
     1961 
     1962  //
     1963  // Call the protocol API to do the work
     1964  //
     1965  Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, CmdLine);
     1966
     1967  //
     1968  // Report any errors
     1969  //
     1970  if (EFI_ERROR(Status)) {
     1971    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, CmdLine);
     1972  }
     1973
     1974  return (Status);
     1975}
     1976
     1977/**
     1978  Reprocess the command line to direct all -? to the help command.
     1979
     1980  if found, will add "help" as argv[0], and move the rest later.
     1981
     1982  @param[in,out] CmdLine        pointer to the command line to update
     1983**/
     1984EFI_STATUS
     1985EFIAPI
     1986DoHelpUpdate(
     1987  IN OUT CHAR16 **CmdLine
     1988  )
     1989{
     1990  CHAR16 *CurrentParameter;
     1991  CHAR16 *Walker;
     1992  CHAR16 *LastWalker;
     1993  CHAR16 *NewCommandLine;
     1994  EFI_STATUS Status;
     1995
     1996  Status = EFI_SUCCESS;
     1997
     1998  CurrentParameter = AllocateZeroPool(StrSize(*CmdLine));
     1999  if (CurrentParameter == NULL) {
     2000    return (EFI_OUT_OF_RESOURCES);
     2001  }
     2002
     2003  Walker = *CmdLine;
     2004  while(Walker != NULL && *Walker != CHAR_NULL) {
     2005    LastWalker = Walker;
     2006    if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine)))) {
     2007      if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {
     2008        LastWalker[0] = L' ';
     2009        LastWalker[1] = L' ';
     2010        NewCommandLine = AllocateZeroPool(StrSize(L"help ") + StrSize(*CmdLine));
     2011        if (NewCommandLine == NULL) {
     2012          Status = EFI_OUT_OF_RESOURCES;
     2013          break;
     2014        }
     2015
     2016        //
     2017        // We know the space is sufficient since we just calculated it.
     2018        //
     2019        StrnCpy(NewCommandLine, L"help ", 5);
     2020        StrnCat(NewCommandLine, *CmdLine, StrLen(*CmdLine));
     2021        SHELL_FREE_NON_NULL(*CmdLine);
     2022        *CmdLine = NewCommandLine;
     2023        break;
     2024      }
     2025    }
     2026  }
     2027
     2028  SHELL_FREE_NON_NULL(CurrentParameter);
     2029
     2030  return (Status);
     2031}
     2032
     2033/**
     2034  Function to update the shell variable "lasterror".
     2035
     2036  @param[in] ErrorCode      the error code to put into lasterror.
     2037**/
     2038EFI_STATUS
     2039EFIAPI
     2040SetLastError(
     2041  IN CONST SHELL_STATUS   ErrorCode
     2042  )
     2043{
     2044  CHAR16 LeString[19];
     2045  if (sizeof(EFI_STATUS) == sizeof(UINT64)) {
     2046    UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ErrorCode);
     2047  } else {
     2048    UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ErrorCode);
     2049  }
     2050  DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););
     2051  InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
     2052
     2053  return (EFI_SUCCESS);
     2054}
     2055
     2056/**
     2057  Converts the command line to it's post-processed form.  this replaces variables and alias' per UEFI Shell spec.
     2058
     2059  @param[in,out] CmdLine        pointer to the command line to update
     2060
     2061  @retval EFI_SUCCESS           The operation was successful
     2062  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.
     2063  @return                       some other error occured
     2064**/
     2065EFI_STATUS
     2066EFIAPI
     2067ProcessCommandLineToFinal(
     2068  IN OUT CHAR16 **CmdLine
     2069  )
     2070{
     2071  EFI_STATUS                Status;
     2072  TrimSpaces(CmdLine);
     2073
     2074  Status = ShellSubstituteAliases(CmdLine);
     2075  if (EFI_ERROR(Status)) {
     2076    return (Status);
     2077  }
     2078
     2079  TrimSpaces(CmdLine);
     2080
     2081  Status = ShellSubstituteVariables(CmdLine);
     2082  if (EFI_ERROR(Status)) {
     2083    return (Status);
     2084  }
     2085  ASSERT (*CmdLine != NULL);
     2086
     2087  TrimSpaces(CmdLine);
     2088
     2089  //
     2090  // update for help parsing
     2091  //
     2092  if (StrStr(*CmdLine, L"?") != NULL) {
     2093    //
     2094    // This may do nothing if the ? does not indicate help.
     2095    // Save all the details for in the API below.
     2096    //
     2097    Status = DoHelpUpdate(CmdLine);
     2098  }
     2099
     2100  TrimSpaces(CmdLine);
     2101
     2102  return (EFI_SUCCESS);
     2103}
     2104
     2105/**
     2106  Run an internal shell command.
     2107
     2108  This API will upadate the shell's environment since these commands are libraries.
     2109 
     2110  @param[in] CmdLine          the command line to run.
     2111  @param[in] FirstParameter   the first parameter on the command line
     2112  @param[in] ParamProtocol    the shell parameters protocol pointer
    12982113
    12992114  @retval EFI_SUCCESS     The command was completed.
     
    13022117EFI_STATUS
    13032118EFIAPI
    1304 RunCommand(
    1305   IN CONST CHAR16   *CmdLine
    1306   )
     2119RunInternalCommand(
     2120  IN CONST CHAR16                   *CmdLine,
     2121  IN       CHAR16                   *FirstParameter,
     2122  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol
     2123)
    13072124{
    13082125  EFI_STATUS                Status;
    1309   CHAR16                    *CommandName;
    1310   SHELL_STATUS              ShellStatus;
    13112126  UINTN                     Argc;
    13122127  CHAR16                    **Argv;
     2128  SHELL_STATUS              CommandReturnedStatus;
    13132129  BOOLEAN                   LastError;
    1314   CHAR16                    LeString[11];
    1315   CHAR16                    *PostAliasCmdLine;
    1316   UINTN                     PostAliasSize;
    1317   CHAR16                    *PostVariableCmdLine;
     2130  CHAR16                    *Walker;
     2131  CHAR16                    *NewCmdLine; 
     2132
     2133  NewCmdLine = AllocateCopyPool (StrSize (CmdLine), CmdLine);
     2134  if (NewCmdLine == NULL) {
     2135    return EFI_OUT_OF_RESOURCES;
     2136  }
     2137
     2138  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
     2139    if (*Walker == L'^' && *(Walker+1) == L'#') {
     2140      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
     2141    }
     2142  }
     2143
     2144  //
     2145  // get the argc and argv updated for internal commands
     2146  //
     2147  Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, &Argv, &Argc);
     2148  if (!EFI_ERROR(Status)) {
     2149    //
     2150    // Run the internal command.
     2151    //
     2152    Status = ShellCommandRunCommandHandler(FirstParameter, &CommandReturnedStatus, &LastError);
     2153
     2154    if (!EFI_ERROR(Status)) {
     2155      //
     2156      // Update last error status.
     2157      // some commands do not update last error.
     2158      //
     2159      if (LastError) {
     2160        SetLastError(CommandReturnedStatus);
     2161      }
     2162
     2163      //
     2164      // Pass thru the exitcode from the app.
     2165      //
     2166      if (ShellCommandGetExit()) {
     2167        //
     2168        // An Exit was requested ("exit" command), pass its value up.
     2169        //
     2170        Status = CommandReturnedStatus;
     2171      } else if (CommandReturnedStatus != SHELL_SUCCESS && IsScriptOnlyCommand(FirstParameter)) {
     2172        //
     2173        // Always abort when a script only command fails for any reason
     2174        //
     2175        Status = EFI_ABORTED;
     2176      } else if (ShellCommandGetCurrentScriptFile() != NULL && CommandReturnedStatus == SHELL_ABORTED) {
     2177        //
     2178        // Abort when in a script and a command aborted
     2179        //
     2180        Status = EFI_ABORTED;
     2181      }
     2182    }
     2183  }
     2184
     2185  //
     2186  // This is guarenteed to be called after UpdateArgcArgv no matter what else happened.
     2187  // This is safe even if the update API failed.  In this case, it may be a no-op.
     2188  //
     2189  RestoreArgcArgv(ParamProtocol, &Argv, &Argc);
     2190
     2191  //
     2192  // If a script is running and the command is not a scipt only command, then
     2193  // change return value to success so the script won't halt (unless aborted).
     2194  //
     2195  // Script only commands have to be able halt the script since the script will
     2196  // not operate if they are failing.
     2197  //
     2198  if ( ShellCommandGetCurrentScriptFile() != NULL
     2199    && !IsScriptOnlyCommand(FirstParameter)
     2200    && Status != EFI_ABORTED
     2201    ) {
     2202    Status = EFI_SUCCESS;
     2203  }
     2204
     2205  FreePool (NewCmdLine);
     2206  return (Status);
     2207}
     2208
     2209/**
     2210  Function to run the command or file.
     2211
     2212  @param[in] Type             the type of operation being run.
     2213  @param[in] CmdLine          the command line to run.
     2214  @param[in] FirstParameter   the first parameter on the command line
     2215  @param[in] ParamProtocol    the shell parameters protocol pointer
     2216
     2217  @retval EFI_SUCCESS     The command was completed.
     2218  @retval EFI_ABORTED     The command's operation was aborted.
     2219**/
     2220EFI_STATUS
     2221EFIAPI
     2222RunCommandOrFile(
     2223  IN       SHELL_OPERATION_TYPES    Type,
     2224  IN CONST CHAR16                   *CmdLine,
     2225  IN       CHAR16                   *FirstParameter,
     2226  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol
     2227)
     2228{
     2229  EFI_STATUS                Status;
     2230  EFI_STATUS                StartStatus;
    13182231  CHAR16                    *CommandWithPath;
    1319   CONST EFI_DEVICE_PATH_PROTOCOL  *DevPath;
    1320   CONST CHAR16              *TempLocation;
    1321   CONST CHAR16              *TempLocation2;
     2232  EFI_DEVICE_PATH_PROTOCOL  *DevPath;
     2233  SHELL_STATUS              CalleeExitStatus;
     2234
     2235  Status            = EFI_SUCCESS;
     2236  CommandWithPath   = NULL;
     2237  DevPath           = NULL;
     2238  CalleeExitStatus  = SHELL_INVALID_PARAMETER;
     2239
     2240  switch (Type) {
     2241    case   Internal_Command:
     2242      Status = RunInternalCommand(CmdLine, FirstParameter, ParamProtocol);
     2243      break;
     2244    case   Script_File_Name:
     2245    case   Efi_Application:
     2246      //
     2247      // Process a fully qualified path
     2248      //
     2249      if (StrStr(FirstParameter, L":") != NULL) {
     2250        ASSERT (CommandWithPath == NULL);
     2251        if (ShellIsFile(FirstParameter) == EFI_SUCCESS) {
     2252          CommandWithPath = StrnCatGrow(&CommandWithPath, NULL, FirstParameter, 0);
     2253        }
     2254      }
     2255
     2256      //
     2257      // Process a relative path and also check in the path environment variable
     2258      //
     2259      if (CommandWithPath == NULL) {
     2260        CommandWithPath = ShellFindFilePathEx(FirstParameter, mExecutableExtensions);
     2261      }
     2262
     2263      //
     2264      // This should be impossible now.
     2265      //
     2266      ASSERT(CommandWithPath != NULL);
     2267
     2268      //
     2269      // Make sure that path is not just a directory (or not found)
     2270      //
     2271      if (!EFI_ERROR(ShellIsDirectory(CommandWithPath))) {
     2272        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
     2273        SetLastError(SHELL_NOT_FOUND);
     2274      }
     2275      switch (Type) {
     2276        case   Script_File_Name:
     2277          Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);
     2278          break;
     2279        case   Efi_Application:
     2280          //
     2281          // Get the device path of the application image
     2282          //
     2283          DevPath = ShellInfoObject.NewEfiShellProtocol->GetDevicePathFromFilePath(CommandWithPath);
     2284          if (DevPath == NULL){
     2285            Status = EFI_OUT_OF_RESOURCES;
     2286            break;
     2287          }
     2288
     2289          //
     2290          // Execute the device path
     2291          //
     2292          Status = InternalShellExecuteDevicePath(
     2293            &gImageHandle,
     2294            DevPath,
     2295            CmdLine,
     2296            NULL,
     2297            &StartStatus
     2298           );
     2299
     2300          SHELL_FREE_NON_NULL(DevPath);
     2301
     2302          if(EFI_ERROR (Status)) {
     2303            CalleeExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
     2304          } else {
     2305            CalleeExitStatus = (SHELL_STATUS) StartStatus;
     2306          }
     2307
     2308          //
     2309          // Update last error status.
     2310          //
     2311          // Status is an EFI_STATUS. Clear top bit to convert to SHELL_STATUS
     2312          SetLastError(CalleeExitStatus);
     2313          break;
     2314        default:
     2315          //
     2316          // Do nothing.
     2317          //
     2318          break;
     2319      }
     2320      break;
     2321    default:
     2322      //
     2323      // Do nothing.
     2324      //
     2325      break;
     2326  }
     2327
     2328  SHELL_FREE_NON_NULL(CommandWithPath);
     2329
     2330  return (Status);
     2331}
     2332
     2333/**
     2334  Function to setup StdIn, StdErr, StdOut, and then run the command or file.
     2335
     2336  @param[in] Type             the type of operation being run.
     2337  @param[in] CmdLine          the command line to run.
     2338  @param[in] FirstParameter   the first parameter on the command line.
     2339  @param[in] ParamProtocol    the shell parameters protocol pointer
     2340
     2341  @retval EFI_SUCCESS     The command was completed.
     2342  @retval EFI_ABORTED     The command's operation was aborted.
     2343**/
     2344EFI_STATUS
     2345EFIAPI
     2346SetupAndRunCommandOrFile(
     2347  IN SHELL_OPERATION_TYPES          Type,
     2348  IN CHAR16                         *CmdLine,
     2349  IN CHAR16                         *FirstParameter,
     2350  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol
     2351)
     2352{
     2353  EFI_STATUS                Status;
    13222354  SHELL_FILE_HANDLE         OriginalStdIn;
    13232355  SHELL_FILE_HANDLE         OriginalStdOut;
    13242356  SHELL_FILE_HANDLE         OriginalStdErr;
    13252357  SYSTEM_TABLE_INFO         OriginalSystemTableInfo;
    1326   CHAR16                    *TempLocation3;
    1327   UINTN                     Count;
    1328   UINTN                     Count2;
     2358
     2359  //
     2360  // Update the StdIn, StdOut, and StdErr for redirection to environment variables, files, etc... unicode and ASCII
     2361  //
     2362  Status = UpdateStdInStdOutStdErr(ParamProtocol, CmdLine, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);
     2363
     2364  //
     2365  // The StdIn, StdOut, and StdErr are set up.
     2366  // Now run the command, script, or application
     2367  //
     2368  if (!EFI_ERROR(Status)) {
     2369    TrimSpaces(&CmdLine);
     2370    Status = RunCommandOrFile(Type, CmdLine, FirstParameter, ParamProtocol);
     2371  }
     2372
     2373  //
     2374  // Now print errors
     2375  //
     2376  if (EFI_ERROR(Status)) {
     2377    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR), ShellInfoObject.HiiHandle, (VOID*)(Status));
     2378  }
     2379
     2380  //
     2381  // put back the original StdIn, StdOut, and StdErr
     2382  //
     2383  RestoreStdInStdOutStdErr(ParamProtocol, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);
     2384
     2385  return (Status);
     2386}
     2387
     2388/**
     2389  Function will process and run a command line.
     2390
     2391  This will determine if the command line represents an internal shell
     2392  command or dispatch an external application.
     2393
     2394  @param[in] CmdLine      The command line to parse.
     2395
     2396  @retval EFI_SUCCESS     The command was completed.
     2397  @retval EFI_ABORTED     The command's operation was aborted.
     2398**/
     2399EFI_STATUS
     2400EFIAPI
     2401RunCommand(
     2402  IN CONST CHAR16   *CmdLine
     2403  )
     2404{
     2405  EFI_STATUS                Status;
    13292406  CHAR16                    *CleanOriginal;
    1330   SPLIT_LIST                *Split;
     2407  CHAR16                    *FirstParameter;
     2408  CHAR16                    *TempWalker;
     2409  SHELL_OPERATION_TYPES     Type;
    13312410
    13322411  ASSERT(CmdLine != NULL);
     
    13352414  }
    13362415
    1337   CommandName         = NULL;
    1338   PostVariableCmdLine = NULL;
    1339   PostAliasCmdLine    = NULL;
    1340   CommandWithPath     = NULL;
    1341   DevPath             = NULL;
    13422416  Status              = EFI_SUCCESS;
    13432417  CleanOriginal       = NULL;
    1344   Split               = NULL;
    13452418
    13462419  CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);
     
    13482421    return (EFI_OUT_OF_RESOURCES);
    13492422  }
    1350   while (CleanOriginal[StrLen(CleanOriginal)-1] == L' ') {
    1351     CleanOriginal[StrLen(CleanOriginal)-1] = CHAR_NULL;
    1352   }
    1353   while (CleanOriginal[0] == L' ') {
    1354     CopyMem(CleanOriginal, CleanOriginal+1, StrSize(CleanOriginal) - sizeof(CleanOriginal[0]));
    1355   }
    1356 
    1357   CommandName = NULL;
    1358   if (StrStr(CleanOriginal, L" ") == NULL){
    1359     StrnCatGrow(&CommandName, NULL, CleanOriginal, 0);
     2423
     2424  TrimSpaces(&CleanOriginal);
     2425
     2426  //
     2427  // NULL out comments (leveraged from RunScriptFileHandle() ).
     2428  // The # character on a line is used to denote that all characters on the same line
     2429  // and to the right of the # are to be ignored by the shell.
     2430  // Afterward, again remove spaces, in case any were between the last command-parameter and '#'.
     2431  //
     2432  for (TempWalker = CleanOriginal; TempWalker != NULL && *TempWalker != CHAR_NULL; TempWalker++) {
     2433    if (*TempWalker == L'^') {
     2434      if (*(TempWalker + 1) == L'#') {
     2435        TempWalker++;
     2436      }
     2437    } else if (*TempWalker == L'#') {
     2438      *TempWalker = CHAR_NULL;
     2439    }
     2440  }
     2441
     2442  TrimSpaces(&CleanOriginal);
     2443
     2444  //
     2445  // Handle case that passed in command line is just 1 or more " " characters.
     2446  //
     2447  if (StrLen (CleanOriginal) == 0) {
     2448    SHELL_FREE_NON_NULL(CleanOriginal);
     2449    return (EFI_SUCCESS);
     2450  }
     2451
     2452  Status = ProcessCommandLineToFinal(&CleanOriginal);
     2453  if (EFI_ERROR(Status)) {
     2454    SHELL_FREE_NON_NULL(CleanOriginal);
     2455    return (Status);
     2456  }
     2457
     2458  //
     2459  // We dont do normal processing with a split command line (output from one command input to another)
     2460  //
     2461  if (ContainsSplit(CleanOriginal)) {
     2462    Status = ProcessNewSplitCommandLine(CleanOriginal);
     2463    SHELL_FREE_NON_NULL(CleanOriginal);
     2464    return (Status);
     2465  }
     2466
     2467  //
     2468  // We need the first parameter information so we can determine the operation type
     2469  //
     2470  FirstParameter = AllocateZeroPool(StrSize(CleanOriginal));
     2471  if (FirstParameter == NULL) {
     2472    SHELL_FREE_NON_NULL(CleanOriginal);
     2473    return (EFI_OUT_OF_RESOURCES);
     2474  }
     2475  TempWalker = CleanOriginal;
     2476  if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal)))) {
     2477    //
     2478    // Depending on the first parameter we change the behavior
     2479    //
     2480    switch (Type = GetOperationType(FirstParameter)) {
     2481      case   File_Sys_Change:
     2482        Status = ChangeMappedDrive (FirstParameter);
     2483        break;
     2484      case   Internal_Command:
     2485      case   Script_File_Name:
     2486      case   Efi_Application:
     2487        Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);
     2488        break;
     2489      default:
     2490        //
     2491        // Whatever was typed, it was invalid.
     2492        //
     2493        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
     2494        SetLastError(SHELL_NOT_FOUND);
     2495        break;
     2496    }
    13602497  } else {
    1361     StrnCatGrow(&CommandName, NULL, CleanOriginal, StrStr(CleanOriginal, L" ") - CleanOriginal);
    1362   }
    1363 
    1364   ASSERT(PostAliasCmdLine == NULL);
    1365   if (!ShellCommandIsCommandOnList(CommandName)) {
    1366     //
    1367     // Convert via alias
    1368     //
    1369     Status = ShellConvertAlias(&CommandName);
    1370     PostAliasSize = 0;
    1371     PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, &PostAliasSize, CommandName, 0);
    1372     PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, &PostAliasSize, StrStr(CleanOriginal, L" "), 0);
    1373     ASSERT_EFI_ERROR(Status);
    1374   } else {
    1375     PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, NULL, CleanOriginal, 0);
    1376   }
    1377 
    1378   if (CleanOriginal != NULL) {
    1379     FreePool(CleanOriginal);
    1380     CleanOriginal = NULL;
    1381   }
    1382 
    1383   if (CommandName != NULL) {
    1384     FreePool(CommandName);
    1385     CommandName = NULL;
    1386   }
    1387 
    1388   PostVariableCmdLine = ShellConvertVariables(PostAliasCmdLine);
    1389 
    1390   //
    1391   // we can now free the modified by alias command line
    1392   //
    1393   if (PostAliasCmdLine != NULL) {
    1394     FreePool(PostAliasCmdLine);
    1395     PostAliasCmdLine = NULL;
    1396   }
    1397 
    1398   if (PostVariableCmdLine == NULL) {
    1399     return (EFI_OUT_OF_RESOURCES);
    1400   }
    1401 
    1402   while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {
    1403     PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;
    1404   }
    1405   while (PostVariableCmdLine[0] == L' ') {
    1406     CopyMem(PostVariableCmdLine, PostVariableCmdLine+1, StrSize(PostVariableCmdLine) - sizeof(PostVariableCmdLine[0]));
    1407   }
    1408 
    1409   //
    1410   // We dont do normal processing with a split command line (output from one command input to another)
    1411   //
    1412   TempLocation3 = NULL;
    1413   if (StrStr(PostVariableCmdLine, L"|") != NULL) {
    1414     for (TempLocation3 = PostVariableCmdLine ; TempLocation3 != NULL && *TempLocation3 != CHAR_NULL ; TempLocation3++) {
    1415       if (*TempLocation3 == L'^' && *(TempLocation3+1) == L'|') {
    1416         TempLocation3++;
    1417       } else if (*TempLocation3 == L'|') {
    1418         break;
    1419       }
    1420     }
    1421   }
    1422   if (TempLocation3 != NULL && *TempLocation3 != CHAR_NULL) {
    1423     //
    1424     // are we in an existing split???
    1425     //
    1426     if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
    1427       Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
    1428     }
    1429 
    1430     if (Split == NULL) {
    1431       Status = RunSplitCommand(PostVariableCmdLine, NULL, NULL);
    1432     } else {
    1433       Status = RunSplitCommand(PostVariableCmdLine, Split->SplitStdIn, Split->SplitStdOut);
    1434     }
    1435   } else {
    1436 
    1437     //
    1438     // If this is a mapped drive change handle that...
    1439     //
    1440     if (PostVariableCmdLine[(StrLen(PostVariableCmdLine)-1)] == L':' && StrStr(PostVariableCmdLine, L" ") == NULL) {
    1441       Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, PostVariableCmdLine);
    1442       if (EFI_ERROR(Status)) {
    1443         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, PostVariableCmdLine);
    1444       }
    1445       FreePool(PostVariableCmdLine);
    1446       return (Status);
    1447     }
    1448 
    1449     ///@todo update this section to divide into 3 ways - run internal command, run split (above), and run an external file...
    1450     ///      We waste a lot of time doing processing like StdIn,StdOut,Argv,Argc for things that are external files...
    1451 
    1452 
    1453 
    1454     Status = UpdateStdInStdOutStdErr(ShellInfoObject.NewShellParametersProtocol, PostVariableCmdLine, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);
    1455     if (EFI_ERROR(Status)) {
    1456       if (Status == EFI_NOT_FOUND) {
    1457         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);
    1458       } else {
    1459         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
    1460       }
    1461     } else {
    1462       while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') {
    1463         PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL;
    1464       }
    1465       while (PostVariableCmdLine[0] == L' ') {
    1466         CopyMem(PostVariableCmdLine, PostVariableCmdLine+1, StrSize(PostVariableCmdLine) - sizeof(PostVariableCmdLine[0]));
    1467       }
    1468 
    1469       //
    1470       // get the argc and argv updated for internal commands
    1471       //
    1472       Status = UpdateArgcArgv(ShellInfoObject.NewShellParametersProtocol, PostVariableCmdLine, &Argv, &Argc);
    1473       ASSERT_EFI_ERROR(Status);
    1474 
    1475       for (Count = 0 ; Count < ShellInfoObject.NewShellParametersProtocol->Argc ; Count++) {
    1476         if (StrStr(ShellInfoObject.NewShellParametersProtocol->Argv[Count], L"-?") == ShellInfoObject.NewShellParametersProtocol->Argv[Count]
    1477         ||  (ShellInfoObject.NewShellParametersProtocol->Argv[0][0] == L'?' && ShellInfoObject.NewShellParametersProtocol->Argv[0][1] == CHAR_NULL)
    1478           ) {
    1479           //
    1480           // We need to redo the arguments since a parameter was -?
    1481           // move them all down 1 to the end, then up one then replace the first with help
    1482           //
    1483           FreePool(ShellInfoObject.NewShellParametersProtocol->Argv[Count]);
    1484           ShellInfoObject.NewShellParametersProtocol->Argv[Count] = NULL;
    1485           for (Count2 = Count ; (Count2 + 1) < ShellInfoObject.NewShellParametersProtocol->Argc ; Count2++) {
    1486             ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = ShellInfoObject.NewShellParametersProtocol->Argv[Count2+1];
    1487           }
    1488           ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = NULL;
    1489           for (Count2 = ShellInfoObject.NewShellParametersProtocol->Argc -1 ; Count2 > 0 ; Count2--) {
    1490             ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = ShellInfoObject.NewShellParametersProtocol->Argv[Count2-1];
    1491           }
    1492           ShellInfoObject.NewShellParametersProtocol->Argv[0] = NULL;
    1493           ShellInfoObject.NewShellParametersProtocol->Argv[0] = StrnCatGrow(&ShellInfoObject.NewShellParametersProtocol->Argv[0], NULL, L"help", 0);
    1494           break;
    1495         }
    1496       }
    1497 
    1498       //
    1499       // command or file?
    1500       //
    1501       if (ShellCommandIsCommandOnList(ShellInfoObject.NewShellParametersProtocol->Argv[0])) {
    1502         //
    1503         // Run the command (which was converted if it was an alias)
    1504         //
    1505         if (!EFI_ERROR(Status))  {
    1506           Status = ShellCommandRunCommandHandler(ShellInfoObject.NewShellParametersProtocol->Argv[0], &ShellStatus, &LastError);
    1507           ASSERT_EFI_ERROR(Status);
    1508           UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%08x", ShellStatus);
    1509           DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););
    1510           if (LastError) {
    1511             InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
    1512           }
    1513           //
    1514           // Pass thru the exitcode from the app.
    1515           //
    1516           if (ShellCommandGetExit()) {
    1517             Status = ShellStatus;
    1518           } else if (ShellStatus != 0 && IsScriptOnlyCommand(ShellInfoObject.NewShellParametersProtocol->Argv[0])) {
    1519             Status = EFI_ABORTED;
    1520           }
    1521         }
    1522       } else {
    1523         //
    1524         // run an external file (or script)
    1525         //
    1526         if (StrStr(ShellInfoObject.NewShellParametersProtocol->Argv[0], L":") != NULL) {
    1527           ASSERT (CommandWithPath == NULL);
    1528           if (ShellIsFile(ShellInfoObject.NewShellParametersProtocol->Argv[0]) == EFI_SUCCESS) {
    1529             CommandWithPath = StrnCatGrow(&CommandWithPath, NULL, ShellInfoObject.NewShellParametersProtocol->Argv[0], 0);
    1530           }
    1531         }
    1532         if (CommandWithPath == NULL) {
    1533           CommandWithPath = ShellFindFilePathEx(ShellInfoObject.NewShellParametersProtocol->Argv[0], mExecutableExtensions);
    1534         }
    1535         if (CommandWithPath == NULL || ShellIsDirectory(CommandWithPath) == EFI_SUCCESS) {
    1536           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, ShellInfoObject.NewShellParametersProtocol->Argv[0]);
    1537         } else {
    1538           //
    1539           // Check if it's a NSH (script) file.
    1540           //
    1541           TempLocation = CommandWithPath+StrLen(CommandWithPath)-4;
    1542           TempLocation2 = mScriptExtension;
    1543           if ((StrLen(CommandWithPath) > 4) && (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0)) {
    1544             Status = RunScriptFile (CommandWithPath);
    1545           } else {
    1546             DevPath = ShellInfoObject.NewEfiShellProtocol->GetDevicePathFromFilePath(CommandWithPath);
    1547             ASSERT(DevPath != NULL);
    1548             Status = InternalShellExecuteDevicePath(
    1549               &gImageHandle,
    1550               DevPath,
    1551               PostVariableCmdLine,
    1552               NULL,
    1553               NULL
    1554              );
    1555           }
    1556         }
    1557       }
    1558       CommandName = StrnCatGrow(&CommandName, NULL, ShellInfoObject.NewShellParametersProtocol->Argv[0], 0);
    1559 
    1560       RestoreArgcArgv(ShellInfoObject.NewShellParametersProtocol, &Argv, &Argc);
    1561 
    1562       RestoreStdInStdOutStdErr(ShellInfoObject.NewShellParametersProtocol, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);
    1563     }
    1564     if (CommandName != NULL) {
    1565       if (ShellCommandGetCurrentScriptFile() != NULL &&  !IsScriptOnlyCommand(CommandName)) {
    1566         //
    1567         // if this is NOT a scipt only command return success so the script won't quit.
    1568         // prevent killing the script - this is the only place where we know the actual command name (after alias and variable replacement...)
    1569         //
    1570         Status = EFI_SUCCESS;
    1571       }
    1572     }
    1573   }
    1574 
    1575   SHELL_FREE_NON_NULL(CommandName);
    1576   SHELL_FREE_NON_NULL(CommandWithPath);
    1577   SHELL_FREE_NON_NULL(PostVariableCmdLine);
     2498    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
     2499    SetLastError(SHELL_NOT_FOUND);
     2500  }
     2501 
     2502  SHELL_FREE_NON_NULL(CleanOriginal);
     2503  SHELL_FREE_NON_NULL(FirstParameter);
    15782504
    15792505  return (Status);
     
    16922618    CommandLine = ShellFileHandleReturnLine(Handle, &Ascii);
    16932619    LineCount++;
    1694     if (CommandLine == NULL || StrLen(CommandLine) == 0) {
     2620    if (CommandLine == NULL || StrLen(CommandLine) == 0 || CommandLine[0] == '#') {
     2621      SHELL_FREE_NON_NULL(CommandLine);
    16952622      continue;
    16962623    }
    16972624    NewScriptFile->CurrentCommand = AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST));
    16982625    if (NewScriptFile->CurrentCommand == NULL) {
     2626      SHELL_FREE_NON_NULL(CommandLine);
    16992627      DeleteScriptFileStruct(NewScriptFile);
    17002628      return (EFI_OUT_OF_RESOURCES);
     
    17332661  ){
    17342662    ASSERT(CommandLine2 != NULL);
    1735     StrCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl);
     2663    StrnCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
    17362664
    17372665    //
     
    17402668    for (CommandLine3 = CommandLine2 ; CommandLine3 != NULL && *CommandLine3 != CHAR_NULL ; CommandLine3++) {
    17412669      if (*CommandLine3 == L'^') {
    1742         if (*(CommandLine3+1) == L'#' || *(CommandLine3+1) == L':') {
     2670        if ( *(CommandLine3+1) == L':') {
    17432671          CopyMem(CommandLine3, CommandLine3+1, StrSize(CommandLine3) - sizeof(CommandLine3[0]));
     2672        } else if (*(CommandLine3+1) == L'#') {
     2673          CommandLine3++;
    17442674        }
    17452675      } else if (*CommandLine3 == L'#') {
     
    17522682      // Due to variability in starting the find and replace action we need to have both buffers the same.
    17532683      //
    1754       StrCpy(CommandLine, CommandLine2);
     2684      StrnCpy(CommandLine, CommandLine2, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
    17552685
    17562686      //
     
    18042734      Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", L"\"\"", FALSE, FALSE);
    18052735
    1806       StrCpy(CommandLine2, CommandLine);
     2736      StrnCpy(CommandLine2, CommandLine, PcdGet16(PcdShellPrintBufferSize)/sizeof(CHAR16)-1);
    18072737
    18082738      LastCommand = NewScriptFile->CurrentCommand;
     
    18262756
    18272757            //
    1828             // Now restore the pre-'@' echo state.
     2758            // If command was "@echo -off" or "@echo -on" then don't restore echo state
    18292759            //
    1830             ShellCommandSetEchoState(PreCommandEchoState);
     2760            if (StrCmp (L"@echo -off", CommandLine3) != 0 &&
     2761                StrCmp (L"@echo -on", CommandLine3) != 0) {
     2762              //
     2763              // Now restore the pre-'@' echo state.
     2764              //
     2765              ShellCommandSetEchoState(PreCommandEchoState);
     2766            }
    18312767          } else {
    18322768            if (ShellCommandGetEchoState()) {
     
    18442780
    18452781        if (ShellCommandGetScriptExit()) {
    1846           UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%Lx", ShellCommandGetExitCode());
    1847           DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););
    1848           InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
     2782          //
     2783          // ShellCommandGetExitCode() always returns a UINT64
     2784          //
     2785          UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());
     2786          DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););
     2787          InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
    18492788
    18502789          ShellCommandRegisterExit(FALSE, 0);
    18512790          Status = EFI_SUCCESS;
     2791          break;
     2792        }
     2793        if (ShellGetExecutionBreakFlag()) {
    18522794          break;
    18532795        }
     
    18942836
    18952837  @param[in] ScriptPath         Pointer to the script file name (including file system path).
     2838  @param[in] Handle             the handle of the script file already opened.
     2839  @param[in] CmdLine            the command line to run.
     2840  @param[in] ParamProtocol      the shell parameters protocol pointer
    18962841
    18972842  @retval EFI_SUCCESS           the script completed sucessfully
     
    19002845EFIAPI
    19012846RunScriptFile (
    1902   IN CONST CHAR16 *ScriptPath
     2847  IN CONST CHAR16                   *ScriptPath,
     2848  IN SHELL_FILE_HANDLE              Handle OPTIONAL,
     2849  IN CONST CHAR16                   *CmdLine,
     2850  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol
    19032851  )
    19042852{
    19052853  EFI_STATUS          Status;
    19062854  SHELL_FILE_HANDLE   FileHandle;
     2855  UINTN                     Argc;
     2856  CHAR16                    **Argv;
    19072857
    19082858  if (ShellIsFile(ScriptPath) != EFI_SUCCESS) {
     
    19102860  }
    19112861
    1912   Status = ShellOpenFileByName(ScriptPath, &FileHandle, EFI_FILE_MODE_READ, 0);
    1913   if (EFI_ERROR(Status)) {
    1914     return (Status);
    1915   }
    1916 
    1917   Status = RunScriptFileHandle(FileHandle, ScriptPath);
    1918 
    1919   ShellCloseFile(&FileHandle);
     2862  //
     2863  // get the argc and argv updated for scripts
     2864  //
     2865  Status = UpdateArgcArgv(ParamProtocol, CmdLine, &Argv, &Argc);
     2866  if (!EFI_ERROR(Status)) {
     2867
     2868    if (Handle == NULL) {
     2869      //
     2870      // open the file
     2871      //
     2872      Status = ShellOpenFileByName(ScriptPath, &FileHandle, EFI_FILE_MODE_READ, 0);
     2873      if (!EFI_ERROR(Status)) {
     2874        //
     2875        // run it
     2876        //
     2877        Status = RunScriptFileHandle(FileHandle, ScriptPath);
     2878
     2879        //
     2880        // now close the file
     2881        //
     2882        ShellCloseFile(&FileHandle);
     2883      }
     2884    } else {
     2885      Status = RunScriptFileHandle(Handle, ScriptPath);
     2886    }
     2887  }
     2888
     2889  //
     2890  // This is guarenteed to be called after UpdateArgcArgv no matter what else happened.
     2891  // This is safe even if the update API failed.  In this case, it may be a no-op.
     2892  //
     2893  RestoreArgcArgv(ParamProtocol, &Argv, &Argc);
    19202894
    19212895  return (Status);
    19222896}
     2897
     2898/**
     2899  Return the pointer to the first occurance of any character from a list of characters
     2900
     2901  @param[in] String           the string to parse
     2902  @param[in] CharacterList    the list of character to look for
     2903  @param[in] EscapeCharacter  An escape character to skip
     2904
     2905  @return the location of the first character in the string
     2906  @retval CHAR_NULL no instance of any character in CharacterList was found in String
     2907**/
     2908CONST CHAR16*
     2909EFIAPI
     2910FindFirstCharacter(
     2911  IN CONST CHAR16 *String,
     2912  IN CONST CHAR16 *CharacterList,
     2913  IN CONST CHAR16 EscapeCharacter
     2914  )
     2915{
     2916  UINT32 WalkChar;
     2917  UINT32 WalkStr;
     2918
     2919  for (WalkStr = 0; WalkStr < StrLen(String); WalkStr++) {
     2920    if (String[WalkStr] == EscapeCharacter) {
     2921      WalkStr++;
     2922      continue;
     2923    }
     2924    for (WalkChar = 0; WalkChar < StrLen(CharacterList); WalkChar++) {
     2925      if (String[WalkStr] == CharacterList[WalkChar]) {
     2926        return (&String[WalkStr]);
     2927      }
     2928    }
     2929  }
     2930  return (String + StrLen(String));
     2931}
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/Shell.h

    r48674 r58459  
    22  function definitions for internal to shell functions.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  (C) Copyright 2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    2021
    2122#include <Guid/ShellVariableGuid.h>
     23#include <Guid/ShellAliasGuid.h>
    2224
    2325#include <Protocol/LoadedImage.h>
     
    4648#include <Library/HandleParsingLib.h>
    4749#include <Library/PathLib.h>
     50#include <Library/FileHandleLib.h>
    4851
    4952#include "ShellParametersProtocol.h"
     
    5356#include "ShellManParser.h"
    5457#include "ConsoleWrappers.h"
     58#include "FileHandleWrappers.h"
    5559
    5660typedef struct {
     
    6973  UINT32  NoVersion:1;    ///< Was "-noversion"     found on command line.
    7074  UINT32  Delay:1;        ///< Was "-delay[:n]      found on command line
    71   UINT32  Reserved:8;     ///< Extra bits
     75  UINT32  Exit:1;         ///< Was "-_exit"          found on command line
     76  UINT32  Reserved:7;     ///< Extra bits
    7277} SHELL_BITS;
    7378
     
    108113  SHELL_PROTOCOL_HANDLE_LIST    OldShellList;         ///< List of other instances to reinstall when closing.
    109114  SPLIT_LIST                    SplitList;            ///< List of Splits in FILO stack.
    110   EFI_HANDLE                    CtrlCNotifyHandle1;   ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
    111   EFI_HANDLE                    CtrlCNotifyHandle2;   ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
    112   EFI_HANDLE                    CtrlCNotifyHandle3;   ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
    113   EFI_HANDLE                    CtrlCNotifyHandle4;   ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
    114   EFI_HANDLE                    CtrlSNotifyHandle1;   ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
    115   EFI_HANDLE                    CtrlSNotifyHandle2;   ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
    116   EFI_HANDLE                    CtrlSNotifyHandle3;   ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
    117   EFI_HANDLE                    CtrlSNotifyHandle4;   ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
     115  VOID                          *CtrlCNotifyHandle1;  ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
     116  VOID                          *CtrlCNotifyHandle2;  ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
     117  VOID                          *CtrlCNotifyHandle3;  ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
     118  VOID                          *CtrlCNotifyHandle4;  ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
     119  VOID                          *CtrlSNotifyHandle1;  ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
     120  VOID                          *CtrlSNotifyHandle2;  ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
     121  VOID                          *CtrlSNotifyHandle3;  ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
     122  VOID                          *CtrlSNotifyHandle4;  ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.
    118123  BOOLEAN                       HaltOutput;           ///< TRUE to start a CTRL-S halt.
    119124} SHELL_INFO;
    120125
    121126extern SHELL_INFO ShellInfoObject;
     127
     128typedef enum {
     129  Internal_Command,
     130  Script_File_Name,
     131  Efi_Application,
     132  File_Sys_Change,
     133  Unknown_Invalid
     134} SHELL_OPERATION_TYPES;
     135
     136/**
     137  Converts the command line to it's post-processed form.  this replaces variables and alias' per UEFI Shell spec.
     138
     139  @param[in,out] CmdLine        pointer to the command line to update
     140
     141  @retval EFI_SUCCESS           The operation was successful
     142  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.
     143  @return                       some other error occured
     144**/
     145EFI_STATUS
     146EFIAPI
     147ProcessCommandLineToFinal(
     148  IN OUT CHAR16 **CmdLine
     149  );
     150
     151/**
     152  Function to update the shell variable "lasterror".
     153
     154  @param[in] ErrorCode      the error code to put into lasterror
     155**/
     156EFI_STATUS
     157EFIAPI
     158SetLastError(
     159  IN CONST SHELL_STATUS   ErrorCode
     160  );
    122161
    123162/**
     
    290329
    291330  @param[in] ScriptPath         Pointer to the script file name (including file system path).
     331  @param[in] Handle             the handle of the script file already opened.
     332  @param[in] CmdLine            the command line to run.
     333  @param[in] ParamProtocol      the shell parameters protocol pointer
    292334
    293335  @retval EFI_SUCCESS           the script completed sucessfully
     
    296338EFIAPI
    297339RunScriptFile (
    298   IN CONST CHAR16 *ScriptPath
    299   );
    300 
     340  IN CONST CHAR16                   *ScriptPath,
     341  IN SHELL_FILE_HANDLE              Handle OPTIONAL,
     342  IN CONST CHAR16                   *CmdLine,
     343  IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol
     344  );
     345
     346/**
     347  Return the pointer to the first occurance of any character from a list of characters
     348
     349  @param[in] String           the string to parse
     350  @param[in] CharacterList    the list of character to look for
     351  @param[in] EscapeCharacter  An escape character to skip
     352
     353  @return the location of the first character in the string
     354  @retval CHAR_NULL no instance of any character in CharacterList was found in String
     355**/
     356CONST CHAR16*
     357EFIAPI
     358FindFirstCharacter(
     359  IN CONST CHAR16 *String,
     360  IN CONST CHAR16 *CharacterList,
     361  IN CONST CHAR16 EscapeCharacter
     362  );
    301363
    302364#endif //_SHELL_INTERNAL_HEADER_
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/Shell.inf

    r48674 r58459  
    22#  This is the shell application
    33#
    4 #  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4#  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
     5#  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
    56#
    67#  This program and the accompanying materials
     
    7374
    7475[Guids]
    75   gShellVariableGuid                                      # ALWAYS_CONSUMED
    76   gShellMapGuid                                           # ALWAYS_CONSUMED
    77   gShellAliasGuid                                         # ALWAYS_CONSUMED
     76  gShellVariableGuid                                      ## CONSUMES ## GUID
     77  gShellMapGuid                                           ## CONSUMES ## GUID
     78  gShellAliasGuid                                         ## CONSUMES ## GUID
    7879
    7980[Protocols]
    80   gEfiShellProtocolGuid                                   # ALWAYS_PRODUCED
    81                                                           # SOMETIMES_CONSUMED
    82   gEfiShellParametersProtocolGuid                         # ALWAYS_PRODUCED
    83                                                           # SOMETIMES_CONSUMED
     81  gEfiShellProtocolGuid                                   ## PRODUCES
     82                                                          ## SOMETIMES_CONSUMES
     83  gEfiShellParametersProtocolGuid                         ## PRODUCES
     84                                                          ## SOMETIMES_CONSUMES
    8485
    85 #  gEfiShellEnvironment2Guid                               # SOMETIMES_PRODUCED
    86 #  gEfiShellInterfaceGuid                                  # SOMETIMES_PRODUCED
     86#  gEfiShellEnvironment2Guid                              ## SOMETIMES_PRODUCES
     87#  gEfiShellInterfaceGuid                                 ## SOMETIMES_PRODUCES
    8788
    88   gEfiSimpleTextInputExProtocolGuid                       # ALWAYS_CONSUMED
    89   gEfiSimpleTextInProtocolGuid                            # ALWAYS_CONSUMED
    90   gEfiSimpleTextOutProtocolGuid                           # ALWAYS_CONSUMED
    91   gEfiSimpleFileSystemProtocolGuid                        # ALWAYS_CONSUMED
    92   gEfiLoadedImageProtocolGuid                             # ALWAYS_CONSUMED
    93   gEfiComponentName2ProtocolGuid                          # ALWAYS_CONSUMED
    94   gEfiUnicodeCollation2ProtocolGuid                       # ALWAYS_CONSUMED
    95   gEfiDevicePathProtocolGuid                              # ALWAYS_CONSUMED
    96   gEfiDevicePathToTextProtocolGuid                        # ALWAYS_CONSUMED
     89  gEfiSimpleTextInputExProtocolGuid                       ## CONSUMES
     90  gEfiSimpleTextInProtocolGuid                            ## CONSUMES
     91  gEfiSimpleTextOutProtocolGuid                           ## CONSUMES
     92  gEfiSimpleFileSystemProtocolGuid                        ## CONSUMES
     93  gEfiLoadedImageProtocolGuid                             ## CONSUMES
     94  gEfiComponentName2ProtocolGuid                          ## CONSUMES
     95  gEfiUnicodeCollation2ProtocolGuid                       ## CONSUMES
     96  gEfiDevicePathProtocolGuid                              ## CONSUMES
    9797
    9898[Pcd]
    99   gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel         # ALWAYS_CONSUMED
    100   gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols  # ALWAYS_CONSUMED
    101   gEfiShellPkgTokenSpaceGuid.PcdShellRequireHiiPlatform   # ALWAYS_CONSUMED
    102   gEfiShellPkgTokenSpaceGuid.PcdShellSupportFrameworkHii  # ALWAYS_CONSUMED
    103   gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault     # ALWAYS_CONSUMED
    104   gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize    # ALWAYS_CONSUMED
    105   gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault    # ALWAYS_CONSUMED
    106   gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount       # ALWAYS_CONSUMED
    107   gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength        # ALWAYS_CONSUMED
    108   gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize      # ALWAYS_CONSUMED
    109   gEfiShellPkgTokenSpaceGuid.PcdShellForceConsole         # ALWAYS_CONSUMED
     99  gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel         ## CONSUMES
     100  gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols  ## CONSUMES
     101  gEfiShellPkgTokenSpaceGuid.PcdShellRequireHiiPlatform   ## CONSUMES
     102  gEfiShellPkgTokenSpaceGuid.PcdShellSupportFrameworkHii  ## CONSUMES
     103  gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault     ## CONSUMES
     104  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize    ## CONSUMES
     105  gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault    ## CONSUMES
     106  gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount       ## CONSUMES
     107  gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength        ## CONSUMES
     108  gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize      ## CONSUMES
     109  gEfiShellPkgTokenSpaceGuid.PcdShellForceConsole         ## CONSUMES
     110  gEfiShellPkgTokenSpaceGuid.PcdShellSupplier             ## CONSUMES
    110111
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ShellEnvVar.c

    r48674 r58459  
    22  function declarations for shell environment functions.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1313**/
    1414
    15 #include <Uefi.h>
    16 #include <ShellBase.h>
    17 
    18 #include <Guid/ShellVariableGuid.h>
    19 
    20 #include <Library/BaseLib.h>
    21 #include <Library/UefiRuntimeServicesTableLib.h>
    22 #include <Library/MemoryAllocationLib.h>
    23 #include <Library/DebugLib.h>
    24 #include <Library/BaseMemoryLib.h>
    25 
    26 #include "ShellEnvVar.h"
     15#include "Shell.h"
     16
     17#define INIT_NAME_BUFFER_SIZE  128
     18#define INIT_DATA_BUFFER_SIZE  1024
    2719
    2820/**
     
    10698
    10799  for ( Node = (ENV_VAR_LIST*)GetFirstNode(List)
    108       ; IsListEmpty(List)
     100      ; !IsListEmpty(List)
    109101      ; Node = (ENV_VAR_LIST*)GetFirstNode(List)
    110102     ){
     
    137129  CHAR16            *VariableName;
    138130  UINTN             NameSize;
    139   UINT64            MaxStorSize;
    140   UINT64            RemStorSize;
    141   UINT64            MaxVarSize;
     131  UINTN             NameBufferSize;
    142132  EFI_STATUS        Status;
    143133  EFI_GUID          Guid;
    144134  UINTN             ValSize;
     135  UINTN             ValBufferSize;
    145136  ENV_VAR_LIST      *VarList;
    146137
     
    148139    return (EFI_INVALID_PARAMETER);
    149140  }
    150 
    151   if (gRT->Hdr.Revision >= EFI_2_00_SYSTEM_TABLE_REVISION) {
    152     Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);
    153     if (EFI_ERROR(Status)) {
    154       return (Status);
    155     }
    156   } else {
    157     Status = EFI_SUCCESS;
    158     MaxVarSize = 16384;
    159   }
    160 
    161   NameSize = (UINTN)MaxVarSize;
    162   VariableName = AllocateZeroPool(NameSize);
     141 
     142  Status = EFI_SUCCESS;
     143 
     144  ValBufferSize = INIT_DATA_BUFFER_SIZE;
     145  NameBufferSize = INIT_NAME_BUFFER_SIZE;
     146  VariableName = AllocateZeroPool(NameBufferSize);
    163147  if (VariableName == NULL) {
    164148    return (EFI_OUT_OF_RESOURCES);
    165149  }
    166   StrCpy(VariableName, L"");
     150  *VariableName = CHAR_NULL;
    167151
    168152  while (!EFI_ERROR(Status)) {
    169     NameSize = (UINTN)MaxVarSize;
     153    NameSize = NameBufferSize;
    170154    Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);
    171155    if (Status == EFI_NOT_FOUND){
    172156      Status = EFI_SUCCESS;
    173157      break;
    174     }
     158    } else if (Status == EFI_BUFFER_TOO_SMALL) {
     159      NameBufferSize = NameSize > NameBufferSize * 2 ? NameSize : NameBufferSize * 2;
     160      SHELL_FREE_NON_NULL(VariableName);
     161      VariableName = AllocateZeroPool(NameBufferSize);
     162      if (VariableName == NULL) {
     163        Status = EFI_OUT_OF_RESOURCES;
     164        break;
     165      }
     166      NameSize = NameBufferSize;
     167      Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);
     168    }
     169   
    175170    if (!EFI_ERROR(Status) && CompareGuid(&Guid, &gShellVariableGuid)){
    176171      VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
     
    178173        Status = EFI_OUT_OF_RESOURCES;
    179174      } else {
    180         ValSize = 0;
     175        ValSize = ValBufferSize;
     176        VarList->Val = AllocateZeroPool(ValSize);
     177        if (VarList->Val == NULL) {
     178            SHELL_FREE_NON_NULL(VarList);
     179            Status = EFI_OUT_OF_RESOURCES;
     180            break;
     181        }
    181182        Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
    182183        if (Status == EFI_BUFFER_TOO_SMALL){
    183           VarList->Val = AllocateZeroPool(ValSize);
     184          ValBufferSize = ValSize > ValBufferSize * 2 ? ValSize : ValBufferSize * 2;
     185          SHELL_FREE_NON_NULL (VarList->Val);
     186          VarList->Val = AllocateZeroPool(ValBufferSize);
    184187          if (VarList->Val == NULL) {
    185188            SHELL_FREE_NON_NULL(VarList);
    186189            Status = EFI_OUT_OF_RESOURCES;
    187           } else {
    188             Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
     190            break;
    189191          }
     192         
     193          ValSize = ValBufferSize;
     194          Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(VariableName, &VarList->Atts, &ValSize, VarList->Val);
    190195        }
    191         if (!EFI_ERROR(Status) && VarList != NULL) {
    192           VarList->Key = AllocateZeroPool(StrSize(VariableName));
     196        if (!EFI_ERROR(Status)) {
     197          VarList->Key = AllocateCopyPool(StrSize(VariableName), VariableName);
    193198          if (VarList->Key == NULL) {
    194199            SHELL_FREE_NON_NULL(VarList->Val);
     
    196201            Status = EFI_OUT_OF_RESOURCES;
    197202          } else {
    198             StrCpy(VarList->Key, VariableName);
    199203            InsertTailList(ListHead, &VarList->Link);
    200204          }
     205        } else {
     206          SHELL_FREE_NON_NULL(VarList->Val);
     207          SHELL_FREE_NON_NULL(VarList);
    201208        }
    202       }
     209      } // if (VarList == NULL) ... else ...
    203210    } // compare guid
    204211  } // while
    205   FreePool(VariableName);
     212  SHELL_FREE_NON_NULL (VariableName);
    206213
    207214  if (EFI_ERROR(Status)) {
     
    298305  ENV_VAR_LIST  *VarList;
    299306  ENV_VAR_LIST  *Node;
    300   UINTN         NewSize;
    301307
    302308  VarList = NULL;
     
    319325    ASSERT(StrStr(CurrentString, L"=") != NULL);
    320326    Node = AllocateZeroPool(sizeof(ENV_VAR_LIST));
    321     ASSERT(Node != NULL);
     327    if (Node == NULL) {
     328      SetEnvironmentVariableList(&VarList->Link);
     329      return (EFI_OUT_OF_RESOURCES);
     330    }
     331
    322332    Node->Key = AllocateZeroPool((StrStr(CurrentString, L"=") - CurrentString + 1) * sizeof(CHAR16));
    323     ASSERT(Node->Key != NULL);
     333    if (Node->Key == NULL) {
     334      SHELL_FREE_NON_NULL(Node);
     335      SetEnvironmentVariableList(&VarList->Link);
     336      return (EFI_OUT_OF_RESOURCES);
     337    }
     338
     339    //
     340    // Copy the string into the Key, leaving the last character allocated as NULL to terminate
     341    //
    324342    StrnCpy(Node->Key, CurrentString, StrStr(CurrentString, L"=") - CurrentString);
    325     NewSize = StrSize(CurrentString);
    326     NewSize -= StrLen(Node->Key) - 1;
    327     Node->Val = AllocateZeroPool(NewSize);
    328     ASSERT(Node->Val != NULL);
    329     StrCpy(Node->Val, CurrentString + StrLen(Node->Key) + 1);
     343
     344    //
     345    // ValueSize = TotalSize - already removed size - size for '=' + size for terminator (the last 2 items cancel each other)
     346    //
     347    Node->Val = AllocateCopyPool(StrSize(CurrentString) - StrSize(Node->Key), CurrentString + StrLen(Node->Key) + 1);
     348    if (Node->Val == NULL) {
     349      SHELL_FREE_NON_NULL(Node->Key);
     350      SHELL_FREE_NON_NULL(Node);
     351      SetEnvironmentVariableList(&VarList->Link);
     352      return (EFI_OUT_OF_RESOURCES);
     353    }
     354
    330355    Node->Atts = EFI_VARIABLE_BOOTSERVICE_ACCESS;
    331356
    332357    if (VarList == NULL) {
    333358      VarList = AllocateZeroPool(sizeof(ENV_VAR_LIST));
    334       ASSERT(VarList != NULL);
     359      if (VarList == NULL) {
     360        SHELL_FREE_NON_NULL(Node->Key);
     361        SHELL_FREE_NON_NULL(Node->Val);
     362        SHELL_FREE_NON_NULL(Node);
     363        return (EFI_OUT_OF_RESOURCES);
     364      }
    335365      InitializeListHead(&VarList->Link);
    336366    }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ShellManParser.c

    r48674 r58459  
    22  Provides interface to shell MAN file parser.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    4040  //
    4141  if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) {
    42     Buffer = AllocateZeroPool(StrSize(ManFileName));
    43     if (Buffer != NULL) {
    44       StrCpy(Buffer, ManFileName);
    45     }
     42    Buffer = AllocateCopyPool(StrSize(ManFileName), ManFileName);
    4643  } else {
    4744    Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));
    4845    if (Buffer != NULL) {
    49       StrCpy(Buffer, ManFileName);
    50       StrCat(Buffer, L".man");
     46      StrnCpy(Buffer, ManFileName, StrLen(ManFileName));
     47      StrnCat(Buffer, L".man", 4);
    5148    }
    5249  }
     
    375372  CHAR16        *TitleEnd;
    376373  CHAR16        *CurrentLocation;
     374  UINTN         TitleLength;
     375  CONST CHAR16  StartString[] = L".TH ";
     376  CONST CHAR16  EndString[]   = L" 0 ";
    377377
    378378  if ( Buffer     == NULL
     
    385385  Status    = EFI_SUCCESS;
    386386
    387   TitleString = AllocateZeroPool((7*sizeof(CHAR16)) + StrSize(Command));
     387  //
     388  // more characters for StartString and EndString
     389  //
     390  TitleLength = StrSize(Command) + (StrLen(StartString) + StrLen(EndString)) * sizeof(CHAR16);
     391  TitleString = AllocateZeroPool(TitleLength);
    388392  if (TitleString == NULL) {
    389393    return (EFI_OUT_OF_RESOURCES);
    390394  }
    391   StrCpy(TitleString, L".TH ");
    392   StrCat(TitleString, Command);
    393   StrCat(TitleString, L" 0 ");
     395  StrnCpy(TitleString, StartString, TitleLength/sizeof(CHAR16) - 1);
     396  StrnCat(TitleString, Command,     TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString));
     397  StrnCat(TitleString, EndString,   TitleLength/sizeof(CHAR16) - 1 - StrLen(TitleString));
    394398
    395399  CurrentLocation = StrStr(*Buffer, TitleString);
     
    468472  UINTN       TitleLen;
    469473  BOOLEAN     Found;
     474  UINTN       TitleSize;
    470475
    471476  if ( Handle     == NULL
     
    485490  }
    486491
    487   TitleString = AllocateZeroPool((4*sizeof(CHAR16)) + StrSize(Command));
     492  TitleSize = (4*sizeof(CHAR16)) + StrSize(Command);
     493  TitleString = AllocateZeroPool(TitleSize);
    488494  if (TitleString == NULL) {
    489495    FreePool(ReadLine);
    490496    return (EFI_OUT_OF_RESOURCES);
    491497  }
    492   StrCpy(TitleString, L".TH ");
    493   StrCat(TitleString, Command);
     498  StrnCpy(TitleString, L".TH ", TitleSize/sizeof(CHAR16) - 1);
     499  StrnCat(TitleString, Command, TitleSize/sizeof(CHAR16) - 1 - StrLen(TitleString));
     500
    494501  TitleLen = StrLen(TitleString);
    495502  for (;!ShellFileHandleEof(Handle);Size = 1024) {
     
    526533          break;
    527534        }
    528         StrCpy(*BriefDesc, TitleEnd);
     535        StrnCpy(*BriefDesc, TitleEnd, (*BriefSize)/sizeof(CHAR16) - 1);
    529536      }
    530537      break;
     
    599606  BriefSize   = 0;
    600607  TempString  = NULL;
     608  Ascii       = FALSE;
    601609  //
    602610  // See if it's in HII first
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ShellParametersProtocol.c

    r48674 r58459  
    33  manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
    44
    5   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     5  Copyright (C) 2014, Red Hat, Inc.
     6  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
     7  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
    68  This program and the accompanying materials
    79  are licensed and made available under the terms and conditions of the BSD License
     
    1416**/
    1517
    16 #include "ShellParametersProtocol.h"
    17 #include "ConsoleWrappers.h"
    18 
    19 /**
    20   return the next parameter from a command line string;
     18#include "Shell.h"
     19
     20/**
     21  Return the next parameter's end from a command line string.
     22
     23  @param[in] String        the string to parse
     24**/
     25CONST CHAR16*
     26EFIAPI
     27FindEndOfParameter(
     28  IN CONST CHAR16 *String
     29  )
     30{
     31  CONST CHAR16 *First;
     32  CONST CHAR16 *CloseQuote;
     33
     34  First = FindFirstCharacter(String, L" \"", L'^');
     35
     36  //
     37  // nothing, all one parameter remaining
     38  //
     39  if (*First == CHAR_NULL) {
     40    return (First);
     41  }
     42
     43  //
     44  // If space before a quote (or neither found, i.e. both CHAR_NULL),
     45  // then that's the end.
     46  //
     47  if (*First == L' ') {
     48    return (First);
     49  }
     50
     51  CloseQuote = FindFirstCharacter (First+1, L"\"", L'^');
     52
     53  //
     54  // We did not find a terminator...
     55  //
     56  if (*CloseQuote == CHAR_NULL) {
     57    return (NULL);
     58  }
     59
     60  return (FindEndOfParameter (CloseQuote+1));
     61}
     62
     63/**
     64  Return the next parameter from a command line string.
    2165
    2266  This function moves the next parameter from Walker into TempParameter and moves
     
    2771  function.
    2872
     73  This will also remove all remaining ^ characters after processing.
     74
    2975  @param[in, out] Walker        pointer to string of command line.  Adjusted to
    3076                                reminaing command line on return
    3177  @param[in, out] TempParameter pointer to string of command line item extracted.
    32 
    33 **/
    34 VOID
     78  @param[in]      Length        buffer size of TempParameter.
     79
     80  @return   EFI_INALID_PARAMETER  A required parameter was NULL or pointed to a NULL or empty string.
     81  @return   EFI_NOT_FOUND         A closing " could not be found on the specified string
     82**/
     83EFI_STATUS
    3584EFIAPI
    3685GetNextParameter(
    37   CHAR16 **Walker,
    38   CHAR16 **TempParameter
    39   )
    40 {
    41   CHAR16 *NextDelim;
    42   CHAR16 *TempLoc;
    43 
    44   ASSERT(Walker           != NULL);
    45   ASSERT(*Walker          != NULL);
    46   ASSERT(TempParameter    != NULL);
    47   ASSERT(*TempParameter   != NULL);
     86  IN OUT CHAR16   **Walker,
     87  IN OUT CHAR16   **TempParameter,
     88  IN CONST UINTN  Length
     89  )
     90{
     91  CONST CHAR16 *NextDelim;
     92
     93  if (Walker           == NULL
     94    ||*Walker          == NULL
     95    ||TempParameter    == NULL
     96    ||*TempParameter   == NULL
     97    ){
     98    return (EFI_INVALID_PARAMETER);
     99  }
     100
    48101
    49102  //
     
    58111  //
    59112  if (StrLen(*Walker) == 0) {
    60     ASSERT((*Walker)[0] == CHAR_NULL);
    61     *Walker = NULL;
    62     return;
    63   }
    64 
    65   //
    66   // we have a quoted parameter
    67   // could be the last parameter, but SHOULD have a trailing quote
    68   //
    69   if ((*Walker)[0] == L'\"') {
    70     NextDelim = NULL;
    71     for (TempLoc = *Walker + 1 ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {
    72       if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') {
    73         TempLoc++;
    74       } else if (*TempLoc == L'\"') {
    75         NextDelim = TempLoc;
    76         break;
    77       }
    78     }
    79 
    80     if (NextDelim - ((*Walker)+1) == 0) {
    81       //
    82       // found ""
    83       //
    84       StrCpy(*TempParameter, L"");
    85       *Walker = NextDelim + 1;
    86     } else if (NextDelim != NULL) {
    87       StrnCpy(*TempParameter, (*Walker)+1, NextDelim - ((*Walker)+1));
    88       *Walker = NextDelim + 1;
    89     } else {
    90       //
    91       // last one... someone forgot the training quote!
    92       //
    93       StrCpy(*TempParameter, *Walker);
    94       *Walker = NULL;
    95     }
    96     for (TempLoc = *TempParameter ; TempLoc != NULL && *TempLoc != CHAR_NULL ; TempLoc++) {
    97       if (*TempLoc == L'^' && *(TempLoc+1) == L'\"') {
    98         CopyMem(TempLoc, TempLoc+1, StrSize(TempLoc) - sizeof(TempLoc[0]));
    99       }
    100     }
    101   } else {
    102     //
    103     // we have a regular parameter (no quote) OR
    104     // we have the final parameter (no trailing space)
    105     //
    106     NextDelim = StrStr((*Walker), L" ");
    107     if (NextDelim != NULL) {
    108       StrnCpy(*TempParameter, *Walker, NextDelim - (*Walker));
    109       (*TempParameter)[NextDelim - (*Walker)] = CHAR_NULL;
    110       *Walker = NextDelim+1;
    111     } else {
    112       //
    113       // last one.
    114       //
    115       StrCpy(*TempParameter, *Walker);
    116       *Walker = NULL;
    117     }
    118     for (NextDelim = *TempParameter ; NextDelim != NULL && *NextDelim != CHAR_NULL ; NextDelim++) {
    119       if (*NextDelim == L'^' && *(NextDelim+1) == L'^') {
    120         CopyMem(NextDelim, NextDelim+1, StrSize(NextDelim) - sizeof(NextDelim[0]));
    121       }
    122     }
    123     while ((*TempParameter)[StrLen(*TempParameter)-1] == L' ') {
    124       (*TempParameter)[StrLen(*TempParameter)-1] = CHAR_NULL;
    125     }
    126     while ((*TempParameter)[0] == L' ') {
    127       CopyMem(*TempParameter, (*TempParameter)+1, StrSize(*TempParameter) - sizeof((*TempParameter)[0]));
    128     }
    129   }
    130   return;
     113DEBUG_CODE_BEGIN();
     114    *Walker        = NULL;
     115DEBUG_CODE_END();
     116    return (EFI_INVALID_PARAMETER);
     117  }
     118
     119  NextDelim = FindEndOfParameter(*Walker);
     120
     121  if (NextDelim == NULL){
     122DEBUG_CODE_BEGIN();
     123    *Walker        = NULL;
     124DEBUG_CODE_END();
     125    return (EFI_NOT_FOUND);
     126  }
     127
     128  StrnCpy(*TempParameter, (*Walker), NextDelim - *Walker);
     129
     130  //
     131  // Add a CHAR_NULL if we didnt get one via the copy
     132  //
     133  if (*NextDelim != CHAR_NULL) {
     134    (*TempParameter)[NextDelim - *Walker] = CHAR_NULL;
     135  }
     136
     137  //
     138  // Update Walker for the next iteration through the function
     139  //
     140  *Walker = (CHAR16*)NextDelim;
     141
     142  //
     143  // Remove any non-escaped quotes in the string
     144  // Remove any remaining escape characters in the string
     145  //
     146  for (NextDelim = FindFirstCharacter(*TempParameter, L"\"^", CHAR_NULL)
     147    ; *NextDelim != CHAR_NULL
     148    ; NextDelim = FindFirstCharacter(NextDelim, L"\"^", CHAR_NULL)
     149    ) {
     150    if (*NextDelim == L'^') {
     151
     152      //
     153      // eliminate the escape ^
     154      //
     155      CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
     156      NextDelim++;
     157    } else if (*NextDelim == L'\"') {
     158
     159      //
     160      // eliminate the unescaped quote
     161      //
     162      CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
     163    }
     164  }
     165
     166  return EFI_SUCCESS;
    131167}
    132168
     
    137173  parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL.  this supports space
    138174  delimited and quote surrounded parameter definition.
     175
     176  All special character processing (alias, environment variable, redirection,
     177  etc... must be complete before calling this API.
    139178
    140179  @param[in] CommandLine         String of command line to parse
     
    177216      , Walker = (CHAR16*)CommandLine
    178217      ; Walker != NULL && *Walker != CHAR_NULL
    179       ; GetNextParameter(&Walker, &TempParameter)
    180       , Count++
    181      );
    182 
    183 /*  Count = 0;
    184   Walker = (CHAR16*)CommandLine;
    185   while(Walker != NULL) {
    186     GetNextParameter(&Walker, &TempParameter);
    187     Count++;
    188   }
    189 */
     218      ; Count++
     219      ) {
     220    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {
     221      break;
     222    }
     223  }
     224
    190225  //
    191226  // lets allocate the pointer array
     
    193228  (*Argv) = AllocateZeroPool((Count)*sizeof(CHAR16*));
    194229  if (*Argv == NULL) {
     230    SHELL_FREE_NON_NULL(TempParameter);
    195231    return (EFI_OUT_OF_RESOURCES);
    196232  }
     
    200236  while(Walker != NULL && *Walker != CHAR_NULL) {
    201237    SetMem16(TempParameter, Size, CHAR_NULL);
    202     GetNextParameter(&Walker, &TempParameter);
    203     NewParam = AllocateZeroPool(StrSize(TempParameter));
    204     ASSERT(NewParam != NULL);
    205     StrCpy(NewParam, TempParameter);
     238    if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {
     239      SHELL_FREE_NON_NULL(TempParameter);
     240      return (EFI_INVALID_PARAMETER);
     241    }
     242
     243    NewParam = AllocateCopyPool(StrSize(TempParameter), TempParameter);
     244    if (NewParam == NULL){
     245      SHELL_FREE_NON_NULL(TempParameter);
     246      return (EFI_OUT_OF_RESOURCES);
     247    }
    206248    ((CHAR16**)(*Argv))[(*Argc)] = NewParam;
    207249    (*Argc)++;
    208250  }
    209251  ASSERT(Count >= (*Argc));
     252  SHELL_FREE_NON_NULL(TempParameter);
    210253  return (EFI_SUCCESS);
    211254}
     
    290333  // Build the full command line
    291334  //
    292   Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, &FullCommandLine);
     335  Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine);
    293336  if (Status == EFI_BUFFER_TOO_SMALL) {
    294337    FullCommandLine = AllocateZeroPool(Size + LoadedImage->LoadOptionsSize);
    295     Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, &FullCommandLine);
     338    Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine);
    296339  }
    297340  if (Status == EFI_NOT_FOUND) {
     
    313356  }
    314357  if (FullCommandLine != NULL) {
    315     if (LoadedImage->LoadOptionsSize != 0){
    316       StrCpy(FullCommandLine, LoadedImage->LoadOptions);
    317     }
     358    CopyMem (FullCommandLine, LoadedImage->LoadOptions, LoadedImage->LoadOptionsSize);
    318359    //
    319360    // Populate Argc and Argv
     
    524565  } else {
    525566    Copy = FileName;
     567    while(Copy[0] == L' ') {
     568      Copy++;
     569    }
    526570    if ((TempLocation = StrStr(Copy , L" ")) != NULL) {
    527571      TempLocation[0] = CHAR_NULL;
     
    535579  return (Copy);
    536580}
     581
     582/**
     583  Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %.
     584
     585  @param[in]  FileName    The filename to start with.
     586
     587  @retval NULL  FileName was invalid.
     588  @return       The modified FileName.
     589**/
     590CHAR16*
     591EFIAPI
     592FixVarName (
     593  IN CHAR16 *FileName
     594  )
     595{
     596  CHAR16  *Copy;
     597  CHAR16  *TempLocation;
     598
     599  Copy = FileName;
     600
     601  if (FileName[0] == L'%') {
     602    Copy = FileName+1;
     603    if ((TempLocation = StrStr(Copy , L"%")) != NULL) {
     604      TempLocation[0] = CHAR_NULL;
     605    }   
     606  }
     607
     608  return (FixFileName(Copy));
     609}
     610
     611/**
     612  Remove the unicode file tag from the begining of the file buffer since that will not be
     613  used by StdIn.
     614 
     615  @param[in]  Handle    Pointer to the handle of the file to be processed.
     616 
     617  @retval EFI_SUCCESS   The unicode file tag has been moved successfully.
     618**/
     619EFI_STATUS
     620EFIAPI
     621RemoveFileTag(
     622  IN SHELL_FILE_HANDLE *Handle
     623  )
     624{
     625  UINTN             CharSize;
     626  CHAR16            CharBuffer;
     627
     628  CharSize    = sizeof(CHAR16);
     629  CharBuffer  = 0;
     630  gEfiShellProtocol->ReadFile(*Handle, &CharSize, &CharBuffer);
     631  if (CharBuffer != gUnicodeFileTag) {
     632    gEfiShellProtocol->SetFilePosition(*Handle, 0);
     633  }
     634  return (EFI_SUCCESS);
     635}
     636
     637/**
     638  Write the unicode file tag to the specified file.
     639
     640  It is the caller's responsibility to ensure that
     641  ShellInfoObject.NewEfiShellProtocol has been initialized before calling this
     642  function.
     643
     644  @param[in] FileHandle  The file to write the unicode file tag to.
     645
     646  @return  Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.
     647**/
     648EFI_STATUS
     649WriteFileTag (
     650  IN SHELL_FILE_HANDLE FileHandle
     651  )
     652{
     653  CHAR16     FileTag;
     654  UINTN      Size;
     655  EFI_STATUS Status;
     656
     657  FileTag = gUnicodeFileTag;
     658  Size = sizeof FileTag;
     659  Status = ShellInfoObject.NewEfiShellProtocol->WriteFile (FileHandle, &Size,
     660                                                  &FileTag);
     661  ASSERT (EFI_ERROR (Status) || Size == sizeof FileTag);
     662  return Status;
     663}
     664
    537665
    538666/**
     
    581709  BOOLEAN           ErrAppend;
    582710  UINTN             Size;
    583   CHAR16            TagBuffer[2];
    584711  SPLIT_LIST        *Split;
    585712  CHAR16            *FirstLocation;
     
    607734  SystemTableInfo->ConOut         = gST->ConOut;
    608735  SystemTableInfo->ConOutHandle   = gST->ConsoleOutHandle;
    609   SystemTableInfo->ConErr         = gST->StdErr;
    610   SystemTableInfo->ConErrHandle   = gST->StandardErrorHandle;
     736  SystemTableInfo->ErrOut         = gST->StdErr;
     737  SystemTableInfo->ErrOutHandle   = gST->StandardErrorHandle;
    611738  *OldStdIn                       = ShellParameters->StdIn;
    612739  *OldStdOut                      = ShellParameters->StdOut;
     
    8861013  // re-populate the string to support any filenames that were in quotes.
    8871014  //
    888   StrCpy(CommandLineCopy, NewCommandLine);
     1015  StrnCpy(CommandLineCopy, NewCommandLine, StrLen(NewCommandLine));
    8891016
    8901017  if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)
     
    9121039    }
    9131040    if (StdErrVarName  != NULL) {
    914       if ((StdErrVarName     = FixFileName(StdErrVarName)) == NULL) {
     1041      if ((StdErrVarName     = FixVarName(StdErrVarName)) == NULL) {
    9151042        Status = EFI_INVALID_PARAMETER;
    9161043      }
    9171044    }
    9181045    if (StdOutVarName  != NULL) {
    919       if ((StdOutVarName     = FixFileName(StdOutVarName)) == NULL) {
     1046      if ((StdOutVarName     = FixVarName(StdOutVarName)) == NULL) {
    9201047        Status = EFI_INVALID_PARAMETER;
    9211048      }
    9221049    }
    9231050    if (StdInVarName   != NULL) {
    924       if ((StdInVarName      = FixFileName(StdInVarName)) == NULL) {
     1051      if ((StdInVarName      = FixVarName(StdInVarName)) == NULL) {
    9251052        Status = EFI_INVALID_PARAMETER;
    9261053      }
     
    9931120        Status = ShellOpenFileByName(StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
    9941121        if (!ErrAppend && ErrUnicode && !EFI_ERROR(Status)) {
    995           //
    996           // Write out the gUnicodeFileTag
    997           //
    998           Size = sizeof(CHAR16);
    999           TagBuffer[0] = gUnicodeFileTag;
    1000           TagBuffer[1] = CHAR_NULL;
    1001           ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
     1122          Status = WriteFileTag (TempHandle);
    10021123        }
    10031124        if (!ErrUnicode && !EFI_ERROR(Status)) {
     
    10071128        if (!EFI_ERROR(Status)) {
    10081129          ShellParameters->StdErr = TempHandle;
    1009           gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle);
     1130          gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);
    10101131        }
    10111132      }
     
    10281149            //no-op
    10291150          } else if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
    1030             //
    1031             // Write out the gUnicodeFileTag
    1032             //
    1033             Size = sizeof(CHAR16);
    1034             TagBuffer[0] = gUnicodeFileTag;
    1035             TagBuffer[1] = CHAR_NULL;
    1036             ShellInfoObject.NewEfiShellProtocol->WriteFile(TempHandle, &Size, TagBuffer);
     1151            Status = WriteFileTag (TempHandle);
    10371152          } else if (OutAppend) {
    1038             //
    1039             // Move to end of file
    1040             //
    10411153            Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize);
    10421154            if (!EFI_ERROR(Status)) {
    1043               Status = ShellInfoObject.NewEfiShellProtocol->SetFilePosition(TempHandle, FileSize);
     1155              //
     1156              // When appending to a new unicode file, write the file tag.
     1157              // Otherwise (ie. when appending to a new ASCII file, or an
     1158              // existent file with any encoding), just seek to the end.
     1159              //
     1160              Status = (FileSize == 0 && OutUnicode) ?
     1161                         WriteFileTag (TempHandle) :
     1162                         ShellInfoObject.NewEfiShellProtocol->SetFilePosition (
     1163                                                                TempHandle,
     1164                                                                FileSize);
    10441165            }
    10451166          }
     
    10501171          if (!EFI_ERROR(Status)) {
    10511172            ShellParameters->StdOut = TempHandle;
    1052             gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle);
     1173            gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
    10531174          }
    10541175        }
     
    10681189        ASSERT(TempHandle != NULL);
    10691190        ShellParameters->StdOut = TempHandle;
    1070         gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle);
     1191        gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
    10711192      }
    10721193
     
    10841205        ASSERT(TempHandle != NULL);
    10851206        ShellParameters->StdErr = TempHandle;
    1086         gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle);
     1207        gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);
    10871208      }
    10881209
     
    11171238          EFI_FILE_MODE_READ,
    11181239          0);
    1119         if (!InUnicode && !EFI_ERROR(Status)) {
     1240        if (InUnicode) {
     1241          //
     1242          // Chop off the 0xFEFF if it's there...
     1243          //
     1244          RemoveFileTag(&TempHandle);
     1245        } else if (!EFI_ERROR(Status)) {
     1246          //
     1247          // Create the ASCII->Unicode conversion layer
     1248          //
    11201249          TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
    11211250        }
     
    11321261
    11331262  if (gST->ConIn == NULL ||gST->ConOut == NULL) {
    1134     return (EFI_OUT_OF_RESOURCES);
    1135   }
     1263    Status = EFI_OUT_OF_RESOURCES;
     1264  }
     1265
     1266  if (Status == EFI_NOT_FOUND) {
     1267    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);
     1268  } else if (EFI_ERROR(Status)) {
     1269    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
     1270  }
     1271
    11361272  return (Status);
    11371273}
     
    11981334    gST->ConsoleOutHandle     = SystemTableInfo->ConOutHandle;
    11991335  }
    1200   if (gST->StdErr != SystemTableInfo->ConErr) {
     1336  if (gST->StdErr != SystemTableInfo->ErrOut) {
    12011337    CloseSimpleTextOutOnFile(gST->StdErr);
    1202     gST->StdErr               = SystemTableInfo->ConErr;
    1203     gST->StandardErrorHandle  = SystemTableInfo->ConErrHandle;
     1338    gST->StdErr               = SystemTableInfo->ErrOut;
     1339    gST->StandardErrorHandle  = SystemTableInfo->ErrOutHandle;
    12041340  }
    12051341
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ShellParametersProtocol.h

    r48674 r58459  
    33  manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
    44
    5   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
     5  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    66  This program and the accompanying materials
    77  are licensed and made available under the terms and conditions of the BSD License
     
    1717#define _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_
    1818
    19 #include <Uefi.h>
    20 
    21 #include <Protocol/SimpleFileSystem.h>
    22 #include <Protocol/EfiShellParameters.h>
    23 #include <Protocol/LoadedImage.h>
    24 #include <Protocol/SimpleTextOut.h>
    25 #include <Protocol/SimpleTextIn.h>
    26 
    27 #include <Guid/ShellVariableGuid.h>
    28 
    29 #include <Library/UefiBootServicesTableLib.h>
    30 #include <Library/UefiRuntimeServicesTableLib.h>
    31 #include <Library/MemoryAllocationLib.h>
    32 #include <Library/UefiLib.h>
    33 #include <Library/DebugLib.h>
    34 #include <Library/ShellLib.h>
    35 #include <Library/FileHandleLib.h>
    36 
    37 #include "ShellEnvVar.h"
    38 #include "FileHandleWrappers.h"
    3919#include "Shell.h"
    4020
     
    124104  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL       *ConOut;
    125105  EFI_HANDLE                            ConOutHandle;
    126   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL       *ConErr;
    127   EFI_HANDLE                            ConErrHandle;
     106  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL       *ErrOut;
     107  EFI_HANDLE                            ErrOutHandle;
    128108} SYSTEM_TABLE_INFO;
    129109
     
    211191                                reminaing command line on return
    212192  @param[in, out] TempParameter pointer to string of command line item extracted.
    213 
    214 **/
    215 VOID
     193  @param[in]      Length        Length of (*TempParameter) in bytes
     194
     195  @return   EFI_INALID_PARAMETER  A required parameter was NULL or pointed to a NULL or empty string.
     196  @return   EFI_NOT_FOUND         A closing " could not be found on the specified string
     197**/
     198EFI_STATUS
    216199EFIAPI
    217200GetNextParameter(
    218   CHAR16 **Walker,
    219   CHAR16 **TempParameter
     201  IN OUT CHAR16   **Walker,
     202  IN OUT CHAR16   **TempParameter,
     203  IN CONST UINTN  Length
    220204  );
    221205
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ShellProtocol.c

    r48674 r58459  
    33  manipulation, and initialization of EFI_SHELL_PROTOCOL.
    44
    5   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     5  (C) Copyright 2014, Hewlett-Packard Development Company, L.P.
     6  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
    67  This program and the accompanying materials
    78  are licensed and made available under the terms and conditions of the BSD License
     
    1516
    1617#include "Shell.h"
    17 #include <Library/FileHandleLib.h>
     18
     19#define INIT_NAME_BUFFER_SIZE  128
    1820
    1921/**
     
    117119  )
    118120{
    119   EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevicePathToText;
    120121  EFI_STATUS                        Status;
    121122  CHAR16                            *Temp;
     
    123124  Status = EFI_SUCCESS;
    124125  DEBUG_CODE_BEGIN();
    125   DevicePathToText = NULL;
    126 
    127   Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid,
    128                                NULL,
    129                                (VOID**)&DevicePathToText);
     126
    130127  if (Mapping != NULL) {
    131128    DEBUG((EFI_D_INFO, "Added new map item:\"%S\"\r\n", Mapping));
    132129  }
    133   if (!EFI_ERROR(Status)) {
    134     if (DevicePath != NULL) {
    135       Temp = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);
    136       DEBUG((EFI_D_INFO, "DevicePath: %S\r\n", Temp));
    137       FreePool(Temp);
    138     }
    139   }
     130  Temp = ConvertDevicePathToText(DevicePath, TRUE, TRUE);
     131  DEBUG((EFI_D_INFO, "DevicePath: %S\r\n", Temp));
     132  FreePool(Temp);
     133
    140134  DEBUG_CODE_END();
    141135  return (Status);
     
    468462          //
    469463          ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));
    470           PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L"\\", 1);
    471464
    472465          AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);
     466          ASSERT (AlignedNode != NULL);
     467
     468          // File Path Device Path Nodes 'can optionally add a "\" separator to
     469          //  the beginning and/or the end of the Path Name string.'
     470          // (UEFI Spec 2.4 section 9.3.6.4).
     471          // If necessary, add a "\", but otherwise don't
     472          // (This is specified in the above section, and also implied by the
     473          //  UEFI Shell spec section 3.7)
     474          if ((PathSize != 0)                        &&
     475              (PathForReturn != NULL)                &&
     476              (PathForReturn[PathSize - 1] != L'\\') &&
     477              (AlignedNode->PathName[0]    != L'\\')) {
     478            PathForReturn = StrnCatGrow (&PathForReturn, &PathSize, L"\\", 1);
     479          }
     480
    473481          PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, AlignedNode->PathName, 0);
    474482          FreePool(AlignedNode);
     
    525533      return (NULL);
    526534    }
    527     Size = StrSize(Cwd);
    528     Size += StrSize(Path);
     535    Size = StrSize(Cwd) + StrSize(Path) - sizeof(CHAR16);
    529536    NewPath = AllocateZeroPool(Size);
    530537    if (NewPath == NULL) {
    531538      return (NULL);
    532539    }
    533     StrCpy(NewPath, Cwd);
     540    StrnCpy(NewPath, Cwd, Size/sizeof(CHAR16)-1);
    534541    if (*Path == L'\\') {
    535542      Path++;
    536543      while (PathRemoveLastItem(NewPath)) ;
    537544    }
    538     StrCat(NewPath, Path);
     545    StrnCat(NewPath, Path, Size/sizeof(CHAR16) - 1 - StrLen(NewPath));
    539546    DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);
    540547    FreePool(NewPath);
     
    649656  EFI_STATUS                        Status;
    650657  EFI_COMPONENT_NAME2_PROTOCOL      *CompName2;
    651   EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevicePathToText;
    652658  EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
    653659  EFI_HANDLE                        *HandleList;
     
    656662  CHAR16                            *DeviceNameToReturn;
    657663  CHAR8                             *Lang;
    658   CHAR8                             *TempChar;
    659 
    660664  UINTN                             ParentControllerCount;
    661665  EFI_HANDLE                        *ParentControllerBuffer;
     
    714718        continue;
    715719      }
    716       if (Language == NULL) {
    717         Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));
    718         if (Lang == NULL) {
    719           return (EFI_OUT_OF_RESOURCES);
    720         }
    721         AsciiStrCpy(Lang, CompName2->SupportedLanguages);
    722         TempChar = AsciiStrStr(Lang, ";");
    723         if (TempChar != NULL){
    724           *TempChar = CHAR_NULL;
    725         }
    726       } else {
    727         Lang = AllocateZeroPool(AsciiStrSize(Language));
    728         if (Lang == NULL) {
    729           return (EFI_OUT_OF_RESOURCES);
    730         }
    731         AsciiStrCpy(Lang, Language);
    732       }
     720      Lang = GetBestLanguageForDriver(CompName2->SupportedLanguages, Language, FALSE);
    733721      Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn);
    734722      FreePool(Lang);
     
    773761            continue;
    774762          }
    775           if (Language == NULL) {
    776             Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));
    777             if (Lang == NULL) {
    778               return (EFI_OUT_OF_RESOURCES);
    779             }
    780             AsciiStrCpy(Lang, CompName2->SupportedLanguages);
    781             TempChar = AsciiStrStr(Lang, ";");
    782             if (TempChar != NULL){
    783               *TempChar = CHAR_NULL;
    784             }
    785           } else {
    786             Lang = AllocateZeroPool(AsciiStrSize(Language));
    787             if (Lang == NULL) {
    788               return (EFI_OUT_OF_RESOURCES);
    789             }
    790             AsciiStrCpy(Lang, Language);
    791           }
     763          Lang = GetBestLanguageForDriver(CompName2->SupportedLanguages, Language, FALSE);
    792764          Status = CompName2->GetControllerName(CompName2, ParentControllerBuffer[LoopVar], DeviceHandle, Lang, &DeviceNameToReturn);
    793765          FreePool(Lang);
     
    817789  }
    818790  if ((Flags & EFI_DEVICE_NAME_USE_DEVICE_PATH) != 0) {
    819     Status = gBS->LocateProtocol(
    820       &gEfiDevicePathToTextProtocolGuid,
     791    Status = gBS->OpenProtocol(
     792      DeviceHandle,
     793      &gEfiDevicePathProtocolGuid,
     794      (VOID**)&DevicePath,
     795      gImageHandle,
    821796      NULL,
    822       (VOID**)&DevicePathToText);
    823     //
    824     // we now have the device path to text protocol
    825     //
     797      EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    826798    if (!EFI_ERROR(Status)) {
    827       Status = gBS->OpenProtocol(
    828         DeviceHandle,
    829         &gEfiDevicePathProtocolGuid,
    830         (VOID**)&DevicePath,
    831         gImageHandle,
    832         NULL,
    833         EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    834       if (!EFI_ERROR(Status)) {
    835         //
    836         // use device path to text on the device path
    837         //
    838         *BestDeviceName = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);
    839         return (EFI_SUCCESS);
    840       }
     799      //
     800      // use device path to text on the device path
     801      //
     802      *BestDeviceName = ConvertDevicePathToText(DevicePath, TRUE, TRUE);
     803      return (EFI_SUCCESS);
    841804    }
    842805  }
     
    996959  EFI_FILE_PROTOCOL               *Handle1;
    997960  EFI_FILE_PROTOCOL               *Handle2;
    998   EFI_DEVICE_PATH_PROTOCOL        *DpCopy;
    999961  FILEPATH_DEVICE_PATH            *AlignedNode;
    1000962
     
    1006968  Handle2       = NULL;
    1007969  Handle        = NULL;
    1008   DpCopy        = DevicePath;
    1009970  ShellHandle   = NULL;
    1010971  FilePathNode  = NULL;
     
    11871148  }
    11881149
    1189   Status = InternalOpenFileDevicePath(DevicePath, FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, FileAttribs); // 0 = no specific file attributes
     1150  Status = InternalOpenFileDevicePath(DevicePath, FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, FileAttribs);
    11901151  FreePool(DevicePath);
    11911152
    11921153  return(Status);
     1154}
     1155
     1156/**
     1157  Register a GUID and a localized human readable name for it.
     1158
     1159  If Guid is not assigned a name, then assign GuidName to Guid.  This list of GUID
     1160  names must be used whenever a shell command outputs GUID information.
     1161
     1162  This function is only available when the major and minor versions in the
     1163  EfiShellProtocol are greater than or equal to 2 and 1, respectively.
     1164
     1165  @param[in] Guid       A pointer to the GUID being registered.
     1166  @param[in] GuidName   A pointer to the localized name for the GUID being registered.
     1167
     1168  @retval EFI_SUCCESS             The operation was successful.
     1169  @retval EFI_INVALID_PARAMETER   Guid was NULL.
     1170  @retval EFI_INVALID_PARAMETER   GuidName was NULL.
     1171  @retval EFI_ACCESS_DENIED       Guid already is assigned a name.
     1172**/
     1173EFI_STATUS
     1174EFIAPI
     1175EfiShellRegisterGuidName(
     1176  IN CONST EFI_GUID *Guid,
     1177  IN CONST CHAR16   *GuidName
     1178  )
     1179{
     1180  return (AddNewGuidNameMapping(Guid, GuidName, NULL));
    11931181}
    11941182
     
    13601348  EFI_STATUS        Status;
    13611349
     1350  FileHandle = NULL;
     1351
    13621352  //
    13631353  // get a handle to the file
     
    14021392  internal worker function to load and run an image via device path.
    14031393
    1404   @param ParentImageHandle  A handle of the image that is executing the specified
    1405                             command line.
    1406   @param DevicePath         device path of the file to execute
    1407   @param CommandLine        Points to the NULL-terminated UCS-2 encoded string
    1408                             containing the command line. If NULL then the command-
    1409                             line will be empty.
    1410   @param Environment        Points to a NULL-terminated array of environment
    1411                             variables with the format 'x=y', where x is the
    1412                             environment variable name and y is the value. If this
    1413                             is NULL, then the current shell environment is used.
    1414   @param StatusCode         Points to the status code returned by the command.
     1394  @param ParentImageHandle      A handle of the image that is executing the specified
     1395                                command line.
     1396  @param DevicePath             device path of the file to execute
     1397  @param CommandLine            Points to the NULL-terminated UCS-2 encoded string
     1398                                containing the command line. If NULL then the command-
     1399                                line will be empty.
     1400  @param Environment            Points to a NULL-terminated array of environment
     1401                                variables with the format 'x=y', where x is the
     1402                                environment variable name and y is the value. If this
     1403                                is NULL, then the current shell environment is used.
     1404                           
     1405  @param[out] StartImageStatus  Returned status from gBS->StartImage.
    14151406
    14161407  @retval EFI_SUCCESS       The command executed successfully. The  status code
     
    14271418  IN CONST CHAR16                   *CommandLine OPTIONAL,
    14281419  IN CONST CHAR16                   **Environment OPTIONAL,
    1429   OUT EFI_STATUS                    *StatusCode OPTIONAL
     1420  OUT EFI_STATUS                    *StartImageStatus OPTIONAL
    14301421  )
    14311422{
    14321423  EFI_STATUS                    Status;
     1424  EFI_STATUS                    StartStatus;
     1425  EFI_STATUS                    CleanupStatus;
    14331426  EFI_HANDLE                    NewHandle;
    14341427  EFI_LOADED_IMAGE_PROTOCOL     *LoadedImage;
    14351428  LIST_ENTRY                    OrigEnvs;
    14361429  EFI_SHELL_PARAMETERS_PROTOCOL ShellParamsProtocol;
     1430  CHAR16                        *ImagePath;
     1431  UINTN                         Index;
     1432  CHAR16                        *Walker;
     1433  CHAR16                        *NewCmdLine;
    14371434
    14381435  if (ParentImageHandle == NULL) {
     
    14431440
    14441441  NewHandle = NULL;
     1442 
     1443  NewCmdLine = AllocateCopyPool (StrSize (CommandLine), CommandLine);
     1444  if (NewCmdLine == NULL) {
     1445    return EFI_OUT_OF_RESOURCES;
     1446  }
     1447
     1448  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
     1449    if (*Walker == L'^' && *(Walker+1) == L'#') {
     1450      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
     1451    }
     1452  }
    14451453
    14461454  //
     
    14721480  if (!EFI_ERROR(Status)) {
    14731481    ASSERT(LoadedImage->LoadOptionsSize == 0);
    1474     if (CommandLine != NULL) {
    1475       LoadedImage->LoadOptionsSize  = (UINT32)StrSize(CommandLine);
    1476       LoadedImage->LoadOptions      = (VOID*)CommandLine;
     1482    if (NewCmdLine != NULL) {
     1483      LoadedImage->LoadOptionsSize  = (UINT32)StrSize(NewCmdLine);
     1484      LoadedImage->LoadOptions      = (VOID*)NewCmdLine;
    14771485    }
    14781486
     
    14931501    ShellParamsProtocol.StdOut  = ShellInfoObject.NewShellParametersProtocol->StdOut;
    14941502    ShellParamsProtocol.StdErr  = ShellInfoObject.NewShellParametersProtocol->StdErr;
    1495     Status = UpdateArgcArgv(&ShellParamsProtocol, CommandLine, NULL, NULL);
     1503    Status = UpdateArgcArgv(&ShellParamsProtocol, NewCmdLine, NULL, NULL);
    14961504    ASSERT_EFI_ERROR(Status);
     1505    //
     1506    // Replace Argv[0] with the full path of the binary we're executing:
     1507    // If the command line was "foo", the binary might be called "foo.efi".
     1508    // "The first entry in [Argv] is always the full file path of the
     1509    //  executable" - UEFI Shell Spec section 2.3
     1510    //
     1511    ImagePath = EfiShellGetFilePathFromDevicePath (DevicePath);
     1512    // The image we're executing isn't necessarily in a filesystem - it might
     1513    // be memory mapped. In this case EfiShellGetFilePathFromDevicePath will
     1514    // return NULL, and we'll leave Argv[0] as UpdateArgcArgv set it.
     1515    if (ImagePath != NULL) {
     1516      if (ShellParamsProtocol.Argv == NULL) {
     1517        // Command line was empty or null.
     1518        // (UpdateArgcArgv sets Argv to NULL when CommandLine is "" or NULL)
     1519        ShellParamsProtocol.Argv = AllocatePool (sizeof (CHAR16 *));
     1520        if (ShellParamsProtocol.Argv == NULL) {
     1521          Status = EFI_OUT_OF_RESOURCES;
     1522          goto UnloadImage;
     1523        }
     1524        ShellParamsProtocol.Argc = 1;
     1525      } else {
     1526        // Free the string UpdateArgcArgv put in Argv[0];
     1527        FreePool (ShellParamsProtocol.Argv[0]);
     1528      }
     1529      ShellParamsProtocol.Argv[0] = ImagePath;
     1530    }
     1531
    14971532    Status = gBS->InstallProtocolInterface(&NewHandle, &gEfiShellParametersProtocolGuid, EFI_NATIVE_INTERFACE, &ShellParamsProtocol);
    14981533    ASSERT_EFI_ERROR(Status);
     
    15041539    //
    15051540    if (!EFI_ERROR(Status)) {
    1506       if (StatusCode != NULL) {
    1507         *StatusCode = gBS->StartImage(NewHandle, NULL, NULL);
    1508       } else {
    1509         Status      = gBS->StartImage(NewHandle, NULL, NULL);
     1541      StartStatus      = gBS->StartImage(
     1542                          NewHandle,
     1543                          0,
     1544                          NULL
     1545                          );
     1546      if (StartImageStatus != NULL) {
     1547        *StartImageStatus = StartStatus;
    15101548      }
    1511     }
    1512 
    1513     //
    1514     // Cleanup (and dont overwrite errors)
    1515     //
    1516     if (EFI_ERROR(Status)) {
    1517       gBS->UninstallProtocolInterface(NewHandle, &gEfiShellParametersProtocolGuid, &ShellParamsProtocol);
    1518     } else {
    1519       Status = gBS->UninstallProtocolInterface(NewHandle, &gEfiShellParametersProtocolGuid, &ShellParamsProtocol);
    1520       ASSERT_EFI_ERROR(Status);
    1521     }
    1522   }
    1523 
     1549
     1550      CleanupStatus = gBS->UninstallProtocolInterface(
     1551                            NewHandle,
     1552                            &gEfiShellParametersProtocolGuid,
     1553                            &ShellParamsProtocol
     1554                            );
     1555      ASSERT_EFI_ERROR(CleanupStatus);
     1556
     1557      goto FreeAlloc;
     1558    }
     1559
     1560UnloadImage:
     1561    // Unload image - We should only get here if we didn't call StartImage
     1562    gBS->UnloadImage (NewHandle);
     1563
     1564FreeAlloc:
     1565    // Free Argv (Allocated in UpdateArgcArgv)
     1566    if (ShellParamsProtocol.Argv != NULL) {
     1567      for (Index = 0; Index < ShellParamsProtocol.Argc; Index++) {
     1568        if (ShellParamsProtocol.Argv[Index] != NULL) {
     1569          FreePool (ShellParamsProtocol.Argv[Index]);
     1570        }
     1571      }
     1572      FreePool (ShellParamsProtocol.Argv);
     1573    }
     1574  }
     1575
     1576  // Restore environment variables
    15241577  if (!IsListEmpty(&OrigEnvs)) {
    1525     if (EFI_ERROR(Status)) {
    1526       SetEnvironmentVariableList(&OrigEnvs);
    1527     } else {
    1528       Status = SetEnvironmentVariableList(&OrigEnvs);
    1529     }
    1530   }
     1578    CleanupStatus = SetEnvironmentVariableList(&OrigEnvs);
     1579    ASSERT_EFI_ERROR (CleanupStatus);
     1580  }
     1581
     1582  FreePool (NewCmdLine);
    15311583
    15321584  return(Status);
     
    15871639
    15881640  DEBUG_CODE_BEGIN();
    1589   Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE);
     1641  Temp = ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE);
    15901642  FreePool(Temp);
    1591   Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE);
     1643  Temp = ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE);
    15921644  FreePool(Temp);
    1593   Temp = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, TRUE);
     1645  Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);
    15941646  FreePool(Temp);
    15951647  DEBUG_CODE_END();
     
    15981650  Size = 0;
    15991651  ASSERT((Temp == NULL && Size == 0) || (Temp != NULL));
    1600   StrnCatGrow(&Temp, &Size, L"Shell.efi ", 0);
     1652  StrnCatGrow(&Temp, &Size, L"Shell.efi -_exit ", 0);
    16011653  StrnCatGrow(&Temp, &Size, CommandLine, 0);
    16021654
     
    16751727    InternalFreeShellFileInfoNode(ShellFileListItem);
    16761728  }
     1729  InternalFreeShellFileInfoNode(*FileList);
     1730  *FileList = NULL;
    16771731  return(EFI_SUCCESS);
    16781732}
     
    16961750  EFI_SHELL_FILE_INFO *ShellFileListItem;
    16971751  EFI_SHELL_FILE_INFO *ShellFileListItem2;
     1752  EFI_SHELL_FILE_INFO *TempNode;
    16981753
    16991754  if (FileList == NULL || *FileList == NULL) {
     
    17131768            (CHAR16*)ShellFileListItem2->FullName) == 0
    17141769         ){
     1770        TempNode = (EFI_SHELL_FILE_INFO *)GetPreviousNode(
     1771                                            &(*FileList)->Link,
     1772                                            &ShellFileListItem2->Link
     1773                                            );
    17151774        RemoveEntryList(&ShellFileListItem2->Link);
    17161775        InternalFreeShellFileInfoNode(ShellFileListItem2);
     1776        // Set ShellFileListItem2 to PreviousNode so we don't access Freed
     1777        // memory in GetNextNode in the loop expression above.
     1778        ShellFileListItem2 = TempNode;
    17171779      }
    17181780    }
     
    17201782  return (EFI_SUCCESS);
    17211783}
     1784
     1785//
     1786// This is the same structure as the external version, but it has no CONST qualifiers.
     1787//
     1788typedef struct {
     1789  LIST_ENTRY        Link;       ///< Linked list members.
     1790  EFI_STATUS        Status;     ///< Status of opening the file.  Valid only if Handle != NULL.
     1791        CHAR16      *FullName;  ///< Fully qualified filename.
     1792        CHAR16      *FileName;  ///< name of this file.
     1793  SHELL_FILE_HANDLE Handle;     ///< Handle for interacting with the opened file or NULL if closed.
     1794  EFI_FILE_INFO     *Info;      ///< Pointer to the FileInfo struct for this file or NULL.
     1795} EFI_SHELL_FILE_INFO_NO_CONST;
     1796
    17221797/**
    17231798  Allocates and duplicates a EFI_SHELL_FILE_INFO node.
     
    17361811  )
    17371812{
    1738   EFI_SHELL_FILE_INFO *NewNode;
     1813  EFI_SHELL_FILE_INFO_NO_CONST *NewNode;
     1814
     1815  //
     1816  // try to confirm that the objects are in sync
     1817  //
     1818  ASSERT(sizeof(EFI_SHELL_FILE_INFO_NO_CONST) == sizeof(EFI_SHELL_FILE_INFO));
    17391819
    17401820  NewNode = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
     
    17421822    return (NULL);
    17431823  }
    1744   NewNode->FullName = AllocateZeroPool(StrSize(Node->FullName));
    1745 
    1746   NewNode->FileName = AllocateZeroPool(StrSize(Node->FileName));
    1747   NewNode->Info     = AllocateZeroPool((UINTN)Node->Info->Size);
     1824  NewNode->FullName = AllocateCopyPool(StrSize(Node->FullName), Node->FullName);
     1825  NewNode->FileName = AllocateCopyPool(StrSize(Node->FileName), Node->FileName);
     1826  NewNode->Info     = AllocateCopyPool((UINTN)Node->Info->Size, Node->Info);
    17481827  if ( NewNode->FullName == NULL
    17491828    || NewNode->FileName == NULL
    17501829    || NewNode->Info == NULL
    1751    ){
     1830  ){
     1831    SHELL_FREE_NON_NULL(NewNode->FullName);
     1832    SHELL_FREE_NON_NULL(NewNode->FileName);
     1833    SHELL_FREE_NON_NULL(NewNode->Info);
     1834    SHELL_FREE_NON_NULL(NewNode);
    17521835    return(NULL);
    17531836  }
     
    17571840    Node->Handle = NULL;
    17581841  }
    1759   StrCpy((CHAR16*)NewNode->FullName, Node->FullName);
    1760   StrCpy((CHAR16*)NewNode->FileName, Node->FileName);
    1761   CopyMem(NewNode->Info, Node->Info, (UINTN)Node->Info->Size);
    1762 
    1763   return(NewNode);
     1842
     1843  return((EFI_SHELL_FILE_INFO*)NewNode);
    17641844}
    17651845
     
    17701850  @param[in] BasePath         the Path to prepend onto filename for FullPath
    17711851  @param[in] Status           Status member initial value.
    1772   @param[in] FullName         FullName member initial value.
    17731852  @param[in] FileName         FileName member initial value.
    17741853  @param[in] Handle           Handle member initial value.
     
    17831862  IN CONST CHAR16 *BasePath,
    17841863  IN CONST EFI_STATUS Status,
    1785   IN CONST CHAR16 *FullName,
    17861864  IN CONST CHAR16 *FileName,
    17871865  IN CONST SHELL_FILE_HANDLE Handle,
     
    18001878    return (NULL);
    18011879  }
    1802   if (Info != NULL) {
     1880  if (Info != NULL && Info->Size != 0) {
    18031881    ShellFileListItem->Info = AllocateZeroPool((UINTN)Info->Size);
    18041882    if (ShellFileListItem->Info == NULL) {
     
    18281906    if (TempString == NULL) {
    18291907      FreePool((VOID*)ShellFileListItem->FileName);
    1830       FreePool(ShellFileListItem->Info);
     1908      SHELL_FREE_NON_NULL(ShellFileListItem->Info);
    18311909      FreePool(ShellFileListItem);
    18321910      return (NULL);
     
    18431921    }
    18441922  }
     1923
     1924  TempString = PathCleanUpDirectories(TempString);
    18451925
    18461926  ShellFileListItem->FullName = TempString;
     
    18821962  CHAR16                    *TempSpot;
    18831963
     1964  BasePath = NULL;
    18841965  Status = FileHandleGetFileName(FileDirHandle, &BasePath);
    18851966  if (EFI_ERROR(Status)) {
     
    18921973    TempString        = StrnCatGrow(&TempString, &Size, ShellFileHandleGetPath(FileDirHandle), 0);
    18931974    if (TempString == NULL) {
     1975      SHELL_FREE_NON_NULL(BasePath);
    18941976      return (EFI_OUT_OF_RESOURCES);
    18951977    }
     
    19021984    TempString        = StrnCatGrow(&TempString, &Size, BasePath, 0);
    19031985    if (TempString == NULL) {
     1986      SHELL_FREE_NON_NULL(BasePath);
    19041987      return (EFI_OUT_OF_RESOURCES);
    19051988    }
     1989    SHELL_FREE_NON_NULL(BasePath);
    19061990    BasePath          = TempString;
    19071991  }
     
    19182002      ; Status = FileHandleFindNextFile(FileDirHandle, FileInfo, &NoFile)
    19192003     ){
    1920     TempString  = NULL;
    1921     Size        = 0;
    19222004    //
    19232005    // allocate a new EFI_SHELL_FILE_INFO and populate it...
    19242006    //
    1925     ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));
    1926     TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);
    1927     TempString = StrnCatGrow(&TempString, &Size, FileInfo->FileName, 0);
    19282007    ShellFileListItem = CreateAndPopulateShellFileInfo(
    19292008      BasePath,
    1930       EFI_SUCCESS, // success since we didnt fail to open it...
    1931       TempString,
     2009      EFI_SUCCESS,  // success since we didnt fail to open it...
    19322010      FileInfo->FileName,
    1933       NULL, // no handle since not open
     2011      NULL,         // no handle since not open
    19342012      FileInfo);
    19352013
     
    19492027  SHELL_FREE_NON_NULL(BasePath);
    19502028  return(Status);
     2029}
     2030
     2031/**
     2032  Get the GUID value from a human readable name.
     2033
     2034  If GuidName is a known GUID name, then update Guid to have the correct value for
     2035  that GUID.
     2036
     2037  This function is only available when the major and minor versions in the
     2038  EfiShellProtocol are greater than or equal to 2 and 1, respectively.
     2039
     2040  @param[in]  GuidName   A pointer to the localized name for the GUID being queried.
     2041  @param[out] Guid       A pointer to the GUID structure to be filled in.
     2042
     2043  @retval EFI_SUCCESS             The operation was successful.
     2044  @retval EFI_INVALID_PARAMETER   Guid was NULL.
     2045  @retval EFI_INVALID_PARAMETER   GuidName was NULL.
     2046  @retval EFI_NOT_FOUND           GuidName is not a known GUID Name.
     2047**/
     2048EFI_STATUS
     2049EFIAPI
     2050EfiShellGetGuidFromName(
     2051  IN  CONST CHAR16   *GuidName,
     2052  OUT       EFI_GUID *Guid
     2053  )
     2054{
     2055  EFI_GUID    *NewGuid;
     2056  EFI_STATUS  Status;
     2057
     2058  if (Guid == NULL || GuidName == NULL) {
     2059    return (EFI_INVALID_PARAMETER);
     2060  }
     2061 
     2062  Status = GetGuidFromStringName(GuidName, NULL, &NewGuid);
     2063
     2064  if (!EFI_ERROR(Status)) {
     2065    CopyGuid(NewGuid, Guid);
     2066  }
     2067
     2068  return (Status);
     2069}
     2070
     2071/**
     2072  Get the human readable name for a GUID from the value.
     2073
     2074  If Guid is assigned a name, then update *GuidName to point to the name. The callee
     2075  should not modify the value.
     2076
     2077  This function is only available when the major and minor versions in the
     2078  EfiShellProtocol are greater than or equal to 2 and 1, respectively.
     2079
     2080  @param[in]  Guid       A pointer to the GUID being queried.
     2081  @param[out] GuidName   A pointer to a pointer the localized to name for the GUID being requested
     2082
     2083  @retval EFI_SUCCESS             The operation was successful.
     2084  @retval EFI_INVALID_PARAMETER   Guid was NULL.
     2085  @retval EFI_INVALID_PARAMETER   GuidName was NULL.
     2086  @retval EFI_NOT_FOUND           Guid is not assigned a name.
     2087**/
     2088EFI_STATUS
     2089EFIAPI
     2090EfiShellGetGuidName(
     2091  IN  CONST EFI_GUID *Guid,
     2092  OUT CONST CHAR16   **GuidName
     2093  )
     2094{
     2095  CHAR16   *Name;
     2096
     2097  if (Guid == NULL || GuidName == NULL) {
     2098    return (EFI_INVALID_PARAMETER);
     2099  }
     2100
     2101  Name = GetStringNameFromGuid(Guid, NULL);
     2102  if (Name == NULL || StrLen(Name) == 0) {
     2103    SHELL_FREE_NON_NULL(Name);
     2104    return (EFI_NOT_FOUND);
     2105  }
     2106
     2107  *GuidName = AddBufferToFreeList(Name);
     2108
     2109  return (EFI_SUCCESS);
    19512110}
    19522111
     
    20382197  EFI_SHELL_FILE_INFO *ShellInfoNode;
    20392198  EFI_SHELL_FILE_INFO *NewShellNode;
     2199  EFI_FILE_INFO       *FileInfo;
    20402200  BOOLEAN             Directory;
    20412201  CHAR16              *NewFullName;
     
    20652225  if (CurrentFilePattern[0]   == CHAR_NULL
    20662226    &&NextFilePatternStart[0] == CHAR_NULL
    2067    ){
    2068     //
    2069     // Add the current parameter FileHandle to the list, then end...
     2227    ){
     2228    //
     2229    // we want the parent or root node (if no parent)
    20702230    //
    20712231    if (ParentNode == NULL) {
    2072       Status = EFI_INVALID_PARAMETER;
     2232      //
     2233      // We want the root node.  create the node.
     2234      //
     2235      FileInfo = FileHandleGetInfo(FileHandle);
     2236      NewShellNode = CreateAndPopulateShellFileInfo(
     2237        MapName,
     2238        EFI_SUCCESS,
     2239        L"\\",
     2240        FileHandle,
     2241        FileInfo
     2242        );
     2243      SHELL_FREE_NON_NULL(FileInfo);
    20732244    } else {
     2245      //
     2246      // Add the current parameter FileHandle to the list, then end...
     2247      //
    20742248      NewShellNode = InternalDuplicateShellFileInfo((EFI_SHELL_FILE_INFO*)ParentNode, TRUE);
    2075       if (NewShellNode == NULL) {
    2076         Status = EFI_OUT_OF_RESOURCES;
    2077       } else {
    2078         NewShellNode->Handle = NULL;
    2079         if (*FileList == NULL) {
    2080           *FileList = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
    2081           InitializeListHead(&((*FileList)->Link));
    2082         }
    2083 
    2084         //
    2085         // Add to the returning to use list
    2086         //
    2087         InsertTailList(&(*FileList)->Link, &NewShellNode->Link);
    2088 
    2089         Status = EFI_SUCCESS;
     2249    }
     2250    if (NewShellNode == NULL) {
     2251      Status = EFI_OUT_OF_RESOURCES;
     2252    } else {
     2253      NewShellNode->Handle = NULL;
     2254      if (*FileList == NULL) {
     2255        *FileList = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
     2256        InitializeListHead(&((*FileList)->Link));
    20902257      }
     2258
     2259      //
     2260      // Add to the returning to use list
     2261      //
     2262      InsertTailList(&(*FileList)->Link, &NewShellNode->Link);
     2263
     2264      Status = EFI_SUCCESS;
    20912265    }
    20922266  } else {
     
    21112285              Status = EFI_OUT_OF_RESOURCES;
    21122286            } else {
    2113               StrCpy(NewFullName, MapName);
    2114               StrCat(NewFullName, ShellInfoNode->FullName+1);
     2287              StrnCpy(NewFullName, MapName, Size/sizeof(CHAR16)-1);
     2288              StrnCat(NewFullName, ShellInfoNode->FullName+1, (Size/sizeof(CHAR16))-StrLen(NewFullName)-1);
    21152289              FreePool((VOID*)ShellInfoNode->FullName);
    21162290              ShellInfoNode->FullName = NewFullName;
     
    22352409  RootFileHandle = NULL;
    22362410  MapName        = NULL;
    2237   PatternCopy = AllocateZeroPool(StrSize(FilePattern));
     2411  PatternCopy = AllocateCopyPool(StrSize(FilePattern), FilePattern);
    22382412  if (PatternCopy == NULL) {
    22392413    return (EFI_OUT_OF_RESOURCES);
    22402414  }
    2241   StrCpy(PatternCopy, FilePattern);
    22422415
    22432416  PatternCopy = PathCleanUpDirectories(PatternCopy);
     
    23682541
    23692542/**
    2370   This function updated with errata.
    2371 
     2543  Gets the environment variable and Attributes, or list of environment variables.  Can be
     2544  used instead of GetEnv().
     2545
     2546  This function returns the current value of the specified environment variable and
     2547  the Attributes. If no variable name was specified, then all of the known
     2548  variables will be returned.
     2549
     2550  @param[in] Name               A pointer to the environment variable name. If Name is NULL,
     2551                                then the function will return all of the defined shell
     2552                                environment variables. In the case where multiple environment
     2553                                variables are being returned, each variable will be terminated
     2554                                by a NULL, and the list will be terminated by a double NULL.
     2555  @param[out] Attributes        If not NULL, a pointer to the returned attributes bitmask for
     2556                                the environment variable. In the case where Name is NULL, and
     2557                                multiple environment variables are being returned, Attributes
     2558                                is undefined.
     2559
     2560  @retval NULL                  The environment variable doesn't exist.
     2561  @return                       A non-NULL value points to the variable's value. The returned
     2562                                pointer does not need to be freed by the caller.
     2563**/
     2564CONST CHAR16 *
     2565EFIAPI
     2566EfiShellGetEnvEx(
     2567  IN  CONST CHAR16 *Name,
     2568  OUT       UINT32 *Attributes OPTIONAL
     2569  )
     2570{
     2571  EFI_STATUS  Status;
     2572  VOID        *Buffer;
     2573  UINTN       Size;
     2574  LIST_ENTRY  List;
     2575  ENV_VAR_LIST *Node;
     2576  CHAR16      *CurrentWriteLocation;
     2577
     2578  Size = 0;
     2579  Buffer = NULL;
     2580
     2581  if (Name == NULL) {
     2582    //
     2583    // Get all our environment variables
     2584    //
     2585    InitializeListHead(&List);
     2586    Status = GetEnvironmentVariableList(&List);
     2587    if (EFI_ERROR(Status)){
     2588      return (NULL);
     2589    }
     2590
     2591    //
     2592    // Build the semi-colon delimited list. (2 passes)
     2593    //
     2594    for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)
     2595      ; !IsNull(&List, &Node->Link)
     2596      ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)
     2597     ){
     2598      ASSERT(Node->Key != NULL);
     2599      Size += StrSize(Node->Key);
     2600    }
     2601
     2602    Size += 2*sizeof(CHAR16);
     2603
     2604    Buffer = AllocateZeroPool(Size);
     2605    if (Buffer == NULL) {
     2606      if (!IsListEmpty (&List)) {
     2607        FreeEnvironmentVariableList(&List);
     2608      }
     2609      return (NULL);
     2610    }
     2611    CurrentWriteLocation = (CHAR16*)Buffer;
     2612
     2613    for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)
     2614      ; !IsNull(&List, &Node->Link)
     2615      ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)
     2616     ){
     2617      ASSERT(Node->Key != NULL);
     2618      StrnCpy(CurrentWriteLocation, Node->Key,  (Size)/sizeof(CHAR16) - (CurrentWriteLocation - ((CHAR16*)Buffer)) - 1);
     2619      CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;
     2620    }
     2621
     2622    //
     2623    // Free the list...
     2624    //
     2625    if (!IsListEmpty (&List)) {
     2626      FreeEnvironmentVariableList(&List);
     2627    }
     2628  } else {
     2629    //
     2630    // We are doing a specific environment variable
     2631    //
     2632
     2633    //
     2634    // get the size we need for this EnvVariable
     2635    //
     2636    Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name, Attributes, &Size, Buffer);
     2637    if (Status == EFI_BUFFER_TOO_SMALL) {
     2638      //
     2639      // Allocate the space and recall the get function
     2640      //
     2641      Buffer = AllocateZeroPool(Size);
     2642      Status = SHELL_GET_ENVIRONMENT_VARIABLE_AND_ATTRIBUTES(Name, Attributes, &Size, Buffer);
     2643    }
     2644    //
     2645    // we didnt get it (might not exist)
     2646    // free the memory if we allocated any and return NULL
     2647    //
     2648    if (EFI_ERROR(Status)) {
     2649      if (Buffer != NULL) {
     2650        FreePool(Buffer);
     2651      }
     2652      return (NULL);
     2653    }
     2654  }
     2655
     2656  //
     2657  // return the buffer
     2658  //
     2659  return (AddBufferToFreeList(Buffer));
     2660}
     2661
     2662/**
    23722663  Gets either a single or list of environment variables.
    23732664
     
    23862677                                NULL.
    23872678
    2388   @return !=NULL                A pointer to the returned string.
     2679  @retval !=NULL                A pointer to the returned string.
    23892680                                The returned pointer does not need to be freed by the caller.
    23902681
     
    23982689  )
    23992690{
    2400   EFI_STATUS  Status;
    2401   VOID        *Buffer;
    2402   UINTN       Size;
    2403   LIST_ENTRY  List;
    2404   ENV_VAR_LIST *Node;
    2405   CHAR16      *CurrentWriteLocation;
    2406 
    2407   Size = 0;
    2408   Buffer = NULL;
    2409 
    2410   if (Name == NULL) {
    2411     //
    2412     // Get all our environment variables
    2413     //
    2414     InitializeListHead(&List);
    2415     Status = GetEnvironmentVariableList(&List);
    2416     if (EFI_ERROR(Status)){
    2417       return (NULL);
    2418     }
    2419 
    2420     //
    2421     // Build the semi-colon delimited list. (2 passes)
    2422     //
    2423     for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)
    2424       ; !IsNull(&List, &Node->Link)
    2425       ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)
    2426      ){
    2427       ASSERT(Node->Key != NULL);
    2428       Size += StrSize(Node->Key);
    2429     }
    2430 
    2431     Size += 2*sizeof(CHAR16);
    2432 
    2433     Buffer = AllocateZeroPool(Size);
    2434     if (Buffer == NULL) {
    2435       if (!IsListEmpty (&List)) {
    2436         FreeEnvironmentVariableList(&List);
    2437       }
    2438       return (NULL);
    2439     }
    2440     CurrentWriteLocation = (CHAR16*)Buffer;
    2441 
    2442     for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)
    2443       ; !IsNull(&List, &Node->Link)
    2444       ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)
    2445      ){
    2446       ASSERT(Node->Key != NULL);
    2447       StrCpy(CurrentWriteLocation, Node->Key);
    2448       CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;
    2449     }
    2450 
    2451     //
    2452     // Free the list...
    2453     //
    2454     if (!IsListEmpty (&List)) {
    2455       FreeEnvironmentVariableList(&List);
    2456     }
    2457   } else {
    2458     //
    2459     // We are doing a specific environment variable
    2460     //
    2461 
    2462     //
    2463     // get the size we need for this EnvVariable
    2464     //
    2465     Status = SHELL_GET_ENVIRONMENT_VARIABLE(Name, &Size, Buffer);
    2466     if (Status == EFI_BUFFER_TOO_SMALL) {
    2467       //
    2468       // Allocate the space and recall the get function
    2469       //
    2470       Buffer = AllocateZeroPool(Size);
    2471       ASSERT(Buffer != NULL);
    2472       Status = SHELL_GET_ENVIRONMENT_VARIABLE(Name, &Size, Buffer);
    2473     }
    2474     //
    2475     // we didnt get it (might not exist)
    2476     // free the memory if we allocated any and return NULL
    2477     //
    2478     if (EFI_ERROR(Status)) {
    2479       if (Buffer != NULL) {
    2480         FreePool(Buffer);
    2481       }
    2482       return (NULL);
    2483     }
    2484   }
    2485 
    2486   //
    2487   // return the buffer
    2488   //
    2489   return (AddBufferToFreeList(Buffer));
     2691  return (EfiShellGetEnvEx(Name, NULL));
    24902692}
    24912693
     
    28253027{
    28263028  CONST CHAR16  *ManFileName;
     3029  CHAR16        *FixCommand;
     3030  EFI_STATUS    Status;
    28273031
    28283032  ASSERT(HelpText != NULL);
     3033  FixCommand = NULL;
    28293034
    28303035  ManFileName = ShellCommandGetManFileNameHandler(Command);
     
    28333038    return (ProcessManFile(ManFileName, Command, Sections, NULL, HelpText));
    28343039  } else {
    2835     return (ProcessManFile(Command, Command, Sections, NULL, HelpText));
     3040    if ((StrLen(Command)> 4)
     3041    && (Command[StrLen(Command)-1] == L'i' || Command[StrLen(Command)-1] == L'I')
     3042    && (Command[StrLen(Command)-2] == L'f' || Command[StrLen(Command)-2] == L'F')
     3043    && (Command[StrLen(Command)-3] == L'e' || Command[StrLen(Command)-3] == L'E')
     3044    && (Command[StrLen(Command)-4] == L'.')
     3045    ) {
     3046      FixCommand = AllocateZeroPool(StrSize(Command) - 4 * sizeof (CHAR16));
     3047      ASSERT(FixCommand != NULL);
     3048
     3049      StrnCpy(FixCommand, Command, StrLen(Command)-4);
     3050      Status = ProcessManFile(FixCommand, FixCommand, Sections, NULL, HelpText);
     3051      FreePool(FixCommand);
     3052      return Status;
     3053    } else {
     3054      return (ProcessManFile(Command, Command, Sections, NULL, HelpText));
     3055    }
    28363056  }
    28373057}
     
    28853105  )
    28863106{
    2887   UINT64            MaxStorSize;
    2888   UINT64            RemStorSize;
    2889   UINT64            MaxVarSize;
     3107 
    28903108  EFI_STATUS        Status;
    28913109  EFI_GUID          Guid;
    28923110  CHAR16            *VariableName;
    28933111  UINTN             NameSize;
     3112  UINTN             NameBufferSize;
    28943113  CHAR16            *RetVal;
    28953114  UINTN             RetSize;
    2896   CHAR16            *Alias;
    2897 
    2898   Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);
    2899   ASSERT_EFI_ERROR(Status);
    2900 
    2901   VariableName  = AllocateZeroPool((UINTN)MaxVarSize);
     3115
     3116  NameBufferSize = INIT_NAME_BUFFER_SIZE;
     3117  VariableName  = AllocateZeroPool(NameBufferSize);
    29023118  RetSize       = 0;
    29033119  RetVal        = NULL;
     
    29103126
    29113127  while (TRUE) {
    2912     NameSize = (UINTN)MaxVarSize;
     3128    NameSize = NameBufferSize;
    29133129    Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);
    29143130    if (Status == EFI_NOT_FOUND){
    29153131      break;
    2916     }
    2917     ASSERT_EFI_ERROR(Status);
    2918     if (EFI_ERROR(Status)) {
     3132    } else if (Status == EFI_BUFFER_TOO_SMALL) {
     3133      NameBufferSize = NameSize > NameBufferSize * 2 ? NameSize : NameBufferSize * 2;
     3134      SHELL_FREE_NON_NULL(VariableName);
     3135      VariableName = AllocateZeroPool(NameBufferSize);
     3136      if (VariableName == NULL) {
     3137        Status = EFI_OUT_OF_RESOURCES;
     3138        SHELL_FREE_NON_NULL(RetVal);
     3139        RetVal = NULL;
     3140        break;
     3141      }
     3142     
     3143      NameSize = NameBufferSize;
     3144      Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);
     3145    }
     3146   
     3147    if (EFI_ERROR (Status)) {
     3148      SHELL_FREE_NON_NULL(RetVal);
     3149      RetVal = NULL;
    29193150      break;
    29203151    }
     3152   
    29213153    if (CompareGuid(&Guid, &gShellAliasGuid)){
    2922       Alias = GetVariable(VariableName, &gShellAliasGuid);
    29233154      ASSERT((RetVal == NULL && RetSize == 0) || (RetVal != NULL));
    29243155      RetVal = StrnCatGrow(&RetVal, &RetSize, VariableName, 0);
     
    29263157    } // compare guid
    29273158  } // while
    2928   FreePool(VariableName);
     3159  SHELL_FREE_NON_NULL(VariableName);
    29293160
    29303161  return (RetVal);
     3162}
     3163
     3164/**
     3165  Convert a null-terminated unicode string, in-place, to all lowercase.
     3166  Then return it.
     3167 
     3168  @param  Str    The null-terminated string to be converted to all lowercase.
     3169 
     3170  @return        The null-terminated string converted into all lowercase. 
     3171**/
     3172CHAR16 *
     3173ToLower (
     3174  CHAR16 *Str
     3175  )
     3176{
     3177  UINTN Index;
     3178
     3179  for (Index = 0; Str[Index] != L'\0'; Index++) {
     3180    if (Str[Index] >= L'A' && Str[Index] <= L'Z') {
     3181      Str[Index] -= (CHAR16)(L'A' - L'a');
     3182    }
     3183  }
     3184  return Str;
    29313185}
    29323186
     
    29603214  UINT32      Attribs;
    29613215  EFI_STATUS  Status;
    2962 
     3216  CHAR16      *AliasLower;
     3217
     3218  // Convert to lowercase to make aliases case-insensitive
    29633219  if (Alias != NULL) {
     3220    AliasLower = AllocateCopyPool (StrSize (Alias), Alias);
     3221    ASSERT (AliasLower != NULL);
     3222    ToLower (AliasLower);
     3223
    29643224    if (Volatile == NULL) {
    2965       return (AddBufferToFreeList(GetVariable((CHAR16*)Alias, &gShellAliasGuid)));
     3225      return (AddBufferToFreeList(GetVariable(AliasLower, &gShellAliasGuid)));
    29663226    }
    29673227    RetSize = 0;
    29683228    RetVal = NULL;
    2969     Status = gRT->GetVariable((CHAR16*)Alias, &gShellAliasGuid, &Attribs, &RetSize, RetVal);
     3229    Status = gRT->GetVariable(AliasLower, &gShellAliasGuid, &Attribs, &RetSize, RetVal);
    29703230    if (Status == EFI_BUFFER_TOO_SMALL) {
    29713231      RetVal = AllocateZeroPool(RetSize);
    2972       Status = gRT->GetVariable((CHAR16*)Alias, &gShellAliasGuid, &Attribs, &RetSize, RetVal);
     3232      Status = gRT->GetVariable(AliasLower, &gShellAliasGuid, &Attribs, &RetSize, RetVal);
    29733233    }
    29743234    if (EFI_ERROR(Status)) {
     
    29843244    }
    29853245
     3246    FreePool (AliasLower);
    29863247    return (AddBufferToFreeList(RetVal));
    29873248  }
     
    30133274  )
    30143275{
     3276  EFI_STATUS  Status;
     3277  CHAR16      *AliasLower;
     3278
     3279  // Convert to lowercase to make aliases case-insensitive
     3280  if (Alias != NULL) {
     3281    AliasLower = AllocateCopyPool (StrSize (Alias), Alias);
     3282    ASSERT (AliasLower != NULL);
     3283    ToLower (AliasLower);
     3284  } else {
     3285    AliasLower = NULL;
     3286  }
     3287
    30153288  //
    30163289  // We must be trying to remove one if Alias is NULL
     
    30203293    // remove an alias (but passed in COMMAND parameter)
    30213294    //
    3022     return (gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL));
     3295    Status = (gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL));
    30233296  } else {
    30243297    //
     
    30293302    gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL);
    30303303
    3031     return (gRT->SetVariable((CHAR16*)Alias, &gShellAliasGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS|(Volatile?0:EFI_VARIABLE_NON_VOLATILE), StrSize(Command), (VOID*)Command));
    3032   }
     3304    Status = (gRT->SetVariable((CHAR16*)Alias, &gShellAliasGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS|(Volatile?0:EFI_VARIABLE_NON_VOLATILE), StrSize(Command), (VOID*)Command));
     3305  }
     3306
     3307  if (Alias != NULL) {
     3308    FreePool (AliasLower);
     3309  }
     3310  return Status;
    30333311}
    30343312
     
    30523330  @retval EFI_ACCESS_DENIED     The alias is a built-in alias or already existed and Replace was set to
    30533331                                FALSE.
     3332  @retval EFI_INVALID_PARAMETER Command is null or the empty string.
    30543333**/
    30553334EFI_STATUS
     
    30623341  )
    30633342{
    3064   //
    3065   // cant set over a built in alias
    3066   //
    30673343  if (ShellCommandIsOnAliasList(Alias==NULL?Command:Alias)) {
     3344    //
     3345    // cant set over a built in alias
     3346    //
    30683347    return (EFI_ACCESS_DENIED);
    3069   }
    3070   if (Command == NULL || *Command == CHAR_NULL || StrLen(Command) == 0) {
     3348  } else if (Command == NULL || *Command == CHAR_NULL || StrLen(Command) == 0) {
     3349    //
     3350    // Command is null or empty
     3351    //
    30713352    return (EFI_INVALID_PARAMETER);
    3072   }
    3073 
    3074   if (EfiShellGetAlias(Command, NULL) != NULL && !Replace) {
     3353  } else if (EfiShellGetAlias(Command, NULL) != NULL && !Replace) {
     3354    //
     3355    // Alias already exists, Replace not set
     3356    //
    30753357    return (EFI_ACCESS_DENIED);
    3076   }
    3077 
    3078   return (InternalSetAlias(Command, Alias, Volatile));
     3358  } else {
     3359    return (InternalSetAlias(Command, Alias, Volatile));
     3360  }
    30793361}
    30803362
     
    31233405  NULL,
    31243406  SHELL_MAJOR_VERSION,
    3125   SHELL_MINOR_VERSION
     3407  SHELL_MINOR_VERSION,
     3408
     3409  // New for UEFI Shell 2.1
     3410  EfiShellRegisterGuidName,
     3411  EfiShellGetGuidName,
     3412  EfiShellGetGuidFromName,
     3413  EfiShellGetEnvEx
    31263414};
    31273415
     
    33373625  )
    33383626{
    3339 //  ShellPrintEx(-1,-1,L"  <Notify>  ");
    3340    if ((KeyData->Key.UnicodeChar == L'c' || KeyData->Key.UnicodeChar == 3) &&
    3341       (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState  == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))
     3627  if ( ((KeyData->Key.UnicodeChar == L'c') &&
     3628        (KeyData->KeyState.KeyShiftState == (EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED) || KeyData->KeyState.KeyShiftState  == (EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED))) ||
     3629      (KeyData->Key.UnicodeChar == 3)
    33423630      ){
    33433631    if (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak == NULL) {
     
    34293717  return (Status);
    34303718}
     3719
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Application/Shell/ShellProtocol.h

    r48674 r58459  
    33  manipulation, and initialization of EFI_SHELL_PROTOCOL.
    44
    5   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     5  (C) Copyright 2014, Hewlett-Packard Development Company, L.P.
     6  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    67  This program and the accompanying materials
    78  are licensed and made available under the terms and conditions of the BSD License
     
    1718#define _SHELL_PROTOCOL_HEADER_
    1819
    19 #include <Uefi.h>
    20 #include <ShellBase.h>
    21 
    22 #include <Guid/ShellVariableGuid.h>
    23 #include <Guid/ShellMapGuid.h>
    24 #include <Guid/ShellAliasGuid.h>
    25 
    26 #include <Protocol/EfiShell.h>
    27 #include <Protocol/EfiShellParameters.h>
    28 #include <Protocol/SimpleFileSystem.h>
    29 #include <Protocol/DevicePathToText.h>
    30 #include <Protocol/ComponentName2.h>
    31 #include <Protocol/LoadedImage.h>
    32 #include <Protocol/UnicodeCollation.h>
    33 #include <Protocol/DevicePath.h>
    34 #include <Protocol/SimpleTextInEx.h>
    35 
    36 #include <Library/UefiBootServicesTableLib.h>
    37 #include <Library/BaseLib.h>
    38 #include <Library/ShellCommandLib.h>
    39 #include <Library/PrintLib.h>
    40 #include <Library/DevicePathLib.h>
    41 #include <Library/UefiRuntimeServicesTableLib.h>
    42 #include <Library/DebugLib.h>
    43 #include <Library/MemoryAllocationLib.h>
    44 #include <Library/BaseMemoryLib.h>
    45 #include <Library/UefiLib.h>
    46 #include <Library/SortLib.h>
    47 #include <Library/PcdLib.h>
    48 #include <Library/ShellLib.h>
    49 
    50 #include "FileHandleWrappers.h"
    51 #include "ShellEnvVar.h"
    52 #include "ShellManParser.h"
     20#include "Shell.h"
    5321
    5422typedef struct {
     
    467435  internal worker function to run a command via Device Path
    468436
    469   @param ParentImageHandle  A handle of the image that is executing the specified
    470                             command line.
    471   @param DevicePath         device path of the file to execute
    472   @param CommandLine        Points to the NULL-terminated UCS-2 encoded string
    473                             containing the command line. If NULL then the command-
    474                             line will be empty.
    475   @param Environment        Points to a NULL-terminated array of environment
    476                             variables with the format 'x=y', where x is the
    477                             environment variable name and y is the value. If this
    478                             is NULL, then the current shell environment is used.
    479   @param StatusCode         Points to the status code returned by the command.
     437  @param ParentImageHandle      A handle of the image that is executing the specified
     438                                command line.
     439  @param DevicePath             device path of the file to execute
     440  @param CommandLine            Points to the NULL-terminated UCS-2 encoded string
     441                                containing the command line. If NULL then the command-
     442                                line will be empty.
     443  @param Environment            Points to a NULL-terminated array of environment
     444                                variables with the format 'x=y', where x is the
     445                                environment variable name and y is the value. If this
     446                                is NULL, then the current shell environment is used.
     447  @param[out] StartImageStatus  Returned status from gBS->StartImage.
    480448
    481449  @retval EFI_SUCCESS       The command executed successfully. The  status code
     
    488456EFIAPI
    489457InternalShellExecuteDevicePath(
    490   IN CONST EFI_HANDLE *ParentImageHandle,
     458  IN CONST EFI_HANDLE               *ParentImageHandle,
    491459  IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
    492   IN CONST CHAR16 *CommandLine OPTIONAL,
    493   IN CONST CHAR16 **Environment OPTIONAL,
    494   OUT EFI_STATUS *StatusCode OPTIONAL
     460  IN CONST CHAR16                   *CommandLine OPTIONAL,
     461  IN CONST CHAR16                   **Environment OPTIONAL,
     462  OUT EFI_STATUS                    *StartImageStatus OPTIONAL
    495463  );
    496464
     
    589557  @param[in] BasePath         the Path to prepend onto filename for FullPath
    590558  @param[in] Status           Status member initial value.
    591   @param[in] FullName         FullName member initial value.
    592559  @param[in] FileName         FileName member initial value.
    593560  @param[in] Handle           Handle member initial value.
     
    600567  IN CONST CHAR16 *BasePath,
    601568  IN CONST EFI_STATUS Status,
    602   IN CONST CHAR16 *FullName,
    603569  IN CONST CHAR16 *FileName,
    604570  IN CONST SHELL_FILE_HANDLE Handle,
     
    689655  @param Name                   A pointer to the environment variable name
    690656
    691   @return !=NULL                The environment variable's value. The returned
     657  @retval !=NULL                The environment variable's value. The returned
    692658                                pointer does not need to be freed by the caller.
    693659  @retval NULL                  The environment variable doesn't exist.
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Include/Guid/ShellAliasGuid.h

    r48674 r58459  
    2424
    2525#endif
    26 
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Include/Guid/ShellLibHiiGuid.h

    r48674 r58459  
    5555    0xf3d301bb, 0xf4a5, 0x45a8, { 0xb0, 0xb7, 0xfa, 0x99, 0x9c, 0x62, 0x37, 0xae } \
    5656  }
     57#define SHELL_BCFG_HII_GUID \
     58  { \
     59    0x5f5f605d, 0x1583, 0x4a2d, {0xa6, 0xb2, 0xeb, 0x12, 0xda, 0xb4, 0xa2, 0xb6 } \
     60  }
    5761
    5862extern EFI_GUID gHandleParsingHiiGuid;
     
    6468extern EFI_GUID gShellLevel3HiiGuid;
    6569extern EFI_GUID gShellNetwork1HiiGuid;
     70extern EFI_GUID gShellBcfgHiiGuid;
    6671
    6772#endif
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Include/Library/HandleParsingLib.h

    r48674 r58459  
    22  Provides interface to advanced shell functionality for parsing both handle and protocol database.
    33
    4   Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1919
    2020/**
     21  Function to add a new GUID/Name mapping.
     22
     23  This cannot overwrite an existing mapping.
     24
     25  @param[in] Guid       The Guid
     26  @param[in] TheName    The Guid's name
     27  @param[in] Lang       RFC4646 language code list or NULL
     28
     29  @retval EFI_SUCCESS           The operation was sucessful
     30  @retval EFI_ACCESS_DENIED     There was a duplicate
     31  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed
     32**/
     33EFI_STATUS
     34EFIAPI
     35AddNewGuidNameMapping(
     36  IN CONST EFI_GUID *Guid,
     37  IN CONST CHAR16   *TheName,
     38  IN CONST CHAR8    *Lang OPTIONAL
     39  );
     40
     41/**
    2142  Function to get the name of a protocol or struct from it's GUID.
    2243
     
    3960  Function to get the Guid for a protocol or struct based on it's string name.
    4061
     62  Do not free or modify the returned GUID.
     63
    4164  @param[in] Name           The pointer to the string name.
    4265  @param[in] Lang           The pointer to the language code (string).
    43   @param[in] Guid           The pointer to the pointer to the Guid.
     66  @param[out] Guid          The pointer to the pointer to the Guid.
    4467
    4568  @retval EFI_SUCCESS       The operation was successful.
     
    5073  IN CONST CHAR16 *Name,
    5174  IN CONST CHAR8  *Lang OPTIONAL,
    52   IN EFI_GUID     **Guid
     75  OUT EFI_GUID    **Guid
    5376  );
    5477
     
    94117  IN CONST EFI_HANDLE TheHandle,
    95118  IN CONST CHAR8      *Language
     119  );
     120
     121/**
     122  Get best support language for this driver.
     123 
     124  First base on the user input language  to search, second base on the current
     125  platform used language to search, third get the first language from the
     126  support language list. The caller need to free the buffer of the best language.
     127
     128  @param[in] SupportedLanguages      The support languages for this driver.
     129  @param[in] InputLanguage           The user input language.
     130  @param[in] Iso639Language          Whether get language for ISO639.
     131
     132  @return                            The best support language for this driver.
     133**/
     134CHAR8 *
     135EFIAPI
     136GetBestLanguageForDriver (
     137  IN CONST CHAR8  *SupportedLanguages,
     138  IN CONST CHAR8  *InputLanguage,
     139  IN BOOLEAN      Iso639Language
    96140  );
    97141
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Include/Library/ShellCommandLib.h

    r48674 r58459  
    55  This library will not funciton if it is used for UEFI Shell 2.0 Applications.
    66
    7   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     7  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
     8  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    89  This program and the accompanying materials
    910  are licensed and made available under the terms and conditions of the BSD License
     
    2526#include <Protocol/EfiShellParameters.h>
    2627#include <Protocol/UnicodeCollation.h>
    27 #include <Protocol/DevicePathToText.h>
    2828#include <Protocol/SimpleFileSystem.h>
    2929
     
    3434//
    3535extern        EFI_UNICODE_COLLATION_PROTOCOL    *gUnicodeCollation;
    36 extern        EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *gDevPathToText;
    3736extern        CONST CHAR16*                     SupportLevel[];
    3837
     
    587586
    588587/**
     588  Add mappings for any devices without one.  Do not change any existing maps.
     589
     590  @retval EFI_SUCCESS   The operation was successful.
     591**/
     592EFI_STATUS
     593EFIAPI
     594ShellCommandUpdateMapping (
     595  VOID
     596  );
     597
     598/**
    589599  Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
    590600
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Include/Library/ShellLib.h

    r48674 r58459  
    22  Provides interface to shell functionality for shell commands and applications.
    33
    4   Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    10091009
    10101010/**
     1011  Function return the number converted from a hex representation of a number.
     1012
     1013  Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid
     1014  result.  Use ShellConvertStringToUint64 instead.
     1015
     1016  @param[in] String   String representation of a number.
     1017
     1018  @return             The unsigned integer result of the conversion.
     1019  @retval (UINTN)(-1) An error occured.
     1020**/
     1021UINTN
     1022EFIAPI
     1023ShellHexStrToUintn(
     1024  IN CONST CHAR16 *String
     1025  );
     1026
     1027/**
    10111028  Safely append with automatic string resizing given length of Destination and
    10121029  desired length of copy from Source.
     
    13291346  );
    13301347
     1348/**
     1349  Function to delete a file by name
     1350 
     1351  @param[in]       FileName       Pointer to file name to delete.
     1352 
     1353  @retval EFI_SUCCESS             the file was deleted sucessfully
     1354  @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
     1355                                  deleted
     1356  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.
     1357  @retval EFI_NOT_FOUND           The specified file could not be found on the
     1358                                  device or the file system could not be found
     1359                                  on the device.
     1360  @retval EFI_NO_MEDIA            The device has no medium.
     1361  @retval EFI_MEDIA_CHANGED       The device has a different medium in it or the
     1362                                  medium is no longer supported.
     1363  @retval EFI_DEVICE_ERROR        The device reported an error.
     1364  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.
     1365  @retval EFI_WRITE_PROTECTED     The file or medium is write protected.
     1366  @retval EFI_ACCESS_DENIED       The file was opened read only.
     1367  @retval EFI_OUT_OF_RESOURCES    Not enough resources were available to open the
     1368                                  file.
     1369  @retval other                   The file failed to open
     1370**/
     1371EFI_STATUS
     1372EFIAPI
     1373ShellDeleteFileByName(
     1374  IN CONST CHAR16               *FileName
     1375  );
     1376
     1377/**
     1378  Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function.
     1379
     1380  @param[in] CommandToGetHelpOn  Pointer to a string containing the command name of help file to be printed.
     1381  @param[in] SectionToGetHelpOn  Pointer to the section specifier(s).
     1382  @param[in] PrintCommandText    If TRUE, prints the command followed by the help content, otherwise prints
     1383                                 the help content only.
     1384  @retval EFI_DEVICE_ERROR       The help data format was incorrect.
     1385  @retval EFI_NOT_FOUND          The help data could not be found.
     1386  @retval EFI_SUCCESS            The operation was successful.
     1387**/
     1388EFI_STATUS
     1389EFIAPI
     1390ShellPrintHelp (
     1391  IN CONST CHAR16     *CommandToGetHelpOn,
     1392  IN CONST CHAR16     *SectionToGetHelpOn,
     1393  IN BOOLEAN          PrintCommandText
     1394  );
     1395
    13311396#endif // __SHELL_LIB__
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Include/Protocol/EfiShell.h

    r48674 r58459  
    22  EFI Shell protocol as defined in the UEFI Shell 2.0 specification including errata.
    33
    4   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
     4  (C) Copyright 2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    415416
    416417/**
     418  Gets the environment variable and Attributes, or list of environment variables.  Can be
     419  used instead of GetEnv().
     420
     421  This function returns the current value of the specified environment variable and
     422  the Attributes. If no variable name was specified, then all of the known
     423  variables will be returned.
     424
     425  @param[in] Name               A pointer to the environment variable name. If Name is NULL,
     426                                then the function will return all of the defined shell
     427                                environment variables. In the case where multiple environment
     428                                variables are being returned, each variable will be terminated
     429                                by a NULL, and the list will be terminated by a double NULL.
     430  @param[out] Attributes        If not NULL, a pointer to the returned attributes bitmask for
     431                                the environment variable. In the case where Name is NULL, and
     432                                multiple environment variables are being returned, Attributes
     433                                is undefined.
     434
     435  @retval NULL                  The environment variable doesn't exist. 
     436  @return                       The environment variable's value. The returned pointer does not
     437                                need to be freed by the caller. 
     438**/
     439typedef
     440CONST CHAR16 *
     441(EFIAPI *EFI_SHELL_GET_ENV_EX) (
     442  IN  CONST CHAR16 *Name,
     443  OUT       UINT32 *Attributes OPTIONAL
     444  );
     445
     446/**
    417447  Gets the file information from an open file handle.
    418448
     
    485515  IN SHELL_FILE_HANDLE FileHandle,
    486516  OUT UINT64 *Size
     517  );
     518
     519/**
     520  Get the GUID value from a human readable name.
     521
     522  If GuidName is a known GUID name, then update Guid to have the correct value for
     523  that GUID.
     524
     525  This function is only available when the major and minor versions in the
     526  EfiShellProtocol are greater than or equal to 2 and 1, respectively.
     527
     528  @param[in]  GuidName   A pointer to the localized name for the GUID being queried.
     529  @param[out] Guid       A pointer to the GUID structure to be filled in.
     530
     531  @retval EFI_SUCCESS             The operation was successful.
     532  @retval EFI_INVALID_PARAMETER   Guid was NULL.
     533  @retval EFI_INVALID_PARAMETER   GuidName was NULL.
     534  @retval EFI_NOT_FOUND           GuidName is not a known GUID Name.
     535**/
     536typedef
     537EFI_STATUS
     538(EFIAPI *EFI_SHELL_GET_GUID_FROM_NAME)(
     539  IN  CONST CHAR16   *GuidName,
     540  OUT       EFI_GUID *Guid
     541  );
     542
     543/**
     544  Get the human readable name for a GUID from the value.
     545
     546  If Guid is assigned a name, then update *GuidName to point to the name. The callee
     547  should not modify the value.
     548
     549  This function is only available when the major and minor versions in the
     550  EfiShellProtocol are greater than or equal to 2 and 1, respectively.
     551
     552  @param[in]  Guid       A pointer to the GUID being queried.
     553  @param[out] GuidName   A pointer to a pointer the localized to name for the GUID being requested
     554
     555  @retval EFI_SUCCESS             The operation was successful.
     556  @retval EFI_INVALID_PARAMETER   Guid was NULL.
     557  @retval EFI_INVALID_PARAMETER   GuidName was NULL.
     558  @retval EFI_NOT_FOUND           Guid is not assigned a name.
     559**/
     560typedef
     561EFI_STATUS
     562(EFIAPI *EFI_SHELL_GET_GUID_NAME)(
     563  IN  CONST EFI_GUID *Guid,
     564  OUT CONST CHAR16   **GuidName
    487565  );
    488566
     
    730808
    731809/**
     810  Register a GUID and a localized human readable name for it.
     811
     812  If Guid is not assigned a name, then assign GuidName to Guid.  This list of GUID
     813  names must be used whenever a shell command outputs GUID information.
     814
     815  This function is only available when the major and minor versions in the
     816  EfiShellProtocol are greater than or equal to 2 and 1, respectively.
     817
     818  @param[in] Guid       A pointer to the GUID being registered.
     819  @param[in] GuidName   A pointer to the localized name for the GUID being registered.
     820
     821  @retval EFI_SUCCESS             The operation was successful.
     822  @retval EFI_INVALID_PARAMETER   Guid was NULL.
     823  @retval EFI_INVALID_PARAMETER   GuidName was NULL.
     824  @retval EFI_ACCESS_DENIED       Guid already is assigned a name.
     825**/
     826typedef
     827EFI_STATUS
     828(EFIAPI *EFI_SHELL_REGISTER_GUID_NAME)(
     829  IN CONST EFI_GUID *Guid,
     830  IN CONST CHAR16   *GuidName
     831  );
     832
     833/**
    732834  Deletes the duplicate file names files in the given file list.
    733835
     
    9511053  );
    9521054
     1055//
     1056// EFI_SHELL_PROTOCOL has been updated since UEFI Shell Spec 2.0
     1057// Usage of this protocol will require version checking before attempting
     1058// to use any new members.  There is no need to check the version for
     1059// members that existed in UEFI Shell Spec 2.0.
     1060//
     1061// Update below for any future UEFI Shell spec changes to this protocol.
     1062//
     1063// Check EFI_SHELL_PROTOCOL MajorVersion and MinorVersion:
     1064// if ((2 == gEfiShellProtocol->MajorVersion) &&
     1065//     (0 == gEfiShellProtocol->MinorVersion)) {
     1066//   //
     1067//   // Cannot call:
     1068//   // RegisterGuidName - UEFI Shell 2.1
     1069//   // GetGuidName      - UEFI Shell 2.1
     1070//   // GetGuidFromName  - UEFI Shell 2.1
     1071//   // GetEnvEx         - UEFI Shell 2.1
     1072//   //
     1073// } else {
     1074//   //
     1075//   // Can use all members
     1076//   //
     1077// }
     1078//
    9531079typedef struct _EFI_SHELL_PROTOCOL {
    9541080  EFI_SHELL_EXECUTE                         Execute;
     
    9941120  UINT32                                    MajorVersion;
    9951121  UINT32                                    MinorVersion;
     1122  // Added for Shell 2.1
     1123  EFI_SHELL_REGISTER_GUID_NAME              RegisterGuidName;
     1124  EFI_SHELL_GET_GUID_NAME                   GetGuidName;
     1125  EFI_SHELL_GET_GUID_FROM_NAME              GetGuidFromName;
     1126  EFI_SHELL_GET_ENV_EX                      GetEnvEx;
    9961127} EFI_SHELL_PROTOCOL;
    9971128
     
    10001131enum ShellVersion {
    10011132  SHELL_MAJOR_VERSION = 2,
    1002   SHELL_MINOR_VERSION = 0
     1133  SHELL_MINOR_VERSION = 1
    10031134};
    10041135
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Include/Protocol/EfiShellEnvironment2.h

    r48674 r58459  
    321321
    322322/**
    323   This function determins whether a script file is currently being processed.
     323  This function determines whether a script file is currently being processed.
    324324
    325325  A script file (.nsh file) can contain a series of commands and this is useful to
     
    421421
    422422/**
    423   This function determins if the shell application should break.
     423  This function determines if the shell application should break.
    424424
    425425  This is used to inform a shell application that a break condition has been
     
    456456
    457457/**
    458   This function determins if the caller is running under the root shell.
     458  This function determines if the caller is running under the root shell.
    459459
    460460  @retval TRUE                  The caller is running under the root shell.
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Include/ShellBase.h

    r48674 r58459  
    155155}SHELL_STATUS;
    156156
    157 #endif //__SHELL_BASE__
    158 
     157#endif //__SHELL_BASE_
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/BasePathLib/BasePathLib.c

    r48674 r58459  
    22  Provides interface to path manipulation functions.
    33
    4   Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1616#include <Library/PathLib.h>
    1717#include <Library/BaseLib.h>
     18#include <Protocol/SimpleTextIn.h>
    1819
    1920/**
     
    116117  }
    117118
    118 
     119  while ((TempString = StrStr(Path, L"\\\\")) != NULL) {
     120    *TempString = CHAR_NULL;
     121    TempString  += 1;
     122    TempSize = StrSize(TempString);
     123    CopyMem(Path+StrLen(Path), TempString, TempSize);
     124  }
     125  if ((TempString = StrStr(Path, L"\\\\")) != NULL && *(TempString + 1) == CHAR_NULL) {
     126    *(TempString) = CHAR_NULL;
     127  }
    119128
    120129  return (Path);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiFileHandleLib/UefiFileHandleLib.c

    r48674 r58459  
    22  Provides interface to EFI_FILE_HANDLE functionality.
    33
    4   Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    8585    // if we got an error free the memory and return NULL
    8686    //
    87     if (EFI_ERROR(Status)) {
     87    if (EFI_ERROR(Status) && (FileInfo != NULL)) {
    8888      FreePool(FileInfo);
    89       return NULL;
     89      FileInfo = NULL;
    9090    }
    9191  }
     
    120120{
    121121
    122   //
    123   // ASSERT if the FileHandle or FileInfo is NULL
    124   //
    125   ASSERT (FileHandle != NULL);
    126   ASSERT (FileInfo   != NULL);
     122  if (FileHandle == NULL || FileInfo == NULL) {
     123    return (EFI_INVALID_PARAMETER);
     124  }
    127125
    128126  //
     
    172170  )
    173171{
    174   //
    175   // ASSERT if FileHandle is NULL
    176   //
    177   ASSERT (FileHandle != NULL);
     172  if (FileHandle == NULL) {
     173    return (EFI_INVALID_PARAMETER);
     174  }
    178175
    179176  //
     
    216213  )
    217214{
    218   //
    219   // ASSERT if FileHandle is NULL
    220   //
    221   ASSERT (FileHandle != NULL);
     215  if (FileHandle == NULL) {
     216    return (EFI_INVALID_PARAMETER);
     217  }
     218
    222219  //
    223220  // Perform the write based on EFI_FILE_PROTOCOL
     
    244241{
    245242  EFI_STATUS Status;
    246   //
    247   // ASSERT if FileHandle is NULL
    248   //
    249   ASSERT (FileHandle != NULL);
     243
     244  if (FileHandle == NULL) {
     245    return (EFI_INVALID_PARAMETER);
     246  }
     247
    250248  //
    251249  // Perform the Close based on EFI_FILE_PROTOCOL
     
    276274{
    277275  EFI_STATUS Status;
    278   //
    279   // ASSERT if FileHandle is NULL
    280   //
    281   ASSERT (FileHandle != NULL);
     276
     277  if (FileHandle == NULL) {
     278    return (EFI_INVALID_PARAMETER);
     279  }
     280
    282281  //
    283282  // Perform the Delete based on EFI_FILE_PROTOCOL
     
    313312  )
    314313{
    315   //
    316   // ASSERT if FileHandle is NULL
    317   //
    318   ASSERT (FileHandle != NULL);
     314  if (FileHandle == NULL) {
     315    return (EFI_INVALID_PARAMETER);
     316  }
     317
    319318  //
    320319  // Perform the SetPosition based on EFI_FILE_PROTOCOL
     
    345344  )
    346345{
    347   if (Position == NULL) {
    348     return (EFI_INVALID_PARAMETER);
    349   }
    350   //
    351   // ASSERT if FileHandle is NULL
    352   //
    353   ASSERT (FileHandle != NULL);
     346  if (Position == NULL || FileHandle == NULL) {
     347    return (EFI_INVALID_PARAMETER);
     348  }
     349
    354350  //
    355351  // Perform the GetPosition based on EFI_FILE_PROTOCOL
     
    377373  )
    378374{
    379   //
    380   // ASSERT if FileHandle is NULL
    381   //
    382   ASSERT (FileHandle != NULL);
     375  if (FileHandle == NULL) {
     376    return (EFI_INVALID_PARAMETER);
     377  }
     378
    383379  //
    384380  // Perform the Flush based on EFI_FILE_PROTOCOL
     
    390386  function to determine if a given handle is a directory handle
    391387
    392   if DirHandle is NULL then ASSERT()
     388  if DirHandle is NULL then return error
    393389
    394390  open the file information on the DirHandle and verify that the Attribute
     
    409405  EFI_FILE_INFO *DirInfo;
    410406
    411   //
    412   // ASSERT if DirHandle is NULL
    413   //
    414   ASSERT(DirHandle != NULL);
     407  if (DirHandle == NULL) {
     408    return (EFI_INVALID_PARAMETER);
     409  }
    415410
    416411  //
     
    510505  Status = FileHandleRead (DirHandle, &BufferSize, *Buffer);
    511506  ASSERT(Status != EFI_BUFFER_TOO_SMALL);
    512   if (EFI_ERROR(Status)) {
     507  if (EFI_ERROR(Status) || BufferSize == 0) {
    513508    FreePool(*Buffer);
    514509    *Buffer = NULL;
     510    if (BufferSize == 0) {
     511      return (EFI_NOT_FOUND);
     512    }
    515513    return (Status);
    516514  }
     
    547545  UINTN         BufferSize;
    548546
    549   //
    550   // ASSERTs for DirHandle or Buffer or NoFile poitners being NULL
    551   //
    552   ASSERT (DirHandle != NULL);
    553   ASSERT (Buffer    != NULL);
    554   ASSERT (NoFile    != NULL);
     547  if (DirHandle == NULL || Buffer == NULL || NoFile == NULL) {
     548    return (EFI_INVALID_PARAMETER);
     549  }
    555550
    556551  //
     
    582577  Retrieve the size of a file.
    583578
    584   if FileHandle is NULL then ASSERT()
    585   if Size is NULL then ASSERT()
     579  if FileHandle is NULL then return error
     580  if Size is NULL then return error
    586581
    587582  This function extracts the file size info from the FileHandle's EFI_FILE_INFO
     
    603598  EFI_FILE_INFO                 *FileInfo;
    604599
    605   //
    606   // ASSERT for FileHandle or Size being NULL
    607   //
    608   ASSERT (FileHandle != NULL);
    609   ASSERT (Size != NULL);
     600  if (FileHandle == NULL || Size == NULL) {
     601    return (EFI_INVALID_PARAMETER);
     602  }
    610603
    611604  //
     
    633626  Set the size of a file.
    634627
    635   If FileHandle is NULL then ASSERT().
     628  If FileHandle is NULL then return error.
    636629
    637630  This function changes the file size info from the FileHandle's EFI_FILE_INFO
     
    654647  EFI_STATUS                    Status;
    655648
    656   //
    657   // ASSERT for FileHandle or Size being NULL
    658   //
    659   ASSERT (FileHandle != NULL);
     649  if (FileHandle == NULL) {
     650    return (EFI_INVALID_PARAMETER);
     651  }
    660652
    661653  //
     
    699691  Destination.
    700692
    701   if Destination is NULL, then ASSERT()
     693  if Destination is NULL, then return error
    702694  if Destination's current length (including NULL terminator) is already more then
    703695  CurrentSize, then ASSERT()
     
    726718  UINTN CopySize;
    727719
    728   //
    729   // ASSERTs
    730   //
    731   ASSERT(Destination != NULL);
     720  if (Destination == NULL) {
     721    return (NULL);
     722  }
    732723
    733724  //
     
    962953  if (Handle == NULL
    963954    ||Size   == NULL
     955    ||(Buffer==NULL&&*Size!=0)
    964956   ){
    965957    return (EFI_INVALID_PARAMETER);
    966958  }
    967   if (Buffer == NULL) {
    968     ASSERT(*Size == 0);
    969   } else {
     959  if (Buffer != NULL) {
    970960    *Buffer = CHAR_NULL;
    971961  }
     
    10301020  function to write a line of unicode text to a file.
    10311021
    1032   if Handle is NULL, ASSERT.
     1022  if Handle is NULL, return error.
    10331023  if Buffer is NULL, do nothing.  (return SUCCESS)
    10341024
     
    10511041  UINTN      Size;
    10521042
    1053   ASSERT(Handle != NULL);
    1054 
    10551043  if (Buffer == NULL) {
    10561044    return (EFI_SUCCESS);
     1045  }
     1046
     1047  if (Handle == NULL) {
     1048    return (EFI_INVALID_PARAMETER);
    10571049  }
    10581050
     
    10941086  //
    10951087  Buffer = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));
    1096   ASSERT (Buffer != NULL);
     1088  if (Buffer == NULL) {
     1089    return (EFI_OUT_OF_RESOURCES);
     1090  }
    10971091
    10981092  //
     
    11201114  This will NOT work on directories.
    11211115
    1122   If Handle is NULL, then ASSERT.
     1116  If Handle is NULL, then return False.
    11231117
    11241118  @param[in] Handle     the file handle
     
    11371131  BOOLEAN       RetVal;
    11381132
    1139   //
    1140   // ASSERT if Handle is NULL
    1141   //
    1142   ASSERT(Handle != NULL);
     1133  if (Handle == NULL) {
     1134    return (FALSE);
     1135  }
    11431136
    11441137  FileHandleGetPosition(Handle, &Pos);
    11451138  Info = FileHandleGetInfo (Handle);
    1146   ASSERT(Info != NULL);
    1147   FileHandleSetPosition(Handle, Pos);
    11481139
    11491140  if (Info == NULL) {
    11501141    return (FALSE);
    11511142  }
     1143
     1144  FileHandleSetPosition(Handle, Pos);
    11521145
    11531146  if (Pos == Info->FileSize) {
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf

    r48674 r58459  
    22# Provides interface to shell functionality for shell commands and applications.
    33#
    4 # Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. <BR>
     4#   Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved. <BR>
    55#
    66#  This program and the accompanying materials
     
    2020  MODULE_TYPE                    = DXE_DRIVER
    2121  VERSION_STRING                 = 1.0
    22   LIBRARY_CLASS                  = FileHandleLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER
     22  LIBRARY_CLASS                  = FileHandleLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER DXE_RUNTIME_DRIVER
    2323
    2424#
     
    4242
    4343[Protocols]
    44   gEfiSimpleFileSystemProtocolGuid             # ALWAYS_USED
     44  gEfiSimpleFileSystemProtocolGuid              ## SOMETIMES_CONSUMES
    4545
    4646[Guids]
    47   gEfiFileInfoGuid                              # ALWAYS_CONSUMED
     47  gEfiFileInfoGuid                              ## SOMETIMES_CONSUMES ## GUID
    4848
    4949[Pcd.common]
    50   gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize # ALWAYS_CONSUMED
     50  gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize ## SOMETIMES_CONSUMES
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c

    r48674 r58459  
    22  Provides interface to advanced shell functionality for parsing both handle and protocol database.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2013 - 2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    1415
    1516#include "UefiHandleParsingLib.h"
    16 
    17 EFI_HANDLE mHandleParsingHiiHandle;
     17#include "IndustryStandard/Acpi10.h"
     18
     19EFI_HANDLE        mHandleParsingHiiHandle = NULL;
    1820HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};
     21GUID_INFO_BLOCK   *GuidList;
     22UINTN             GuidListCount;
     23/**
     24  Function to translate the EFI_MEMORY_TYPE into a string.
     25
     26  @param[in] Memory     The memory type.
     27
     28  @retval               A string representation of the type allocated from BS Pool.
     29**/
     30CHAR16*
     31EFIAPI
     32ConvertMemoryType (
     33  IN CONST EFI_MEMORY_TYPE Memory
     34  )
     35{
     36  CHAR16 *RetVal;
     37  RetVal = NULL;
     38
     39  switch (Memory) {
     40  case EfiReservedMemoryType:       StrnCatGrow(&RetVal, NULL, L"EfiReservedMemoryType", 0);        break;
     41  case EfiLoaderCode:               StrnCatGrow(&RetVal, NULL, L"EfiLoaderCode", 0);                break;
     42  case EfiLoaderData:               StrnCatGrow(&RetVal, NULL, L"EfiLoaderData", 0);                break;
     43  case EfiBootServicesCode:         StrnCatGrow(&RetVal, NULL, L"EfiBootServicesCode", 0);          break;
     44  case EfiBootServicesData:         StrnCatGrow(&RetVal, NULL, L"EfiBootServicesData", 0);          break;
     45  case EfiRuntimeServicesCode:      StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesCode", 0);       break;
     46  case EfiRuntimeServicesData:      StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesData", 0);       break;
     47  case EfiConventionalMemory:       StrnCatGrow(&RetVal, NULL, L"EfiConventionalMemory", 0);        break;
     48  case EfiUnusableMemory:           StrnCatGrow(&RetVal, NULL, L"EfiUnusableMemory", 0);            break;
     49  case EfiACPIReclaimMemory:        StrnCatGrow(&RetVal, NULL, L"EfiACPIReclaimMemory", 0);         break;
     50  case EfiACPIMemoryNVS:            StrnCatGrow(&RetVal, NULL, L"EfiACPIMemoryNVS", 0);             break;
     51  case EfiMemoryMappedIO:           StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIO", 0);            break;
     52  case EfiMemoryMappedIOPortSpace:  StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIOPortSpace", 0);   break;
     53  case EfiPalCode:                  StrnCatGrow(&RetVal, NULL, L"EfiPalCode", 0);                   break;
     54  case EfiMaxMemoryType:            StrnCatGrow(&RetVal, NULL, L"EfiMaxMemoryType", 0);             break;
     55  default: ASSERT(FALSE);
     56  }
     57  return (RetVal);
     58}
     59
     60/**
     61  Function to translate the EFI_GRAPHICS_PIXEL_FORMAT into a string.
     62
     63  @param[in] Fmt     The format type.
     64
     65  @retval               A string representation of the type allocated from BS Pool.
     66**/
     67CHAR16*
     68EFIAPI
     69ConvertPixelFormat (
     70  IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt
     71  )
     72{
     73  CHAR16 *RetVal;
     74  RetVal = NULL;
     75
     76  switch (Fmt) {
     77  case PixelRedGreenBlueReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelRedGreenBlueReserved8BitPerColor", 0);  break;
     78  case PixelBlueGreenRedReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelBlueGreenRedReserved8BitPerColor", 0);  break;
     79  case PixelBitMask:                          StrnCatGrow(&RetVal, NULL, L"PixelBitMask", 0);                           break;
     80  case PixelBltOnly:                          StrnCatGrow(&RetVal, NULL, L"PixelBltOnly", 0);                           break;
     81  case PixelFormatMax:                        StrnCatGrow(&RetVal, NULL, L"PixelFormatMax", 0);                         break;
     82  default: ASSERT(FALSE);
     83  }
     84  return (RetVal);
     85}
    1986
    2087/**
     
    33100  )
    34101{
    35   mHandleParsingHiiHandle = HiiAddPackages (&gHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);
     102  GuidListCount = 0;
     103  GuidList      = NULL;
     104
     105  //
     106  // Do nothing with mHandleParsingHiiHandle.  Initialize HII as needed.
     107  //
     108  return (EFI_SUCCESS);
     109}
     110
     111/**
     112  Initialization function for HII packages.
     113 
     114**/
     115VOID
     116HandleParsingHiiInit (VOID)
     117{
    36118  if (mHandleParsingHiiHandle == NULL) {
    37     return (EFI_DEVICE_ERROR);
    38   }
    39 
    40   return (EFI_SUCCESS);
     119    mHandleParsingHiiHandle = HiiAddPackages (&gHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);
     120    ASSERT (mHandleParsingHiiHandle != NULL);
     121  }
    41122}
    42123
     
    56137  )
    57138{
     139  UINTN                 LoopCount;
     140
     141  for (LoopCount = 0; GuidList != NULL && LoopCount < GuidListCount; LoopCount++) {
     142    SHELL_FREE_NON_NULL(GuidList[LoopCount].GuidId);
     143  }
     144
     145  SHELL_FREE_NON_NULL(GuidList);
    58146  if (mHandleParsingHiiHandle != NULL) {
    59147    HiiRemovePackages(mHandleParsingHiiHandle);
     
    62150}
    63151
    64 /*
     152/**
     153  Function to dump information about LoadedImage.
     154
     155  This will allocate the return buffer from boot services pool.
     156
     157  @param[in] TheHandle      The handle that has LoadedImage installed.
     158  @param[in] Verbose        TRUE for additional information, FALSE otherwise.
     159
     160  @retval A poitner to a string containing the information.
     161**/
    65162CHAR16*
    66163EFIAPI
     
    70167  )
    71168{
    72   EFI_LOADED_IMAGE_PROTOCOL         *Image;
     169  EFI_LOADED_IMAGE_PROTOCOL         *LoadedImage;
    73170  EFI_STATUS                        Status;
    74   EFI_DEVICE_PATH_PROTOCOL          *DevPath;
    75   EFI_DEVICE_PATH_PROTOCOL          *DevPathNode;
    76   VOID                              *Buffer;
    77   UINTN                             BufferSize;
    78   UINT32                            AuthenticationStatus;
    79   EFI_GUID                          *NameGuid;
    80   EFI_FIRMWARE_VOLUME_PROTOCOL      *FV;
    81   EFI_FIRMWARE_VOLUME2_PROTOCOL     *FV2;
    82 
    83   FV          = NULL;
    84   FV2         = NULL;
    85   Buffer      = NULL;
    86   BufferSize  = 0;
    87 
    88   Status      = HandleProtocol (
     171  CHAR16                            *RetVal;
     172  CHAR16                            *Temp;
     173  CHAR16                            *CodeType;
     174  CHAR16                            *DataType;
     175
     176  if (!Verbose) {
     177    return (CatSPrint(NULL, L"LoadedImage"));
     178  }
     179
     180  HandleParsingHiiInit();
     181
     182  Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);
     183  RetVal = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));
     184  if (Temp == NULL || RetVal == NULL) {
     185    SHELL_FREE_NON_NULL(Temp);
     186    SHELL_FREE_NON_NULL(RetVal);
     187    return NULL;
     188  }
     189
     190  Status = gBS->OpenProtocol (
     191                TheHandle,
     192                &gEfiLoadedImageProtocolGuid,
     193                (VOID**)&LoadedImage,
     194                gImageHandle,
     195                NULL,
     196                EFI_OPEN_PROTOCOL_GET_PROTOCOL
     197               );
     198
     199  if (EFI_ERROR (Status)) {
     200    SHELL_FREE_NON_NULL (Temp);
     201    SHELL_FREE_NON_NULL (RetVal);
     202    return NULL;
     203  }
     204
     205  DataType = ConvertMemoryType(LoadedImage->ImageDataType);
     206  CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);
     207
     208  RetVal = CatSPrint(RetVal,
     209                      Temp,
     210                      LoadedImage->Revision,
     211                      LoadedImage->ParentHandle,
     212                      LoadedImage->SystemTable,
     213                      LoadedImage->DeviceHandle,
     214                      LoadedImage->FilePath,
     215                      LoadedImage->LoadOptionsSize,
     216                      LoadedImage->LoadOptions,
     217                      LoadedImage->ImageBase,
     218                      LoadedImage->ImageSize,
     219                      CodeType,
     220                      DataType,
     221                      LoadedImage->Unload);
     222
     223 
     224  SHELL_FREE_NON_NULL(Temp);
     225  SHELL_FREE_NON_NULL(CodeType);
     226  SHELL_FREE_NON_NULL(DataType);
     227
     228  return RetVal;
     229}
     230
     231/**
     232  Function to dump information about GOP.
     233
     234  This will allocate the return buffer from boot services pool.
     235
     236  @param[in] TheHandle      The handle that has LoadedImage installed.
     237  @param[in] Verbose        TRUE for additional information, FALSE otherwise.
     238
     239  @retval A poitner to a string containing the information.
     240**/
     241CHAR16*
     242EFIAPI
     243GraphicsOutputProtocolDumpInformation(
     244  IN CONST EFI_HANDLE TheHandle,
     245  IN CONST BOOLEAN    Verbose
     246  )
     247{
     248  EFI_GRAPHICS_OUTPUT_PROTOCOL      *GraphicsOutput;
     249  EFI_STATUS                        Status;
     250  CHAR16                            *RetVal;
     251  CHAR16                            *Temp;
     252  CHAR16                            *Fmt;
     253
     254  if (!Verbose) {
     255    return (CatSPrint(NULL, L"GraphicsOutput"));
     256  }
     257
     258  HandleParsingHiiInit();
     259
     260  Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_GOP_DUMP_MAIN), NULL);
     261  RetVal = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));
     262  if (Temp == NULL || RetVal == NULL) {
     263    SHELL_FREE_NON_NULL(Temp);
     264    SHELL_FREE_NON_NULL(RetVal);
     265    return NULL;
     266  }
     267
     268  Status = gBS->OpenProtocol (
     269                TheHandle,
     270                &gEfiGraphicsOutputProtocolGuid,
     271                (VOID**)&GraphicsOutput,
     272                gImageHandle,
     273                NULL,
     274                EFI_OPEN_PROTOCOL_GET_PROTOCOL
     275               );
     276
     277  if (EFI_ERROR (Status)) {
     278    SHELL_FREE_NON_NULL (Temp);
     279    SHELL_FREE_NON_NULL (RetVal);
     280    return NULL;
     281  }
     282
     283  Fmt = ConvertPixelFormat(GraphicsOutput->Mode->Info->PixelFormat);
     284
     285  RetVal = CatSPrint(RetVal,
     286                      Temp,
     287                      GraphicsOutput->Mode->MaxMode,
     288                      GraphicsOutput->Mode->Mode,
     289                      GraphicsOutput->Mode->FrameBufferBase,
     290                      (UINT64)GraphicsOutput->Mode->FrameBufferSize,
     291                      (UINT64)GraphicsOutput->Mode->SizeOfInfo,
     292                      GraphicsOutput->Mode->Info->Version,
     293                      GraphicsOutput->Mode->Info->HorizontalResolution,
     294                      GraphicsOutput->Mode->Info->VerticalResolution,
     295                      Fmt,
     296                      GraphicsOutput->Mode->Info->PixelsPerScanLine,
     297                      GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.RedMask,
     298                      GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.GreenMask,
     299                      GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.BlueMask
     300                      );
     301 
     302  SHELL_FREE_NON_NULL(Temp);
     303  SHELL_FREE_NON_NULL(Fmt);
     304
     305  return RetVal;
     306}
     307
     308/**
     309  Function to dump information about PciRootBridgeIo.
     310
     311  This will allocate the return buffer from boot services pool.
     312
     313  @param[in] TheHandle      The handle that has PciRootBridgeIo installed.
     314  @param[in] Verbose        TRUE for additional information, FALSE otherwise.
     315
     316  @retval A poitner to a string containing the information.
     317**/
     318CHAR16*
     319EFIAPI
     320PciRootBridgeIoDumpInformation(
     321  IN CONST EFI_HANDLE TheHandle,
     322  IN CONST BOOLEAN    Verbose
     323  )
     324{
     325  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   *PciRootBridgeIo;
     326  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration;
     327  UINT64                            Supports;
     328  UINT64                            Attributes;
     329  CHAR16                            *Temp;
     330  CHAR16                            *Temp2;
     331  CHAR16                            *RetVal;
     332  EFI_STATUS                        Status;
     333
     334  RetVal  = NULL;
     335
     336  if (!Verbose) {
     337    return (CatSPrint(NULL, L"PciRootBridgeIo"));
     338  }
     339
     340  HandleParsingHiiInit();
     341
     342  Status = gBS->HandleProtocol(
    89343    TheHandle,
    90     &gEfiLoadedImageProtocolGuid,
    91     &Image);
    92   ASSERT_EFI_ERROR(Status);
    93 
    94   DevPath     = UnpackDevicePath (Image->FilePath);
    95 
    96   if (DevPath == NULL) {
     344    &gEfiPciRootBridgeIoProtocolGuid,
     345    (VOID**)&PciRootBridgeIo);
     346
     347  if (EFI_ERROR(Status)) {
    97348    return NULL;
    98349  }
    99350
    100   DevPathNode = DevPath;
    101 
    102   while (!IsDevicePathEnd (DevPathNode)) {
    103     //
    104     // Find the Fv File path
    105     //
    106     NameGuid = GetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)DevPathNode);
    107     if (NameGuid != NULL) {
    108       Status = BS->HandleProtocol (
    109                     Image->DeviceHandle,
    110                     &gEfiFirmwareVolumeProtocolGuid,
    111                     &FV
    112                    );
    113       if (!EFI_ERROR (Status)) {
    114         Status = FV->ReadSection (
    115                       FV,
    116                       NameGuid,
    117                       EFI_SECTION_USER_INTERFACE,
    118                       0,
    119                       &Buffer,
    120                       &BufferSize,
    121                       &AuthenticationStatus
    122                      );
    123         if (!EFI_ERROR (Status)) {
    124           break;
    125         }
    126 
    127         Buffer = NULL;
    128       } else {
    129         Status = BS->HandleProtocol (
    130                       Image->DeviceHandle,
    131                       &gEfiFirmwareVolume2ProtocolGuid,
    132                       &FV2
    133                      );
    134         if (!EFI_ERROR (Status)) {
    135           Status = FV2->ReadSection (
    136                           FV2,
    137                           NameGuid,
    138                           EFI_SECTION_USER_INTERFACE,
    139                           0,
    140                           &Buffer,
    141                           &BufferSize,
    142                           &AuthenticationStatus
    143                          );
    144           if (!EFI_ERROR (Status)) {
    145             break;
    146           }
    147 
    148           Buffer = NULL;
    149         }
     351  Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_PH), NULL);
     352  ASSERT (Temp != NULL);
     353  Temp2 = CatSPrint(L"\r\n", Temp, PciRootBridgeIo->ParentHandle);
     354  FreePool(Temp);
     355  RetVal = Temp2;
     356  Temp2 = NULL;
     357 
     358  Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SEG), NULL);
     359  ASSERT (Temp != NULL);
     360  Temp2 = CatSPrint(RetVal, Temp, PciRootBridgeIo->SegmentNumber);
     361  FreePool(Temp);
     362  FreePool(RetVal);
     363  RetVal = Temp2;
     364  Temp2 = NULL;
     365
     366  Supports   = 0;
     367  Attributes = 0;
     368  Status = PciRootBridgeIo->GetAttributes (PciRootBridgeIo, &Supports, &Attributes);
     369  if (!EFI_ERROR(Status)) {
     370    Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_ATT), NULL);
     371    ASSERT (Temp != NULL);   
     372    Temp2 = CatSPrint(RetVal, Temp, Attributes);
     373    FreePool(Temp);
     374    FreePool(RetVal);
     375    RetVal = Temp2;
     376    Temp2 = NULL;
     377   
     378    Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS), NULL);
     379    ASSERT (Temp != NULL);
     380    Temp2 = CatSPrint(RetVal, Temp, Supports);
     381    FreePool(Temp);
     382    FreePool(RetVal);
     383    RetVal = Temp2;
     384    Temp2 = NULL;
     385  }
     386
     387  Configuration   = NULL;
     388  Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Configuration);
     389  if (!EFI_ERROR(Status) && Configuration != NULL) {
     390    Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_TITLE), NULL);
     391    ASSERT (Temp != NULL);
     392    Temp2 = CatSPrint(RetVal, Temp, Supports);
     393    FreePool(Temp);
     394    FreePool(RetVal);
     395    RetVal = Temp2;
     396    Temp2 = NULL;
     397    while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
     398      Temp = NULL;
     399      switch (Configuration->ResType) {
     400      case ACPI_ADDRESS_SPACE_TYPE_MEM:
     401        Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_MEM), NULL);
     402        break;
     403      case ACPI_ADDRESS_SPACE_TYPE_IO:
     404        Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_IO), NULL);
     405        break;
     406      case ACPI_ADDRESS_SPACE_TYPE_BUS:
     407        Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_BUS), NULL);
     408        break;
    150409      }
    151     }
    152     //
    153     // Next device path node
    154     //
    155     DevPathNode = NextDevicePathNode (DevPathNode);
    156   }
    157 
    158   FreePool (DevPath);
    159   return Buffer;
    160 }
    161 */
     410      if (Temp != NULL) {
     411        Temp2 = CatSPrint(RetVal, L"%s", Temp);
     412        FreePool(Temp);
     413        FreePool(RetVal);
     414        RetVal = Temp2;
     415        Temp2 = NULL;
     416      }
     417
     418      Temp2 = CatSPrint(RetVal,
     419        L"%H%02x    %016lx  %016lx  %02x%N\r\n",
     420        Configuration->SpecificFlag,
     421        Configuration->AddrRangeMin,
     422        Configuration->AddrRangeMax,
     423        Configuration->AddrSpaceGranularity
     424        );
     425      FreePool(RetVal);
     426      RetVal = Temp2;
     427      Temp2 = NULL;
     428      Configuration++;
     429    }
     430  }
     431  return (RetVal);
     432}
    162433
    163434/**
     
    191462    return (NULL);
    192463  }
     464
     465  HandleParsingHiiInit();
    193466
    194467  RetVal  = NULL;
     
    225498      Index == Dev->Mode->Mode ? L'*' : L' ',
    226499      Index,
    227       !EFI_ERROR(Status)?Col:-1,
    228       !EFI_ERROR(Status)?Row:-1
     500      !EFI_ERROR(Status)?(INTN)Col:-1,
     501      !EFI_ERROR(Status)?(INTN)Row:-1
    229502     );
    230503  }
     
    290563  CHAR16                            *Temp2;
    291564  EFI_STATUS                        Status;
    292   EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevPathToText;
    293565  Temp = NULL;
    294566
    295   Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID**)&DevPathToText);
     567  Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    296568  if (!EFI_ERROR(Status)) {
    297     Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    298     if (!EFI_ERROR(Status)) {
    299       //
    300       // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
    301       //
    302       Temp = DevPathToText->ConvertDevicePathToText(DevPath, TRUE, TRUE);
    303       gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);
    304     }
     569    //
     570    // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
     571    //
     572    Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);
     573    gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);
    305574  }
    306575  if (!Verbose && Temp != NULL && StrLen(Temp) > 30) {
     
    318587#define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
    319588  { \
    320     0x58c518b1, 0x76f3, 0x11d4, 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
     589    0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
    321590  }
    322591
    323592#define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
    324593  { \
    325     0x96eb4ad6, 0xa32a, 0x11d4, 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
     594    0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
    326595  }
    327596
    328597#define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
    329598  { \
    330     0xc95a93d, 0xa006, 0x11d4, 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
     599    0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
    331600  }
    332601STATIC CONST EFI_GUID WinNtThunkProtocolGuid = LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID;
     
    334603STATIC CONST EFI_GUID WinNtSerialPortGuid    = LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID;
    335604
    336 STATIC CONST PROTOCOL_INFO_BLOCK mGuidStringListNT[] = {
     605STATIC CONST GUID_INFO_BLOCK mGuidStringListNT[] = {
    337606  {STRING_TOKEN(STR_WINNT_THUNK),           (EFI_GUID*)&WinNtThunkProtocolGuid,               NULL},
    338607  {STRING_TOKEN(STR_WINNT_DRIVER_IO),       (EFI_GUID*)&WinNtIoProtocolGuid,                  NULL},
     
    341610};
    342611
    343 STATIC CONST PROTOCOL_INFO_BLOCK mGuidStringList[] = {
    344   {STRING_TOKEN(STR_LOADED_IMAGE),          &gEfiLoadedImageProtocolGuid,                     NULL},
     612STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {
     613  {STRING_TOKEN(STR_LOADED_IMAGE),          &gEfiLoadedImageProtocolGuid,                     LoadedImageProtocolDumpInformation},
    345614  {STRING_TOKEN(STR_DEVICE_PATH),           &gEfiDevicePathProtocolGuid,                      DevicePathProtocolDumpInformation},
    346615  {STRING_TOKEN(STR_IMAGE_PATH),            &gEfiLoadedImageDevicePathProtocolGuid,           DevicePathProtocolDumpInformation},
     
    367636  {STRING_TOKEN(STR_ABS_POINTER),           &gEfiAbsolutePointerProtocolGuid,                 NULL},
    368637  {STRING_TOKEN(STR_SERIAL_IO),             &gEfiSerialIoProtocolGuid,                        NULL},
    369   {STRING_TOKEN(STR_GRAPHICS_OUTPUT),       &gEfiGraphicsOutputProtocolGuid,                  NULL},
     638  {STRING_TOKEN(STR_GRAPHICS_OUTPUT),       &gEfiGraphicsOutputProtocolGuid,                  GraphicsOutputProtocolDumpInformation},
    370639  {STRING_TOKEN(STR_EDID_DISCOVERED),       &gEfiEdidDiscoveredProtocolGuid,                  NULL},
    371640  {STRING_TOKEN(STR_EDID_ACTIVE),           &gEfiEdidActiveProtocolGuid,                      NULL},
     
    377646  {STRING_TOKEN(STR_LOAD_FILE2),            &gEfiLoadFile2ProtocolGuid,                       NULL},
    378647  {STRING_TOKEN(STR_SIMPLE_FILE_SYS),       &gEfiSimpleFileSystemProtocolGuid,                NULL},
    379   {STRING_TOKEN(STR_FILE_INFO),             &gEfiFileInfoGuid,                                NULL},
    380   {STRING_TOKEN(STR_FILE_SYS_INFO),         &gEfiFileSystemInfoGuid,                          NULL},
    381648  {STRING_TOKEN(STR_TAPE_IO),               &gEfiTapeIoProtocolGuid,                          NULL},
    382649  {STRING_TOKEN(STR_DISK_IO),               &gEfiDiskIoProtocolGuid,                          NULL},
     
    384651  {STRING_TOKEN(STR_UC),                    &gEfiUnicodeCollationProtocolGuid,                NULL},
    385652  {STRING_TOKEN(STR_UC2),                   &gEfiUnicodeCollation2ProtocolGuid,               NULL},
    386   {STRING_TOKEN(STR_PCIRB_IO),              &gEfiPciRootBridgeIoProtocolGuid,                 NULL},
     653  {STRING_TOKEN(STR_PCIRB_IO),              &gEfiPciRootBridgeIoProtocolGuid,                 PciRootBridgeIoDumpInformation},
    387654  {STRING_TOKEN(STR_PCI_IO),                &gEfiPciIoProtocolGuid,                           NULL},
    388655  {STRING_TOKEN(STR_SCSI_PT),               &gEfiScsiPassThruProtocolGuid,                    NULL},
     
    415682  {STRING_TOKEN(STR_IPV4),                  &gEfiIp4ProtocolGuid,                             NULL},
    416683  {STRING_TOKEN(STR_IPV4_CFG),              &gEfiIp4ConfigProtocolGuid,                       NULL},
    417   {STRING_TOKEN(STR_SHELL_PARAMETERS),      &gEfiShellParametersProtocolGuid,                 NULL},
    418   {STRING_TOKEN(STR_SHELL),                 &gEfiShellProtocolGuid,                           NULL},
    419   {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE),   &gEfiGlobalVariableGuid,                          NULL},
    420684  {STRING_TOKEN(STR_UDPV4_SB),              &gEfiUdp4ServiceBindingProtocolGuid,              NULL},
    421685  {STRING_TOKEN(STR_UDPV4),                 &gEfiUdp4ProtocolGuid,                            NULL},
     
    432696  {STRING_TOKEN(STR_HII_CONFIG_ACC),        &gEfiHiiConfigAccessProtocolGuid,                 NULL},
    433697  {STRING_TOKEN(STR_HII_FORM_BROWSER2),     &gEfiFormBrowser2ProtocolGuid,                    NULL},
     698  {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE),   &gEfiDriverFamilyOverrideProtocolGuid,            NULL},
     699  {STRING_TOKEN(STR_PCD),                   &gPcdProtocolGuid,                                NULL},
     700  {STRING_TOKEN(STR_TCG),                   &gEfiTcgProtocolGuid,                             NULL},
     701  {STRING_TOKEN(STR_HII_PACKAGE_LIST),      &gEfiHiiPackageListProtocolGuid,                  NULL},
     702
     703//
     704// the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
     705//
    434706  {STRING_TOKEN(STR_SHELL_INTERFACE),       &gEfiShellInterfaceGuid,                          NULL},
    435707  {STRING_TOKEN(STR_SHELL_ENV2),            &gEfiShellEnvironment2Guid,                       NULL},
     
    442714  {STRING_TOKEN(STR_DRIVER_CONFIG),         &gEfiDriverConfigurationProtocolGuid,             NULL},
    443715  {STRING_TOKEN(STR_DRIVER_CONFIG2),        &gEfiDriverConfiguration2ProtocolGuid,            NULL},
     716
     717//
     718// the ones under this are GUID identified structs, not protocols
     719//
     720  {STRING_TOKEN(STR_FILE_INFO),             &gEfiFileInfoGuid,                                NULL},
     721  {STRING_TOKEN(STR_FILE_SYS_INFO),         &gEfiFileSystemInfoGuid,                          NULL},
     722
     723//
     724// the ones under this are misc GUIDS.
     725//
     726  {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE),   &gEfiGlobalVariableGuid,                          NULL},
     727
     728//
     729// UEFI 2.2
     730//
     731  {STRING_TOKEN(STR_IP6_SB),                &gEfiIp6ServiceBindingProtocolGuid,               NULL},
     732  {STRING_TOKEN(STR_IP6),                   &gEfiIp6ProtocolGuid,                             NULL},
     733  {STRING_TOKEN(STR_IP6_CONFIG),            &gEfiIp6ConfigProtocolGuid,                       NULL},
     734  {STRING_TOKEN(STR_MTFTP6_SB),             &gEfiMtftp6ServiceBindingProtocolGuid,            NULL},
     735  {STRING_TOKEN(STR_MTFTP6),                &gEfiMtftp6ProtocolGuid,                          NULL},
     736  {STRING_TOKEN(STR_DHCP6_SB),              &gEfiDhcp6ServiceBindingProtocolGuid,             NULL},
     737  {STRING_TOKEN(STR_DHCP6),                 &gEfiDhcp6ProtocolGuid,                           NULL},
     738  {STRING_TOKEN(STR_UDP6_SB),               &gEfiUdp6ServiceBindingProtocolGuid,              NULL},
     739  {STRING_TOKEN(STR_UDP6),                  &gEfiUdp6ProtocolGuid,                            NULL},
     740  {STRING_TOKEN(STR_TCP6_SB),               &gEfiTcp6ServiceBindingProtocolGuid,              NULL},
     741  {STRING_TOKEN(STR_TCP6),                  &gEfiTcp6ProtocolGuid,                            NULL},
     742  {STRING_TOKEN(STR_VLAN_CONFIG),           &gEfiVlanConfigProtocolGuid,                      NULL},
     743  {STRING_TOKEN(STR_EAP),                   &gEfiEapProtocolGuid,                             NULL},
     744  {STRING_TOKEN(STR_EAP_MGMT),              &gEfiEapManagementProtocolGuid,                   NULL},
     745  {STRING_TOKEN(STR_FTP4_SB),               &gEfiFtp4ServiceBindingProtocolGuid,              NULL},
     746  {STRING_TOKEN(STR_FTP4),                  &gEfiFtp4ProtocolGuid,                            NULL},
     747  {STRING_TOKEN(STR_IP_SEC_CONFIG),         &gEfiIpSecConfigProtocolGuid,                     NULL},
     748  {STRING_TOKEN(STR_DH),                    &gEfiDriverHealthProtocolGuid,                    NULL},
     749  {STRING_TOKEN(STR_DEF_IMG_LOAD),          &gEfiDeferredImageLoadProtocolGuid,               NULL},
     750  {STRING_TOKEN(STR_USER_CRED),             &gEfiUserCredentialProtocolGuid,                  NULL},
     751  {STRING_TOKEN(STR_USER_MNGR),             &gEfiUserManagerProtocolGuid,                     NULL},
     752  {STRING_TOKEN(STR_ATA_PASS_THRU),         &gEfiAtaPassThruProtocolGuid,                     NULL},
     753
     754//
     755// UEFI 2.3
     756//
     757  {STRING_TOKEN(STR_FW_MGMT),               &gEfiFirmwareManagementProtocolGuid,              NULL},
     758  {STRING_TOKEN(STR_IP_SEC),                &gEfiIpSecProtocolGuid,                           NULL},
     759  {STRING_TOKEN(STR_IP_SEC2),               &gEfiIpSec2ProtocolGuid,                          NULL},
     760
     761//
     762// UEFI 2.3.1
     763//
     764  {STRING_TOKEN(STR_KMS),                   &gEfiKmsProtocolGuid,                             NULL},
     765  {STRING_TOKEN(STR_BLK_IO2),               &gEfiBlockIo2ProtocolGuid,                        NULL},
     766  {STRING_TOKEN(STR_SSC),                   &gEfiStorageSecurityCommandProtocolGuid,          NULL},
     767  {STRING_TOKEN(STR_UCRED2),                &gEfiUserCredential2ProtocolGuid,                 NULL},
     768
     769//
     770// UEFI 2.4
     771//
     772  {STRING_TOKEN(STR_DISK_IO2),              &gEfiDiskIo2ProtocolGuid,                         NULL},
     773  {STRING_TOKEN(STR_ADAPTER_INFO),          &gEfiAdapterInformationProtocolGuid,              NULL},
     774
     775//
     776// PI Spec ones
     777//
     778  {STRING_TOKEN(STR_IDE_CONT_INIT),         &gEfiIdeControllerInitProtocolGuid,               NULL},
     779
     780//
     781// UEFI Shell Spec 2.0
     782//
     783  {STRING_TOKEN(STR_SHELL_PARAMETERS),      &gEfiShellParametersProtocolGuid,                 NULL},
     784  {STRING_TOKEN(STR_SHELL),                 &gEfiShellProtocolGuid,                           NULL},
     785
     786//
     787// UEFI Shell Spec 2.1
     788//
     789  {STRING_TOKEN(STR_SHELL_DYNAMIC),         &gEfiShellDynamicCommandProtocolGuid,             NULL},
     790
     791//
     792// terminator
     793//
    444794  {STRING_TOKEN(STR_UNKNOWN_DEVICE),        NULL,                                             NULL},
    445795};
     
    454804  @return                       The node.
    455805**/
    456 CONST PROTOCOL_INFO_BLOCK *
     806CONST GUID_INFO_BLOCK *
    457807EFIAPI
    458808InternalShellGetNodeFromGuid(
     
    460810  )
    461811{
    462   CONST PROTOCOL_INFO_BLOCK *ListWalker;
     812  CONST GUID_INFO_BLOCK *ListWalker;
     813  UINTN                 LoopCount;
    463814
    464815  ASSERT(Guid != NULL);
     816
     817  for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {
     818    if (CompareGuid(ListWalker->GuidId, Guid)) {
     819      return (ListWalker);
     820    }
     821  }
    465822
    466823  if (PcdGetBool(PcdShellIncludeNtGuids)) {
     
    476833    }
    477834  }
    478   return (ListWalker);
     835  return (NULL);
     836}
     837
     838/**
     839Function to add a new GUID/Name mapping.
     840
     841@param[in] Guid       The Guid
     842@param[in] NameID     The STRING id of the HII string to use
     843@param[in] DumpFunc   The pointer to the dump function
     844
     845
     846@retval EFI_SUCCESS           The operation was sucessful
     847@retval EFI_OUT_OF_RESOURCES  A memory allocation failed
     848@retval EFI_INVALID_PARAMETER Guid NameId was invalid
     849**/
     850EFI_STATUS
     851EFIAPI
     852InsertNewGuidNameMapping(
     853  IN CONST EFI_GUID           *Guid,
     854  IN CONST EFI_STRING_ID      NameID,
     855  IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
     856  )
     857{
     858  ASSERT(Guid   != NULL);
     859  ASSERT(NameID != 0);
     860
     861  GuidList = ReallocatePool(GuidListCount * sizeof(GUID_INFO_BLOCK), GuidListCount+1 * sizeof(GUID_INFO_BLOCK), GuidList);
     862  if (GuidList == NULL) {
     863    GuidListCount = 0;
     864    return (EFI_OUT_OF_RESOURCES);
     865  }
     866  GuidListCount++;
     867
     868  GuidList[GuidListCount - 1].GuidId   = AllocateCopyPool(sizeof(EFI_GUID), Guid);
     869  GuidList[GuidListCount - 1].StringId = NameID;
     870  GuidList[GuidListCount - 1].DumpInfo = DumpFunc;
     871
     872  if (GuidList[GuidListCount - 1].GuidId == NULL) {
     873    return (EFI_OUT_OF_RESOURCES);
     874  }
     875
     876  return (EFI_SUCCESS);
     877}
     878
     879/**
     880  Function to add a new GUID/Name mapping.
     881
     882  This cannot overwrite an existing mapping.
     883
     884  @param[in] Guid       The Guid
     885  @param[in] TheName    The Guid's name
     886  @param[in] Lang       RFC4646 language code list or NULL
     887
     888  @retval EFI_SUCCESS           The operation was sucessful
     889  @retval EFI_ACCESS_DENIED     There was a duplicate
     890  @retval EFI_OUT_OF_RESOURCES  A memory allocation failed
     891  @retval EFI_INVALID_PARAMETER Guid or TheName was NULL
     892**/
     893EFI_STATUS
     894EFIAPI
     895AddNewGuidNameMapping(
     896  IN CONST EFI_GUID *Guid,
     897  IN CONST CHAR16   *TheName,
     898  IN CONST CHAR8    *Lang OPTIONAL
     899  )
     900{
     901  CONST GUID_INFO_BLOCK *Temp;
     902  EFI_STRING_ID         NameID;
     903
     904  HandleParsingHiiInit();
     905
     906  if (Guid == NULL || TheName == NULL){
     907    return (EFI_INVALID_PARAMETER);
     908  }
     909
     910  if ((Temp = InternalShellGetNodeFromGuid(Guid)) != NULL) {
     911    return (EFI_ACCESS_DENIED);
     912  }
     913
     914  NameID = HiiSetString(mHandleParsingHiiHandle, 0, (CHAR16*)TheName, Lang);
     915  if (NameID == 0) {
     916    return (EFI_OUT_OF_RESOURCES);
     917  }
     918
     919  return (InsertNewGuidNameMapping(Guid, NameID, NULL));
    479920}
    480921
     
    497938  )
    498939{
    499   CONST PROTOCOL_INFO_BLOCK *Id;
     940  CONST GUID_INFO_BLOCK *Id;
     941
     942  HandleParsingHiiInit();
    500943
    501944  Id = InternalShellGetNodeFromGuid(Guid);
    502   return (HiiGetString(mHandleParsingHiiHandle, Id->StringId, Lang));
     945  return (HiiGetString(mHandleParsingHiiHandle, Id==NULL?STRING_TOKEN(STR_UNKNOWN_DEVICE):Id->StringId, Lang));
    503946}
    504947
     
    527970  )
    528971{
    529   CONST PROTOCOL_INFO_BLOCK *Id;
     972  CONST GUID_INFO_BLOCK *Id;
    530973
    531974  ASSERT(TheHandle  != NULL);
     
    546989  Function to get the Guid for a protocol or struct based on it's string name.
    547990
     991  do not modify the returned Guid.
     992
    548993  @param[in] Name           The pointer to the string name.
    549994  @param[in] Lang           The pointer to the language code.
    550   @param[in] Guid           The pointer to the Guid.
     995  @param[out] Guid          The pointer to the Guid.
    551996
    552997  @retval EFI_SUCCESS       The operation was sucessful.
     
    5571002  IN CONST CHAR16 *Name,
    5581003  IN CONST CHAR8  *Lang OPTIONAL,
    559   IN EFI_GUID     **Guid
    560   )
    561 {
    562   CONST PROTOCOL_INFO_BLOCK  *ListWalker;
     1004  OUT EFI_GUID    **Guid
     1005  )
     1006{
     1007  CONST GUID_INFO_BLOCK  *ListWalker;
    5631008  CHAR16                     *String;
     1009  UINTN                  LoopCount;
     1010
     1011  HandleParsingHiiInit();
    5641012
    5651013  ASSERT(Guid != NULL);
     
    5721020    for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
    5731021      String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
    574       if (Name != NULL && String != NULL && StrCmp(Name, String)==0) {
     1022      if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
    5751023        *Guid = ListWalker->GuidId;
    5761024      }
     
    5831031  for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
    5841032    String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
    585     if (Name != NULL && String != NULL && StrCmp(Name, String)==0) {
     1033    if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
    5861034      *Guid = ListWalker->GuidId;
    5871035    }
     
    5911039    }
    5921040  }
     1041
     1042  for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {
     1043    String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
     1044    if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
     1045      *Guid = ListWalker->GuidId;
     1046    }
     1047    SHELL_FREE_NON_NULL(String);
     1048    if (*Guid != NULL) {
     1049      return (EFI_SUCCESS);
     1050    }
     1051  }
     1052
    5931053  return (EFI_NOT_FOUND);
     1054}
     1055
     1056/**
     1057  Get best support language for this driver.
     1058 
     1059  First base on the user input language  to search, second base on the current
     1060  platform used language to search, third get the first language from the
     1061  support language list. The caller need to free the buffer of the best language.
     1062
     1063  @param[in] SupportedLanguages      The support languages for this driver.
     1064  @param[in] InputLanguage           The user input language.
     1065  @param[in] Iso639Language          Whether get language for ISO639.
     1066
     1067  @return                            The best support language for this driver.
     1068**/
     1069CHAR8 *
     1070EFIAPI
     1071GetBestLanguageForDriver (
     1072  IN CONST CHAR8  *SupportedLanguages,
     1073  IN CONST CHAR8  *InputLanguage,
     1074  IN BOOLEAN      Iso639Language
     1075  )
     1076{
     1077  CHAR8                         *LanguageVariable;
     1078  CHAR8                         *BestLanguage;
     1079
     1080  LanguageVariable = GetVariable (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid);
     1081
     1082  BestLanguage = GetBestLanguage(
     1083                   SupportedLanguages,
     1084                   Iso639Language,
     1085                   (InputLanguage != NULL) ? InputLanguage : "",
     1086                   (LanguageVariable != NULL) ? LanguageVariable : "",
     1087                   SupportedLanguages,
     1088                   NULL
     1089                   );
     1090
     1091  if (LanguageVariable != NULL) {
     1092    FreePool (LanguageVariable);
     1093  }
     1094
     1095  return BestLanguage;
    5941096}
    5951097
     
    6141116  EFI_STATUS                    Status;
    6151117  CHAR16                        *RetVal;
     1118  CHAR8                         *BestLang;
     1119
     1120  BestLang = NULL;
    6161121
    6171122  Status = gBS->OpenProtocol(
     
    6231128    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    6241129  if (!EFI_ERROR(Status)) {
    625     Status = CompNameStruct->GetDriverName(CompNameStruct, (CHAR8*)Language, &RetVal);
     1130    BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
     1131    Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
     1132    if (BestLang != NULL) {
     1133      FreePool (BestLang);
     1134      BestLang = NULL;
     1135    }
    6261136    if (!EFI_ERROR(Status)) {
    6271137      return (RetVal);
     
    6361146    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    6371147  if (!EFI_ERROR(Status)) {
    638     Status = CompNameStruct->GetDriverName(CompNameStruct, (CHAR8*)Language, &RetVal);
     1148    BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
     1149    Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
     1150    if (BestLang != NULL) {
     1151      FreePool (BestLang);
     1152    }
    6391153    if (!EFI_ERROR(Status)) {
    6401154      return (RetVal);
     
    7051219  )
    7061220{
    707   HANDLE_LIST *ListWalker;
     1221  EFI_STATUS   Status;
     1222  EFI_GUID     **ProtocolBuffer;
     1223  UINTN        ProtocolCount;
     1224  HANDLE_LIST  *ListWalker;
     1225
    7081226  if (TheHandle == NULL) {
    7091227    return 0;
     
    7171235   ){
    7181236    if (ListWalker->TheHandle == TheHandle) {
     1237      //
     1238      // Verify that TheHandle is still present in the Handle Database
     1239      //
     1240      Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
     1241      if (EFI_ERROR (Status)) {
     1242        //
     1243        // TheHandle is not present in the Handle Database, so delete from the handle list
     1244        //
     1245        RemoveEntryList (&ListWalker->Link);
     1246        return 0;
     1247      }
     1248      FreePool (ProtocolBuffer);
    7191249      return (ListWalker->TheIndex);
    7201250    }
    7211251  }
     1252
     1253  //
     1254  // Verify that TheHandle is valid handle
     1255  //
     1256  Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);
     1257  if (EFI_ERROR (Status)) {
     1258    //
     1259    // TheHandle is not valid, so do not add to handle list
     1260    //
     1261    return 0;
     1262  }
     1263  FreePool (ProtocolBuffer);
     1264
    7221265  ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));
    7231266  ASSERT(ListWalker != NULL);
     
    7451288  )
    7461289{
     1290  EFI_STATUS   Status;
     1291  EFI_GUID     **ProtocolBuffer;
     1292  UINTN        ProtocolCount;
    7471293  HANDLE_LIST *ListWalker;
    7481294
     
    7501296
    7511297  if (TheIndex >= mHandleList.NextIndex) {
    752     return (NULL);
     1298    return NULL;
    7531299  }
    7541300
     
    7571303    ;  ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)
    7581304   ){
    759     if (ListWalker->TheIndex == TheIndex) {
     1305    if (ListWalker->TheIndex == TheIndex && ListWalker->TheHandle != NULL) {
     1306      //
     1307      // Verify that LinkWalker->TheHandle is valid handle
     1308      //
     1309      Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);
     1310      if (EFI_ERROR (Status)) {
     1311        //
     1312        // TheHandle is not valid, so do not add to handle list
     1313        //
     1314        ListWalker->TheHandle = NULL;
     1315      }
    7601316      return (ListWalker->TheHandle);
    7611317    }
    7621318  }
    763   return (NULL);
     1319  return NULL;
    7641320}
    7651321
     
    8091365  UINTN                               OpenInfoIndex;
    8101366  UINTN                               ChildIndex;
     1367  INTN                                DriverBindingHandleIndex;
    8111368
    8121369  ASSERT(HandleCount  != NULL);
     
    8361393  ASSERT(*HandleType != NULL);
    8371394
     1395  DriverBindingHandleIndex = -1;
     1396  for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
     1397    if (DriverBindingHandle != NULL && (*HandleBuffer)[HandleIndex] == DriverBindingHandle) {
     1398      DriverBindingHandleIndex = (INTN)HandleIndex;
     1399    }
     1400  }
     1401
    8381402  for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {
    8391403    //
     
    8451409                  &ArrayCount
    8461410                 );
    847     if (!EFI_ERROR (Status)) {
    848 
    849       for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
    850 
    851         //
    852         // Set the bit describing what this handle has
    853         //
    854         if        (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid)         ) {
    855           (*HandleType)[HandleIndex] |= HR_IMAGE_HANDLE;
    856         } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid)       ) {
    857           (*HandleType)[HandleIndex] |= HR_DRIVER_BINDING_HANDLE;
    858         } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {
    859           (*HandleType)[HandleIndex] |= HR_DRIVER_CONFIGURATION_HANDLE;
    860         } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {
    861           (*HandleType)[HandleIndex] |= HR_DRIVER_CONFIGURATION_HANDLE;
    862         } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid)  ) {
    863           (*HandleType)[HandleIndex] |= HR_DRIVER_DIAGNOSTICS_HANDLE;
    864         } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid)   ) {
    865           (*HandleType)[HandleIndex] |= HR_DRIVER_DIAGNOSTICS_HANDLE;
    866         } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid)      ) {
    867           (*HandleType)[HandleIndex] |= HR_COMPONENT_NAME_HANDLE;
    868         } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid)       ) {
    869           (*HandleType)[HandleIndex] |= HR_COMPONENT_NAME_HANDLE;
    870         } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid)          ) {
    871           (*HandleType)[HandleIndex] |= HR_DEVICE_HANDLE;
    872         } else {
    873           DEBUG_CODE_BEGIN();
    874           ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]);
    875           DEBUG_CODE_END();
    876         }
    877         //
    878         // Retrieve the list of agents that have opened each protocol
    879         //
    880         Status = gBS->OpenProtocolInformation (
     1411    if (EFI_ERROR (Status)) {
     1412      continue;
     1413    }
     1414
     1415    for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {
     1416
     1417      //
     1418      // Set the bit describing what this handle has
     1419      //
     1420      if        (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid)         ) {
     1421        (*HandleType)[HandleIndex] |= (UINTN)HR_IMAGE_HANDLE;
     1422      } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid)       ) {
     1423        (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_BINDING_HANDLE;
     1424      } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {
     1425        (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
     1426      } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {
     1427        (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;
     1428      } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid)  ) {
     1429        (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
     1430      } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid)   ) {
     1431        (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;
     1432      } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid)      ) {
     1433        (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
     1434      } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid)       ) {
     1435        (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;
     1436      } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid)          ) {
     1437        (*HandleType)[HandleIndex] |= (UINTN)HR_DEVICE_HANDLE;
     1438      } else {
     1439        DEBUG_CODE_BEGIN();
     1440        ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]);
     1441        DEBUG_CODE_END();
     1442      }
     1443      //
     1444      // Retrieve the list of agents that have opened each protocol
     1445      //
     1446      Status = gBS->OpenProtocolInformation (
    8811447                      (*HandleBuffer)[HandleIndex],
    8821448                      ProtocolGuidArray[ProtocolIndex],
     
    8841450                      &OpenInfoCount
    8851451                     );
    886         if (!EFI_ERROR (Status)) {
     1452      if (EFI_ERROR (Status)) {
     1453        continue;
     1454      }
     1455
     1456      if (ControllerHandle == NULL) {
     1457        //
     1458        // ControllerHandle == NULL and DriverBindingHandle != NULL. 
     1459        // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
     1460        //
     1461        for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
     1462          if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
     1463            (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
     1464            if (DriverBindingHandleIndex != -1) {
     1465              (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
     1466            }
     1467          }
     1468          if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
     1469            (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
     1470            if (DriverBindingHandleIndex != -1) {
     1471              (*HandleType)[DriverBindingHandleIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
     1472            }
     1473            for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
     1474              if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
     1475                (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
     1476              }
     1477            }
     1478          }
     1479        }
     1480      }
     1481      if (DriverBindingHandle == NULL && ControllerHandle != NULL) {
     1482        if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
     1483          (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
    8871484          for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
    888             if (DriverBindingHandle != NULL && OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
    889               if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
    890                 (*HandleType)[HandleIndex] |= (HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
    891               }
    892               if (ControllerHandle != NULL && (*HandleBuffer)[HandleIndex] == ControllerHandle) {
    893                 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
    894                   for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
    895                     if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].ControllerHandle) {
    896                       (*HandleType)[ChildIndex] |= (HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
    897                     }
    898                   }
     1485            if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
     1486              for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
     1487                if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
     1488                  (*HandleType)[ChildIndex] |= (UINTN)HR_DEVICE_DRIVER;
    8991489                }
    9001490              }
    9011491            }
    902             if (DriverBindingHandle == NULL && OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
    903               if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
    904                 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
    905                   if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {
    906                     (*HandleType)[ChildIndex] |= HR_DEVICE_DRIVER;
    907                   }
     1492            if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
     1493              for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
     1494                if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
     1495                  (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
    9081496                }
    909               }
    910               if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
    911                 (*HandleType)[HandleIndex] |= HR_PARENT_HANDLE;
    912                 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
    913                   if ((*HandleBuffer)[ChildIndex] == OpenInfo[OpenInfoIndex].AgentHandle) {
    914                     (*HandleType)[ChildIndex] |= HR_BUS_DRIVER;
    915                   }
     1497                if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
     1498                  (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
    9161499                }
    9171500              }
    9181501            }
    9191502          }
    920 
    921           FreePool (OpenInfo);
     1503        } else {
     1504          for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
     1505            if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
     1506              if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
     1507                (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
     1508              }
     1509            }
     1510          }
    9221511        }
    9231512      }
    924 
    925       FreePool (ProtocolGuidArray);
    926     }
    927   }
    928 
    929   if (EFI_ERROR(Status)) {
    930     if (*HandleType != NULL) {
    931       FreePool (*HandleType);
    932     }
    933     if (*HandleBuffer != NULL) {
    934       FreePool (*HandleBuffer);
    935     }
    936 
    937     *HandleCount  = 0;
    938     *HandleBuffer = NULL;
    939     *HandleType   = NULL;
    940   }
    941 
    942   return Status;
     1513      if (DriverBindingHandle != NULL && ControllerHandle != NULL) {
     1514        if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {
     1515          (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);
     1516          for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
     1517            if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
     1518              if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
     1519                if (DriverBindingHandleIndex != -1) {
     1520                  (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;
     1521                }
     1522              }
     1523            }
     1524            if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
     1525              if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {
     1526                for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
     1527                  if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {
     1528                    (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);
     1529                  }
     1530                }
     1531              }
     1532
     1533              for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {
     1534                if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {
     1535                  (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);
     1536                }
     1537              }
     1538            }
     1539          }
     1540        } else {
     1541          for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
     1542            if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
     1543              if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {
     1544                (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);
     1545              }
     1546            }
     1547          }
     1548        }
     1549      }
     1550      FreePool (OpenInfo);
     1551    }
     1552    FreePool (ProtocolGuidArray);
     1553  }
     1554  return EFI_SUCCESS;
    9431555}
    9441556
     
    10951707{
    10961708  EFI_STATUS  Status;
    1097 //  UINTN       HandleIndex;
     1709  UINTN       HandleIndex;
    10981710  UINTN       DriverBindingHandleCount;
    10991711  EFI_HANDLE  *DriverBindingHandleBuffer;
     
    11021714  EFI_HANDLE  *ChildControllerHandleBuffer;
    11031715  UINTN       ChildControllerHandleIndex;
    1104 //  BOOLEAN     Found;
    11051716  EFI_HANDLE  *HandleBufferForReturn;
    11061717
     
    11221733  // Get a buffer big enough for all the controllers.
    11231734  //
    1124   HandleBufferForReturn = GetHandleListByProtocol(&gEfiDevicePathProtocolGuid);
     1735  HandleBufferForReturn = GetHandleListByProtocol(NULL);
    11251736  if (HandleBufferForReturn == NULL) {
    11261737    FreePool (DriverBindingHandleBuffer);
     
    11431754         ChildControllerHandleIndex++
    11441755       ) {
    1145 //      Found = FALSE;
    1146       HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
    1147 //      for (HandleIndex = 0; HandleBufferForReturn[HandleIndex] != NULL; HandleIndex++) {
    1148 //        if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {
    1149 //          Found = TRUE;
    1150 //          break;
    1151 //        }
    1152 //      }
    1153 
    1154 //      if (Found) {
    1155 //        HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
    1156 //      }
     1756      for (HandleIndex = 0; HandleIndex < *MatchingHandleCount; HandleIndex++) {
     1757        if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {
     1758          break;
     1759        }
     1760      }
     1761      if (HandleIndex >= *MatchingHandleCount) {
     1762        HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
     1763      }
    11571764    }
    11581765
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.h

    r48674 r58459  
    22  Provides interface to advanced shell functionality for parsing both handle and protocol database.
    33
    4   Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2013 - 2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    105106//#include <Protocol/FirmwareVolume.h>
    106107//#include <Protocol/FirmwareVolume2.h>
     108#include <Protocol/DriverFamilyOverride.h>
     109#include <Protocol/Pcd.h>
     110#include <Protocol/TcgService.h>
     111#include <Protocol/HiiPackageList.h>
     112#include <Protocol/Ip6.h>
     113#include <Protocol/Ip6Config.h>
     114#include <Protocol/Mtftp6.h>
     115#include <Protocol/Dhcp6.h>
     116#include <Protocol/Udp6.h>
     117#include <Protocol/Tcp6.h>
     118#include <Protocol/VlanConfig.h>
     119#include <Protocol/Eap.h>
     120#include <Protocol/EapManagement.h>
     121#include <Protocol/Ftp4.h>
     122#include <Protocol/IpSecConfig.h>
     123#include <Protocol/DriverHealth.h>
     124#include <Protocol/DeferredImageLoad.h>
     125#include <Protocol/UserCredential.h>
     126#include <Protocol/UserManager.h>
     127#include <Protocol/AtaPassThru.h>
     128#include <Protocol/FirmwareManagement.h>
     129#include <Protocol/IpSec.h>
     130#include <Protocol/Kms.h>
     131#include <Protocol/BlockIo2.h>
     132#include <Protocol/StorageSecurityCommand.h>
     133#include <Protocol/UserCredential2.h>
     134#include <Protocol/IdeControllerInit.h>
     135#include <Protocol/DiskIo2.h>
     136#include <Protocol/AdapterInformation.h>
     137#include <Protocol/EfiShellDynamicCommand.h>
    107138
    108139#include <Library/HandleParsingLib.h>
     
    118149#include <Library/HiiLib.h>
    119150#include <Library/ShellLib.h>
     151#include <Library/SortLib.h>
    120152
    121153typedef struct {
     
    137169  );
    138170
    139 
    140 typedef struct {
     171typedef struct _GUID_INFO_BLOCK{
    141172  EFI_STRING_ID                 StringId;
    142173  EFI_GUID                      *GuidId;
    143174  DUMP_PROTOCOL_INFO            DumpInfo;
    144 } PROTOCOL_INFO_BLOCK;
     175} GUID_INFO_BLOCK;
    145176
    146177#endif
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf

    r48674 r58459  
    11##  @file
    22#  Provides interface to advanced shell functionality for parsing both handle and protocol database.
    3 #  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved. <BR>
     3#  Copyright (c) 2013 - 2014, Hewlett-Packard Development Company, L.P.<BR>
     4#  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
    45#
    56#  This program and the accompanying materials
     
    1920  MODULE_TYPE                    = UEFI_DRIVER
    2021  VERSION_STRING                 = 1.0
    21   LIBRARY_CLASS                  = HandleParsingLib|UEFI_APPLICATION UEFI_DRIVER
     22  LIBRARY_CLASS                  = HandleParsingLib|UEFI_APPLICATION UEFI_DRIVER DXE_RUNTIME_DRIVER
    2223  CONSTRUCTOR                    = HandleParsingLibConstructor
    2324  DESTRUCTOR                     = HandleParsingLibDestructor
     
    4849  UefiLib
    4950  HiiLib
     51  SortLib
    5052
    5153[Protocols]
    52   gEfiSimpleFileSystemProtocolGuid              # ALWAYS_CONSUMED
     54  gEfiSimpleFileSystemProtocolGuid                        ## CONSUMES
    5355
    5456  # shell 2.0
    55   gEfiShellProtocolGuid                         # SOMETIMES_CONSUMED
    56   gEfiShellParametersProtocolGuid               # SOMETIMES_CONSUMED
     57  gEfiShellProtocolGuid                                   ## SOMETIMES_CONSUMES
     58  gEfiShellParametersProtocolGuid                         ## SOMETIMES_CONSUMES
    5759
    5860  # 'old' shell
    59   gEfiShellEnvironment2Guid                     # SOMETIMES_CONSUMED
    60   gEfiShellInterfaceGuid                        # SOMETIMES_CONSUMED
     61  gEfiShellEnvironment2Guid                               ## SOMETIMES_CONSUMES
     62  gEfiShellInterfaceGuid                                  ## SOMETIMES_CONSUMES
    6163
    62   gEfiUnicodeCollation2ProtocolGuid                       # ALWAYS_CONSUMED
    63   gEfiDevicePathToTextProtocolGuid                        # ALWAYS_CONSUMED
    64   gEfiBusSpecificDriverOverrideProtocolGuid               # ALWAYS_CONSUMED
    65   gEfiDevicePathUtilitiesProtocolGuid                     # ALWAYS_CONSUMED
    66   gEfiDevicePathFromTextProtocolGuid                      # ALWAYS_CONSUMED
    67   gEfiPlatformDriverOverrideProtocolGuid                  # ALWAYS_CONSUMED
    68   gEfiSimpleTextInProtocolGuid                            # ALWAYS_CONSUMED
    69   gEfiPlatformToDriverConfigurationProtocolGuid           # ALWAYS_CONSUMED
    70   gEfiDriverSupportedEfiVersionProtocolGuid               # ALWAYS_CONSUMED
    71   gEfiLoadedImageProtocolGuid                             # ALWAYS_CONSUMED
    72   gEfiDevicePathProtocolGuid                              # ALWAYS_CONSUMED
    73   gEfiLoadedImageDevicePathProtocolGuid                   # ALWAYS_CONSUMED
    74   gEfiSimpleTextOutProtocolGuid
    75   gEfiSimplePointerProtocolGuid
    76   gEfiAbsolutePointerProtocolGuid
    77   gEfiSerialIoProtocolGuid
    78   gEfiEdidDiscoveredProtocolGuid
    79   gEfiEdidActiveProtocolGuid
    80   gEfiEdidOverrideProtocolGuid
    81   gEfiLoadFileProtocolGuid
    82   gEfiLoadFile2ProtocolGuid
    83   gEfiTapeIoProtocolGuid
    84   gEfiDiskIoProtocolGuid
    85   gEfiBlockIoProtocolGuid
    86   gEfiUnicodeCollationProtocolGuid
    87   gEfiPciRootBridgeIoProtocolGuid
    88   gEfiPciIoProtocolGuid
    89   gEfiScsiPassThruProtocolGuid
    90   gEfiScsiIoProtocolGuid
    91   gEfiExtScsiPassThruProtocolGuid
    92   gEfiIScsiInitiatorNameProtocolGuid
    93   gEfiUsbIoProtocolGuid
    94   gEfiUsbHcProtocolGuid
    95   gEfiUsb2HcProtocolGuid
    96   gEfiDebugSupportProtocolGuid
    97   gEfiDebugPortProtocolGuid
    98   gEfiDecompressProtocolGuid
    99   gEfiAcpiTableProtocolGuid
    100   gEfiEbcProtocolGuid
    101   gEfiSimpleNetworkProtocolGuid
    102   gEfiNetworkInterfaceIdentifierProtocolGuid
    103   gEfiNetworkInterfaceIdentifierProtocolGuid_31
    104   gEfiPxeBaseCodeProtocolGuid
    105   gEfiPxeBaseCodeCallbackProtocolGuid
    106   gEfiBisProtocolGuid
    107   gEfiManagedNetworkServiceBindingProtocolGuid
    108   gEfiManagedNetworkProtocolGuid
    109   gEfiArpServiceBindingProtocolGuid
    110   gEfiArpProtocolGuid
    111   gEfiDhcp4ServiceBindingProtocolGuid
    112   gEfiDhcp4ProtocolGuid
    113   gEfiTcp4ServiceBindingProtocolGuid
    114   gEfiTcp4ProtocolGuid
    115   gEfiIp4ServiceBindingProtocolGuid
    116   gEfiIp4ProtocolGuid
    117   gEfiIp4ConfigProtocolGuid
    118   gEfiUdp4ServiceBindingProtocolGuid
    119   gEfiUdp4ProtocolGuid
    120   gEfiMtftp4ServiceBindingProtocolGuid
    121   gEfiMtftp4ProtocolGuid
    122   gEfiAuthenticationInfoProtocolGuid
    123   gEfiHashServiceBindingProtocolGuid
    124   gEfiHashProtocolGuid
    125   gEfiHiiFontProtocolGuid
    126   gEfiHiiStringProtocolGuid
    127   gEfiHiiImageProtocolGuid
    128   gEfiHiiConfigRoutingProtocolGuid
    129   gEfiHiiConfigAccessProtocolGuid
    130   gEfiFormBrowser2ProtocolGuid
    131   gEfiDeviceIoProtocolGuid
    132   gEfiUgaDrawProtocolGuid
    133   gEfiUgaIoProtocolGuid
    134   gEfiDriverConfigurationProtocolGuid
    135   gEfiDriverConfiguration2ProtocolGuid
    136   gEfiSimpleTextInputExProtocolGuid
     64  gEfiUnicodeCollation2ProtocolGuid                       ## CONSUMES
     65  gEfiDevicePathToTextProtocolGuid                        ## CONSUMES
     66  gEfiBusSpecificDriverOverrideProtocolGuid               ## CONSUMES
     67  gEfiDevicePathUtilitiesProtocolGuid                     ## CONSUMES
     68  gEfiDevicePathFromTextProtocolGuid                      ## CONSUMES
     69  gEfiPlatformDriverOverrideProtocolGuid                  ## CONSUMES
     70  gEfiSimpleTextInProtocolGuid                            ## CONSUMES
     71  gEfiPlatformToDriverConfigurationProtocolGuid           ## CONSUMES
     72  gEfiDriverSupportedEfiVersionProtocolGuid               ## CONSUMES
     73  gEfiLoadedImageProtocolGuid                             ## CONSUMES
     74  gEfiDevicePathProtocolGuid                              ## CONSUMES
     75  gEfiLoadedImageDevicePathProtocolGuid                   ## CONSUMES
     76  gEfiSimpleTextOutProtocolGuid                           ## UNDEFINED
     77  gEfiSimplePointerProtocolGuid                           ## UNDEFINED
     78  gEfiAbsolutePointerProtocolGuid                         ## UNDEFINED
     79  gEfiSerialIoProtocolGuid                                ## UNDEFINED
     80  gEfiEdidDiscoveredProtocolGuid                          ## UNDEFINED
     81  gEfiEdidActiveProtocolGuid                              ## UNDEFINED
     82  gEfiEdidOverrideProtocolGuid                            ## UNDEFINED
     83  gEfiLoadFileProtocolGuid                                ## UNDEFINED
     84  gEfiLoadFile2ProtocolGuid                               ## UNDEFINED
     85  gEfiTapeIoProtocolGuid                                  ## UNDEFINED
     86  gEfiDiskIoProtocolGuid                                  ## UNDEFINED
     87  gEfiBlockIoProtocolGuid                                 ## UNDEFINED
     88  gEfiUnicodeCollationProtocolGuid                        ## UNDEFINED
     89  gEfiPciRootBridgeIoProtocolGuid                         ## UNDEFINED
     90  gEfiPciIoProtocolGuid                                   ## UNDEFINED
     91  gEfiScsiPassThruProtocolGuid                            ## UNDEFINED
     92  gEfiScsiIoProtocolGuid                                  ## UNDEFINED
     93  gEfiExtScsiPassThruProtocolGuid                         ## UNDEFINED
     94  gEfiIScsiInitiatorNameProtocolGuid                      ## UNDEFINED
     95  gEfiUsbIoProtocolGuid                                   ## UNDEFINED
     96  gEfiUsbHcProtocolGuid                                   ## UNDEFINED
     97  gEfiUsb2HcProtocolGuid                                  ## UNDEFINED
     98  gEfiDebugSupportProtocolGuid                            ## UNDEFINED
     99  gEfiDebugPortProtocolGuid                               ## UNDEFINED
     100  gEfiDecompressProtocolGuid                              ## UNDEFINED
     101  gEfiAcpiTableProtocolGuid                               ## UNDEFINED
     102  gEfiEbcProtocolGuid                                     ## UNDEFINED
     103  gEfiSimpleNetworkProtocolGuid                           ## UNDEFINED
     104  gEfiNetworkInterfaceIdentifierProtocolGuid              ## UNDEFINED
     105  gEfiNetworkInterfaceIdentifierProtocolGuid_31           ## UNDEFINED
     106  gEfiPxeBaseCodeProtocolGuid                             ## UNDEFINED
     107  gEfiPxeBaseCodeCallbackProtocolGuid                     ## UNDEFINED
     108  gEfiBisProtocolGuid                                     ## UNDEFINED
     109  gEfiManagedNetworkServiceBindingProtocolGuid            ## UNDEFINED
     110  gEfiManagedNetworkProtocolGuid                          ## UNDEFINED
     111  gEfiArpServiceBindingProtocolGuid                       ## UNDEFINED
     112  gEfiArpProtocolGuid                                     ## UNDEFINED
     113  gEfiDhcp4ServiceBindingProtocolGuid                     ## UNDEFINED
     114  gEfiDhcp4ProtocolGuid                                   ## UNDEFINED
     115  gEfiTcp4ServiceBindingProtocolGuid                      ## UNDEFINED
     116  gEfiTcp4ProtocolGuid                                    ## UNDEFINED
     117  gEfiIp4ServiceBindingProtocolGuid                       ## UNDEFINED
     118  gEfiIp4ProtocolGuid                                     ## UNDEFINED
     119  gEfiIp4ConfigProtocolGuid                               ## UNDEFINED
     120  gEfiUdp4ServiceBindingProtocolGuid                      ## UNDEFINED
     121  gEfiUdp4ProtocolGuid                                    ## UNDEFINED
     122  gEfiMtftp4ServiceBindingProtocolGuid                    ## UNDEFINED
     123  gEfiMtftp4ProtocolGuid                                  ## UNDEFINED
     124  gEfiAuthenticationInfoProtocolGuid                      ## UNDEFINED
     125  gEfiHashServiceBindingProtocolGuid                      ## UNDEFINED
     126  gEfiHashProtocolGuid                                    ## UNDEFINED
     127  gEfiHiiFontProtocolGuid                                 ## UNDEFINED
     128  gEfiHiiStringProtocolGuid                               ## UNDEFINED
     129  gEfiHiiImageProtocolGuid                                ## UNDEFINED
     130  gEfiHiiConfigRoutingProtocolGuid                        ## UNDEFINED
     131  gEfiHiiConfigAccessProtocolGuid                         ## UNDEFINED
     132  gEfiFormBrowser2ProtocolGuid                            ## UNDEFINED
     133  gEfiDeviceIoProtocolGuid                                ## UNDEFINED
     134  gEfiUgaDrawProtocolGuid                                 ## UNDEFINED
     135  gEfiUgaIoProtocolGuid                                   ## UNDEFINED
     136  gEfiDriverConfigurationProtocolGuid                     ## UNDEFINED
     137  gEfiDriverConfiguration2ProtocolGuid                    ## UNDEFINED
     138  gEfiSimpleTextInputExProtocolGuid                       ## UNDEFINED
     139  gEfiIp6ServiceBindingProtocolGuid                       ## UNDEFINED
     140  gEfiIp6ProtocolGuid                                     ## UNDEFINED
     141  gEfiIp6ConfigProtocolGuid                               ## UNDEFINED
     142  gEfiMtftp6ServiceBindingProtocolGuid                    ## UNDEFINED
     143  gEfiMtftp6ProtocolGuid                                  ## UNDEFINED
     144  gEfiDhcp6ServiceBindingProtocolGuid                     ## UNDEFINED
     145  gEfiDhcp6ProtocolGuid                                   ## UNDEFINED
     146  gEfiUdp6ServiceBindingProtocolGuid                      ## UNDEFINED
     147  gEfiUdp6ProtocolGuid                                    ## UNDEFINED
     148  gEfiTcp6ServiceBindingProtocolGuid                      ## UNDEFINED
     149  gEfiTcp6ProtocolGuid                                    ## UNDEFINED
     150  gEfiVlanConfigProtocolGuid                              ## UNDEFINED
     151  gEfiEapProtocolGuid                                     ## UNDEFINED
     152  gEfiEapManagementProtocolGuid                           ## UNDEFINED
     153  gEfiFtp4ServiceBindingProtocolGuid                      ## UNDEFINED
     154  gEfiFtp4ProtocolGuid                                    ## UNDEFINED
     155  gEfiIpSecConfigProtocolGuid                             ## UNDEFINED
     156  gEfiDriverHealthProtocolGuid                            ## UNDEFINED
     157  gEfiDeferredImageLoadProtocolGuid                       ## UNDEFINED
     158  gEfiUserCredentialProtocolGuid                          ## UNDEFINED
     159  gEfiUserManagerProtocolGuid                             ## UNDEFINED
     160  gEfiAtaPassThruProtocolGuid                             ## UNDEFINED
     161  gEfiFirmwareManagementProtocolGuid                      ## UNDEFINED
     162  gEfiIpSecProtocolGuid                                   ## UNDEFINED
     163  gEfiIpSec2ProtocolGuid                                  ## UNDEFINED
     164  gEfiKmsProtocolGuid                                     ## UNDEFINED
     165  gEfiBlockIo2ProtocolGuid                                ## UNDEFINED
     166  gEfiStorageSecurityCommandProtocolGuid                  ## UNDEFINED
     167  gEfiUserCredential2ProtocolGuid                         ## UNDEFINED
     168  gPcdProtocolGuid                                        ## UNDEFINED
     169  gEfiTcgProtocolGuid                                     ## UNDEFINED
     170  gEfiHiiPackageListProtocolGuid                          ## UNDEFINED
     171  gEfiDriverFamilyOverrideProtocolGuid                    ## UNDEFINED
     172  gEfiIdeControllerInitProtocolGuid                       ## UNDEFINED
     173  gEfiDiskIo2ProtocolGuid                                 ## UNDEFINED
     174  gEfiAdapterInformationProtocolGuid                      ## UNDEFINED
     175  gEfiShellDynamicCommandProtocolGuid                     ## UNDEFINED
    137176
    138177[Guids]
    139   gEfiFileInfoGuid                              # ALWAYS_CONSUMED
    140   gEfiShellEnvironment2ExtGuid                  # ALWAYS_CONSUMED
    141   gEfiPcAnsiGuid
    142   gEfiVT100Guid
    143   gEfiVT100PlusGuid
    144   gEfiVTUTF8Guid
    145   gEfiStandardErrorDeviceGuid
    146   gEfiConsoleInDeviceGuid
    147   gEfiConsoleOutDeviceGuid
    148   gEfiFileSystemInfoGuid
    149   gEfiGlobalVariableGuid
    150   gEfiPartTypeSystemPartGuid
    151   gEfiPartTypeLegacyMbrGuid
    152   gHandleParsingHiiGuid
     178  gEfiFileInfoGuid                                        ## CONSUMES ## GUID
     179  gEfiShellEnvironment2ExtGuid                            ## CONSUMES ## GUID
     180  gEfiPcAnsiGuid                                          ## UNDEFINED
     181  gEfiVT100Guid                                           ## UNDEFINED
     182  gEfiVT100PlusGuid                                       ## UNDEFINED
     183  gEfiVTUTF8Guid                                          ## UNDEFINED
     184  gEfiStandardErrorDeviceGuid                             ## UNDEFINED
     185  gEfiConsoleInDeviceGuid                                 ## UNDEFINED
     186  gEfiConsoleOutDeviceGuid                                ## UNDEFINED
     187  gEfiFileSystemInfoGuid                                  ## UNDEFINED
     188  gEfiGlobalVariableGuid                                  ## UNDEFINED
     189  gEfiPartTypeSystemPartGuid                              ## UNDEFINED
     190  gEfiPartTypeLegacyMbrGuid                               ## UNDEFINED
     191  gHandleParsingHiiGuid                                   ## UNDEFINED
    153192
    154193[Pcd.common]
    155   gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize     # ALWAYS_CONSUMED
    156   gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize       # ALWAYS_CONSUMED
    157   gEfiShellPkgTokenSpaceGuid.PcdShellIncludeNtGuids        # ALWAYS_CONSUMED
     194  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize    ## CONSUMES
     195  gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize      ## CONSUMES
     196  gEfiShellPkgTokenSpaceGuid.PcdShellIncludeNtGuids       ## CONSUMES
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.c

    r48674 r58459  
    22  Provides application point extension for "C" style main funciton
    33
    4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    3030  An application that uses UefiShellCEntryLib must have a ShellAppMain
    3131  function as prototyped in Include/Library/ShellCEntryLib.h.
     32
     33  Note that the Shell uses POSITIVE integers for error values, while UEFI
     34  uses NEGATIVE values.  If the application is to be used within a script,
     35  it needs to return one of the SHELL_STATUS values defined in ShellBase.h.
    3236
    3337  @param  ImageHandle  The image handle of the UEFI Application.
     
    9296    }
    9397  }
    94   if (ReturnFromMain == 0) {
    95     return (EFI_SUCCESS);
    96   } else {
    97     return (EFI_UNSUPPORTED);
    98   }
     98  return ReturnFromMain;
    9999}
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf

    r48674 r58459  
    22#  Provides interface to shell functionality for shell commands and applications.
    33#
    4 #  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved. <BR>
     4#  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved. <BR>
    55#
    66#  This program and the accompanying materials
     
    3939
    4040[Protocols]
    41   gEfiShellParametersProtocolGuid                         # ALWAYS_CONSUMED
    42   gEfiShellInterfaceGuid                                  # SOMETIMES_CONSUMED
     41  gEfiShellParametersProtocolGuid                         ## CONSUMES
     42  gEfiShellInterfaceGuid                                  ## SOMETIMES_CONSUMES
    4343 
    4444
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellCommandLib/ConsistMapping.c

    r48674 r58459  
    22  Main file for support of shell consist mapping.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    9999  }
    100100
    101   StrCat (Str->Str, AppendStr);
     101  StrnCat (Str->Str, AppendStr, StringSize/sizeof(CHAR16) - 1 - StrLen(Str->Str));
    102102  Str->Len = StringSize;
    103103
     
    951951
    952952DEV_PATH_CONSIST_MAPPING_TABLE  DevPathConsistMappingTable[] = {
    953   HARDWARE_DEVICE_PATH,
    954   HW_PCI_DP,
    955   DevPathSerialDefault,
    956   DevPathComparePci,
    957   ACPI_DEVICE_PATH,
    958   ACPI_DP,
    959   DevPathSerialAcpi,
    960   DevPathCompareAcpi,
    961   MESSAGING_DEVICE_PATH,
    962   MSG_ATAPI_DP,
    963   DevPathSerialAtapi,
    964   DevPathCompareDefault,
    965   MESSAGING_DEVICE_PATH,
    966   MSG_SCSI_DP,
    967   DevPathSerialScsi,
    968   DevPathCompareDefault,
    969   MESSAGING_DEVICE_PATH,
    970   MSG_FIBRECHANNEL_DP,
    971   DevPathSerialFibre,
    972   DevPathCompareDefault,
    973   MESSAGING_DEVICE_PATH,
    974   MSG_1394_DP,
    975   DevPathSerial1394,
    976   DevPathCompareDefault,
    977   MESSAGING_DEVICE_PATH,
    978   MSG_USB_DP,
    979   DevPathSerialUsb,
    980   DevPathCompareDefault,
    981   MESSAGING_DEVICE_PATH,
    982   MSG_I2O_DP,
    983   DevPathSerialI2O,
    984   DevPathCompareDefault,
    985   MESSAGING_DEVICE_PATH,
    986   MSG_MAC_ADDR_DP,
    987   DevPathSerialMacAddr,
    988   DevPathCompareDefault,
    989   MESSAGING_DEVICE_PATH,
    990   MSG_IPv4_DP,
    991   DevPathSerialIPv4,
    992   DevPathCompareDefault,
    993   MESSAGING_DEVICE_PATH,
    994   MSG_IPv6_DP,
    995   DevPathSerialIPv6,
    996   DevPathCompareDefault,
    997   MESSAGING_DEVICE_PATH,
    998   MSG_INFINIBAND_DP,
    999   DevPathSerialInfiniBand,
    1000   DevPathCompareDefault,
    1001   MESSAGING_DEVICE_PATH,
    1002   MSG_UART_DP,
    1003   DevPathSerialUart,
    1004   DevPathCompareDefault,
    1005   MESSAGING_DEVICE_PATH,
    1006   MSG_VENDOR_DP,
    1007   DevPathSerialVendor,
    1008   DevPathCompareDefault,
    1009   MESSAGING_DEVICE_PATH,
    1010   MSG_DEVICE_LOGICAL_UNIT_DP,
    1011   DevPathSerialLun,
    1012   DevPathCompareDefault,
    1013   MESSAGING_DEVICE_PATH,
    1014   MSG_SATA_DP,
    1015   DevPathSerialSata,
    1016   DevPathCompareDefault,
    1017   MESSAGING_DEVICE_PATH,
    1018   MSG_ISCSI_DP,
    1019   DevPathSerialIScsi,
    1020   DevPathCompareDefault,
    1021   MEDIA_DEVICE_PATH,
    1022   MEDIA_HARDDRIVE_DP,
    1023   DevPathSerialHardDrive,
    1024   DevPathCompareDefault,
    1025   MEDIA_DEVICE_PATH,
    1026   MEDIA_CDROM_DP,
    1027   DevPathSerialCdRom,
    1028   DevPathCompareDefault,
    1029   MEDIA_DEVICE_PATH,
    1030   MEDIA_VENDOR_DP,
    1031   DevPathSerialVendor,
    1032   DevPathCompareDefault,
    1033   0,
    1034   0,
    1035   NULL,
    1036   NULL
     953  {
     954    HARDWARE_DEVICE_PATH,
     955    HW_PCI_DP,
     956    DevPathSerialDefault,
     957    DevPathComparePci
     958  },
     959  {
     960    ACPI_DEVICE_PATH,
     961    ACPI_DP,
     962    DevPathSerialAcpi,
     963    DevPathCompareAcpi
     964  },
     965  {
     966    MESSAGING_DEVICE_PATH,
     967    MSG_ATAPI_DP,
     968    DevPathSerialAtapi,
     969    DevPathCompareDefault
     970  },
     971  {
     972    MESSAGING_DEVICE_PATH,
     973    MSG_SCSI_DP,
     974    DevPathSerialScsi,
     975    DevPathCompareDefault
     976  },
     977  {
     978    MESSAGING_DEVICE_PATH,
     979    MSG_FIBRECHANNEL_DP,
     980    DevPathSerialFibre,
     981    DevPathCompareDefault
     982  },
     983  {
     984    MESSAGING_DEVICE_PATH,
     985    MSG_1394_DP,
     986    DevPathSerial1394,
     987    DevPathCompareDefault
     988  },
     989  {
     990    MESSAGING_DEVICE_PATH,
     991    MSG_USB_DP,
     992    DevPathSerialUsb,
     993    DevPathCompareDefault
     994  },
     995  {
     996    MESSAGING_DEVICE_PATH,
     997    MSG_I2O_DP,
     998    DevPathSerialI2O,
     999    DevPathCompareDefault
     1000  },
     1001  {
     1002    MESSAGING_DEVICE_PATH,
     1003    MSG_MAC_ADDR_DP,
     1004    DevPathSerialMacAddr,
     1005    DevPathCompareDefault
     1006  },
     1007  {
     1008    MESSAGING_DEVICE_PATH,
     1009    MSG_IPv4_DP,
     1010    DevPathSerialIPv4,
     1011    DevPathCompareDefault
     1012  },
     1013  {
     1014    MESSAGING_DEVICE_PATH,
     1015    MSG_IPv6_DP,
     1016    DevPathSerialIPv6,
     1017    DevPathCompareDefault
     1018  },
     1019  {
     1020    MESSAGING_DEVICE_PATH,
     1021    MSG_INFINIBAND_DP,
     1022    DevPathSerialInfiniBand,
     1023    DevPathCompareDefault
     1024  },
     1025  {
     1026    MESSAGING_DEVICE_PATH,
     1027    MSG_UART_DP,
     1028    DevPathSerialUart,
     1029    DevPathCompareDefault
     1030  },
     1031  {
     1032    MESSAGING_DEVICE_PATH,
     1033    MSG_VENDOR_DP,
     1034    DevPathSerialVendor,
     1035    DevPathCompareDefault
     1036  },
     1037  {
     1038    MESSAGING_DEVICE_PATH,
     1039    MSG_DEVICE_LOGICAL_UNIT_DP,
     1040    DevPathSerialLun,
     1041    DevPathCompareDefault
     1042  },
     1043  {
     1044    MESSAGING_DEVICE_PATH,
     1045    MSG_SATA_DP,
     1046    DevPathSerialSata,
     1047    DevPathCompareDefault
     1048  },
     1049  {
     1050    MESSAGING_DEVICE_PATH,
     1051    MSG_ISCSI_DP,
     1052    DevPathSerialIScsi,
     1053    DevPathCompareDefault
     1054  },
     1055  {
     1056    MEDIA_DEVICE_PATH,
     1057    MEDIA_HARDDRIVE_DP,
     1058    DevPathSerialHardDrive,
     1059    DevPathCompareDefault
     1060  },
     1061  {
     1062    MEDIA_DEVICE_PATH,
     1063    MEDIA_CDROM_DP,
     1064    DevPathSerialCdRom,
     1065    DevPathCompareDefault
     1066  },
     1067  {
     1068    MEDIA_DEVICE_PATH,
     1069    MEDIA_VENDOR_DP,
     1070    DevPathSerialVendor,
     1071    DevPathCompareDefault
     1072  },
     1073  {
     1074    0,
     1075    0,
     1076    NULL,
     1077    NULL
     1078  }
    10371079};
    10381080
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c

    r48674 r58459  
    22  Provides interface to shell internal functions for shell commands.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2013-2014, Hewlett-Packard Development Company, L.P.<BR>
     5  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    1415
    1516#include "UefiShellCommandLib.h"
    16 
    17 /// The tag for use in identifying UNICODE files.
    18 /// If the file is UNICODE, the first 16 bits of the file will equal this value.
    19 enum {
    20   gUnicodeFileTag = 0xFEFF
    21 };
    2217
    2318// STATIC local variables
     
    3732// global variables required by library class.
    3833EFI_UNICODE_COLLATION_PROTOCOL    *gUnicodeCollation            = NULL;
    39 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *gDevPathToText               = NULL;
    4034SHELL_MAP_LIST                    gShellMapList;
    4135SHELL_MAP_LIST                    *gShellCurDir                 = NULL;
     
    6155  if (gUnicodeCollation == NULL) {
    6256    Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);
    63     if (EFI_ERROR(Status)) {
    64       return (EFI_DEVICE_ERROR);
    65     }
    66   }
    67   if (gDevPathToText == NULL) {
    68     Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID**)&gDevPathToText);
    6957    if (EFI_ERROR(Status)) {
    7058      return (EFI_DEVICE_ERROR);
     
    115103
    116104/**
     105  Frees list of file handles.
     106
     107  @param[in] List     The list to free.
     108**/
     109VOID
     110EFIAPI
     111FreeFileHandleList (
     112  IN BUFFER_LIST *List
     113  )
     114{
     115  BUFFER_LIST               *BufferListEntry;
     116
     117  if (List == NULL){
     118    return;
     119  }
     120  //
     121  // enumerate through the buffer list and free all memory
     122  //
     123  for ( BufferListEntry = ( BUFFER_LIST *)GetFirstNode(&List->Link)
     124      ; !IsListEmpty (&List->Link)
     125      ; BufferListEntry = (BUFFER_LIST *)GetFirstNode(&List->Link)
     126     ){
     127    RemoveEntryList(&BufferListEntry->Link);
     128    ASSERT(BufferListEntry->Buffer != NULL);
     129    SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE*)(BufferListEntry->Buffer))->Path);
     130    SHELL_FREE_NON_NULL(BufferListEntry->Buffer);
     131    SHELL_FREE_NON_NULL(BufferListEntry);
     132  }
     133}
     134
     135/**
    117136  Destructor for the library.  free any resources.
    118137
     
    130149{
    131150  SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node;
    132   COMMAND_LIST                      *Node2;
     151  ALIAS_LIST                        *Node2;
    133152  SCRIPT_FILE_LIST                  *Node3;
    134153  SHELL_MAP_LIST                    *MapNode;
     
    145164
    146165  //
    147   // enumerate through the init command list and free all memory
     166  // enumerate through the alias list and free all memory
    148167  //
    149168  while (!IsListEmpty (&mAliasList.Link)) {
    150     Node2 = (COMMAND_LIST *)GetFirstNode(&mAliasList.Link);
     169    Node2 = (ALIAS_LIST *)GetFirstNode(&mAliasList.Link);
    151170    RemoveEntryList(&Node2->Link);
    152171    SHELL_FREE_NON_NULL(Node2->CommandString);
    153     FreePool(Node2);
     172    SHELL_FREE_NON_NULL(Node2->Alias);
     173    SHELL_FREE_NON_NULL(Node2);
    154174    DEBUG_CODE(Node2 = NULL;);
    155175  }
     
    182202  }
    183203  if (!IsListEmpty(&mFileHandleList.Link)){
    184     FreeBufferList(&mFileHandleList);
     204    FreeFileHandleList(&mFileHandleList);
    185205  }
    186206
     
    190210
    191211  gUnicodeCollation            = NULL;
    192   gDevPathToText               = NULL;
    193212  gShellCurDir                 = NULL;
    194213
     
    197216
    198217/**
    199   Checks if a command is already on the list.
     218  Find a dynamic command protocol instance given a command name string.
     219
     220  @param CommandString  the command name string
     221
     222  @return instance      the command protocol instance, if dynamic command instance found
     223  @retval NULL          no dynamic command protocol instance found for name
     224**/
     225CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *
     226EFIAPI
     227ShellCommandFindDynamicCommand (
     228  IN CONST CHAR16 *CommandString
     229  )
     230{
     231  EFI_STATUS                          Status;
     232  EFI_HANDLE                          *CommandHandleList;
     233  EFI_HANDLE                          *NextCommand;
     234  EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *DynamicCommand;
     235
     236  CommandHandleList = GetHandleListByProtocol(&gEfiShellDynamicCommandProtocolGuid);
     237  if (CommandHandleList == NULL) {
     238    //
     239    // not found or out of resources
     240    //
     241    return NULL;
     242  }
     243
     244  for (NextCommand = CommandHandleList; *NextCommand != NULL; NextCommand++) {
     245    Status = gBS->HandleProtocol(
     246      *NextCommand,
     247      &gEfiShellDynamicCommandProtocolGuid,
     248      (VOID **)&DynamicCommand
     249      );
     250
     251    if (EFI_ERROR(Status)) {
     252      continue;
     253    }
     254
     255    if (gUnicodeCollation->StriColl(
     256          gUnicodeCollation,
     257          (CHAR16*)CommandString,
     258          (CHAR16*)DynamicCommand->CommandName) == 0
     259          ){
     260        FreePool(CommandHandleList);
     261        return (DynamicCommand);
     262    }
     263  }
     264
     265  FreePool(CommandHandleList);
     266  return (NULL);
     267}
     268
     269/**
     270  Checks if a command exists as a dynamic command protocol instance
    200271
    201272  @param[in] CommandString        The command string to check for on the list.
     
    203274BOOLEAN
    204275EFIAPI
    205 ShellCommandIsCommandOnList (
    206   IN CONST  CHAR16                      *CommandString
     276ShellCommandDynamicCommandExists (
     277  IN CONST CHAR16 *CommandString
     278  )
     279{
     280  return (BOOLEAN) ((ShellCommandFindDynamicCommand(CommandString) != NULL));
     281}
     282
     283/**
     284  Checks if a command is already on the internal command list.
     285
     286  @param[in] CommandString        The command string to check for on the list.
     287**/
     288BOOLEAN
     289EFIAPI
     290ShellCommandIsCommandOnInternalList(
     291  IN CONST  CHAR16 *CommandString
    207292  )
    208293{
     
    234319
    235320/**
    236   Get the help text for a command.
     321  Checks if a command exists, either internally or through the dynamic command protocol.
     322
     323  @param[in] CommandString        The command string to check for on the list.
     324**/
     325BOOLEAN
     326EFIAPI
     327ShellCommandIsCommandOnList(
     328  IN CONST  CHAR16                      *CommandString
     329  )
     330{
     331  if (ShellCommandIsCommandOnInternalList(CommandString)) {
     332    return TRUE;
     333  }
     334
     335  return ShellCommandDynamicCommandExists(CommandString);
     336}
     337
     338/**
     339 Get the help text for a dynamic command.
     340
     341  @param[in] CommandString        The command name.
     342
     343  @retval NULL  No help text was found.
     344  @return       String of help text. Caller required to free.
     345**/
     346CHAR16*
     347EFIAPI
     348ShellCommandGetDynamicCommandHelp(
     349  IN CONST  CHAR16                      *CommandString
     350  )
     351{
     352  EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *DynamicCommand;
     353
     354  DynamicCommand = (EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *)ShellCommandFindDynamicCommand(CommandString);
     355  if (DynamicCommand == NULL) {
     356    return (NULL);
     357  }
     358
     359  //
     360  // TODO: how to get proper language?
     361  //
     362  return DynamicCommand->GetHelp(DynamicCommand, "en");
     363}
     364
     365/**
     366  Get the help text for an internal command.
    237367
    238368  @param[in] CommandString        The command name.
     
    243373CHAR16*
    244374EFIAPI
    245 ShellCommandGetCommandHelp (
     375ShellCommandGetInternalCommandHelp(
    246376  IN CONST  CHAR16                      *CommandString
    247377  )
     
    272402  return (NULL);
    273403}
     404
     405/**
     406  Get the help text for a command.
     407
     408  @param[in] CommandString        The command name.
     409
     410  @retval NULL  No help text was found.
     411  @return       String of help text.Caller reuiqred to free.
     412**/
     413CHAR16*
     414EFIAPI
     415ShellCommandGetCommandHelp (
     416  IN CONST  CHAR16                      *CommandString
     417  )
     418{
     419  CHAR16      *HelpStr;
     420  HelpStr = ShellCommandGetInternalCommandHelp(CommandString);
     421
     422  if (HelpStr == NULL) {
     423    HelpStr = ShellCommandGetDynamicCommandHelp(CommandString);
     424  }
     425
     426  return HelpStr;
     427}
     428
    274429
    275430/**
     
    334489{
    335490  SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node;
     491  SHELL_COMMAND_INTERNAL_LIST_ENTRY *Command;
     492  SHELL_COMMAND_INTERNAL_LIST_ENTRY *PrevCommand;
     493  INTN LexicalMatchValue;
     494
     495  //
     496  // Initialize local variables.
     497  //
     498  Command = NULL;
     499  PrevCommand = NULL;
     500  LexicalMatchValue = 0;
    336501
    337502  //
     
    362527  Node = AllocateZeroPool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY));
    363528  ASSERT(Node != NULL);
    364   Node->CommandString = AllocateZeroPool(StrSize(CommandString));
     529  Node->CommandString = AllocateCopyPool(StrSize(CommandString), CommandString);
    365530  ASSERT(Node->CommandString != NULL);
    366 
    367   //
    368   // populate the new struct
    369   //
    370   StrCpy(Node->CommandString, CommandString);
    371531
    372532  Node->GetManFileName  = GetManFileName;
     
    392552
    393553  //
    394   // add the new struct to the list
    395   //
    396   InsertTailList (&mCommandList.Link, &Node->Link);
     554  // Insert a new entry on top of the list
     555  //
     556  InsertHeadList (&mCommandList.Link, &Node->Link);
     557
     558  //
     559  // Move a new registered command to its sorted ordered location in the list
     560  //
     561  for (Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetFirstNode (&mCommandList.Link),
     562        PrevCommand = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetFirstNode (&mCommandList.Link)
     563        ; !IsNull (&mCommandList.Link, &Command->Link)
     564        ; Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Command->Link)) {
     565
     566    //
     567    // Get Lexical Comparison Value between PrevCommand and Command list entry
     568    //
     569    LexicalMatchValue = gUnicodeCollation->StriColl (
     570                                             gUnicodeCollation,
     571                                             PrevCommand->CommandString,
     572                                             Command->CommandString
     573                                             );
     574
     575    //
     576    // Swap PrevCommand and Command list entry if PrevCommand list entry
     577    // is alphabetically greater than Command list entry
     578    //
     579    if (LexicalMatchValue > 0){
     580      Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *) SwapListEntries (&PrevCommand->Link, &Command->Link);
     581    } else if (LexicalMatchValue < 0) {
     582      //
     583      // PrevCommand entry is lexically lower than Command entry
     584      //
     585      break;
     586    }
     587  }
    397588
    398589  return (RETURN_SUCCESS);
     
    446637  )
    447638{
    448   SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node;
     639  SHELL_COMMAND_INTERNAL_LIST_ENTRY   *Node;
     640  EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *DynamicCommand;
    449641
    450642  //
     
    465657          (CHAR16*)CommandString,
    466658          Node->CommandString) == 0
    467        ){
     659      ){
    468660      if (CanAffectLE != NULL) {
    469661        *CanAffectLE = Node->LastError;
     
    477669    }
    478670  }
     671
     672  //
     673  // An internal command was not found, try to find a dynamic command
     674  //
     675  DynamicCommand = (EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *)ShellCommandFindDynamicCommand(CommandString);
     676  if (DynamicCommand != NULL) {
     677    if (RetVal != NULL) {
     678      *RetVal = DynamicCommand->Handler(DynamicCommand, gST, gEfiShellParametersProtocol, gEfiShellProtocol);
     679    } else {
     680      DynamicCommand->Handler(DynamicCommand, gST, gEfiShellParametersProtocol, gEfiShellProtocol);
     681    }
     682    return (RETURN_SUCCESS);
     683  }
     684
    479685  return (RETURN_NOT_FOUND);
    480686}
     
    567773{
    568774  ALIAS_LIST *Node;
     775  ALIAS_LIST *CommandAlias;
     776  ALIAS_LIST *PrevCommandAlias;
     777  INTN       LexicalMatchValue;
    569778
    570779  //
     
    579788  Node = AllocateZeroPool(sizeof(ALIAS_LIST));
    580789  ASSERT(Node != NULL);
    581   Node->CommandString = AllocateZeroPool(StrSize(Command));
    582   Node->Alias = AllocateZeroPool(StrSize(Alias));
     790  Node->CommandString = AllocateCopyPool(StrSize(Command), Command);
     791  Node->Alias = AllocateCopyPool(StrSize(Alias), Alias);
    583792  ASSERT(Node->CommandString != NULL);
    584793  ASSERT(Node->Alias != NULL);
    585794
    586   //
    587   // populate the new struct
    588   //
    589   StrCpy(Node->CommandString, Command);
    590   StrCpy(Node->Alias        , Alias );
    591 
    592   //
    593   // add the new struct to the list
    594   //
    595   InsertTailList (&mAliasList.Link, &Node->Link);
     795  InsertHeadList (&mAliasList.Link, &Node->Link);
     796
     797  //
     798  // Move a new pre-defined registered alias to its sorted ordered location in the list
     799  //
     800  for ( CommandAlias = (ALIAS_LIST *)GetFirstNode (&mAliasList.Link),
     801         PrevCommandAlias = (ALIAS_LIST *)GetFirstNode (&mAliasList.Link)
     802       ; !IsNull (&mAliasList.Link, &CommandAlias->Link)
     803       ; CommandAlias = (ALIAS_LIST *) GetNextNode (&mAliasList.Link, &CommandAlias->Link) ) {
     804    //
     805    // Get Lexical comparison value between PrevCommandAlias and CommandAlias List Entry
     806    //
     807    LexicalMatchValue = gUnicodeCollation->StriColl (
     808                                             gUnicodeCollation,
     809                                             PrevCommandAlias->Alias,
     810                                             CommandAlias->Alias
     811                                             );
     812
     813    //
     814    // Swap PrevCommandAlias and CommandAlias list entry if PrevCommandAlias list entry
     815    // is alphabetically greater than CommandAlias list entry
     816    //
     817    if (LexicalMatchValue > 0) {
     818      CommandAlias = (ALIAS_LIST *) SwapListEntries (&PrevCommandAlias->Link, &CommandAlias->Link);
     819    } else if (LexicalMatchValue < 0) {
     820      //
     821      // PrevCommandAlias entry is lexically lower than CommandAlias entry
     822      //
     823      break;
     824    }
     825  }
    596826
    597827  return (RETURN_SUCCESS);
     
    663893
    664894/**
    665   Function to determine current state of ECHO.  Echo determins if lines from scripts
     895  Function to determine current state of ECHO.  Echo determines if lines from scripts
    666896  and ECHO commands are enabled.
    667897
     
    679909
    680910/**
    681   Function to set current state of ECHO.  Echo determins if lines from scripts
     911  Function to set current state of ECHO.  Echo determines if lines from scripts
    682912  and ECHO commands are enabled.
    683913
     
    9361166  } else {
    9371167    MapListNode->Flags = Flags;
    938     MapListNode->MapName = AllocateZeroPool(StrSize(Name));
     1168    MapListNode->MapName = AllocateCopyPool(StrSize(Name), Name);
    9391169    MapListNode->DevicePath = DuplicateDevicePath(DevicePath);
    9401170    if ((MapListNode->MapName == NULL) || (MapListNode->DevicePath == NULL)){
    9411171      Status = EFI_OUT_OF_RESOURCES;
    9421172    } else {
    943       StrCpy(MapListNode->MapName, Name);
    9441173      InsertTailList(&gShellMapList.Link, &MapListNode->Link);
    9451174    }
     
    11431372
    11441373/**
     1374  Add mappings for any devices without one.  Do not change any existing maps.
     1375
     1376  @retval EFI_SUCCESS   The operation was successful.
     1377**/
     1378EFI_STATUS
     1379EFIAPI
     1380ShellCommandUpdateMapping (
     1381  VOID
     1382  )
     1383{
     1384  EFI_STATUS                Status;
     1385  EFI_HANDLE                *HandleList;
     1386  UINTN                     Count;
     1387  EFI_DEVICE_PATH_PROTOCOL  **DevicePathList;
     1388  CHAR16                    *NewDefaultName;
     1389  CHAR16                    *NewConsistName;
     1390  EFI_DEVICE_PATH_PROTOCOL  **ConsistMappingTable;
     1391
     1392  HandleList  = NULL;
     1393  Status      = EFI_SUCCESS;
     1394
     1395  //
     1396  // remove mappings that represent removed devices.
     1397  //
     1398
     1399  //
     1400  // Find each handle with Simple File System
     1401  //
     1402  HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
     1403  if (HandleList != NULL) {
     1404    //
     1405    // Do a count of the handles
     1406    //
     1407    for (Count = 0 ; HandleList[Count] != NULL ; Count++);
     1408
     1409    //
     1410    // Get all Device Paths
     1411    //
     1412    DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
     1413    if (DevicePathList == NULL) {
     1414      return (EFI_OUT_OF_RESOURCES);
     1415    }
     1416
     1417    for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
     1418      DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);
     1419    }
     1420
     1421    //
     1422    // Sort all DevicePaths
     1423    //
     1424    PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);
     1425
     1426    ShellCommandConsistMappingInitialize(&ConsistMappingTable);
     1427
     1428    //
     1429    // Assign new Mappings to remainders
     1430    //
     1431    for (Count = 0 ; !EFI_ERROR(Status) && HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {
     1432      //
     1433      // Skip ones that already have
     1434      //
     1435      if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) {
     1436        continue;
     1437      }
     1438      //
     1439      // Get default name
     1440      //
     1441      NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);
     1442      if (NewDefaultName == NULL) {
     1443        Status = EFI_OUT_OF_RESOURCES;
     1444        break;
     1445      }
     1446
     1447      //
     1448      // Call shell protocol SetMap function now...
     1449      //
     1450      Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName);
     1451
     1452      if (!EFI_ERROR(Status)) {
     1453        //
     1454        // Now do consistent name
     1455        //
     1456        NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);
     1457        if (NewConsistName != NULL) {
     1458          Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName);
     1459          FreePool(NewConsistName);
     1460        }
     1461      }
     1462
     1463      FreePool(NewDefaultName);
     1464    }
     1465    ShellCommandConsistMappingUnInitialize(ConsistMappingTable);
     1466    SHELL_FREE_NON_NULL(HandleList);
     1467    SHELL_FREE_NON_NULL(DevicePathList);
     1468
     1469    HandleList = NULL;
     1470  } else {
     1471    Count = (UINTN)-1;
     1472  }
     1473  //
     1474  // Do it all over again for gEfiBlockIoProtocolGuid
     1475  //
     1476
     1477  return (Status);
     1478}
     1479
     1480/**
    11451481  Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
    11461482
     
    11841520    NewNode             = AllocateZeroPool(sizeof(BUFFER_LIST));
    11851521    if (NewNode == NULL) {
     1522      SHELL_FREE_NON_NULL(Buffer);
    11861523      return (NULL);
    11871524    }
     
    11891526    Buffer->Path        = StrnCatGrow(&Buffer->Path, NULL, Path, 0);
    11901527    if (Buffer->Path == NULL) {
     1528      SHELL_FREE_NON_NULL(NewNode);
     1529      SHELL_FREE_NON_NULL(Buffer);
    11911530      return (NULL);
    11921531    }
     
    13261665     ){
    13271666    RemoveEntryList(&BufferListEntry->Link);
    1328     ASSERT(BufferListEntry->Buffer != NULL);
    13291667    if (BufferListEntry->Buffer != NULL) {
    13301668      FreePool(BufferListEntry->Buffer);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h

    r48674 r58459  
    22  Provides interface to shell internal functions for shell commands.
    33
    4   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    2929#include <Protocol/UnicodeCollation.h>
    3030#include <Protocol/BlockIo.h>
     31#include <Protocol/EfiShellDynamicCommand.h>
    3132
    3233#include <Library/DevicePathLib.h>
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf

    r48674 r58459  
    22#  Provides interface to shell internal functions for shell commands.
    33#
    4 #  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved. <BR>
     4#  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved. <BR>
    55#
    66#  This program and the accompanying materials
     
    2020  MODULE_TYPE                    = UEFI_DRIVER
    2121  VERSION_STRING                 = 1.0
    22   LIBRARY_CLASS                  = ShellCommandLib|UEFI_APPLICATION UEFI_DRIVER
     22  LIBRARY_CLASS                  = ShellCommandLib|UEFI_APPLICATION UEFI_DRIVER DXE_RUNTIME_DRIVER
    2323  CONSTRUCTOR                    = ShellCommandLibConstructor
    2424  DESTRUCTOR                     = ShellCommandLibDestructor
     
    4747  ShellLib
    4848  HiiLib
     49  HandleParsingLib
    4950
    5051[Protocols]
    51   gEfiUnicodeCollation2ProtocolGuid                       # ALWAYS_CONSUMED
    52   gEfiShellProtocolGuid                                   # ALWAYS_CONSUMED
    53   gEfiShellParametersProtocolGuid                         # ALWAYS_CONSUMED
    54   gEfiDevicePathToTextProtocolGuid                        # ALWAYS_CONSUMED
     52  gEfiUnicodeCollation2ProtocolGuid                       ## CONSUMES
     53  gEfiShellProtocolGuid                                   ## CONSUMES
     54  gEfiShellParametersProtocolGuid                         ## CONSUMES
     55  gEfiShellDynamicCommandProtocolGuid                     ## SOMETIMES_CONSUMES
    5556
    5657[Guids]
    57   gEfiSasDevicePathGuid                                   # ALWAYS_CONSUMED
     58  gEfiSasDevicePathGuid                                   ## CONSUMES ## GUID
    5859
    5960[Pcd.common]
    60   gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel         ## ALWAYS_CONSUMED
    61   gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength        ## ALWAYS_CONSUMED
     61  gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel         ## CONSUMES
     62  gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength        ## CONSUMES
     63
     64[Depex]
     65  gEfiUnicodeCollation2ProtocolGuid
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c

    r48674 r58459  
    22  Main file for Comp shell Debug1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    5151  CHAR16              *FileName2;
    5252  CONST CHAR16        *TempParam;
     53  UINTN               ErrorAddress;
    5354
    5455  ErrorCount          = 0;
     
    137138          ASSERT_EFI_ERROR(Status);
    138139          if (DataFromFile1 != DataFromFile2) {
     140            ErrorAddress = LoopVar;
    139141            ADF_File11 = 0;
    140142            ADF_File12 = 0;
     
    143145            ADF_File22 = 0;
    144146            ADF_File23 = 0;
     147
     148            //
     149            // Now check the next 3 bytes if possible.  This will make output
     150            // cleaner when there are a sequence of differences.
     151            //
    145152            if (LoopVar + 1 < Size1) {
    146153              LoopVar++;
     
    170177              }
    171178            }
     179
     180            //
     181            // Print out based on highest of the 4 bytes that are different.
     182            //
    172183            if (ADF_File13 != ADF_File23) {
    173184              ShellPrintHiiEx(
     
    179190                ++ErrorCount,
    180191                FileName1,
    181                 LoopVar,
     192                ErrorAddress,
    182193                DataFromFile1, ADF_File11, ADF_File12, ADF_File13,
    183194                DataFromFile1, ADF_File11, ADF_File12, ADF_File13,
    184195                FileName2,
    185                 LoopVar,
     196                ErrorAddress,
    186197                DataFromFile2, ADF_File21, ADF_File22, ADF_File23,
    187198                DataFromFile2, ADF_File21, ADF_File22, ADF_File23
     
    196207                ++ErrorCount,
    197208                FileName1,
    198                 LoopVar,
     209                ErrorAddress,
    199210                DataFromFile1, ADF_File11, ADF_File12,
    200211                DataFromFile1, ADF_File11, ADF_File12,
    201212                FileName2,
    202                 LoopVar,
     213                ErrorAddress,
    203214                DataFromFile2, ADF_File21, ADF_File22,
    204215                DataFromFile2, ADF_File21, ADF_File22
     
    213224                ++ErrorCount,
    214225                FileName1,
    215                 LoopVar,
     226                ErrorAddress,
    216227                DataFromFile1, ADF_File11,
    217228                DataFromFile1, ADF_File11,
    218229                FileName2,
    219                 LoopVar,
     230                ErrorAddress,
    220231                DataFromFile2, ADF_File21,
    221232                DataFromFile2, ADF_File21
     
    230241                ++ErrorCount,
    231242                FileName1,
    232                 LoopVar,
     243                ErrorAddress,
    233244                DataFromFile1,
    234245                DataFromFile1,
    235246                FileName2,
    236                 LoopVar,
     247                ErrorAddress,
    237248                DataFromFile2,
    238249                DataFromFile2
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c

    r48674 r58459  
    88  are applied to each Block.
    99
    10   Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
     10  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
    1111  This program and the accompanying materials
    1212  are licensed and made available under the terms and conditions of the BSD License
     
    2323#include <Library/DebugLib.h>
    2424#include <ShellBase.h>
     25#include <Uefi.h>
    2526
    2627//
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Dmem.c

    r48674 r58459  
    7575  } else {
    7676    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_MMIO_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size);
    77     DumpHex(2,0,Size,Buffer);
     77    DumpHex(2, (UINTN)Address, Size, Buffer);
    7878  }
    7979
     
    169169      if (!ShellCommandLineGetFlag(Package, L"-mmio")) {
    170170        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMEM_HEADER_ROW), gShellDebug1HiiHandle, (UINT64)(UINTN)Address, Size);
    171         DumpHex(2,0,(UINTN)Size,Address);
     171        DumpHex(2, (UINTN)Address, (UINTN)Size, Address);
    172172        if (Address == (VOID*)gST) {
    173173          Acpi20TableAddress  = 0;
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c

    r48674 r58459  
    11/** @file
    22  Main file for DmpStore shell Debug1 function.
    3 
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     3   
     4  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    1516#include "UefiShellDebug1CommandsLib.h"
    1617
    17 STATIC CHAR16   *AttrType[] = {
    18   L"invalid",   // 000
    19   L"invalid",   // 001
    20   L"BS",        // 010
    21   L"NV+BS",     // 011
    22   L"RT+BS",     // 100
    23   L"NV+RT+BS",  // 101
    24   L"RT+BS",     // 110
    25   L"NV+RT+BS",  // 111
    26 };
     18typedef enum {
     19  DmpStoreDisplay,
     20  DmpStoreDelete,
     21  DmpStoreSave,
     22  DmpStoreLoad
     23} DMP_STORE_TYPE;
     24
     25typedef struct {
     26  UINT32     Signature;
     27  CHAR16     *Name;
     28  EFI_GUID   Guid;
     29  UINT32     Attributes;
     30  UINT32     DataSize;
     31  UINT8      *Data;
     32  LIST_ENTRY Link;
     33} DMP_STORE_VARIABLE;
     34
     35#define DMP_STORE_VARIABLE_SIGNATURE  SIGNATURE_32 ('_', 'd', 's', 's')
    2736
    2837/**
    29   Function to display or delete variables.
    30 
    31   @param[in] VariableName   The variable name of the EFI variable (or NULL).
     38  Base on the input attribute value to return the attribute string.
     39
     40  @param[in]     Atts           The input attribute value
     41
     42  @retval The attribute string info.
     43**/
     44CHAR16 *
     45EFIAPI
     46GetAttrType (
     47  IN CONST UINT32 Atts
     48  )
     49{
     50  UINTN  BufLen;
     51  CHAR16 *RetString;
     52
     53  BufLen      = 0;
     54  RetString   = NULL;
     55 
     56  if ((Atts & EFI_VARIABLE_NON_VOLATILE) != 0) {
     57    StrnCatGrow (&RetString, &BufLen, L"+NV", 0);
     58  }
     59  if ((Atts & EFI_VARIABLE_RUNTIME_ACCESS) != 0) {
     60    StrnCatGrow (&RetString, &BufLen, L"+RT+BS", 0);
     61  } else if ((Atts & EFI_VARIABLE_BOOTSERVICE_ACCESS) != 0) {
     62    StrnCatGrow (&RetString, &BufLen, L"+BS", 0);
     63  }
     64  if ((Atts & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) {
     65    StrnCatGrow (&RetString, &BufLen, L"+HR", 0);
     66  }
     67  if ((Atts & EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) != 0) {
     68    StrnCatGrow (&RetString, &BufLen, L"+AW", 0);
     69  }
     70  if ((Atts & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != 0) {
     71    StrnCatGrow (&RetString, &BufLen, L"+AT", 0);
     72  }
     73
     74  if (RetString == NULL) {
     75    RetString = StrnCatGrow(&RetString, &BufLen, L"Invalid", 0);
     76  }
     77
     78  if ((RetString != NULL) && (RetString[0] == L'+')) {
     79    CopyMem(RetString, RetString + 1, StrSize(RetString + 1));
     80  }
     81
     82  return RetString;
     83}
     84
     85/**
     86  Load the variable data from file and set to variable data base.
     87
     88  @param[in]  FileHandle     The file to be read.
     89  @param[in]  Name           The name of the variables to be loaded.
     90  @param[in]  Guid           The guid of the variables to be loaded.
     91  @param[out] Found          TRUE when at least one variable was loaded and set.
     92
     93  @retval SHELL_DEVICE_ERROR      Cannot access the file.
     94  @retval SHELL_VOLUME_CORRUPTED  The file is in bad format.
     95  @retval SHELL_OUT_OF_RESOURCES  There is not enough memory to perform the operation.
     96  @retval SHELL_SUCCESS           Successfully load and set the variables.
     97**/
     98SHELL_STATUS
     99LoadVariablesFromFile (
     100  IN SHELL_FILE_HANDLE FileHandle,
     101  IN CONST CHAR16      *Name,
     102  IN CONST EFI_GUID    *Guid,
     103  OUT BOOLEAN          *Found
     104  )
     105{
     106  EFI_STATUS           Status;
     107  SHELL_STATUS         ShellStatus;
     108  UINT32               NameSize;
     109  UINT32               DataSize;
     110  UINTN                BufferSize;
     111  UINTN                RemainingSize;
     112  UINT64               Position;
     113  UINT64               FileSize;
     114  LIST_ENTRY           List;
     115  DMP_STORE_VARIABLE   *Variable;
     116  LIST_ENTRY           *Link;
     117  CHAR16               *Attributes;
     118  UINT8                *Buffer;
     119  UINT32               Crc32;
     120
     121  Status = ShellGetFileSize (FileHandle, &FileSize);
     122  if (EFI_ERROR (Status)) {
     123    return SHELL_DEVICE_ERROR;
     124  }
     125 
     126  ShellStatus = SHELL_SUCCESS;
     127 
     128  InitializeListHead (&List);
     129 
     130  Position = 0;
     131  while (Position < FileSize) {
     132    //
     133    // NameSize
     134    //
     135    BufferSize = sizeof (NameSize);
     136    Status = ShellReadFile (FileHandle, &BufferSize, &NameSize);
     137    if (EFI_ERROR (Status) || (BufferSize != sizeof (NameSize))) {
     138      ShellStatus = SHELL_VOLUME_CORRUPTED;
     139      break;
     140    }
     141
     142    //
     143    // DataSize
     144    //
     145    BufferSize = sizeof (DataSize);
     146    Status = ShellReadFile (FileHandle, &BufferSize, &DataSize);
     147    if (EFI_ERROR (Status) || (BufferSize != sizeof (DataSize))) {
     148      ShellStatus = SHELL_VOLUME_CORRUPTED;
     149      break;
     150    }
     151
     152    //
     153    // Name, Guid, Attributes, Data, Crc32
     154    //
     155    RemainingSize = NameSize + sizeof (EFI_GUID) + sizeof (UINT32) + DataSize + sizeof (Crc32);
     156    BufferSize    = sizeof (NameSize) + sizeof (DataSize) + RemainingSize;
     157    Buffer        = AllocatePool (BufferSize);
     158    if (Buffer == NULL) {
     159      ShellStatus = SHELL_OUT_OF_RESOURCES;
     160      break;
     161    }
     162    BufferSize    = RemainingSize;
     163    Status = ShellReadFile (FileHandle, &BufferSize, (UINT32 *) Buffer + 2);
     164    if (EFI_ERROR (Status) || (BufferSize != RemainingSize)) {
     165      ShellStatus = SHELL_VOLUME_CORRUPTED;
     166      FreePool (Buffer);
     167      break;
     168    }
     169
     170    //
     171    // Check Crc32
     172    //
     173    * (UINT32 *) Buffer       = NameSize;
     174    * ((UINT32 *) Buffer + 1) = DataSize;
     175    BufferSize = RemainingSize + sizeof (NameSize) + sizeof (DataSize) - sizeof (Crc32);
     176    gBS->CalculateCrc32 (
     177           Buffer,
     178           BufferSize,
     179           &Crc32
     180           );
     181    if (Crc32 != * (UINT32 *) (Buffer + BufferSize)) {
     182      FreePool (Buffer);
     183      ShellStatus = SHELL_VOLUME_CORRUPTED;
     184      break;
     185    }
     186
     187    Position += BufferSize + sizeof (Crc32);
     188   
     189    Variable = AllocateZeroPool (sizeof (*Variable) + NameSize + DataSize);
     190    if (Variable == NULL) {
     191      FreePool (Buffer);
     192      ShellStatus = SHELL_OUT_OF_RESOURCES;
     193      break;
     194    }
     195    Variable->Signature = DMP_STORE_VARIABLE_SIGNATURE;
     196    Variable->Name      = (CHAR16 *) (Variable + 1);
     197    Variable->DataSize  = DataSize;
     198    Variable->Data      = (UINT8 *) Variable->Name + NameSize;
     199    CopyMem (Variable->Name,        Buffer + sizeof (NameSize) + sizeof (DataSize),                                                  NameSize);
     200    CopyMem (&Variable->Guid,       Buffer + sizeof (NameSize) + sizeof (DataSize) + NameSize,                                       sizeof (EFI_GUID));
     201    CopyMem (&Variable->Attributes, Buffer + sizeof (NameSize) + sizeof (DataSize) + NameSize + sizeof (EFI_GUID),                   sizeof (UINT32));
     202    CopyMem (Variable->Data,        Buffer + sizeof (NameSize) + sizeof (DataSize) + NameSize + sizeof (EFI_GUID) + sizeof (UINT32), DataSize);
     203
     204    InsertTailList (&List, &Variable->Link);
     205    FreePool (Buffer);
     206  }
     207   
     208  if ((Position != FileSize) || (ShellStatus != SHELL_SUCCESS)) {
     209    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_BAD_FILE), gShellDebug1HiiHandle);
     210    if (Position != FileSize) {
     211      ShellStatus = SHELL_VOLUME_CORRUPTED;
     212    }
     213  }
     214 
     215  for ( Link = GetFirstNode (&List)
     216      ; !IsNull (&List, Link) && (ShellStatus == SHELL_SUCCESS)
     217      ; Link = GetNextNode (&List, Link)
     218      ) {
     219    Variable = CR (Link, DMP_STORE_VARIABLE, Link, DMP_STORE_VARIABLE_SIGNATURE);
     220   
     221    if (((Name == NULL) || gUnicodeCollation->MetaiMatch (gUnicodeCollation, Variable->Name, (CHAR16 *) Name)) &&
     222        ((Guid == NULL) || CompareGuid (&Variable->Guid, Guid))
     223       ) {
     224      Attributes = GetAttrType (Variable->Attributes);
     225      ShellPrintHiiEx (
     226        -1, -1, NULL, STRING_TOKEN(STR_DMPSTORE_HEADER_LINE), gShellDebug1HiiHandle,
     227        Attributes, &Variable->Guid, Variable->Name, Variable->DataSize
     228        );
     229      SHELL_FREE_NON_NULL(Attributes);
     230
     231      *Found = TRUE;
     232      Status = gRT->SetVariable (
     233                      Variable->Name,
     234                      &Variable->Guid,
     235                      Variable->Attributes,
     236                      Variable->DataSize,
     237                      Variable->Data
     238                      );
     239      if (EFI_ERROR (Status)) {
     240        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD_GEN_FAIL), gShellDebug1HiiHandle, Variable->Name, Status);
     241      }
     242    }
     243  }
     244
     245  for (Link = GetFirstNode (&List); !IsNull (&List, Link); ) {
     246    Variable = CR (Link, DMP_STORE_VARIABLE, Link, DMP_STORE_VARIABLE_SIGNATURE);
     247    Link = RemoveEntryList (&Variable->Link);
     248    FreePool (Variable);
     249  }
     250
     251  return ShellStatus;
     252}
     253
     254/**
     255  Append one variable to file.
     256
     257  @param[in] FileHandle        The file to be appended.
     258  @param[in] Name              The variable name.
     259  @param[in] Guid              The variable GUID.
     260  @param[in] Attributes        The variable attributes.
     261  @param[in] DataSize          The variable data size.
     262  @param[in] Data              The variable data.
     263
     264  @retval EFI_OUT_OF_RESOURCES  There is not enough memory to perform the operation.
     265  @retval EFI_SUCCESS           The variable is appended to file successfully.
     266  @retval others                Failed to append the variable to file.
     267**/
     268EFI_STATUS
     269AppendSingleVariableToFile (
     270  IN SHELL_FILE_HANDLE FileHandle,
     271  IN CONST CHAR16      *Name,
     272  IN CONST EFI_GUID    *Guid,
     273  IN UINT32            Attributes,
     274  IN UINT32            DataSize,
     275  IN CONST UINT8       *Data
     276  )
     277{
     278  UINT32              NameSize;
     279  UINT8               *Buffer;
     280  UINT8               *Ptr;
     281  UINTN               BufferSize;
     282  EFI_STATUS          Status;
     283
     284  NameSize   = (UINT32) StrSize (Name);
     285  BufferSize = sizeof (NameSize) + sizeof (DataSize)
     286             + sizeof (*Guid)
     287             + sizeof (Attributes)
     288             + NameSize + DataSize
     289             + sizeof (UINT32);
     290
     291  Buffer = AllocatePool (BufferSize);
     292  if (Buffer == NULL) {
     293    return EFI_OUT_OF_RESOURCES;
     294  }
     295
     296  Ptr = Buffer;
     297  //
     298  // NameSize and DataSize
     299  //
     300  * (UINT32 *) Ptr = NameSize;
     301  Ptr += sizeof (NameSize);
     302  *(UINT32 *) Ptr = DataSize;
     303  Ptr += sizeof (DataSize);
     304
     305  //
     306  // Name
     307  //
     308  CopyMem (Ptr, Name, NameSize);
     309  Ptr += NameSize;
     310
     311  //
     312  // Guid
     313  //
     314  CopyMem (Ptr, Guid, sizeof (*Guid));
     315  Ptr += sizeof (*Guid);
     316
     317  //
     318  // Attributes
     319  //
     320  * (UINT32 *) Ptr = Attributes;
     321  Ptr += sizeof (Attributes);
     322
     323  //
     324  // Data
     325  //
     326  CopyMem (Ptr, Data, DataSize);
     327  Ptr += DataSize;
     328
     329  //
     330  // Crc32
     331  //
     332  gBS->CalculateCrc32 (Buffer, (UINTN) (Ptr - Buffer), (UINT32 *) Ptr);
     333
     334  Status = ShellWriteFile (FileHandle, &BufferSize, Buffer);
     335  FreePool (Buffer);
     336
     337  if (!EFI_ERROR (Status) &&
     338      (BufferSize != sizeof (NameSize) + sizeof (DataSize) + sizeof (*Guid) + sizeof (Attributes) + NameSize + DataSize)
     339    ) {
     340    Status = EFI_DEVICE_ERROR;
     341  }
     342 
     343  return Status;
     344}
     345
     346/**
     347  Recursive function to display or delete variables.
     348
     349  This function will call itself to create a stack-based list of allt he variables to process,
     350  then fromt he last to the first, they will do either printing or deleting.
     351
     352  This is necessary since once a delete happens GetNextVariableName() will work.
     353
     354  @param[in] Name           The variable name of the EFI variable (or NULL).
    32355  @param[in] Guid           The GUID of the variable set (or NULL).
    33   @param[in] Delete         TRUE to delete, FALSE otherwise.
     356  @param[in] Type           The operation type.
     357  @param[in] FileHandle     The file to operate on (or NULL).
     358  @param[in] PrevName       The previous variable name from GetNextVariableName. L"" to start.
     359  @param[in] FoundVarGuid   The previous GUID from GetNextVariableName. ignored at start.
     360  @param[in] FoundOne       If a VariableName or Guid was specified and one was printed or
     361                            deleted, then set this to TRUE, otherwise ignored.
     362
     363  @retval SHELL_SUCCESS           The operation was successful.
     364  @retval SHELL_OUT_OF_RESOURCES  A memorty allocation failed.
     365  @retval SHELL_ABORTED           The abort message was received.
     366  @retval SHELL_DEVICE_ERROR      UEFI Variable Services returned an error.
     367  @retval SHELL_NOT_FOUND         the Name/Guid pair could not be found.
     368**/
     369SHELL_STATUS
     370EFIAPI
     371CascadeProcessVariables (
     372  IN CONST CHAR16      *Name        OPTIONAL,
     373  IN CONST EFI_GUID    *Guid        OPTIONAL,
     374  IN DMP_STORE_TYPE    Type,
     375  IN EFI_FILE_PROTOCOL *FileHandle  OPTIONAL,
     376  IN CONST CHAR16      * CONST PrevName,
     377  IN EFI_GUID          FoundVarGuid,
     378  IN BOOLEAN           *FoundOne
     379  )
     380{
     381  EFI_STATUS                Status;
     382  CHAR16                    *FoundVarName;
     383  UINT8                     *DataBuffer;
     384  UINTN                     DataSize;
     385  UINT32                    Atts;
     386  SHELL_STATUS              ShellStatus;
     387  UINTN                     NameSize;
     388  CHAR16                    *RetString;
     389
     390  if (ShellGetExecutionBreakFlag()) {
     391    return (SHELL_ABORTED);
     392  }
     393
     394  NameSize      = 0;
     395  FoundVarName  = NULL;
     396
     397  if (PrevName!=NULL) {
     398    StrnCatGrow(&FoundVarName, &NameSize, PrevName, 0);
     399  } else {
     400    FoundVarName = AllocateZeroPool(sizeof(CHAR16));
     401  }
     402
     403  Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
     404  if (Status == EFI_BUFFER_TOO_SMALL) {
     405    SHELL_FREE_NON_NULL(FoundVarName);
     406    FoundVarName = AllocateZeroPool (NameSize);
     407    if (FoundVarName != NULL) {
     408      if (PrevName != NULL) {
     409        StrnCpy(FoundVarName, PrevName, NameSize/sizeof(CHAR16)-1);
     410      }
     411
     412      Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);
     413    } else {
     414      Status = EFI_OUT_OF_RESOURCES;
     415    }
     416  }
     417
     418  //
     419  // No more is fine.
     420  //
     421  if (Status == EFI_NOT_FOUND) {
     422    SHELL_FREE_NON_NULL(FoundVarName);
     423    return (SHELL_SUCCESS);
     424  } else if (EFI_ERROR(Status)) {
     425    SHELL_FREE_NON_NULL(FoundVarName);
     426    return (SHELL_DEVICE_ERROR);
     427  }
     428
     429  //
     430  // Recurse to the next iteration.  We know "our" variable's name.
     431  //
     432  ShellStatus = CascadeProcessVariables(Name, Guid, Type, FileHandle, FoundVarName, FoundVarGuid, FoundOne);
     433
     434  if (ShellGetExecutionBreakFlag() || (ShellStatus == SHELL_ABORTED)) {
     435    SHELL_FREE_NON_NULL(FoundVarName);
     436    return (SHELL_ABORTED);
     437  }
     438
     439  //
     440  // No matter what happened we process our own variable
     441  // Only continue if Guid and VariableName are each either NULL or a match
     442  //
     443  if ( ( Name == NULL
     444      || gUnicodeCollation->MetaiMatch(gUnicodeCollation, FoundVarName, (CHAR16*) Name) )
     445     && ( Guid == NULL
     446      || CompareGuid(&FoundVarGuid, Guid) )
     447      ) {
     448    DataSize      = 0;
     449    DataBuffer    = NULL;
     450    //
     451    // do the print or delete
     452    //
     453    *FoundOne = TRUE;
     454    Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
     455    if (Status == EFI_BUFFER_TOO_SMALL) {
     456      SHELL_FREE_NON_NULL (DataBuffer);
     457      DataBuffer = AllocatePool (DataSize);
     458      if (DataBuffer == NULL) {
     459        Status = EFI_OUT_OF_RESOURCES;
     460      } else {
     461        Status = gRT->GetVariable (FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
     462      }
     463    }
     464    if ((Type == DmpStoreDisplay) || (Type == DmpStoreSave)) {
     465      //
     466      // Last error check then print this variable out.
     467      //
     468      if (!EFI_ERROR(Status) && (DataBuffer != NULL) && (FoundVarName != NULL)) {
     469        RetString = GetAttrType(Atts);
     470        ShellPrintHiiEx(
     471          -1,
     472          -1,
     473          NULL,
     474          STRING_TOKEN(STR_DMPSTORE_HEADER_LINE),
     475          gShellDebug1HiiHandle,
     476          RetString,
     477          &FoundVarGuid,
     478          FoundVarName,
     479          DataSize);
     480        if (Type == DmpStoreDisplay) {
     481          DumpHex(2, 0, DataSize, DataBuffer);
     482        } else {
     483          Status = AppendSingleVariableToFile (
     484                     FileHandle,
     485                     FoundVarName,
     486                     &FoundVarGuid,
     487                     Atts,
     488                     (UINT32) DataSize,
     489                     DataBuffer
     490                     );
     491        }
     492        SHELL_FREE_NON_NULL(RetString);
     493      }
     494    } else if (Type == DmpStoreDelete) {
     495      //
     496      // We only need name to delete it...
     497      //
     498      ShellPrintHiiEx (
     499        -1,
     500        -1,
     501        NULL,
     502        STRING_TOKEN(STR_DMPSTORE_DELETE_LINE),
     503        gShellDebug1HiiHandle,
     504        &FoundVarGuid,
     505        FoundVarName,
     506        gRT->SetVariable (FoundVarName, &FoundVarGuid, Atts, 0, NULL)
     507        );
     508    }
     509    SHELL_FREE_NON_NULL(DataBuffer);
     510  }
     511
     512  SHELL_FREE_NON_NULL(FoundVarName);
     513
     514  if (Status == EFI_DEVICE_ERROR) {
     515    ShellStatus = SHELL_DEVICE_ERROR;
     516  } else if (Status == EFI_SECURITY_VIOLATION) {
     517    ShellStatus = SHELL_SECURITY_VIOLATION;
     518  } else if (EFI_ERROR(Status)) {
     519    ShellStatus = SHELL_NOT_READY;
     520  }
     521
     522  return (ShellStatus);
     523}
     524
     525/**
     526  Function to display or delete variables.  This will set up and call into the recursive function.
     527
     528  @param[in] Name        The variable name of the EFI variable (or NULL).
     529  @param[in] Guid        The GUID of the variable set (or NULL).
     530  @param[in] Type        The operation type.
     531  @param[in] FileHandle  The file to save or load variables.
    34532
    35533  @retval SHELL_SUCCESS           The operation was successful.
     
    42540EFIAPI
    43541ProcessVariables (
    44   IN CONST CHAR16   *VariableName OPTIONAL,
    45   IN CONST EFI_GUID *Guid OPTIONAL,
    46   IN BOOLEAN        Delete
     542  IN CONST CHAR16      *Name      OPTIONAL,
     543  IN CONST EFI_GUID    *Guid      OPTIONAL,
     544  IN DMP_STORE_TYPE    Type,
     545  IN SHELL_FILE_HANDLE FileHandle OPTIONAL
    47546  )
    48547{
    49   EFI_STATUS                Status;
    50   UINT64                    MaxStorSize;
    51   UINT64                    RemStorSize;
    52   UINT64                    MaxVarSize;
    53   CHAR16                    *FoundVarName;
    54   UINTN                     Size;
    55   EFI_GUID                  FoundVarGuid;
    56   UINT8                     *DataBuffer;
    57   UINTN                     DataSize;
    58   UINT32                    Atts;
    59548  SHELL_STATUS              ShellStatus;
    60549  BOOLEAN                   Found;
    61 
    62   Status = gRT->QueryVariableInfo(EFI_VARIABLE_BOOTSERVICE_ACCESS|EFI_VARIABLE_RUNTIME_ACCESS|EFI_VARIABLE_NON_VOLATILE, &MaxStorSize, &RemStorSize, &MaxVarSize);
    63   if (EFI_ERROR(Status)) {
    64     return (SHELL_DEVICE_ERROR);
    65   }
     550  EFI_GUID                  FoundVarGuid;
    66551
    67552  Found         = FALSE;
    68553  ShellStatus   = SHELL_SUCCESS;
    69   Size          = PcdGet16(PcdShellFileOperationSize);
    70   FoundVarName  = AllocateZeroPool(Size);
    71 
    72   if (FoundVarName == NULL) {
    73     return (SHELL_OUT_OF_RESOURCES);
    74   }
    75   FoundVarName[0] = CHAR_NULL;
    76 
    77 
    78   DataSize = (UINTN)MaxVarSize;
    79   DataBuffer = AllocateZeroPool(DataSize);
    80   if (DataBuffer == NULL) {
    81     FreePool(FoundVarName);
    82     return (SHELL_OUT_OF_RESOURCES);
    83   }
    84 
    85   for (;;){
    86     if (ShellGetExecutionBreakFlag()) {
    87       ShellStatus = SHELL_ABORTED;
    88       break;
    89     }
    90     Size      = (UINTN)PcdGet16(PcdShellFileOperationSize);
    91     DataSize  = (UINTN)MaxVarSize;
    92 
    93     Status = gRT->GetNextVariableName(&Size, FoundVarName, &FoundVarGuid);
    94     if (Status == EFI_NOT_FOUND) {
    95       break;
    96     }
    97     ASSERT_EFI_ERROR(Status);
    98 
    99     Status = gRT->GetVariable(FoundVarName, &FoundVarGuid, &Atts, &DataSize, DataBuffer);
    100     ASSERT_EFI_ERROR(Status);
    101 
    102     //
    103     // Check if it matches
    104     //
    105     if (VariableName != NULL) {
    106       if (!gUnicodeCollation->MetaiMatch(gUnicodeCollation, FoundVarName, (CHAR16*)VariableName)) {
    107         continue;
    108       }
    109     }
    110     if (Guid != NULL) {
    111       if (!CompareGuid(&FoundVarGuid, Guid)) {
    112         continue;
    113       }
    114     }
    115 
    116     //
    117     // do the print or delete
    118     //
    119     Found = TRUE;
    120     if (!Delete) {
    121       ShellPrintHiiEx(
    122         -1,
    123         -1,
    124         NULL,
    125         STRING_TOKEN(STR_DMPSTORE_HEADER_LINE),
    126         gShellDebug1HiiHandle,
    127         AttrType[Atts & 7],
    128         &FoundVarGuid,
    129         FoundVarName,
    130         DataSize);
    131       DumpHex(2, 0, DataSize, DataBuffer);
    132     } else {
    133       ShellPrintHiiEx(
    134         -1,
    135         -1,
    136         NULL,
    137         STRING_TOKEN(STR_DMPSTORE_DELETE_LINE),
    138         gShellDebug1HiiHandle,
    139         &FoundVarGuid,
    140         FoundVarName);
    141       ShellPrintHiiEx(
    142         -1,
    143         -1,
    144         NULL,
    145         STRING_TOKEN(STR_DMPSTORE_DELETE_DONE),
    146         gShellDebug1HiiHandle,
    147         gRT->SetVariable(FoundVarName, &FoundVarGuid, Atts, 0, NULL));
    148     }
    149   }
    150 
    151   if (FoundVarName != NULL) {
    152     FreePool(FoundVarName);
    153   }
    154   if (DataBuffer != NULL) {
    155     FreePool(DataBuffer);
    156   }
     554  ZeroMem (&FoundVarGuid, sizeof(EFI_GUID));
     555
     556  if (Type == DmpStoreLoad) {
     557    ShellStatus = LoadVariablesFromFile (FileHandle, Name, Guid, &Found);
     558  } else {
     559    ShellStatus = CascadeProcessVariables(Name, Guid, Type, FileHandle, NULL, FoundVarGuid, &Found);
     560  }
     561
    157562  if (!Found) {
    158     if (VariableName != NULL && Guid == NULL) {
    159       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, VariableName);
    160     } else if (VariableName != NULL && Guid != NULL) {
    161       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, Guid, VariableName);
    162     } else if (VariableName == NULL && Guid == NULL) {
     563    if (ShellStatus == SHELL_OUT_OF_RESOURCES) {
     564      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);
     565      return (ShellStatus);
     566    } else if (Name != NULL && Guid == NULL) {
     567      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N), gShellDebug1HiiHandle, Name);
     568    } else if (Name != NULL && Guid != NULL) {
     569      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN), gShellDebug1HiiHandle, Guid, Name);
     570    } else if (Name == NULL && Guid == NULL) {
    163571      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND), gShellDebug1HiiHandle);
    164     } else if (VariableName == NULL && Guid != NULL) {
     572    } else if (Name == NULL && Guid != NULL) {
    165573      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G), gShellDebug1HiiHandle, Guid);
    166574    }
    167575    return (SHELL_NOT_FOUND);
    168576  }
    169   return (SHELL_SUCCESS);
     577  return (ShellStatus);
    170578}
    171579
    172580STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
    173581  {L"-d", TypeFlag},
    174   {L"-l", TypeFlag},
    175   {L"-s", TypeFlag},
     582  {L"-l", TypeValue},
     583  {L"-s", TypeValue},
    176584  {L"-all", TypeFlag},
    177585  {L"-guid", TypeValue},
     
    192600  )
    193601{
    194   EFI_STATUS    Status;
    195   LIST_ENTRY    *Package;
    196   CHAR16        *ProblemParam;
    197   SHELL_STATUS  ShellStatus;
    198   CONST CHAR16  *Temp;
    199   EFI_GUID      *Guid;
    200   EFI_GUID      GuidData;
    201   CONST CHAR16  *VariableName;
     602  EFI_STATUS        Status;
     603  LIST_ENTRY        *Package;
     604  CHAR16            *ProblemParam;
     605  SHELL_STATUS      ShellStatus;
     606  CONST CHAR16      *GuidStr;
     607  CONST CHAR16      *File;
     608  EFI_GUID          *Guid;
     609  EFI_GUID          GuidData;
     610  CONST CHAR16      *Name;
     611  DMP_STORE_TYPE    Type;
     612  SHELL_FILE_HANDLE FileHandle;
     613  EFI_FILE_INFO     *FileInfo;
    202614
    203615  ShellStatus   = SHELL_SUCCESS;
    204616  Package       = NULL;
     617  FileHandle    = NULL;
     618  File          = NULL;
     619  Type          = DmpStoreDisplay;
    205620
    206621  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
     
    220635      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"-all", L"-guid");
    221636      ShellStatus = SHELL_INVALID_PARAMETER;
     637    } else if (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-l")) {
     638      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"-l", L"-s");
     639      ShellStatus = SHELL_INVALID_PARAMETER;
    222640    } else if ((ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) && ShellCommandLineGetFlag(Package, L"-d")) {
    223641      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellDebug1HiiHandle, L"-l or -s", L"-d");
    224642      ShellStatus = SHELL_INVALID_PARAMETER;
    225643    } else {
     644      //
     645      // Determine the GUID to search for based on -all and -guid parameters
     646      //
    226647      if (!ShellCommandLineGetFlag(Package, L"-all")) {
    227         Temp = ShellCommandLineGetValue(Package, L"-guid");
    228         if (Temp != NULL) {
    229           Status = ConvertStringToGuid(Temp, &GuidData);
     648        GuidStr = ShellCommandLineGetValue(Package, L"-guid");
     649        if (GuidStr != NULL) {
     650          Status = ConvertStringToGuid(GuidStr, &GuidData);
    230651          if (EFI_ERROR(Status)) {
    231             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
     652            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, GuidStr);
    232653            ShellStatus = SHELL_INVALID_PARAMETER;
    233654          }
     
    236657          Guid = &gEfiGlobalVariableGuid;
    237658        }
    238         VariableName = ShellCommandLineGetRawValue(Package, 1);
    239659      } else {
    240         VariableName  = NULL;
    241         Guid          = NULL;
     660        Guid  = NULL;
    242661      }
     662
     663      //
     664      // Get the Name of the variable to find
     665      //
     666      Name = ShellCommandLineGetRawValue(Package, 1);
     667
    243668      if (ShellStatus == SHELL_SUCCESS) {
    244         if (ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-l")) {
    245           ///@todo fix this after Jordan makes lib...
    246           ShellPrintEx(-1, -1, L"Not implemeneted yet.\r\n");
    247           ShellStatus = SHELL_UNSUPPORTED;
    248         } else {
    249           ShellStatus = ProcessVariables (VariableName, Guid, ShellCommandLineGetFlag(Package, L"-d"));
     669        if (ShellCommandLineGetFlag(Package, L"-s")) {
     670          Type = DmpStoreSave;
     671          File = ShellCommandLineGetValue(Package, L"-s");
     672          if (File == NULL) {
     673            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-s");
     674            ShellStatus = SHELL_INVALID_PARAMETER;
     675          } else {
     676            Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);
     677            if (!EFI_ERROR (Status)) {
     678              //
     679              // Delete existing file, but do not delete existing directory
     680              //
     681              FileInfo = ShellGetFileInfo (FileHandle);
     682              if (FileInfo == NULL) {
     683                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);
     684                Status = EFI_DEVICE_ERROR;
     685              } else {
     686                if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
     687                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, File);
     688                  Status = EFI_INVALID_PARAMETER;
     689                } else {
     690                  Status = ShellDeleteFile (&FileHandle);
     691                  if (EFI_ERROR (Status)) {
     692                    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_DELETE_FAIL), gShellDebug1HiiHandle, File);
     693                  }
     694                }
     695                FreePool (FileInfo);
     696              }
     697            } else if (Status == EFI_NOT_FOUND) {
     698              //
     699              // Good when file doesn't exist
     700              //
     701              Status = EFI_SUCCESS;
     702            } else {
     703              //
     704              // Otherwise it's bad.
     705              //
     706              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);
     707            }
     708
     709            if (!EFI_ERROR (Status)) {
     710              Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0);
     711              if (EFI_ERROR (Status)) {
     712                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);
     713              }
     714            }
     715
     716            if (EFI_ERROR (Status)) {
     717              ShellStatus = SHELL_INVALID_PARAMETER;
     718            }
     719          }
     720        } else if (ShellCommandLineGetFlag(Package, L"-l")) {
     721          Type = DmpStoreLoad;
     722          File = ShellCommandLineGetValue(Package, L"-l");
     723          if (File == NULL) {
     724            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-l");
     725            ShellStatus = SHELL_INVALID_PARAMETER;
     726          } else {
     727            Status = ShellOpenFileByName (File, &FileHandle, EFI_FILE_MODE_READ, 0);
     728            if (EFI_ERROR (Status)) {
     729              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);
     730              ShellStatus = SHELL_INVALID_PARAMETER;
     731            } else {
     732              FileInfo = ShellGetFileInfo (FileHandle);
     733              if (FileInfo == NULL) {
     734                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, File);
     735                ShellStatus = SHELL_DEVICE_ERROR;
     736              } else {
     737                if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
     738                  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_IS_DIRECTORY), gShellDebug1HiiHandle, File);
     739                  ShellStatus = SHELL_INVALID_PARAMETER;
     740                }
     741                FreePool (FileInfo);
     742              }
     743            }
     744          }
     745        } else if (ShellCommandLineGetFlag(Package, L"-d")) {
     746          Type = DmpStoreDelete;
    250747        }
    251748      }
     749
     750      if (ShellStatus == SHELL_SUCCESS) {
     751        if (Type == DmpStoreSave) {
     752          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_SAVE), gShellDebug1HiiHandle, File);
     753        } else if (Type == DmpStoreLoad) {
     754          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DMPSTORE_LOAD), gShellDebug1HiiHandle, File);
     755        }
     756        ShellStatus = ProcessVariables (Name, Guid, Type, FileHandle);
     757        if ((Type == DmpStoreLoad) || (Type == DmpStoreSave)) {
     758          ShellCloseFile (&FileHandle);
     759        }
     760      }
    252761    }
    253762  }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c

    r48674 r58459  
    22  Implements filebuffer interface functions.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    301301      //
    302302      Orig                  = MainEditor.ColorAttributes;
    303       New.Colors.Foreground = Orig.Colors.Background;
    304       New.Colors.Background = Orig.Colors.Foreground;
     303      New.Data              = 0;
     304      New.Colors.Foreground = Orig.Colors.Background & 0xF;
     305      New.Colors.Background = Orig.Colors.Foreground & 0x7;
    305306
    306307      //
     
    343344      // set the new mouse position
    344345      //
    345       gST->ConOut->SetAttribute (gST->ConOut, New.Data);
     346      gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
    346347
    347348      //
     
    489490  CHAR16  *Buffer;
    490491  UINTN   Limit;
    491   CHAR16  PrintLine[200];
     492  CHAR16  *PrintLine;
     493  CHAR16  *PrintLine2;
     494  UINTN   BufLen;
    492495
    493496  //
     
    501504  }
    502505
    503   StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200));
     506  BufLen = (MainEditor.ScreenSize.Column + 1) * sizeof (CHAR16);
     507  PrintLine = AllocatePool (BufLen);
     508  ASSERT (PrintLine != NULL);
     509
     510  StrnCpy (PrintLine, Buffer, MIN(Limit, MainEditor.ScreenSize.Column));
    504511  for (; Limit < MainEditor.ScreenSize.Column; Limit++) {
    505512    PrintLine[Limit] = L' ';
     
    507514
    508515  PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL;
     516
     517  PrintLine2 = AllocatePool (BufLen * 2);
     518  ASSERT (PrintLine2 != NULL);
     519
     520  ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE);
    509521
    510522  ShellPrintEx (
     
    512524    (INT32)Row - 1,
    513525    L"%s",
    514     PrintLine
     526    PrintLine2
    515527    );
     528
     529  FreePool (PrintLine);
     530  FreePool (PrintLine2);
    516531
    517532  return EFI_SUCCESS;
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/MainTextEditor.c

    r48674 r58459  
    22  Implements editor interface functions.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    490490  //        "Nothing to Cut".
    491491  //
     492  Line = NULL;
    492493  Status = FileBufferCutLine (&Line);
    493494  if (Status == EFI_NOT_FOUND) {
     
    14001401  &FileBuffer,
    14011402  {
    1402     0,
    1403     0
     1403    {0, 0}
    14041404  },
    14051405  {
     
    15041504  // below will call the five components' init function
    15051505  //
    1506   Status = MainTitleBarInit (L"UEFI EDIT 2.0");
     1506  Status = MainTitleBarInit (L"UEFI EDIT");
    15071507  if (EFI_ERROR (Status)) {
    15081508    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBEDITOR_TITLEBAR), gShellDebug1HiiHandle);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/EditInputBar.c

    r48674 r58459  
    22  Implements inputbar interface functions.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    104104typedef struct {
    105105  UINT32  Foreground : 4;
    106   UINT32  Background : 4;
     106  UINT32  Background : 3;
    107107} INPUT_BAR_COLOR_ATTRIBUTES;
    108108
     
    134134  EFI_STATUS              Status;
    135135  BOOLEAN                 NoDisplay;
    136   UINTN                   Limit;
    137   UINTN                   mPromptLen;
    138136  UINTN                   EventIndex;
    139137  UINTN                   CursorRow;
     
    152150  CursorRow             = gST->ConOut->Mode->CursorRow;
    153151  Orig.Data             = gST->ConOut->Mode->Attribute;
    154   New.Colors.Foreground = Orig.Colors.Background;
    155   New.Colors.Background = Orig.Colors.Foreground;
    156 
    157   gST->ConOut->SetAttribute (gST->ConOut, New.Data);
     152  New.Data              = 0;
     153  New.Colors.Foreground = Orig.Colors.Background & 0xF;
     154  New.Colors.Background = Orig.Colors.Foreground & 0x7;
     155
     156  gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
    158157
    159158  //
     
    164163  gST->ConOut->SetCursorPosition (gST->ConOut, 0, LastRow - 1);
    165164  ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_LIBINPUTBAR_MAININPUTBAR), gShellDebug1HiiHandle, mPrompt);
    166 
    167   //
    168   // that's the maximum input length that can be displayed on screen
    169   //
    170   mPromptLen = StrLen (mPrompt);
    171   Limit     = LastColumn - mPromptLen;
    172165
    173166  //
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/EditStatusBar.c

    r48674 r58459  
    22  Implements statusbar interface functions.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    6363typedef struct {
    6464  UINT32  Foreground : 4;
    65   UINT32  Background : 4;
     65  UINT32  Background : 3;
    6666} STATUS_BAR_COLOR_ATTRIBUTES;
    6767
     
    112112  //
    113113  Orig.Data             = gST->ConOut->Mode->Attribute;
    114   New.Colors.Foreground = Orig.Colors.Background;
    115   New.Colors.Background = Orig.Colors.Foreground;
     114  New.Data              = 0;
     115  New.Colors.Foreground = Orig.Colors.Background & 0xF;
     116  New.Colors.Background = Orig.Colors.Foreground & 0x7;
    116117
    117118  gST->ConOut->EnableCursor (gST->ConOut, FALSE);
    118   gST->ConOut->SetAttribute (gST->ConOut, New.Data);
     119  gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
    119120
    120121  //
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/EditTitleBar.c

    r48674 r58459  
    22  Implements titlebar interface functions.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    108109  //
    109110  Orig.Data             = gST->ConOut->Mode->Attribute;
    110   New.Colors.Foreground = Orig.Colors.Background;
    111   New.Colors.Background = Orig.Colors.Foreground;
    112 
    113   gST->ConOut->SetAttribute (gST->ConOut, New.Data);
     111  New.Data              = 0;
     112  New.Colors.Foreground = Orig.Colors.Background & 0xF;
     113  New.Colors.Background = Orig.Colors.Foreground & 0x7;
     114
     115  gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
    114116
    115117  //
     
    170172    case FileTypeUnicode:
    171173      if (FileType == FileTypeAscii){
     174        ShellPrintEx (-1,-1, L"     ASCII     ");
     175      } else {
    172176        ShellPrintEx (-1,-1, L"     UNICODE   ");
    173177      }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c

    r48674 r58459  
    22  Main file for EfiDecompress shell Debug1 function.
    33
    4   Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    111111            ShellStatus = SHELL_NOT_FOUND;
    112112          }
    113           Status = ShellOpenFileByName(OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
    114           if (EFI_ERROR(Status)) {
    115             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
    116             ShellStatus = SHELL_NOT_FOUND;
    117           }
    118113        }
    119114
     
    132127
    133128          Status = Decompress->GetInfo(Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize);
    134           ASSERT_EFI_ERROR(Status);
     129          if (EFI_ERROR(Status) || OutSize == 0) {
     130            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName);
     131            ShellStatus = SHELL_NOT_FOUND;
     132          } else {
     133            Status = ShellOpenFileByName(OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
     134            if (EFI_ERROR(Status)) {
     135              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
     136              ShellStatus = SHELL_NOT_FOUND;
     137            } else {
     138              OutBuffer = AllocateZeroPool(OutSize);
     139              ScratchBuffer = AllocateZeroPool(ScratchSize);
     140              ASSERT(OutBuffer != NULL);
     141              ASSERT(ScratchBuffer != NULL);
    135142
    136           OutBuffer = AllocateZeroPool(OutSize);
    137           ScratchBuffer = AllocateZeroPool(ScratchSize);
    138           ASSERT(OutBuffer != NULL);
    139           ASSERT(ScratchBuffer != NULL);
     143              Status = Decompress->Decompress(Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
     144              ASSERT_EFI_ERROR(Status);
    140145
    141           Status = Decompress->Decompress(Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
    142           ASSERT_EFI_ERROR(Status);
    143 
    144           if (EFI_ERROR(Status)) {
    145             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
    146             ShellStatus = SHELL_DEVICE_ERROR;
    147           } else {
    148             OutSizeTemp = OutSize;
    149             Status = gEfiShellProtocol->WriteFile(OutFileHandle, &OutSizeTemp, OutBuffer);
    150             OutSize = (UINT32)OutSizeTemp;
    151             if (EFI_ERROR(Status)) {
    152               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status);
    153               ShellStatus = SHELL_DEVICE_ERROR;
    154             }
     146              if (EFI_ERROR(Status)) {
     147                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
     148                ShellStatus = SHELL_DEVICE_ERROR;
     149              } else {
     150                OutSizeTemp = OutSize;
     151                Status = gEfiShellProtocol->WriteFile(OutFileHandle, &OutSizeTemp, OutBuffer);
     152                OutSize = (UINT32)OutSizeTemp;
     153                if (EFI_ERROR(Status)) {
     154                  ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status);
     155                  ShellStatus = SHELL_DEVICE_ERROR;
     156                }
     157              }
     158            }
    155159          }
    156160        }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c

    r48674 r58459  
    33  as well as the event handlers for editing the file
    44 
    5   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
     5  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
    66  This program and the accompanying materials
    77  are licensed and made available under the terms and conditions of the BSD License
     
    319319
    320320    if (BeNewColor) {
    321       gST->ConOut->SetAttribute (gST->ConOut, New.Data);
     321      gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
    322322    } else {
    323       gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
     323      gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);
    324324    }
    325325
     
    338338  }
    339339
    340   gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
     340  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);
    341341  while (Index < 0x08) {
    342342    Pos = 10 + (Index * 3);
     
    356356
    357357    if (BeNewColor) {
    358       gST->ConOut->SetAttribute (gST->ConOut, New.Data);
     358      gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
    359359    } else {
    360       gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
     360      gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);
    361361    }
    362362
     
    371371  }
    372372
    373   gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
     373  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);
    374374  while (Index < 0x10) {
    375375    Pos = 10 + (Index * 3) + 1;
     
    380380  // restore the original color
    381381  //
    382   gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
     382  gST->ConOut->SetAttribute (gST->ConOut, Orig.Data & 0x7F);
    383383
    384384  //
     
    581581      //
    582582      Orig                  = HMainEditor.ColorAttributes;
    583       New.Colors.Foreground = Orig.Colors.Background;
    584       New.Colors.Background = Orig.Colors.Foreground;
     583      New.Data              = 0;
     584      New.Colors.Foreground = Orig.Colors.Background & 0xF;
     585      New.Colors.Background = Orig.Colors.Foreground & 0x7;
    585586
    586587      //
     
    594595        gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
    595596      } else {
    596         gST->ConOut->SetAttribute (gST->ConOut, New.Data);
     597        gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
    597598      }
    598599      //
     
    646647            HBufferImage.MousePosition.Column
    647648            )) {
    648         gST->ConOut->SetAttribute (gST->ConOut, New.Data);
     649        gST->ConOut->SetAttribute (gST->ConOut, New.Data & 0x7F);
    649650      } else {
    650651        gST->ConOut->SetAttribute (gST->ConOut, Orig.Data);
     
    753754  UINTN                   EndRow;
    754755  UINTN                   FStartRow;
    755   UINTN                   FEndRow;
    756756  UINTN                   Tmp;
    757757
    758758  Orig                  = HMainEditor.ColorAttributes;
     759  New.Data              = 0;
    759760  New.Colors.Foreground = Orig.Colors.Background;
    760761  New.Colors.Background = Orig.Colors.Foreground;
     
    822823
    823824      FStartRow = StartRow;
    824       FEndRow   = EndRow;
    825825
    826826      StartRow  = 2 + StartRow - HBufferImage.LowVisibleRow;
     
    17511751  )
    17521752{
    1753   HEFI_EDITOR_LINE  *Line;
    17541753  UINTN             FRow;
    17551754  UINTN             FCol;
     
    17571756  INTN              Retreat;
    17581757
    1759   Line  = HBufferImage.CurrentLine;
    1760 
    17611758  FRow  = HBufferImage.BufferPosition.Row;
    17621759  FCol  = HBufferImage.BufferPosition.Column;
     
    17771774  Retreat = -Retreat;
    17781775
    1779   //
    1780   // get correct line
    1781   //
    1782   Line = HMoveLine (Retreat);
    1783 
    17841776  FRow -= Gap;
    17851777
     
    17991791  )
    18001792{
    1801   HEFI_EDITOR_LINE  *Line;
    18021793  UINTN             FRow;
    18031794  UINTN             FCol;
    18041795  BOOLEAN           HighBits;
    1805 
    1806   Line = HBufferImage.CurrentLine;
    18071796
    18081797  //
     
    19191908  HEFI_EDITOR_LINE  *Line;
    19201909  LIST_ENTRY    *Link;
    1921   UINTN             StartRow;
    19221910
    19231911  UINTN             OldFCol;
     
    19281916
    19291917  EFI_STATUS        Status;
    1930 
    1931   //
    1932   // get the line that start position is at
    1933   //
    1934   StartRow  = Pos / 0x10;
    19351918
    19361919  Size      = HBufferImageGetTotalSize ();
     
    20552038
    20562039  LIST_ENTRY    *Link;
    2057   UINTN             StartRow;
    20582040
    20592041  UINTN             OldFCol;
     
    20622044
    20632045  UINTN             NewPos;
    2064 
    2065   //
    2066   // get the line that start position is at
    2067   //
    2068   StartRow  = Pos / 0x10;
    20692046
    20702047  Size      = HBufferImageGetTotalSize ();
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/DiskImage.c

    r48674 r58459  
    182182
    183183  HEFI_EDITOR_LINE                *Line;
    184   UINT64                          ByteOffset;
    185 
    186   EDIT_FILE_TYPE                  BufferTypeBackup;
    187 
    188   BufferTypeBackup        = HBufferImage.BufferType;
     184
    189185  HBufferImage.BufferType = FileTypeDiskBuffer;
    190186
     
    226222    return EFI_OUT_OF_RESOURCES;
    227223  }
    228 
    229   ByteOffset = MultU64x32 (Offset, BlkIo->Media->BlockSize);
    230224
    231225  //
     
    356350  UINTN                           Bytes;
    357351
    358   UINT64                          ByteOffset;
    359 
    360   EDIT_FILE_TYPE                  BufferTypeBackup;
    361 
    362352  //
    363353  // if not modified, directly return
     
    367357  }
    368358
    369   BufferTypeBackup        = HBufferImage.BufferType;
    370359  HBufferImage.BufferType = FileTypeDiskBuffer;
    371360
     
    406395    return Status;
    407396  }
    408 
    409   ByteOffset = MultU64x32 (Offset, BlkIo->Media->BlockSize);
    410397
    411398  //
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEdit.c

    r48674 r58459  
    4444  SHELL_STATUS            ShellStatus;
    4545  LIST_ENTRY              *Package;
    46   CONST CHAR16            *Cwd;
    4746  CHAR16                  *NewName;
    48   CHAR16                  *Spot;
    4947  CONST CHAR16            *Name;
    5048  UINTN                   Offset;
    5149  UINTN                   Size;
    52   UINT64                  LastOffset;
    5350  EDIT_FILE_TYPE          WhatToDo;
    5451
     
    5653  ShellStatus = SHELL_SUCCESS;
    5754  NewName         = NULL;
    58   Cwd         = NULL;
    5955  Buffer      = NULL;
    6056  Name        = NULL;
    61   Spot        = NULL;
    6257  Offset      = 0;
    6358  Size        = 0;
    64   LastOffset  = 0;
    6559  WhatToDo    = FileTypeNone;
    6660
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/HexEditorTypes.h

    r48674 r58459  
    6161typedef union {
    6262  HEFI_EDITOR_COLOR_ATTRIBUTES  Colors;
    63   UINT8                         Data;
     63  UINTN                         Data;
    6464} HEFI_EDITOR_COLOR_UNION;
    6565
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MainHexEditor.c

    r48674 r58459  
    55     - Main Interfaces
    66 
    7   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
     7  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved. <BR>
    88  This program and the accompanying materials
    99  are licensed and made available under the terms and conditions of the BSD License
     
    5151  &HBufferImage,
    5252  {
    53     0,
    54     0
     53    {0, 0}
    5554  },
    5655  {
     
    292291        //
    293292        return EFI_SUCCESS;
    294         break;
    295293
    296294      case L'c':
     
    600598{
    601599  UINTN             Index;
    602   HEFI_EDITOR_LINE  *Line;
    603600  LIST_ENTRY    *Link;
    604601  UINT8             *Buffer;
     
    624621    Link = Link->ForwardLink;
    625622  }
    626 
    627   Line    = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST);
    628623
    629624  Count   = HMainEditor.SelectEnd - HMainEditor.SelectStart + 1;
     
    16891684  // below will call the five components' init function
    16901685  //
    1691   Status = MainTitleBarInit (NULL);
     1686  Status = MainTitleBarInit (L"UEFI HEXEDIT");
    16921687  if (EFI_ERROR (Status)) {
    16931688    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_LIBEDITOR_MAINEDITOR_TITLE), gShellDebug1HiiHandle);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/MemImage.c

    r48674 r58459  
    191191  HEFI_EDITOR_LINE                *Line;
    192192
    193   EDIT_FILE_TYPE                  BufferTypeBackup;
    194 
    195   BufferTypeBackup        = HBufferImage.BufferType;
    196193  HBufferImage.BufferType = FileTypeMemBuffer;
    197194
     
    302299  VOID                            *Buffer;
    303300
    304   EDIT_FILE_TYPE                  BufferTypeBackup;
    305 
    306301  //
    307302  // not modified, so directly return
     
    311306  }
    312307
    313   BufferTypeBackup        = HBufferImage.BufferType;
    314308  HBufferImage.BufferType = FileTypeMemBuffer;
    315309
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c

    r48674 r58459  
    22  Main file for Mode shell Debug1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
    5   This program and the acModeanying materials
     4  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
     6  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
    78  which acModeanies this distribution.  The full text of the license may be found at
     
    1314**/
    1415
     16//
     17// Need full names for Standard-Format Output
     18//
    1519STATIC CONST CHAR16 NameEfiReservedMemoryType[]      = L"Reserved";
    1620STATIC CONST CHAR16 NameEfiLoaderCode[]              = L"LoaderCode";
    1721STATIC CONST CHAR16 NameEfiLoaderData[]              = L"LoaderData";
    18 STATIC CONST CHAR16 NameEfiBootServicesCode[]        = L"BS_Code";
    19 STATIC CONST CHAR16 NameEfiBootServicesData[]        = L"BS_Data";
    20 STATIC CONST CHAR16 NameEfiRuntimeServicesCode[]     = L"RT_Code";
    21 STATIC CONST CHAR16 NameEfiRuntimeServicesData[]     = L"RT_Data";
     22STATIC CONST CHAR16 NameEfiBootServicesCode[]        = L"BootServiceCode";
     23STATIC CONST CHAR16 NameEfiBootServicesData[]        = L"BootServiceData";
     24STATIC CONST CHAR16 NameEfiRuntimeServicesCode[]     = L"RuntimeCode";
     25STATIC CONST CHAR16 NameEfiRuntimeServicesData[]     = L"RuntimeData";
    2226STATIC CONST CHAR16 NameEfiConventionalMemory[]      = L"Available";
    23 STATIC CONST CHAR16 NameEfiUnusableMemory[]          = L"Unusable";
    24 STATIC CONST CHAR16 NameEfiACPIReclaimMemory[]       = L"ACPIRec";
    25 STATIC CONST CHAR16 NameEfiACPIMemoryNVS[]           = L"ACPI_NVS";
    26 STATIC CONST CHAR16 NameEfiMemoryMappedIO[]          = L"MMIO";
    27 STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpace[] = L"MMIOPort";
     27STATIC CONST CHAR16 NameEfiPersistentMemory[]        = L"Persistent";
     28STATIC CONST CHAR16 NameEfiUnusableMemory[]          = L"UnusableMemory";
     29STATIC CONST CHAR16 NameEfiACPIReclaimMemory[]       = L"ACPIReclaimMemory";
     30STATIC CONST CHAR16 NameEfiACPIMemoryNVS[]           = L"ACPIMemoryNVS";
     31STATIC CONST CHAR16 NameEfiMemoryMappedIO[]          = L"MemoryMappedIO";
     32STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpace[] = L"MemoryMappedIOPortSpace";
    2833STATIC CONST CHAR16 NameEfiPalCode[]                 = L"PalCode";
     34
     35//
     36// Need short names for some memory types
     37//
     38STATIC CONST CHAR16 NameEfiBootServicesCodeShort[]        = L"BS_Code";
     39STATIC CONST CHAR16 NameEfiBootServicesDataShort[]        = L"BS_Data";
     40STATIC CONST CHAR16 NameEfiRuntimeServicesCodeShort[]     = L"RT_Code";
     41STATIC CONST CHAR16 NameEfiRuntimeServicesDataShort[]     = L"RT_Data";
     42STATIC CONST CHAR16 NameEfiUnusableMemoryShort[]          = L"Unusable";
     43STATIC CONST CHAR16 NameEfiACPIReclaimMemoryShort[]       = L"ACPI_Recl";
     44STATIC CONST CHAR16 NameEfiACPIMemoryNVSShort[]           = L"ACPI_NVS";
     45STATIC CONST CHAR16 NameEfiMemoryMappedIOShort[]          = L"MMIO";
     46STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpaceShort[] = L"MMIO_Port";
    2947
    3048#include "UefiShellDebug1CommandsLib.h"
     
    7795  UINT64              AcpiNvsPagesSize;
    7896  UINT64              MmioSpacePagesSize;
     97  UINT64              MmioPortPages;
     98  UINT64              MmioPortPagesSize;
     99  UINT64              UnusableMemoryPages;
     100  UINT64              UnusableMemoryPagesSize;
     101  UINT64              PalCodePages;
     102  UINT64              PalCodePagesSize;
    79103  BOOLEAN             Sfo;
    80104
     
    91115  RTCodePages         = 0;
    92116  AvailPages          = 0;
     117  MmioPortPages       = 0;
     118  UnusableMemoryPages = 0;
     119  PalCodePages        = 0;
    93120  Size                = 0;
    94121  Buffer              = NULL;
     
    133160      } else {
    134161        ASSERT(Version == EFI_MEMORY_DESCRIPTOR_VERSION);
     162
    135163        Sfo = ShellCommandLineGetFlag(Package, L"-sfo");
    136         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle);
     164        if (!Sfo) {
     165          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle);
     166        } else {
     167          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap");
     168        }
     169
    137170        for (Walker = (UINT8*)Buffer; Walker < (((UINT8*)Buffer)+Size) && Walker != NULL; Walker += ItemSize){
    138171          switch (((EFI_MEMORY_DESCRIPTOR*)Walker)->Type) {
    139             // replaced ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages) with 0000
    140172            case  EfiReservedMemoryType:
    141173              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiReservedMemoryType, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    142174              ReservedPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    143               TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    144175              break;
    145176            case EfiLoaderCode:
     
    154185              break;
    155186            case EfiBootServicesCode:
    156               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiBootServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     187              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiBootServicesCodeShort:NameEfiBootServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    157188              BSCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    158189              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    159190              break;
    160191            case EfiBootServicesData:
    161               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiBootServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     192              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiBootServicesDataShort:NameEfiBootServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    162193              BSDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    163194              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    164195              break;
    165196            case EfiRuntimeServicesCode:
    166               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiRuntimeServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     197              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiRuntimeServicesCodeShort:NameEfiRuntimeServicesCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    167198              RTCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    168199              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    169200              break;
    170201            case EfiRuntimeServicesData:
    171               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiRuntimeServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     202              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiRuntimeServicesDataShort:NameEfiRuntimeServicesData, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    172203              RTDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    173204              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
     
    178209              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    179210              break;
     211            case EfiPersistentMemory:
     212              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiPersistentMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     213              AvailPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
     214              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
     215              break;
    180216            case EfiUnusableMemory:
    181               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiUnusableMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    182               TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
     217              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiUnusableMemoryShort:NameEfiUnusableMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     218              UnusableMemoryPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    183219              break;
    184220            case EfiACPIReclaimMemory:
    185               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiACPIReclaimMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     221              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiACPIReclaimMemoryShort:NameEfiACPIReclaimMemory, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    186222              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    187223              AcpiReclaimPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    188224              break;
    189225            case EfiACPIMemoryNVS:
    190               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiACPIMemoryNVS, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     226              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiACPIMemoryNVSShort:NameEfiACPIMemoryNVS, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    191227              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    192228              AcpiNvsPages    += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    193229              break;
    194230            case EfiMemoryMappedIO:
    195               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiMemoryMappedIO, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    196               TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
     231              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiMemoryMappedIOShort:NameEfiMemoryMappedIO, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    197232              MmioSpacePages  += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    198233              break;
    199234            case EfiMemoryMappedIOPortSpace:
    200               ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiMemoryMappedIOPortSpace, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    201               TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
     235              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, !Sfo?NameEfiMemoryMappedIOPortSpaceShort:NameEfiMemoryMappedIOPortSpace, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
     236              MmioPortPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    202237              break;
    203238            case EfiPalCode:
    204239              ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiPalCode, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart, ((EFI_MEMORY_DESCRIPTOR*)Walker)->PhysicalStart+MultU64x64(SIZE_4KB,((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages)-1, ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages, ((EFI_MEMORY_DESCRIPTOR*)Walker)->Attribute);
    205240              TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
     241              PalCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages;
    206242              break;
    207243            default:
     
    212248        // print the summary
    213249        //
    214         ReservedPagesSize               = MultU64x64(SIZE_4KB,ReservedPages);
    215         LoadCodePagesSize               = MultU64x64(SIZE_4KB,LoadCodePages);
    216         LoadDataPagesSize               = MultU64x64(SIZE_4KB,LoadDataPages);
    217         BSCodePagesSize           = MultU64x64(SIZE_4KB,BSCodePages);
    218         BSDataPagesSize           = MultU64x64(SIZE_4KB,BSDataPages);
    219         RTDataPagesSize           = MultU64x64(SIZE_4KB,RTDataPages);
    220         RTCodePagesSize           = MultU64x64(SIZE_4KB,RTCodePages);
    221         AvailPagesSize            = MultU64x64(SIZE_4KB,AvailPages);
    222         TotalPagesSize            = MultU64x64(SIZE_4KB,TotalPages);
    223         AcpiReclaimPagesSize     = MultU64x64(SIZE_4KB,AcpiReclaimPages);
    224         AcpiNvsPagesSize         = MultU64x64(SIZE_4KB,AcpiNvsPages);
    225         MmioSpacePagesSize       = MultU64x64(SIZE_4KB,MmioSpacePages);
     250        ReservedPagesSize       = MultU64x64(SIZE_4KB,ReservedPages);
     251        LoadCodePagesSize       = MultU64x64(SIZE_4KB,LoadCodePages);
     252        LoadDataPagesSize       = MultU64x64(SIZE_4KB,LoadDataPages);
     253        BSCodePagesSize         = MultU64x64(SIZE_4KB,BSCodePages);
     254        BSDataPagesSize         = MultU64x64(SIZE_4KB,BSDataPages);
     255        RTDataPagesSize         = MultU64x64(SIZE_4KB,RTDataPages);
     256        RTCodePagesSize         = MultU64x64(SIZE_4KB,RTCodePages);
     257        AvailPagesSize          = MultU64x64(SIZE_4KB,AvailPages);
     258        TotalPagesSize          = MultU64x64(SIZE_4KB,TotalPages);
     259        AcpiReclaimPagesSize    = MultU64x64(SIZE_4KB,AcpiReclaimPages);
     260        AcpiNvsPagesSize        = MultU64x64(SIZE_4KB,AcpiNvsPages);
     261        MmioSpacePagesSize      = MultU64x64(SIZE_4KB,MmioSpacePages);
     262        MmioPortPagesSize       = MultU64x64(SIZE_4KB,MmioPortPages);
     263        PalCodePagesSize        = MultU64x64(SIZE_4KB,PalCodePages);
     264        UnusableMemoryPagesSize = MultU64x64(SIZE_4KB,UnusableMemoryPages);
    226265        if (!Sfo) {
    227266          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_SUMM), gShellDebug1HiiHandle,
     
    236275            AcpiNvsPages, AcpiNvsPagesSize,
    237276            MmioSpacePages, MmioSpacePagesSize,
     277            MmioPortPages, MmioPortPagesSize,
     278            PalCodePages, PalCodePagesSize,
    238279            AvailPages, AvailPagesSize,
    239280            DivU64x32(MultU64x64(SIZE_4KB,TotalPages), SIZE_1MB), TotalPagesSize
     
    242283          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_SUMM_SFO), gShellDebug1HiiHandle,
    243284            TotalPagesSize,
    244             MultU64x64(SIZE_4KB,ReservedPages),
     285            ReservedPagesSize,
    245286            BSCodePagesSize,
    246287            BSDataPagesSize,
     
    249290            LoadCodePagesSize,
    250291            LoadDataPagesSize,
    251             AvailPages, AvailPagesSize
     292            AvailPagesSize,
     293            MmioSpacePagesSize,
     294            MmioPortPagesSize,
     295            UnusableMemoryPagesSize,
     296            AcpiReclaimPagesSize,
     297            AcpiNvsPagesSize,
     298            PalCodePagesSize
    252299           );
    253300        }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Mm.c

    r48674 r58459  
    22  Main file for Mm shell Debug1 function.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    218218  UINTN                           Index;
    219219  UINTN                           Size;
    220   CHAR16                          *AddressStr;
    221220//  CHAR16                          *ValueStr;
    222221  BOOLEAN                         Complete;
     
    231230  CONST CHAR16                    *Temp;
    232231
     232  Value         = 0;
    233233  Address       = 0;
    234234  PciEAddress   = 0;
     
    246246  Size        = 1;
    247247  AccessType  = EfiMemory;
    248   AddressStr  = NULL;
    249248//  ValueStr    = NULL;
    250249  Interactive = TRUE;
     
    318317    }
    319318
    320     if (ShellCommandLineGetFlag (Package, L"-n")) {
     319    //
     320    // Non interactive for a script file or for the specific parameter
     321    //
     322    if (gEfiShellProtocol->BatchIsActive() || ShellCommandLineGetFlag (Package, L"-n")) {
    321323      Interactive = FALSE;
    322324    }
     
    363365    Temp = ShellCommandLineGetRawValue(Package, 2);
    364366    if (Temp != NULL) {
     367      //
     368      // Per spec if value is specified, then -n is assumed.
     369      //
     370      Interactive = FALSE;
     371
    365372      if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, &Value, TRUE, FALSE))) {
    366373        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
     
    490497    //
    491498    if (!Interactive) {
     499      Buffer = 0;
     500      if (AccessType == EFIMemoryMappedIo) {
     501        if (!gEfiShellProtocol->BatchIsActive()) {
     502          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle);
     503        }
     504        IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer);
     505      } else if (AccessType == EfiIo) {
     506        if (!gEfiShellProtocol->BatchIsActive()) {
     507          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle);
     508        }
     509        IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer);
     510      } else if (AccessType == EfiPciConfig) {
     511        if (!gEfiShellProtocol->BatchIsActive()) {
     512          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle);
     513        }
     514        IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer);
     515      } else if (AccessType == EfiPciEConfig) {
     516        if (!gEfiShellProtocol->BatchIsActive()) {
     517          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);
     518        }
     519        IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer);
     520      } else {
     521        if (!gEfiShellProtocol->BatchIsActive()) {
     522          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);
     523        }
     524        ReadMem (Width, Address, 1, &Buffer);
     525      }
     526      if (!gEfiShellProtocol->BatchIsActive()) {
     527        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address);
     528      }
     529      if (Size == 1) {
     530        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, (UINTN)Buffer);
     531      } else if (Size == 2) {
     532        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, (UINTN)Buffer);
     533      } else if (Size == 4) {
     534        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, (UINTN)Buffer);
     535      } else if (Size == 8) {
     536        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer);
     537      }
     538
     539      ShellPrintEx(-1, -1, L"\r\n");
     540
     541      ASSERT(ShellStatus == SHELL_SUCCESS);
     542      goto Done;
     543    }
     544    //
     545    // interactive mode
     546    //
     547    Complete = FALSE;
     548    do {
     549      if (AccessType == EfiIo && Address + Size > 0x10000) {
     550        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE2), gShellDebug1HiiHandle);
     551        break;
     552      }
     553
    492554      Buffer = 0;
    493555      if (AccessType == EFIMemoryMappedIo) {
     
    509571
    510572      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address);
     573
    511574      if (Size == 1) {
    512         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, Buffer);
     575        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, (UINTN)Buffer);
    513576      } else if (Size == 2) {
    514         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, Buffer);
     577        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, (UINTN)Buffer);
    515578      } else if (Size == 4) {
    516         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, Buffer);
    517       } else if (Size == 8) {
    518         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer);
    519       }
    520 
    521       ShellPrintEx(-1, -1, L"\r\n");
    522 
    523       ASSERT(ShellStatus == SHELL_SUCCESS);
    524       goto Done;
    525     }
    526     //
    527     // interactive mode
    528     //
    529     Complete = FALSE;
    530     do {
    531       if (AccessType == EfiIo && Address + Size > 0x10000) {
    532         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE2), gShellDebug1HiiHandle);
    533         break;
    534       }
    535 
    536       Buffer = 0;
    537       if (AccessType == EFIMemoryMappedIo) {
    538         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle);
    539         IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer);
    540       } else if (AccessType == EfiIo) {
    541         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle);
    542         IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer);
    543       } else if (AccessType == EfiPciConfig) {
    544         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle);
    545         IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer);
    546       } else if (AccessType == EfiPciEConfig) {
    547         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle);
    548         IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer);
    549       } else {
    550         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle);
    551         ReadMem (Width, Address, 1, &Buffer);
    552       }
    553 
    554       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address);
    555 
    556       if (Size == 1) {
    557         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, Buffer);
    558       } else if (Size == 2) {
    559         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, Buffer);
    560       } else if (Size == 4) {
    561         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, Buffer);
     579        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, (UINTN)Buffer);
    562580      } else if (Size == 8) {
    563581        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Mode.c

    r48674 r58459  
    22  Main file for Mode shell Debug1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
    5   This program and the acModeanying materials
     4  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
     5  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
    77  which acModeanies this distribution.  The full text of the license may be found at
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.c

    r48674 r58459  
    22  Main file for Pci shell Debug1 function.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    2021#include "Pci.h"
    2122
    22 #define PCI_CLASS_STRING_LIMIT  54
    2323//
    2424// Printable strings for Pci class code
     
    6363PCI_CLASS_ENTRY PCISubClass_10[];
    6464PCI_CLASS_ENTRY PCISubClass_11[];
     65PCI_CLASS_ENTRY PCISubClass_12[];
     66PCI_CLASS_ENTRY PCISubClass_13[];
     67PCI_CLASS_ENTRY PCIPIFClass_0100[];
    6568PCI_CLASS_ENTRY PCIPIFClass_0101[];
     69PCI_CLASS_ENTRY PCIPIFClass_0105[];
     70PCI_CLASS_ENTRY PCIPIFClass_0106[];
     71PCI_CLASS_ENTRY PCIPIFClass_0107[];
     72PCI_CLASS_ENTRY PCIPIFClass_0108[];
     73PCI_CLASS_ENTRY PCIPIFClass_0109[];
    6674PCI_CLASS_ENTRY PCIPIFClass_0300[];
    6775PCI_CLASS_ENTRY PCIPIFClass_0604[];
     76PCI_CLASS_ENTRY PCIPIFClass_0609[];
     77PCI_CLASS_ENTRY PCIPIFClass_060b[];
    6878PCI_CLASS_ENTRY PCIPIFClass_0700[];
    6979PCI_CLASS_ENTRY PCIPIFClass_0701[];
     
    7686PCI_CLASS_ENTRY PCIPIFClass_0c00[];
    7787PCI_CLASS_ENTRY PCIPIFClass_0c03[];
     88PCI_CLASS_ENTRY PCIPIFClass_0c07[];
     89PCI_CLASS_ENTRY PCIPIFClass_0d01[];
    7890PCI_CLASS_ENTRY PCIPIFClass_0e00[];
    7991
     
    173185  },
    174186  {
     187    0x12,
     188    L"Processing Accelerators",
     189    PCISubClass_12
     190  },
     191  {
     192    0x13,
     193    L"Non-Essential Instrumentation",
     194    PCISubClass_13
     195  },
     196  {
    175197    0xff,
    176198    L"Device does not fit in any defined classes",
     
    221243  {
    222244    0x00,
    223     L"SCSI controller",
    224     PCIBlankEntry
     245    L"SCSI",
     246    PCIPIFClass_0100
    225247  },
    226248  {
     
    245267  },
    246268  {
     269    0x05,
     270    L"ATA controller with ADMA interface",
     271    PCIPIFClass_0105
     272  },
     273  {
     274    0x06,
     275    L"Serial ATA controller",
     276    PCIPIFClass_0106
     277  },
     278  {
     279    0x07,
     280    L"Serial Attached SCSI (SAS) controller ",
     281    PCIPIFClass_0107
     282  },
     283  {
     284    0x08,
     285    L"Non-volatile memory subsystem",
     286    PCIPIFClass_0108
     287  },
     288  {
     289    0x09,
     290    L"Universal Flash Storage (UFS) controller ",
     291    PCIPIFClass_0109
     292  },
     293  {
    247294    0x80,
    248295    L"Other mass storage controller",
     
    283330  },
    284331  {
     332    0x05,
     333    L"WorldFip controller",
     334    PCIBlankEntry
     335  },
     336  {
     337    0x06,
     338    L"PICMG 2.14 Multi Computing",
     339    PCIBlankEntry
     340  },
     341  {
     342    0x07,
     343    L"InfiniBand controller",
     344    PCIBlankEntry
     345  },
     346  {
    285347    0x80,
    286348    L"Other network controller",
     
    336398    0x02,
    337399    L"Computer Telephony device",
     400    PCIBlankEntry
     401  },
     402  {
     403    0x03,
     404    L"Mixed mode device",
    338405    PCIBlankEntry
    339406  },
     
    420487  },
    421488  {
     489    0x09,
     490    L"Semi-transparent PCI-to-PCI bridge",
     491    PCIPIFClass_0609
     492  },
     493  {
     494    0x0A,
     495    L"InfiniBand-to-PCI host bridge",
     496    PCIBlankEntry
     497  },
     498  {
     499    0x0B,
     500    L"Advanced Switching to PCI host bridge",
     501    PCIPIFClass_060b
     502  },
     503  {
    422504    0x80,
    423505    L"Other bridge type",
     
    453535  },
    454536  {
     537    0x04,
     538    L"GPIB (IEEE 488.1/2) controller",
     539    PCIBlankEntry
     540  },
     541  {
     542    0x05,
     543    L"Smart Card",
     544    PCIBlankEntry
     545  },
     546  {
    455547    0x80,
    456548    L"Other communication device",
     
    491583  },
    492584  {
     585    0x05,
     586    L"SD Host controller",
     587    PCIBlankEntry
     588  },
     589  {
     590    0x06,
     591    L"IOMMU",
     592    PCIBlankEntry
     593  },
     594  {
     595    0x07,
     596    L"Root Complex Event Collector",
     597    PCIBlankEntry
     598  },
     599  {
    493600    0x80,
    494601    L"Other system peripheral",
     
    609716  {
    610717    0x00,
    611     L"Firewire(IEEE 1394)",
    612     PCIPIFClass_0c03
     718    L"IEEE 1394",
     719    PCIPIFClass_0c00
    613720  },
    614721  {
     
    625732    0x03,
    626733    L"USB",
    627     PCIPIFClass_0c00
     734    PCIPIFClass_0c03
    628735  },
    629736  {
     
    638745  },
    639746  {
     747    0x06,
     748    L"InfiniBand",
     749    PCIBlankEntry
     750  },
     751  {
     752    0x07,
     753    L"IPMI",
     754    PCIPIFClass_0c07
     755  },
     756  {
     757    0x08,
     758    L"SERCOS Interface Standard (IEC 61491)",
     759    PCIBlankEntry
     760  },
     761  {
     762    0x09,
     763    L"CANbus",
     764    PCIBlankEntry
     765  },
     766  {
    640767    0x80,
    641768    L"Other bus type",
     
    657784  {
    658785    0x01,
    659     L"Consumer IR controller",
    660     PCIBlankEntry
     786    L"",
     787    PCIPIFClass_0d01
    661788  },
    662789  {
     
    666793  },
    667794  {
     795    0x11,
     796    L"Bluetooth",
     797    PCIBlankEntry
     798  },
     799  {
     800    0x12,
     801    L"Broadband",
     802    PCIBlankEntry
     803  },
     804  {
     805    0x20,
     806    L"Ethernet (802.11a - 5 GHz)",
     807    PCIBlankEntry
     808  },
     809  {
     810    0x21,
     811    L"Ethernet (802.11b - 2.4 GHz)",
     812    PCIBlankEntry
     813  },
     814  {
    668815    0x80,
    669816    L"Other type of wireless controller",
     
    692839PCI_CLASS_ENTRY PCISubClass_0f[] = {
    693840  {
    694     0x00,
     841    0x01,
    695842    L"TV",
    696843    PCIBlankEntry
    697844  },
    698845  {
    699     0x01,
     846    0x02,
    700847    L"Audio",
    701848    PCIBlankEntry
    702849  },
    703850  {
    704     0x02,
     851    0x03,
    705852    L"Voice",
    706853    PCIBlankEntry
    707854  },
    708855  {
    709     0x03,
     856    0x04,
    710857    L"Data",
     858    PCIBlankEntry
     859  },
     860  {
     861    0x80,
     862    L"Other satellite communication controller",
    711863    PCIBlankEntry
    712864  },
     
    748900  },
    749901  {
     902    0x01,
     903    L"Performance Counters",
     904    PCIBlankEntry
     905  },
     906  {
     907    0x10,
     908    L"Communications synchronization plus time and frequency test/measurement ",
     909    PCIBlankEntry
     910  },
     911  {
     912    0x20,
     913    L"Management card",
     914    PCIBlankEntry
     915  },
     916  {
    750917    0x80,
    751918    L"Other DAQ & SP controllers",
     919    PCIBlankEntry
     920  },
     921  {
     922    0x00,
     923    NULL,
     924    /* null string ends the list */NULL
     925  }
     926};
     927
     928PCI_CLASS_ENTRY PCISubClass_12[] = {
     929  {
     930    0x00,
     931    L"Processing Accelerator",
     932    PCIBlankEntry
     933  },
     934  {
     935    0x00,
     936    NULL,
     937    /* null string ends the list */NULL
     938  }
     939};
     940
     941PCI_CLASS_ENTRY PCISubClass_13[] = {
     942  {
     943    0x00,
     944    L"Non-Essential Instrumentation Function",
    752945    PCIBlankEntry
    753946  },
     
    762955// Programming Interface entries
    763956//
     957PCI_CLASS_ENTRY PCIPIFClass_0100[] = {
     958  {
     959    0x00,
     960    L"SCSI controller",
     961    PCIBlankEntry
     962  },
     963  {
     964    0x11,
     965    L"SCSI storage device SOP using PQI",
     966    PCIBlankEntry
     967  },
     968  {
     969    0x12,
     970    L"SCSI controller SOP using PQI",
     971    PCIBlankEntry
     972  },
     973  {
     974    0x13,
     975    L"SCSI storage device and controller SOP using PQI",
     976    PCIBlankEntry
     977  },
     978  {
     979    0x21,
     980    L"SCSI storage device SOP using NVMe",
     981    PCIBlankEntry
     982  },
     983  {
     984    0x00,
     985    NULL,
     986    /* null string ends the list */NULL
     987  }
     988};
     989
    764990PCI_CLASS_ENTRY PCIPIFClass_0101[] = {
    765991  {
     
    9301156};
    9311157
     1158PCI_CLASS_ENTRY PCIPIFClass_0105[] = {
     1159  {
     1160    0x20,
     1161    L"Single stepping",
     1162    PCIBlankEntry
     1163  },
     1164  {
     1165    0x30,
     1166    L"Continuous operation",
     1167    PCIBlankEntry
     1168  },
     1169  {
     1170    0x00,
     1171    NULL,
     1172    /* null string ends the list */NULL
     1173  }
     1174};
     1175
     1176PCI_CLASS_ENTRY PCIPIFClass_0106[] = {
     1177  {
     1178    0x00,
     1179    L"",
     1180    PCIBlankEntry
     1181  },
     1182  {
     1183    0x01,
     1184    L"AHCI",
     1185    PCIBlankEntry
     1186  },
     1187  {
     1188    0x02,
     1189    L"Serial Storage Bus",
     1190    PCIBlankEntry
     1191  },
     1192  {
     1193    0x00,
     1194    NULL,
     1195    /* null string ends the list */NULL
     1196  }
     1197};
     1198
     1199PCI_CLASS_ENTRY PCIPIFClass_0107[] = {
     1200  {
     1201    0x00,
     1202    L"",
     1203    PCIBlankEntry
     1204  },
     1205  {
     1206    0x01,
     1207    L"Obsolete",
     1208    PCIBlankEntry
     1209  },
     1210  {
     1211    0x00,
     1212    NULL,
     1213    /* null string ends the list */NULL
     1214  }
     1215};
     1216
     1217PCI_CLASS_ENTRY PCIPIFClass_0108[] = {
     1218  {
     1219    0x00,
     1220    L"",
     1221    PCIBlankEntry
     1222  },
     1223  {
     1224    0x01,
     1225    L"NVMHCI",
     1226    PCIBlankEntry
     1227  },
     1228  {
     1229    0x02,
     1230    L"NVM Express",
     1231    PCIBlankEntry
     1232  },
     1233  {
     1234    0x00,
     1235    NULL,
     1236    /* null string ends the list */NULL
     1237  }
     1238};
     1239
     1240PCI_CLASS_ENTRY PCIPIFClass_0109[] = {
     1241  {
     1242    0x00,
     1243    L"",
     1244    PCIBlankEntry
     1245  },
     1246  {
     1247    0x01,
     1248    L"UFSHCI",
     1249    PCIBlankEntry
     1250  },
     1251  {
     1252    0x00,
     1253    NULL,
     1254    /* null string ends the list */NULL
     1255  }
     1256};
     1257
    9321258PCI_CLASS_ENTRY PCIPIFClass_0300[] = {
    9331259  {
     
    9661292};
    9671293
     1294PCI_CLASS_ENTRY PCIPIFClass_0609[] = {
     1295  {
     1296    0x40,
     1297    L"Primary PCI bus side facing the system host processor",
     1298    PCIBlankEntry
     1299  },
     1300  {
     1301    0x80,
     1302    L"Secondary PCI bus side facing the system host processor",
     1303    PCIBlankEntry
     1304  },
     1305  {
     1306    0x00,
     1307    NULL,
     1308    /* null string ends the list */NULL
     1309  }
     1310};
     1311
     1312PCI_CLASS_ENTRY PCIPIFClass_060b[] = {
     1313  {
     1314    0x00,
     1315    L"Custom",
     1316    PCIBlankEntry
     1317  },
     1318  {
     1319    0x01,
     1320    L"ASI-SIG Defined Portal",
     1321    PCIBlankEntry
     1322  },
     1323  {
     1324    0x00,
     1325    NULL,
     1326    /* null string ends the list */NULL
     1327  }
     1328};
     1329
    9681330PCI_CLASS_ENTRY PCIPIFClass_0700[] = {
    9691331  {
     
    11981560  {
    11991561    0x00,
    1200     L"Universal Host Controller spec",
     1562    L"",
    12011563    PCIBlankEntry
    12021564  },
    12031565  {
    12041566    0x10,
    1205     L"Open Host Controller spec",
     1567    L"Using 1394 OpenHCI spec",
     1568    PCIBlankEntry
     1569  },
     1570  {
     1571    0x00,
     1572    NULL,
     1573    /* null string ends the list */NULL
     1574  }
     1575};
     1576
     1577PCI_CLASS_ENTRY PCIPIFClass_0c03[] = {
     1578  {
     1579    0x00,
     1580    L"UHCI",
     1581    PCIBlankEntry
     1582  },
     1583  {
     1584    0x10,
     1585    L"OHCI",
     1586    PCIBlankEntry
     1587  },
     1588  {
     1589    0x20,
     1590    L"EHCI",
     1591    PCIBlankEntry
     1592  },
     1593  {
     1594    0x30,
     1595    L"xHCI",
    12061596    PCIBlankEntry
    12071597  },
     
    12231613};
    12241614
    1225 PCI_CLASS_ENTRY PCIPIFClass_0c03[] = {
    1226   {
    1227     0x00,
    1228     L"",
     1615PCI_CLASS_ENTRY PCIPIFClass_0c07[] = {
     1616  {
     1617    0x00,
     1618    L"SMIC",
     1619    PCIBlankEntry
     1620  },
     1621  {
     1622    0x01,
     1623    L"Keyboard Controller Style",
     1624    PCIBlankEntry
     1625  },
     1626  {
     1627    0x02,
     1628    L"Block Transfer",
     1629    PCIBlankEntry
     1630  },
     1631  {
     1632    0x00,
     1633    NULL,
     1634    /* null string ends the list */NULL
     1635  }
     1636};
     1637
     1638PCI_CLASS_ENTRY PCIPIFClass_0d01[] = {
     1639  {
     1640    0x00,
     1641    L"Consumer IR controller",
    12291642    PCIBlankEntry
    12301643  },
    12311644  {
    12321645    0x10,
    1233     L"Using 1394 OpenHCI spec",
     1646    L"UWB Radio controller",
    12341647    PCIBlankEntry
    12351648  },
     
    13781791
    13791792  @param[in] ClassCodePtr   Points to the memory which stores register Class Code in PCI
    1380                  configuation space.
     1793                            configuration space.
    13811794  @param[in] IncludePIF     If the printed string should include the programming I/F part
    13821795**/
     
    13891802  UINT32            ClassCode;
    13901803  PCI_CLASS_STRINGS ClassStrings;
    1391   CHAR16            OutputString[PCI_CLASS_STRING_LIMIT + 1];
    13921804
    13931805  ClassCode = 0;
    1394   ClassCode |= ClassCodePtr[0];
    1395   ClassCode |= (ClassCodePtr[1] << 8);
    1396   ClassCode |= (ClassCodePtr[2] << 16);
     1806  ClassCode |= (UINT32)ClassCodePtr[0];
     1807  ClassCode |= (UINT32)(ClassCodePtr[1] << 8);
     1808  ClassCode |= (UINT32)(ClassCodePtr[2] << 16);
    13971809
    13981810  //
     
    14031815  if (IncludePIF) {
    14041816    //
    1405     // Only print base class and sub class name
     1817    // Print base class, sub class, and programming inferface name
    14061818    //
    1407     ShellPrintEx(-1,-1, L"%s - %s - %s",
     1819    ShellPrintEx (-1, -1, L"%s - %s - %s",
    14081820      ClassStrings.BaseClass,
    14091821      ClassStrings.SubClass,
     
    14131825  } else {
    14141826    //
    1415     // Print base class, sub class, and programming inferface name
     1827    // Only print base class and sub class name
    14161828    //
    1417     UnicodeSPrint (
    1418       OutputString,
    1419       PCI_CLASS_STRING_LIMIT * sizeof (CHAR16),
    1420       L"%s - %s",
     1829    ShellPrintEx (-1, -1, L"%s - %s",
    14211830      ClassStrings.BaseClass,
    14221831      ClassStrings.SubClass
    1423      );
    1424 
    1425     OutputString[PCI_CLASS_STRING_LIMIT] = 0;
    1426     ShellPrintEx(-1,-1, L"%s", OutputString);
     1832    );
    14271833  }
    14281834}
     
    14991905  @param[in] Address         Address used to access configuration space of this PCI device.
    15001906  @param[in] IoDev           Handle used to access configuration space of PCI device.
     1907  @param[in] EnhancedDump    The print format for the dump data.
    15011908
    15021909  @retval EFI_SUCCESS     The command completed successfully.
     
    15061913  IN PCI_CONFIG_SPACE                       *ConfigSpace,
    15071914  IN UINT64                                 Address,
    1508   IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
     1915  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev,
     1916  IN CONST UINT16                           EnhancedDump
    15091917  );
    15101918
     
    16242032  Print each capability structure.
    16252033
    1626   @param[in] IoDev      The pointer to the deivce.
    1627   @param[in] Address    The address to start at.
    1628   @param[in] CapPtr     The offset from the address.
    1629 
    1630   @retval EFI_SUCCESS     The operation was successful.
     2034  @param[in] IoDev            The pointer to the deivce.
     2035  @param[in] Address          The address to start at.
     2036  @param[in] CapPtr           The offset from the address.
     2037  @param[in] EnhancedDump     The print format for the dump data.
     2038
     2039  @retval EFI_SUCCESS         The operation was successful.
    16312040**/
    16322041EFI_STATUS
     
    16342043  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,
    16352044  IN UINT64                                   Address,
    1636   IN  UINT8                                   CapPtr
     2045  IN  UINT8                                   CapPtr,
     2046  IN CONST UINT16                            EnhancedDump
    16372047  );
    16382048
     
    16402050  Display Pcie device structure.
    16412051
    1642   @param[in] IoDev          The pointer to the root pci protocol.
    1643   @param[in] Address        The Address to start at.
    1644   @param[in] CapabilityPtr  The offset from the address to start.
     2052  @param[in] IoDev            The pointer to the root pci protocol.
     2053  @param[in] Address          The Address to start at.
     2054  @param[in] CapabilityPtr    The offset from the address to start.
     2055  @param[in] EnhancedDump     The print format for the dump data.
     2056 
     2057  @retval EFI_SUCCESS           The command completed successfully.
     2058  @retval @retval EFI_SUCCESS   Pci express extend space IO is not suppoted.   
    16452059**/
    16462060EFI_STATUS
     
    16482062  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,
    16492063  IN  UINT64                                  Address,
    1650   IN  UINT8                                   CapabilityPtr
     2064  IN  UINT8                                   CapabilityPtr,
     2065  IN CONST UINT16                            EnhancedDump
    16512066  );
    16522067
     
    16602075EFI_STATUS
    16612076ExplainPcieCapReg (
    1662   IN PCIE_CAP_STURCTURE *PciExpressCap
     2077  IN PCIE_CAP_STRUCTURE *PciExpressCap
    16632078  );
    16642079
     
    16722087EFI_STATUS
    16732088ExplainPcieDeviceCap (
    1674   IN PCIE_CAP_STURCTURE *PciExpressCap
     2089  IN PCIE_CAP_STRUCTURE *PciExpressCap
    16752090  );
    16762091
     
    16842099EFI_STATUS
    16852100ExplainPcieDeviceControl (
    1686   IN PCIE_CAP_STURCTURE *PciExpressCap
     2101  IN PCIE_CAP_STRUCTURE *PciExpressCap
    16872102  );
    16882103
     
    16962111EFI_STATUS
    16972112ExplainPcieDeviceStatus (
    1698   IN PCIE_CAP_STURCTURE *PciExpressCap
     2113  IN PCIE_CAP_STRUCTURE *PciExpressCap
    16992114  );
    17002115
     
    17082123EFI_STATUS
    17092124ExplainPcieLinkCap (
    1710   IN PCIE_CAP_STURCTURE *PciExpressCap
     2125  IN PCIE_CAP_STRUCTURE *PciExpressCap
    17112126  );
    17122127
     
    17202135EFI_STATUS
    17212136ExplainPcieLinkControl (
    1722   IN PCIE_CAP_STURCTURE *PciExpressCap
     2137  IN PCIE_CAP_STRUCTURE *PciExpressCap
    17232138  );
    17242139
     
    17322147EFI_STATUS
    17332148ExplainPcieLinkStatus (
    1734   IN PCIE_CAP_STURCTURE *PciExpressCap
     2149  IN PCIE_CAP_STRUCTURE *PciExpressCap
    17352150  );
    17362151
     
    17442159EFI_STATUS
    17452160ExplainPcieSlotCap (
    1746   IN PCIE_CAP_STURCTURE *PciExpressCap
     2161  IN PCIE_CAP_STRUCTURE *PciExpressCap
    17472162  );
    17482163
     
    17562171EFI_STATUS
    17572172ExplainPcieSlotControl (
    1758   IN PCIE_CAP_STURCTURE *PciExpressCap
     2173  IN PCIE_CAP_STRUCTURE *PciExpressCap
    17592174  );
    17602175
     
    17682183EFI_STATUS
    17692184ExplainPcieSlotStatus (
    1770   IN PCIE_CAP_STURCTURE *PciExpressCap
     2185  IN PCIE_CAP_STRUCTURE *PciExpressCap
    17712186  );
    17722187
     
    17802195EFI_STATUS
    17812196ExplainPcieRootControl (
    1782   IN PCIE_CAP_STURCTURE *PciExpressCap
     2197  IN PCIE_CAP_STRUCTURE *PciExpressCap
    17832198  );
    17842199
     
    17922207EFI_STATUS
    17932208ExplainPcieRootCap (
    1794   IN PCIE_CAP_STURCTURE *PciExpressCap
     2209  IN PCIE_CAP_STRUCTURE *PciExpressCap
    17952210  );
    17962211
     
    18042219EFI_STATUS
    18052220ExplainPcieRootStatus (
    1806   IN PCIE_CAP_STURCTURE *PciExpressCap
     2221  IN PCIE_CAP_STRUCTURE *PciExpressCap
    18072222  );
    18082223
    1809 typedef EFI_STATUS (*PCIE_EXPLAIN_FUNCTION) (IN PCIE_CAP_STURCTURE *PciExpressCap);
     2224typedef EFI_STATUS (*PCIE_EXPLAIN_FUNCTION) (IN PCIE_CAP_STRUCTURE *PciExpressCap);
    18102225
    18112226typedef enum {
     
    20552470  CHAR16                            *ProblemParam;
    20562471  SHELL_STATUS                      ShellStatus;
    2057   UINTN                             Size;
    20582472  CONST CHAR16                      *Temp;
     2473  UINT64                            RetVal;
     2474  UINT16                            EnhancedDump;
    20592475
    20602476  ShellStatus         = SHELL_SUCCESS;
    20612477  Status              = EFI_SUCCESS;
    20622478  Address             = 0;
    2063   Size                = 0;
    20642479  IoDev               = NULL;
    20652480  HandleBuf           = NULL;
     
    23112726    Temp = ShellCommandLineGetValue(Package, L"-s");
    23122727    if (Temp != NULL) {
    2313       Segment = (UINT16) ShellStrToUintn (Temp);
     2728      //
     2729      // Input converted to hexadecimal number.
     2730      //
     2731      if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) {
     2732        Segment = (UINT16) RetVal;
     2733      } else {
     2734        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle);
     2735        ShellStatus = SHELL_INVALID_PARAMETER;
     2736        goto Done;
     2737      }
    23142738    }
    23152739
     
    23202744    Temp = ShellCommandLineGetRawValue(Package, 1);
    23212745    if (Temp != NULL) {
    2322       Bus = (UINT16)ShellStrToUintn(Temp);
     2746      //
     2747      // Input converted to hexadecimal number.
     2748      //
     2749      if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) {
     2750        Bus = (UINT16) RetVal;
     2751      } else {
     2752        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle);
     2753        ShellStatus = SHELL_INVALID_PARAMETER;
     2754        goto Done;
     2755      }
     2756
    23232757      if (Bus > MAX_BUS_NUMBER) {
    23242758        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
     
    23292763    Temp = ShellCommandLineGetRawValue(Package, 2);
    23302764    if (Temp != NULL) {
    2331       Device = (UINT16) ShellStrToUintn(Temp);
     2765      //
     2766      // Input converted to hexadecimal number.
     2767      //
     2768      if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) {
     2769        Device = (UINT16) RetVal;
     2770      } else {
     2771        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle);
     2772        ShellStatus = SHELL_INVALID_PARAMETER;
     2773        goto Done;
     2774      }
     2775
    23322776      if (Device > MAX_DEVICE_NUMBER){
    23332777        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
     
    23392783    Temp = ShellCommandLineGetRawValue(Package, 3);
    23402784    if (Temp != NULL) {
    2341       Func = (UINT16) ShellStrToUintn(Temp);
     2785      //
     2786      // Input converted to hexadecimal number.
     2787      //
     2788      if (!EFI_ERROR (ShellConvertStringToUint64 (Temp, &RetVal, TRUE, TRUE))) {
     2789        Func = (UINT16) RetVal;
     2790      } else {
     2791        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV_HEX), gShellDebug1HiiHandle);
     2792        ShellStatus = SHELL_INVALID_PARAMETER;
     2793        goto Done;
     2794      }
     2795
    23422796      if (Func > MAX_FUNCTION_NUMBER){
    23432797        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp);
     
    23622816      ShellPrintHiiEx(
    23632817        -1, -1, NULL, STRING_TOKEN (STR_PCI_NO_FIND), gShellDebug1HiiHandle,
    2364         gShellDebug1HiiHandle,
    23652818        Segment,
    23662819        Bus
     
    24242877    //
    24252878    if (ExplainData) {
    2426       Status = PciExplainData (&ConfigSpace, Address, IoDev);
     2879      EnhancedDump = 0;
     2880      if (ShellCommandLineGetFlag(Package, L"-_e")) {
     2881        EnhancedDump = 0xFFFF;
     2882        Temp = ShellCommandLineGetValue(Package, L"-_e");
     2883        if (Temp != NULL) {
     2884          EnhancedDump = (UINT16) ShellHexStrToUintn (Temp);
     2885        }
     2886      }
     2887      Status = PciExplainData (&ConfigSpace, Address, IoDev, EnhancedDump);
    24272888    }
    24282889  }
     
    24652926  UINTN                             Index;
    24662927  EFI_STATUS                        Status;
    2467   BOOLEAN                           FoundInterface;
    24682928  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;
    24692929  UINT16                            MinBus;
     
    24712931  BOOLEAN                           IsEnd;
    24722932
    2473   FoundInterface = FALSE;
    24742933  //
    24752934  // Go through all handles, until the one meets the criteria is found
     
    25032962
    25042963      if (MinBus <= Bus && MaxBus >= Bus) {
    2505         FoundInterface = TRUE;
    2506         break;
     2964        return EFI_SUCCESS;
    25072965      }
    25082966    }
    25092967  }
    25102968
    2511   if (FoundInterface) {
    2512     return EFI_SUCCESS;
    2513   } else {
    2514     return EFI_INVALID_PARAMETER;
    2515   }
     2969  return EFI_NOT_FOUND;
    25162970}
    25172971
     
    26253079  @param[in] Address         Address used to access configuration space of this PCI device.
    26263080  @param[in] IoDev           Handle used to access configuration space of PCI device.
     3081  @param[in] EnhancedDump    The print format for the dump data.
    26273082
    26283083  @retval EFI_SUCCESS     The command completed successfully.
     
    26323087  IN PCI_CONFIG_SPACE                       *ConfigSpace,
    26333088  IN UINT64                                 Address,
    2634   IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev
     3089  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *IoDev,
     3090  IN CONST UINT16                           EnhancedDump
    26353091  )
    26363092{
     
    26423098  Common = &(ConfigSpace->Common);
    26433099
    2644   Print (L"\n");
     3100  ShellPrintEx (-1, -1, L"\r\n");
    26453101
    26463102  //
     
    26673123  // Print register Revision ID
    26683124  //
    2669   ShellPrintEx(-1, -1, L"/r/n");
     3125  ShellPrintEx(-1, -1, L"\r\n");
    26703126  ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_PCI_LINE_RID), gShellDebug1HiiHandle,
    26713127    INDEX_OF (&(Common->RevisionId)),
     
    27433199  ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_CLASS), gShellDebug1HiiHandle);
    27443200  PciPrintClassCode ((UINT8 *) Common->ClassCode, TRUE);
    2745   Print (L"\n");
     3201  ShellPrintEx (-1, -1, L"\r\n");
    27463202
    27473203  if (ShellGetExecutionBreakFlag()) {
     
    27903246  //
    27913247  if ((Common->Status) & EFI_PCI_STATUS_CAPABILITY) {
    2792     PciExplainCapabilityStruct (IoDev, Address, CapPtr);
     3248    PciExplainCapabilityStruct (IoDev, Address, CapPtr, EnhancedDump);
    27933249  }
    27943250
     
    28343290      BarExist = TRUE;
    28353291      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_START_TYPE), gShellDebug1HiiHandle);
    2836       Print (L"  --------------------------------------------------------------------------");
     3292      ShellPrintEx (-1, -1, L"  --------------------------------------------------------------------------");
    28373293    }
    28383294
     
    28543310
    28553311  } else {
    2856     Print (L"\n  --------------------------------------------------------------------------");
     3312    ShellPrintEx (-1, -1, L"\r\n  --------------------------------------------------------------------------");
    28573313  }
    28583314
     
    29853441      BarExist = TRUE;
    29863442      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_START_TYPE_2), gShellDebug1HiiHandle);
    2987       Print (L"  --------------------------------------------------------------------------");
     3443      ShellPrintEx (-1, -1, L"  --------------------------------------------------------------------------");
    29883444    }
    29893445
     
    30043460    ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_NONE), gShellDebug1HiiHandle);
    30053461  } else {
    3006     Print (L"\n  --------------------------------------------------------------------------");
     3462    ShellPrintEx (-1, -1, L"\r\n  --------------------------------------------------------------------------");
    30073463  }
    30083464
     
    30323488   );
    30333489
    3034   Print (L"               ------------------------------------------------------\n");
     3490  ShellPrintEx (-1, -1, L"               ------------------------------------------------------\r\n");
    30353491
    30363492  ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_BRIDGE), gShellDebug1HiiHandle, Bridge->PrimaryBus);
     
    30593515  //
    30603516  ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_RESOURCE_TYPE), gShellDebug1HiiHandle);
    3061   Print (L"----------------------------------------------------------------------\n");
     3517  ShellPrintEx (-1, -1, L"----------------------------------------------------------------------\r\n");
    30623518
    30633519  //
     
    32003656      Bar64 = 0x0;
    32013657      CopyMem (&Bar64, Bar, sizeof (UINT64));
    3202       ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_ONE_VAR_2), gShellDebug1HiiHandle, RShiftU64 ((Bar64 & 0xfffffffffffffff0ULL), 32));
     3658      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_ONE_VAR_2), gShellDebug1HiiHandle, (UINT32) RShiftU64 ((Bar64 & 0xfffffffffffffff0ULL), 32));
    32033659      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_ONE_VAR_3), gShellDebug1HiiHandle, (UINT32) (Bar64 & 0xfffffffffffffff0ULL));
    32043660      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_MEM), gShellDebug1HiiHandle);
     
    32283684    IsMem = FALSE;
    32293685    ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_ONE_VAR_4), gShellDebug1HiiHandle, *Bar & 0xfffffffc);
    3230     Print (L"I/O                               ");
     3686    ShellPrintEx (-1, -1, L"I/O                               ");
    32313687  }
    32323688
     
    33003756
    33013757    } else {
    3302       ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_RSHIFT), gShellDebug1HiiHandle, RShiftU64 (NewBar64, 32));
     3758      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_RSHIFT), gShellDebug1HiiHandle, (UINT32) RShiftU64 (NewBar64, 32));
    33033759      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_RSHIFT), gShellDebug1HiiHandle, (UINT32) NewBar64);
    3304       Print (L"  ");
     3760      ShellPrintEx (-1, -1, L"  ");
    33053761      ShellPrintHiiEx(-1, -1, NULL,
    33063762        STRING_TOKEN (STR_PCI2_RSHIFT),
    33073763        gShellDebug1HiiHandle,
    3308         RShiftU64 ((NewBar64 + (Bar64 & 0xfffffffffffffff0ULL) - 1), 32)
     3764        (UINT32) RShiftU64 ((NewBar64 + (Bar64 & 0xfffffffffffffff0ULL) - 1), 32)
    33093765       );
    33103766      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_RSHIFT), gShellDebug1HiiHandle, (UINT32) (NewBar64 + (Bar64 & 0xfffffffffffffff0ULL) - 1));
     
    33623818   );
    33633819
    3364   Print (L"               ------------------------------------------------------\n");
     3820  ShellPrintEx (-1, -1, L"               ------------------------------------------------------\r\n");
    33653821
    33663822  ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_CARDBUS), gShellDebug1HiiHandle, CardBus->PciBusNumber);
     
    33823838  //
    33833839  ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_PCI2_RESOURCE_TYPE_2), gShellDebug1HiiHandle);
    3384   Print (L"----------------------------------------------------------------------\n");
     3840  ShellPrintEx (-1, -1, L"----------------------------------------------------------------------\r\n");
    33853841
    33863842  ShellPrintHiiEx(-1, -1, NULL,
     
    37544210  Print each capability structure.
    37554211
    3756   @param[in] IoDev      The pointer to the deivce.
    3757   @param[in] Address    The address to start at.
    3758   @param[in] CapPtr     The offset from the address.
     4212  @param[in] IoDev            The pointer to the deivce.
     4213  @param[in] Address          The address to start at.
     4214  @param[in] CapPtr           The offset from the address.
     4215  @param[in] EnhancedDump     The print format for the dump data.
    37594216
    37604217  @retval EFI_SUCCESS     The operation was successful.
     
    37644221  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,
    37654222  IN UINT64                                   Address,
    3766   IN  UINT8                                   CapPtr
     4223  IN  UINT8                                   CapPtr,
     4224  IN CONST UINT16                            EnhancedDump
    37674225  )
    37684226{
     
    37874245    //
    37884246    if (EFI_PCI_CAPABILITY_ID_PCIEXP == CapabilityID) {
    3789       PciExplainPciExpress (IoDev, Address, CapabilityPtr);
     4247      PciExplainPciExpress (IoDev, Address, CapabilityPtr, EnhancedDump);
    37904248      return EFI_SUCCESS;
    37914249    }
     
    38084266EFI_STATUS
    38094267ExplainPcieCapReg (
    3810   IN PCIE_CAP_STURCTURE *PciExpressCap
     4268  IN PCIE_CAP_STRUCTURE *PciExpressCap
    38114269  )
    38124270{
     
    38154273
    38164274  PcieCapReg = PciExpressCap->PcieCapReg;
    3817   Print (
    3818     L"  Capability Version(3:0):          %E0x%04x%N\n",
     4275  ShellPrintEx (-1, -1,
     4276    L"  Capability Version(3:0):          %E0x%04x%N\r\n",
    38194277    PCIE_CAP_VERSION (PcieCapReg)
    38204278   );
     
    38244282    DevicePortType = L"Unknown Type";
    38254283  }
    3826   Print (
    3827     L"  Device/PortType(7:4):             %E%s%N\n",
     4284  ShellPrintEx (-1, -1,
     4285    L"  Device/PortType(7:4):             %E%s%N\r\n",
    38284286    DevicePortType
    38294287   );
     
    38354293  if (PCIE_CAP_DEVICEPORT_TYPE (PcieCapReg) == PCIE_ROOT_COMPLEX_ROOT_PORT ||
    38364294      PCIE_CAP_DEVICEPORT_TYPE (PcieCapReg) == PCIE_SWITCH_DOWNSTREAM_PORT) {
    3837     Print (
    3838       L"  Slot Implemented(8):              %E%d%N\n",
     4295    ShellPrintEx (-1, -1,
     4296      L"  Slot Implemented(8):              %E%d%N\r\n",
    38394297      PCIE_CAP_SLOT_IMPLEMENTED (PcieCapReg)
    38404298     );
    38414299  }
    3842   Print (
    3843     L"  Interrupt Message Number(13:9):   %E0x%05x%N\n",
     4300  ShellPrintEx (-1, -1,
     4301    L"  Interrupt Message Number(13:9):   %E0x%05x%N\r\n",
    38444302    PCIE_CAP_INT_MSG_NUM (PcieCapReg)
    38454303   );
     
    38564314EFI_STATUS
    38574315ExplainPcieDeviceCap (
    3858   IN PCIE_CAP_STURCTURE *PciExpressCap
     4316  IN PCIE_CAP_STRUCTURE *PciExpressCap
    38594317  )
    38604318{
     
    38684326  PcieDeviceCap  = PciExpressCap->PcieDeviceCap;
    38694327  DevicePortType = (UINT8) PCIE_CAP_DEVICEPORT_TYPE (PcieCapReg);
    3870   Print (L"  Max_Payload_Size Supported(2:0):          ");
     4328  ShellPrintEx (-1, -1, L"  Max_Payload_Size Supported(2:0):          ");
    38714329  if (PCIE_CAP_MAX_PAYLOAD (PcieDeviceCap) < 6) {
    3872     Print (L"%E%d bytes%N\n", 1 << (PCIE_CAP_MAX_PAYLOAD (PcieDeviceCap) + 7));
     4330    ShellPrintEx (-1, -1, L"%E%d bytes%N\r\n", 1 << (PCIE_CAP_MAX_PAYLOAD (PcieDeviceCap) + 7));
    38734331  } else {
    3874     Print (L"%EUnknown%N\n");
    3875   }
    3876   Print (
    3877     L"  Phantom Functions Supported(4:3):         %E%d%N\n",
     4332    ShellPrintEx (-1, -1, L"%EUnknown%N\r\n");
     4333  }
     4334  ShellPrintEx (-1, -1,
     4335    L"  Phantom Functions Supported(4:3):         %E%d%N\r\n",
    38784336    PCIE_CAP_PHANTOM_FUNC (PcieDeviceCap)
    38794337   );
    3880   Print (
    3881     L"  Extended Tag Field Supported(5):          %E%d-bit Tag field supported%N\n",
     4338  ShellPrintEx (-1, -1,
     4339    L"  Extended Tag Field Supported(5):          %E%d-bit Tag field supported%N\r\n",
    38824340    PCIE_CAP_EXTENDED_TAG (PcieDeviceCap) ? 8 : 5
    38834341   );
     
    38884346    L0sLatency = (UINT8) PCIE_CAP_L0SLATENCY (PcieDeviceCap);
    38894347    L1Latency  = (UINT8) PCIE_CAP_L1LATENCY (PcieDeviceCap);
    3890     Print (L"  Endpoint L0s Acceptable Latency(8:6):     ");
     4348    ShellPrintEx (-1, -1, L"  Endpoint L0s Acceptable Latency(8:6):     ");
    38914349    if (L0sLatency < 4) {
    3892       Print (L"%EMaximum of %d ns%N\n", 1 << (L0sLatency + 6));
     4350      ShellPrintEx (-1, -1, L"%EMaximum of %d ns%N\r\n", 1 << (L0sLatency + 6));
    38934351    } else {
    38944352      if (L0sLatency < 7) {
    3895         Print (L"%EMaximum of %d us%N\n", 1 << (L0sLatency - 3));
     4353        ShellPrintEx (-1, -1, L"%EMaximum of %d us%N\r\n", 1 << (L0sLatency - 3));
    38964354      } else {
    3897         Print (L"%ENo limit%N\n");
     4355        ShellPrintEx (-1, -1, L"%ENo limit%N\r\n");
    38984356      }
    38994357    }
    3900     Print (L"  Endpoint L1 Acceptable Latency(11:9):     ");
     4358    ShellPrintEx (-1, -1, L"  Endpoint L1 Acceptable Latency(11:9):     ");
    39014359    if (L1Latency < 7) {
    3902       Print (L"%EMaximum of %d us%N\n", 1 << (L1Latency + 1));
     4360      ShellPrintEx (-1, -1, L"%EMaximum of %d us%N\r\n", 1 << (L1Latency + 1));
    39034361    } else {
    3904       Print (L"%ENo limit%N\n");
     4362      ShellPrintEx (-1, -1, L"%ENo limit%N\r\n");
    39054363    }
    39064364  }
    3907   Print (
    3908     L"  Role-based Error Reporting(15):           %E%d%N\n",
     4365  ShellPrintEx (-1, -1,
     4366    L"  Role-based Error Reporting(15):           %E%d%N\r\n",
    39094367    PCIE_CAP_ERR_REPORTING (PcieDeviceCap)
    39104368   );
     
    39154373  //
    39164374  if (DevicePortType == PCIE_SWITCH_UPSTREAM_PORT) {
    3917     Print (
    3918       L"  Captured Slot Power Limit Value(25:18):   %E0x%02x%N\n",
     4375    ShellPrintEx (-1, -1,
     4376      L"  Captured Slot Power Limit Value(25:18):   %E0x%02x%N\r\n",
    39194377      PCIE_CAP_SLOT_POWER_VALUE (PcieDeviceCap)
    39204378     );
    3921     Print (
    3922       L"  Captured Slot Power Limit Scale(27:26):   %E%s%N\n",
     4379    ShellPrintEx (-1, -1,
     4380      L"  Captured Slot Power Limit Scale(27:26):   %E%s%N\r\n",
    39234381      SlotPwrLmtScaleTable[PCIE_CAP_SLOT_POWER_SCALE (PcieDeviceCap)]
    39244382     );
     
    39284386  //
    39294387  if (IS_PCIE_ENDPOINT (DevicePortType)) {
    3930     Print (
    3931       L"  Function Level Reset Capability(28):      %E%d%N\n",
     4388    ShellPrintEx (-1, -1,
     4389      L"  Function Level Reset Capability(28):      %E%d%N\r\n",
    39324390      PCIE_CAP_FUNC_LEVEL_RESET (PcieDeviceCap)
    39334391     );
     
    39454403EFI_STATUS
    39464404ExplainPcieDeviceControl (
    3947   IN PCIE_CAP_STURCTURE *PciExpressCap
     4405  IN PCIE_CAP_STRUCTURE *PciExpressCap
    39484406  )
    39494407{
     
    39534411  PcieCapReg        = PciExpressCap->PcieCapReg;
    39544412  PcieDeviceControl = PciExpressCap->DeviceControl;
    3955   Print (
    3956     L"  Correctable Error Reporting Enable(0):    %E%d%N\n",
     4413  ShellPrintEx (-1, -1,
     4414    L"  Correctable Error Reporting Enable(0):    %E%d%N\r\n",
    39574415    PCIE_CAP_COR_ERR_REPORTING_ENABLE (PcieDeviceControl)
    39584416   );
    3959   Print (
    3960     L"  Non-Fatal Error Reporting Enable(1):      %E%d%N\n",
     4417  ShellPrintEx (-1, -1,
     4418    L"  Non-Fatal Error Reporting Enable(1):      %E%d%N\r\n",
    39614419    PCIE_CAP_NONFAT_ERR_REPORTING_ENABLE (PcieDeviceControl)
    39624420   );
    3963   Print (
    3964     L"  Fatal Error Reporting Enable(2):          %E%d%N\n",
     4421  ShellPrintEx (-1, -1,
     4422    L"  Fatal Error Reporting Enable(2):          %E%d%N\r\n",
    39654423    PCIE_CAP_FATAL_ERR_REPORTING_ENABLE (PcieDeviceControl)
    39664424   );
    3967   Print (
    3968     L"  Unsupported Request Reporting Enable(3):  %E%d%N\n",
     4425  ShellPrintEx (-1, -1,
     4426    L"  Unsupported Request Reporting Enable(3):  %E%d%N\r\n",
    39694427    PCIE_CAP_UNSUP_REQ_REPORTING_ENABLE (PcieDeviceControl)
    39704428   );
    3971   Print (
    3972     L"  Enable Relaxed Ordering(4):               %E%d%N\n",
     4429  ShellPrintEx (-1, -1,
     4430    L"  Enable Relaxed Ordering(4):               %E%d%N\r\n",
    39734431    PCIE_CAP_RELAXED_ORDERING_ENABLE (PcieDeviceControl)
    39744432   );
    3975   Print (L"  Max_Payload_Size(7:5):                    ");
     4433  ShellPrintEx (-1, -1, L"  Max_Payload_Size(7:5):                    ");
    39764434  if (PCIE_CAP_MAX_PAYLOAD_SIZE (PcieDeviceControl) < 6) {
    3977     Print (L"%E%d bytes%N\n", 1 << (PCIE_CAP_MAX_PAYLOAD_SIZE (PcieDeviceControl) + 7));
     4435    ShellPrintEx (-1, -1, L"%E%d bytes%N\r\n", 1 << (PCIE_CAP_MAX_PAYLOAD_SIZE (PcieDeviceControl) + 7));
    39784436  } else {
    3979     Print (L"%EUnknown%N\n");
    3980   }
    3981   Print (
    3982     L"  Extended Tag Field Enable(8):             %E%d%N\n",
     4437    ShellPrintEx (-1, -1, L"%EUnknown%N\r\n");
     4438  }
     4439  ShellPrintEx (-1, -1,
     4440    L"  Extended Tag Field Enable(8):             %E%d%N\r\n",
    39834441    PCIE_CAP_EXTENDED_TAG_ENABLE (PcieDeviceControl)
    39844442   );
    3985   Print (
    3986     L"  Phantom Functions Enable(9):              %E%d%N\n",
     4443  ShellPrintEx (-1, -1,
     4444    L"  Phantom Functions Enable(9):              %E%d%N\r\n",
    39874445    PCIE_CAP_PHANTOM_FUNC_ENABLE (PcieDeviceControl)
    39884446   );
    3989   Print (
    3990     L"  Auxiliary (AUX) Power PM Enable(10):      %E%d%N\n",
     4447  ShellPrintEx (-1, -1,
     4448    L"  Auxiliary (AUX) Power PM Enable(10):      %E%d%N\r\n",
    39914449    PCIE_CAP_AUX_PM_ENABLE (PcieDeviceControl)
    39924450   );
    3993   Print (
    3994     L"  Enable No Snoop(11):                      %E%d%N\n",
     4451  ShellPrintEx (-1, -1,
     4452    L"  Enable No Snoop(11):                      %E%d%N\r\n",
    39954453    PCIE_CAP_NO_SNOOP_ENABLE (PcieDeviceControl)
    39964454   );
    3997   Print (L"  Max_Read_Request_Size(14:12):             ");
     4455  ShellPrintEx (-1, -1, L"  Max_Read_Request_Size(14:12):             ");
    39984456  if (PCIE_CAP_MAX_READ_REQ_SIZE (PcieDeviceControl) < 6) {
    3999     Print (L"%E%d bytes%N\n", 1 << (PCIE_CAP_MAX_READ_REQ_SIZE (PcieDeviceControl) + 7));
     4457    ShellPrintEx (-1, -1, L"%E%d bytes%N\r\n", 1 << (PCIE_CAP_MAX_READ_REQ_SIZE (PcieDeviceControl) + 7));
    40004458  } else {
    4001     Print (L"%EUnknown%N\n");
     4459    ShellPrintEx (-1, -1, L"%EUnknown%N\r\n");
    40024460  }
    40034461  //
     
    40054463  //
    40064464  if (PCIE_CAP_DEVICEPORT_TYPE (PcieCapReg) == PCIE_PCIE_TO_PCIX_BRIDGE) {
    4007     Print (
    4008       L"  Bridge Configuration Retry Enable(15):  %E%d%N\n",
     4465    ShellPrintEx (-1, -1,
     4466      L"  Bridge Configuration Retry Enable(15):  %E%d%N\r\n",
    40094467      PCIE_CAP_BRG_CONF_RETRY (PcieDeviceControl)
    40104468     );
     
    40224480EFI_STATUS
    40234481ExplainPcieDeviceStatus (
    4024   IN PCIE_CAP_STURCTURE *PciExpressCap
     4482  IN PCIE_CAP_STRUCTURE *PciExpressCap
    40254483  )
    40264484{
     
    40284486
    40294487  PcieDeviceStatus = PciExpressCap->DeviceStatus;
    4030   Print (
    4031     L"  Correctable Error Detected(0):            %E%d%N\n",
     4488  ShellPrintEx (-1, -1,
     4489    L"  Correctable Error Detected(0):            %E%d%N\r\n",
    40324490    PCIE_CAP_COR_ERR_DETECTED (PcieDeviceStatus)
    40334491   );
    4034   Print (
    4035     L"  Non-Fatal Error Detected(1):              %E%d%N\n",
     4492  ShellPrintEx (-1, -1,
     4493    L"  Non-Fatal Error Detected(1):              %E%d%N\r\n",
    40364494    PCIE_CAP_NONFAT_ERR_DETECTED (PcieDeviceStatus)
    40374495   );
    4038   Print (
    4039     L"  Fatal Error Detected(2):                  %E%d%N\n",
     4496  ShellPrintEx (-1, -1,
     4497    L"  Fatal Error Detected(2):                  %E%d%N\r\n",
    40404498    PCIE_CAP_FATAL_ERR_DETECTED (PcieDeviceStatus)
    40414499   );
    4042   Print (
    4043     L"  Unsupported Request Detected(3):          %E%d%N\n",
     4500  ShellPrintEx (-1, -1,
     4501    L"  Unsupported Request Detected(3):          %E%d%N\r\n",
    40444502    PCIE_CAP_UNSUP_REQ_DETECTED (PcieDeviceStatus)
    40454503   );
    4046   Print (
    4047     L"  AUX Power Detected(4):                    %E%d%N\n",
     4504  ShellPrintEx (-1, -1,
     4505    L"  AUX Power Detected(4):                    %E%d%N\r\n",
    40484506    PCIE_CAP_AUX_POWER_DETECTED (PcieDeviceStatus)
    40494507   );
    4050   Print (
    4051     L"  Transactions Pending(5):                  %E%d%N\n",
     4508  ShellPrintEx (-1, -1,
     4509    L"  Transactions Pending(5):                  %E%d%N\r\n",
    40524510    PCIE_CAP_TRANSACTION_PENDING (PcieDeviceStatus)
    40534511   );
     
    40644522EFI_STATUS
    40654523ExplainPcieLinkCap (
    4066   IN PCIE_CAP_STURCTURE *PciExpressCap
     4524  IN PCIE_CAP_STRUCTURE *PciExpressCap
    40674525  )
    40684526{
    40694527  UINT32 PcieLinkCap;
    4070   CHAR16 *SupLinkSpeeds;
     4528  CHAR16 *MaxLinkSpeed;
    40714529  CHAR16 *AspmValue;
    40724530
    40734531  PcieLinkCap = PciExpressCap->LinkCap;
    4074   switch (PCIE_CAP_SUP_LINK_SPEEDS (PcieLinkCap)) {
     4532  switch (PCIE_CAP_MAX_LINK_SPEED (PcieLinkCap)) {
    40754533    case 1:
    4076       SupLinkSpeeds = L"2.5 GT/s";
     4534      MaxLinkSpeed = L"2.5 GT/s";
    40774535      break;
    40784536    case 2:
    4079       SupLinkSpeeds = L"5.0 GT/s and 2.5 GT/s";
     4537      MaxLinkSpeed = L"5.0 GT/s";
     4538      break;
     4539    case 3:
     4540      MaxLinkSpeed = L"8.0 GT/s";
    40804541      break;
    40814542    default:
    4082       SupLinkSpeeds = L"Unknown";
     4543      MaxLinkSpeed = L"Unknown";
    40834544      break;
    40844545  }
    4085   Print (
    4086     L"  Supported Link Speeds(3:0):                         %E%s supported%N\n",
    4087     SupLinkSpeeds
    4088    );
    4089   Print (
    4090     L"  Maximum Link Width(9:4):                            %Ex%d%N\n",
     4546  ShellPrintEx (-1, -1,
     4547    L"  Maximum Link Speed(3:0):                            %E%s%N\r\n",
     4548    MaxLinkSpeed
     4549   );
     4550  ShellPrintEx (-1, -1,
     4551    L"  Maximum Link Width(9:4):                            %Ex%d%N\r\n",
    40914552    PCIE_CAP_MAX_LINK_WIDTH (PcieLinkCap)
    40924553   );
    40934554  switch (PCIE_CAP_ASPM_SUPPORT (PcieLinkCap)) {
     4555    case 0:
     4556      AspmValue = L"Not";
     4557      break;
    40944558    case 1:
    4095       AspmValue = L"L0s Entry";
     4559      AspmValue = L"L0s";
     4560      break;
     4561    case 2:
     4562      AspmValue = L"L1";
    40964563      break;
    40974564    case 3:
     
    41024569      break;
    41034570  }
    4104   Print (
    4105     L"  Active State Power Management Support(11:10):       %E%s Supported%N\n",
     4571  ShellPrintEx (-1, -1,
     4572    L"  Active State Power Management Support(11:10):       %E%s Supported%N\r\n",
    41064573    AspmValue
    41074574   );
    4108   Print (
    4109     L"  L0s Exit Latency(14:12):                            %E%s%N\n",
     4575  ShellPrintEx (-1, -1,
     4576    L"  L0s Exit Latency(14:12):                            %E%s%N\r\n",
    41104577    L0sLatencyStrTable[PCIE_CAP_L0S_LATENCY (PcieLinkCap)]
    41114578   );
    4112   Print (
    4113     L"  L1 Exit Latency(17:15):                             %E%s%N\n",
     4579  ShellPrintEx (-1, -1,
     4580    L"  L1 Exit Latency(17:15):                             %E%s%N\r\n",
    41144581    L1LatencyStrTable[PCIE_CAP_L0S_LATENCY (PcieLinkCap)]
    41154582   );
    4116   Print (
    4117     L"  Clock Power Management(18):                         %E%d%N\n",
     4583  ShellPrintEx (-1, -1,
     4584    L"  Clock Power Management(18):                         %E%d%N\r\n",
    41184585    PCIE_CAP_CLOCK_PM (PcieLinkCap)
    41194586   );
    4120   Print (
    4121     L"  Surprise Down Error Reporting Capable(19):          %E%d%N\n",
     4587  ShellPrintEx (-1, -1,
     4588    L"  Surprise Down Error Reporting Capable(19):          %E%d%N\r\n",
    41224589    PCIE_CAP_SUP_DOWN_ERR_REPORTING (PcieLinkCap)
    41234590   );
    4124   Print (
    4125     L"  Data Link Layer Link Active Reporting Capable(20):  %E%d%N\n",
     4591  ShellPrintEx (-1, -1,
     4592    L"  Data Link Layer Link Active Reporting Capable(20):  %E%d%N\r\n",
    41264593    PCIE_CAP_LINK_ACTIVE_REPORTING (PcieLinkCap)
    41274594   );
    4128   Print (
    4129     L"  Link Bandwidth Notification Capability(21):         %E%d%N\n",
     4595  ShellPrintEx (-1, -1,
     4596    L"  Link Bandwidth Notification Capability(21):         %E%d%N\r\n",
    41304597    PCIE_CAP_LINK_BWD_NOTIF_CAP (PcieLinkCap)
    41314598   );
    4132   Print (
    4133     L"  Port Number(31:24):                                 %E0x%02x%N\n",
     4599  ShellPrintEx (-1, -1,
     4600    L"  Port Number(31:24):                                 %E0x%02x%N\r\n",
    41344601    PCIE_CAP_PORT_NUMBER (PcieLinkCap)
    41354602   );
     
    41464613EFI_STATUS
    41474614ExplainPcieLinkControl (
    4148   IN PCIE_CAP_STURCTURE *PciExpressCap
     4615  IN PCIE_CAP_STRUCTURE *PciExpressCap
    41494616  )
    41504617{
     
    41544621  PcieLinkControl = PciExpressCap->LinkControl;
    41554622  DevicePortType  = (UINT8) PCIE_CAP_DEVICEPORT_TYPE (PciExpressCap->PcieCapReg);
    4156   Print (
    4157     L"  Active State Power Management Control(1:0):         %E%s%N\n",
     4623  ShellPrintEx (-1, -1,
     4624    L"  Active State Power Management Control(1:0):         %E%s%N\r\n",
    41584625    ASPMCtrlStrTable[PCIE_CAP_ASPM_CONTROL (PcieLinkControl)]
    41594626   );
     
    41624629  //
    41634630  if (!IS_PCIE_SWITCH(DevicePortType)) {
    4164     Print (
    4165       L"  Read Completion Boundary (RCB)(3):                  %E%d byte%N\n",
     4631    ShellPrintEx (-1, -1,
     4632      L"  Read Completion Boundary (RCB)(3):                  %E%d byte%N\r\n",
    41664633      1 << (PCIE_CAP_RCB (PcieLinkControl) + 6)
    41674634     );
     
    41764643      DevicePortType != PCIE_SWITCH_UPSTREAM_PORT &&
    41774644      DevicePortType != PCIE_PCIE_TO_PCIX_BRIDGE) {
    4178     Print (
    4179       L"  Link Disable(4):                                    %E%d%N\n",
     4645    ShellPrintEx (-1, -1,
     4646      L"  Link Disable(4):                                    %E%d%N\r\n",
    41804647      PCIE_CAP_LINK_DISABLE (PcieLinkControl)
    41814648     );
    41824649  }
    4183   Print (
    4184     L"  Common Clock Configuration(6):                      %E%d%N\n",
     4650  ShellPrintEx (-1, -1,
     4651    L"  Common Clock Configuration(6):                      %E%d%N\r\n",
    41854652    PCIE_CAP_COMMON_CLK_CONF (PcieLinkControl)
    41864653   );
    4187   Print (
    4188     L"  Extended Synch(7):                                  %E%d%N\n",
     4654  ShellPrintEx (-1, -1,
     4655    L"  Extended Synch(7):                                  %E%d%N\r\n",
    41894656    PCIE_CAP_EXT_SYNC (PcieLinkControl)
    41904657   );
    4191   Print (
    4192     L"  Enable Clock Power Management(8):                   %E%d%N\n",
     4658  ShellPrintEx (-1, -1,
     4659    L"  Enable Clock Power Management(8):                   %E%d%N\r\n",
    41934660    PCIE_CAP_CLK_PWR_MNG (PcieLinkControl)
    41944661   );
    4195   Print (
    4196     L"  Hardware Autonomous Width Disable(9):               %E%d%N\n",
     4662  ShellPrintEx (-1, -1,
     4663    L"  Hardware Autonomous Width Disable(9):               %E%d%N\r\n",
    41974664    PCIE_CAP_HW_AUTO_WIDTH_DISABLE (PcieLinkControl)
    41984665   );
    4199   Print (
    4200     L"  Link Bandwidth Management Interrupt Enable(10):     %E%d%N\n",
     4666  ShellPrintEx (-1, -1,
     4667    L"  Link Bandwidth Management Interrupt Enable(10):     %E%d%N\r\n",
    42014668    PCIE_CAP_LINK_BDW_MNG_INT_EN (PcieLinkControl)
    42024669   );
    4203   Print (
    4204     L"  Link Autonomous Bandwidth Interrupt Enable(11):     %E%d%N\n",
     4670  ShellPrintEx (-1, -1,
     4671    L"  Link Autonomous Bandwidth Interrupt Enable(11):     %E%d%N\r\n",
    42054672    PCIE_CAP_LINK_AUTO_BDW_INT_EN (PcieLinkControl)
    42064673   );
     
    42174684EFI_STATUS
    42184685ExplainPcieLinkStatus (
    4219   IN PCIE_CAP_STURCTURE *PciExpressCap
     4686  IN PCIE_CAP_STRUCTURE *PciExpressCap
    42204687  )
    42214688{
    42224689  UINT16 PcieLinkStatus;
    4223   CHAR16 *SupLinkSpeeds;
     4690  CHAR16 *CurLinkSpeed;
    42244691
    42254692  PcieLinkStatus = PciExpressCap->LinkStatus;
    42264693  switch (PCIE_CAP_CUR_LINK_SPEED (PcieLinkStatus)) {
    42274694    case 1:
    4228       SupLinkSpeeds = L"2.5 GT/s";
     4695      CurLinkSpeed = L"2.5 GT/s";
    42294696      break;
    42304697    case 2:
    4231       SupLinkSpeeds = L"5.0 GT/s";
     4698      CurLinkSpeed = L"5.0 GT/s";
     4699      break;
     4700    case 3:
     4701      CurLinkSpeed = L"8.0 GT/s";
    42324702      break;
    42334703    default:
    4234       SupLinkSpeeds = L"Reserved";
     4704      CurLinkSpeed = L"Reserved";
    42354705      break;
    42364706  }
    4237   Print (
    4238     L"  Current Link Speed(3:0):                            %E%s%N\n",
    4239     SupLinkSpeeds
    4240    );
    4241   Print (
    4242     L"  Negotiated Link Width(9:4):                         %Ex%d%N\n",
     4707  ShellPrintEx (-1, -1,
     4708    L"  Current Link Speed(3:0):                            %E%s%N\r\n",
     4709    CurLinkSpeed
     4710   );
     4711  ShellPrintEx (-1, -1,
     4712    L"  Negotiated Link Width(9:4):                         %Ex%d%N\r\n",
    42434713    PCIE_CAP_NEGO_LINK_WIDTH (PcieLinkStatus)
    42444714   );
    4245   Print (
    4246     L"  Link Training(11):                                  %E%d%N\n",
     4715  ShellPrintEx (-1, -1,
     4716    L"  Link Training(11):                                  %E%d%N\r\n",
    42474717    PCIE_CAP_LINK_TRAINING (PcieLinkStatus)
    42484718   );
    4249   Print (
    4250     L"  Slot Clock Configuration(12):                       %E%d%N\n",
     4719  ShellPrintEx (-1, -1,
     4720    L"  Slot Clock Configuration(12):                       %E%d%N\r\n",
    42514721    PCIE_CAP_SLOT_CLK_CONF (PcieLinkStatus)
    42524722   );
    4253   Print (
    4254     L"  Data Link Layer Link Active(13):                    %E%d%N\n",
     4723  ShellPrintEx (-1, -1,
     4724    L"  Data Link Layer Link Active(13):                    %E%d%N\r\n",
    42554725    PCIE_CAP_DATA_LINK_ACTIVE (PcieLinkStatus)
    42564726   );
    4257   Print (
    4258     L"  Link Bandwidth Management Status(14):               %E%d%N\n",
     4727  ShellPrintEx (-1, -1,
     4728    L"  Link Bandwidth Management Status(14):               %E%d%N\r\n",
    42594729    PCIE_CAP_LINK_BDW_MNG_STAT (PcieLinkStatus)
    42604730   );
    4261   Print (
    4262     L"  Link Autonomous Bandwidth Status(15):               %E%d%N\n",
     4731  ShellPrintEx (-1, -1,
     4732    L"  Link Autonomous Bandwidth Status(15):               %E%d%N\r\n",
    42634733    PCIE_CAP_LINK_AUTO_BDW_STAT (PcieLinkStatus)
    42644734   );
     
    42754745EFI_STATUS
    42764746ExplainPcieSlotCap (
    4277   IN PCIE_CAP_STURCTURE *PciExpressCap
     4747  IN PCIE_CAP_STRUCTURE *PciExpressCap
    42784748  )
    42794749{
     
    42824752  PcieSlotCap = PciExpressCap->SlotCap;
    42834753
    4284   Print (
    4285     L"  Attention Button Present(0):                        %E%d%N\n",
     4754  ShellPrintEx (-1, -1,
     4755    L"  Attention Button Present(0):                        %E%d%N\r\n",
    42864756    PCIE_CAP_ATT_BUT_PRESENT (PcieSlotCap)
    42874757   );
    4288   Print (
    4289     L"  Power Controller Present(1):                        %E%d%N\n",
     4758  ShellPrintEx (-1, -1,
     4759    L"  Power Controller Present(1):                        %E%d%N\r\n",
    42904760    PCIE_CAP_PWR_CTRLLER_PRESENT (PcieSlotCap)
    42914761   );
    4292   Print (
    4293     L"  MRL Sensor Present(2):                              %E%d%N\n",
     4762  ShellPrintEx (-1, -1,
     4763    L"  MRL Sensor Present(2):                              %E%d%N\r\n",
    42944764    PCIE_CAP_MRL_SENSOR_PRESENT (PcieSlotCap)
    42954765   );
    4296   Print (
    4297     L"  Attention Indicator Present(3):                     %E%d%N\n",
     4766  ShellPrintEx (-1, -1,
     4767    L"  Attention Indicator Present(3):                     %E%d%N\r\n",
    42984768    PCIE_CAP_ATT_IND_PRESENT (PcieSlotCap)
    42994769   );
    4300   Print (
    4301     L"  Power Indicator Present(4):                         %E%d%N\n",
     4770  ShellPrintEx (-1, -1,
     4771    L"  Power Indicator Present(4):                         %E%d%N\r\n",
    43024772    PCIE_CAP_PWD_IND_PRESENT (PcieSlotCap)
    43034773   );
    4304   Print (
    4305     L"  Hot-Plug Surprise(5):                               %E%d%N\n",
     4774  ShellPrintEx (-1, -1,
     4775    L"  Hot-Plug Surprise(5):                               %E%d%N\r\n",
    43064776    PCIE_CAP_HOTPLUG_SUPPRISE (PcieSlotCap)
    43074777   );
    4308   Print (
    4309     L"  Hot-Plug Capable(6):                                %E%d%N\n",
     4778  ShellPrintEx (-1, -1,
     4779    L"  Hot-Plug Capable(6):                                %E%d%N\r\n",
    43104780    PCIE_CAP_HOTPLUG_CAPABLE (PcieSlotCap)
    43114781   );
    4312   Print (
    4313     L"  Slot Power Limit Value(14:7):                       %E0x%02x%N\n",
     4782  ShellPrintEx (-1, -1,
     4783    L"  Slot Power Limit Value(14:7):                       %E0x%02x%N\r\n",
    43144784    PCIE_CAP_SLOT_PWR_LIMIT_VALUE (PcieSlotCap)
    43154785   );
    4316   Print (
    4317     L"  Slot Power Limit Scale(16:15):                      %E%s%N\n",
     4786  ShellPrintEx (-1, -1,
     4787    L"  Slot Power Limit Scale(16:15):                      %E%s%N\r\n",
    43184788    SlotPwrLmtScaleTable[PCIE_CAP_SLOT_PWR_LIMIT_SCALE (PcieSlotCap)]
    43194789   );
    4320   Print (
    4321     L"  Electromechanical Interlock Present(17):            %E%d%N\n",
     4790  ShellPrintEx (-1, -1,
     4791    L"  Electromechanical Interlock Present(17):            %E%d%N\r\n",
    43224792    PCIE_CAP_ELEC_INTERLOCK_PRESENT (PcieSlotCap)
    43234793   );
    4324   Print (
    4325     L"  No Command Completed Support(18):                   %E%d%N\n",
     4794  ShellPrintEx (-1, -1,
     4795    L"  No Command Completed Support(18):                   %E%d%N\r\n",
    43264796    PCIE_CAP_NO_COMM_COMPLETED_SUP (PcieSlotCap)
    43274797   );
    4328   Print (
    4329     L"  Physical Slot Number(31:19):                        %E%d%N\n",
     4798  ShellPrintEx (-1, -1,
     4799    L"  Physical Slot Number(31:19):                        %E%d%N\r\n",
    43304800    PCIE_CAP_PHY_SLOT_NUM (PcieSlotCap)
    43314801   );
     
    43434813EFI_STATUS
    43444814ExplainPcieSlotControl (
    4345   IN PCIE_CAP_STURCTURE *PciExpressCap
     4815  IN PCIE_CAP_STRUCTURE *PciExpressCap
    43464816  )
    43474817{
     
    43494819
    43504820  PcieSlotControl = PciExpressCap->SlotControl;
    4351   Print (
    4352     L"  Attention Button Pressed Enable(0):                 %E%d%N\n",
     4821  ShellPrintEx (-1, -1,
     4822    L"  Attention Button Pressed Enable(0):                 %E%d%N\r\n",
    43534823    PCIE_CAP_ATT_BUT_ENABLE (PcieSlotControl)
    43544824   );
    4355   Print (
    4356     L"  Power Fault Detected Enable(1):                     %E%d%N\n",
     4825  ShellPrintEx (-1, -1,
     4826    L"  Power Fault Detected Enable(1):                     %E%d%N\r\n",
    43574827    PCIE_CAP_PWR_FLT_DETECT_ENABLE (PcieSlotControl)
    43584828   );
    4359   Print (
    4360     L"  MRL Sensor Changed Enable(2):                       %E%d%N\n",
     4829  ShellPrintEx (-1, -1,
     4830    L"  MRL Sensor Changed Enable(2):                       %E%d%N\r\n",
    43614831    PCIE_CAP_MRL_SENSOR_CHANGE_ENABLE (PcieSlotControl)
    43624832   );
    4363   Print (
    4364     L"  Presence Detect Changed Enable(3):                  %E%d%N\n",
     4833  ShellPrintEx (-1, -1,
     4834    L"  Presence Detect Changed Enable(3):                  %E%d%N\r\n",
    43654835    PCIE_CAP_PRES_DETECT_CHANGE_ENABLE (PcieSlotControl)
    43664836   );
    4367   Print (
    4368     L"  Command Completed Interrupt Enable(4):              %E%d%N\n",
     4837  ShellPrintEx (-1, -1,
     4838    L"  Command Completed Interrupt Enable(4):              %E%d%N\r\n",
    43694839    PCIE_CAP_COMM_CMPL_INT_ENABLE (PcieSlotControl)
    43704840   );
    4371   Print (
    4372     L"  Hot-Plug Interrupt Enable(5):                       %E%d%N\n",
     4841  ShellPrintEx (-1, -1,
     4842    L"  Hot-Plug Interrupt Enable(5):                       %E%d%N\r\n",
    43734843    PCIE_CAP_HOTPLUG_INT_ENABLE (PcieSlotControl)
    43744844   );
    4375   Print (
    4376     L"  Attention Indicator Control(7:6):                   %E%s%N\n",
     4845  ShellPrintEx (-1, -1,
     4846    L"  Attention Indicator Control(7:6):                   %E%s%N\r\n",
    43774847    IndicatorTable[PCIE_CAP_ATT_IND_CTRL (PcieSlotControl)]
    43784848   );
    4379   Print (
    4380     L"  Power Indicator Control(9:8):                       %E%s%N\n",
     4849  ShellPrintEx (-1, -1,
     4850    L"  Power Indicator Control(9:8):                       %E%s%N\r\n",
    43814851    IndicatorTable[PCIE_CAP_PWR_IND_CTRL (PcieSlotControl)]
    43824852   );
    4383   Print (L"  Power Controller Control(10):                       %EPower ");
     4853  ShellPrintEx (-1, -1, L"  Power Controller Control(10):                       %EPower ");
    43844854  if (PCIE_CAP_PWR_CTRLLER_CTRL (PcieSlotControl)) {
    4385     Print (L"Off%N\n");
     4855    ShellPrintEx (-1, -1, L"Off%N\r\n");
    43864856  } else {
    4387     Print (L"On%N\n");
    4388   }
    4389   Print (
    4390     L"  Electromechanical Interlock Control(11):            %E%d%N\n",
     4857    ShellPrintEx (-1, -1, L"On%N\r\n");
     4858  }
     4859  ShellPrintEx (-1, -1,
     4860    L"  Electromechanical Interlock Control(11):            %E%d%N\r\n",
    43914861    PCIE_CAP_ELEC_INTERLOCK_CTRL (PcieSlotControl)
    43924862   );
    4393   Print (
    4394     L"  Data Link Layer State Changed Enable(12):           %E%d%N\n",
     4863  ShellPrintEx (-1, -1,
     4864    L"  Data Link Layer State Changed Enable(12):           %E%d%N\r\n",
    43954865    PCIE_CAP_DLINK_STAT_CHANGE_ENABLE (PcieSlotControl)
    43964866   );
     
    44074877EFI_STATUS
    44084878ExplainPcieSlotStatus (
    4409   IN PCIE_CAP_STURCTURE *PciExpressCap
     4879  IN PCIE_CAP_STRUCTURE *PciExpressCap
    44104880  )
    44114881{
     
    44144884  PcieSlotStatus = PciExpressCap->SlotStatus;
    44154885
    4416   Print (
    4417     L"  Attention Button Pressed(0):           %E%d%N\n",
     4886  ShellPrintEx (-1, -1,
     4887    L"  Attention Button Pressed(0):           %E%d%N\r\n",
    44184888    PCIE_CAP_ATT_BUT_PRESSED (PcieSlotStatus)
    44194889   );
    4420   Print (
    4421     L"  Power Fault Detected(1):               %E%d%N\n",
     4890  ShellPrintEx (-1, -1,
     4891    L"  Power Fault Detected(1):               %E%d%N\r\n",
    44224892    PCIE_CAP_PWR_FLT_DETECTED (PcieSlotStatus)
    44234893   );
    4424   Print (
    4425     L"  MRL Sensor Changed(2):                 %E%d%N\n",
     4894  ShellPrintEx (-1, -1,
     4895    L"  MRL Sensor Changed(2):                 %E%d%N\r\n",
    44264896    PCIE_CAP_MRL_SENSOR_CHANGED (PcieSlotStatus)
    44274897   );
    4428   Print (
    4429     L"  Presence Detect Changed(3):            %E%d%N\n",
     4898  ShellPrintEx (-1, -1,
     4899    L"  Presence Detect Changed(3):            %E%d%N\r\n",
    44304900    PCIE_CAP_PRES_DETECT_CHANGED (PcieSlotStatus)
    44314901   );
    4432   Print (
    4433     L"  Command Completed(4):                  %E%d%N\n",
     4902  ShellPrintEx (-1, -1,
     4903    L"  Command Completed(4):                  %E%d%N\r\n",
    44344904    PCIE_CAP_COMM_COMPLETED (PcieSlotStatus)
    44354905   );
    4436   Print (L"  MRL Sensor State(5):                   %EMRL ");
     4906  ShellPrintEx (-1, -1, L"  MRL Sensor State(5):                   %EMRL ");
    44374907  if (PCIE_CAP_MRL_SENSOR_STATE (PcieSlotStatus)) {
    4438     Print (L" Opened%N\n");
     4908    ShellPrintEx (-1, -1, L" Opened%N\r\n");
    44394909  } else {
    4440     Print (L" Closed%N\n");
    4441   }
    4442   Print (L"  Presence Detect State(6):              ");
     4910    ShellPrintEx (-1, -1, L" Closed%N\r\n");
     4911  }
     4912  ShellPrintEx (-1, -1, L"  Presence Detect State(6):              ");
    44434913  if (PCIE_CAP_PRES_DETECT_STATE (PcieSlotStatus)) {
    4444     Print (L"%ECard Present in slot%N\n");
     4914    ShellPrintEx (-1, -1, L"%ECard Present in slot%N\r\n");
    44454915  } else {
    4446     Print (L"%ESlot Empty%N\n");
    4447   }
    4448   Print (L"  Electromechanical Interlock Status(7): %EElectromechanical Interlock ");
     4916    ShellPrintEx (-1, -1, L"%ESlot Empty%N\r\n");
     4917  }
     4918  ShellPrintEx (-1, -1, L"  Electromechanical Interlock Status(7): %EElectromechanical Interlock ");
    44494919  if (PCIE_CAP_ELEC_INTERLOCK_STATE (PcieSlotStatus)) {
    4450     Print (L"Engaged%N\n");
     4920    ShellPrintEx (-1, -1, L"Engaged%N\r\n");
    44514921  } else {
    4452     Print (L"Disengaged%N\n");
    4453   }
    4454   Print (
    4455     L"  Data Link Layer State Changed(8):      %E%d%N\n",
     4922    ShellPrintEx (-1, -1, L"Disengaged%N\r\n");
     4923  }
     4924  ShellPrintEx (-1, -1,
     4925    L"  Data Link Layer State Changed(8):      %E%d%N\r\n",
    44564926    PCIE_CAP_DLINK_STAT_CHANGED (PcieSlotStatus)
    44574927   );
     
    44684938EFI_STATUS
    44694939ExplainPcieRootControl (
    4470   IN PCIE_CAP_STURCTURE *PciExpressCap
     4940  IN PCIE_CAP_STRUCTURE *PciExpressCap
    44714941  )
    44724942{
     
    44754945  PcieRootControl = PciExpressCap->RootControl;
    44764946
    4477   Print (
    4478     L"  System Error on Correctable Error Enable(0):  %E%d%N\n",
     4947  ShellPrintEx (-1, -1,
     4948    L"  System Error on Correctable Error Enable(0):  %E%d%N\r\n",
    44794949    PCIE_CAP_SYSERR_ON_CORERR_EN (PcieRootControl)
    44804950   );
    4481   Print (
    4482     L"  System Error on Non-Fatal Error Enable(1):    %E%d%N\n",
     4951  ShellPrintEx (-1, -1,
     4952    L"  System Error on Non-Fatal Error Enable(1):    %E%d%N\r\n",
    44834953    PCIE_CAP_SYSERR_ON_NONFATERR_EN (PcieRootControl)
    44844954   );
    4485   Print (
    4486     L"  System Error on Fatal Error Enable(2):        %E%d%N\n",
     4955  ShellPrintEx (-1, -1,
     4956    L"  System Error on Fatal Error Enable(2):        %E%d%N\r\n",
    44874957    PCIE_CAP_SYSERR_ON_FATERR_EN (PcieRootControl)
    44884958   );
    4489   Print (
    4490     L"  PME Interrupt Enable(3):                      %E%d%N\n",
     4959  ShellPrintEx (-1, -1,
     4960    L"  PME Interrupt Enable(3):                      %E%d%N\r\n",
    44914961    PCIE_CAP_PME_INT_ENABLE (PcieRootControl)
    44924962   );
    4493   Print (
    4494     L"  CRS Software Visibility Enable(4):            %E%d%N\n",
     4963  ShellPrintEx (-1, -1,
     4964    L"  CRS Software Visibility Enable(4):            %E%d%N\r\n",
    44954965    PCIE_CAP_CRS_SW_VIS_ENABLE (PcieRootControl)
    44964966   );
     
    45084978EFI_STATUS
    45094979ExplainPcieRootCap (
    4510   IN PCIE_CAP_STURCTURE *PciExpressCap
     4980  IN PCIE_CAP_STRUCTURE *PciExpressCap
    45114981  )
    45124982{
     
    45154985  PcieRootCap = PciExpressCap->RsvdP;
    45164986
    4517   Print (
    4518     L"  CRS Software Visibility(0):                   %E%d%N\n",
     4987  ShellPrintEx (-1, -1,
     4988    L"  CRS Software Visibility(0):                   %E%d%N\r\n",
    45194989    PCIE_CAP_CRS_SW_VIS (PcieRootCap)
    45204990   );
     
    45325002EFI_STATUS
    45335003ExplainPcieRootStatus (
    4534   IN PCIE_CAP_STURCTURE *PciExpressCap
     5004  IN PCIE_CAP_STRUCTURE *PciExpressCap
    45355005  )
    45365006{
     
    45395009  PcieRootStatus = PciExpressCap->RootStatus;
    45405010
    4541   Print (
    4542     L"  PME Requester ID(15:0):                       %E0x%04x%N\n",
     5011  ShellPrintEx (-1, -1,
     5012    L"  PME Requester ID(15:0):                       %E0x%04x%N\r\n",
    45435013    PCIE_CAP_PME_REQ_ID (PcieRootStatus)
    45445014   );
    4545   Print (
    4546     L"  PME Status(16):                               %E%d%N\n",
     5015  ShellPrintEx (-1, -1,
     5016    L"  PME Status(16):                               %E%d%N\r\n",
    45475017    PCIE_CAP_PME_STATUS (PcieRootStatus)
    45485018   );
    4549   Print (
    4550     L"  PME Pending(17):                              %E%d%N\n",
     5019  ShellPrintEx (-1, -1,
     5020    L"  PME Pending(17):                              %E%d%N\r\n",
    45515021    PCIE_CAP_PME_PENDING (PcieRootStatus)
    45525022   );
    45535023  return EFI_SUCCESS;
     5024}
     5025
     5026/**
     5027  Function to interpret and print out the link control structure
     5028
     5029  @param[in] HeaderAddress        The Address of this capability header.
     5030  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5031**/
     5032EFI_STATUS
     5033EFIAPI
     5034PrintInterpretedExtendedCompatibilityLinkControl (
     5035  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5036  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5037  )
     5038{
     5039  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_INTERNAL_LINK_CONTROL *Header;
     5040  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_INTERNAL_LINK_CONTROL*)HeaderAddress;
     5041
     5042  ShellPrintHiiEx(
     5043    -1, -1, NULL,
     5044    STRING_TOKEN (STR_PCI_EXT_CAP_LINK_CONTROL),
     5045    gShellDebug1HiiHandle,
     5046    Header->RootComplexLinkCapabilities,
     5047    Header->RootComplexLinkControl,
     5048    Header->RootComplexLinkStatus
     5049    );
     5050  DumpHex (
     5051    4,
     5052    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5053    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_INTERNAL_LINK_CONTROL),
     5054    (VOID *) (HeaderAddress)
     5055    );
     5056  return (EFI_SUCCESS);
     5057}
     5058
     5059/**
     5060  Function to interpret and print out the power budgeting structure
     5061
     5062  @param[in] HeaderAddress        The Address of this capability header.
     5063  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5064**/
     5065EFI_STATUS
     5066EFIAPI
     5067PrintInterpretedExtendedCompatibilityPowerBudgeting (
     5068  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5069  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5070  )
     5071{
     5072  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_POWER_BUDGETING *Header;
     5073  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_POWER_BUDGETING*)HeaderAddress;
     5074
     5075  ShellPrintHiiEx(
     5076    -1, -1, NULL,
     5077    STRING_TOKEN (STR_PCI_EXT_CAP_POWER),
     5078    gShellDebug1HiiHandle,
     5079    Header->DataSelect,
     5080    Header->Data,
     5081    Header->PowerBudgetCapability
     5082    );
     5083  DumpHex (
     5084    4,
     5085    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5086    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_POWER_BUDGETING),
     5087    (VOID *) (HeaderAddress)
     5088    );
     5089  return (EFI_SUCCESS);
     5090}
     5091
     5092/**
     5093  Function to interpret and print out the ACS structure
     5094
     5095  @param[in] HeaderAddress        The Address of this capability header.
     5096  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5097**/
     5098EFI_STATUS
     5099EFIAPI
     5100PrintInterpretedExtendedCompatibilityAcs (
     5101  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5102  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5103  )
     5104{
     5105  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_ACS_EXTENDED  *Header;
     5106  UINT16                                                VectorSize;
     5107  UINT16                                                LoopCounter;
     5108
     5109  Header      = (PCI_EXPRESS_EXTENDED_CAPABILITIES_ACS_EXTENDED*)HeaderAddress;
     5110  VectorSize  = 0;
     5111
     5112  ShellPrintHiiEx(
     5113    -1, -1, NULL,
     5114    STRING_TOKEN (STR_PCI_EXT_CAP_ACS),
     5115    gShellDebug1HiiHandle,
     5116    Header->AcsCapability,
     5117    Header->AcsControl
     5118    );
     5119  if (PCI_EXPRESS_EXTENDED_CAPABILITY_ACS_EXTENDED_GET_EGRES_CONTROL(Header)) {
     5120    VectorSize = PCI_EXPRESS_EXTENDED_CAPABILITY_ACS_EXTENDED_GET_EGRES_VECTOR_SIZE(Header);
     5121    if (VectorSize == 0) {
     5122      VectorSize = 256;
     5123    }
     5124    for (LoopCounter = 0 ; LoopCounter * 8 < VectorSize ; LoopCounter++) {
     5125      ShellPrintHiiEx(
     5126        -1, -1, NULL,
     5127        STRING_TOKEN (STR_PCI_EXT_CAP_ACS2),
     5128        gShellDebug1HiiHandle,
     5129        LoopCounter + 1,
     5130        Header->EgressControlVectorArray[LoopCounter]
     5131        );
     5132    }
     5133  }
     5134  DumpHex (
     5135    4,
     5136    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5137    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_ACS_EXTENDED) + (VectorSize / 8) - 1,
     5138    (VOID *) (HeaderAddress)
     5139    );
     5140  return (EFI_SUCCESS);
     5141}
     5142
     5143/**
     5144  Function to interpret and print out the latency tolerance reporting structure
     5145
     5146  @param[in] HeaderAddress        The Address of this capability header.
     5147  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5148**/
     5149EFI_STATUS
     5150EFIAPI
     5151PrintInterpretedExtendedCompatibilityLatencyToleranceReporting (
     5152  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5153  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5154  )
     5155{
     5156  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_LATENCE_TOLERANCE_REPORTING *Header;
     5157  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_LATENCE_TOLERANCE_REPORTING*)HeaderAddress;
     5158
     5159  ShellPrintHiiEx(
     5160    -1, -1, NULL,
     5161    STRING_TOKEN (STR_PCI_EXT_CAP_LAT),
     5162    gShellDebug1HiiHandle,
     5163    Header->MaxSnoopLatency,
     5164    Header->MaxNoSnoopLatency
     5165    );
     5166  DumpHex (
     5167    4,
     5168    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5169    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_LATENCE_TOLERANCE_REPORTING),
     5170    (VOID *) (HeaderAddress)
     5171    );
     5172  return (EFI_SUCCESS);
     5173}
     5174
     5175/**
     5176  Function to interpret and print out the serial number structure
     5177
     5178  @param[in] HeaderAddress        The Address of this capability header.
     5179  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5180**/
     5181EFI_STATUS
     5182EFIAPI
     5183PrintInterpretedExtendedCompatibilitySerialNumber (
     5184  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5185  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5186  )
     5187{
     5188  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_SERIAL_NUMBER *Header;
     5189  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_SERIAL_NUMBER*)HeaderAddress;
     5190
     5191  ShellPrintHiiEx(
     5192    -1, -1, NULL,
     5193    STRING_TOKEN (STR_PCI_EXT_CAP_SN),
     5194    gShellDebug1HiiHandle,
     5195    Header->SerialNumber
     5196    );
     5197  DumpHex (
     5198    4,
     5199    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5200    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_SERIAL_NUMBER),
     5201    (VOID *) (HeaderAddress)
     5202    );
     5203  return (EFI_SUCCESS);
     5204}
     5205
     5206/**
     5207  Function to interpret and print out the RCRB structure
     5208
     5209  @param[in] HeaderAddress        The Address of this capability header.
     5210  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5211**/
     5212EFI_STATUS
     5213EFIAPI
     5214PrintInterpretedExtendedCompatibilityRcrb (
     5215  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5216  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5217  )
     5218{
     5219  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_RCRB_HEADER *Header;
     5220  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_RCRB_HEADER*)HeaderAddress;
     5221
     5222  ShellPrintHiiEx(
     5223    -1, -1, NULL,
     5224    STRING_TOKEN (STR_PCI_EXT_CAP_RCRB),
     5225    gShellDebug1HiiHandle,
     5226    Header->VendorId,
     5227    Header->DeviceId,
     5228    Header->RcrbCapabilities,
     5229    Header->RcrbControl
     5230    );
     5231  DumpHex (
     5232    4,
     5233    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5234    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_RCRB_HEADER),
     5235    (VOID *) (HeaderAddress)
     5236    );
     5237  return (EFI_SUCCESS);
     5238}
     5239
     5240/**
     5241  Function to interpret and print out the vendor specific structure
     5242
     5243  @param[in] HeaderAddress        The Address of this capability header.
     5244  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5245**/
     5246EFI_STATUS
     5247EFIAPI
     5248PrintInterpretedExtendedCompatibilityVendorSpecific (
     5249  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5250  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5251  )
     5252{
     5253  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_VENDOR_SPECIFIC *Header;
     5254  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_VENDOR_SPECIFIC*)HeaderAddress;
     5255
     5256  ShellPrintHiiEx(
     5257    -1, -1, NULL,
     5258    STRING_TOKEN (STR_PCI_EXT_CAP_VEN),
     5259    gShellDebug1HiiHandle,
     5260    Header->VendorSpecificHeader
     5261    );
     5262  DumpHex (
     5263    4,
     5264    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5265    PCI_EXPRESS_EXTENDED_CAPABILITY_VENDOR_SPECIFIC_GET_SIZE(Header),
     5266    (VOID *) (HeaderAddress)
     5267    );
     5268  return (EFI_SUCCESS);
     5269}
     5270
     5271/**
     5272  Function to interpret and print out the Event Collector Endpoint Association structure
     5273
     5274  @param[in] HeaderAddress        The Address of this capability header.
     5275  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5276**/
     5277EFI_STATUS
     5278EFIAPI
     5279PrintInterpretedExtendedCompatibilityECEA (
     5280  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5281  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5282  )
     5283{
     5284  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_EVENT_COLLECTOR_ENDPOINT_ASSOCIATION *Header;
     5285  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_EVENT_COLLECTOR_ENDPOINT_ASSOCIATION*)HeaderAddress;
     5286
     5287  ShellPrintHiiEx(
     5288    -1, -1, NULL,
     5289    STRING_TOKEN (STR_PCI_EXT_CAP_ECEA),
     5290    gShellDebug1HiiHandle,
     5291    Header->AssociationBitmap
     5292    );
     5293  DumpHex (
     5294    4,
     5295    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5296    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_EVENT_COLLECTOR_ENDPOINT_ASSOCIATION),
     5297    (VOID *) (HeaderAddress)
     5298    );
     5299  return (EFI_SUCCESS);
     5300}
     5301
     5302/**
     5303  Function to interpret and print out the ARI structure
     5304
     5305  @param[in] HeaderAddress        The Address of this capability header.
     5306  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5307**/
     5308EFI_STATUS
     5309EFIAPI
     5310PrintInterpretedExtendedCompatibilityAri (
     5311  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5312  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5313  )
     5314{
     5315  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_ARI_CAPABILITY *Header;
     5316  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_ARI_CAPABILITY*)HeaderAddress;
     5317
     5318  ShellPrintHiiEx(
     5319    -1, -1, NULL,
     5320    STRING_TOKEN (STR_PCI_EXT_CAP_ARI),
     5321    gShellDebug1HiiHandle,
     5322    Header->AriCapability,
     5323    Header->AriControl
     5324    );
     5325  DumpHex (
     5326    4,
     5327    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5328    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_ARI_CAPABILITY),
     5329    (VOID *) (HeaderAddress)
     5330    );
     5331  return (EFI_SUCCESS);
     5332}
     5333
     5334/**
     5335  Function to interpret and print out the DPA structure
     5336
     5337  @param[in] HeaderAddress        The Address of this capability header.
     5338  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5339**/
     5340EFI_STATUS
     5341EFIAPI
     5342PrintInterpretedExtendedCompatibilityDynamicPowerAllocation (
     5343  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5344  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5345  )
     5346{
     5347  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_DYNAMIC_POWER_ALLOCATION *Header;
     5348  UINT8                                                            LinkCount;
     5349  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_DYNAMIC_POWER_ALLOCATION*)HeaderAddress;
     5350
     5351  ShellPrintHiiEx(
     5352    -1, -1, NULL,
     5353    STRING_TOKEN (STR_PCI_EXT_CAP_DPA),
     5354    gShellDebug1HiiHandle,
     5355    Header->DpaCapability,
     5356    Header->DpaLatencyIndicator,
     5357    Header->DpaStatus,
     5358    Header->DpaControl
     5359    );
     5360  for (LinkCount = 0 ; LinkCount < PCI_EXPRESS_EXTENDED_CAPABILITY_DYNAMIC_POWER_ALLOCATION_GET_SUBSTATE_MAX(Header) + 1 ; LinkCount++) {
     5361    ShellPrintHiiEx(
     5362      -1, -1, NULL,
     5363      STRING_TOKEN (STR_PCI_EXT_CAP_DPA2),
     5364      gShellDebug1HiiHandle,
     5365      LinkCount+1,
     5366      Header->DpaPowerAllocationArray[LinkCount]
     5367      );
     5368  }
     5369  DumpHex (
     5370    4,
     5371    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5372    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_DYNAMIC_POWER_ALLOCATION) - 1 + PCI_EXPRESS_EXTENDED_CAPABILITY_DYNAMIC_POWER_ALLOCATION_GET_SUBSTATE_MAX(Header),
     5373    (VOID *) (HeaderAddress)
     5374    );
     5375  return (EFI_SUCCESS);
     5376}
     5377
     5378/**
     5379  Function to interpret and print out the link declaration structure
     5380
     5381  @param[in] HeaderAddress        The Address of this capability header.
     5382  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5383**/
     5384EFI_STATUS
     5385EFIAPI
     5386PrintInterpretedExtendedCompatibilityLinkDeclaration (
     5387  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5388  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5389  )
     5390{
     5391  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_LINK_DECLARATION  *Header;
     5392  UINT8                                                     LinkCount;
     5393  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_LINK_DECLARATION*)HeaderAddress;
     5394
     5395  ShellPrintHiiEx(
     5396    -1, -1, NULL,
     5397    STRING_TOKEN (STR_PCI_EXT_CAP_LINK_DECLAR),
     5398    gShellDebug1HiiHandle,
     5399    Header->ElementSelfDescription
     5400    );
     5401
     5402  for (LinkCount = 0 ; LinkCount < PCI_EXPRESS_EXTENDED_CAPABILITY_LINK_DECLARATION_GET_LINK_COUNT(Header) ; LinkCount++) {
     5403    ShellPrintHiiEx(
     5404      -1, -1, NULL,
     5405      STRING_TOKEN (STR_PCI_EXT_CAP_LINK_DECLAR2),
     5406      gShellDebug1HiiHandle,
     5407      LinkCount+1,
     5408      Header->LinkEntry[LinkCount]
     5409      );
     5410  }
     5411  DumpHex (
     5412    4,
     5413    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5414    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_LINK_DECLARATION) + (PCI_EXPRESS_EXTENDED_CAPABILITY_LINK_DECLARATION_GET_LINK_COUNT(Header)-1)*sizeof(UINT32),
     5415    (VOID *) (HeaderAddress)
     5416    );
     5417  return (EFI_SUCCESS);
     5418}
     5419
     5420/**
     5421  Function to interpret and print out the Advanced Error Reporting structure
     5422
     5423  @param[in] HeaderAddress        The Address of this capability header.
     5424  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5425**/
     5426EFI_STATUS
     5427EFIAPI
     5428PrintInterpretedExtendedCompatibilityAer (
     5429  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5430  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5431  )
     5432{
     5433  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_ADVANCED_ERROR_REPORTING *Header;
     5434  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_ADVANCED_ERROR_REPORTING*)HeaderAddress;
     5435
     5436  ShellPrintHiiEx(
     5437    -1, -1, NULL,
     5438    STRING_TOKEN (STR_PCI_EXT_CAP_AER),
     5439    gShellDebug1HiiHandle,
     5440    Header->UncorrectableErrorStatus,
     5441    Header->UncorrectableErrorMask,
     5442    Header->UncorrectableErrorSeverity,
     5443    Header->CorrectableErrorStatus,
     5444    Header->CorrectableErrorMask,
     5445    Header->AdvancedErrorCapabilitiesAndControl,
     5446    Header->HeaderLog,
     5447    Header->RootErrorCommand,
     5448    Header->RootErrorStatus,
     5449    Header->ErrorSourceIdentification,
     5450    Header->CorrectableErrorSourceIdentification,
     5451    Header->TlpPrefixLog[0],
     5452    Header->TlpPrefixLog[1],
     5453    Header->TlpPrefixLog[2],
     5454    Header->TlpPrefixLog[3]
     5455    );
     5456  DumpHex (
     5457    4,
     5458    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5459    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_ADVANCED_ERROR_REPORTING),
     5460    (VOID *) (HeaderAddress)
     5461    );
     5462  return (EFI_SUCCESS);
     5463}
     5464
     5465/**
     5466  Function to interpret and print out the multicast structure
     5467
     5468  @param[in] HeaderAddress        The Address of this capability header.
     5469  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5470  @param[in] PciExpressCapPtr     The address of the PCIe capabilities structure.
     5471**/
     5472EFI_STATUS
     5473EFIAPI
     5474PrintInterpretedExtendedCompatibilityMulticast (
     5475  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5476  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress,
     5477  IN CONST PCIE_CAP_STRUCTURE *PciExpressCapPtr
     5478  )
     5479{
     5480  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_MULTICAST *Header;
     5481  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_MULTICAST*)HeaderAddress;
     5482
     5483  ShellPrintHiiEx(
     5484    -1, -1, NULL,
     5485    STRING_TOKEN (STR_PCI_EXT_CAP_MULTICAST),
     5486    gShellDebug1HiiHandle,
     5487    Header->MultiCastCapability,
     5488    Header->MulticastControl,
     5489    Header->McBaseAddress,
     5490    Header->McReceiveAddress,
     5491    Header->McBlockAll,
     5492    Header->McBlockUntranslated,
     5493    Header->McOverlayBar
     5494    );
     5495
     5496  DumpHex (
     5497    4,
     5498    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5499    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_MULTICAST),
     5500    (VOID *) (HeaderAddress)
     5501    );
     5502
     5503  return (EFI_SUCCESS);
     5504}
     5505
     5506/**
     5507  Function to interpret and print out the virtual channel and multi virtual channel structure
     5508
     5509  @param[in] HeaderAddress        The Address of this capability header.
     5510  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5511**/
     5512EFI_STATUS
     5513EFIAPI
     5514PrintInterpretedExtendedCompatibilityVirtualChannel (
     5515  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5516  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5517  )
     5518{
     5519  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_CAPABILITY  *Header;
     5520  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_VC          *CapabilityItem;
     5521  UINT32                                                              ItemCount;
     5522  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_CAPABILITY*)HeaderAddress;
     5523
     5524  ShellPrintHiiEx(
     5525    -1, -1, NULL,
     5526    STRING_TOKEN (STR_PCI_EXT_CAP_VC_BASE),
     5527    gShellDebug1HiiHandle,
     5528    Header->ExtendedVcCount,
     5529    Header->PortVcCapability1,
     5530    Header->PortVcCapability2,
     5531    Header->VcArbTableOffset,
     5532    Header->PortVcControl,
     5533    Header->PortVcStatus
     5534    );
     5535  for (ItemCount = 0 ; ItemCount < Header->ExtendedVcCount ; ItemCount++) {
     5536    CapabilityItem = &Header->Capability[ItemCount];
     5537    ShellPrintHiiEx(
     5538      -1, -1, NULL,
     5539      STRING_TOKEN (STR_PCI_EXT_CAP_VC_ITEM),
     5540      gShellDebug1HiiHandle,
     5541      ItemCount+1,
     5542      CapabilityItem->VcResourceCapability,
     5543      CapabilityItem->PortArbTableOffset,
     5544      CapabilityItem->VcResourceControl,
     5545      CapabilityItem->VcResourceStatus
     5546      );
     5547  }
     5548
     5549  DumpHex (
     5550    4,
     5551    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5552    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_VC) + (Header->ExtendedVcCount - 1) * sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_CAPABILITY),
     5553    (VOID *) (HeaderAddress)
     5554    );
     5555
     5556  return (EFI_SUCCESS);
     5557}
     5558
     5559/**
     5560  Function to interpret and print out the resizeable bar structure
     5561
     5562  @param[in] HeaderAddress        The Address of this capability header.
     5563  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5564**/
     5565EFI_STATUS
     5566EFIAPI
     5567PrintInterpretedExtendedCompatibilityResizeableBar (
     5568  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5569  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5570  )
     5571{
     5572  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR        *Header;
     5573  UINT32                                                       ItemCount;
     5574  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR*)HeaderAddress;
     5575
     5576  for (ItemCount = 0 ; ItemCount < (UINT32)GET_NUMBER_RESIZABLE_BARS(Header) ; ItemCount++) {
     5577    ShellPrintHiiEx(
     5578      -1, -1, NULL,
     5579      STRING_TOKEN (STR_PCI_EXT_CAP_RESIZE_BAR),
     5580      gShellDebug1HiiHandle,
     5581      ItemCount+1,
     5582      Header->Capability[ItemCount].ResizableBarCapability,
     5583      Header->Capability[ItemCount].ResizableBarControl
     5584      );
     5585  }
     5586
     5587  DumpHex (
     5588    4,
     5589    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5590    (UINT32)GET_NUMBER_RESIZABLE_BARS(Header) * sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_ENTRY),
     5591    (VOID *) (HeaderAddress)
     5592    );
     5593
     5594  return (EFI_SUCCESS);
     5595}
     5596
     5597/**
     5598  Function to interpret and print out the TPH structure
     5599
     5600  @param[in] HeaderAddress        The Address of this capability header.
     5601  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5602**/
     5603EFI_STATUS
     5604EFIAPI
     5605PrintInterpretedExtendedCompatibilityTph (
     5606  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5607  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress
     5608  )
     5609{
     5610  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_TPH *Header;
     5611  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_TPH*)HeaderAddress;
     5612
     5613  ShellPrintHiiEx(
     5614    -1, -1, NULL,
     5615    STRING_TOKEN (STR_PCI_EXT_CAP_TPH),
     5616    gShellDebug1HiiHandle,
     5617    Header->TphRequesterCapability,
     5618    Header->TphRequesterControl
     5619    );
     5620  DumpHex (
     5621    8,
     5622    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)Header->TphStTable - (UINT8*)HeadersBaseAddress),
     5623    GET_TPH_TABLE_SIZE(Header),
     5624    (VOID *)Header->TphStTable
     5625    );
     5626
     5627  DumpHex (
     5628    4,
     5629    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5630    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_TPH) + GET_TPH_TABLE_SIZE(Header) - sizeof(UINT16),
     5631    (VOID *) (HeaderAddress)
     5632    );
     5633
     5634  return (EFI_SUCCESS);
     5635}
     5636
     5637/**
     5638  Function to interpret and print out the secondary PCIe capability structure
     5639
     5640  @param[in] HeaderAddress        The Address of this capability header.
     5641  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5642  @param[in] PciExpressCapPtr     The address of the PCIe capabilities structure.
     5643**/
     5644EFI_STATUS
     5645EFIAPI
     5646PrintInterpretedExtendedCompatibilitySecondary (
     5647  IN CONST PCI_EXP_EXT_HDR *HeaderAddress,
     5648  IN CONST PCI_EXP_EXT_HDR *HeadersBaseAddress,
     5649  IN CONST PCIE_CAP_STRUCTURE *PciExpressCapPtr
     5650  )
     5651{
     5652  CONST PCI_EXPRESS_EXTENDED_CAPABILITIES_SECONDARY_PCIE *Header;
     5653  Header = (PCI_EXPRESS_EXTENDED_CAPABILITIES_SECONDARY_PCIE*)HeaderAddress;
     5654
     5655  ShellPrintHiiEx(
     5656    -1, -1, NULL,
     5657    STRING_TOKEN (STR_PCI_EXT_CAP_SECONDARY),
     5658    gShellDebug1HiiHandle,
     5659    Header->LinkControl3,
     5660    Header->LaneErrorStatus
     5661    );
     5662  DumpHex (
     5663    8,
     5664    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)Header->EqualizationControl - (UINT8*)HeadersBaseAddress),
     5665    PCIE_CAP_MAX_LINK_WIDTH(PciExpressCapPtr->LinkCap),
     5666    (VOID *)Header->EqualizationControl
     5667    );
     5668
     5669  DumpHex (
     5670    4,
     5671    EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8*)HeaderAddress - (UINT8*)HeadersBaseAddress),
     5672    sizeof(PCI_EXPRESS_EXTENDED_CAPABILITIES_TPH) - sizeof(Header->EqualizationControl) + PCIE_CAP_MAX_LINK_WIDTH(PciExpressCapPtr->LinkCap),
     5673    (VOID *) (HeaderAddress)
     5674    );
     5675
     5676  return (EFI_SUCCESS);
     5677}
     5678
     5679/**
     5680  Display Pcie extended capability details
     5681
     5682  @param[in] HeadersBaseAddress   The address of all the extended capability headers.
     5683  @param[in] HeaderAddress        The address of this capability header.
     5684  @param[in] PciExpressCapPtr     The address of the PCIe capabilities structure.
     5685**/
     5686EFI_STATUS
     5687EFIAPI
     5688PrintPciExtendedCapabilityDetails(
     5689  IN CONST PCI_EXP_EXT_HDR    *HeadersBaseAddress,
     5690  IN CONST PCI_EXP_EXT_HDR    *HeaderAddress,
     5691  IN CONST PCIE_CAP_STRUCTURE *PciExpressCapPtr
     5692  )
     5693{
     5694  switch (HeaderAddress->CapabilityId){
     5695    case PCI_EXPRESS_EXTENDED_CAPABILITY_ADVANCED_ERROR_REPORTING_ID:
     5696      return PrintInterpretedExtendedCompatibilityAer(HeaderAddress, HeadersBaseAddress);
     5697    case PCI_EXPRESS_EXTENDED_CAPABILITY_LINK_CONTROL_ID:
     5698      return PrintInterpretedExtendedCompatibilityLinkControl(HeaderAddress, HeadersBaseAddress);
     5699    case PCI_EXPRESS_EXTENDED_CAPABILITY_LINK_DECLARATION_ID:
     5700      return PrintInterpretedExtendedCompatibilityLinkDeclaration(HeaderAddress, HeadersBaseAddress);
     5701    case PCI_EXPRESS_EXTENDED_CAPABILITY_SERIAL_NUMBER_ID:
     5702      return PrintInterpretedExtendedCompatibilitySerialNumber(HeaderAddress, HeadersBaseAddress);
     5703    case PCI_EXPRESS_EXTENDED_CAPABILITY_POWER_BUDGETING_ID:
     5704      return PrintInterpretedExtendedCompatibilityPowerBudgeting(HeaderAddress, HeadersBaseAddress);
     5705    case PCI_EXPRESS_EXTENDED_CAPABILITY_ACS_EXTENDED_ID:
     5706      return PrintInterpretedExtendedCompatibilityAcs(HeaderAddress, HeadersBaseAddress);
     5707    case PCI_EXPRESS_EXTENDED_CAPABILITY_LATENCE_TOLERANCE_REPORTING_ID:
     5708      return PrintInterpretedExtendedCompatibilityLatencyToleranceReporting(HeaderAddress, HeadersBaseAddress);
     5709    case PCI_EXPRESS_EXTENDED_CAPABILITY_ARI_CAPABILITY_ID:
     5710      return PrintInterpretedExtendedCompatibilityAri(HeaderAddress, HeadersBaseAddress);
     5711    case PCI_EXPRESS_EXTENDED_CAPABILITY_RCRB_HEADER_ID:
     5712      return PrintInterpretedExtendedCompatibilityRcrb(HeaderAddress, HeadersBaseAddress);
     5713    case PCI_EXPRESS_EXTENDED_CAPABILITY_VENDOR_SPECIFIC_ID:
     5714      return PrintInterpretedExtendedCompatibilityVendorSpecific(HeaderAddress, HeadersBaseAddress);
     5715    case PCI_EXPRESS_EXTENDED_CAPABILITY_DYNAMIC_POWER_ALLOCATION_ID:
     5716      return PrintInterpretedExtendedCompatibilityDynamicPowerAllocation(HeaderAddress, HeadersBaseAddress);
     5717    case PCI_EXPRESS_EXTENDED_CAPABILITY_EVENT_COLLECTOR_ENDPOINT_ASSOCIATION_ID:
     5718      return PrintInterpretedExtendedCompatibilityECEA(HeaderAddress, HeadersBaseAddress);
     5719    case PCI_EXPRESS_EXTENDED_CAPABILITY_VIRTUAL_CHANNEL_ID:
     5720    case PCI_EXPRESS_EXTENDED_CAPABILITY_MULTI_FUNCTION_VIRTUAL_CHANNEL_ID:
     5721      return PrintInterpretedExtendedCompatibilityVirtualChannel(HeaderAddress, HeadersBaseAddress);
     5722    case PCI_EXPRESS_EXTENDED_CAPABILITY_MULTICAST_ID:
     5723      //
     5724      // should only be present if PCIE_CAP_DEVICEPORT_TYPE(PciExpressCapPtr->PcieCapReg) == 0100b, 0101b, or 0110b
     5725      //
     5726      return PrintInterpretedExtendedCompatibilityMulticast(HeaderAddress, HeadersBaseAddress, PciExpressCapPtr);
     5727    case PCI_EXPRESS_EXTENDED_CAPABILITY_RESIZABLE_BAR_ID:
     5728      return PrintInterpretedExtendedCompatibilityResizeableBar(HeaderAddress, HeadersBaseAddress);
     5729    case PCI_EXPRESS_EXTENDED_CAPABILITY_TPH_ID:
     5730      return PrintInterpretedExtendedCompatibilityTph(HeaderAddress, HeadersBaseAddress);
     5731    case PCI_EXPRESS_EXTENDED_CAPABILITY_SECONDARY_PCIE_ID:
     5732      return PrintInterpretedExtendedCompatibilitySecondary(HeaderAddress, HeadersBaseAddress, PciExpressCapPtr);
     5733    default:
     5734      ShellPrintEx (-1, -1,
     5735        L"Unknown PCIe extended capability ID (%04xh).  No interpretation available.\r\n",
     5736        HeaderAddress->CapabilityId
     5737        );
     5738      return EFI_SUCCESS;
     5739  };
     5740
    45545741}
    45555742
     
    45605747  @param[in] Address        The Address to start at.
    45615748  @param[in] CapabilityPtr  The offset from the address to start.
     5749  @param[in] EnhancedDump   The print format for the dump data.
     5750 
    45625751**/
    45635752EFI_STATUS
     
    45655754  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL         *IoDev,
    45665755  IN  UINT64                                  Address,
    4567   IN  UINT8                                   CapabilityPtr
     5756  IN  UINT8                                   CapabilityPtr,
     5757  IN CONST UINT16                            EnhancedDump
    45685758  )
    45695759{
    45705760
    4571   PCIE_CAP_STURCTURE  PciExpressCap;
     5761  PCIE_CAP_STRUCTURE  PciExpressCap;
    45725762  EFI_STATUS          Status;
    45735763  UINT64              CapRegAddress;
     
    45825772  UINT8               *RegAddr;
    45835773  UINTN               RegValue;
     5774  PCI_EXP_EXT_HDR     *ExtHdr;
    45845775
    45855776  CapRegAddress = Address + CapabilityPtr;
     
    45945785  DevicePortType = (UINT8) PCIE_CAP_DEVICEPORT_TYPE (PciExpressCap.PcieCapReg);
    45955786
    4596   Print (L"\nPci Express device capability structure:\n");
     5787  ShellPrintEx (-1, -1, L"\r\nPci Express device capability structure:\r\n");
    45975788
    45985789  for (Index = 0; PcieExplainList[Index].Type < PcieExplainTypeMax; Index++) {
     
    46685859  Func          = (UINT8) (RShiftU64 (Address, 8));
    46695860
    4670   Pciex_Address = CALC_EFI_PCIEX_ADDRESS (Bus, Dev, Func, 0x100);
    4671 
    4672   ExtendRegSize = 0x1000 - 0x100;
     5861  Pciex_Address = CALC_EFI_PCIEX_ADDRESS (Bus, Dev, Func, EFI_PCIE_CAPABILITY_BASE_OFFSET);
     5862
     5863  ExtendRegSize = 0x1000 - EFI_PCIE_CAPABILITY_BASE_OFFSET;
    46735864
    46745865  ExRegBuffer   = (UINT8 *) AllocateZeroPool (ExtendRegSize);
     
    46765867  //
    46775868  // PciRootBridgeIo protocol should support pci express extend space IO
    4678   // (Begins at offset 0x100)
     5869  // (Begins at offset EFI_PCIE_CAPABILITY_BASE_OFFSET)
    46795870  //
    46805871  Status = IoDev->Pci.Read (
     
    46855876                        (VOID *) (ExRegBuffer)
    46865877                       );
    4687   if (EFI_ERROR (Status)) {
    4688     FreePool ((VOID *) ExRegBuffer);
     5878  if (EFI_ERROR (Status) || ExRegBuffer == NULL) {
     5879    SHELL_FREE_NON_NULL(ExRegBuffer);
    46895880    return EFI_UNSUPPORTED;
    46905881  }
    4691   //
    4692   // Start outputing PciEx extend space( 0xFF-0xFFF)
    4693   //
    4694   Print (L"\n%HStart dumping PCIex extended configuration space (0x100 - 0xFFF).%N\n\n");
    4695 
    4696   if (ExRegBuffer != NULL) {
     5882
     5883  if (EnhancedDump == 0) {
     5884    //
     5885    // Print the PciEx extend space in raw bytes ( 0xFF-0xFFF)
     5886    //
     5887    ShellPrintEx (-1, -1, L"\r\n%HStart dumping PCIex extended configuration space (0x100 - 0xFFF).%N\r\n\r\n");
     5888
    46975889    DumpHex (
    46985890      2,
    4699       0x100,
     5891      EFI_PCIE_CAPABILITY_BASE_OFFSET,
    47005892      ExtendRegSize,
    47015893      (VOID *) (ExRegBuffer)
    4702      );
    4703 
    4704     FreePool ((VOID *) ExRegBuffer);
    4705   }
     5894      );
     5895  } else {
     5896    ExtHdr = (PCI_EXP_EXT_HDR*)ExRegBuffer;
     5897    while (ExtHdr->CapabilityId != 0 && ExtHdr->CapabilityVersion != 0) {
     5898      //
     5899      // Process this item
     5900      //
     5901      if (EnhancedDump == 0xFFFF || EnhancedDump == ExtHdr->CapabilityId) {
     5902        //
     5903        // Print this item
     5904        //
     5905        PrintPciExtendedCapabilityDetails((PCI_EXP_EXT_HDR*)ExRegBuffer, ExtHdr, &PciExpressCap);
     5906      }
     5907
     5908      //
     5909      // Advance to the next item if it exists
     5910      //
     5911      if (ExtHdr->NextCapabilityOffset != 0) {
     5912        ExtHdr = (PCI_EXP_EXT_HDR*)((UINT8*)ExRegBuffer + ExtHdr->NextCapabilityOffset);
     5913      } else {
     5914        break;
     5915      }
     5916    }
     5917  }
     5918  SHELL_FREE_NON_NULL(ExRegBuffer);
    47065919
    47075920Done:
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/Pci.h

    r48674 r58459  
    22  Header file for Pci shell Debug1 function.
    33
     4  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
    45  Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
     
    158159// Link Capabilities Register
    159160//
    160 #define PCIE_CAP_SUP_LINK_SPEEDS(PcieLinkCap) \
     161#define PCIE_CAP_MAX_LINK_SPEED(PcieLinkCap) \
    161162    ((PcieLinkCap) & 0x0f)
    162163#define PCIE_CAP_MAX_LINK_WIDTH(PcieLinkCap) \
     
    453454  UINT16  SlotControl;
    454455  UINT16  SlotStatus;
     456  UINT16  RootControl;
    455457  UINT16  RsvdP;
    456   UINT16  RootControl;
    457458  UINT32  RootStatus;
    458 } PCIE_CAP_STURCTURE;
     459} PCIE_CAP_STRUCTURE;
    459460
    460461#pragma pack()
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c

    r48674 r58459  
    22  Main file for SetVar shell Debug1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    5050  UINTN               LoopVar;
    5151  EFI_DEVICE_PATH_PROTOCOL           *DevPath;
    52   EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *DevPathFromText;
    5352
    5453  ShellStatus         = SHELL_SUCCESS;
     
    141140        }
    142141        if (ShellCommandLineGetFlag(Package, L"-rt")) {
    143           Attributes |= EFI_VARIABLE_RUNTIME_ACCESS;
     142          Attributes |= EFI_VARIABLE_RUNTIME_ACCESS |
     143                        EFI_VARIABLE_BOOTSERVICE_ACCESS;
    144144        }
    145145        if (ShellCommandLineGetFlag(Package, L"-nv")) {
     
    178178            Buffer = AllocateZeroPool(Size);
    179179            Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes2, &Size, Buffer);
    180             FreePool(Buffer);
     180            if (Buffer != NULL) {
     181              FreePool(Buffer);
     182            }
    181183            Attributes = Attributes2;
    182184          }         
     
    227229          Data++;
    228230          Data++;
    229           Status = gBS->LocateProtocol(&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID**)&DevPathFromText);
    230           ASSERT_EFI_ERROR(Status);
    231           DevPath = DevPathFromText->ConvertTextToDevicePath(Data);
     231          DevPath = ConvertTextToDevicePath(Data);
    232232          if (DevPath == NULL) {
    233233            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_DPFT), gShellDebug1HiiHandle, Status);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/LibSmbiosView.c

    r48674 r58459  
    22  API for SMBIOS table.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1616#include "../UefiShellDebug1CommandsLib.h"
    1717#include <Guid/SmBios.h>
    18 #include "LibSmbios.h"
    1918#include "LibSmbiosView.h"
    2019#include "SmbiosView.h"
    2120
    2221STATIC UINT8                    mInit         = 0;
    23 STATIC SMBIOS_STRUCTURE_TABLE  *mSmbiosTable = NULL;
     22STATIC SMBIOS_TABLE_ENTRY_POINT *mSmbiosTable = NULL;
    2423STATIC SMBIOS_STRUCTURE_POINTER m_SmbiosStruct;
    2524STATIC SMBIOS_STRUCTURE_POINTER *mSmbiosStruct = &m_SmbiosStruct;
     
    9190VOID
    9291LibSmbiosGetEPS (
    93   OUT SMBIOS_STRUCTURE_TABLE **EntryPointStructure
     92  OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure
    9493  )
    9594{
     
    101100
    102101/**
    103     Get SMBIOS structure given the Handle,copy data to the Buffer,
     102  Return SMBIOS string for the given string number.
     103
     104  @param[in] Smbios         Pointer to SMBIOS structure.
     105  @param[in] StringNumber   String number to return. -1 is used to skip all strings and
     106                            point to the next SMBIOS structure.
     107
     108  @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
     109**/
     110CHAR8*
     111LibGetSmbiosString (
     112  IN  SMBIOS_STRUCTURE_POINTER    *Smbios,
     113  IN  UINT16                      StringNumber
     114  )
     115{
     116  UINT16  Index;
     117  CHAR8   *String;
     118
     119  ASSERT (Smbios != NULL);
     120
     121  //
     122  // Skip over formatted section
     123  //
     124  String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);
     125
     126  //
     127  // Look through unformated section
     128  //
     129  for (Index = 1; Index <= StringNumber; Index++) {
     130    if (StringNumber == Index) {
     131      return String;
     132    }
     133    //
     134    // Skip string
     135    //
     136    for (; *String != 0; String++);
     137    String++;
     138
     139    if (*String == 0) {
     140      //
     141      // If double NULL then we are done.
     142      //  Return pointer to next structure in Smbios.
     143      //  if you pass in a -1 you will always get here
     144      //
     145      Smbios->Raw = (UINT8 *)++String;
     146      return NULL;
     147    }
     148  }
     149
     150  return NULL;
     151}
     152
     153/**
     154    Get SMBIOS structure for the given Handle,
    104155    Handle is changed to the next handle or 0xFFFF when the end is
    105156    reached or the handle is not found.
     
    107158    @param[in, out] Handle     0xFFFF: get the first structure
    108159                               Others: get a structure according to this value.
    109     @param[in, out] Buffer     The pointer to the caller's memory buffer.
    110     @param[out] Length         Length of return buffer in bytes.
    111 
    112     @retval DMI_SUCCESS   Buffer contains the required structure data
    113                           Handle is updated with next structure handle or
     160    @param[out] Buffer         The pointer to the pointer to the structure.
     161    @param[out] Length         Length of the structure.
     162
     163    @retval DMI_SUCCESS   Handle is updated with next structure handle or
    114164                          0xFFFF(end-of-list).
    115165
    116     @retval DMI_INVALID_HANDLE  Buffer not contain the requiring structure data.
    117                                 Handle is updated with next structure handle or
     166    @retval DMI_INVALID_HANDLE  Handle is updated with first structure handle or
    118167                                0xFFFF(end-of-list).
    119168**/
     
    121170LibGetSmbiosStructure (
    122171  IN  OUT UINT16  *Handle,
    123   IN  OUT UINT8   *Buffer,
     172  OUT UINT8       **Buffer,
    124173  OUT UINT16      *Length
    125174  )
     
    129178  UINT8                     *Raw;
    130179
    131   if (*Handle == INVALIDE_HANDLE) {
     180  if (*Handle == INVALID_HANDLE) {
    132181    *Handle = mSmbiosStruct->Hdr->Handle;
    133182    return DMI_INVALID_HANDLE;
    134183  }
    135184
    136   if (Buffer == NULL) {
    137     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_SPEC), gShellDebug1HiiHandle);
     185  if ((Buffer == NULL) || (Length == NULL)) {
     186    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUFF_LEN_SPEC), gShellDebug1HiiHandle);
    138187    return DMI_INVALID_HANDLE;
    139188  }
     
    153202      //
    154203      *Length = (UINT16) (Smbios.Raw - Raw);
    155       CopyMem (Buffer, Raw, *Length);
     204      *Buffer = Raw;
    156205      //
    157206      // update with the next structure handle.
     
    160209        *Handle = Smbios.Hdr->Handle;
    161210      } else {
    162         *Handle = INVALIDE_HANDLE;
     211        *Handle = INVALID_HANDLE;
    163212      }
    164213      return DMI_SUCCESS;
     
    170219  }
    171220
    172   *Handle = INVALIDE_HANDLE;
     221  *Handle = INVALID_HANDLE;
    173222  return DMI_INVALID_HANDLE;
    174223}
    175224
    176 /**
    177   Check the structure to see if it is legal.
    178 
    179   @param[in] Smbios    - Pointer to the structure that will be checked.
    180 
    181   @retval DMI_SUCCESS           Structure data is legal.
    182   @retval DMI_BAD_PARAMETER     Structure data contains bad parameter.
    183 **/
    184 EFI_STATUS
    185 SmbiosCheckStructure (
    186   IN  SMBIOS_STRUCTURE_POINTER *Smbios
    187   )
    188 {
    189   //
    190   // If key != value, then error.
    191   //
    192 #define CHECK_VALUE(key, value) (((key) == (value)) ? EFI_SUCCESS : DMI_BAD_PARAMETER)
    193 
    194   EFI_STATUS  Status;
    195   //
    196   // Assume staus is EFI_SUCCESS,
    197   // but if check is error, then EFI_ERROR.
    198   //
    199   Status = EFI_SUCCESS;
    200 
    201   switch (Smbios->Hdr->Type) {
    202   case 0:
    203     break;
    204 
    205   case 1:
    206     if (Smbios->Type1->Hdr.Length == 0x08 || Smbios->Type0->Hdr.Length == 0x19) {
    207       Status = EFI_SUCCESS;
    208     } else {
    209       Status = DMI_BAD_PARAMETER;
    210     }
    211     break;
    212 
    213   case 2:
    214     Status = CHECK_VALUE (Smbios->Type2->Hdr.Length, 0x08);
    215     break;
    216 
    217   case 6:
    218     Status = CHECK_VALUE (Smbios->Type6->Hdr.Length, 0x0C);
    219     break;
    220 
    221   case 11:
    222     Status = CHECK_VALUE (Smbios->Type11->Hdr.Length, 0x05);
    223     break;
    224 
    225   case 12:
    226     Status = CHECK_VALUE (Smbios->Type12->Hdr.Length, 0x05);
    227     break;
    228 
    229   case 13:
    230     Status = CHECK_VALUE (Smbios->Type13->Hdr.Length, 0x16);
    231     break;
    232 
    233   case 16:
    234     Status = CHECK_VALUE (Smbios->Type16->Hdr.Length, 0x0F);
    235     break;
    236 
    237   case 19:
    238     Status = CHECK_VALUE (Smbios->Type19->Hdr.Length, 0x0F);
    239     break;
    240 
    241   case 20:
    242     Status = CHECK_VALUE (Smbios->Type20->Hdr.Length, 0x13);
    243     break;
    244 
    245   case 32:
    246     //
    247     // Because EFI_SUCCESS == 0,
    248     // So errors added up is also error.
    249     //
    250     Status = CHECK_VALUE (Smbios->Type32->Reserved[0], 0x00) +
    251       CHECK_VALUE (Smbios->Type32->Reserved[1], 0x00) +
    252       CHECK_VALUE (Smbios->Type32->Reserved[2], 0x00) +
    253       CHECK_VALUE (Smbios->Type32->Reserved[3], 0x00) +
    254       CHECK_VALUE (Smbios->Type32->Reserved[4], 0x00) +
    255       CHECK_VALUE (Smbios->Type32->Reserved[5], 0x00);
    256     break;
    257 
    258   default:
    259     Status = DMI_BAD_PARAMETER;
    260   }
    261 
    262   return Status;
    263 }
    264 
    265 /**
    266   Get a string from the smbios information.
    267 
    268   @param[in] Smbios         The pointer to the smbios information.
    269   @param[in] StringNumber   The index to the string to get.
    270   @param[out] Buffer        The buffer to fill with the string when retrieved.
    271 **/
    272 VOID
    273 SmbiosGetPendingString (
    274   IN  SMBIOS_STRUCTURE_POINTER      *Smbios,
    275   IN  UINT16                        StringNumber,
    276   OUT CHAR8                         *Buffer
    277   )
    278 {
    279   CHAR8 *String;
    280   if (Buffer == NULL) {
    281     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_NO_BUF_SPEC_WHEN_STRUCT), gShellDebug1HiiHandle);
    282     return ;
    283   }
    284   //
    285   // Get string and copy to buffer.
    286   // Caller should provide the buffer.
    287   //
    288   String = LibGetSmbiosString (Smbios, StringNumber);
    289   if (String != NULL) {
    290     CopyMem (Buffer, String, AsciiStrLen(String));
    291   } else {
    292     Buffer = NULL;
    293   }
    294 }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/LibSmbiosView.h

    r48674 r58459  
    22  API for SMBIOS Plug and Play functions, access to SMBIOS table and structures.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1616#define _LIB_SMBIOS_VIEW_H_
    1717
    18 #include "LibSmbios.h"
     18#include <IndustryStandard/SmBios.h>
    1919
    2020#define DMI_SUCCESS                     0x00
     
    3131#define DMI_INVALID_LOCK                0x92
    3232
    33 #define INVALIDE_HANDLE                 (UINT16) (-1)
     33#define INVALID_HANDLE                  (UINT16) (-1)
    3434
    3535#define EFI_SMBIOSERR(val)              EFIERR (0x30000 | val)
     
    6565VOID
    6666LibSmbiosGetEPS (
    67   OUT SMBIOS_STRUCTURE_TABLE **EntryPointStructure
     67  OUT SMBIOS_TABLE_ENTRY_POINT **EntryPointStructure
    6868  );
    6969
    7070/**
    71     Get SMBIOS structure given the Handle,copy data to the Buffer,
     71  Return SMBIOS string for the given string number.
     72
     73  @param[in] Smbios         Pointer to SMBIOS structure.
     74  @param[in] StringNumber   String number to return. -1 is used to skip all strings and
     75                            point to the next SMBIOS structure.
     76
     77  @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == -1
     78**/
     79CHAR8*
     80LibGetSmbiosString (
     81  IN  SMBIOS_STRUCTURE_POINTER    *Smbios,
     82  IN  UINT16                      StringNumber
     83  );
     84
     85/**
     86    Get SMBIOS structure for the given Handle,
    7287    Handle is changed to the next handle or 0xFFFF when the end is
    7388    reached or the handle is not found.
     
    7590    @param[in, out] Handle     0xFFFF: get the first structure
    7691                               Others: get a structure according to this value.
    77     @param[in, out] Buffer     The pointer to the caller's memory buffer.
    78     @param[out] Length         Length of return buffer in bytes.
     92    @param[out] Buffer         The pointer to the pointer to the structure.
     93    @param[out] Length         Length of the structure.
    7994
    80     @retval DMI_SUCCESS   Buffer contains the required structure data
    81                           Handle is updated with next structure handle or
     95    @retval DMI_SUCCESS   Handle is updated with next structure handle or
    8296                          0xFFFF(end-of-list).
    8397
    84     @retval DMI_INVALID_HANDLE  Buffer not contain the requiring structure data.
    85                                 Handle is updated with next structure handle or
     98    @retval DMI_INVALID_HANDLE  Handle is updated with first structure handle or
    8699                                0xFFFF(end-of-list).
    87100**/
     
    89102LibGetSmbiosStructure (
    90103  IN  OUT UINT16  *Handle,
    91   IN  OUT UINT8   *Buffer,
     104  OUT UINT8       **Buffer,
    92105  OUT UINT16      *Length
    93106  );
    94107
    95 /**
    96   Get a string from the smbios information.
    97 
    98   @param[in] Smbios         The pointer to the smbios information.
    99   @param[in] StringNumber   The index to the string to get.
    100   @param[out] Buffer        The buffer to fill with the string when retrieved.
    101 **/
    102 VOID
    103 SmbiosGetPendingString (
    104   IN  SMBIOS_STRUCTURE_POINTER      *Smbios,
    105   IN  UINT16                        StringNumber,
    106   OUT CHAR8                         *Buffer
    107   );
    108 
    109 /**
    110   Check the structure to see if it is legal.
    111 
    112   @param[in] Smbios    - Pointer to the structure that will be checked.
    113 
    114   @retval DMI_SUCCESS           Structure data is legal.
    115   @retval DMI_BAD_PARAMETER     Structure data contains bad parameter.
    116 **/
    117 EFI_STATUS
    118 SmbiosCheckStructure (
    119   IN  SMBIOS_STRUCTURE_POINTER *Smbios
    120   );
    121 
    122108#endif
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c

    r48674 r58459  
    22  Module for clarifying the content of the smbios structure element information.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
     5  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    2425//
    2526#define BIT(value, bit) ((value) & ((UINT64) 1) << (bit))
     27
     28//
     29// Check if above or equal to version
     30//
     31#define AE_SMBIOS_VERSION(MajorVersion, MinorVersion) \
     32  (SmbiosMajorVersion > (MajorVersion) || (SmbiosMajorVersion == (MajorVersion) && SmbiosMinorVersion >= (MinorVersion)))
    2633
    2734//
     
    3138#define PRINT_PENDING_STRING(pStruct, type, element) \
    3239  do { \
    33     CHAR8 StringBuf[64]; \
    34     SetMem (StringBuf, sizeof (StringBuf), 0x00); \
    35     SmbiosGetPendingString ((pStruct), (pStruct->type->element), StringBuf); \
     40    CHAR8 *StringBuf; \
     41    StringBuf = LibGetSmbiosString ((pStruct), (pStruct->type->element)); \
    3642    ShellPrintEx(-1,-1,L"%a",#element); \
    37     ShellPrintEx(-1,-1,L": %a\n", StringBuf); \
     43    ShellPrintEx(-1,-1,L": %a\n", (StringBuf != NULL) ? StringBuf: ""); \
    3844  } while (0);
    3945
    4046#define PRINT_SMBIOS_STRING(pStruct, stringnumber, element) \
    4147  do { \
    42     CHAR8 StringBuf[64]; \
    43     SetMem (StringBuf, sizeof (StringBuf), 0x00); \
    44     SmbiosGetPendingString ((pStruct), (stringnumber), StringBuf); \
     48    CHAR8 *StringBuf; \
     49    StringBuf = LibGetSmbiosString ((pStruct), (stringnumber)); \
    4550    ShellPrintEx(-1,-1,L"%a",#element); \
    46     ShellPrintEx(-1,-1,L": %a\n", StringBuf); \
     51    ShellPrintEx(-1,-1,L": %a\n", (StringBuf != NULL) ? StringBuf: ""); \
    4752  } while (0);
    4853
     
    5762    ShellPrintEx(-1,-1,L"%a",#element); \
    5863    ShellPrintEx(-1,-1,L": 0x%x\n", (pStruct->type->element)); \
     64  } while (0);
     65
     66#define PRINT_STRUCT_VALUE_LH(pStruct, type, element) \
     67  do { \
     68    ShellPrintEx(-1,-1,L"%a",#element); \
     69    ShellPrintEx(-1,-1,L": 0x%lx\n", (pStruct->type->element)); \
    5970  } while (0);
    6071
     
    124135VOID
    125136SmbiosPrintEPSInfo (
    126   IN  SMBIOS_STRUCTURE_TABLE  *SmbiosTable,
    127   IN  UINT8                   Option
     137  IN  SMBIOS_TABLE_ENTRY_POINT  *SmbiosTable,
     138  IN  UINT8                     Option
    128139  )
    129140{
     
    208219  UINT8 *Buffer;
    209220
    210   Buffer = (UINT8 *) (UINTN) (Struct->Raw);
    211 
    212221  if (Struct == NULL) {
    213222    return EFI_INVALID_PARAMETER;
     
    217226    return EFI_SUCCESS;
    218227  }
     228
     229  Buffer = (UINT8 *) (UINTN) (Struct->Raw);
     230
    219231  //
    220232  // Display structure header
     
    230242  switch (Struct->Hdr->Type) {
    231243  //
    232   //
     244  // BIOS Information (Type 0)
    233245  //
    234246  case 0:
     
    239251    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIOS_SIZE), gShellDebug1HiiHandle, 64 * (Struct->Type0->BiosSize + 1));
    240252
    241     if (Option < SHOW_DETAIL) {
    242       PRINT_STRUCT_VALUE_H (Struct, Type0, BiosCharacteristics);
    243     } else {
    244       DisplayBiosCharacteristics (Struct->Type0->BiosCharacteristics, Option);
    245 
    246       //
    247       // The length of above format part is 0x12 bytes,
    248       // Ext bytes are following, size = 'len-0x12'.
    249       // If len-0x12 > 0, then
    250       //    there are extension bytes (Byte1, byte2, byte3...)
    251       // And byte3 not stated in spec, so dump all extension bytes(1, 2, 3..)
    252       //
    253       if ((Buffer[1] - (CHAR8) 0x12) > 0) {
    254         DisplayBiosCharacteristicsExt1 (Buffer[0x12], Option);
    255       }
    256 
    257       if ((Buffer[1] - (CHAR8) 0x12) > 1) {
    258         DisplayBiosCharacteristicsExt2 (Buffer[0x13], Option);
    259       }
    260 
    261       if ((Buffer[1] - (CHAR8) 0x12) > 2) {
    262         PRINT_BIT_FIELD (
    263           Struct,
    264           Type0,
    265           BiosCharacteristics,
    266           Buffer[1] - (CHAR8) 0x12
    267          );
    268       }
    269     }
     253    DisplayBiosCharacteristics (ReadUnaligned64 ((UINT64 *) (UINTN) &(Struct->Type0->BiosCharacteristics)), Option);
     254
     255    if (Struct->Hdr->Length > 0x12) {
     256      DisplayBiosCharacteristicsExt1 (Struct->Type0->BIOSCharacteristicsExtensionBytes[0], Option);
     257    }
     258    if (Struct->Hdr->Length > 0x13) {
     259      DisplayBiosCharacteristicsExt2 (Struct->Type0->BIOSCharacteristicsExtensionBytes[1], Option);
     260    }
     261
     262    if (AE_SMBIOS_VERSION (0x2, 0x4) && (Struct->Hdr->Length > 0x14)) {
     263      PRINT_STRUCT_VALUE (Struct, Type0, SystemBiosMajorRelease);
     264      PRINT_STRUCT_VALUE (Struct, Type0, SystemBiosMinorRelease);
     265      PRINT_STRUCT_VALUE (Struct, Type0, EmbeddedControllerFirmwareMajorRelease);
     266      PRINT_STRUCT_VALUE (Struct, Type0, EmbeddedControllerFirmwareMinorRelease);
     267    }
     268
    270269    break;
    271270
     
    280279    PRINT_BIT_FIELD (Struct, Type1, Uuid, 16);
    281280    DisplaySystemWakeupType (Struct->Type1->WakeUpType, Option);
    282     break;
    283 
     281    if (AE_SMBIOS_VERSION (0x2, 0x4) && (Struct->Hdr->Length > 0x19)) {
     282      PRINT_PENDING_STRING (Struct, Type1, SKUNumber);
     283      PRINT_PENDING_STRING (Struct, Type1, Family);
     284    }
     285
     286    break;
     287
     288  //
     289  // Baseboard Information (Type 2)
     290  //
    284291  case 2:
    285292    PRINT_PENDING_STRING (Struct, Type2, Manufacturer);
     
    287294    PRINT_PENDING_STRING (Struct, Type2, Version);
    288295    PRINT_PENDING_STRING (Struct, Type2, SerialNumber);
     296    if (Struct->Hdr->Length > 0x8) {
     297      PRINT_PENDING_STRING (Struct, Type2, AssetTag);
     298      DisplayBaseBoardFeatureFlags (*(UINT8 *) &Struct->Type2->FeatureFlag, Option);
     299      PRINT_PENDING_STRING (Struct, Type2, LocationInChassis);
     300      PRINT_STRUCT_VALUE_H (Struct, Type2, ChassisHandle);
     301      DisplayBaseBoardBoardType (Struct->Type2->BoardType, Option);
     302    }
    289303    break;
    290304
     
    307321    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_SECURITY_STATUS), gShellDebug1HiiHandle);
    308322    DisplaySESecurityStatus (Struct->Type3->SecurityStatus, Option);
    309     PRINT_BIT_FIELD (Struct, Type3, OemDefined, 4);
     323    if (AE_SMBIOS_VERSION (0x2, 0x3) && (Struct->Hdr->Length > 0xD)) {
     324      PRINT_BIT_FIELD (Struct, Type3, OemDefined, 4);
     325    }
    310326    break;
    311327
     
    316332    PRINT_PENDING_STRING (Struct, Type4, Socket);
    317333    DisplayProcessorType (Struct->Type4->ProcessorType, Option);
    318     if ((SmbiosMajorVersion > 0x2 || (SmbiosMajorVersion == 0x2 && SmbiosMinorVersion >= 0x6)) &&
     334    if (AE_SMBIOS_VERSION (0x2, 0x6) && (Struct->Hdr->Length > 0x28) &&
    319335        (Struct->Type4->ProcessorFamily == 0xFE)) {
    320336      //
     
    328344    PRINT_BIT_FIELD (Struct, Type4, ProcessorId, 8);
    329345    PRINT_PENDING_STRING (Struct, Type4, ProcessorVersion);
    330     DisplayProcessorVoltage (Struct->Type4->Voltage, Option);
     346    DisplayProcessorVoltage (*(UINT8 *) &(Struct->Type4->Voltage), Option);
    331347    PRINT_STRUCT_VALUE (Struct, Type4, ExternalClock);
    332348    PRINT_STRUCT_VALUE (Struct, Type4, MaxSpeed);
     
    337353    PRINT_STRUCT_VALUE_H (Struct, Type4, L2CacheHandle);
    338354    PRINT_STRUCT_VALUE_H (Struct, Type4, L3CacheHandle);
    339     PRINT_PENDING_STRING (Struct, Type4, SerialNumber);
    340     PRINT_PENDING_STRING (Struct, Type4, AssetTag);
    341     PRINT_PENDING_STRING (Struct, Type4, PartNumber);
    342     if (SmbiosMajorVersion > 0x2 || (SmbiosMajorVersion == 0x2 && SmbiosMinorVersion >= 0x5)) {
     355    if (AE_SMBIOS_VERSION (0x2, 0x3) && (Struct->Hdr->Length > 0x20)) {
     356      PRINT_PENDING_STRING (Struct, Type4, SerialNumber);
     357      PRINT_PENDING_STRING (Struct, Type4, AssetTag);
     358      PRINT_PENDING_STRING (Struct, Type4, PartNumber);
     359    }
     360    if (AE_SMBIOS_VERSION (0x2, 0x5) && (Struct->Hdr->Length > 0x23)) {
    343361      PRINT_STRUCT_VALUE (Struct, Type4, CoreCount);
    344362      PRINT_STRUCT_VALUE (Struct, Type4, EnabledCoreCount);
    345363      PRINT_STRUCT_VALUE (Struct, Type4, ThreadCount);
    346       PRINT_STRUCT_VALUE_H (Struct, Type4, ProcessorCharacteristics);
     364      DisplayProcessorCharacteristics (Struct->Type4->ProcessorCharacteristics, Option);
     365    }
     366    if ((SmbiosMajorVersion >= 0x3) && (Struct->Hdr->Length > 0x2A)) {
     367      PRINT_STRUCT_VALUE (Struct, Type4, CoreCount2);
     368      PRINT_STRUCT_VALUE (Struct, Type4, EnabledCoreCount2);
     369      PRINT_STRUCT_VALUE (Struct, Type4, ThreadCount2);
    347370    }
    348371    break;
     
    357380
    358381      DisplayMcErrorDetectMethod (Struct->Type5->ErrDetectMethod, Option);
    359       DisplayMcErrorCorrectCapability (Struct->Type5->ErrCorrectCapability, Option);
     382      DisplayMcErrorCorrectCapability (*(UINT8 *) &(Struct->Type5->ErrCorrectCapability), Option);
    360383      ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_SUPOPRT), gShellDebug1HiiHandle);
    361384      DisplayMcInterleaveSupport (Struct->Type5->SupportInterleave, Option);
     
    363386      DisplayMcInterleaveSupport (Struct->Type5->CurrentInterleave, Option);
    364387      DisplayMaxMemoryModuleSize (Struct->Type5->MaxMemoryModuleSize, SlotNum, Option);
    365       DisplayMcMemorySpeeds (Struct->Type5->SupportSpeed, Option);
     388      DisplayMcMemorySpeeds (*(UINT16 *) &(Struct->Type5->SupportSpeed), Option);
    366389      DisplayMmMemoryType (Struct->Type5->SupportMemoryType, Option);
    367390      DisplayMemoryModuleVoltage (Struct->Type5->MemoryModuleVoltage, Option);
     
    382405    DisplayMmBankConnections (Struct->Type6->BankConnections, Option);
    383406    PRINT_STRUCT_VALUE (Struct, Type6, CurrentSpeed);
    384     DisplayMmMemoryType (Struct->Type6->CurrentMemoryType, Option);
     407    DisplayMmMemoryType (*(UINT16 *) &(Struct->Type6->CurrentMemoryType), Option);
    385408    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_INSTALLED), gShellDebug1HiiHandle);
    386     DisplayMmMemorySize (Struct->Type6->InstalledSize, Option);
     409    DisplayMmMemorySize (*(UINT8 *) &(Struct->Type6->InstalledSize), Option);
    387410    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_ENABLED), gShellDebug1HiiHandle);
    388     DisplayMmMemorySize (Struct->Type6->EnabledSize, Option);
     411    DisplayMmMemorySize (*(UINT8 *) &(Struct->Type6->EnabledSize), Option);
    389412    DisplayMmErrorStatus (Struct->Type6->ErrorStatus, Option);
    390413    break;
     
    395418  case 7:
    396419    PRINT_PENDING_STRING (Struct, Type7, SocketDesignation);
    397     PRINT_STRUCT_VALUE_H (Struct, Type7, CacheConfiguration);
     420    DisplayCacheConfiguration (Struct->Type7->CacheConfiguration, Option);
    398421    PRINT_STRUCT_VALUE_H (Struct, Type7, MaximumCacheSize);
    399422    PRINT_STRUCT_VALUE_H (Struct, Type7, InstalledSize);
    400423    PRINT_STRUCT_VALUE_H (Struct, Type7, SupportedSRAMType);
    401424    PRINT_STRUCT_VALUE_H (Struct, Type7, CurrentSRAMType);
    402     DisplayCacheSRAMType (Struct->Type7->CurrentSRAMType, Option);
     425    DisplayCacheSRAMType (ReadUnaligned16 ((UINT16 *) (UINTN) &(Struct->Type7->CurrentSRAMType)), Option);
    403426    PRINT_STRUCT_VALUE_H (Struct, Type7, CacheSpeed);
    404427    DisplayCacheErrCorrectingType (Struct->Type7->ErrorCorrectionType, Option);
     
    434457      Option
    435458     );
    436     DisplaySlotCharacteristics1 (Struct->Type9->SlotCharacteristics1, Option);
    437     DisplaySlotCharacteristics2 (Struct->Type9->SlotCharacteristics2, Option);
    438     if (SmbiosMajorVersion > 0x2 || (SmbiosMajorVersion == 0x2 && SmbiosMinorVersion >= 0x6)) {
     459    DisplaySlotCharacteristics1 (*(UINT8 *) &(Struct->Type9->SlotCharacteristics1), Option);
     460    DisplaySlotCharacteristics2 (*(UINT8 *) &(Struct->Type9->SlotCharacteristics2), Option);
     461    if (AE_SMBIOS_VERSION (0x2, 0x6) && (Struct->Hdr->Length > 0xD)) {
    439462      PRINT_STRUCT_VALUE_H (Struct, Type9, SegmentGroupNum);
    440463      PRINT_STRUCT_VALUE_H (Struct, Type9, BusNum);
     
    449472    {
    450473      UINTN NumOfDevice;
    451       NumOfDevice = (Struct->Type10->Hdr.Length - sizeof (SMBIOS_HEADER)) / (2 * sizeof (UINT8));
     474      NumOfDevice = (Struct->Type10->Hdr.Length - sizeof (SMBIOS_STRUCTURE)) / (2 * sizeof (UINT8));
    452475      for (Index = 0; Index < NumOfDevice; Index++) {
    453476        DisplayOnboardDeviceTypes (Struct->Type10->Device[Index].DeviceType, Option);
    454477        ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_DESC_STRING), gShellDebug1HiiHandle);
    455         ShellPrintEx(-1,-1,L"%a",LibGetSmbiosString (Struct, Struct->Type10->Device[Index].DescriptionString));
     478        ShellPrintEx(-1,-1,L"%a\n",LibGetSmbiosString (Struct, Struct->Type10->Device[Index].DescriptionString));
    456479      }
    457480    }
    458481    break;
    459482
     483  //
     484  // Oem Strings (Type 11)
     485  //
    460486  case 11:
    461487    PRINT_STRUCT_VALUE (Struct, Type11, StringCount);
     
    465491    break;
    466492
     493  //
     494  // System Configuration Options (Type 12)
     495  //
    467496  case 12:
    468497    PRINT_STRUCT_VALUE (Struct, Type12, StringCount);
     
    472501    break;
    473502
     503  //
     504  // BIOS Language Information (Type 13)
     505  //
    474506  case 13:
    475507    PRINT_STRUCT_VALUE (Struct, Type13, InstallableLanguages);
     
    479511    break;
    480512
     513  //
     514  // Group Associations (Type 14)
     515  //
    481516  case 14:
    482     PRINT_PENDING_STRING (Struct, Type14, GroupName);
    483     PRINT_STRUCT_VALUE (Struct, Type14, ItemType);
    484     PRINT_STRUCT_VALUE (Struct, Type14, ItemHandle);
     517    {
     518      UINT8 NumOfItem;
     519      NumOfItem = (Struct->Type14->Hdr.Length - 5) / 3;
     520      PRINT_PENDING_STRING (Struct, Type14, GroupName);
     521      for (Index = 0; Index < NumOfItem; Index++) {
     522        ShellPrintEx(-1,-1,L"ItemType %d: %d\n", Index + 1, Struct->Type14->Group[Index].ItemType);
     523        ShellPrintEx(-1,-1,L"ItemHandle %d: %d\n", Index + 1, Struct->Type14->Group[Index].ItemHandle);
     524      }
     525    }
    485526    break;
    486527
     
    490531  case 15:
    491532    {
    492       EVENTLOGTYPE  *Ptr;
    493       UINT8         Count;
    494       UINT8         *AccessMethodAddress;
     533      EVENT_LOG_TYPE  *Ptr;
     534      UINT8           Count;
     535      UINT8           *AccessMethodAddress;
    495536
    496537      PRINT_STRUCT_VALUE_H (Struct, Type15, LogAreaLength);
     
    557598            (UINT16)
    558599            (
    559             Struct->Type15->LogAreaLength -
    560             (Struct->Type15->LogDataStartOffset - Struct->Type15->LogDataStartOffset)
    561            )
     600              Struct->Type15->LogAreaLength -
     601              (Struct->Type15->LogDataStartOffset - Struct->Type15->LogHeaderStartOffset)
     602            )
    562603           );
    563604        }
     
    580621    PRINT_STRUCT_VALUE_H (Struct, Type16, MemoryErrorInformationHandle);
    581622    PRINT_STRUCT_VALUE_H (Struct, Type16, NumberOfMemoryDevices);
     623    if (AE_SMBIOS_VERSION (0x2, 0x7) && Struct->Hdr->Length > 0xF) {
     624      PRINT_STRUCT_VALUE_LH (Struct, Type16, ExtendedMaximumCapacity);
     625    }
    582626    break;
    583627
     
    596640    PRINT_PENDING_STRING (Struct, Type17, BankLocator);
    597641    DisplayMemoryDeviceType (Struct->Type17->MemoryType, Option);
    598     DisplayMemoryDeviceTypeDetail (Struct->Type17->TypeDetail, Option);
     642    DisplayMemoryDeviceTypeDetail (ReadUnaligned16 ((UINT16 *) (UINTN) &(Struct->Type17->TypeDetail)), Option);
    599643    PRINT_STRUCT_VALUE_H (Struct, Type17, Speed);
    600644    PRINT_PENDING_STRING (Struct, Type17, Manufacturer);
     
    602646    PRINT_PENDING_STRING (Struct, Type17, AssetTag);
    603647    PRINT_PENDING_STRING (Struct, Type17, PartNumber);
    604     if (SmbiosMajorVersion > 0x2 || (SmbiosMajorVersion == 0x2 && SmbiosMinorVersion >= 0x6)) {
     648    if (AE_SMBIOS_VERSION (0x2, 0x6) && (Struct->Hdr->Length > 0x1B)) {
    605649      PRINT_STRUCT_VALUE_H (Struct, Type17, Attributes);
     650    }
     651    if (AE_SMBIOS_VERSION (0x2, 0x7) && (Struct->Hdr->Length > 0x1C)) {
     652      PRINT_STRUCT_VALUE (Struct, Type17, ExtendedSize);
     653      PRINT_STRUCT_VALUE (Struct, Type17, ConfiguredMemoryClockSpeed);
    606654    }
    607655    break;
     
    631679    PRINT_STRUCT_VALUE_H (Struct, Type19, MemoryArrayHandle);
    632680    PRINT_STRUCT_VALUE_H (Struct, Type19, PartitionWidth);
    633     break;
    634 
    635   //
    636   // Memory Device Mapped Address  (Type 20)
     681    if (AE_SMBIOS_VERSION (0x2, 0x7) && (Struct->Hdr->Length > 0xF)) {
     682      PRINT_STRUCT_VALUE_LH (Struct, Type19, ExtendedStartingAddress);
     683      PRINT_STRUCT_VALUE_LH (Struct, Type19, ExtendedEndingAddress);
     684    }
     685    break;
     686
     687  //
     688  // Memory Device Mapped Address (Type 20)
    637689  //
    638690  case 20:
     
    644696    PRINT_STRUCT_VALUE_H (Struct, Type20, InterleavePosition);
    645697    PRINT_STRUCT_VALUE_H (Struct, Type20, InterleavedDataDepth);
    646     break;
    647 
    648   //
    649   // Built-in Pointing Device  (Type 21)
     698    if (AE_SMBIOS_VERSION (0x2, 0x7) && (Struct->Hdr->Length > 0x13)) {
     699      PRINT_STRUCT_VALUE_LH (Struct, Type19, ExtendedStartingAddress);
     700      PRINT_STRUCT_VALUE_LH (Struct, Type19, ExtendedEndingAddress);
     701    }
     702    break;
     703
     704  //
     705  // Built-in Pointing Device (Type 21)
    650706  //
    651707  case 21:
     
    656712
    657713  //
    658   // Portable Battery  (Type 22)
     714  // Portable Battery (Type 22)
    659715  //
    660716  case 22:
     
    682738    break;
    683739
     740  //
     741  // System Reset (Type 23)
     742  //
    684743  case 23:
    685744    DisplaySystemResetCapabilities (
     
    693752    break;
    694753
     754  //
     755  // Hardware Security (Type 24)
     756  //
    695757  case 24:
    696758    DisplayHardwareSecuritySettings (
     
    700762    break;
    701763
     764  //
     765  // System Power Controls (Type 25)
     766  //
    702767  case 25:
    703768    PRINT_STRUCT_VALUE_H (Struct, Type25, NextScheduledPowerOnMonth);
     
    708773    break;
    709774
     775  //
     776  // Voltage Probe (Type 26)
     777  //
    710778  case 26:
    711779    PRINT_PENDING_STRING (Struct, Type26, Description);
    712     DisplayVPLocation (Struct->Type26->LocationAndStatus, Option);
    713     DisplayVPStatus (Struct->Type26->LocationAndStatus, Option);
     780    DisplayVPLocation (*(UINT8 *) &(Struct->Type26->LocationAndStatus), Option);
     781    DisplayVPStatus (*(UINT8 *) &(Struct->Type26->LocationAndStatus), Option);
    714782    PRINT_STRUCT_VALUE_H (Struct, Type26, MaximumValue);
    715783    PRINT_STRUCT_VALUE_H (Struct, Type26, MinimumValue);
     
    721789    break;
    722790
     791  //
     792  // Cooling Device (Type 27)
     793  //
    723794  case 27:
    724795    PRINT_STRUCT_VALUE_H (Struct, Type27, TemperatureProbeHandle);
    725     DisplayCoolingDeviceStatus (Struct->Type27->DeviceTypeAndStatus, Option);
    726     DisplayCoolingDeviceType (Struct->Type27->DeviceTypeAndStatus, Option);
     796    DisplayCoolingDeviceStatus (*(UINT8 *) &(Struct->Type27->DeviceTypeAndStatus), Option);
     797    DisplayCoolingDeviceType (*(UINT8 *) &(Struct->Type27->DeviceTypeAndStatus), Option);
    727798    PRINT_STRUCT_VALUE_H (Struct, Type27, CoolingUnitGroup);
    728799    PRINT_STRUCT_VALUE_H (Struct, Type27, OEMDefined);
    729800    PRINT_STRUCT_VALUE_H (Struct, Type27, NominalSpeed);
    730     break;
    731 
     801    if (AE_SMBIOS_VERSION (0x2, 0x7) && (Struct->Hdr->Length > 0xE)) {
     802      PRINT_PENDING_STRING (Struct, Type27, Description);
     803    }
     804    break;
     805
     806  //
     807  // Temperature Probe (Type 28)
     808  //
    732809  case 28:
    733810    PRINT_PENDING_STRING (Struct, Type28, Description);
    734     DisplayTemperatureProbeStatus (Struct->Type28->LocationAndStatus, Option);
    735     DisplayTemperatureProbeLoc (Struct->Type28->LocationAndStatus, Option);
     811    DisplayTemperatureProbeStatus (*(UINT8 *) &(Struct->Type28->LocationAndStatus), Option);
     812    DisplayTemperatureProbeLoc (*(UINT8 *) &(Struct->Type28->LocationAndStatus), Option);
    736813    PRINT_STRUCT_VALUE_H (Struct, Type28, MaximumValue);
    737814    PRINT_STRUCT_VALUE_H (Struct, Type28, MinimumValue);
     
    743820    break;
    744821
     822  //
     823  // Electrical Current Probe (Type 29)
     824  //
    745825  case 29:
    746826    PRINT_PENDING_STRING (Struct, Type29, Description);
    747     DisplayECPStatus (Struct->Type29->LocationAndStatus, Option);
    748     DisplayECPLoc (Struct->Type29->LocationAndStatus, Option);
     827    DisplayECPStatus (*(UINT8 *) &(Struct->Type29->LocationAndStatus), Option);
     828    DisplayECPLoc (*(UINT8 *) &(Struct->Type29->LocationAndStatus), Option);
    749829    PRINT_STRUCT_VALUE_H (Struct, Type29, MaximumValue);
    750830    PRINT_STRUCT_VALUE_H (Struct, Type29, MinimumValue);
     
    756836    break;
    757837
     838  //
     839  // Out-of-Band Remote Access (Type 30)
     840  //
    758841  case 30:
    759842    PRINT_PENDING_STRING (Struct, Type30, ManufacturerName);
     
    761844    break;
    762845
     846  //
     847  // Boot Integrity Services (BIS) Entry Point (Type 31)
     848  //
    763849  case 31:
    764850    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_STRUCT_TYPE31), gShellDebug1HiiHandle);
    765851    break;
    766852
     853  //
     854  // System Boot Information (Type 32)
     855  //
    767856  case 32:
    768857    PRINT_BIT_FIELD (Struct, Type32, Reserved, 6);
    769     DisplaySystemBootStatus (Struct->Type32->BootStatus[0], Option);
    770     break;
    771 
     858    DisplaySystemBootStatus (Struct->Type32->BootStatus, Option);
     859    break;
     860
     861  //
     862  // 64-Bit Memory Error Information (Type 33)
     863  //
    772864  case 33:
    773865    DisplayMemoryErrorType (Struct->Type33->ErrorType, Option);
     
    778870    DisplayMemoryErrorOperation (Struct->Type33->ErrorOperation, Option);
    779871    PRINT_STRUCT_VALUE_H (Struct, Type33, VendorSyndrome);
    780     PRINT_STRUCT_VALUE_H (Struct, Type33, MemoryArrayErrorAddress);
    781     PRINT_STRUCT_VALUE_H (Struct, Type33, DeviceErrorAddress);
     872    PRINT_STRUCT_VALUE_LH (Struct, Type33, MemoryArrayErrorAddress);
     873    PRINT_STRUCT_VALUE_LH (Struct, Type33, DeviceErrorAddress);
    782874    PRINT_STRUCT_VALUE_H (Struct, Type33, ErrorResolution);
    783875    break;
    784876
    785877  //
    786   // Management Device  (Type 34)
     878  // Management Device (Type 34)
    787879  //
    788880  case 34:
     
    790882    DisplayMDType (Struct->Type34->Type, Option);
    791883    PRINT_STRUCT_VALUE_H (Struct, Type34, Address);
    792     PRINT_STRUCT_VALUE_H (Struct, Type34, AddressType);
    793     break;
    794 
     884    DisplayMDAddressType (Struct->Type34->AddressType, Option);
     885    break;
     886
     887  //
     888  // Management Device Component (Type 35)
     889  //
    795890  case 35:
    796891    PRINT_PENDING_STRING (Struct, Type35, Description);
     
    800895    break;
    801896
     897  //
     898  // Management Device Threshold Data (Type 36)
     899  //
    802900  case 36:
    803901    PRINT_STRUCT_VALUE_H (Struct, Type36, LowerThresholdNonCritical);
     
    810908
    811909  //
    812   // Memory Channel  (Type 37)
     910  // Memory Channel (Type 37)
    813911  //
    814912  case 37:
    815913    {
    816       UINT8         Count;
    817       MEMORYDEVICE  *Ptr;
     914      UINT8          Count;
     915      MEMORY_DEVICE  *Ptr;
    818916      DisplayMemoryChannelType (Struct->Type37->ChannelType, Option);
    819917      PRINT_STRUCT_VALUE_H (Struct, Type37, MaximumChannelLoad);
     
    824922      for (Index = 0; Index < Count; Index++) {
    825923        ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_MEM_DEVICE), gShellDebug1HiiHandle, Index + 1);
    826         ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_DEV_LOAD), gShellDebug1HiiHandle, Ptr->DeviceLoad);
    827         ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_DEV_HANDLE), gShellDebug1HiiHandle, Ptr->DeviceHandle);
     924        ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_DEV_LOAD), gShellDebug1HiiHandle, Ptr[Index].DeviceLoad);
     925        ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_DEV_HANDLE), gShellDebug1HiiHandle, Ptr[Index].DeviceHandle);
    828926      }
    829927    }
     
    831929
    832930  //
    833   // IPMI Device Information  (Type 38)
     931  // IPMI Device Information (Type 38)
    834932  //
    835933  case 38:
     
    838936    PRINT_STRUCT_VALUE_H (Struct, Type38, I2CSlaveAddress);
    839937    PRINT_STRUCT_VALUE_H (Struct, Type38, NVStorageDeviceAddress);
    840     PRINT_STRUCT_VALUE_H (Struct, Type38, BaseAddress);
     938    PRINT_STRUCT_VALUE_LH (Struct, Type38, BaseAddress);
    841939    break;
    842940
     
    855953    PRINT_STRUCT_VALUE_H (Struct, Type39, MaxPowerCapacity);
    856954    DisplaySPSCharacteristics (
    857       Struct->Type39->PowerSupplyCharacteristics,
     955      *(UINT16 *) &(Struct->Type39->PowerSupplyCharacteristics),
    858956      Option
    859957     );
     
    895993  case 41:
    896994    PRINT_PENDING_STRING (Struct, Type41, ReferenceDesignation);
    897     PRINT_STRUCT_VALUE_H (Struct, Type41, DeviceType);
     995    ShellPrintEx(-1,-1,(((Struct->Type41->DeviceType) & 0x80) != 0) ? L"Device Enabled\n": L"Device Disabled\n");
     996    DisplayOnboardDeviceTypes ((Struct->Type41->DeviceType) & 0x7F, Option);
    898997    PRINT_STRUCT_VALUE_H (Struct, Type41, DeviceTypeInstance);
    899998    PRINT_STRUCT_VALUE_H (Struct, Type41, SegmentGroupNum);
     
    9021001    break;
    9031002
     1003  //
     1004  // Management Controller Host Interface (Type 42)
     1005  //
     1006  case 42:
     1007    PRINT_STRUCT_VALUE_H (Struct, Type42, InterfaceType);
     1008    break;
     1009
     1010  //
     1011  // Inactive (Type 126)
     1012  //
    9041013  case 126:
    9051014    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_INACTIVE_STRUCT), gShellDebug1HiiHandle);
    9061015    break;
    9071016
     1017  //
     1018  // End-of-Table (Type 127)
     1019  //
    9081020  case 127:
    9091021    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_THIS_STRUCT_END_TABLE), gShellDebug1HiiHandle);
     
    11581270  }
    11591271
    1160   ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BITS_RSVD_FOR_FUTURE), gShellDebug1HiiHandle);
     1272  if (AE_SMBIOS_VERSION (0x2, 0x4)) {
     1273    if (BIT (byte2, 2) != 0) {
     1274      ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_ENABLE_TAR_CONT_DIST), gShellDebug1HiiHandle);
     1275    }
     1276    if (AE_SMBIOS_VERSION (0x2, 0x7)) {
     1277      if (BIT (byte2, 3) != 0) {
     1278        ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_UEFI_SPEC_SUPPORT), gShellDebug1HiiHandle);
     1279      }
     1280      if (BIT (byte2, 4) != 0) {
     1281        ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_VIRTUAL_MACHINE), gShellDebug1HiiHandle);
     1282      }
     1283      ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BITS_RSVD_FOR_FUTURE), gShellDebug1HiiHandle, 5);
     1284    } else {
     1285      ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BITS_RSVD_FOR_FUTURE), gShellDebug1HiiHandle, 3);
     1286    }
     1287  } else {
     1288    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BITS_RSVD_FOR_FUTURE), gShellDebug1HiiHandle, 2);
     1289  }
    11611290}
    11621291
     
    12581387    break;
    12591388
     1389  case 0x13:
     1390    Print (L"M2 Family\n");
     1391    break;
     1392
     1393  case 0x14:
     1394    Print (L"Intel Celeron M\n");
     1395    break;
     1396
     1397  case 0x15:
     1398    Print (L"Intel Pentium 4 HT\n");
     1399    break;
     1400
    12601401  case 0x18:
    12611402    Print (L"AMD Duron\n");
     
    12661407    break;
    12671408
     1409  case 0x1A:
     1410    Print (L"K6 Family\n");
     1411    break;
     1412
     1413  case 0x1B:
     1414    Print (L"K6-2\n");
     1415    break;
     1416
     1417  case 0x1C:
     1418    Print (L"K6-3\n");
     1419    break;
     1420
     1421  case 0x1D:
     1422    Print (L"AMD Althon Processor Family\n");
     1423    break;
     1424
     1425  case 0x1E:
     1426    Print (L"AMD 29000 Family\n");
     1427    break;
     1428
     1429  case 0x1F:
     1430    Print (L"K6-2+\n");
     1431    break;
     1432
    12681433  case 0x20:
    12691434    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_POWER_PC_FAMILY), gShellDebug1HiiHandle);
     
    13461511    break;
    13471512
     1513  case 0x38:
     1514    Print (L"AMD Turion II Ultra Dual-Core Mobile M Processor Family\n");
     1515    break;
     1516
     1517  case 0x39:
     1518    Print (L"AMD Turion II Dual-Core Mobile M Processor Family\n");
     1519    break;
     1520
     1521  case 0x3A:
     1522    Print (L"AMD Althon II Dual-Core M Processor Family\n");
     1523    break;
     1524
     1525  case 0x3B:
     1526    Print (L"AMD Opteron 6100 Series Processor\n");
     1527    break;
     1528
     1529  case 0x3C:
     1530    Print (L"AMD Opteron 4100 Series Processor\n");
     1531    break;
     1532
     1533  case 0x3D:
     1534    Print (L"AMD Opteron 6200 Series Processor\n");
     1535    break;
     1536
     1537  case 0x3E:
     1538    Print (L"AMD Opteron 4200 Series Processor\n");
     1539    break;
     1540
     1541  case 0x3F:
     1542    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_FX_SERIES), gShellDebug1HiiHandle);
     1543    break;
     1544
    13481545  case 0x40:
    13491546    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_MIPS_FAMILY), gShellDebug1HiiHandle);
     
    13701567    break;
    13711568
     1569  case 0x46:
     1570    Print (L"AMD C-Series Processor\n");
     1571    break;
     1572
     1573  case 0x47:
     1574    Print (L"AMD E-Series Processor\n");
     1575    break;
     1576
     1577  case 0x48:
     1578    Print (L"AMD A-Series Processor\n");
     1579    break;
     1580
     1581  case 0x49:
     1582    Print (L"AMD G-Series Processor\n");
     1583    break;
     1584
     1585  case 0x4A:
     1586    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_Z_SERIES), gShellDebug1HiiHandle);
     1587    break;
     1588
     1589  case 0x4B:
     1590    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_R_SERIES), gShellDebug1HiiHandle);
     1591    break;
     1592
     1593  case 0x4C:
     1594    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_OPTERON_4300_SERIES), gShellDebug1HiiHandle);
     1595    break;
     1596
     1597  case 0x4D:
     1598    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_OPTERON_6300_SERIES), gShellDebug1HiiHandle);
     1599    break;
     1600
     1601  case 0x4E:
     1602    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_OPTERON_3300_SERIES), gShellDebug1HiiHandle);
     1603    break;
     1604
     1605  case 0x4F:
     1606    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_OPTERON_FIREPRO_SERIES), gShellDebug1HiiHandle);
     1607    break;
     1608
    13721609  case 0x50:
    13731610    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_SPARC_FAMILY), gShellDebug1HiiHandle);
     
    15101747    break;
    15111748
     1749  case 0x91:
     1750    Print (L"PA-RISC 8500\n");
     1751    break;
     1752
     1753  case 0x92:
     1754    Print (L"PA-RISC 8000\n");
     1755    break;
     1756
     1757  case 0x93:
     1758    Print (L"PA-RISC 7300LC\n");
     1759    break;
     1760
     1761  case 0x94:
     1762    Print (L"PA-RISC 7200\n");
     1763    break;
     1764
     1765  case 0x95:
     1766    Print (L"PA-RISC 7100LC\n");
     1767    break;
     1768
     1769  case 0x96:
     1770    Print (L"PA-RISC 7100\n");
     1771    break;
     1772
    15121773  case 0xA0:
    15131774    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_V30_FAMILY), gShellDebug1HiiHandle);
     
    15781839    break;
    15791840
     1841  case 0xB1:
     1842    Print (L"Pentium III Processorwith Intel SpeedStep Technology\n");
     1843    break;
     1844
     1845  case 0xB2:
     1846    Print (L"Pentium 4 processor\n");
     1847    break;
     1848
     1849  case 0xB3:
     1850    Print (L"Intel Xeon Processor\n");
     1851    break;
     1852
     1853  case 0xB4:
     1854    Print (L"AS400 Family\n");
     1855    break;
     1856
     1857  case 0xB5:
     1858    Print (L"Intel Xeon processor MP\n");
     1859    break;
     1860
     1861  case 0xB6:
     1862    Print (L"AMD Althon XP Processor Family\n");
     1863    break;
     1864
     1865  case 0xB7:
     1866    Print (L"AMD Althon MP Promcessor Family\n");
     1867    break;
     1868
     1869  case 0xB8:
     1870    Print (L"Intel Itanium 2 processor\n");
     1871    break;
     1872
     1873  case 0xB9:
     1874    Print (L"Intel Penium M processor\n");
     1875    break;
     1876
     1877  case 0xBA:
     1878    Print (L"Intel Celeron D processor\n");
     1879    break;
     1880
     1881  case 0xBB:
     1882    Print (L"Intel Pentium D processor\n");
     1883    break;
     1884
     1885  case 0xBC:
     1886    Print (L"Intel Pentium Processor Extreme Edition\n");
     1887    break;
     1888
     1889  case 0xBD:
     1890    Print (L"Intel Core Solo Processor\n");
     1891    break;
     1892
     1893  case 0xBF:
     1894    Print (L"Intel Core 2 Duo Processor\n");
     1895    break;
     1896
    15801897  case 0xC0:
    15811898    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_INTEL_CORE2_SOLO), gShellDebug1HiiHandle);
     
    16271944
    16281945  case 0xCC:
    1629     Print (L"zArchitectur\n");
     1946    Print (L"zArchitecture\n");
     1947    break;
     1948
     1949  case 0xCD:
     1950    Print (L"Intel Core i5 processor\n");
     1951    break;
     1952
     1953  case 0xCE:
     1954    Print (L"Intel Core i3 processor\n");
    16301955    break;
    16311956
     
    16782003    break;
    16792004
     2005  case 0xE0:
     2006    Print (L"Multi-Core Intel Xeon processor 3400 Series\n");
     2007    break;
     2008
     2009  case 0xE4:
     2010    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_OPTERON_3000_SERIES), gShellDebug1HiiHandle);
     2011    break;
     2012
     2013  case 0xE5:
     2014    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_SEMPRON_II), gShellDebug1HiiHandle);
     2015    break;
     2016
     2017
    16802018  case 0xE6:
    16812019    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_AMD_EMBEDDED_OPTERON_QUAD_CORE), gShellDebug1HiiHandle);
     
    17022040    break;
    17032041
     2042  case 0xEC:
     2043    Print (L"AMD Phenom II Processor Family\n");
     2044    break;
     2045
     2046  case 0xED:
     2047    Print (L"AMD Althon II Processor Family\n");
     2048    break;
     2049
     2050  case 0xEE:
     2051    Print (L"Six-Core AMD Opteron Processor Family\n");
     2052    break;
     2053
     2054  case 0xEF:
     2055    Print (L"AMD Sempron M Processor Family\n");
     2056    break;
     2057
    17042058  case 0xFA:
    17052059    Print (L"i860\n");
     
    17112065
    17122066  default:
    1713     //
    1714     // In order to reduce code quality notice of
    1715     // case & break not pair, so
    1716     // move multiple case into the else part and
    1717     // use if/else to check value.
    1718     //
    1719     if (Family >= 0x13 && Family <= 0x17) {
    1720       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_RSVD_FOR_SPEC_M1), gShellDebug1HiiHandle);
    1721     } else if (Family >= 0x1A && Family <= 0x1F) {
    1722       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_RSVD_FOR_SPEC_K5), gShellDebug1HiiHandle);
    1723     } else if (Family >= 0xB1 && Family <= 0xBF) {
    1724       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_RSVD_FOR_SPEC_PENTIUM), gShellDebug1HiiHandle);
    1725     } else {
    1726       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_UNDEFINED_PROC_FAMILY), gShellDebug1HiiHandle);
    1727     }
     2067    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_UNDEFINED_PROC_FAMILY), gShellDebug1HiiHandle);
    17282068  }
    17292069  //
     
    18782218  @param[in] Status   The status.
    18792219Bit 7 Reserved, must be 0
    1880 Bit 6   CPU Socket Populated
    1881  1 - CPU Socket Populated
    1882  0 - CPU Socket UnpopulatedBits
    1883  5:3 Reserved, must be zero
    1884  Bits 2:0 CPU Status
     2220Bit 6 CPU Socket Populated
     2221  1 - CPU Socket Populated
     2222  0 - CPU Socket Unpopulated
     2223Bits 5:3 Reserved, must be zero
     2224Bits 2:0 CPU Status
    18852225  0h - Unknown
    18862226  1h - CPU Enabled
     
    19032243
    19042244  if (BIT (Status, 7) != 0) {
    1905     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_ERROR_BIT7), gShellDebug1HiiHandle);
     2245    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT7_NOT_ZERO), gShellDebug1HiiHandle);
    19062246  } else if (BIT (Status, 5) != 0) {
    1907     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_ERROR_BIT5), gShellDebug1HiiHandle);
     2247    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT5_NOT_ZERO), gShellDebug1HiiHandle);
    19082248  } else if (BIT (Status, 4) != 0) {
    1909     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_ERROR_BIT4), gShellDebug1HiiHandle);
     2249    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT4_NOT_ZERO), gShellDebug1HiiHandle);
    19102250  } else if (BIT (Status, 3) != 0) {
    1911     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_ERROR_BIT3), gShellDebug1HiiHandle);
     2251    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT3_NOT_ZERO), gShellDebug1HiiHandle);
    19122252  }
    19132253  //
     
    21022442
    21032443/**
     2444  Display Cache Configuration.
     2445
     2446  @param[in] CacheConfiguration   Cache Configuration.
     2447Bits 15:10 Reserved, must be 0
     2448Bits 9:8 Operational Mode
     2449  0h - Write Through
     2450  1h - Write Back
     2451  2h - Varies with Memory Address
     2452  3h - Unknown
     2453Bit 7 Enabled/Disabled
     2454  1 - Enabled
     2455  0 - Disabled
     2456Bits 6:5 Location
     2457  0h - Internal
     2458  1h - External
     2459  2h - Reserved
     2460  3h - Unknown
     2461Bit 4 Reserved, must be zero
     2462Bit 3 Cache Socketed
     2463  1 - Socketed
     2464  0 - Unsocketed
     2465Bits 2:0 Cache Level
     2466  1 through 8 (For example, an L1 cache would
     2467  use value 000b and an L3 cache would use 010b.)
     2468
     2469  @param[in] Option   The option
     2470**/
     2471VOID
     2472DisplayCacheConfiguration (
     2473  IN UINT16 CacheConfiguration,
     2474  IN UINT8 Option
     2475  )
     2476{
     2477  ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_CONFIGURATION), gShellDebug1HiiHandle);
     2478  PRINT_INFO_OPTION (CacheConfiguration, Option);
     2479
     2480  if (BIT (CacheConfiguration, 15) != 0) {
     2481    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT15_NOT_ZERO), gShellDebug1HiiHandle);
     2482  } else if (BIT (CacheConfiguration, 14) != 0) {
     2483    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT14_NOT_ZERO), gShellDebug1HiiHandle);
     2484  } else if (BIT (CacheConfiguration, 13) != 0) {
     2485    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT13_NOT_ZERO), gShellDebug1HiiHandle);
     2486  } else if (BIT (CacheConfiguration, 12) != 0) {
     2487    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT12_NOT_ZERO), gShellDebug1HiiHandle);
     2488  } else if (BIT (CacheConfiguration, 11) != 0) {
     2489    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT11_NOT_ZERO), gShellDebug1HiiHandle);
     2490  } else if (BIT (CacheConfiguration, 10) != 0) {
     2491    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT10_NOT_ZERO), gShellDebug1HiiHandle);
     2492  } else if (BIT (CacheConfiguration, 4) != 0) {
     2493    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIT4_NOT_ZERO), gShellDebug1HiiHandle);
     2494  }
     2495
     2496  //
     2497  // Check BITs 9:8
     2498  //
     2499  switch ((CacheConfiguration & 0x300) >> 8) {
     2500  case 0:
     2501    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_WRITE_THROUGH), gShellDebug1HiiHandle);
     2502    break;
     2503
     2504  case 1:
     2505    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_WRITE_BACK), gShellDebug1HiiHandle);
     2506    break;
     2507
     2508  case 2:
     2509    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_VARIES_WITH_MEM_ADDR), gShellDebug1HiiHandle);
     2510    break;
     2511
     2512  case 3:
     2513    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_UNKNOWN), gShellDebug1HiiHandle);
     2514    break;
     2515  }
     2516
     2517  //
     2518  // Check BIT 7
     2519  //
     2520  if (BIT (CacheConfiguration, 7) != 0) {
     2521    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_ENABLED), gShellDebug1HiiHandle);
     2522  } else {
     2523    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_DISABLED), gShellDebug1HiiHandle);
     2524  }
     2525
     2526  //
     2527  // Check BITs 6:5
     2528  //
     2529  switch ((CacheConfiguration & 0x60) >> 5) {
     2530  case 0:
     2531    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_INTERNAL), gShellDebug1HiiHandle);
     2532    break;
     2533
     2534  case 1:
     2535    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_EXTERNAL), gShellDebug1HiiHandle);
     2536    break;
     2537
     2538  case 2:
     2539    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_RESERVED), gShellDebug1HiiHandle);
     2540    break;
     2541
     2542  case 3:
     2543    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_UNKNOWN), gShellDebug1HiiHandle);
     2544    break;
     2545  }
     2546
     2547  //
     2548  // Check BIT 3
     2549  //
     2550  if (BIT (CacheConfiguration, 3) != 0) {
     2551    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_SOCKETED), gShellDebug1HiiHandle);
     2552  } else {
     2553    ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_NOT_SOCKETED), gShellDebug1HiiHandle);
     2554  }
     2555
     2556
     2557  ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_CACHE_LEVEL), gShellDebug1HiiHandle, (CacheConfiguration & 0x07) + 1);
     2558}
     2559
     2560/**
    21042561  The Slot ID field of the System Slot structure provides a mechanism to
    21052562  correlate the physical attributes of the slot to its logical access method
     
    21752632
    21762633  default:
    2177     if (SlotType >= 0x0E && SlotType <= 0x12) {
     2634    if ((SlotType >= 0x0E && SlotType <= 0x12) || (SlotType >= 0xA6 && SlotType <= 0xB6)){
    21782635      ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_VALUE_PRESENT), gShellDebug1HiiHandle, SlotId);
    21792636    } else {
     
    22622719  //
    22632720  Day   = Date & 0x001F;
    2264   Month = (Date & 0x00E0) >> 5;
    2265   Year  = ((Date & 0xFF00) >> 8) + 1980;
     2721  Month = (Date & 0x01E0) >> 5;
     2722  Year  = ((Date & 0xFE00) >> 9) + 1980;
    22662723  ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_MONTH_DAY_YEAR), gShellDebug1HiiHandle, Day, Month, Year);
    22672724
     
    22692726
    22702727/**
    2271   Display System Reset  (Type 23) information.
     2728  Display System Reset (Type 23) information.
    22722729
    22732730 
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.h

    r48674 r58459  
    22  Module to clarify the element info of the smbios structure.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1616#define _SMBIOS_PRINT_INFO_H_
    1717
    18 #include "LibSmbios.h"
     18#include <IndustryStandard/SmBios.h>
    1919
    2020extern UINT8  SmbiosMajorVersion;
     
    4343VOID
    4444SmbiosPrintEPSInfo (
    45   IN  SMBIOS_STRUCTURE_TABLE  *SmbiosTable,
    46   IN  UINT8                   Option
     45  IN  SMBIOS_TABLE_ENTRY_POINT  *SmbiosTable,
     46  IN  UINT8                     Option
    4747  );
    4848
     
    155155
    156156  @param[in] Status   The status.
    157                         Bit 7 Reserved, must be 0
    158                         Bit 6  CPU Socket Populated
    159                          1 - CPU Socket Populated
    160                          0 - CPU Socket UnpopulatedBits
    161                          5:3 Reserved, must be zero
    162                          Bits 2:0 CPU Status
    163                           0h - Unknown
    164                           1h - CPU Enabled
    165                           2h - CPU Disabled by User via BIOS Setup
    166                           3h - CPU Disabled By BIOS (POST Error)
    167                           4h - CPU is Idle, waiting to be enabled.
    168                           5-6h - Reserved
    169                           7h - Other
     157Bit 7 Reserved, must be 0
     158Bit 6 CPU Socket Populated
     159  1 - CPU Socket Populated
     160  0 - CPU Socket Unpopulated
     161Bits 5:3 Reserved, must be zero
     162Bits 2:0 CPU Status
     163  0h - Unknown
     164  1h - CPU Enabled
     165  2h - CPU Disabled by User via BIOS Setup
     166  3h - CPU Disabled By BIOS (POST Error)
     167  4h - CPU is Idle, waiting to be enabled.
     168  5-6h - Reserved
     169  7h - Other
    170170
    171171  @param[in] Option   The option
     
    234234DisplayMmMemorySize (
    235235  IN UINT8 Size,
     236  IN UINT8 Option
     237  );
     238
     239/**
     240  Display Cache Configuration.
     241
     242  @param[in] CacheConfiguration   Cache Configuration.
     243Bits 15:10 Reserved, must be 0
     244Bits 9:8 Operational Mode
     245  0h - Write Through
     246  1h - Write Back
     247  2h - Varies with Memory Address
     248  3h - Unknown
     249Bit 7 Enabled/Disabled
     250  1 - Enabled
     251  0 - Disabled
     252Bits 6:5 Location
     253  0h - Internal
     254  1h - External
     255  2h - Reserved
     256  3h - Unknown
     257Bit 4 Reserved, must be zero
     258Bit 3 Cache Socketed
     259  1 - Socketed
     260  0 - Unsocketed
     261Bits 2:0 Cache Level
     262  1 through 8 (For example, an L1 cache would
     263  use value 000b and an L3 cache would use 010b.)
     264
     265  @param[in] Option   The option
     266**/
     267VOID
     268DisplayCacheConfiguration (
     269  IN UINT16 CacheConfiguration,
    236270  IN UINT8 Option
    237271  );
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.c

    r48674 r58459  
    33  And give a interface of query a string out of a table.
    44
    5   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     5  Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
    66  This program and the accompanying materials
    77  are licensed and made available under the terms and conditions of the BSD License
     
    5353};
    5454
     55TABLE_ITEM  BaseBoardFeatureFlagsTable[] = {
     56  {
     57    0,
     58    L" Hosting board"
     59  },
     60  {
     61    1,
     62    L" Requires at least one daughter board or auxiliary card"
     63  },
     64  {
     65    2,
     66    L" Removable"
     67  },
     68  {
     69    3,
     70    L" Replaceable"
     71  },
     72  {
     73    4,
     74    L" Hot swappable"
     75  }
     76};
     77
     78TABLE_ITEM  BaseBoardBoardTypeTable[] = {
     79  {
     80    0x01,
     81    L" Unknown"
     82  },
     83  {
     84    0x02,
     85    L" Other"
     86  },
     87  {
     88    0x03,
     89    L" Server Blade"
     90  },
     91  {
     92    0x04,
     93    L" Connectivity Switch"
     94  },
     95  {
     96    0x05,
     97    L" System Management Module"
     98  },
     99  {
     100    0x06,
     101    L" Processor Module"
     102  },
     103  {
     104    0x07,
     105    L" I/O Module"
     106  },
     107  {
     108    0x08,
     109    L" Memory Module"
     110  },
     111  {
     112    0x09,
     113    L" Daughter board"
     114  },
     115  {
     116    0x0A,
     117    L" Motherboard"
     118  },
     119  {
     120    0x0B,
     121    L" Processor/Memory Module"
     122  },
     123  {
     124    0x0C,
     125    L" Processor/IO Module"
     126  },
     127  {
     128    0x0D,
     129    L" Interconnect Board"
     130  }
     131};
     132
    55133TABLE_ITEM  SystemEnclosureTypeTable[] = {
    56134  {
    57135    0x01,
    58     L"  None"
     136    L"  Other"
    59137  },
    60138  {
     
    349427    0x19,
    350428    L"Socket LGA1366"
    351   }\
    352 };
     429  },
     430  {
     431    0x1A,
     432    L"Socket G34"
     433  },
     434  {
     435    0x1B,
     436    L"Socket AM3"
     437  },
     438  {
     439    0x1C,
     440    L"Socket C32"
     441  },
     442  {
     443    0x1D,
     444    L"Socket LGA1156"
     445  },
     446  {
     447    0x1E,
     448    L"Socket LGA1567"
     449  },
     450  {
     451    0x1F,
     452    L"Socket PGA988A"
     453  },
     454  {
     455    0x20,
     456    L"Socket BGA1288"
     457  },
     458  {
     459    0x21,
     460    L"Socket rPGA988B"
     461  },
     462  {
     463    0x22,
     464    L"Socket BGA1023"
     465  },
     466  {
     467    0x23,
     468    L"Socket BGA1224"
     469  },
     470  {
     471    0x24,
     472    L"Socket LGA1155"
     473  },
     474  {
     475    0x25,
     476    L"Socket LGA1356"
     477  },
     478  {
     479    0x26,
     480    L"Socket LGA2011"
     481  },
     482  {
     483    0x27,
     484    L"Socket FS1"
     485  },
     486  {
     487    0x28,
     488    L"Socket FS2"
     489  },
     490  {
     491    0x29,
     492    L"Socket FM1"
     493  },
     494  {
     495    0x2A,
     496    L"Socket FM2"
     497  },
     498  {
     499    0x2B,
     500    L"Socket LGA2011-3"
     501  },
     502  {
     503    0x2C,
     504    L"Socket LGA1356-3"
     505  }
     506};
     507
     508TABLE_ITEM  ProcessorCharacteristicsTable[] = {
     509  {
     510    1,
     511    L" Unknown"
     512  },
     513  {
     514    2,
     515    L" 64-bit Capable"
     516  },
     517  {
     518    3,
     519    L" Multi-Core"
     520  },
     521  {
     522    4,
     523    L" Hardware Thread"
     524  },
     525  {
     526    5,
     527    L" Execute Protection"
     528  },
     529  {
     530    6,
     531    L" Enhanced Virtualization"
     532  },
     533  {
     534    7,
     535    L" Power/Performance Control"
     536  }
     537};
     538
    353539
    354540TABLE_ITEM  McErrorDetectMethodTable[] = {
     
    600786    0x06,
    601787    L"Multi-bit ECC"
    602   },
    603   {
    604     0x07,
    605     L"Sixteen Way Interleave"
    606788  }
    607789};
     
    682864    0x0D,
    683865    L"64-way Set-Associative"
     866  },
     867  {
     868    0x0E,
     869    L"20-way Set-Associative"
    684870  }
    685871};
     
    11221308  {
    11231309    0xAB,
    1124     L"PCI Express Gen 26"
     1310    L"PCI Express Gen 2"
    11251311  },
    11261312  {
     
    11431329    0xB0,
    11441330    L"PCI Express Gen 2 X16"
     1331  },
     1332  {
     1333    0xB1,
     1334    L"PCI Express Gen 3"
     1335  },
     1336  {
     1337    0xB2,
     1338    L"PCI Express Gen 3 X1"
     1339  },
     1340  {
     1341    0xB3,
     1342    L"PCI Express Gen 3 X2"
     1343  },
     1344  {
     1345    0xB4,
     1346    L"PCI Express Gen 3 X4"
     1347  },
     1348  {
     1349    0xB5,
     1350    L"PCI Express Gen 3 X8"
     1351  },
     1352  {
     1353    0xB6,
     1354    L"PCI Express Gen 3 X16"
    11451355  }
    11461356};
     
    11751385    L" 128 bit"
    11761386  },
     1387  {
     1388    0x08,
     1389    L" 1x or x1"
     1390  },
     1391  {
     1392    0x09,
     1393    L" 2x or x2"
     1394  },
     1395  {
     1396    0x0A,
     1397    L" 4x or x4"
     1398  },
     1399  {
     1400    0x0B,
     1401    L" 8x or x8"
     1402  },
     1403  {
     1404    0x0C,
     1405    L" 12x or x12"
     1406  },
     1407  {
     1408    0x0D,
     1409    L" 16x or x16"
     1410  },
     1411  {
     1412    0x0E,
     1413    L" 32x or x32"
     1414  }
    11771415};
    11781416
     
    21182356    L" Non-volatile"
    21192357  },
     2358  {
     2359    13,
     2360    L" Registered(Buffered)"
     2361  },
     2362  {
     2363    14,
     2364    L" Unbuffered(Unregistered)"
     2365  }
    21202366};
    21212367
     
    24732719  },
    24742720  {
    2475     0x0A,
     2721    0x10,
    24762722    L" Active Cooling "
    24772723  },
    24782724  {
    2479     0x0B,
     2725    0x11,
    24802726    L" Passive Cooling "
    24812727  },
     
    29103156    39,
    29113157    L" System Power Supply"
     3158  },
     3159  {
     3160    40,
     3161    L" Additional Information"
     3162  },
     3163  {
     3164    41,
     3165    L" Onboard Devices Extended Information"
     3166  },
     3167  {
     3168    42,
     3169    L" Management Controller Host Interface"
    29123170  },
    29133171  {
     
    29653223    High  = (UINT8) (Table[Index].Key >> 8);
    29663224    Low   = (UINT8) (Table[Index].Key & 0x00FF);
     3225
    29673226    //
    29683227    // Check if Key is in the range
     3228    // or if Key == Value in the table
    29693229    //
    2970     if (High > Low && Key >= Low && Key <= High) {
     3230    if ((High > Low && Key >= Low && Key <= High)
     3231      || (Table[Index].Key == Key)) {
    29713232      StrnCpy (Info, Table[Index].Info, InfoLen-1);
    2972       StrnCat (Info, L"\n", InfoLen - StrLen(Info));
    2973       return Key;
    2974     }
    2975     //
    2976     // Check if Key == Value in the table
    2977     //
    2978     if (Table[Index].Key == Key) {
    2979       StrnCpy (Info, Table[Index].Info, InfoLen-1);
    2980       StrnCat (Info, L"\n", InfoLen - StrLen(Info));
     3233      StrnCat (Info, L"\n", InfoLen - 1 - StrLen(Info));
    29813234      return Key;
    29823235    }
    29833236  }
    29843237
    2985   StrnCpy (Info, L"Undefined Value\n", InfoLen);
     3238  StrnCpy (Info, L"Undefined Value\n", InfoLen - 1);
    29863239  return QUERY_TABLE_UNFOUND;
    29873240}
     
    30883341
    30893342/**
     3343  Display Base Board (Type 2) Feature Flags.
     3344
     3345  @param[in] FeatureFlags   The key of the structure.
     3346  @param[in] Option         The optional information.
     3347**/
     3348VOID
     3349DisplayBaseBoardFeatureFlags (
     3350  IN UINT8 FeatureFlags,
     3351  IN UINT8 Option
     3352  )
     3353{
     3354  ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_BASE_BOARD_FEATURE_FLAGS), gShellDebug1HiiHandle);
     3355  PRINT_INFO_OPTION (FeatureFlags, Option);
     3356  PRINT_BITS_INFO (BaseBoardFeatureFlagsTable, FeatureFlags);
     3357}
     3358
     3359/**
     3360  Display Base Board (Type 2) Board Type.
     3361
     3362  @param[in] Type           The key of the structure.
     3363  @param[in] Option         The optional information.
     3364**/
     3365VOID
     3366DisplayBaseBoardBoardType(
     3367  IN UINT8 Type,
     3368  IN UINT8 Option
     3369  )
     3370{
     3371  ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_BASE_BOARD_BOARD_TYPE), gShellDebug1HiiHandle);
     3372  PRINT_INFO_OPTION (Type, Option);
     3373  PRINT_TABLE_ITEM (BaseBoardBoardTypeTable, Type);
     3374}
     3375
     3376/**
    30903377  Display System Enclosure (Type 3) Enclosure Type.
    30913378
     
    31773464  PRINT_INFO_OPTION (Upgrade, Option);
    31783465  PRINT_TABLE_ITEM (ProcessorUpgradeTable, Upgrade);
     3466}
     3467
     3468/**
     3469  Display Processor Information (Type 4) Characteristics.
     3470
     3471  @param[in] Type           The key of the structure.
     3472  @param[in] Option         The optional information.
     3473**/
     3474VOID
     3475DisplayProcessorCharacteristics (
     3476  IN UINT16 Type,
     3477  IN UINT8 Option
     3478  )
     3479{
     3480  ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_PROC_CHARACTERISTICS), gShellDebug1HiiHandle);
     3481  PRINT_INFO_OPTION (Type, Option);
     3482  PRINT_BITS_INFO (ProcessorCharacteristicsTable, Type);
    31793483}
    31803484
     
    36533957  )
    36543958{
    3655   ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_PHYS_MEM_ARRAY_LOCATION), gShellDebug1HiiHandle);
     3959  ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_PHYS_MEM_ARRAY_USE), gShellDebug1HiiHandle);
    36563960  PRINT_INFO_OPTION (Use, Option);
    36573961  PRINT_TABLE_ITEM (PMAUseTable, Use);
     
    39894293
    39904294/**
    3991   Display Management Device (Type 34) information.
     4295  Display Management Device (Type 34) Type.
    39924296
    39934297  @param[in] Key      The key of the structure.
     
    40034307  PRINT_INFO_OPTION (Key, Option);
    40044308  PRINT_TABLE_ITEM (MDTypeTable, Key);
     4309}
     4310
     4311/**
     4312  Display Management Device (Type 34) Address Type.
     4313
     4314  @param[in] Key      The key of the structure.
     4315  @param[in] Option   The optional information.
     4316**/
     4317VOID
     4318DisplayMDAddressType (
     4319  IN UINT8 Key,
     4320  IN UINT8 Option
     4321  )
     4322{
     4323  ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_QUERYTABLE_MANAGEMENT_DEV_ADDR_TYPE), gShellDebug1HiiHandle);
     4324  PRINT_INFO_OPTION (Key, Option);
     4325  PRINT_TABLE_ITEM (MDAddressTypeTable, Key);
    40054326}
    40064327
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/QueryTable.h

    r48674 r58459  
    33  and give a interface of query a string out of a table.
    44
    5   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     5  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
    66  This program and the accompanying materials
    77  are licensed and made available under the terms and conditions of the BSD License
     
    9696
    9797/**
     98  Display Base Board (Type 2) Feature Flags.
     99
     100  @param[in] FeatureFlags   The key of the structure.
     101  @param[in] Option         The optional information.
     102**/
     103VOID
     104DisplayBaseBoardFeatureFlags (
     105  IN UINT8 FeatureFlags,
     106  IN UINT8 Option
     107  );
     108
     109/**
     110  Display Base Board (Type 2) Board Type.
     111
     112  @param[in] Type           The key of the structure.
     113  @param[in] Option         The optional information.
     114**/
     115VOID
     116DisplayBaseBoardBoardType(
     117  IN UINT8 Type,
     118  IN UINT8 Option
     119  );
     120
     121/**
    98122  Display System Enclosure (Type 3) Enclosure Type.
    99123
     
    153177DisplayProcessorUpgrade (
    154178  IN UINT8 Upgrade,
     179  IN UINT8 Option
     180  );
     181
     182/**
     183  Display Processor Information (Type 4) Characteristics.
     184
     185  @param[in] Type           The key of the structure.
     186  @param[in] Option         The optional information.
     187**/
     188VOID
     189DisplayProcessorCharacteristics (
     190  IN UINT16 Type,
    155191  IN UINT8 Option
    156192  );
     
    697733
    698734/**
    699   Display Management Device (Type 34) information.
     735  Display Management Device (Type 34) Type.
    700736
    701737  @param[in] Key      The key of the structure.
     
    709745
    710746/**
     747  Display Management Device (Type 34) Address Type.
     748
     749  @param[in] Key      The key of the structure.
     750  @param[in] Option   The optional information.
     751**/
     752VOID
     753DisplayMDAddressType (
     754  IN UINT8 Key,
     755  IN UINT8 Option
     756  );
     757
     758/**
    711759  Display Memory Channel (Type 37) information.
    712760
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.c

    r48674 r58459  
    22  Tools of clarify the content of the smbios table.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    112112      // Initialize the StructHandle to be the first handle
    113113      //
    114       StructHandle  = STRUCTURE_HANDLE_INVALID;
     114      StructHandle  = INVALID_HANDLE;
    115115      LibGetSmbiosStructure (&StructHandle, NULL, NULL);
    116116
     
    189189{
    190190  UINT16                    Handle;
    191   UINT8                     Buffer[1024];
    192   //
    193   // bigger than SMBIOS_STRUCTURE_TABLE.MaxStructureSize
    194   //
     191  UINT8                     *Buffer;
    195192  UINT16                    Length;
    196193  UINTN                     Index;
    197   UINT16                    Offset;
    198   //
    199   // address offset from structure table head.
    200   //
    201   UINT32                    TableHead;
    202   //
    203   // structure table head.
    204   //
    205194
    206195  SMBIOS_STRUCTURE_POINTER  SmbiosStruct;
    207   SMBIOS_STRUCTURE_TABLE    *SMBiosTable;
     196  SMBIOS_TABLE_ENTRY_POINT  *SMBiosTable;
    208197
    209198  SMBiosTable = NULL;
     
    216205  if (CompareMem (SMBiosTable->AnchorString, "_SM_", 4) == 0) {
    217206    //
    218     // Have get SMBIOS table
     207    // Have got SMBIOS table
    219208    //
    220209    SmbiosPrintEPSInfo (SMBiosTable, Option);
     
    260249    //
    261250    Handle    = QueryHandle;
    262     TableHead = SMBiosTable->TableAddress;
    263     Offset    = 0;
    264251    for (Index = 0; Index < SMBiosTable->NumberOfSmbiosStructures; Index++) {
    265252      //
    266253      // if reach the end of table, break..
    267254      //
    268       if (Handle == STRUCTURE_HANDLE_INVALID) {
     255      if (Handle == INVALID_HANDLE) {
    269256        break;
    270257      }
     
    272259      // handle then point to the next!
    273260      //
    274       if (LibGetSmbiosStructure (&Handle, Buffer, &Length) != DMI_SUCCESS) {
     261      if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
    275262        break;
    276263      }
    277       Offset      = (UINT16) (Offset + Length);
     264
    278265      SmbiosStruct.Raw = Buffer;
    279266
     
    298285      // Addr of structure in structure in table
    299286      //
    300       ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, TableHead + Offset);
     287      ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_SMBIOSVIEW_ADDR), gShellDebug1HiiHandle, (UINTN) Buffer);
    301288      DumpHex (0, 0, Length, Buffer);
    302289
     
    316303
    317304      if (gShowType != SHOW_NONE) {
    318         //
    319         // check structure legality
    320         //
    321         SmbiosCheckStructure (&SmbiosStruct);
    322 
    323305        //
    324306        // Print structure information
     
    344326        break;
    345327      }
     328      //
     329      // Support Execution Interrupt.
     330      //
     331      if (ShellGetExecutionBreakFlag ()) {
     332        return EFI_ABORTED;
     333      }
    346334    }
    347335
     
    365353{
    366354  UINT16                    Handle;
    367   UINT8                     Buffer[1024];
     355  UINT8                     *Buffer;
    368356  UINT16                    Length;
    369357  UINT16                    Offset;
     
    371359
    372360  SMBIOS_STRUCTURE_POINTER  SmbiosStruct;
    373   SMBIOS_STRUCTURE_TABLE    *SMBiosTable;
     361  SMBIOS_TABLE_ENTRY_POINT  *SMBiosTable;
    374362  STRUCTURE_STATISTICS      *StatisticsPointer;
    375363
     
    406394  // search from the first one
    407395  //
    408   Handle = STRUCTURE_HANDLE_INVALID;
     396  Handle = INVALID_HANDLE;
    409397  LibGetSmbiosStructure (&Handle, NULL, NULL);
    410398  for (Index = 1; Index <= SMBiosTable->NumberOfSmbiosStructures; Index++) {
     
    412400    // If reach the end of table, break..
    413401    //
    414     if (Handle == STRUCTURE_HANDLE_INVALID) {
     402    if (Handle == INVALID_HANDLE) {
    415403      break;
    416404    }
     
    418406    // After LibGetSmbiosStructure(), handle then point to the next!
    419407    //
    420     if (LibGetSmbiosStructure (&Handle, Buffer, &Length) != DMI_SUCCESS) {
     408    if (LibGetSmbiosStructure (&Handle, &Buffer, &Length) != DMI_SUCCESS) {
    421409      break;
    422410    }
    423411
    424412    SmbiosStruct.Raw = Buffer;
    425     Offset      = (UINT16) (Offset + Length);
    426413
    427414    //
     
    433420    StatisticsPointer->Length = Length;
    434421    StatisticsPointer->Addr   = Offset;
     422
     423    Offset = (UINT16) (Offset + Length);
    435424
    436425    StatisticsPointer         = &mStatisticsTable[Index];
     
    453442  )
    454443{
    455   UINTN                   Index;
    456   UINTN                   Num;
    457   STRUCTURE_STATISTICS    *StatisticsPointer;
    458   SMBIOS_STRUCTURE_TABLE *SMBiosTable;
     444  UINTN                    Index;
     445  UINTN                    Num;
     446  STRUCTURE_STATISTICS     *StatisticsPointer;
     447  SMBIOS_TABLE_ENTRY_POINT *SMBiosTable;
    459448
    460449  SMBiosTable = NULL;
     
    559548}
    560549
    561 /*
    562 EFI_STATUS
    563 InitializeSmbiosViewApplicationGetLineHelp (
    564   OUT CHAR16              **Str
    565   )
    566 {
    567   return LibCmdGetStringByToken (STRING_ARRAY_NAME, &EfiSmbiosViewGuid, STRING_TOKEN (STR_SMBIOSVIEW_LINE_HELP), Str);
    568 }
    569 */
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/SmbiosView.h

    r48674 r58459  
    22  Tools of clarify the content of the smbios table.
    33
    4   Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1818#define STRUCTURE_TYPE_RANDOM     (UINT8) 0xFE
    1919#define STRUCTURE_TYPE_INVALID    (UINT8) 0xFF
    20 
    21 #define STRUCTURE_HANDLE_INVALID  (UINT16) 0xFFFF
    2220
    2321typedef struct {
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c

    r48674 r58459  
    1414
    1515#include "UefiShellDebug1CommandsLib.h"
     16#include <Library/BcfgCommandLib.h>
    1617
    1718STATIC CONST CHAR16 mFileName[] = L"Debug1Commands";
     
    8586  ShellCommandRegisterCommandName(L"hexedit",       ShellCommandRunHexEdit            , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT)      );
    8687
    87   //
    88   // check install profile bit of the profiles mask is set
    89   //
    90   if ((PcdGet8(PcdShellProfileMask) & BIT2) == 0) {
    91     ShellCommandRegisterCommandName(L"bcfg",        ShellCommandRunBcfg               , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_BCFG)         );
    92   }
    93 
    94 
    95 
    96 
    9788  ShellCommandRegisterAlias(L"dmem", L"mem");
     89
     90  BcfgLibraryRegisterBcfgCommand(ImageHandle, SystemTable, L"Debug1");
    9891
    9992  return (EFI_SUCCESS);
     
    116109    HiiRemovePackages(gShellDebug1HiiHandle);
    117110  }
     111
     112  BcfgLibraryUnregisterBcfgCommand(ImageHandle, SystemTable);
    118113  return (EFI_SUCCESS);
    119114}
     
    181176    Val[Index * 3]  = 0;
    182177    Str[Index]      = 0;
    183     ShellPrintEx(-1, -1, L"%*a%02X: %-.48a *%a*\r\n", Indent, "", Offset, Val, Str);
     178    ShellPrintEx(-1, -1, L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str);
    184179
    185180    Data += Size;
     
    491486  EFI_STATUS         Status;
    492487  UINTN              Suffix;
    493   BOOLEAN            FoundNewFile;
    494488  CHAR16             *FileNameTmp;
    495489
    496490  Suffix       = 0;
    497   FoundNewFile = FALSE;
    498491
    499492  do {
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.h

    r48674 r58459  
    22  Main file for NULL named library for Profile1 shell command functions.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    3030#include <Protocol/LoadedImage.h>
    3131#include <Protocol/UnicodeCollation.h>
    32 #include <Protocol/DevicePathToText.h>
    3332#include <Protocol/DriverDiagnostics2.h>
    3433#include <Protocol/DriverDiagnostics.h>
     
    3938#include <Protocol/DriverFamilyOverride.h>
    4039#include <Protocol/DriverHealth.h>
    41 #include <Protocol/DevicePathFromText.h>
    4240#include <Protocol/SimplePointer.h>
    4341#include <Protocol/PciRootBridgeIo.h>
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf

    r48674 r58459  
    22# Provides shell Debug1 profile functions
    33#
    4 # Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
    55#
    66#  This program and the accompanying materials
     
    3737  SetVar.c
    3838  SerMode.c
    39   Bcfg.c
    4039  Pci.c
    4140  Pci.h
     
    4746  SmbiosView/QueryTable.c
    4847  SmbiosView/SmbiosView.c
    49   SmbiosView/Smbios.c
    5048  SmbiosView/SmbiosViewStrings.uni
    5149  SmbiosView/LibSmbiosView.c
    5250  SmbiosView/PrintInfo.h
    5351  SmbiosView/LibSmbiosView.h
    54   SmbiosView/LibSmbios.h
    5552  SmbiosView/QueryTable.h
    5653  SmbiosView/SmbiosView.h
     
    118115  SortLib
    119116  PrintLib
     117  BcfgCommandLib
    120118
    121119[Pcd]
    122   gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask              # ALWAYS_CONSUMED
    123   gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize        # ALWAYS_CONSUMED
    124   gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength      # ALWAYS_CONSUMED
     120  gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask              ## CONSUMES
     121  gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize        ## CONSUMES
     122  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength      ## CONSUMES
    125123
    126124[Protocols]
    127   gEfiPciRootBridgeIoProtocolGuid
    128   gEfiBlockIoProtocolGuid
    129   gEfiSimplePointerProtocolGuid
     125  gEfiPciRootBridgeIoProtocolGuid             ## CONSUMES
     126  gEfiBlockIoProtocolGuid                     ## CONSUMES
     127  gEfiSimplePointerProtocolGuid               ## CONSUMES
    130128
    131129[Guids]
    132   gEfiGlobalVariableGuid
    133   gEfiSmbiosTableGuid
    134   gEfiMpsTableGuid
    135   gEfiSalSystemTableGuid
    136   gEfiAcpi10TableGuid
    137   gEfiAcpi20TableGuid
    138   gShellDebug1HiiGuid
     130  gEfiGlobalVariableGuid          ## SOMETIMES_CONSUMES ## GUID
     131  gEfiSmbiosTableGuid             ## SOMETIMES_CONSUMES ## SystemTable
     132  gEfiMpsTableGuid                ## SOMETIMES_CONSUMES ## SystemTable
     133  gEfiSalSystemTableGuid          ## SOMETIMES_CONSUMES ## SystemTable
     134  gEfiAcpi10TableGuid             ## SOMETIMES_CONSUMES ## SystemTable
     135  gEfiAcpi20TableGuid             ## SOMETIMES_CONSUMES ## SystemTable
     136  gShellDebug1HiiGuid             ## SOMETIMES_CONSUMES ## HII
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Connect.c

    r48674 r58459  
    22  Main file for connect shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1616
    1717/**
     18  Create all handles associate with every device path node.
     19
     20  @param  DevicePathToConnect           The device path which will be connected.
     21
     22  @retval EFI_SUCCESS                   All handles associate with every device path node
     23                                        have been created.
     24  @retval EFI_INVALID_PARAMETER         DevicePathToConnect is NULL.
     25  @retval EFI_NOT_FOUND                 Create the handle associate with one device path
     26                                        node failed
     27
     28**/
     29EFI_STATUS
     30ShellConnectDevicePath (
     31  IN EFI_DEVICE_PATH_PROTOCOL   *DevicePathToConnect
     32  )
     33{
     34  EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath;
     35  EFI_STATUS                Status;
     36  EFI_HANDLE                Handle;
     37  EFI_HANDLE                PreviousHandle;
     38 
     39  if (DevicePathToConnect == NULL) {
     40    return EFI_INVALID_PARAMETER;
     41  }
     42
     43  PreviousHandle = NULL;
     44  do{   
     45    RemainingDevicePath = DevicePathToConnect;
     46    Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &Handle);
     47   
     48    if (!EFI_ERROR (Status) && (Handle != NULL)) {
     49      if (PreviousHandle == Handle) {
     50        Status = EFI_NOT_FOUND;
     51      } else {
     52        PreviousHandle = Handle;
     53        Status = gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);
     54      }
     55    }
     56   
     57  } while (!EFI_ERROR (Status) && !IsDevicePathEnd (RemainingDevicePath) );
     58 
     59  return Status;
     60   
     61}
     62
     63/**
     64  Connect drivers for PCI root bridge.
     65 
     66  @retval EFI_SUCCESS                     Connect drivers successfully.
     67  @retval EFI_NOT_FOUND                   Cannot find PCI root bridge device.
     68
     69**/
     70EFI_STATUS
     71ShellConnectPciRootBridge (
     72  VOID
     73  )
     74
     75  UINTN               RootBridgeHandleCount;
     76  EFI_HANDLE          *RootBridgeHandleBuffer;
     77  UINTN               RootBridgeIndex;
     78  EFI_STATUS          Status;
     79 
     80  RootBridgeHandleCount = 0;
     81 
     82  Status = gBS->LocateHandleBuffer ( 
     83              ByProtocol, 
     84              &gEfiPciRootBridgeIoProtocolGuid,
     85              NULL, 
     86              &RootBridgeHandleCount, 
     87              &RootBridgeHandleBuffer 
     88              );
     89  if (EFI_ERROR (Status)) {
     90    return Status;
     91  }
     92 
     93  for (RootBridgeIndex = 0; RootBridgeIndex < RootBridgeHandleCount; RootBridgeIndex++) {   
     94    gBS->ConnectController (RootBridgeHandleBuffer[RootBridgeIndex], NULL, NULL, FALSE);   
     95  } 
     96 
     97  return EFI_SUCCESS;
     98}
     99
     100
     101/**
    18102  Connect controller(s) and driver(s).
    19103
    20   @param[in] ControllerHandle     The handle to the controller.  Should have driver binding on it.
    21   @param[in] DriverHandle         The handle to the driver.  Should have driver binding.
     104  @param[in] ControllerHandle     The handle to the controller. Should have driver binding on it.
     105  @param[in] DriverHandle         The handle to the driver. Should have driver binding.
    22106  @param[in] Recursive            TRUE to connect recursively, FALSE otherwise.
    23107  @param[in] Output               TRUE to have info on the screen, FALSE otherwise.
     
    114198{
    115199  EFI_DEVICE_PATH_PROTOCOL  *DevPath;
    116   EFI_DEVICE_PATH_PROTOCOL  *DevPathWalker;
     200  EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevPath;
     201  EFI_DEVICE_PATH_PROTOCOL  *Instance; 
     202  EFI_DEVICE_PATH_PROTOCOL  *Next;
    117203  UINTN                     Length;
    118   EFI_HANDLE                Handle;
     204  UINTN                     Index;
     205  UINTN                     HandleArrayCount;
     206  UINTN                     Size;
     207  EFI_HANDLE                *HandleArray;
    119208  EFI_STATUS                Status;
    120 
     209  BOOLEAN                   AtLeastOneConnected;
     210  EFI_PCI_IO_PROTOCOL       *PciIo;
     211  UINT8                     Class[3];
     212 
    121213  DevPath = NULL;
    122214  Length  = 0;
     215  AtLeastOneConnected = FALSE;
    123216
    124217  //
     
    128221  if (Status == EFI_BUFFER_TOO_SMALL) {
    129222    DevPath = AllocateZeroPool(Length);
     223    if (DevPath == NULL) {
     224      return EFI_OUT_OF_RESOURCES;
     225    }
    130226    Status = gRT->GetVariable((CHAR16*)Key, (EFI_GUID*)&gEfiGlobalVariableGuid, NULL, &Length, DevPath);
     227    if (EFI_ERROR (Status)) {
     228      if (DevPath != NULL) {
     229        FreePool (DevPath);
     230      }
     231      return Status;
     232    }
     233  } else if (EFI_ERROR (Status)) {
     234    return Status;
    131235  }
    132236
    133237  Status = EFI_NOT_FOUND;
     238
     239  CopyOfDevPath = DevPath;
    134240  //
    135241  // walk the list of devices and connect them
    136242  //
    137   for (DevPathWalker = DevPath
    138     ;  DevPathWalker < (DevPath + Length) && EFI_ERROR(Status) && DevPath != NULL
    139     ;  DevPathWalker += GetDevicePathSize(DevPathWalker)
    140    ){
    141     //
    142     // get the correct handle from a given device path
    143     //
    144     if ((StrCmp(Key, L"ConInDev") == 0)
    145       ||(StrCmp(Key, L"ConIn") == 0)
    146     ){
    147       Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleInDeviceGuid, &DevPathWalker, &Handle);
    148       if (!EFI_ERROR(Status)) {
    149         Status = ConnectControllers(NULL, Handle, FALSE, TRUE, FALSE);
    150       }
    151     } else if ((StrCmp(Key, L"ConOutDev") == 0)
    152             || (StrCmp(Key, L"ConErrDev") == 0)
    153             || (StrCmp(Key, L"ConOut")    == 0)
    154             || (StrCmp(Key, L"ConErr")    == 0)
    155             ){
    156       Status = gBS->LocateDevicePath((EFI_GUID*)&gEfiConsoleOutDeviceGuid, &DevPathWalker, &Handle);
    157       if (!EFI_ERROR(Status)) {
    158         Status = ConnectControllers(NULL, Handle, FALSE, TRUE, FALSE);
    159       }
    160     }
    161   }
    162 
     243  do {
     244    //
     245    // Check every instance of the console variable
     246    //
     247    Instance = GetNextDevicePathInstance (&CopyOfDevPath, &Size);
     248    if (Instance == NULL) {
     249      if (DevPath != NULL) {
     250        FreePool (DevPath);
     251      }
     252      return EFI_UNSUPPORTED;
     253    }
     254
     255    Next = Instance;
     256    while (!IsDevicePathEndType (Next)) {
     257      Next = NextDevicePathNode (Next);
     258    }
     259
     260    SetDevicePathEndNode (Next);
     261    //
     262    // connect short form device path
     263    //
     264    if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&
     265      ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)
     266      || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)
     267      )) {
     268     
     269      Status = ShellConnectPciRootBridge ();
     270      if (EFI_ERROR(Status)) {
     271        FreePool(Instance);
     272        FreePool(DevPath);
     273        return Status;
     274      }
     275     
     276      Status = gBS->LocateHandleBuffer (
     277                  ByProtocol,
     278                  &gEfiPciIoProtocolGuid,
     279                  NULL,
     280                  &HandleArrayCount,
     281                  &HandleArray
     282                  );
     283     
     284      if (!EFI_ERROR (Status)) {
     285        for (Index = 0; Index < HandleArrayCount; Index++) {
     286          Status = gBS->HandleProtocol (
     287                      HandleArray[Index],
     288                      &gEfiPciIoProtocolGuid,
     289                      (VOID **)&PciIo
     290                      );
     291         
     292          if (!EFI_ERROR (Status)) {
     293            Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0x09, 3, &Class);
     294            if (!EFI_ERROR (Status)) {
     295              if ((PCI_CLASS_SERIAL == Class[2]) &&
     296                  (PCI_CLASS_SERIAL_USB == Class[1])) {
     297                Status = gBS->ConnectController (
     298                              HandleArray[Index],
     299                              NULL,
     300                              Instance,
     301                              FALSE
     302                              );
     303                if (!EFI_ERROR(Status)) {
     304                  AtLeastOneConnected = TRUE;
     305                }
     306              }
     307            }
     308          }
     309        }
     310      }
     311
     312      if (HandleArray != NULL) {
     313        FreePool (HandleArray);
     314      }
     315    } else {
     316      //
     317      // connect the entire device path
     318      //
     319      Status = ShellConnectDevicePath (Instance);
     320      if (!EFI_ERROR (Status)) {
     321        AtLeastOneConnected = TRUE;
     322      }
     323    }
     324    FreePool (Instance);
     325   
     326  } while (CopyOfDevPath != NULL);
     327 
    163328  if (DevPath != NULL) {
    164329    FreePool(DevPath);
    165330  }
    166   return (Status);
     331
     332  if (AtLeastOneConnected) {
     333    return EFI_SUCCESS;
     334  } else {
     335    return EFI_NOT_FOUND;
     336  }
     337 
    167338}
    168339
     
    252423
    253424  ShellStatus         = SHELL_SUCCESS;
    254 
    255425  //
    256426  // initialize the shell lib (we must be in non-auto-init...)
     
    300470      }
    301471      if (EFI_ERROR(Status)) {
    302         ConnectFromDevPaths(L"ConErrDev");
    303       } else {
    304         Status = ConnectFromDevPaths(L"ConErrDev");
    305       }
    306       if (EFI_ERROR(Status)) {
    307         ConnectFromDevPaths(L"ConErr");
    308       } else {
    309         Status = ConnectFromDevPaths(L"ConErr");
     472        ConnectFromDevPaths(L"ErrOutDev");
     473      } else {
     474        Status = ConnectFromDevPaths(L"ErrOutDev");
     475      }
     476      if (EFI_ERROR(Status)) {
     477        ConnectFromDevPaths(L"ErrOut");
     478      } else {
     479        Status = ConnectFromDevPaths(L"ErrOut");
    310480      }
    311481      if (EFI_ERROR(Status)) {
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DevTree.c

    r48674 r58459  
    22  Main file for DevTree shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
     5  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    5859
    5960  ASSERT(TheHandle    != NULL);
     61 
     62  if (ShellGetExecutionBreakFlag()) {
     63    ShellStatus = SHELL_ABORTED;
     64    return ShellStatus;
     65  }
     66 
    6067  //
    6168  // We want controller handles.  they will not have LoadedImage or DriverBinding (or others...)
     
    8390  if (!EFI_ERROR (Status)) {
    8491    return SHELL_SUCCESS;
    85   }
    86 
    87   //
    88   // If we are at the begining then we want root handles they have no parents and do have device path.
    89   //
    90   if (IndentCharCount == 0) {
    91     Status = gBS->OpenProtocol (
    92                   TheHandle,
    93                   &gEfiDevicePathProtocolGuid,
    94                   NULL,
    95                   NULL,
    96                   NULL,
    97                   EFI_OPEN_PROTOCOL_TEST_PROTOCOL
    98                  );
    99     if (EFI_ERROR (Status)) {
    100       return SHELL_SUCCESS;
    101     }
    10292  }
    10393
     
    137127  for (LoopVar = 0 ; LoopVar < ChildCount && ShellStatus == SHELL_SUCCESS; LoopVar++){
    138128    ShellStatus = DoDevTreeForHandle(ChildHandleBuffer[LoopVar], Lang, UseDevPaths, IndentCharCount+2, HiiString);
     129    if (ShellStatus == SHELL_ABORTED) {
     130      break;
     131    }
    139132  }
    140133
     
    170163  BOOLEAN             FlagD;
    171164  UINT64              Intermediate;
     165  UINTN               ParentControllerHandleCount;
     166  EFI_HANDLE          *ParentControllerHandleBuffer;
    172167
    173168  ShellStatus         = SHELL_SUCCESS;
     
    227222          break;
    228223        }
     224
     225        //
     226        // Skip handles that do not have device path protocol
     227        //
     228        Status = gBS->OpenProtocol (
     229                      TheHandle,
     230                      &gEfiDevicePathProtocolGuid,
     231                      NULL,
     232                      NULL,
     233                      NULL,
     234                      EFI_OPEN_PROTOCOL_TEST_PROTOCOL
     235                     );
     236        if (EFI_ERROR (Status)) {
     237          continue;
     238        }
     239
     240        //
     241        // Skip handles that do have parents
     242        //
     243        ParentControllerHandleBuffer = NULL;
     244        Status = PARSE_HANDLE_DATABASE_PARENTS (
     245                   TheHandle,
     246                   &ParentControllerHandleCount,
     247                   &ParentControllerHandleBuffer
     248                   );
     249        SHELL_FREE_NON_NULL (ParentControllerHandleBuffer);
     250        if (ParentControllerHandleCount > 0) {
     251          continue;
     252        }
     253
     254        //
     255        // Start a devtree from TheHandle that has a device path and no parents
     256        //
    229257        ShellStatus = DoDevTreeForHandle(TheHandle, Language, FlagD, 0, HiiString);
    230258      }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c

    r48674 r58459  
    22  Main file for devices shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2012-2014, Hewlett-Packard Development Company, L.P.<BR>
     5  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    115116
    116117STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
     118  {L"-sfo", TypeFlag},
    117119  {L"-l", TypeValue},
    118120  {NULL, TypeMax}
     
    147149  CHAR16              *Name;
    148150  CONST CHAR16        *Lang;
     151  BOOLEAN             SfoFlag;
    149152
    150153  ShellStatus         = SHELL_SUCCESS;
    151154  Language            = NULL;
     155  SfoFlag             = FALSE;
    152156
    153157  //
     
    204208      //
    205209      // Print Header
    206       //
    207       ShellPrintHiiEx(-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);
     210
     211      //
     212      if (ShellCommandLineGetFlag (Package, L"-sfo")) {
     213        ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDriver1HiiHandle, L"devices");
     214        SfoFlag = TRUE;
     215      } else {
     216        ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);
     217      }
    208218
    209219      //
     
    223233        Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);
    224234        if (Name != NULL && (Parents != 0 || Devices != 0 || Children != 0)) {
    225           ShellPrintHiiEx(
     235          ShellPrintHiiEx (
    226236            -1,
    227237            -1,
    228238            Language,
    229             STRING_TOKEN (STR_DEVICES_ITEM_LINE),
     239            SfoFlag?STRING_TOKEN (STR_DEVICES_ITEM_LINE_SFO):STRING_TOKEN (STR_DEVICES_ITEM_LINE),
    230240            gShellDriver1HiiHandle,
    231             ConvertHandleToHandleIndex(*HandleListWalker),
     241            ConvertHandleToHandleIndex (*HandleListWalker),
    232242            Type,
    233             Cfg?L'X':L'-',
    234             Diag?L'X':L'-',
     243            Cfg?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'),
     244            Diag?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'),
    235245            Parents,
    236246            Devices,
     
    241251          FreePool(Name);
    242252        }
     253        if (ShellGetExecutionBreakFlag ()) {
     254          ShellStatus = SHELL_ABORTED;
     255          break;
     256        }
     257       
    243258      }
    244259
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Dh.c

    r48674 r58459  
    22  Main file for Dh shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
     5  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    6162{
    6263  CHAR8                             *Lang;
    63   CHAR8                             *TempChar;
    6464  EFI_STATUS                        Status;
    6565  EFI_COMPONENT_NAME2_PROTOCOL      *CompName2;
     
    8888    return (EFI_NOT_FOUND);
    8989  }
    90   if (Language == NULL) {
    91     Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));
    92     if (Lang == NULL) {
    93       return (EFI_OUT_OF_RESOURCES);
    94     }
    95     AsciiStrCpy(Lang, CompName2->SupportedLanguages);
    96     TempChar = AsciiStrStr(Lang, ";");
    97     if (TempChar != NULL){
    98       *TempChar = CHAR_NULL;
    99     }
    100   } else {
    101     Lang = AllocateZeroPool(AsciiStrSize(Language));
    102     if (Lang == NULL) {
    103       return (EFI_OUT_OF_RESOURCES);
    104     }
    105     AsciiStrCpy(Lang, Language);
    106   }
     90  Lang = GetBestLanguageForDriver (CompName2->SupportedLanguages, Language, FALSE);
    10791  Status = CompName2->GetDriverName(CompName2, Lang, &NameToReturn);
    10892  FreePool(Lang);
     
    203187            StrnCatGrow(&RetVal, &Size, L"(", 0);
    204188            StrnCatGrow(&RetVal, &Size, Temp, 0);
    205             StrnCatGrow(&RetVal, &Size, L")", 0);
     189            StrnCatGrow(&RetVal, &Size, L")\r\n", 0);
    206190          } else {
    207191            StrnCatGrow(&RetVal, &Size, Seperator, 0);
     
    261245  }
    262246  DevicePath = LoadedImage->FilePath;
    263   *Name = gDevPathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);
     247  *Name = ConvertDevicePathToText(DevicePath, TRUE, TRUE);
    264248  return (EFI_SUCCESS);
    265249}
     
    301285  BOOLEAN                     Image;
    302286
     287  DriverName = NULL;
     288
    303289  //
    304290  // See if Handle is a device handle and display its details.
     
    355341    SHELL_FREE_NON_NULL(TempStringPointer);
    356342 
    357     TempStringPointer = gDevPathToText->ConvertDevicePathToText(DevicePath, TRUE, FALSE);
     343    TempStringPointer = ConvertDevicePathToText(DevicePath, TRUE, FALSE);
    358344    ShellPrintHiiEx(
    359345      -1,
     
    395381                  &DriverName
    396382                  );
    397         if (DriverName == NULL) {
     383        if (EFI_ERROR (Status)) {
    398384          Status = GetDriverImageName (
    399385                    DriverBindingHandleBuffer[Index],
    400386                    &DriverName
    401387                    );
     388          if (EFI_ERROR (Status)) {
     389            DriverName = NULL;
     390          }
    402391        }
    403392
     
    538527
    539528  Status = GetDriverName (Handle, Language, &DriverName);
     529  if (EFI_ERROR (Status)) {
     530    DriverName = NULL;
     531  }
    540532
    541533  ShellPrintHiiEx(
     
    549541    );
    550542  SHELL_FREE_NON_NULL(DriverName);
    551   DriverName = NULL;
    552543  Status = GetDriverImageName (
    553544            Handle,
    554545            &DriverName
    555546            );
     547  if (EFI_ERROR (Status)) {
     548    DriverName = NULL;
     549  }
    556550  ShellPrintHiiEx(
    557551    -1,
     
    667661  CHAR16              *ProtocolInfoString;
    668662  SHELL_STATUS        ShellStatus;
    669   EFI_STATUS          Status;
    670 
    671   Status              = EFI_SUCCESS;
     663
    672664  ShellStatus         = SHELL_SUCCESS;
    673665  ProtocolInfoString  = NULL;
     
    729721
    730722  @param[in] HandleList       The NULL-terminated list of handles.
     723  @param[in] Verbose          TRUE for extra info, FALSE otherwise.
    731724  @param[in] Sfo              TRUE to output in standard format output (spec).
    732725  @param[in] Language         Language string per UEFI specification.
     
    740733DoDhForHandleList(
    741734  IN CONST EFI_HANDLE *HandleList,
     735  IN CONST BOOLEAN    Verbose,
    742736  IN CONST BOOLEAN    Sfo,
    743737  IN CONST CHAR8      *Language,
     
    753747    ShellStatus = DoDhByHandle(
    754748          *HandleWalker,
    755           FALSE,
     749          Verbose,
    756750          Sfo,
    757751          Language,
     
    759753          TRUE
    760754         );
     755    if (ShellGetExecutionBreakFlag ()) {
     756      ShellStatus = SHELL_ABORTED;
     757      break;
     758    }
    761759  }
    762760  return (ShellStatus);
     
    767765
    768766  @param[in] Sfo              TRUE to output in standard format output (spec).
     767  @param[in] Verbose          TRUE for extra info, FALSE otherwise.
    769768  @param[in] Language         Language string per UEFI specification.
    770769  @param[in] DriverInfo       TRUE to show all info about the handle.
     
    777776DoDhForAll(
    778777  IN CONST BOOLEAN  Sfo,
     778  IN CONST BOOLEAN  Verbose,
    779779  IN CONST CHAR8    *Language,
    780780  IN CONST BOOLEAN  DriverInfo
     
    788788  ShellStatus = DoDhForHandleList(
    789789    HandleList,
     790    Verbose,
    790791    Sfo,
    791792    Language,
     
    801802
    802803  @param[in] ProtocolName     The pointer to the name of the protocol.
     804  @param[in] Verbose          TRUE for extra info, FALSE otherwise.
    803805  @param[in] Sfo              TRUE to output in standard format output (spec).
    804806  @param[in] Language         Language string per UEFI specification.
     
    812814DoDhByProtocol(
    813815  IN CONST CHAR16   *ProtocolName,
     816  IN CONST BOOLEAN  Verbose,
    814817  IN CONST BOOLEAN  Sfo,
    815818  IN CONST CHAR8    *Language,
     
    836839  ShellStatus = DoDhForHandleList(
    837840    HandleList,
     841    Verbose,
    838842    Sfo,
    839843    Language,
     
    933937        ShellStatus = DoDhByProtocol(
    934938          ShellCommandLineGetValue(Package, L"-p"),
     939          Verbose,
    935940          SfoMode,
    936941          Lang==NULL?NULL:Language,
     
    946951        ShellStatus = DoDhForAll(
    947952          SfoMode,
     953          Verbose,
    948954          Lang==NULL?NULL:Language,
    949955          FlagD
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c

    r48674 r58459  
    22  Main file for Disconnect shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    164164          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param3);
    165165          ShellStatus = SHELL_INVALID_PARAMETER;
    166         } else if (EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiDevicePathProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
    167           ASSERT(Param1 != NULL);
    168           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, ShellStrToUintn(Param1), L"controller handle");
    169           ShellStatus = SHELL_INVALID_PARAMETER;
    170166        } else if (Handle2 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
    171167          ASSERT(Param2 != NULL);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Drivers.c

    r48674 r58459  
    22  Main file for Drivers shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2012-2014, Hewlett-Packard Development Company, L.P.<BR>
     5  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    1415
    1516#include "UefiShellDriver1CommandsLib.h"
     17
     18#define MAX_LEN_DRIVER_NAME 35
    1619
    1720STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
     
    8184  RetVal = gEfiShellProtocol->GetFilePathFromDevicePath(FinalPath);
    8285  if (RetVal == NULL) {
    83     RetVal = gDevPathToText->ConvertDevicePathToText(FinalPath, TRUE, TRUE);
     86    RetVal = ConvertDevicePathToText(FinalPath, TRUE, TRUE);
    8487  }
    8588  FreePool(FinalPath);
     
    186189  UINTN               DeviceCount;
    187190  CHAR16              *Temp2;
     191  CONST CHAR16        *FullDriverName;
     192  CHAR16              *TruncatedDriverName;
    188193  CHAR16              *FormatString;
    189194  UINT32              DriverVersion;
    190195  BOOLEAN             DriverConfig;
    191196  BOOLEAN             DriverDiag;
     197  BOOLEAN             SfoFlag;
    192198
    193199  ShellStatus         = SHELL_SUCCESS;
     
    195201  Language            = NULL;
    196202  FormatString        = NULL;
     203  SfoFlag             = FALSE;
    197204
    198205  //
     
    222229      ShellStatus = SHELL_INVALID_PARAMETER;
    223230    } else {
    224       Lang = ShellCommandLineGetValue(Package, L"-l");
    225       if (Lang != NULL) {
    226         Language = AllocateZeroPool(StrSize(Lang));
    227         AsciiSPrint(Language, StrSize(Lang), "%S", Lang);
    228       } else if (!ShellCommandLineGetFlag(Package, L"-l")){
    229         ASSERT(Language == NULL);
    230   //      Language = AllocateZeroPool(10);
    231   //      AsciiSPrint(Language, 10, "en-us");
     231      if (ShellCommandLineGetFlag(Package, L"-l")){
     232        Lang = ShellCommandLineGetValue(Package, L"-l");
     233        if (Lang != NULL) {
     234          Language = AllocateZeroPool(StrSize(Lang));
     235          AsciiSPrint(Language, StrSize(Lang), "%S", Lang);
     236        } else {
     237          ASSERT(Language == NULL);
     238          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l");
     239          ShellCommandLineFreeVarList (Package);
     240          return (SHELL_INVALID_PARAMETER);
     241        }
     242      }
     243
     244      if (ShellCommandLineGetFlag (Package, L"-sfo")) {
     245        SfoFlag = TRUE;
     246        FormatString = HiiGetString (gShellDriver1HiiHandle, STRING_TOKEN (STR_DRIVERS_ITEM_LINE_SFO), Language);
     247        //
     248        // print the SFO header
     249        //
     250        ShellPrintHiiEx (
     251          -1,
     252          -1,
     253          Language,
     254          STRING_TOKEN (STR_GEN_SFO_HEADER),
     255          gShellDriver1HiiHandle,
     256          L"drivers");
    232257      } else {
    233         ASSERT(Language == NULL);
    234         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l");
    235         ShellCommandLineFreeVarList (Package);
    236         return (SHELL_INVALID_PARAMETER);
    237       }
    238 
    239       if (ShellCommandLineGetFlag(Package, L"-sfo")) {
    240         FormatString = HiiGetString(gShellDriver1HiiHandle, STRING_TOKEN(STR_DRIVERS_ITEM_LINE_SFO), Language);
    241       } else {
    242         FormatString = HiiGetString(gShellDriver1HiiHandle, STRING_TOKEN(STR_DRIVERS_ITEM_LINE), Language);
     258        FormatString = HiiGetString (gShellDriver1HiiHandle, STRING_TOKEN (STR_DRIVERS_ITEM_LINE), Language);
    243259        //
    244260        // print the header row
     
    248264          -1,
    249265          Language,
    250           STRING_TOKEN(STR_DRIVERS_HEADER_LINES),
     266          STRING_TOKEN (STR_DRIVERS_HEADER_LINES),
    251267          gShellDriver1HiiHandle);
    252268      }
     
    254270      HandleList = GetHandleListByProtocol(&gEfiDriverBindingProtocolGuid);
    255271      for (HandleWalker = HandleList ; HandleWalker != NULL && *HandleWalker != NULL ; HandleWalker++){
    256         ChildCount    = 0;
    257         DeviceCount   = 0;
    258         Status        = ParseHandleDatabaseForChildDevices (*HandleWalker, &ChildCount , NULL);
    259         Status        = PARSE_HANDLE_DATABASE_DEVICES      (*HandleWalker, &DeviceCount, NULL);
    260         Temp2         = GetDevicePathTextForHandle(*HandleWalker);
    261         DriverVersion = ReturnDriverVersion(*HandleWalker);
    262         DriverConfig  = ReturnDriverConfig(*HandleWalker);
    263         DriverDiag    = ReturnDriverDiag  (*HandleWalker);
    264         Lang          = GetStringNameFromHandle(*HandleWalker, Language==NULL?"en":Language);
     272        ChildCount     = 0;
     273        DeviceCount    = 0;
     274        Status         = ParseHandleDatabaseForChildDevices (*HandleWalker, &ChildCount , NULL);
     275        Status         = PARSE_HANDLE_DATABASE_DEVICES      (*HandleWalker, &DeviceCount, NULL);
     276        Temp2          = GetDevicePathTextForHandle(*HandleWalker);
     277        DriverVersion  = ReturnDriverVersion(*HandleWalker);
     278        DriverConfig   = ReturnDriverConfig(*HandleWalker);
     279        DriverDiag     = ReturnDriverDiag  (*HandleWalker);
     280        FullDriverName = GetStringNameFromHandle(*HandleWalker, Language);
     281
     282        TruncatedDriverName = NULL;
     283        if (!SfoFlag && (FullDriverName != NULL)) {
     284          TruncatedDriverName = AllocateZeroPool ((MAX_LEN_DRIVER_NAME + 1) * sizeof (CHAR16));
     285          StrnCpy (TruncatedDriverName, FullDriverName, MAX_LEN_DRIVER_NAME);
     286        }
    265287
    266288        ShellPrintEx(
     
    275297          DeviceCount,
    276298          ChildCount,
    277           Lang,
     299          SfoFlag?FullDriverName:TruncatedDriverName,
    278300          Temp2==NULL?L"":Temp2
    279301         );
     302        if (TruncatedDriverName != NULL) {
     303          FreePool (TruncatedDriverName);
     304        }
    280305        if (Temp2 != NULL) {
    281306          FreePool(Temp2);
     307        }
     308       
     309        if (ShellGetExecutionBreakFlag ()) {
     310          ShellStatus = SHELL_ABORTED;
     311          break;
    282312        }
    283313      }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c

    r48674 r58459  
    22  Main file for DrvCfg shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    407407                // print out an error.
    408408                //
    409                 TempDevPathString = gDevPathToText->ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), TRUE, TRUE);
     409                TempDevPathString = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), TRUE, TRUE);
    410410                ShellPrintHiiEx(
    411411                  -1,
     
    515515  default:
    516516    return (EFI_INVALID_PARAMETER);
    517     break;
    518517  }
    519518
     
    10961095
    10971096  if (!Found) {
    1098     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle);
     1097    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE_FOUND), gShellDriver1HiiHandle);
    10991098    return (SHELL_SUCCESS);
    11001099  }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/DrvDiag.c

    r48674 r58459  
    22  Main file for DrvDiag shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    7272  UINTN                               HandleIndex2;
    7373  CHAR8                               *Language;
    74   CHAR8                               *TempChar;
    7574  BOOLEAN                             Found;
    7675
     
    181180                NULL,
    182181                EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    183               if (!EFI_ERROR(Status)) {
    184                 if (Lang == NULL) {
    185                   Language = AllocateZeroPool(AsciiStrSize(DriverDiagnostics2->SupportedLanguages));
    186                   if (Language == NULL) {
    187                     return (EFI_OUT_OF_RESOURCES);
    188                   }
    189                   AsciiStrCpy(Language, DriverDiagnostics2->SupportedLanguages);
    190                   TempChar = AsciiStrStr(Language, ";");
    191                   if (TempChar != NULL){
    192                     *TempChar = CHAR_NULL;
    193                   }
    194                 } else {
    195                   Language = AllocateZeroPool(AsciiStrSize(Lang));
    196                   if (Language == NULL) {
    197                     return (EFI_OUT_OF_RESOURCES);
    198                   }
    199                   AsciiStrCpy(Language, Lang);
    200                 }
     182              if (!EFI_ERROR(Status) && (DriverDiagnostics2 != NULL)) {
     183                Language = GetBestLanguageForDriver(DriverDiagnostics2->SupportedLanguages, Lang, FALSE);
    201184                Found = TRUE;
    202185                Status = DriverDiagnostics2->RunDiagnostics(
     
    221204                EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    222205              if (!EFI_ERROR(Status)) {
    223                 if (Lang == NULL) {
    224                   Language = AllocateZeroPool(AsciiStrSize(DriverDiagnostics2->SupportedLanguages));
    225                   if (Language == NULL) {
    226                     return (EFI_OUT_OF_RESOURCES);
    227                   }
    228                   AsciiStrCpy(Language, DriverDiagnostics2->SupportedLanguages);
    229                   TempChar = AsciiStrStr(Language, ";");
    230                   if (TempChar != NULL){
    231                     *TempChar = CHAR_NULL;
    232                   }
    233                 } else {
    234                   Language = AllocateZeroPool(AsciiStrSize(Lang));
    235                   if (Language == NULL) {
    236                     return (EFI_OUT_OF_RESOURCES);
    237                   }
    238                   AsciiStrCpy(Language, Lang);
    239                 }
     206                Language = GetBestLanguageForDriver(DriverDiagnostics->SupportedLanguages, Lang, FALSE);
    240207                Status = DriverDiagnostics->RunDiagnostics(
    241208                  DriverDiagnostics,
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/OpenInfo.c

    r48674 r58459  
    4949  UINTN                               HandleIndex;
    5050  CONST CHAR16                        *Name;
     51  UINTN                               ControllerIndex;
    5152
    5253  if (TheHandle == NULL) {
     
    99100            default:                                    OpenTypeString = StringUnknown;   break;
    100101          }
    101           HandleIndex = ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].AgentHandle);
    102           Name        = GetStringNameFromHandle(OpenInfo[OpenInfoIndex].AgentHandle, "en");
    103           if (OpenInfo[OpenInfoIndex].ControllerHandle!=NULL) {
     102          HandleIndex     = ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].AgentHandle);
     103          Name            = GetStringNameFromHandle(OpenInfo[OpenInfoIndex].AgentHandle, NULL);
     104          ControllerIndex = ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].ControllerHandle);
     105          if (ControllerIndex != 0) {
    104106            ShellPrintHiiEx(
    105107              -1,
     
    109111              gShellDriver1HiiHandle,
    110112              HandleIndex,
    111               ConvertHandleToHandleIndex(OpenInfo[OpenInfoIndex].ControllerHandle),
     113              ControllerIndex,
    112114              OpenInfo[OpenInfoIndex].OpenCount,
    113115              OpenTypeString,
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.c

    r48674 r58459  
    22  Main file for NULL named library for level 1 shell command functions.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.h

    r48674 r58459  
    22  Main file for NULL named library for Profile1 shell command functions.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    2323#include <Guid/ConsoleOutDevice.h>
    2424#include <Guid/ShellLibHiiGuid.h>
     25
     26#include <IndustryStandard/Pci.h>
    2527
    2628#include <Protocol/EfiShell.h>
     
    2931#include <Protocol/LoadedImage.h>
    3032#include <Protocol/UnicodeCollation.h>
    31 #include <Protocol/DevicePathToText.h>
    3233#include <Protocol/DriverDiagnostics2.h>
    3334#include <Protocol/DriverDiagnostics.h>
     
    3839#include <Protocol/DriverFamilyOverride.h>
    3940#include <Protocol/DriverHealth.h>
     41#include <Protocol/PciIo.h>
     42#include <Protocol/PciRootBridgeIo.h>
    4043
    4144#include <Library/BaseLib.h>
     
    5659#include <Library/HandleParsingLib.h>
    5760#include <Library/PeCoffGetEntryPointLib.h>
     61#include <Library/HandleParsingLib.h>
    5862
    5963
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf

    r48674 r58459  
    22# Provides shell driver1 profile functions
    33#
    4 # Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
    55#
    66#  This program and the accompanying materials
     
    5959
    6060[Pcd]
    61   gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask  # ALWAYS_CONSUMED
     61  gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask  ## CONSUMES
    6262
    6363[Protocols]
    64   gEfiDriverHealthProtocolGuid                    # ALWAYS_CONSUMED
    65   gEfiDriverFamilyOverrideProtocolGuid            # ALWAYS_CONSUMED
    66   gEfiHiiConfigAccessProtocolGuid                 # ALWAYS_CONSUMED
    67   gEfiHiiDatabaseProtocolGuid                     # ALWAYS_CONSUMED
     64  gEfiDriverHealthProtocolGuid                    ## CONSUMES
     65  gEfiDriverFamilyOverrideProtocolGuid            ## CONSUMES
     66  gEfiHiiConfigAccessProtocolGuid                 ## CONSUMES
     67  gEfiHiiDatabaseProtocolGuid                     ## CONSUMES
    6868
    6969[Guids]
    70   gEfiGlobalVariableGuid                          # ALWAYS_CONSUMED
    71   gEfiConsoleInDeviceGuid                         # ALWAYS_CONSUMED
    72   gEfiConsoleOutDeviceGuid                        # ALWAYS_CONSUMED
    73   gShellDriver1HiiGuid                            ## PRODUCES
     70  gEfiGlobalVariableGuid                          ## CONSUMES ## GUID
     71  gEfiConsoleInDeviceGuid                         ## CONSUMES ## GUID
     72  gEfiConsoleOutDeviceGuid                        ## CONSUMES ## GUID
     73  gShellDriver1HiiGuid                            ## PRODUCES ## HII
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c

    r48674 r58459  
    22  Main file for Unload shell Driver1 function.
    33
    4   Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1414
    1515#include "UefiShellDriver1CommandsLib.h"
    16 
    17 /**
    18   Function to translate the EFI_MEMORY_TYPE into a string.
    19 
    20   @param[in] Memory     The memory type.
    21 
    22   @retval               A string representation of the type allocated from BS Pool.
    23 **/
    24 CHAR16*
    25 EFIAPI
    26 ConvertMemoryType (
    27   IN CONST EFI_MEMORY_TYPE Memory
    28   )
    29 {
    30   CHAR16 *RetVal;
    31   RetVal = NULL;
    32 
    33   switch (Memory) {
    34   case EfiReservedMemoryType:       StrnCatGrow(&RetVal, NULL, L"EfiReservedMemoryType", 0);        break;
    35   case EfiLoaderCode:               StrnCatGrow(&RetVal, NULL, L"EfiLoaderCode", 0);                break;
    36   case EfiLoaderData:               StrnCatGrow(&RetVal, NULL, L"EfiLoaderData", 0);                break;
    37   case EfiBootServicesCode:         StrnCatGrow(&RetVal, NULL, L"EfiBootServicesCode", 0);          break;
    38   case EfiBootServicesData:         StrnCatGrow(&RetVal, NULL, L"EfiBootServicesData", 0);          break;
    39   case EfiRuntimeServicesCode:      StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesCode", 0);       break;
    40   case EfiRuntimeServicesData:      StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesData", 0);       break;
    41   case EfiConventionalMemory:       StrnCatGrow(&RetVal, NULL, L"EfiConventionalMemory", 0);        break;
    42   case EfiUnusableMemory:           StrnCatGrow(&RetVal, NULL, L"EfiUnusableMemory", 0);            break;
    43   case EfiACPIReclaimMemory:        StrnCatGrow(&RetVal, NULL, L"EfiACPIReclaimMemory", 0);         break;
    44   case EfiACPIMemoryNVS:            StrnCatGrow(&RetVal, NULL, L"EfiACPIMemoryNVS", 0);             break;
    45   case EfiMemoryMappedIO:           StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIO", 0);            break;
    46   case EfiMemoryMappedIOPortSpace:  StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIOPortSpace", 0);   break;
    47   case EfiPalCode:                  StrnCatGrow(&RetVal, NULL, L"EfiPalCode", 0);                   break;
    48   case EfiMaxMemoryType:            StrnCatGrow(&RetVal, NULL, L"EfiMaxMemoryType", 0);             break;
    49   default: ASSERT(FALSE);
    50   }
    51   return (RetVal);
    52 }
    5316
    5417/**
     
    6629  )
    6730{
    68   EFI_LOADED_IMAGE_PROTOCOL         *Image;
    69   EFI_STATUS                        Status;
    70   EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevicePathToText;
    71   CHAR16                            *DevicePathText;
    72   CHAR16                            *CodeTypeText;
    73   CHAR16                            *DataTypeText;
    74   CHAR8                             *PdbPointer;
     31  CHAR16 *TheString;
    7532
    76   Image = NULL;
     33  TheString = GetProtocolInformationDump(TheHandle, &gEfiLoadedImageProtocolGuid, TRUE);
     34 
     35  ShellPrintEx(-1, -1, L"%s", TheString);
    7736
    78   Status = gBS->OpenProtocol(TheHandle, &gEfiLoadedImageProtocolGuid, (VOID**)&Image, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
    79   if (EFI_ERROR(Status)) {
    80     return (EFI_INVALID_PARAMETER);
    81   }
    82 
    83   Status = gBS->LocateProtocol(
    84     &gEfiDevicePathToTextProtocolGuid,
    85     NULL,
    86     (VOID**)&DevicePathToText);
    87   //
    88   // we now have the device path to text protocol
    89   //
    90   if (!EFI_ERROR(Status)) {
    91     DevicePathText = DevicePathToText->ConvertDevicePathToText(Image->FilePath, TRUE, TRUE);
    92   } else {
    93     DevicePathText = NULL;
    94   }
    95 
    96   CodeTypeText = ConvertMemoryType(Image->ImageCodeType);
    97   DataTypeText = ConvertMemoryType(Image->ImageDataType);
    98   PdbPointer = (CHAR8*)PeCoffLoaderGetPdbPointer(Image->ImageBase);
    99   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_UNLOAD_VERBOSE), gShellDriver1HiiHandle,
    100     ConvertHandleToHandleIndex(TheHandle),
    101     TheHandle,
    102     Image,
    103     Image->ParentHandle,
    104     Image->SystemTable,
    105     Image->DeviceHandle,
    106     DevicePathText,
    107     PdbPointer,
    108     Image->ImageBase,
    109     Image->ImageSize,
    110     CodeTypeText,
    111     DataTypeText
    112     );
    113 
    114   SHELL_FREE_NON_NULL(DevicePathText);
    115   SHELL_FREE_NON_NULL(CodeTypeText);
    116   SHELL_FREE_NON_NULL(DataTypeText);
    117 
     37  SHELL_FREE_NON_NULL(TheString);
     38 
    11839  return (EFI_SUCCESS);
    11940}
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.c

    r48674 r58459  
    1313**/
    1414
    15 #include "UefiShellInstall1CommandsLib.h"
    16 
    17 STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
    18 EFI_HANDLE gShellInstall1HiiHandle = NULL;
    19 
    20 /**
    21   Function to get the filename with help context if HII will not be used.
    22 
    23   @return   The filename with help text in it.
    24 **/
    25 CONST CHAR16*
    26 EFIAPI
    27 ShellCommandGetManFileNameInstall1 (
    28   VOID
    29   )
    30 {
    31   return (mFileName);
    32 }
     15#include <Library/BcfgCommandLib.h>
    3316
    3417/**
     
    5740  }
    5841
    59   gShellInstall1HiiHandle = HiiAddPackages (&gShellInstall1HiiGuid, gImageHandle, UefiShellInstall1CommandsLibStrings, NULL);
    60   if (gShellInstall1HiiHandle == NULL) {
    61     return (EFI_DEVICE_ERROR);
    62   }
    63 
    64   //
    65   // install our shell command handlers that are always installed
    66   //
    67   ShellCommandRegisterCommandName(L"bcfg", ShellCommandRunBcfgInstall , ShellCommandGetManFileNameInstall1, 0, L"Install", FALSE, gShellInstall1HiiHandle, STRING_TOKEN(STR_GET_HELP_BCFG));
    68 
    69   return (EFI_SUCCESS);
     42  return (BcfgLibraryRegisterBcfgCommand(ImageHandle, SystemTable, L"Install1"));
    7043}
    7144
     
    8356  )
    8457{
    85   if (gShellInstall1HiiHandle != NULL) {
    86     HiiRemovePackages(gShellInstall1HiiHandle);
    87   }
    88   return (EFI_SUCCESS);
     58  return (BcfgLibraryUnregisterBcfgCommand(ImageHandle, SystemTable));
    8959}
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf

    r48674 r58459  
    22#  Provides shell install1 functions
    33#
    4 #  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved. <BR>
     4#  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
    55#
    66#  This program and the accompanying materials
     
    2525[Sources.common]
    2626  UefiShellInstall1CommandsLib.c
    27   UefiShellInstall1CommandsLib.h
    28   UefiShellInstall1CommandsLib.uni
    29   Bcfg.c
    3027
    3128[Packages]
     
    4643  SortLib
    4744  PrintLib
     45  BcfgCommandLib
    4846
    4947[Pcd]
    50   gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask # ALWAYS_CONSUMED
     48  gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask ## CONSUMES
    5149
    5250[Guids]
    53   gShellInstall1HiiGuid
     51  gShellInstall1HiiGuid                         ## UNDEFINED
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c

    r48674 r58459  
    22  Main file for endfor and for shell level 1 functions.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    252252  }
    253253  return (FALSE);
     254}
     255
     256/**
     257  Function to determine whether a string is decimal or hex representation of a number
     258  and return the number converted from the string.
     259
     260  @param[in] String   String representation of a number
     261
     262  @return             the number
     263  @retval (UINTN)(-1) An error ocurred.
     264**/
     265UINTN
     266EFIAPI
     267ReturnUintn(
     268  IN CONST CHAR16 *String
     269  )
     270{
     271  UINT64        RetVal;
     272
     273  if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, FALSE, TRUE))) {
     274    return ((UINTN)RetVal);
     275  }
     276  return ((UINTN)(-1));
    254277}
    255278
     
    272295  CHAR16              *ArgSet;
    273296  CHAR16              *ArgSetWalker;
     297  CHAR16              *Parameter;
    274298  UINTN               ArgSize;
    275299  UINTN               LoopVar;
     
    287311  ArgSetWalker        = NULL;
    288312  TempString          = NULL;
     313  Parameter           = NULL;
    289314  FirstPass           = FALSE;
    290315
     
    311336  ASSERT(CurrentScriptFile != NULL);
    312337
    313   if (CurrentScriptFile->CurrentCommand->Data == NULL) {
     338  if ((CurrentScriptFile->CurrentCommand != NULL) && (CurrentScriptFile->CurrentCommand->Data == NULL)) {
    314339    FirstPass = TRUE;
    315340
     
    326351        L"EndFor",
    327352        L"For",
    328         CurrentScriptFile->CurrentCommand!=NULL
    329           ?CurrentScriptFile->CurrentCommand->Line:0);
     353        CurrentScriptFile->CurrentCommand->Line);
    330354      return (SHELL_DEVICE_ERROR);
    331355    }
     
    348372      for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
    349373        ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
    350         if (ArgSet == NULL) {
    351   //        ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
    352         } else {
    353           ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
    354         }
    355374        if (StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL
    356375          ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL
     
    360379          Status = ShellOpenFileMetaArg ((CHAR16*)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList);
    361380          if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
     381            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
    362382            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
     383            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
    363384          } else {
    364385            for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
     
    373394          }
    374395        } else {
    375           ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
    376         }
    377         ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
     396          Parameter = gEfiShellParametersProtocol->Argv[LoopVar];
     397          if (Parameter[0] == L'\"' && Parameter[StrLen(Parameter)-1] == L'\"') {
     398            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
     399            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Parameter, 0);
     400          } else {
     401            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
     402            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Parameter, 0);
     403            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
     404          }
     405        }
    378406      }
    379407      if (ArgSet == NULL) {
     
    426454        Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));
    427455        ASSERT(Info != NULL);
     456        Info->Signature = SHELL_FOR_INFO_SIGNATURE;
    428457        CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));
    429458        Info->ReplacementName = Info->Set;
     
    438467            gShellLevel1HiiHandle,
    439468            ArgSet,
    440             CurrentScriptFile!=NULL
    441               && CurrentScriptFile->CurrentCommand!=NULL
    442               ? CurrentScriptFile->CurrentCommand->Line:0);
     469            CurrentScriptFile->CurrentCommand->Line);
    443470          ShellStatus = SHELL_INVALID_PARAMETER;
    444471        } else {
     
    462489              STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
    463490              gShellLevel1HiiHandle,
    464               CurrentScriptFile!=NULL
    465                 && CurrentScriptFile->CurrentCommand!=NULL
    466                 ? CurrentScriptFile->CurrentCommand->Line:0);
     491              CurrentScriptFile->CurrentCommand->Line);
    467492            ShellStatus = SHELL_INVALID_PARAMETER;
    468493          } else {
     
    480505                gShellLevel1HiiHandle,
    481506                ArgSet,
    482                 CurrentScriptFile!=NULL
    483                   && CurrentScriptFile->CurrentCommand!=NULL
    484                   ? CurrentScriptFile->CurrentCommand->Line:0);
     507                CurrentScriptFile->CurrentCommand->Line);
    485508              ShellStatus = SHELL_INVALID_PARAMETER;
    486509            } else {
    487510              if (ArgSetWalker[0] == L'-') {
    488                 Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
     511                Info->Current = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
    489512              } else {
    490                 Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);
     513                Info->Current = (INTN)ReturnUintn(ArgSetWalker);
    491514              }
    492515              ArgSetWalker  = StrStr(ArgSetWalker, L" ");
     
    502525                  gShellLevel1HiiHandle,
    503526                  ArgSet,
    504                   CurrentScriptFile!=NULL
    505                     && CurrentScriptFile->CurrentCommand!=NULL
    506                     ? CurrentScriptFile->CurrentCommand->Line:0);
     527                  CurrentScriptFile->CurrentCommand->Line);
    507528                ShellStatus = SHELL_INVALID_PARAMETER;
    508529              } else {
    509530                if (ArgSetWalker[0] == L'-') {
    510                   Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
     531                  Info->End = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
    511532                } else {
    512                   Info->End = (INTN)ShellStrToUintn(ArgSetWalker);
     533                  Info->End = (INTN)ReturnUintn(ArgSetWalker);
    513534                }
    514535                if (Info->Current < Info->End) {
     
    531552                      gShellLevel1HiiHandle,
    532553                      ArgSet,
    533                       CurrentScriptFile!=NULL
    534                         && CurrentScriptFile->CurrentCommand!=NULL
    535                         ? CurrentScriptFile->CurrentCommand->Line:0);
     554                      CurrentScriptFile->CurrentCommand->Line);
    536555                    ShellStatus = SHELL_INVALID_PARAMETER;
    537556                  } else {
     
    540559                    } else {
    541560                      if (ArgSetWalker[0] == L'-') {
    542                         Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
     561                        Info->Step = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
    543562                      } else {
    544                         Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);
     563                        Info->Step = (INTN)ReturnUintn(ArgSetWalker);
    545564                      }
    546565
     
    553572                          gShellLevel1HiiHandle,
    554573                          ArgSet,
    555                           CurrentScriptFile!=NULL
    556                             && CurrentScriptFile->CurrentCommand!=NULL
    557                             ? CurrentScriptFile->CurrentCommand->Line:0);
     574                          CurrentScriptFile->CurrentCommand->Line);
    558575                        ShellStatus = SHELL_INVALID_PARAMETER;
    559576                      }
     
    660677      ASSERT(Info->Set != NULL);
    661678      if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) {
    662         if (Info->CurrentValue[0] == L'\"') {
     679        if (Info->CurrentValue[0] == L' ') {
    663680          Info->CurrentValue++;
    664681        }
    665 //        while (Info->CurrentValue[0] == L' ') {
    666 //          Info->CurrentValue++;
    667 //        }
    668682        if (Info->CurrentValue[0] == L'\"') {
    669683          Info->CurrentValue++;
     
    690704            Info->CurrentValue++;
    691705          }
    692           while (Info->CurrentValue[0] == L' ') {
    693             Info->CurrentValue++;
    694           }
    695           if (Info->CurrentValue[0] == L'\"') {
    696             Info->CurrentValue++;
    697           }
    698706          FreePool(TempString);
    699707        }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c

    r48674 r58459  
    22  Main file for If and else shell level 1 function.
    33
     4  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
    45  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
     
    167168    }
    168169    return (FALSE);
    169     break;
    170170  case OperatorUnsignedLessThan:
    171171  case OperatorLessThan:
     
    203203    }
    204204    return (FALSE);
    205     break;
    206205  case OperatorEqual:
    207206    if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
     
    231230    }
    232231    return (FALSE);
    233     break;
    234232  case OperatorNotEqual:
    235233    if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
     
    259257    }
    260258    return (FALSE);
    261     break;
    262259  case OperatorUnsignedGreaterOrEqual:
    263260  case OperatorGreatorOrEqual:
     
    294291    }
    295292    return (FALSE);
    296     break;
    297293  case OperatorLessOrEqual:
    298294  case OperatorUnsignedLessOrEqual:
     
    329325    }
    330326    return (FALSE);
    331     break;
    332327  default:
    333328    ASSERT(FALSE);
     
    663658  )
    664659{
    665   CHAR16    *Buffer;
    666   UINTN     BufferSize;
    667 
    668660  *EndTag = EndTagMax;
    669661
    670   for(Buffer = NULL, BufferSize = 0
     662  for(
    671663    ; ParameterNumber < gEfiShellParametersProtocol->Argc
    672664    ; ParameterNumber++
     
    744736    }
    745737    CommandWalker = CommandName;
    746     while (CommandWalker[0] == L' ') {
     738
     739    //
     740    // Skip leading spaces and tabs.
     741    //
     742    while ((CommandWalker[0] == L' ') || (CommandWalker[0] == L'\t')) {
    747743      CommandWalker++;
    748744    }
     
    857853      STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
    858854      gShellLevel1HiiHandle,
    859       L"EnfIf",
     855      L"EndIf",
    860856      L"If",
    861857      CurrentScriptFile!=NULL
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c

    r48674 r58459  
    22  Main file for NULL named library for level 1 shell command functions.
    33
     4  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
    45  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
     
    151152
    152153  CommandNameWalker = CommandName;
    153   while(CommandNameWalker[0] == L' ') {
     154
     155  //
     156  // Skip leading spaces and tabs.
     157  //
     158  while ((CommandNameWalker[0] == L' ') || (CommandNameWalker[0] == L'\t')) {
    154159    CommandNameWalker++;
    155160  }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h

    r48674 r58459  
    22  Main file for NULL named library for level 1 shell command functions.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    2626#include <Protocol/LoadedImage.h>
    2727#include <Protocol/UnicodeCollation.h>
    28 #include <Protocol/DevicePathToText.h>
    2928
    3029#include <Library/BaseLib.h>
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf

    r48674 r58459  
    22#  Provides shell level 1 functions
    33#
    4 #  Copyright (c) 2009-2011, Intel Corporation. All rights reserved. <BR>
     4#  Copyright (c) 2009-2015, Intel Corporation. All rights reserved. <BR>
    55#
    66#  This program and the accompanying materials
     
    5454
    5555[Pcd.common]
    56   gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED
     56  gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel ## CONSUMES
    5757
    5858[Guids]
    59   gShellLevel1HiiGuid
     59  gShellLevel1HiiGuid       ## SOMETIMES_CONSUMES ## HII
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Attrib.c

    r48674 r58459  
    22  Main file for attrib shell level 2 function.
    33
     4  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
    45  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
     
    153154                FileNode->FileName
    154155               );
     156               
     157              if (ShellGetExecutionBreakFlag()) {
     158                  ShellStatus = SHELL_ABORTED;
     159                  break;
     160              }
    155161            }
    156162            Status = ShellCloseFileMetaArg(&ListOfFiles);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c

    r48674 r58459  
    22  Main file for attrib shell level 2 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    3939  CONST CHAR16      *Param1;
    4040  CHAR16            *Param1Copy;
     41  CHAR16*           Walker;
    4142
    4243  ProblemParam = NULL;
     
    9798    } else {
    9899      Param1Copy = CatSPrint(NULL, L"%s", Param1, NULL);
     100      for (Walker = Param1Copy; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
     101        if (*Walker == L'\"') {
     102          CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
     103        }
     104      }
     105     
    99106      if (Param1Copy != NULL) {
    100107        Param1Copy = PathCleanUpDirectories(Param1Copy);
     
    150157          }
    151158        } else if (StrStr(Param1Copy, L":") == NULL) {
     159          //
     160          // change directory without a drive identifier
     161          //
    152162          if (ShellGetCurrentDir(NULL) == NULL) {
    153163            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
     
    190200        } else {
    191201          //
    192           // change directory on other drive letter
    193           //
    194           Drive = AllocateZeroPool(StrSize(Param1Copy));
     202          // change directory with a drive letter
     203          //
     204          Drive = AllocateCopyPool(StrSize(Param1Copy), Param1Copy);
    195205          if (Drive == NULL) {
    196206            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
    197207            ShellStatus = SHELL_OUT_OF_RESOURCES;
    198208          } else {
    199             Drive = StrCpy(Drive, Param1Copy);
    200209            Path = StrStr(Drive, L":");
    201210            ASSERT(Path != NULL);
    202             if (*(Path+1) == CHAR_NULL) {
     211            if (EFI_ERROR(ShellIsDirectory(Param1Copy))) {
     212              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, Param1Copy);
     213              ShellStatus = SHELL_NOT_FOUND;
     214            } else if (*(Path+1) == CHAR_NULL) {
    203215              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CD_NF), gShellLevel2HiiHandle);
    204216              ShellStatus = SHELL_NOT_FOUND;
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c

    r48674 r58459  
    22  Main file for cp shell level 2 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    1414
    1515#include "UefiShellLevel2CommandsLib.h"
     16#include <Guid/FileSystemInfo.h>
     17#include <Guid/FileSystemVolumeLabelInfo.h>
    1618
    1719/**
     
    6365  )
    6466{
    65   VOID                *Response;
    66   UINTN               ReadSize;
    67   SHELL_FILE_HANDLE   SourceHandle;
    68   SHELL_FILE_HANDLE   DestHandle;
    69   EFI_STATUS          Status;
    70   VOID                *Buffer;
    71   CHAR16              *TempName;
    72   UINTN               Size;
    73   EFI_SHELL_FILE_INFO *List;
    74   SHELL_STATUS        ShellStatus;
    75 
     67  VOID                  *Response;
     68  UINTN                 ReadSize;
     69  SHELL_FILE_HANDLE     SourceHandle;
     70  SHELL_FILE_HANDLE     DestHandle;
     71  EFI_STATUS            Status;
     72  VOID                  *Buffer;
     73  CHAR16                *TempName;
     74  UINTN                 Size;
     75  EFI_SHELL_FILE_INFO   *List;
     76  SHELL_STATUS          ShellStatus;
     77  UINT64                SourceFileSize;
     78  UINT64                DestFileSize;
     79  EFI_FILE_PROTOCOL     *DestVolumeFP;
     80  EFI_FILE_SYSTEM_INFO  *DestVolumeInfo;
     81  UINTN                 DestVolumeInfoSize;
    7682
    7783  ASSERT(Resp != NULL);
    7884
    79   SourceHandle  = NULL;
    80   DestHandle    = NULL;
    81   Response      = *Resp;
    82   List          = NULL;
    83 
    84   ReadSize = PcdGet16(PcdShellFileOperationSize);
     85  SourceHandle    = NULL;
     86  DestHandle      = NULL;
     87  Response        = *Resp;
     88  List            = NULL;
     89  DestVolumeInfo  = NULL;
     90  ShellStatus     = SHELL_SUCCESS;
     91
     92  ReadSize = PcdGet32(PcdShellFileOperationSize);
    8593  // Why bother copying a file to itself
    8694  if (StrCmp(Source, Dest) == 0) {
     
    8997
    9098  //
    91   // Open destination file without create
    92   //
    93   Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
    94 
    95   //
    96   // close file
    97   //
    98   if (DestHandle != NULL) {
    99     ShellCloseFile(&DestHandle);
    100     DestHandle   = NULL;
    101   }
    102 
    103   //
    10499  // if the destination file existed check response and possibly prompt user
    105100  //
    106   if (!EFI_ERROR(Status)) {
     101  if (ShellFileExists(Dest) == EFI_SUCCESS) {
    107102    if (Response == NULL && !SilentMode) {
    108103      Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
     
    137132    Status = ShellCreateDirectory(Dest, &DestHandle);
    138133    if (EFI_ERROR(Status)) {
     134      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, Dest);
    139135      return (SHELL_ACCESS_DENIED);
    140136    }
     
    144140    //
    145141    TempName    = NULL;
    146     Size          = 0;
     142    Size        = 0;
    147143    StrnCatGrow(&TempName, &Size, Source, 0);
    148144    StrnCatGrow(&TempName, &Size, L"\\*", 0);
    149     ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List);
    150     TempName = NULL;
    151     StrnCatGrow(&TempName, &Size, Dest, 0);
    152     StrnCatGrow(&TempName, &Size, L"\\", 0);
    153     ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp);
    154     ShellCloseFileMetaArg(&List);
    155     FreePool(TempName);
    156     Size = 0;
     145    if (TempName != NULL) {
     146      ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List);
     147      *TempName = CHAR_NULL;
     148      StrnCatGrow(&TempName, &Size, Dest, 0);
     149      StrnCatGrow(&TempName, &Size, L"\\", 0);
     150      ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp);
     151      ShellCloseFileMetaArg(&List);
     152      SHELL_FREE_NON_NULL(TempName);
     153      Size = 0;
     154    }
    157155  } else {
     156    Status = ShellDeleteFileByName(Dest);
     157
    158158    //
    159159    // open file with create enabled
     
    161161    Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
    162162    if (EFI_ERROR(Status)) {
     163      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, Dest);
    163164      return (SHELL_ACCESS_DENIED);
    164165    }
     
    171172
    172173    //
    173     // copy data between files
    174     //
    175     Buffer = AllocateZeroPool(ReadSize);
    176     ASSERT(Buffer != NULL);
    177     while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {
    178       Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);
    179       ASSERT_EFI_ERROR(Status);
    180       Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
    181     }
    182   }
    183 
     174    //get file size of source file and freespace available on destination volume
     175    //
     176    ShellGetFileSize(SourceHandle, &SourceFileSize);
     177    ShellGetFileSize(DestHandle, &DestFileSize);
     178
     179    //
     180    //if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space
     181    //
     182    if(DestFileSize < SourceFileSize){
     183      SourceFileSize -= DestFileSize;
     184    } else {
     185      SourceFileSize = 0;
     186    }
     187
     188    //
     189    //get the system volume info to check the free space
     190    //
     191    DestVolumeFP = ConvertShellHandleToEfiFileProtocol(DestHandle);
     192    DestVolumeInfo = NULL;
     193    DestVolumeInfoSize = 0;
     194    Status = DestVolumeFP->GetInfo(
     195      DestVolumeFP,
     196      &gEfiFileSystemInfoGuid,
     197      &DestVolumeInfoSize,
     198      DestVolumeInfo
     199      );
     200
     201    if (Status == EFI_BUFFER_TOO_SMALL) {
     202      DestVolumeInfo = AllocateZeroPool(DestVolumeInfoSize);
     203      Status = DestVolumeFP->GetInfo(
     204        DestVolumeFP,
     205        &gEfiFileSystemInfoGuid,
     206        &DestVolumeInfoSize,
     207        DestVolumeInfo
     208        );
     209    }
     210
     211    //
     212    //check if enough space available on destination drive to complete copy
     213    //
     214    if (DestVolumeInfo!= NULL && (DestVolumeInfo->FreeSpace < SourceFileSize)) {
     215      //
     216      //not enough space on destination directory to copy file
     217      //
     218      SHELL_FREE_NON_NULL(DestVolumeInfo);
     219      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle);
     220      return(SHELL_VOLUME_FULL);
     221    } else {
     222      //
     223      // copy data between files
     224      //
     225      Buffer = AllocateZeroPool(ReadSize);
     226      ASSERT(Buffer != NULL);
     227      while (ReadSize == PcdGet32(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {
     228        Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);
     229        if (!EFI_ERROR(Status)) {
     230          Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
     231          if (EFI_ERROR(Status)) {
     232            ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
     233            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, Dest);
     234            break;
     235          }
     236        } else {
     237          ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
     238          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, Source);
     239          break;
     240        }
     241      }
     242    }
     243    SHELL_FREE_NON_NULL(DestVolumeInfo);
     244  }
     245 
    184246  //
    185247  // close files
     
    197259  // return
    198260  //
    199   return (SHELL_SUCCESS);
     261  return ShellStatus;
    200262}
    201263
     
    234296  CONST EFI_SHELL_FILE_INFO *Node;
    235297  SHELL_STATUS              ShellStatus;
     298  EFI_STATUS                Status;
    236299  CHAR16                    *DestPath;
    237300  VOID                      *Response;
    238   UINTN                     PathLen;
     301  UINTN                     PathSize;
    239302  CONST CHAR16              *Cwd;
    240   CONST CHAR16              *TempLocation;
    241303  UINTN                     NewSize;
     304  CHAR16                    *CleanFilePathStr;
    242305
    243306  if (Resp == NULL) {
     
    247310  }
    248311
    249   DestPath    = NULL;
    250   ShellStatus = SHELL_SUCCESS;
    251   PathLen     = 0;
    252   Cwd         = ShellGetCurrentDir(NULL);
     312  DestPath         = NULL;
     313  ShellStatus      = SHELL_SUCCESS;
     314  PathSize         = 0;
     315  Cwd              = ShellGetCurrentDir(NULL);
     316  CleanFilePathStr = NULL;
    253317
    254318  ASSERT(FileList != NULL);
    255319  ASSERT(DestDir  != NULL);
    256320
    257   //
    258   // We already verified that this was present.
    259   //
    260   ASSERT(Cwd      != NULL);
     321 
     322  Status = ShellLevel2StripQuotes (DestDir, &CleanFilePathStr);
     323  if (EFI_ERROR (Status)) {
     324    if (Status == EFI_OUT_OF_RESOURCES) {
     325      return SHELL_OUT_OF_RESOURCES;
     326    } else {
     327      return SHELL_INVALID_PARAMETER;
     328    }
     329  }
     330 
     331  ASSERT (CleanFilePathStr != NULL);
    261332
    262333  //
    263334  // If we are trying to copy multiple files... make sure we got a directory for the target...
    264335  //
    265   if (EFI_ERROR(ShellIsDirectory(DestDir)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
     336  if (EFI_ERROR(ShellIsDirectory(CleanFilePathStr)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
    266337    //
    267338    // Error for destination not a directory
    268339    //
    269     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
     340    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, CleanFilePathStr);
     341    FreePool (CleanFilePathStr);
    270342    return (SHELL_INVALID_PARAMETER);
    271343  }
     
    273345    ;  !IsNull(&FileList->Link, &Node->Link)
    274346    ;  Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
    275    ){
     347    ){
    276348    //
    277349    // skip the directory traversing stuff...
     
    281353    }
    282354
    283     NewSize =  StrSize(DestDir);
     355    NewSize =  StrSize(CleanFilePathStr);
    284356    NewSize += StrSize(Node->FullName);
    285     NewSize += StrSize(Cwd);
    286     if (NewSize > PathLen) {
    287       PathLen = NewSize;
     357    NewSize += (Cwd == NULL)? 0 : StrSize(Cwd);
     358    if (NewSize > PathSize) {
     359      PathSize = NewSize;
    288360    }
    289361
     
    293365    if (!RecursiveMode && !EFI_ERROR(ShellIsDirectory(Node->FullName))) {
    294366      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle);
     367      FreePool (CleanFilePathStr);
    295368      return (SHELL_INVALID_PARAMETER);
    296369    }
     
    299372    // make sure got dest as dir if needed
    300373    //
    301     if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(DestDir))) {
     374    if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(CleanFilePathStr))) {
    302375      //
    303376      // Error for destination not a directory
    304377      //
    305       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, DestDir);
     378      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, CleanFilePathStr);
     379      FreePool (CleanFilePathStr);
    306380      return (SHELL_INVALID_PARAMETER);
    307381    }
     
    310384  HiiOutput   = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);
    311385  HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
    312   DestPath    = AllocateZeroPool(PathLen);
     386  DestPath    = AllocateZeroPool(PathSize);
    313387
    314388  if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {
     
    316390    SHELL_FREE_NON_NULL(HiiOutput);
    317391    SHELL_FREE_NON_NULL(HiiResultOk);
     392    FreePool (CleanFilePathStr);
    318393    return (SHELL_OUT_OF_RESOURCES);
    319394  }
     
    325400    ;  !IsNull(&FileList->Link, &Node->Link)
    326401    ;  Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
    327    ){
     402    ){
    328403    if (ShellGetExecutionBreakFlag()) {
    329404      break;
     
    340415
    341416    if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item
    342       && EFI_ERROR(ShellIsDirectory(DestDir))                 // not an existing directory
    343      ) {
    344       if (StrStr(DestDir, L":") == NULL) {
     417      && EFI_ERROR(ShellIsDirectory(CleanFilePathStr))                 // not an existing directory
     418      ) {
     419      if (StrStr(CleanFilePathStr, L":") == NULL) {
    345420        //
    346421        // simple copy of a single file
    347422        //
    348         StrCpy(DestPath, Cwd);
    349         if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
    350           StrCat(DestPath, L"\\");
    351         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
     423        if (Cwd != NULL) {
     424          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16)-1);
     425        } else {
     426          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, CleanFilePathStr);
     427          FreePool (CleanFilePathStr);
     428          return (SHELL_INVALID_PARAMETER);
     429        }
     430        if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
     431          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
     432        } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
    352433          ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
    353434        }
    354         StrCat(DestPath, DestDir);
     435        StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
    355436      } else {
    356         StrCpy(DestPath, DestDir);
     437        StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);
    357438      }
    358439    } else {
     
    364445      // Check for leading slash
    365446      //
    366       if (DestDir[0] == L'\\') {
     447      if (CleanFilePathStr[0] == L'\\') {
    367448         //
    368449         // Copy to the root of CWD
    369450         //
    370         StrCpy(DestPath, Cwd);
     451        if (Cwd != NULL) {
     452          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);
     453        } else {
     454          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, CleanFilePathStr);
     455          FreePool(CleanFilePathStr);
     456          return (SHELL_INVALID_PARAMETER);
     457        }
    371458        while (PathRemoveLastItem(DestPath));
    372         StrCat(DestPath, DestDir+1);
    373         StrCat(DestPath, Node->FileName);
    374       } else if (StrStr(DestDir, L":") == NULL) {
    375         StrCpy(DestPath, Cwd);
    376         if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
    377           StrCat(DestPath, L"\\");
    378         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
     459        StrnCat(DestPath, CleanFilePathStr+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
     460        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
     461      } else if (StrStr(CleanFilePathStr, L":") == NULL) {
     462        if (Cwd != NULL) {
     463          StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);
     464        } else {
     465          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, CleanFilePathStr);
     466          FreePool(CleanFilePathStr);
     467          return (SHELL_INVALID_PARAMETER);
     468        }
     469        if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
     470          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
     471        } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
    379472          ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
    380473        }
    381         StrCat(DestPath, DestDir);
    382         if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
    383           StrCat(DestPath, L"\\");
    384         } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
     474        StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
     475        if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
     476          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
     477        } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
    385478          ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
    386479        }
    387         StrCat(DestPath, Node->FileName);
     480        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
    388481
    389482      } else {
    390         StrCpy(DestPath, DestDir);
    391         if (DestDir[StrLen(DestDir)-1] != L'\\' && Node->FileName[0] != L'\\') {
    392           StrCat(DestPath, L"\\");
    393         } else if (DestDir[StrLen(DestDir)-1] == L'\\' && Node->FileName[0] == L'\\') {
    394           ((CHAR16*)DestDir)[StrLen(DestDir)-1] = CHAR_NULL;
    395         }
    396         StrCat(DestPath, Node->FileName);
     483        StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);
     484        if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
     485          StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
     486        } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
     487          ((CHAR16*)CleanFilePathStr)[StrLen(CleanFilePathStr)-1] = CHAR_NULL;
     488        }
     489        StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
    397490      }
    398491    }
    399 
     492   
    400493    //
    401494    // Make sure the path exists
     
    410503      && !EFI_ERROR(ShellIsDirectory(DestPath))
    411504      && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == NULL
    412      ){
     505      ){
    413506      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle);
    414507      ShellStatus = SHELL_INVALID_PARAMETER;
     
    421514    }
    422515
    423     if ((TempLocation = StrniCmp(Node->FullName, DestPath, StrLen(Node->FullName))) == 0
     516    if ((StrniCmp(Node->FullName, DestPath, StrLen(Node->FullName)) == 0)
    424517      && (DestPath[StrLen(Node->FullName)] == CHAR_NULL || DestPath[StrLen(Node->FullName)] == L'\\')
    425      ) {
     518      ) {
    426519      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle);
    427520      ShellStatus = SHELL_INVALID_PARAMETER;
     
    431524    PathCleanUpDirectories(DestPath);
    432525
    433     ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
     526    if (!SilentMode) {
     527      ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
     528    }
    434529
    435530    //
     
    448543  SHELL_FREE_NON_NULL(HiiOutput);
    449544  SHELL_FREE_NON_NULL(HiiResultOk);
     545  SHELL_FREE_NON_NULL(CleanFilePathStr);
    450546  if (Resp == NULL) {
    451547    SHELL_FREE_NON_NULL(Response);
     
    453549
    454550  return (ShellStatus);
     551
    455552}
    456553
     
    478575  SHELL_STATUS        ShellStatus;
    479576  EFI_SHELL_FILE_INFO *List;
    480   EFI_STATUS          Status;
    481577  EFI_FILE_INFO       *FileInfo;
    482 
    483   List = NULL;
    484 
    485   Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
     578  CHAR16              *FullName;
     579
     580  List      = NULL;
     581  FullName  = NULL;
     582  FileInfo  = NULL;
     583
     584  ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
    486585  if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {
    487586    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);
     
    491590    ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
    492591    ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
    493     FileInfo    = NULL;
    494592    FileInfo = gEfiShellProtocol->GetFileInfo(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
    495593    ASSERT(FileInfo != NULL);
     594    StrnCatGrow(&FullName, NULL, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, 0);
     595    ShellCloseFileMetaArg(&List);
    496596    if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {
    497       ShellStatus = ValidateAndCopyFiles(FileList, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, SilentMode, RecursiveMode, NULL);
     597      ShellStatus = ValidateAndCopyFiles(FileList, FullName, SilentMode, RecursiveMode, NULL);
    498598    } else {
    499599      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle);
    500600      ShellStatus = SHELL_ACCESS_DENIED;
    501601    }
    502     SHELL_FREE_NON_NULL(FileInfo);
     602  } else {
    503603    ShellCloseFileMetaArg(&List);
    504   } else {
    505       ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
    506   }
    507 
     604    ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
     605  }
     606
     607  SHELL_FREE_NON_NULL(FileInfo);
     608  SHELL_FREE_NON_NULL(FullName);
    508609  return (ShellStatus);
    509610}
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Load.c

    r48674 r58459  
    8282  EFI_HANDLE                    LoadedDriverHandle;
    8383  EFI_STATUS                    Status;
    84   EFI_DEVICE_PATH_PROTOCOL      *Node;
    8584  EFI_DEVICE_PATH_PROTOCOL      *FilePath;
    8685  EFI_LOADED_IMAGE_PROTOCOL     *LoadedDriverImage;
     
    8887  LoadedDriverImage   = NULL;
    8988  FilePath            = NULL;
    90   Node                = NULL;
    9189  LoadedDriverHandle  = NULL;
    9290  Status              = EFI_SUCCESS;
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c

    r48674 r58459  
    22  Main file for ls shell level 2 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2013 - 2014, Hewlett-Packard Development Company, L.P.<BR>
     5  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    1516#include "UefiShellLevel2CommandsLib.h"
    1617#include <Guid/FileSystemInfo.h>
     18
     19/**
     20  print out the standard format output volume entry.
     21
     22  @param[in] TheList           a list of files from the volume.
     23**/
     24EFI_STATUS
     25EFIAPI
     26PrintSfoVolumeInfoTableEntry(
     27  IN CONST EFI_SHELL_FILE_INFO *TheList
     28  )
     29{
     30  EFI_STATUS            Status;
     31  EFI_SHELL_FILE_INFO   *Node;
     32  CHAR16                *DirectoryName;
     33  EFI_FILE_SYSTEM_INFO  *SysInfo;
     34  UINTN                 SysInfoSize;
     35  SHELL_FILE_HANDLE     ShellFileHandle;
     36  EFI_FILE_PROTOCOL     *EfiFpHandle;
     37
     38  //
     39  // Get the first valid handle (directories)
     40  //
     41  for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&TheList->Link)
     42      ; !IsNull(&TheList->Link, &Node->Link) && Node->Handle == NULL
     43      ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&TheList->Link, &Node->Link)
     44     );
     45
     46  if (Node->Handle == NULL) {
     47    DirectoryName = GetFullyQualifiedPath(((EFI_SHELL_FILE_INFO *)GetFirstNode(&TheList->Link))->FullName);
     48
     49    //
     50    // We need to open something up to get system information
     51    //
     52    Status = gEfiShellProtocol->OpenFileByName(
     53      DirectoryName,
     54      &ShellFileHandle,
     55      EFI_FILE_MODE_READ
     56      );
     57
     58    ASSERT_EFI_ERROR(Status);
     59    FreePool(DirectoryName);
     60
     61    //
     62    // Get the Volume Info from ShellFileHandle
     63    //
     64    SysInfo     = NULL;
     65    SysInfoSize = 0;
     66    EfiFpHandle = ConvertShellHandleToEfiFileProtocol(ShellFileHandle);
     67    Status = EfiFpHandle->GetInfo(
     68      EfiFpHandle,
     69      &gEfiFileSystemInfoGuid,
     70      &SysInfoSize,
     71      SysInfo
     72      );
     73
     74    if (Status == EFI_BUFFER_TOO_SMALL) {
     75      SysInfo = AllocateZeroPool(SysInfoSize);
     76      Status = EfiFpHandle->GetInfo(
     77        EfiFpHandle,
     78        &gEfiFileSystemInfoGuid,
     79        &SysInfoSize,
     80        SysInfo
     81        );
     82    }
     83
     84    ASSERT_EFI_ERROR(Status);
     85
     86    gEfiShellProtocol->CloseFile(ShellFileHandle);
     87  } else {
     88    //
     89    // Get the Volume Info from Node->Handle
     90    //
     91    SysInfo = NULL;
     92    SysInfoSize = 0;
     93    EfiFpHandle = ConvertShellHandleToEfiFileProtocol(Node->Handle);
     94    Status = EfiFpHandle->GetInfo(
     95      EfiFpHandle,
     96      &gEfiFileSystemInfoGuid,
     97      &SysInfoSize,
     98      SysInfo
     99      );
     100
     101    if (Status == EFI_BUFFER_TOO_SMALL) {
     102      SysInfo = AllocateZeroPool(SysInfoSize);
     103      Status = EfiFpHandle->GetInfo(
     104        EfiFpHandle,
     105        &gEfiFileSystemInfoGuid,
     106        &SysInfoSize,
     107        SysInfo
     108        );
     109    }
     110
     111    ASSERT_EFI_ERROR(Status);
     112  }
     113
     114  ShellPrintHiiEx (
     115    -1,
     116    -1,
     117    NULL,
     118    STRING_TOKEN (STR_GEN_SFO_HEADER),
     119    gShellLevel2HiiHandle,
     120    L"ls"
     121    );
     122  //
     123  // print VolumeInfo table
     124  //
     125  ASSERT(SysInfo != NULL);
     126  ShellPrintHiiEx (
     127    0,
     128    gST->ConOut->Mode->CursorRow,
     129    NULL,
     130    STRING_TOKEN (STR_LS_SFO_VOLINFO),
     131    gShellLevel2HiiHandle,
     132    SysInfo->VolumeLabel,
     133    SysInfo->VolumeSize,
     134    SysInfo->ReadOnly?L"TRUE":L"FALSE",
     135    SysInfo->FreeSpace,
     136    SysInfo->BlockSize
     137    );
     138
     139  SHELL_FREE_NON_NULL(SysInfo);
     140
     141  return (Status);
     142}
     143
     144/**
     145  print out the info on a single file.
     146
     147  @param[in] Sfo      TRUE if in SFO, false otherwise.
     148  @param[in] TheNode  the EFI_SHELL_FILE_INFO node to print out information on.
     149  @param[in] Files    incremented if a file is printed.
     150  @param[in] Size     incremented by file size.
     151  @param[in] Dirs     incremented if a directory is printed.
     152
     153**/
     154VOID
     155EFIAPI
     156PrintFileInformation(
     157  IN CONST BOOLEAN              Sfo,
     158  IN CONST EFI_SHELL_FILE_INFO  *TheNode,
     159  IN UINT64                     *Files,
     160  IN UINT64                     *Size,
     161  IN UINT64                     *Dirs
     162  )
     163{
     164  ASSERT(Files    != NULL);
     165  ASSERT(Size     != NULL);
     166  ASSERT(Dirs     != NULL);
     167  ASSERT(TheNode  != NULL);
     168
     169  if (Sfo) {
     170    //
     171    // Print the FileInfo Table
     172    //
     173    ShellPrintHiiEx (
     174      0,
     175      gST->ConOut->Mode->CursorRow,
     176      NULL,
     177      STRING_TOKEN (STR_LS_SFO_FILEINFO),
     178      gShellLevel2HiiHandle,
     179      TheNode->FullName,
     180      TheNode->Info->FileSize,
     181      TheNode->Info->PhysicalSize,
     182      (TheNode->Info->Attribute & EFI_FILE_ARCHIVE)   != 0?L"a":L"",
     183      (TheNode->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"d":L"",
     184      (TheNode->Info->Attribute & EFI_FILE_HIDDEN)    != 0?L"h":L"",
     185      (TheNode->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L"r":L"",
     186      (TheNode->Info->Attribute & EFI_FILE_SYSTEM)    != 0?L"s":L"",
     187      TheNode->Info->CreateTime.Hour,
     188      TheNode->Info->CreateTime.Minute,
     189      TheNode->Info->CreateTime.Second,
     190      TheNode->Info->CreateTime.Day,
     191      TheNode->Info->CreateTime.Month,
     192      TheNode->Info->CreateTime.Year,
     193      TheNode->Info->LastAccessTime.Hour,
     194      TheNode->Info->LastAccessTime.Minute,
     195      TheNode->Info->LastAccessTime.Second,
     196      TheNode->Info->LastAccessTime.Day,
     197      TheNode->Info->LastAccessTime.Month,
     198      TheNode->Info->LastAccessTime.Year,
     199      TheNode->Info->ModificationTime.Hour,
     200      TheNode->Info->ModificationTime.Minute,
     201      TheNode->Info->ModificationTime.Second,
     202      TheNode->Info->ModificationTime.Day,
     203      TheNode->Info->ModificationTime.Month,
     204      TheNode->Info->ModificationTime.Year
     205      );
     206  } else {
     207    //
     208    // print this one out...
     209    // first print the universal start, next print the type specific name format, last print the CRLF
     210    //
     211    ShellPrintHiiEx (
     212      -1,
     213      -1,
     214      NULL,
     215      STRING_TOKEN (STR_LS_LINE_START_ALL),
     216      gShellLevel2HiiHandle,
     217      &TheNode->Info->ModificationTime,
     218      (TheNode->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"<DIR>":L"",
     219      (TheNode->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L'r':L' ',
     220      TheNode->Info->FileSize
     221      );
     222    if (TheNode->Info->Attribute & EFI_FILE_DIRECTORY) {
     223      (*Dirs)++;
     224      ShellPrintHiiEx (
     225        -1,
     226        -1,
     227        NULL,
     228        STRING_TOKEN (STR_LS_LINE_END_DIR),
     229        gShellLevel2HiiHandle,
     230        TheNode->FileName
     231        );
     232    } else {
     233      (*Files)++;
     234      (*Size) += TheNode->Info->FileSize;
     235      if ( (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".nsh", (CHAR16*)&(TheNode->FileName[StrLen (TheNode->FileName) - 4])) == 0)
     236        || (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".efi", (CHAR16*)&(TheNode->FileName[StrLen (TheNode->FileName) - 4])) == 0)
     237       ){
     238        ShellPrintHiiEx (
     239          -1,
     240          -1,
     241          NULL,
     242          STRING_TOKEN (STR_LS_LINE_END_EXE),
     243          gShellLevel2HiiHandle,
     244          TheNode->FileName
     245          );
     246      } else {
     247        ShellPrintHiiEx (
     248          -1,
     249          -1,
     250          NULL,
     251          STRING_TOKEN (STR_LS_LINE_END_FILE),
     252          gShellLevel2HiiHandle,
     253          TheNode->FileName
     254          );
     255      }
     256    }
     257  }
     258}
     259
     260/**
     261  print out the header when not using standard format output.
     262
     263  @param[in] Path           String with starting path.
     264**/
     265VOID
     266EFIAPI
     267PrintNonSfoHeader(
     268  IN CONST CHAR16 *Path
     269  )
     270{
     271  CHAR16 *DirectoryName;
     272
     273  //
     274  // get directory name from path...
     275  //
     276  DirectoryName = GetFullyQualifiedPath(Path);
     277
     278  if (DirectoryName != NULL) {
     279    //
     280    // print header
     281    //
     282    ShellPrintHiiEx (
     283      0,
     284      gST->ConOut->Mode->CursorRow,
     285      NULL,
     286      STRING_TOKEN (STR_LS_HEADER_LINE1),
     287      gShellLevel2HiiHandle,
     288      DirectoryName
     289      );
     290
     291    SHELL_FREE_NON_NULL(DirectoryName);
     292  }
     293}
     294
     295/**
     296  print out the footer when not using standard format output.
     297
     298  @param[in] Files            The number of files.
     299  @param[in] Size             The size of files in bytes.
     300  @param[in] Dirs             The number of directories.
     301**/
     302VOID
     303EFIAPI
     304PrintNonSfoFooter(
     305  IN UINT64                     Files,
     306  IN UINT64                     Size,
     307  IN UINT64                     Dirs
     308  )
     309{
     310  //
     311  // print footer
     312  //
     313  ShellPrintHiiEx (
     314    -1,
     315    -1,
     316    NULL,
     317    STRING_TOKEN (STR_LS_FOOTER_LINE),
     318    gShellLevel2HiiHandle,
     319    Files,
     320    Size,
     321    Dirs
     322   );
     323}
    17324
    18325/**
     
    24331                            If 0 then all non-system and non-hidden files will be printed.
    25332  @param[in] Sfo            TRUE to use Standard Format Output, FALSE otherwise
    26   @param[in] Path           String with starting path.
    27   @param[in] First          TRUE for the original and FALSE for any recursion spawned instances.
     333  @param[in] RootPath       String with starting path to search in.
     334  @param[in] SearchString   String with search string.
     335  @param[in] Found          Set to TRUE, if anyone were found.
    28336  @param[in] Count          The count of bits enabled in Attribs.
    29337  @param[in] TimeZone       The current time zone offset.
     
    37345  IN CONST UINT64  Attribs,
    38346  IN CONST BOOLEAN Sfo,
    39   IN CONST CHAR16  *Path,
    40   IN CONST BOOLEAN First,
     347  IN CONST CHAR16  *RootPath,
     348  IN CONST CHAR16  *SearchString,
     349  IN       BOOLEAN *Found,
    41350  IN CONST UINTN   Count,
    42351  IN CONST INT16   TimeZone
     
    50359  UINT64                DirCount;
    51360  UINT64                FileSize;
    52   CHAR16                *DirectoryName;
    53361  UINTN                 LongestPath;
    54   EFI_FILE_SYSTEM_INFO  *SysInfo;
    55   UINTN                 SysInfoSize;
    56   SHELL_FILE_HANDLE     ShellFileHandle;
    57362  CHAR16                *CorrectedPath;
    58   EFI_FILE_PROTOCOL     *EfiFpHandle;
    59 
     363  BOOLEAN               FoundOne;
     364  BOOLEAN               HeaderPrinted;
     365
     366  HeaderPrinted = FALSE;
    60367  FileCount     = 0;
    61368  DirCount      = 0;
     
    66373  CorrectedPath = NULL;
    67374
    68   CorrectedPath = StrnCatGrow(&CorrectedPath, NULL, Path, 0);
    69   ASSERT(CorrectedPath != NULL);
     375  if (Found != NULL) {
     376    FoundOne = *Found;
     377  } else {
     378    FoundOne = FALSE;
     379  }
     380
     381  CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath,     0);
     382  if (CorrectedPath == NULL) {
     383    return SHELL_OUT_OF_RESOURCES;
     384  }
     385  if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'
     386    &&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {
     387    CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\",     0);
     388  }
     389  CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, SearchString, 0);
     390  if (CorrectedPath == NULL) {
     391    return (SHELL_OUT_OF_RESOURCES);
     392  }
     393
    70394  PathCleanUpDirectories(CorrectedPath);
    71395
    72396  Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
    73   if (EFI_ERROR(Status)) {
    74     return (SHELL_DEVICE_ERROR);
    75   }
    76   if (ListHead == NULL || IsListEmpty(&ListHead->Link)) {
    77     //
    78     // On the first one only we expect to find something...
    79     // do we find the . and .. directories otherwise?
    80     //
    81     if (First) {
    82       return (SHELL_NOT_FOUND);
    83     }
    84     return (SHELL_SUCCESS);
    85   }
    86 
    87   if (Sfo && First) {
    88     //
    89     // Get the first valid handle (directories)
    90     //
    91     for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
    92         ; !IsNull(&ListHead->Link, &Node->Link) && Node->Handle == NULL
     397  if (!EFI_ERROR(Status)) {
     398    if (ListHead == NULL || IsListEmpty(&ListHead->Link)) {
     399      SHELL_FREE_NON_NULL(CorrectedPath);
     400      return (SHELL_SUCCESS);
     401    }
     402
     403    if (Sfo && Found == NULL) {
     404      PrintSfoVolumeInfoTableEntry(ListHead);
     405    }
     406
     407    for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link), LongestPath = 0
     408        ; !IsNull(&ListHead->Link, &Node->Link)
    93409        ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
    94        );
    95 
    96     if (Node->Handle == NULL) {
    97       DirectoryName = GetFullyQualifiedPath(((EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link))->FullName);
    98 
    99       //
    100       // We need to open something up to get system information
    101       //
    102       Status = gEfiShellProtocol->OpenFileByName(
    103         DirectoryName,
    104         &ShellFileHandle,
    105         EFI_FILE_MODE_READ);
    106 
    107       ASSERT_EFI_ERROR(Status);
    108       FreePool(DirectoryName);
    109 
    110       //
    111       // Get the Volume Info from ShellFileHandle
    112       //
    113       SysInfo     = NULL;
    114       SysInfoSize = 0;
    115       EfiFpHandle = ConvertShellHandleToEfiFileProtocol(ShellFileHandle);
    116       Status = EfiFpHandle->GetInfo(
    117         EfiFpHandle,
    118         &gEfiFileSystemInfoGuid,
    119         &SysInfoSize,
    120         SysInfo);
    121 
    122       if (Status == EFI_BUFFER_TOO_SMALL) {
    123         SysInfo = AllocateZeroPool(SysInfoSize);
    124         Status = EfiFpHandle->GetInfo(
    125           EfiFpHandle,
    126           &gEfiFileSystemInfoGuid,
    127           &SysInfoSize,
    128           SysInfo);
     410        ){
     411      if (ShellGetExecutionBreakFlag ()) {
     412        ShellStatus = SHELL_ABORTED;
     413        break;
    129414      }
    130 
    131       ASSERT_EFI_ERROR(Status);
    132 
    133       gEfiShellProtocol->CloseFile(ShellFileHandle);
    134     } else {
    135       //
    136       // Get the Volume Info from Node->Handle
    137       //
    138       SysInfo = NULL;
    139       SysInfoSize = 0;
    140       EfiFpHandle = ConvertShellHandleToEfiFileProtocol(Node->Handle);
    141       Status = EfiFpHandle->GetInfo(
    142         EfiFpHandle,
    143         &gEfiFileSystemInfoGuid,
    144         &SysInfoSize,
    145         SysInfo);
    146 
    147       if (Status == EFI_BUFFER_TOO_SMALL) {
    148         SysInfo = AllocateZeroPool(SysInfoSize);
    149         Status = EfiFpHandle->GetInfo(
    150           EfiFpHandle,
    151           &gEfiFileSystemInfoGuid,
    152           &SysInfoSize,
    153           SysInfo);
     415      ASSERT(Node != NULL);
     416      if (LongestPath < StrSize(Node->FullName)) {
     417        LongestPath = StrSize(Node->FullName);
    154418      }
    155 
    156       ASSERT_EFI_ERROR(Status);
    157     }
    158 
    159     ShellPrintHiiEx (
    160       -1,
    161       -1,
    162       NULL,
    163       STRING_TOKEN (STR_GEN_SFO_HEADER),
    164       gShellLevel2HiiHandle,
    165       L"ls");
    166     //
    167     // print VolumeInfo table
    168     //
    169     ASSERT(SysInfo != NULL);
    170     ShellPrintHiiEx (
    171       0,
    172       gST->ConOut->Mode->CursorRow,
    173       NULL,
    174       STRING_TOKEN (STR_LS_SFO_VOLINFO),
    175       gShellLevel2HiiHandle,
    176       SysInfo->VolumeLabel,
    177       SysInfo->VolumeSize,
    178       SysInfo->ReadOnly?L"TRUE":L"FALSE",
    179       SysInfo->FreeSpace,
    180       SysInfo->BlockSize
    181      );
    182     if (SysInfo != NULL) {
    183       FreePool(SysInfo);
    184     }
    185   }
    186 
    187   if (!Sfo) {
    188     //
    189     // get directory name from path...
    190     //
    191     DirectoryName = GetFullyQualifiedPath(CorrectedPath);
    192 
    193     //
    194     // print header
    195     //
    196     ShellPrintHiiEx (
    197       0,
    198       gST->ConOut->Mode->CursorRow,
    199       NULL,
    200       STRING_TOKEN (STR_LS_HEADER_LINE1),
    201       gShellLevel2HiiHandle,
    202       DirectoryName
    203      );
    204     FreePool(DirectoryName);
    205   }
    206   for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
    207       ; !IsNull(&ListHead->Link, &Node->Link)
    208       ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
    209      ){
    210     ASSERT(Node != NULL);
    211     if (LongestPath < StrSize(Node->FullName)) {
    212       LongestPath = StrSize(Node->FullName);
    213     }
    214     ASSERT(Node->Info != NULL);
    215     ASSERT((Node->Info->Attribute & EFI_FILE_VALID_ATTR) == Node->Info->Attribute);
    216     if (Attribs == 0) {
    217       //
    218       // NOT system & NOT hidden
    219       //
    220       if ( (Node->Info->Attribute & EFI_FILE_SYSTEM)
    221         || (Node->Info->Attribute & EFI_FILE_HIDDEN)
    222        ){
    223         continue;
    224       }
    225     } else if (Attribs != EFI_FILE_VALID_ATTR) {
    226       if (Count == 1) {
     419      ASSERT(Node->Info != NULL);
     420      ASSERT((Node->Info->Attribute & EFI_FILE_VALID_ATTR) == Node->Info->Attribute);
     421      if (Attribs == 0) {
    227422        //
    228         // the bit must match
     423        // NOT system & NOT hidden
     424        //
     425        if ( (Node->Info->Attribute & EFI_FILE_SYSTEM)
     426          || (Node->Info->Attribute & EFI_FILE_HIDDEN)
     427         ){
     428          continue;
     429        }
     430      } else if ((Attribs != EFI_FILE_VALID_ATTR) ||
     431                 (Count == 5)) {
     432        //
     433        // Only matches the bits which "Attribs" contains, not
     434        // all files/directories with any of the bits.
     435        // Count == 5 is used to tell the difference between a user
     436        // specifying all bits (EX: -arhsda) and just specifying
     437        // -a (means display all files with any attribute).
    229438        //
    230439        if ( (Node->Info->Attribute & Attribs) != Attribs) {
    231440          continue;
    232441        }
    233       } else {
    234         //
    235         // exact match on all bits
    236         //
    237         if ( (Node->Info->Attribute|EFI_FILE_ARCHIVE) != (Attribs|EFI_FILE_ARCHIVE)) {
    238           continue;
    239         }
    240442      }
    241     }
    242 
    243     if (Sfo) {
    244       //
    245       // Print the FileInfo Table
    246       //
    247     ShellPrintHiiEx (
    248       0,
    249       gST->ConOut->Mode->CursorRow,
    250       NULL,
    251       STRING_TOKEN (STR_LS_SFO_FILEINFO),
    252       gShellLevel2HiiHandle,
    253       Node->FullName,
    254       Node->Info->FileSize,
    255       Node->Info->PhysicalSize,
    256       (Node->Info->Attribute & EFI_FILE_ARCHIVE)   != 0?L"a":L"",
    257       (Node->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"d":L"",
    258       (Node->Info->Attribute & EFI_FILE_HIDDEN)    != 0?L"h":L"",
    259       (Node->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L"r":L"",
    260       (Node->Info->Attribute & EFI_FILE_SYSTEM)    != 0?L"s":L"",
    261       Node->Info->CreateTime.Hour,
    262       Node->Info->CreateTime.Minute,
    263       Node->Info->CreateTime.Second,
    264       Node->Info->CreateTime.Day,
    265       Node->Info->CreateTime.Month,
    266       Node->Info->CreateTime.Year,
    267       Node->Info->LastAccessTime.Hour,
    268       Node->Info->LastAccessTime.Minute,
    269       Node->Info->LastAccessTime.Second,
    270       Node->Info->LastAccessTime.Day,
    271       Node->Info->LastAccessTime.Month,
    272       Node->Info->LastAccessTime.Year,
    273       Node->Info->ModificationTime.Hour,
    274       Node->Info->ModificationTime.Minute,
    275       Node->Info->ModificationTime.Second,
    276       Node->Info->ModificationTime.Day,
    277       Node->Info->ModificationTime.Month,
    278       Node->Info->ModificationTime.Year
    279      );
    280     } else {
    281       //
    282       // print this one out...
    283       // first print the universal start, next print the type specific name format, last print the CRLF
    284       //
    285       ShellPrintHiiEx (
    286         -1,
    287         -1,
    288         NULL,
    289         STRING_TOKEN (STR_LS_LINE_START_ALL),
    290         gShellLevel2HiiHandle,
    291         &Node->Info->ModificationTime,
    292         (Node->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"<DIR>":L"",
    293         (Node->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L'r':L' ',
    294         Node->Info->FileSize
    295        );
    296       if (Node->Info->Attribute & EFI_FILE_DIRECTORY) {
    297         DirCount++;
    298         ShellPrintHiiEx (
    299           -1,
    300           -1,
    301           NULL,
    302           STRING_TOKEN (STR_LS_LINE_END_DIR),
    303           gShellLevel2HiiHandle,
    304           Node->FileName
    305          );
    306       } else {
    307         FileCount++;
    308         FileSize += Node->Info->FileSize;
    309         if ( (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".nsh", (CHAR16*)&(Node->FileName[StrLen (Node->FileName) - 4])) == 0)
    310           || (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".efi", (CHAR16*)&(Node->FileName[StrLen (Node->FileName) - 4])) == 0)
    311          ){
    312           ShellPrintHiiEx (
    313             -1,
    314             -1,
    315             NULL,
    316             STRING_TOKEN (STR_LS_LINE_END_EXE),
    317             gShellLevel2HiiHandle,
    318             Node->FileName
    319            );
    320         } else {
    321           ShellPrintHiiEx (
    322             -1,
    323             -1,
    324             NULL,
    325             STRING_TOKEN (STR_LS_LINE_END_FILE),
    326             gShellLevel2HiiHandle,
    327             Node->FileName
    328            );
    329         }
     443
     444      if (!Sfo && !HeaderPrinted) {
     445        PrintNonSfoHeader(CorrectedPath);
    330446      }
    331     }
    332   }
    333 
    334   if (!Sfo) {
    335     //
    336     // print footer
    337     //
    338     ShellPrintHiiEx (
    339       -1,
    340       -1,
    341       NULL,
    342       STRING_TOKEN (STR_LS_FOOTER_LINE),
    343       gShellLevel2HiiHandle,
    344       FileCount,
    345       FileSize,
    346       DirCount
    347      );
    348   }
    349 
    350   if (Rec){
    351     DirectoryName = AllocateZeroPool(LongestPath + 2*sizeof(CHAR16));
    352     if (DirectoryName == NULL) {
    353       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
    354       ShellStatus = SHELL_OUT_OF_RESOURCES;
    355     } else {
     447      PrintFileInformation(Sfo, Node, &FileCount, &FileSize, &DirCount);
     448      FoundOne = TRUE;
     449      HeaderPrinted = TRUE;
     450    }
     451
     452    if (!Sfo && ShellStatus != SHELL_ABORTED) {
     453      PrintNonSfoFooter(FileCount, FileSize, DirCount);
     454    }
     455  }
     456
     457  if (Rec && ShellStatus != SHELL_ABORTED) {
     458    //
     459    // Re-Open all the files under the starting path for directories that didnt necessarily match our file filter
     460    //
     461    ShellCloseFileMetaArg(&ListHead);
     462    CorrectedPath[0] = CHAR_NULL;
     463    CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath, 0);
     464    if (CorrectedPath == NULL) {
     465      return SHELL_OUT_OF_RESOURCES;
     466    }
     467    if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'
     468      &&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {
     469      CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\",     0);
     470    }
     471    CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"*",     0);
     472    Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
     473   
     474    if (!EFI_ERROR(Status)) {
    356475      for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
    357           ; !IsNull(&ListHead->Link, &Node->Link)
     476          ; !IsNull(&ListHead->Link, &Node->Link) && ShellStatus == SHELL_SUCCESS
    358477          ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
    359478         ){
     479        if (ShellGetExecutionBreakFlag ()) {
     480          ShellStatus = SHELL_ABORTED;
     481          break;
     482        }
     483
    360484        //
    361485        // recurse on any directory except the traversing ones...
     
    365489          && StrCmp(Node->FileName, L"..") != 0
    366490         ){
    367           StrCpy(DirectoryName, Node->FullName);
    368           StrCat(DirectoryName, L"\\*");
    369           PrintLsOutput(
     491          ShellStatus = PrintLsOutput(
    370492            Rec,
    371493            Attribs,
    372494            Sfo,
    373             DirectoryName,
    374             FALSE,
     495            Node->FullName,
     496            SearchString,
     497            &FoundOne,
    375498            Count,
    376499            TimeZone);
     500           
     501          //
     502          // Since it's running recursively, we have to break immediately when returned SHELL_ABORTED
     503          //
     504          if (ShellStatus == SHELL_ABORTED) {
     505            break;
     506          }
    377507        }
    378508      }
    379       FreePool(DirectoryName);
    380     }
    381   }
    382 
    383   FreePool(CorrectedPath);
     509    }
     510  }
     511
     512  SHELL_FREE_NON_NULL(CorrectedPath);
    384513  ShellCloseFileMetaArg(&ListHead);
    385   FreePool(ListHead);
     514
     515  if (Found == NULL && !FoundOne) {
     516    return (SHELL_NOT_FOUND);
     517  }
     518
     519  if (Found != NULL) {
     520    *Found = FoundOne;
     521  }
     522
    386523  return (ShellStatus);
    387524}
     
    419556  UINTN         Size;
    420557  EFI_TIME      TheTime;
    421   BOOLEAN       SfoMode;
     558  CHAR16        *SearchString;
    422559
    423560  Size                = 0;
     
    428565  RequiredAttributes  = 0;
    429566  PathName            = NULL;
     567  SearchString        = NULL;
    430568  CurDir              = NULL;
    431569  Count               = 0;
     
    517655        PathName = ShellCommandLineGetRawValue(Package, 1);
    518656        if (PathName == NULL) {
     657          //
     658          // Nothing specified... must start from current directory
     659          //
    519660          CurDir = gEfiShellProtocol->GetCurDir(NULL);
    520661          if (CurDir == NULL) {
     
    522663            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
    523664          }
    524         }
    525         if (PathName != NULL) {
     665          //
     666          // Copy to the 2 strings for starting path and file search string
     667          //
     668          ASSERT(SearchString == NULL);
     669          ASSERT(FullPath == NULL);
     670          StrnCatGrow(&SearchString, NULL, L"*", 0);
     671          StrnCatGrow(&FullPath, NULL, CurDir, 0);
     672        } else {
    526673          if (StrStr(PathName, L":") == NULL && gEfiShellProtocol->GetCurDir(NULL) == NULL) {
     674            //
     675            // If we got something and it doesnt have a fully qualified path, then we needed to have a CWD.
     676            //
    527677            ShellStatus = SHELL_NOT_FOUND;
    528678            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
    529679          } else {
     680            //
     681            // We got a valid fully qualified path or we have a CWD
     682            //
    530683            ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL));
     684            if (StrStr(PathName, L":") == NULL) {
     685              StrnCatGrow(&FullPath, &Size, gEfiShellProtocol->GetCurDir(NULL), 0);
     686              if (FullPath == NULL) {
     687                ShellCommandLineFreeVarList (Package);
     688                return SHELL_OUT_OF_RESOURCES;
     689              }
     690            }
    531691            StrnCatGrow(&FullPath, &Size, PathName, 0);
     692            if (FullPath == NULL) {
     693                ShellCommandLineFreeVarList (Package);
     694                return SHELL_OUT_OF_RESOURCES;
     695            }
     696               
    532697            if  (ShellIsDirectory(PathName) == EFI_SUCCESS) {
    533               StrnCatGrow(&FullPath, &Size, L"\\*", 0);
     698              //
     699              // is listing ends with a directory, then we list all files in that directory
     700              //
     701              StrnCatGrow(&SearchString, NULL, L"*", 0);
     702            } else {
     703              //
     704              // must split off the search part that applies to files from the end of the directory part
     705              //
     706              for (StrnCatGrow(&SearchString, NULL, PathName, 0)
     707                ; SearchString != NULL && StrStr(SearchString, L"\\") != NULL
     708                ; CopyMem(SearchString, StrStr(SearchString, L"\\") + 1, 1 + StrSize(StrStr(SearchString, L"\\") + 1))) ;
     709              FullPath[StrLen(FullPath) - StrLen(SearchString)] = CHAR_NULL;
    534710            }
    535711          }
    536         } else {
    537           ASSERT(FullPath == NULL);
    538           StrnCatGrow(&FullPath, NULL, L"*", 0);
    539712        }
    540713        Status = gRT->GetTime(&TheTime, NULL);
     
    544717        }
    545718
    546         SfoMode = ShellCommandLineGetFlag(Package, L"-sfo");
    547719        if (ShellStatus == SHELL_SUCCESS) {
    548720          ShellStatus = PrintLsOutput(
    549721            ShellCommandLineGetFlag(Package, L"-r"),
    550722            RequiredAttributes,
    551             SfoMode,
     723            ShellCommandLineGetFlag(Package, L"-sfo"),
    552724            FullPath,
    553             TRUE,
     725            SearchString,
     726            NULL,
    554727            Count,
    555728            (INT16)(TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:TheTime.TimeZone)
    556729           );
    557730          if (ShellStatus == SHELL_NOT_FOUND) {
    558             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_FILES), gShellLevel2HiiHandle);
     731            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle);
    559732          } else if (ShellStatus == SHELL_INVALID_PARAMETER) {
    560733            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
     734          } else if (ShellStatus == SHELL_ABORTED) {
     735            //
     736            // Ignore aborting.
     737            //
    561738          } else if (ShellStatus != SHELL_SUCCESS) {
    562739            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle);
     
    567744  }
    568745
    569   if (FullPath != NULL) {
    570     FreePool(FullPath);
    571   }
    572   //
    573   // free the command line package
    574   //
     746  //
     747  // Free memory allocated
     748  //
     749  SHELL_FREE_NON_NULL(SearchString);
     750  SHELL_FREE_NON_NULL(FullPath);
    575751  ShellCommandLineFreeVarList (Package);
    576752
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c

    r48674 r58459  
    22  Main file for map shell level 2 command.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    119120
    120121/**
    121   Add mappings for any devices without one.  Do not change any existing maps.
    122 
    123   @retval EFI_SUCCESS   The operation was successful.
    124 **/
    125 EFI_STATUS
    126 EFIAPI
    127 UpdateMapping (
    128   VOID
    129   )
    130 {
    131   EFI_STATUS                Status;
    132   EFI_HANDLE                *HandleList;
    133   UINTN                     Count;
    134   EFI_DEVICE_PATH_PROTOCOL  **DevicePathList;
    135   CHAR16                    *NewDefaultName;
    136   CHAR16                    *NewConsistName;
    137   EFI_DEVICE_PATH_PROTOCOL  **ConsistMappingTable;
    138 
    139   HandleList  = NULL;
    140   Status      = EFI_SUCCESS;
    141 
    142   //
    143   // remove mappings that represent removed devices.
    144   //
    145 
    146   //
    147   // Find each handle with Simple File System
    148   //
    149   HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid);
    150   if (HandleList != NULL) {
    151     //
    152     // Do a count of the handles
    153     //
    154     for (Count = 0 ; HandleList[Count] != NULL ; Count++);
    155 
    156     //
    157     // Get all Device Paths
    158     //
    159     DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);
    160     ASSERT(DevicePathList != NULL);
    161 
    162     for (Count = 0 ; HandleList[Count] != NULL ; Count++) {
    163       DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);
    164     }
    165 
    166     //
    167     // Sort all DevicePaths
    168     //
    169     PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare);
    170 
    171     ShellCommandConsistMappingInitialize(&ConsistMappingTable);
    172 
    173     //
    174     // Assign new Mappings to remainders
    175     //
    176     for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {
    177       //
    178       // Skip ones that already have
    179       //
    180       if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) {
    181         continue;
    182       }
    183       //
    184       // Get default name
    185       //
    186       NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);
    187       ASSERT(NewDefaultName != NULL);
    188 
    189       //
    190       // Call shell protocol SetMap function now...
    191       //
    192       Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName);
    193 
    194       if (!EFI_ERROR(Status)) {
    195         //
    196         // Now do consistent name
    197         //
    198         NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable);
    199         if (NewConsistName != NULL) {
    200           Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName);
    201           FreePool(NewConsistName);
    202         }
    203       }
    204 
    205       FreePool(NewDefaultName);
    206     }
    207     ShellCommandConsistMappingUnInitialize(ConsistMappingTable);
    208     SHELL_FREE_NON_NULL(HandleList);
    209     SHELL_FREE_NON_NULL(DevicePathList);
    210 
    211     HandleList = NULL;
    212   } else {
    213     Count = (UINTN)-1;
    214   }
    215   //
    216   // Do it all over again for gEfiBlockIoProtocolGuid
    217   //
    218 
    219   return (Status);
    220 }
    221 
    222 /**
    223122  Determine what type of device is represented and return it's string.  The
    224123  string is in allocated memory and must be callee freed.  The HII is is listed below.
     
    330229  //
    331230  if (Specific != NULL) {
    332     NewSpecific = AllocateZeroPool(StrSize(Specific) + sizeof(CHAR16));
     231    NewSpecific = AllocateCopyPool(StrSize(Specific) + sizeof(CHAR16), Specific);
    333232    if (NewSpecific == NULL){
    334233      return FALSE;
    335234    }
    336     StrCpy(NewSpecific, Specific);
    337235    if (NewSpecific[StrLen(NewSpecific)-1] != L':') {
    338       StrCat(NewSpecific, L":");
     236      StrnCat(NewSpecific, L":", 2);
    339237    }
    340238
     
    346244  }
    347245  if (  Consist
     246    && Specific == NULL
    348247    && (SearchList(MapList, L"HD*",  NULL, TRUE, TRUE, L";")
    349248      ||SearchList(MapList, L"CD*",  NULL, TRUE, TRUE, L";")
     
    354253
    355254  if (  Normal
     255    && Specific == NULL
    356256    && (SearchList(MapList, L"FS",  NULL, FALSE, TRUE, L";")
    357257      ||SearchList(MapList, L"BLK", NULL, FALSE, TRUE, L";"))){
     
    398298  CHAR16                    *DevPathString;
    399299  CHAR16                    *TempSpot;
     300  CHAR16                    *Alias;
    400301  UINTN                     TempLen;
    401302  BOOLEAN                   Removable;
    402303  CONST CHAR16              *TempSpot2;
    403304
     305  Alias       = NULL;
     306  TempSpot2   = NULL;
     307  CurrentName = NULL;
    404308  DevPath = DevicePathFromHandle(Handle);
    405309  DevPathCopy = DevPath;
     
    413317  }
    414318
    415   CurrentName = NULL;
    416   CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
    417   if (CurrentName == NULL) {
    418     return (EFI_OUT_OF_RESOURCES);
    419   }
    420   TempSpot = StrStr(CurrentName, L";");
    421   if (TempSpot != NULL) {
    422     *TempSpot = CHAR_NULL;
    423   }
    424   DevPathString = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, FALSE);
     319  if (Normal || !Consist) {
     320    //
     321    // need the Normal here since people can use both on command line.  otherwise unused.
     322    //
     323
     324    //
     325    // Allocate a name
     326    //
     327    CurrentName = NULL;
     328    CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
     329    if (CurrentName == NULL) {
     330      return (EFI_OUT_OF_RESOURCES);
     331    }
     332
     333    //
     334    // Chop off the other names that become "Alias(s)"
     335    // leaving just the normal name
     336    //
     337    TempSpot = StrStr(CurrentName, L";");
     338    if (TempSpot != NULL) {
     339      *TempSpot = CHAR_NULL;
     340    }
     341  } else {
     342    CurrentName = NULL;
     343
     344    //
     345    // Skip the first name.  This is the standard name.
     346    //
     347    TempSpot = StrStr(MapList, L";");
     348    if (TempSpot != NULL) {
     349      TempSpot++;
     350    }
     351    SearchList(TempSpot, L"HD*", &CurrentName, TRUE, FALSE, L";");
     352    if (CurrentName == NULL) {
     353      SearchList(TempSpot, L"CD*", &CurrentName, TRUE, FALSE, L";");
     354    }
     355    if (CurrentName == NULL) {
     356      SearchList(TempSpot, L"FP*", &CurrentName, TRUE, FALSE, L";");
     357    }
     358    if (CurrentName == NULL) {
     359      SearchList(TempSpot, L"F*",  &CurrentName, TRUE, FALSE, L";");
     360    }
     361    if (CurrentName == NULL) {
     362      //
     363      // We didnt find anything, so just the first one in the list...
     364      //
     365      CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
     366      if (CurrentName == NULL) {
     367        return (EFI_OUT_OF_RESOURCES);
     368      }
     369      TempSpot = StrStr(CurrentName, L";");
     370      if (TempSpot != NULL) {
     371        *TempSpot = CHAR_NULL;
     372      }
     373    } else {
     374      Alias = StrnCatGrow(&Alias, 0, MapList, 0);
     375      if (Alias == NULL) {
     376        return EFI_OUT_OF_RESOURCES;
     377      }
     378      TempSpot = StrStr(Alias, CurrentName);
     379      if (TempSpot != NULL) {
     380        TempSpot2 = StrStr(TempSpot, L";");
     381        if (TempSpot2 != NULL) {
     382          TempSpot2++; // Move past ";" from CurrentName
     383          CopyMem(TempSpot, TempSpot2, StrSize(TempSpot2));
     384        } else {
     385          *TempSpot = CHAR_NULL;
     386        }
     387      }
     388      if (Alias[StrLen(Alias)-1] == L';') {
     389        Alias[StrLen(Alias)-1] = CHAR_NULL;
     390      }
     391    }
     392  }
     393  DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
     394  TempLen = StrLen(CurrentName);
    425395  if (!SFO) {
    426     TempLen = StrLen(CurrentName);
    427396    ShellPrintHiiEx (
    428397      -1,
     
    432401      gShellLevel2HiiHandle,
    433402      CurrentName,
    434       TempLen < StrLen(MapList)?MapList + TempLen+1:L"",
     403      Alias!=NULL?Alias:(TempLen < StrLen(MapList)?MapList + TempLen+1:L""),
    435404      DevPathString
    436405     );
     
    455424         );
    456425      }
    457       FreePool(MediaType);
     426      SHELL_FREE_NON_NULL(MediaType);
    458427    }
    459428  } else {
    460     TempLen = StrLen(CurrentName);
    461429    ShellPrintHiiEx (
    462430      -1,
     
    467435      CurrentName,
    468436      DevPathString,
    469       TempLen < StrLen(MapList)?MapList + TempLen+1:L""
     437      Consist?L"":(TempLen < StrLen(MapList)?MapList + TempLen+1:L"")
    470438     );
    471439  }
    472   FreePool(DevPathString);
    473   FreePool(CurrentName);
     440  SHELL_FREE_NON_NULL(DevPathString);
     441  SHELL_FREE_NON_NULL(CurrentName);
     442  SHELL_FREE_NON_NULL(Alias);
    474443  return EFI_SUCCESS;
    475444}
     
    908877  CHAR16                          *NewSName;
    909878 
    910   NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));
     879  NewSName = AllocateCopyPool(StrSize(SName) + sizeof(CHAR16), SName);
    911880  if (NewSName == NULL) {
    912881    return (SHELL_OUT_OF_RESOURCES);
    913882  }
    914   StrCpy(NewSName, SName);
    915883  if (NewSName[StrLen(NewSName)-1] != L':') {
    916     StrCat(NewSName, L":");
     884    StrnCat(NewSName, L":", 2);
    917885  }
    918886
     
    961929  CHAR16                    *NewSName;
    962930 
    963   NewSName = AllocateZeroPool(StrSize(SName) + sizeof(CHAR16));
     931  NewSName = AllocateCopyPool(StrSize(SName) + sizeof(CHAR16), SName);
    964932  if (NewSName == NULL) {
    965933    return (SHELL_OUT_OF_RESOURCES);
    966934  }
    967   StrCpy(NewSName, SName);
    968935  if (NewSName[StrLen(NewSName)-1] != L':') {
    969     StrCat(NewSName, L":");
     936    StrnCat(NewSName, L":", 2);
    970937  }
    971938
     
    1026993  CONST CHAR16  *Mapping;
    1027994  EFI_HANDLE    MapAsHandle;
    1028   CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;
    1029995  SHELL_STATUS  ShellStatus;
    1030996  BOOLEAN       SfoMode;
     
    10381004  Mapping       = NULL;
    10391005  SName         = NULL;
    1040   DevPath       = NULL;
    10411006  ShellStatus   = SHELL_SUCCESS;
    10421007  MapAsHandle = NULL;
     
    10941059            Status = PerformMappingDelete(SName);
    10951060            if (EFI_ERROR(Status)) {
    1096               switch (Status) {
    1097                 case EFI_ACCESS_DENIED:
    1098                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel2HiiHandle);
    1099                   ShellStatus = SHELL_ACCESS_DENIED;
    1100                   break;
    1101                 case EFI_NOT_FOUND:
    1102                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, SName);
    1103                   ShellStatus = SHELL_INVALID_PARAMETER;
    1104                   break;
    1105                 default:
    1106                   ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
    1107                   ShellStatus = SHELL_UNSUPPORTED;
     1061              if (Status == EFI_ACCESS_DENIED) {
     1062                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel2HiiHandle);
     1063                ShellStatus = SHELL_ACCESS_DENIED;
     1064              } else if (Status == EFI_NOT_FOUND) {
     1065                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MAP_NF), gShellLevel2HiiHandle, SName);
     1066                ShellStatus = SHELL_INVALID_PARAMETER;
     1067              } else {
     1068                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
     1069                ShellStatus = SHELL_UNSUPPORTED;
    11081070              }
    11091071            }
     
    11341096          // Do the Update
    11351097          //
    1136           Status = UpdateMapping();
     1098          Status = ShellCommandUpdateMapping ();
    11371099          if (EFI_ERROR(Status)) {
    11381100            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c

    r48674 r58459  
    22  Main file for mv shell level 2 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    2930  @param DestPath [in]    The target location to move to
    3031  @param Attribute[in]    The Attribute of the file
     32  @param FileStatus[in]   The Status of the file when opened
    3133
    3234  @retval TRUE        The move is valid
     
    3638EFIAPI
    3739IsValidMove(
    38   IN CONST CHAR16   *FullName,
    39   IN CONST CHAR16   *Cwd,
    40   IN CONST CHAR16   *DestPath,
    41   IN CONST UINT64   Attribute
     40  IN CONST CHAR16     *FullName,
     41  IN CONST CHAR16     *Cwd,
     42  IN CONST CHAR16     *DestPath,
     43  IN CONST UINT64     Attribute,
     44  IN CONST EFI_STATUS FileStatus
    4245  )
    4346{
     
    8790    return (FALSE);
    8891  }
    89   if ((Attribute & EFI_FILE_READ_ONLY) != 0) {
     92  if (((Attribute & EFI_FILE_READ_ONLY) != 0) || (FileStatus == EFI_WRITE_PROTECTED)) {
    9093    //
    9194    // invalid to move read only
    9295    //
    93     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle);
     96    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle, FullName);
    9497    return (FALSE);
    9598  }
     
    136139  EFI_SHELL_FILE_INFO       *DestList;
    137140  EFI_SHELL_FILE_INFO       *Node;
    138   EFI_STATUS                Status;
    139141  CHAR16                    *DestPath;
    140   CHAR16                    *TempLocation;
    141142  UINTN                     NewSize;
     143  UINTN                     CurrentSize;
    142144
    143145  DestList = NULL;
     
    154156    StrCpy(DestPath, Cwd);
    155157    while (PathRemoveLastItem(DestPath)) ;
     158
     159    //
     160    // Append DestDir beyond '\' which may be present
     161    //
     162    CurrentSize = StrSize(DestPath);
     163    StrnCatGrow(&DestPath, &CurrentSize, &DestDir[1], 0);
     164
    156165    *DestPathPointer =  DestPath;
    157166    return (SHELL_SUCCESS);
     
    160169  // get the destination path
    161170  //
    162   Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
     171  ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
    163172  if (DestList == NULL || IsListEmpty(&DestList->Link)) {
    164173    //
    165174    // Not existing... must be renaming
    166175    //
    167     if ((TempLocation = StrStr(DestDir, L":")) == NULL) {
     176    if (StrStr(DestDir, L":") == NULL) {
    168177      if (Cwd == NULL) {
    169178        ShellCloseFileMetaArg(&DestList);
     
    262271  VOID                      *Response;
    263272  SHELL_FILE_HANDLE         DestHandle;
     273  CHAR16                    *CleanFilePathStr;
    264274
    265275  ASSERT(FileList != NULL);
    266276  ASSERT(DestDir  != NULL);
    267277
    268   DestPath = NULL;
    269   Cwd      = ShellGetCurrentDir(NULL);
    270   Response = *Resp;
     278  DestPath         = NULL;
     279  Cwd              = ShellGetCurrentDir(NULL);
     280  Response         = *Resp;
     281  CleanFilePathStr = NULL;
     282
     283  Status = ShellLevel2StripQuotes (DestDir, &CleanFilePathStr);
     284  if (EFI_ERROR (Status)) {
     285    if (Status == EFI_OUT_OF_RESOURCES) {
     286      return SHELL_OUT_OF_RESOURCES;
     287    } else {
     288      return SHELL_INVALID_PARAMETER;
     289    }
     290  } 
     291
     292  ASSERT (CleanFilePathStr != NULL);
    271293
    272294  //
    273295  // Get and validate the destination location
    274296  //
    275   ShellStatus = GetDestinationLocation(DestDir, &DestPath, Cwd);
     297  ShellStatus = GetDestinationLocation(CleanFilePathStr, &DestPath, Cwd);
     298  FreePool (CleanFilePathStr);
    276299  if (ShellStatus != SHELL_SUCCESS) {
    277300    return (ShellStatus);
     
    284307  ASSERT  (HiiResultOk  != NULL);
    285308  ASSERT  (HiiOutput    != NULL);
    286 //  ASSERT  (Cwd          != NULL);
    287309
    288310  //
     
    296318      break;
    297319    }
     320
     321    //
     322    // These should never be NULL
     323    //
    298324    ASSERT(Node->FileName != NULL);
    299325    ASSERT(Node->FullName != NULL);
     326    ASSERT(Node->Info     != NULL);
    300327
    301328    //
     
    309336    // Validate that the move is valid
    310337    //
    311     if (!IsValidMove(Node->FullName, Cwd, DestPath, Node->Info->Attribute)) {
     338    if (!IsValidMove(Node->FullName, Cwd, DestPath, Node->Info->Attribute, Node->Status)) {
    312339      ShellStatus = SHELL_INVALID_PARAMETER;
    313340      continue;
     
    406433      if (EFI_ERROR(Status)) {
    407434        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
    408         //
    409         // move failed
    410         //
    411         switch(Status){
    412           default:
    413             ShellStatus = SHELL_INVALID_PARAMETER;
    414           case EFI_SECURITY_VIOLATION:
    415             ShellStatus = SHELL_SECURITY_VIOLATION;
    416           case EFI_WRITE_PROTECTED:
    417             ShellStatus = SHELL_WRITE_PROTECTED;
    418           case EFI_OUT_OF_RESOURCES:
    419             ShellStatus = SHELL_OUT_OF_RESOURCES;
    420           case EFI_DEVICE_ERROR:
    421             ShellStatus = SHELL_DEVICE_ERROR;
    422           case EFI_ACCESS_DENIED:
    423             ShellStatus = SHELL_ACCESS_DENIED;
    424         } // switch
     435        ShellStatus = SHELL_INVALID_PARAMETER;
     436        if (Status == EFI_SECURITY_VIOLATION) {
     437          ShellStatus = SHELL_SECURITY_VIOLATION;
     438        } else if (Status == EFI_WRITE_PROTECTED) {
     439          ShellStatus = SHELL_WRITE_PROTECTED;
     440        } else if (Status == EFI_OUT_OF_RESOURCES) {
     441          ShellStatus = SHELL_OUT_OF_RESOURCES;
     442        } else if (Status == EFI_DEVICE_ERROR) {
     443          ShellStatus = SHELL_DEVICE_ERROR;
     444        } else if (Status == EFI_ACCESS_DENIED) {
     445          ShellStatus = SHELL_ACCESS_DENIED;
     446        }
    425447      } else {
    426448        ShellPrintEx(-1, -1, L"%s", HiiResultOk);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c

    r48674 r58459  
    22  Main file for Parse shell level 2 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    5758    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, FileName);
    5859    ShellStatus = SHELL_NOT_FOUND;
     60  } else if (!EFI_ERROR (FileHandleIsDirectory (FileHandle))) {
     61    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_FILE), gShellLevel2HiiHandle, FileName);
     62    ShellStatus = SHELL_NOT_FOUND;
    5963  } else {
    6064    for (LoopVariable = 0 ; LoopVariable < ShellCommandInstance && !ShellFileHandleEof(FileHandle);) {
     
    6367        break;
    6468      }
    65       if (StrStr(TempLine, L"ShellCommand, \"") == TempLine) {
     69
     70      //
     71      // Search for "ShellCommand," in the file to start the SFO table
     72      // for a given ShellCommand.  The UEFI Shell spec does not specify
     73      // a space after the comma.
     74      //
     75      if (StrStr (TempLine, L"ShellCommand,") == TempLine) {
    6676        LoopVariable++;
    6777      }
     
    7282      while(1) {
    7383        TempLine = ShellFileHandleReturnLine(FileHandle, &Ascii);
    74         if ( TempLine == NULL
    75           || *TempLine == CHAR_NULL
    76           || StrStr(TempLine, L"ShellCommand, \"") == TempLine
    77          ){
     84        if (TempLine == NULL
     85            || *TempLine == CHAR_NULL
     86            || StrStr (TempLine, L"ShellCommand,") == TempLine) {
    7887          SHELL_FREE_NON_NULL(TempLine);
    7988          break;
    8089        }
    81         if (StrStr(TempLine, TableName) == TempLine) {
     90        if (StrStr (TempLine, TableName) == TempLine) {
    8291          LoopVariable++;
    83         }
    84         if ( LoopVariable == TableNameInstance
    85           || (TableNameInstance == (UINTN)-1 && StrStr(TempLine, TableName) == TempLine)
    86          ){
    87           for (ColumnLoop = 1, ColumnPointer = TempLine; ColumnLoop < ColumnIndex && ColumnPointer != NULL && *ColumnPointer != CHAR_NULL; ColumnLoop++) {
    88             ColumnPointer = StrStr(ColumnPointer, L",");
    89             if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL){
    90               ColumnPointer++;
     92          if (LoopVariable == TableNameInstance
     93              || (TableNameInstance == (UINTN)-1)) {
     94            for (ColumnLoop = 1, ColumnPointer = TempLine; ColumnLoop < ColumnIndex && ColumnPointer != NULL && *ColumnPointer != CHAR_NULL; ColumnLoop++) {
     95              ColumnPointer = StrStr (ColumnPointer, L",");
     96              if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL){
     97                ColumnPointer++;
     98              }
    9199            }
    92           }
    93           if (ColumnLoop == ColumnIndex) {
    94             ASSERT(ColumnPointer != NULL);
    95             TempSpot = StrStr(ColumnPointer, L",");
    96             if (TempSpot != NULL) {
    97               *TempSpot = CHAR_NULL;
     100            if (ColumnLoop == ColumnIndex) {
     101              if (ColumnPointer == NULL) {
     102                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"Column Index");
     103                ShellStatus = SHELL_INVALID_PARAMETER;
     104              } else {
     105                TempSpot = StrStr (ColumnPointer, L",");
     106                if (TempSpot != NULL) {
     107                  *TempSpot = CHAR_NULL;
     108                }
     109                while (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L' '){
     110                  ColumnPointer++;
     111                }
     112                if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L'\"'){
     113                  ColumnPointer++;
     114                }
     115                if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[StrLen (ColumnPointer) - 1] == L'\"'){
     116                  ColumnPointer[StrLen (ColumnPointer) - 1] = CHAR_NULL;
     117                }
     118
     119                ShellPrintEx (-1, -1, L"%s\r\n", ColumnPointer);
     120              }
    98121            }
    99             while (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L' '){
    100               ColumnPointer++;
    101             }
    102             if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L'\"'){
    103               ColumnPointer++;
    104             }
    105             if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[StrLen(ColumnPointer)-1] == L'\"'){
    106               ColumnPointer[StrLen(ColumnPointer)-1] = CHAR_NULL;
    107             }
    108 
    109             ShellPrintEx(-1, -1, L"%s\r\n", ColumnPointer);
    110122          }
    111123        }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Reset.c

    r48674 r58459  
    22  Main file for attrib shell level 2 function.
    33
    4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    8282          String = ShellCommandLineGetValue(Package, L"-w");
    8383          if (String != NULL) {
    84             gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, StrSize(String), (VOID*)String);
     84            gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, StrSize(String), (VOID*)String);
    8585          } else {
    86             gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
     86            gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
    8787          }
    8888        }
     
    106106        String = ShellCommandLineGetValue(Package, L"-c");
    107107        if (String != NULL) {
    108           gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, StrSize(String), (VOID*)String);
     108          gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, StrSize(String), (VOID*)String);
    109109        } else {
    110           gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
     110          gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
    111111        }
    112112      }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c

    r48674 r58459  
    22  Main file for attrib shell level 2 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    3434  )
    3535{
    36   EFI_STATUS      Status;
    3736  EFI_FILE_INFO   *FileInfo;
    3837  BOOLEAN         NoFile;
     
    4140  RetVal = TRUE;
    4241  NoFile = FALSE;
    43 
    44   for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo)
     42  FileInfo = NULL;
     43
     44  for (FileHandleFindFirstFile(FileHandle, &FileInfo)
    4545    ;  !NoFile
    46     ;  Status = FileHandleFindNextFile(FileHandle, FileInfo, &NoFile)
     46    ;  FileHandleFindNextFile(FileHandle, FileInfo, &NoFile)
    4747   ){
    4848    if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName
     
    7777  EFI_STATUS            Status;
    7878  SHELL_PROMPT_RESPONSE *Resp;
     79  CHAR16                *TempName;
     80  UINTN                 NewSize;
    7981
    8082  Resp                  = NULL;
     
    9395        Status = ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_RM_LOG_DELETE_CONF), gShellLevel2HiiHandle, Node->FullName);
    9496        Status = ShellPromptForResponse(ShellPromptResponseTypeYesNo, NULL, (VOID**)&Resp);
    95         ASSERT_EFI_ERROR(Status);
    9697        ASSERT(Resp != NULL);
    9798        if (EFI_ERROR(Status) || *Resp != ShellPromptResponseYes) {
     
    122123        }
    123124        Node2->Status = gEfiShellProtocol->OpenFileByName (Node2->FullName, &Node2->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
    124         ShellStatus = CascadeDelete(Node2, Quiet);
     125        if (EFI_ERROR(Node2->Status) && StrStr(Node2->FileName, L":") == NULL) {
     126          //
     127          // Update the node filename to have full path with file system identifier
     128          //
     129          NewSize = StrSize(Node->FullName) + StrSize(Node2->FullName);
     130          TempName = AllocateZeroPool(NewSize);
     131          if (TempName == NULL) {
     132            ShellStatus = SHELL_OUT_OF_RESOURCES;
     133          } else {
     134            StrnCpy(TempName, Node->FullName, NewSize/sizeof(CHAR16) -1);
     135            TempName[StrStr(TempName, L":")+1-TempName] = CHAR_NULL;
     136            StrnCat(TempName, Node2->FullName, NewSize/sizeof(CHAR16) -1 - StrLen(TempName));
     137            FreePool((VOID*)Node2->FullName);
     138            Node2->FullName = TempName;
     139
     140            //
     141            // Now try again to open the file
     142            //
     143            Node2->Status = gEfiShellProtocol->OpenFileByName (Node2->FullName, &Node2->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
     144          }
     145        }
     146        if (!EFI_ERROR(Node2->Status)) {
     147          ShellStatus = CascadeDelete(Node2, Quiet);
     148        } else if (ShellStatus == SHELL_SUCCESS) {
     149          ShellStatus = (SHELL_STATUS)(Node2->Status&(~0x80000000));
     150        }
    125151        if (ShellStatus != SHELL_SUCCESS) {
    126152          if (List!=NULL) {
     
    140166    // now delete the current node...
    141167    //
    142     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE), gShellLevel2HiiHandle, Node->FullName);
     168    if (!Quiet) {
     169      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE), gShellLevel2HiiHandle, Node->FullName);
     170    }
    143171    Status = gEfiShellProtocol->DeleteFile(Node->Handle);
    144172    Node->Handle = NULL;
     
    152180    return (SHELL_ACCESS_DENIED);
    153181  } else {
    154     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_COMP), gShellLevel2HiiHandle);
     182    if (!Quiet) {
     183      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_COMP), gShellLevel2HiiHandle);
     184    }
    155185    return (SHELL_SUCCESS);
    156186  }
     
    158188
    159189/**
    160   Determins if a Node is a valid delete target.  Will prevent deleting the root directory.
     190  Determines if a Node is a valid delete target.  Will prevent deleting the root directory.
    161191
    162192  @param[in] List       RESERVED.  Not used.
     
    203233  Pattern       = StrnCatGrow(&Pattern     , NULL, TempLocation  , 0);
    204234  SearchString  = StrnCatGrow(&SearchString, &Size, Node->FullName, 0);
    205   SearchString  = StrnCatGrow(&SearchString, &Size, L"*", 0);
     235  if (!EFI_ERROR(ShellIsDirectory(SearchString))) {
     236    SearchString  = StrnCatGrow(&SearchString, &Size, L"\\", 0);
     237    SearchString  = StrnCatGrow(&SearchString, &Size, L"*", 0);
     238  }
    206239
    207240  if (Pattern == NULL || SearchString == NULL) {
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c

    r48674 r58459  
    22  Main file for time, timezone, and date shell level 2 and shell level 3 functions.
    33
     4  (C) Copyright 2012-2014, Hewlett-Packard Development Company, L.P.
    45  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
     
    222223        //
    223224        Status = gRT->GetTime(&TheTime, NULL);
    224         ASSERT_EFI_ERROR(Status);
     225        if (EFI_ERROR(Status)) {
     226          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
     227          return (SHELL_DEVICE_ERROR);
     228        }
    225229
    226230        //
     
    228232        //
    229233        if (ShellCommandLineGetFlag(Package, L"-sfo")) {
    230           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
     234          //
     235          // Match UEFI Shell spec:
     236          // ShellCommand,"date"
     237          // Date,"DD","MM","YYYY"
     238          //
     239          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel2HiiHandle, L"date");
     240          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Day, TheTime.Month, TheTime.Year);
    231241        } else {
    232242          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year);
     
    313323
    314324  Status = gRT->GetTime(&TheTime, NULL);
    315   ASSERT_EFI_ERROR(Status);
     325  if (EFI_ERROR(Status)) {
     326    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
     327    return (SHELL_DEVICE_ERROR);
     328  }
    316329
    317330  if (TimeString != NULL) {
     
    333346    if (Walker2 != NULL && *Walker2 == L':') {
    334347      *Walker2 = CHAR_NULL;
     348      TheTime.Second = (UINT8)0;
     349    }
     350    else if (Walker2 == NULL) {
     351      TheTime.Second = (UINT8)0;
    335352    }
    336353    if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {
     
    338355      if (Walker2 != NULL) {
    339356        Walker1 = Walker2 + 1;
     357        if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {
     358          TheTime.Second = (UINT8)ShellStrToUintn (Walker1);
     359        }
    340360      }
    341       if (Walker1 != NULL && Walker1[0] != CHAR_NULL) {
    342         TheTime.Second = (UINT8)ShellStrToUintn (Walker1);
    343       }
    344361    }
    345362    SHELL_FREE_NON_NULL(TimeStringCopy);
     
    347364
    348365
    349   if ((Tz >= -1440 && Tz <= 1440)||(Tz == 0x7FF)) {
     366  if (Tz >= -1440 && Tz <= 1440) {
     367    //
     368    // EFI_TIME TimeZone is stored to meet the following calculation (see UEFI Spec):
     369    // Localtime = UTC - TimeZone
     370    // This means the sign must be changed for the user provided Tz.
     371    // EX: User wants to set TimeZone to Pacific Standard Time, so runs
     372    // time -tz -480 # set to UTC-08:00
     373    // To meet the calculation, the sign must be changed.
     374    //
     375    TheTime.TimeZone = -Tz;
     376  } else if (Tz == EFI_UNSPECIFIED_TIMEZONE) {
    350377    TheTime.TimeZone = Tz;
    351378  }
     
    379406  EFI_STATUS    Status;
    380407  LIST_ENTRY    *Package;
    381   CHAR16        *Message;
    382408  EFI_TIME      TheTime;
    383409  CHAR16        *ProblemParam;
     
    388414  UINTN         TzMinutes;
    389415
     416  //
     417  // Initialize variables
     418  //
    390419  ShellStatus  = SHELL_SUCCESS;
    391420  ProblemParam = NULL;
    392 
    393   //
    394   // Initialize variables
    395   //
    396   Message = NULL;
    397421
    398422  //
     
    424448    //
    425449    Status = gRT->GetTime(&TheTime, NULL);
    426     ASSERT_EFI_ERROR(Status);
     450    if (EFI_ERROR(Status)) {
     451      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
     452      return (SHELL_DEVICE_ERROR);
     453    }
     454
    427455    if (ShellCommandLineGetFlag(Package, L"-?")) {
    428456      ASSERT(FALSE);
     
    446474        }
    447475
    448         ShellPrintHiiEx (
    449           -1,
    450           -1,
    451           NULL,
    452           STRING_TOKEN (STR_TIME_FORMAT),
    453           gShellLevel2HiiHandle,
    454           TheTime.Hour,
    455           TheTime.Minute,
    456           TheTime.Second,
    457           TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"),
    458           TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,
    459           TzMinutes
    460          );
    461          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);
     476        if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {
     477          ShellPrintHiiEx (
     478            -1,
     479            -1,
     480            NULL,
     481            STRING_TOKEN (STR_TIME_FORMAT),
     482            gShellLevel2HiiHandle,
     483            TheTime.Hour,
     484            TheTime.Minute,
     485            TheTime.Second,
     486            (TheTime.TimeZone > 0?L"-":L"+"),
     487            ((ABS(TheTime.TimeZone)) / 60),
     488            TzMinutes
     489            );
     490        } else {
     491          ShellPrintHiiEx (
     492            -1,
     493            -1,
     494            NULL,
     495            STRING_TOKEN (STR_TIME_FORMAT_LOCAL),
     496            gShellLevel2HiiHandle,
     497            TheTime.Hour,
     498            TheTime.Minute,
     499            TheTime.Second
     500            );
     501        }
     502        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);
    462503      } else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) {
    463504        if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {
    464           TzMinutes = 0;
     505          ShellPrintHiiEx (
     506            -1,
     507            -1,
     508            NULL,
     509            STRING_TOKEN (STR_TIME_FORMAT_LOCAL),
     510            gShellLevel2HiiHandle,
     511            TheTime.Hour,
     512            TheTime.Minute,
     513            TheTime.Second
     514            );
    465515        } else {
    466516          TzMinutes = (ABS(TheTime.TimeZone)) % 60;
    467         }
    468 
    469         ShellPrintHiiEx (
    470           -1,
    471           -1,
    472           NULL,
    473           STRING_TOKEN (STR_TIME_FORMAT),
    474           gShellLevel2HiiHandle,
    475           TheTime.Hour,
    476           TheTime.Minute,
    477           TheTime.Second,
    478           TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"),
    479           TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,
    480           TzMinutes
    481          );
     517          ShellPrintHiiEx (
     518            -1,
     519            -1,
     520            NULL,
     521            STRING_TOKEN (STR_TIME_FORMAT),
     522            gShellLevel2HiiHandle,
     523            TheTime.Hour,
     524            TheTime.Minute,
     525            TheTime.Second,
     526            (TheTime.TimeZone > 0?L"-":L"+"),
     527            ((ABS(TheTime.TimeZone)) / 60),
     528            TzMinutes
     529           );
     530        }
    482531          switch (TheTime.Daylight) {
    483532            case 0:
     
    505554          //
    506555          if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {
    507             if (TempLocation[0] == L'-') {
    508               Tz = (INT16)(0 - ShellStrToUintn(++TempLocation));
     556            if (StrniCmp (TempLocation, L"_local", StrLen (TempLocation)) == NULL) {
     557              Tz = EFI_UNSPECIFIED_TIMEZONE;
     558            } else if (TempLocation[0] == L'-') {
     559
     560              Tz = (INT16) ShellStrToUintn (++TempLocation);
     561              //
     562              // When the argument of "time [-tz tz]" is not numeric, ShellStrToUintn() returns "-1".
     563              // Here we can detect the argument error by checking the return of ShellStrToUintn().
     564              //
     565              if (Tz == -1) {
     566                Tz = 1441; //make it to be out of bounds value
     567              } else {
     568                Tz *= (-1); //sign convert
     569              }
    509570            } else {
    510               Tz = (INT16)ShellStrToUintn(TempLocation);
     571              if (TempLocation[0] == L'+') {
     572                Tz = (INT16)ShellStrToUintn (++TempLocation);
     573              } else {
     574                Tz = (INT16)ShellStrToUintn (TempLocation);
     575              }
     576              //
     577              // Detect the return of ShellStrToUintn() to make sure the argument is valid.
     578              //
     579              if (Tz == -1) {
     580                Tz = 1441; //make it to be out of bounds value
     581              }
    511582            }
    512583            if (!(Tz >= -1440 && Tz <= 1440) && Tz != EFI_UNSPECIFIED_TIMEZONE) {
     
    523594          if (TempLocation != NULL) {
    524595            Daylight = (UINT8)ShellStrToUintn(TempLocation);
     596            //
     597            // The argument of "time [-d dl]" is unsigned, if the first character is '-',
     598            // the argument is incorrect.  That's because ShellStrToUintn() will skip past
     599            // any '-' sign and convert what's next, forgetting the sign is here.
     600            //
     601            if (TempLocation[0] == '-') {
     602              Daylight = 0xff; //make it invalid = will not use
     603            }
    525604            if (Daylight != 0 && Daylight != 1 && Daylight != 3) {
    526605              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-d");
     
    608687    {-720 , STRING_TOKEN (STR_TIMEZONE_P12)},
    609688    {-780 , STRING_TOKEN (STR_TIMEZONE_P13)},
    610     {-840 , STRING_TOKEN (STR_TIMEZONE_P14)}
     689    {-840 , STRING_TOKEN (STR_TIMEZONE_P14)},
     690    {EFI_UNSPECIFIED_TIMEZONE, STRING_TOKEN (STR_TIMEZONE_LOCAL)}
    611691};
    612692
     
    638718  }
    639719
     720  if (StrniCmp (TimeZoneString, L"_local", StrLen (TimeZoneString)) == NULL) {
     721    Status = gRT->GetTime (&TheTime, NULL);
     722    if (EFI_ERROR (Status)) {
     723      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
     724      return (SHELL_DEVICE_ERROR);
     725    }
     726
     727    TheTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE;
     728    Status = gRT->SetTime (&TheTime);
     729    if (!EFI_ERROR(Status)){
     730      return (SHELL_SUCCESS);
     731    }
     732    return (SHELL_INVALID_PARAMETER);
     733  }
    640734  if (TimeZoneString != NULL && !InternalIsTimeLikeString(TimeZoneString, L':', 1, 1, TRUE)) {
    641735    return (SHELL_INVALID_PARAMETER);
     
    644738  Status = gRT->GetTime(&TheTime, NULL);
    645739  if (EFI_ERROR(Status)) {
     740    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
    646741    return (SHELL_DEVICE_ERROR);
    647742  }
     
    660755    TheTime.TimeZone = (INT16)((ShellStrToUintn (++Walker)) * 60);
    661756  } else {
    662     TheTime.TimeZone = (INT16)((ShellStrToUintn (Walker)) * -60);
     757    TheTime.TimeZone = (INT16)((INT16)(ShellStrToUintn (Walker)) * -60);
    663758  }
    664759  if (Walker2 != NULL) {
     
    789884      //
    790885      Status = gRT->GetTime(&TheTime, NULL);
    791       ASSERT_EFI_ERROR(Status);
     886      if (EFI_ERROR(Status)) {
     887        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
     888        return (SHELL_DEVICE_ERROR);
     889      }
    792890
    793891      if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {
     
    807905              // Print basic info only
    808906              //
    809               if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {
    810                 TzMinutes = 0;
    811               } else {
    812                 TzMinutes = (ABS(TheTime.TimeZone)) % 60;
    813               }
     907              TzMinutes = (ABS(TheTime.TimeZone)) % 60;
    814908
    815909              ShellPrintHiiEx (
     
    819913                STRING_TOKEN(STR_TIMEZONE_SIMPLE),
    820914                gShellLevel2HiiHandle,
    821                 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"),
    822                 TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,
     915                (TheTime.TimeZone > 0?L"-":L"+"),
     916                (ABS(TheTime.TimeZone)) / 60,
    823917                TzMinutes);
    824918            }
     
    831925          // Print basic info only
    832926          //
    833           if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {
    834             TzMinutes = 0;
    835           } else {
    836             TzMinutes = (ABS(TheTime.TimeZone)) % 60;
    837           }
     927          TzMinutes = (ABS(TheTime.TimeZone)) % 60;
     928
    838929          ShellPrintHiiEx (
    839930            -1,
     
    842933            STRING_TOKEN(STR_TIMEZONE_SIMPLE),
    843934            gShellLevel2HiiHandle,
    844             TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"),
    845             TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,
     935            (TheTime.TimeZone > 0?L"-":L"+"),
     936            (ABS(TheTime.TimeZone)) / 60,
    846937            TzMinutes);
     938
    847939          if (ShellCommandLineGetFlag(Package, L"-f")) {
    848940            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle);
     
    851943      } else {
    852944        //
    853         // TimeZone was EFI_UNSPECIFIED_TIMEZONE (unknown) from GetTime()
     945        // TimeZone was EFI_UNSPECIFIED_TIMEZONE (local) from GetTime()
    854946        //
     947        if (ShellCommandLineGetFlag (Package, L"-f")) {
     948          for ( LoopVar = 0
     949              ; LoopVar < sizeof (TimeZoneList) / sizeof (TimeZoneList[0])
     950              ; LoopVar++
     951             ){
     952            if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) {
     953              //
     954              //  Print all info about current time zone
     955              //
     956              ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle);
     957              break;
     958            }
     959          }
     960        } else {
     961          //
     962          // Print basic info only
     963          //
     964          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_TIMEZONE_SIMPLE_LOCAL), gShellLevel2HiiHandle);
     965        }
    855966      }
    856967    }
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c

    r48674 r58459  
    2222  * functions are non-interactive only
    2323
    24 
    25   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     24  Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
     25  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
    2626  This program and the accompanying materials
    2727  are licensed and made available under the terms and conditions of the BSD License
     
    9494  ShellCommandRegisterCommandName(L"parse",    ShellCommandRunParse   , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_PARSE)  );
    9595  ShellCommandRegisterCommandName(L"reset",    ShellCommandRunReset   , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RESET)  );
    96   ShellCommandRegisterCommandName(L"set",      ShellCommandRunSet     , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET)    );
     96  ShellCommandRegisterCommandName(L"set",      ShellCommandRunSet     , ShellCommandGetManFileNameLevel2, 2, L"",FALSE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET)    );
    9797  ShellCommandRegisterCommandName(L"ls",       ShellCommandRunLs      , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LS)     );
    9898  ShellCommandRegisterCommandName(L"rm",       ShellCommandRunRm      , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RM)     );
     
    108108  ShellCommandRegisterAlias(L"cd ..", L"cd..");
    109109  ShellCommandRegisterAlias(L"cd \\", L"cd\\");
    110   ShellCommandRegisterAlias(L"ren", L"mv");
     110  ShellCommandRegisterAlias(L"mv", L"ren");
     111  ShellCommandRegisterAlias(L"mv", L"move");
     112  ShellCommandRegisterAlias(L"map", L"mount");
    111113  //
    112114  // These are installed in level 2 or 3...
     
    308310}
    309311
     312
     313/**
     314  Cleans off all the quotes in the string.
     315
     316  @param[in]     OriginalString   pointer to the string to be cleaned.
     317  @param[out]   CleanString      The new string with all quotes removed.
     318                                                  Memory allocated in the function and free
     319                                                  by caller.
     320
     321  @retval EFI_SUCCESS   The operation was successful.
     322**/
     323EFI_STATUS
     324EFIAPI
     325ShellLevel2StripQuotes (
     326  IN  CONST CHAR16     *OriginalString,
     327  OUT CHAR16           **CleanString
     328  )
     329{
     330  CHAR16            *Walker;
     331 
     332  if (OriginalString == NULL || CleanString == NULL) {
     333    return EFI_INVALID_PARAMETER;
     334  }
     335
     336  *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);
     337  if (*CleanString == NULL) {
     338    return EFI_OUT_OF_RESOURCES;
     339  }
     340
     341  for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
     342    if (*Walker == L'\"') {
     343      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
     344    }
     345  }
     346
     347  return EFI_SUCCESS;
     348}
     349
     350
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h

    r48674 r58459  
    1010
    1111
    12   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     12  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
    1313  This program and the accompanying materials
    1414  are licensed and made available under the terms and conditions of the BSD License
     
    3434#include <Protocol/LoadedImage.h>
    3535#include <Protocol/UnicodeCollation.h>
    36 #include <Protocol/DevicePathToText.h>
    3736
    3837#include <Library/BaseLib.h>
     
    303302
    304303/**
     304  Cleans off all the quotes in the string.
     305
     306  @param[in]     OriginalString   pointer to the string to be cleaned.
     307  @param[out]   CleanString      The new string with all quotes removed.
     308                                                  Memory allocated in the function and free
     309                                                  by caller.
     310
     311  @retval EFI_SUCCESS   The operation was successful.
     312**/
     313EFI_STATUS
     314EFIAPI
     315ShellLevel2StripQuotes (
     316  IN  CONST CHAR16     *OriginalString,
     317  OUT CHAR16           **CleanString
     318  );
     319
     320/**
    305321  Function for 'Vol' command.
    306322
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf

    r48674 r58459  
    22# Provides shell level 2 functions
    33#
    4 # Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
     4# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. <BR>
    55#
    66#  This program and the accompanying materials
     
    6666  HandleParsingLib
    6767  PathLib
     68  DevicePathLib
    6869
    6970[Protocols]
    70   gEfiUnicodeCollation2ProtocolGuid                       # ALWAYS_CONSUMED
    71   gEfiShellProtocolGuid                                   # ALWAYS_CONSUMED
    72   gEfiShellParametersProtocolGuid                         # ALWAYS_CONSUMED
    73   gEfiDevicePathProtocolGuid                              # ALWAYS_CONSUMED
    74   gEfiLoadedImageProtocolGuid                             # ALWAYS_CONSUMED
    75   gEfiSimpleFileSystemProtocolGuid                        # ALWAYS_CONSUMED
    76   gEfiDevicePathToTextProtocolGuid                        # ALWAYS_CONSUMED
     71  gEfiUnicodeCollation2ProtocolGuid                       ## CONSUMES
     72  gEfiShellProtocolGuid                                   ## CONSUMES
     73  gEfiShellParametersProtocolGuid                         ## CONSUMES
     74  gEfiDevicePathProtocolGuid                              ## CONSUMES
     75  gEfiLoadedImageProtocolGuid                             ## CONSUMES
     76  gEfiSimpleFileSystemProtocolGuid                        ## CONSUMES
    7777
    7878[Pcd.common]
    79   gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel         # ALWAYS_CONSUMED
    80   gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize    # ALWAYS_CONSUMED
     79  gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel         ## CONSUMES
     80  gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize    ## CONSUMES
    8181
    8282[Guids]
    83   gEfiFileSystemInfoGuid
    84   gEfiFileInfoGuid
    85   gShellLevel2HiiGuid
     83  gEfiFileSystemInfoGuid                                  ## CONSUMES ## GUID
     84  gEfiFileInfoGuid                                        ## UNDEFINED
     85  gShellLevel2HiiGuid                                     ## SOMETIMES_CONSUMES ## HII
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel2CommandsLib/Vol.c

    r48674 r58459  
    22  Main file for vol shell level 2 function.
    33
    4   Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    102102
    103103  if (Delete) {
    104     StrCpy ((CHAR16 *) SysInfo->VolumeLabel, L"");
     104    *((CHAR16 *) SysInfo->VolumeLabel) = CHAR_NULL;
    105105    SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize(SysInfo->VolumeLabel);
    106106    Status = EfiFpHandle->SetInfo(
     
    120120    }
    121121    if (SysInfo != NULL) {
    122       StrCpy ((CHAR16 *) SysInfo->VolumeLabel, Name);
     122      StrnCpy ((CHAR16 *) SysInfo->VolumeLabel, Name, (Size1 > Size2?Size1/sizeof(CHAR16):Size2/sizeof(CHAR16))-1);
    123123      SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + Size1;
    124124      Status = EfiFpHandle->SetInfo(
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/Alias.c

    r48674 r58459  
    22  Main file for Alias shell level 3 function.
    33
    4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    9191  CONST CHAR16        *Param1;
    9292  CONST CHAR16        *Param2;
     93  CHAR16              *CleanParam2;
    9394
    9495  ProblemParam        = NULL;
    9596  ShellStatus         = SHELL_SUCCESS;
     97  CleanParam2         = NULL;
    9698
    9799  //
     
    119121    Param1 = ShellCommandLineGetRawValue(Package, 1);
    120122    Param2 = ShellCommandLineGetRawValue(Package, 2);
     123
     124    if (Param2 != NULL) {
     125      CleanParam2 = AllocateCopyPool (StrSize(Param2), Param2);
     126      if (CleanParam2 == NULL) {
     127        return SHELL_OUT_OF_RESOURCES;
     128      }
     129
     130      if (CleanParam2[0] == L'\"' && CleanParam2[StrLen(CleanParam2)-1] == L'\"') {
     131        CleanParam2[StrLen(CleanParam2)-1] = L'\0';
     132        CopyMem (CleanParam2, CleanParam2 + 1, StrSize(CleanParam2) - sizeof(CleanParam2[0]));
     133      }
     134    }
     135
    121136    //
    122137    // check for "-?"
     
    139154      // must be adding an alias
    140155      //
    141       Status = gEfiShellProtocol->SetAlias(Param2, Param1, FALSE, ShellCommandLineGetFlag(Package, L"-v"));
     156      Status = gEfiShellProtocol->SetAlias(CleanParam2, Param1, FALSE, ShellCommandLineGetFlag(Package, L"-v"));
    142157      if (EFI_ERROR(Status)) {
    143158        if (Status == EFI_ACCESS_DENIED) {
     
    162177  }
    163178
     179  SHELL_FREE_NON_NULL (CleanParam2);
    164180  return (ShellStatus);
    165181}
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c

    r48674 r58459  
    22  Main file for attrib shell level 2 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    3030  EFI_STATUS    Status;
    3131  LIST_ENTRY    *Package;
    32   CHAR16        *Message;
    3332  UINTN         Background;
    3433  UINTN         ForeColor;
     
    3736  CONST CHAR16  *Param1;
    3837
     38  //
     39  // Initialize variables
     40  //
    3941  ShellStatus   = SHELL_SUCCESS;
    4042  ProblemParam  = NULL;
    4143  Background    = 0;
    42 
    43   //
    44   // Initialize variables
    45   //
    46   Message = NULL;
    4744
    4845  //
     
    115112          }
    116113          ForeColor = (~ShellStrToUintn(Param1)) & 0xF;
    117           Status = gST->ConOut->SetAttribute (gST->ConOut, ForeColor | Background);
     114          Status = gST->ConOut->SetAttribute (gST->ConOut, (ForeColor | Background) & 0x7F );
    118115          ASSERT_EFI_ERROR(Status);
    119116          Status = gST->ConOut->ClearScreen (gST->ConOut);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c

    r48674 r58459  
    22  Main file for Echo shell level 3 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    4141  UINTN               ParamCount;
    4242  CHAR16              *ProblemParam;
     43  UINTN               Size;
     44  CHAR16              *PrintString;
    4345
     46  Size                = 0;
    4447  ProblemParam        = NULL;
     48  PrintString         = NULL;
    4549  ShellStatus         = SHELL_SUCCESS;
    4650
     
    97101          ; ParamCount++
    98102         ) {
     103        StrnCatGrow(&PrintString, &Size, ShellCommandLineGetRawValue(Package, ParamCount), 0);
    99104        if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {
    100           ShellPrintEx(-1, -1, L"%s ", ShellCommandLineGetRawValue(Package, ParamCount));
    101         } else {
    102           ShellPrintEx(-1, -1, L"%s", ShellCommandLineGetRawValue(Package, ParamCount));
    103         }
     105          StrnCatGrow(&PrintString, &Size, L" ", 0);
     106        }
    104107      }
    105       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel3HiiHandle);
     108      ShellPrintEx(-1, -1, L"%s\r\n", PrintString);
     109      SHELL_FREE_NON_NULL(PrintString);
    106110    }
    107111
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/GetMtc.c

    r48674 r58459  
    22  Main file for GetMtc shell level 3 function.
    33
    4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    7171      //
    7272      Status = gBS->GetNextMonotonicCount(&Mtc);
    73       switch(Status) {
    74         case EFI_DEVICE_ERROR:
    75           ShellStatus = SHELL_DEVICE_ERROR;
    76           break;
    77         case EFI_SECURITY_VIOLATION:
    78           ShellStatus = SHELL_SECURITY_VIOLATION;
    79           break;
    80         default:
    81           if (EFI_ERROR(Status)) {
    82             ShellStatus = SHELL_DEVICE_ERROR;
    83           }
     73      if (Status == EFI_DEVICE_ERROR) {
     74        ShellStatus = SHELL_DEVICE_ERROR;
     75      } else if (Status == EFI_SECURITY_VIOLATION) {
     76        ShellStatus = SHELL_SECURITY_VIOLATION;
     77      } else if (EFI_ERROR(Status)) {
     78        ShellStatus = SHELL_DEVICE_ERROR;
    8479      }
    8580
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c

    r48674 r58459  
    22  Main file for Help shell level 3 function.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>
     5  Copyright (c) 2014, ARM Limited. All rights reserved. <BR>
    56  This program and the accompanying materials
    67  are licensed and made available under the terms and conditions of the BSD License
     
    1617
    1718#include <Library/ShellLib.h>
     19#include <Library/HandleParsingLib.h>
     20
     21#include <Protocol/EfiShellDynamicCommand.h>
     22
     23/**
     24  Attempt to print help from a dynamically added command.
     25
     26  @param[in]  CommandToGetHelpOn  The unicode name of the command that help is
     27                                  requested on.
     28  @param[in]  SectionToGetHelpOn  Pointer to the section specifier(s).
     29  @param[in]  PrintCommandText    Print the command followed by the help content
     30                                  or just help.
     31
     32  @retval EFI_SUCCESS             The help was displayed
     33  @retval EFI_NOT_FOUND           The command name could not be found
     34  @retval EFI_DEVICE_ERROR        The help data format was incorrect.
     35**/
     36EFI_STATUS
     37EFIAPI
     38PrintDynamicCommandHelp(
     39  IN CHAR16  *CommandToGetHelpOn,
     40  IN CHAR16  *SectionToGetHelpOn,
     41  IN BOOLEAN  PrintCommandText
     42 )
     43{
     44  EFI_STATUS                          Status;
     45  BOOLEAN                             Found;
     46  EFI_HANDLE                          *CommandHandleList;
     47  EFI_HANDLE                          *NextCommand;
     48  EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL  *DynamicCommand;
     49
     50  Status = EFI_NOT_FOUND;
     51  Found = FALSE;
     52  CommandHandleList = NULL;
     53
     54  CommandHandleList = GetHandleListByProtocol(&gEfiShellDynamicCommandProtocolGuid);
     55
     56  if (CommandHandleList == NULL) {
     57    //
     58    // not found or out of resources
     59    //
     60    return Status;
     61  }
     62
     63  for (NextCommand = CommandHandleList; *NextCommand != NULL; NextCommand++) {
     64    Status = gBS->HandleProtocol(
     65      *NextCommand,
     66      &gEfiShellDynamicCommandProtocolGuid,
     67      (VOID **)&DynamicCommand
     68      );
     69
     70    if (EFI_ERROR(Status)) {
     71      continue;
     72    }
     73
     74    //
     75    // Check execution break flag when printing multiple command help information.
     76    //
     77    if (ShellGetExecutionBreakFlag ()) {
     78      break;
     79    }
     80
     81    if ((gUnicodeCollation->MetaiMatch (gUnicodeCollation, (CHAR16 *)DynamicCommand->CommandName, CommandToGetHelpOn)) ||
     82      (gEfiShellProtocol->GetAlias (CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch (gUnicodeCollation, (CHAR16 *)DynamicCommand->CommandName, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {
     83      // Print as Shell Help if in ManPage format.
     84      Status = ShellPrintHelp (DynamicCommand->CommandName, SectionToGetHelpOn,
     85                              PrintCommandText);
     86      if (Status == EFI_DEVICE_ERROR) {
     87        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HELP_INV),
     88                        gShellLevel3HiiHandle, DynamicCommand->CommandName);
     89      } else if (EFI_ERROR(Status)) {
     90        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HELP_NF),
     91                        gShellLevel3HiiHandle, DynamicCommand->CommandName);
     92      } else {
     93        Found = TRUE;
     94      }
     95    }
     96  }
     97
     98  return (Found ? EFI_SUCCESS : Status);
     99
     100}
    18101
    19102STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
     
    42125  CHAR16              *ProblemParam;
    43126  SHELL_STATUS        ShellStatus;
    44   CHAR16              *OutText;
    45127  CONST COMMAND_LIST  *CommandList;
    46128  CONST COMMAND_LIST  *Node;
     
    49131  CHAR16              *HiiString;
    50132  BOOLEAN             Found;
    51 
     133  BOOLEAN             PrintCommandText;
     134
     135  PrintCommandText    = TRUE;
    52136  ProblemParam        = NULL;
    53137  ShellStatus         = SHELL_SUCCESS;
    54   OutText             = NULL;
    55138  CommandToGetHelpOn  = NULL;
    56139  SectionToGetHelpOn  = NULL;
     
    110193        StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
    111194      } else {
     195        PrintCommandText = FALSE;
    112196        ASSERT(SectionToGetHelpOn == NULL);
    113197        //
     
    120204        } else if (ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v")) {
    121205        } else {
    122           StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);
     206          //
     207          // The output of help <command> will display NAME, SYNOPSIS, OPTIONS, DESCRIPTION, and EXAMPLES sections.
     208          //
     209          StrnCatGrow (&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS,OPTIONS,DESCRIPTION,EXAMPLES", 0);
    123210        }
    124211      }
     
    140227            ; Node = (COMMAND_LIST*)GetNextNode(&CommandList->Link, &Node->Link)
    141228           ){
     229          //
     230          // Checking execution break flag when print multiple command help information.
     231          //
     232          if (ShellGetExecutionBreakFlag ()) {
     233            break;
     234          }
    142235          if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) ||
    143236             (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {
     
    145238            // We have a command to look for help on.
    146239            //
    147             Status = gEfiShellProtocol->GetHelpText(Node->CommandString, SectionToGetHelpOn, &OutText);
    148             if (EFI_ERROR(Status) || OutText == NULL) {
    149               if (Status == EFI_DEVICE_ERROR) {
     240            Status = ShellPrintHelp(Node->CommandString, SectionToGetHelpOn, PrintCommandText);
     241            if (Status == EFI_DEVICE_ERROR) {
    150242                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, Node->CommandString);
    151               } else {
     243            } else if (EFI_ERROR(Status)) {
    152244                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString);
    153               }
    154               ShellStatus = SHELL_NOT_FOUND;
    155245            } else {
    156               while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {
    157                 OutText[StrLen(OutText)-1] = CHAR_NULL;
    158               }
    159               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_COMMAND), gShellLevel3HiiHandle, Node->CommandString, OutText);
    160               FreePool(OutText);
    161               OutText = NULL;
    162               Found = TRUE;
     246                Found = TRUE;
    163247            }
    164248          }
    165249        }
    166       }
    167 
    168       if (!Found && ShellStatus == SHELL_SUCCESS) {
    169         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);
     250
     251        //
     252        // now try to match against the dynamic command list and print help
     253        //
     254        Status = PrintDynamicCommandHelp (CommandToGetHelpOn, SectionToGetHelpOn,
     255                                          PrintCommandText);
     256        if (!EFI_ERROR(Status)) {
     257          Found = TRUE;
     258        }
     259
     260        //
     261        // Search the .man file for Shell applications (Shell external commands).
     262        //
     263        if (!Found) {
     264          Status = ShellPrintHelp(CommandToGetHelpOn, SectionToGetHelpOn, FALSE);
     265          if (Status == EFI_DEVICE_ERROR) {
     266              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, CommandToGetHelpOn);
     267          } else if (EFI_ERROR(Status)) {
     268              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);
     269          } else {
     270            Found = TRUE;
     271          }
     272        }
     273      }
     274
     275      if (!Found) {
    170276        ShellStatus = SHELL_NOT_FOUND;
    171277      }
     
    177283    }
    178284  }
     285
     286  if (CommandToGetHelpOn != NULL && StrCmp(CommandToGetHelpOn, L"*") == 0){
     287    //
     288    // If '*' then the command entered was 'Help' without qualifiers, This footer
     289    // provides additional info on help switches
     290    //
     291    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_FOOTER), gShellLevel3HiiHandle);
     292  }
    179293  if (CommandToGetHelpOn != NULL) {
    180294    FreePool(CommandToGetHelpOn);
     
    186300  return (ShellStatus);
    187301}
    188 
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/Pause.c

    r48674 r58459  
    22  Main file for Pause shell level 3 function.
    33
    4   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
     4  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    4141  ProblemParam        = NULL;
    4242  ShellStatus         = SHELL_SUCCESS;
     43  Resp                = NULL;
    4344
    4445  //
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c

    r48674 r58459  
    3939  }
    4040  Status = gRT->GetTime(&FileInfo->ModificationTime, NULL);
    41   ASSERT_EFI_ERROR(Status);
     41  if (EFI_ERROR(Status)) {
     42    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"gRT->GetTime", Status);
     43    return (SHELL_DEVICE_ERROR);
     44  }
     45
    4246  CopyMem(&FileInfo->LastAccessTime, &FileInfo->ModificationTime, sizeof(EFI_TIME));
    4347
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/Type.c

    r48674 r58459  
    22  Main file for Type shell level 3 function.
    33
     4  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
    45  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
    56  This program and the accompanying materials
     
    3233EFIAPI
    3334TypeFileByHandle (
    34   IN EFI_HANDLE Handle,
    35   BOOLEAN Ascii,
    36   BOOLEAN UCS2
     35  IN SHELL_FILE_HANDLE Handle,
     36  IN BOOLEAN Ascii,
     37  IN BOOLEAN UCS2
    3738  )
    3839{
    3940  UINTN       ReadSize;
    4041  VOID        *Buffer;
     42  VOID        *AllocatedBuffer;
    4143  EFI_STATUS  Status;
    4244  UINTN       LoopVar;
     45  UINTN       LoopSize;
    4346  CHAR16      AsciiChar;
    44 
    45   ReadSize = PcdGet16(PcdShellFileOperationSize);
    46   Buffer = AllocateZeroPool(ReadSize);
    47   if (Buffer == NULL) {
     47  CHAR16      Ucs2Char;
     48
     49  ReadSize = PcdGet32(PcdShellFileOperationSize);
     50  AllocatedBuffer = AllocateZeroPool(ReadSize);
     51  if (AllocatedBuffer == NULL) {
    4852    return (EFI_OUT_OF_RESOURCES);
    4953  }
     
    5256  ASSERT_EFI_ERROR(Status);
    5357
    54   while (ReadSize == ((UINTN)PcdGet16(PcdShellFileOperationSize))){
     58  while (ReadSize == ((UINTN)PcdGet32(PcdShellFileOperationSize))) {
     59    Buffer = AllocatedBuffer;
    5560    ZeroMem(Buffer, ReadSize);
    5661    Status = ShellReadFile(Handle, &ReadSize, Buffer);
     
    5964    }
    6065
    61     if (!(Ascii|UCS2)){
     66    if (!(Ascii|UCS2)) {
    6267      if (*(UINT16*)Buffer == gUnicodeFileTag) {
    6368        UCS2 = TRUE;
    64         Buffer = ((UINT16*)Buffer) + 1;
    6569      } else {
    6670        Ascii = TRUE;
     
    6872    }
    6973
    70     //
    71     // We want to use plain Print function here! (no color support for files)
    72     //
    73     if (Ascii){
    74       for (LoopVar = 0 ; LoopVar < ReadSize ; LoopVar++) {
    75       AsciiChar = CHAR_NULL;
    76       AsciiChar = ((CHAR8*)Buffer)[LoopVar];
    77       if (AsciiChar == CHAR_NULL) {
    78         AsciiChar = '.';
    79       }
    80       Print(L"%c", AsciiChar);
     74    if (Ascii) {
     75      LoopSize = ReadSize;
     76      for (LoopVar = 0 ; LoopVar < LoopSize ; LoopVar++) {
     77        //
     78        // The valid range of ASCII characters is 0x20-0x7E.
     79        // Display "." when there is an invalid character.
     80        //
     81        AsciiChar = CHAR_NULL;
     82        AsciiChar = ((CHAR8*)Buffer)[LoopVar];
     83        if (AsciiChar == '\r' || AsciiChar == '\n') {
     84          //
     85          // Allow Line Feed (LF) (0xA) & Carriage Return (CR) (0xD)
     86          // characters to be displayed as is.
     87          //
     88          if (AsciiChar == '\n' && ((CHAR8*)Buffer)[LoopVar-1] != '\r') {
     89            //
     90            // In case Line Feed (0xA) is encountered & Carriage Return (0xD)
     91            // was not the previous character, print CR and LF. This is because
     92            // Shell 2.0 requires carriage return with line feed for displaying
     93            // each new line from left.
     94            //
     95            ShellPrintEx (-1, -1, L"\r\n");
     96            continue;
     97          }
     98        } else {
     99          //
     100          // For all other characters which are not printable, display '.'
     101          //
     102          if (AsciiChar < 0x20 || AsciiChar >= 0x7F) {
     103            AsciiChar = '.';
     104          }
     105        }
     106        ShellPrintEx (-1, -1, L"%c", AsciiChar);
    81107      }
    82108    } else {
    83       Print(L"%s", Buffer);
     109      if (*(UINT16*)Buffer == gUnicodeFileTag) {
     110        //
     111        // For unicode files, skip displaying the byte order marker.
     112        //
     113        Buffer = ((UINT16*)Buffer) + 1;
     114        LoopSize = (ReadSize / (sizeof (CHAR16))) - 1;
     115      } else {
     116        LoopSize = ReadSize / (sizeof (CHAR16));
     117      }
     118     
     119      for (LoopVar = 0 ; LoopVar < LoopSize ; LoopVar++) {
     120        //
     121        // An invalid range of characters is 0x0-0x1F.
     122        // Display "." when there is an invalid character.
     123        //
     124        Ucs2Char = CHAR_NULL;
     125        Ucs2Char = ((CHAR16*)Buffer)[LoopVar];
     126        if (Ucs2Char == '\r' || Ucs2Char == '\n') {
     127          //
     128          // Allow Line Feed (LF) (0xA) & Carriage Return (CR) (0xD)
     129          // characters to be displayed as is.
     130          //
     131          if (Ucs2Char == '\n' && ((CHAR16*)Buffer)[LoopVar-1] != '\r') {
     132            //
     133            // In case Line Feed (0xA) is encountered & Carriage Return (0xD)
     134            // was not the previous character, print CR and LF. This is because
     135            // Shell 2.0 requires carriage return with line feed for displaying
     136            // each new line from left.
     137            //
     138            ShellPrintEx (-1, -1, L"\r\n");
     139            continue;
     140          }
     141        }
     142        else if (Ucs2Char < 0x20) {
     143          //
     144          // For all other characters which are not printable, display '.'
     145          //
     146          Ucs2Char = L'.';
     147        }
     148        ShellPrintEx (-1, -1, L"%c", Ucs2Char);
     149      }
     150    }
     151
     152    if (ShellGetExecutionBreakFlag()) {
     153      break;
    84154    }
    85155  }
    86   Print(L"\r\n", Buffer);
     156  FreePool (AllocatedBuffer);
     157  ShellPrintEx (-1, -1, L"\r\n");
    87158  return (Status);
    88159}
     
    197268                ; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
    198269               ){
     270
     271              if (ShellGetExecutionBreakFlag()) {
     272                break;
     273              }
     274
    199275              //
    200276              // make sure the file opened ok
     
    218294              // do it
    219295              //
    220               Status = TypeFileByHandle(Node->Handle, AsciiMode, UnicodeMode);
     296              Status = TypeFileByHandle (Node->Handle, AsciiMode, UnicodeMode);
    221297              if (EFI_ERROR(Status)) {
    222298                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TYP_ERROR), gShellLevel3HiiHandle, Node->FileName, Status);
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.c

    r48674 r58459  
    22  Main file for NULL named library for level 3 shell command functions.
    33
     4  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
    45  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
    56  This program and the accompanying materials
     
    7677  ShellCommandRegisterCommandName(L"help",    ShellCommandRunHelp   , ShellCommandGetManFileNameLevel3, 3, L"", TRUE , gShellLevel3HiiHandle, STRING_TOKEN(STR_GET_HELP_HELP));
    7778
     79  ShellCommandRegisterAlias(L"type", L"cat");
     80
    7881  return (EFI_SUCCESS);
    7982}
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.h

    r48674 r58459  
    2626#include <Protocol/LoadedImage.h>
    2727#include <Protocol/UnicodeCollation.h>
    28 #include <Protocol/DevicePathToText.h>
    2928
    3029#include <Library/BaseLib.h>
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf

    r48674 r58459  
    33# Note that the interactive versions of the time, date, and timezone functions are handled in the level 2 library.
    44#
    5 # Copyright (c) 2009-2011, Intel Corporation. All rights reserved. <BR>
     5# Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
     6# Copyright (c) 2009-2015, Intel Corporation. All rights reserved. <BR>
    67#
    78#  This program and the accompanying materials
     
    6061  HiiLib
    6162  FileHandleLib
     63  HandleParsingLib
    6264
    6365[Guids]
    64   gEfiFileInfoGuid
    65   gShellLevel3HiiGuid
     66  gEfiFileInfoGuid                                        ## UNDEFINED
     67  gShellLevel3HiiGuid                                     ## SOMETIMES_CONSUMES ## HII
    6668
    6769[Pcd.common]
    68   gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel
    69   gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize
     70  gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel         ## CONSUMES
     71  gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize    ## SOMETIMES_CONSUMES
     72  gEfiShellPkgTokenSpaceGuid.PcdShellSupplier             ## SOMETIMES_CONSUMES
    7073
     74[Protocols]
     75  gEfiShellDynamicCommandProtocolGuid                     ## SOMETIMES_CONSUMES
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLevel3CommandsLib/Ver.c

    r48674 r58459  
    22  Main file for Ver shell level 3 function.
    33
     4  Copyright (c) 2013, Hewlett-Packard Development Company, L.P.
    45  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
    56  This program and the accompanying materials
     
    115116            -1,
    116117            NULL,
    117             STRING_TOKEN (STR_VER_EXTRA_STRING),
    118             gShellLevel3HiiHandle
     118            STRING_TOKEN (STR_VER_OUTPUT_SUPPLIER),
     119            gShellLevel3HiiHandle,
     120            (CHAR16 *) PcdGetPtr (PcdShellSupplier)
    119121           );
    120122
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLib/UefiShellLib.c

    r48674 r58459  
    22  Provides interface to shell functionality for shell commands and applications.
    33
    4   Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
    55  This program and the accompanying materials
    66  are licensed and made available under the terms and conditions of the BSD License
     
    487487  EFI_FILE_PROTOCOL               *Handle1;
    488488  EFI_FILE_PROTOCOL               *Handle2;
     489  CHAR16                          *FnafPathName;
     490  UINTN                           PathLen;
    489491
    490492  if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {
     
    553555
    554556    //
     557    // File Name Alignment Fix (FNAF)
     558    // Handle2->Open may be incapable of handling a unaligned CHAR16 data.
     559    // The structure pointed to by FilePath may be not CHAR16 aligned.
     560    // This code copies the potentially unaligned PathName data from the
     561    // FilePath structure to the aligned FnafPathName for use in the
     562    // calls to Handl2->Open.
     563    //
     564
     565    //
     566    // Determine length of PathName, in bytes.
     567    //
     568    PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;
     569
     570    //
     571    // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment
     572    // Copy bytes from possibly unaligned location to aligned location
     573    //
     574    FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName);
     575    if (FnafPathName == NULL) {
     576      return EFI_OUT_OF_RESOURCES;
     577    }
     578
     579    //
    555580    // Try to test opening an existing file
    556581    //
     
    558583                          Handle2,
    559584                          &Handle1,
    560                           ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,
     585                          FnafPathName,
    561586                          OpenMode &~EFI_FILE_MODE_CREATE,
    562587                          0
     
    570595                            Handle2,
    571596                            &Handle1,
    572                             ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,
     597                            FnafPathName,
    573598                            OpenMode,
    574599                            Attributes
    575600                           );
    576601    }
     602
     603    //
     604    // Free the alignment buffer
     605    //
     606    FreePool(FnafPathName);
     607
    577608    //
    578609    // Close the last node
     
    11451176  device.
    11461177
    1147   The EnvironmentVariables and Status parameters are ignored in a pre-UEFI Shell 2.0
     1178  The EnvironmentVariables pararemeter is ignored in a pre-UEFI Shell 2.0
    11481179  environment.  The values pointed to by the parameters will be unchanged by the
    11491180  ShellExecute() function.  The Output parameter has no effect in a
     
    11731204  )
    11741205{
     1206  EFI_STATUS                CmdStatus;
    11751207  //
    11761208  // Check for UEFI Shell 2.0 protocols
     
    11911223  if (mEfiShellEnvironment2 != NULL) {
    11921224    //
    1193     // Call EFI Shell version (not using EnvironmentVariables or Status parameters)
     1225    // Call EFI Shell version.
    11941226    // Due to oddity in the EFI shell we want to dereference the ParentHandle here
    11951227    //
    1196     return (mEfiShellEnvironment2->Execute(*ParentHandle,
     1228    CmdStatus = (mEfiShellEnvironment2->Execute(*ParentHandle,
    11971229                                          CommandLine,
    11981230                                          Output));
     1231    //
     1232    // No Status output parameter so just use the returned status
     1233    //
     1234    if (Status != NULL) {
     1235      *Status = CmdStatus;
     1236    }
     1237    //
     1238    // If there was an error, we can't tell if it was from the command or from
     1239    // the Execute() function, so we'll just assume the shell ran successfully
     1240    // and the error came from the command.
     1241    //
     1242    return EFI_SUCCESS;
    11991243  }
    12001244
    12011245  return (EFI_UNSUPPORTED);
    12021246}
     1247
    12031248/**
    12041249  Retreives the current directory path
     
    13861431    // allocate new space to copy strings and structure
    13871432    //
    1388     NewInfo->FullName     = AllocateZeroPool(StrSize(OldInfo->FullName));
    1389     NewInfo->FileName     = AllocateZeroPool(StrSize(OldInfo->FileName));
    1390     NewInfo->Info         = AllocateZeroPool((UINTN)OldInfo->Info->Size);
     1433    NewInfo->FullName     = AllocateCopyPool(StrSize(OldInfo->FullName), OldInfo->FullName);
     1434    NewInfo->FileName     = AllocateCopyPool(StrSize(OldInfo->FileName), OldInfo->FileName);
     1435    NewInfo->Info         = AllocateCopyPool((UINTN)OldInfo->Info->Size, OldInfo->Info);
    13911436
    13921437    //
     
    13941439    //
    13951440    if (NULL == NewInfo->FullName || NewInfo->FileName == NULL || NewInfo->Info == NULL) {
     1441      //
     1442      // Free the partially allocated new node
     1443      //
     1444      SHELL_FREE_NON_NULL(NewInfo->FullName);
     1445      SHELL_FREE_NON_NULL(NewInfo->FileName);
     1446      SHELL_FREE_NON_NULL(NewInfo->Info);
     1447      SHELL_FREE_NON_NULL(NewInfo);
     1448
     1449      //
     1450      // Free the previously converted stuff
     1451      //
    13961452      ShellCloseFileMetaArg((EFI_SHELL_FILE_INFO**)(&ListHead));
    13971453      ListHead = NULL;
     
    14001456
    14011457    //
    1402     // Copt the strings and structure
    1403     //
    1404     StrCpy(NewInfo->FullName, OldInfo->FullName);
    1405     StrCpy(NewInfo->FileName, OldInfo->FileName);
    1406     gBS->CopyMem (NewInfo->Info, OldInfo->Info, (UINTN)OldInfo->Info->Size);
    1407 
    1408     //
    14091458    // add that to the list
    14101459    //
     
    14171466
    14181467  This function uses the Arg to open all the matching files. Each matched
    1419   file has a SHELL_FILE_ARG structure to record the file information. These
    1420   structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG
     1468  file has a SHELL_FILE_INFO structure to record the file information. These
     1469  structures are placed on the list ListHead. Users can get the SHELL_FILE_INFO
    14211470  structures from ListHead to access each file. This function supports wildcards
    14221471  and will process '?' and '*' as such.  the list must be freed with a call to
     
    14461495  EFI_STATUS                    Status;
    14471496  LIST_ENTRY                    mOldStyleFileList;
     1497  CHAR16                        *CleanFilePathStr;
    14481498
    14491499  //
     
    14521502  ASSERT(Arg      != NULL);
    14531503  ASSERT(ListHead != NULL);
     1504
     1505  CleanFilePathStr = NULL;
     1506
     1507  Status = InternalShellStripQuotes (Arg, &CleanFilePathStr);
     1508  if (EFI_ERROR (Status)) {
     1509    return Status;
     1510  }
    14541511
    14551512  //
     
    14601517      *ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
    14611518      if (*ListHead == NULL) {
     1519        FreePool(CleanFilePathStr);
    14621520        return (EFI_OUT_OF_RESOURCES);
    14631521      }
    14641522      InitializeListHead(&((*ListHead)->Link));
    14651523    }
    1466     Status = gEfiShellProtocol->OpenFileList(Arg,
     1524    Status = gEfiShellProtocol->OpenFileList(CleanFilePathStr,
    14671525                                           OpenMode,
    14681526                                           ListHead);
     
    14741532    if (*ListHead != NULL && IsListEmpty(&(*ListHead)->Link)) {
    14751533      FreePool(*ListHead);
     1534      FreePool(CleanFilePathStr);
    14761535      *ListHead = NULL;
    14771536      return (EFI_NOT_FOUND);
    14781537    }
     1538    FreePool(CleanFilePathStr);
    14791539    return (Status);
    14801540  }
     
    14921552    // Get the EFI Shell list of files
    14931553    //
    1494     Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList);
     1554    Status = mEfiShellEnvironment2->FileMetaArg(CleanFilePathStr, &mOldStyleFileList);
    14951555    if (EFI_ERROR(Status)) {
    14961556      *ListHead = NULL;
     1557      FreePool(CleanFilePathStr);
    14971558      return (Status);
    14981559    }
     
    15011562      *ListHead = (EFI_SHELL_FILE_INFO    *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
    15021563      if (*ListHead == NULL) {
     1564        FreePool(CleanFilePathStr);
    15031565        return (EFI_OUT_OF_RESOURCES);
    15041566      }
     
    15211583      Status = EFI_NOT_FOUND;
    15221584    }
     1585    FreePool(CleanFilePathStr);
    15231586    return (Status);
    15241587  }
    15251588
     1589  FreePool(CleanFilePathStr);
    15261590  return (EFI_UNSUPPORTED);
    15271591}
     
    15681632      FreePool((EFI_SHELL_FILE_INFO_NO_CONST*)Node);
    15691633    }
     1634    SHELL_FREE_NON_NULL(*ListHead);
    15701635    return EFI_SUCCESS;
    15711636  }
     
    16261691      return (NULL);
    16271692    }
    1628     StrCpy(TestPath, Path);
    1629     StrCat(TestPath, FileName);
     1693    StrnCpy(TestPath, Path, Size/sizeof(CHAR16) - 1);
     1694    StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
    16301695    Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);
    16311696    if (!EFI_ERROR(Status)){
     
    16591724        }
    16601725        if (TestPath[StrLen(TestPath)-1] != L'\\') {
    1661           StrCat(TestPath, L"\\");
     1726          StrnCat(TestPath, L"\\", Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
    16621727        }
    16631728        if (FileName[0] == L'\\') {
    16641729          FileName++;
    16651730        }
    1666         StrCat(TestPath, FileName);
     1731        StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
    16671732        if (StrStr(Walker, L";") != NULL) {
    16681733          Walker = StrStr(Walker, L";") + 1;
     
    17331798  }
    17341799  for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension;  TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){
    1735     StrCpy(TestPath, FileName);
     1800    StrnCpy(TestPath, FileName, Size/sizeof(CHAR16) - 1);
    17361801    if (ExtensionWalker != NULL) {
    1737       StrCat(TestPath, ExtensionWalker);
     1802      StrnCat(TestPath, ExtensionWalker, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
    17381803    }
    17391804    TempChar = StrStr(TestPath, L";");
     
    18581923  // If we accept numbers then dont return TRUE. (they will be values)
    18591924  //
    1860   if (((Name[0] == L'-' || Name[0] == L'+') && ShellIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers) {
     1925  if (((Name[0] == L'-' || Name[0] == L'+') && InternalShellIsHexOrDecimalNumber(Name+1, FALSE, FALSE)) && AlwaysAllowNumbers) {
    18611926    return (FALSE);
    18621927  }
     
    19181983  UINTN                         Count;
    19191984  CONST CHAR16                  *TempPointer;
     1985  UINTN                         CurrentValueSize;
    19201986
    19211987  CurrentItemPackage = NULL;
     
    19732039        return (EFI_OUT_OF_RESOURCES);
    19742040      }
    1975       CurrentItemPackage->Name  = AllocateZeroPool(StrSize(Argv[LoopCounter]));
     2041      CurrentItemPackage->Name  = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]);
    19762042      if (CurrentItemPackage->Name == NULL) {
    19772043        ShellCommandLineFreeVarList(*CheckPackage);
     
    19792045        return (EFI_OUT_OF_RESOURCES);
    19802046      }
    1981       StrCpy(CurrentItemPackage->Name,  Argv[LoopCounter]);
    19822047      CurrentItemPackage->Type  = CurrentItemType;
    19832048      CurrentItemPackage->OriginalPosition = (UINTN)(-1);
     
    20162081      // get the item VALUE for a previous flag
    20172082      //
    2018       CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16), CurrentItemPackage->Value);
    2019       ASSERT(CurrentItemPackage->Value != NULL);
    2020       if (ValueSize == 0) {
    2021         StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);
     2083      if (StrStr(Argv[LoopCounter], L" ") == NULL) {
     2084        CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
     2085        CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);
     2086        ASSERT(CurrentItemPackage->Value != NULL);
     2087        if (ValueSize == 0) {
     2088          StrnCpy(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1);
     2089        } else {
     2090          StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
     2091          StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
     2092        }
     2093        ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
    20222094      } else {
    2023         StrCat(CurrentItemPackage->Value, L" ");
    2024         StrCat(CurrentItemPackage->Value, Argv[LoopCounter]);
    2025       }
    2026       ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
     2095        //
     2096        // the parameter has spaces.  must be quoted.
     2097        //
     2098        CurrentValueSize =  ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16) + sizeof(CHAR16) + sizeof(CHAR16);
     2099        CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);
     2100        ASSERT(CurrentItemPackage->Value != NULL);
     2101        if (ValueSize == 0) {
     2102          StrnCpy(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1);
     2103          StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
     2104          StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
     2105        } else {
     2106          StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
     2107          StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
     2108          StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
     2109          StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
     2110       }
     2111        ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
     2112      }
    20272113      GetItemValue--;
    20282114      if (GetItemValue == 0) {
     
    20492135      CurrentItemPackage->Name  = NULL;
    20502136      CurrentItemPackage->Type  = TypePosition;
    2051       CurrentItemPackage->Value = AllocateZeroPool(StrSize(TempPointer));
     2137      CurrentItemPackage->Value = AllocateCopyPool(StrSize(TempPointer), TempPointer);
    20522138      if (CurrentItemPackage->Value == NULL) {
    20532139        ShellCommandLineFreeVarList(*CheckPackage);
     
    20552141        return (EFI_OUT_OF_RESOURCES);
    20562142      }
    2057       StrCpy(CurrentItemPackage->Value, TempPointer);
    20582143      CurrentItemPackage->OriginalPosition = Count++;
    20592144      InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
     
    20632148      //
    20642149      if (ProblemParam != NULL) {
    2065         *ProblemParam = AllocateZeroPool(StrSize(Argv[LoopCounter]));
    2066         if (*ProblemParam != NULL) {
    2067           StrCpy(*ProblemParam, Argv[LoopCounter]);
    2068         }
     2150        *ProblemParam = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]);
    20692151      }
    20702152      ShellCommandLineFreeVarList(*CheckPackage);
     
    24252507
    24262508/**
    2427   Determins if a parameter is duplicated.
     2509  Determines if a parameter is duplicated.
    24282510
    24292511  If Param is not NULL then it will point to a callee allocated string buffer
     
    25332615    return (EFI_OUT_OF_RESOURCES);
    25342616  }
    2535   NewString = SetMem16(NewString, NewSize, CHAR_NULL);
     2617  NewString = ZeroMem(NewString, NewSize);
    25362618  while (*SourceString != CHAR_NULL) {
    25372619    //
     
    25482630        return (EFI_BUFFER_TOO_SMALL);
    25492631      }
    2550       StrCat(NewString, Replace);
     2632      StrnCat(NewString, Replace, NewSize/sizeof(CHAR16) - 1 - StrLen(NewString));
    25512633    } else {
    25522634      Size = StrSize(NewString);
     
    25882670  }
    25892671  if (mEfiShellInterface          != NULL) {
     2672    if (mEfiShellInterface->RedirArgc == 0) {
    25902673    //
    25912674    // Divide in half for old shell.  Must be string length not size.
    2592     //
    2593     Size /= 2;
     2675      //
     2676      Size /=2;  // Divide in half only when no redirection.
     2677    }
    25942678    return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut,          &Size, (VOID*)String));
    25952679  }
     
    27022786    if (ResumeLocation != NULL) {
    27032787      if (*(ResumeLocation-1) == L'^') {
     2788        //
     2789        // Move cursor back 1 position to overwrite the ^
     2790        //
     2791        gST->ConOut->SetCursorPosition(gST->ConOut, gST->ConOut->Mode->CursorColumn - 1, gST->ConOut->Mode->CursorRow);
     2792
    27042793        //
    27052794        // Print a simple '%' symbol
     
    30013090
    30023091/**
     3092  Function return the number converted from a hex representation of a number.
     3093
     3094  Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid
     3095  result.  Use ShellConvertStringToUint64 instead.
     3096
     3097  @param[in] String   String representation of a number.
     3098
     3099  @return             The unsigned integer result of the conversion.
     3100  @retval (UINTN)(-1) An error occured.
     3101**/
     3102UINTN
     3103EFIAPI
     3104ShellHexStrToUintn(
     3105  IN CONST CHAR16 *String
     3106  )
     3107{
     3108  UINT64        RetVal;
     3109
     3110  if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) {
     3111    return ((UINTN)RetVal);
     3112  }
     3113 
     3114  return ((UINTN)(-1));
     3115}
     3116
     3117/**
    30033118  Function to determine whether a string is decimal or hex representation of a number
    3004   and return the number converted from the string.
     3119  and return the number converted from the string.  Spaces are always skipped.
    30053120
    30063121  @param[in] String   String representation of a number
     
    31173232  if (CurrentSize != NULL) {
    31183233    NewSize = *CurrentSize;
    3119     while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {
    3120       NewSize += 2 * Count * sizeof(CHAR16);
    3121     }
    3122     *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);
    3123     *CurrentSize = NewSize;
     3234    if (NewSize < DestinationStartSize + (Count * sizeof(CHAR16))) {
     3235      while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {
     3236        NewSize += 2 * Count * sizeof(CHAR16);
     3237      }
     3238      *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);
     3239      *CurrentSize = NewSize;
     3240    }
    31243241  } else {
    31253242    *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));
     
    31953312      gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
    31963313      Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
    3197       ASSERT_EFI_ERROR(Status);
     3314      if (EFI_ERROR(Status)) {
     3315        break;
     3316      }
    31983317      ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
    31993318      if (Key.UnicodeChar == L'Q' || Key.UnicodeChar ==L'q') {
     
    32123331      *Resp = ShellPromptResponseMax;
    32133332      while (*Resp == ShellPromptResponseMax) {
     3333        if (ShellGetExecutionBreakFlag()) {
     3334          Status = EFI_ABORTED;
     3335          break;
     3336        }
    32143337        gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
    32153338        Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
    3216         ASSERT_EFI_ERROR(Status);
     3339        if (EFI_ERROR(Status)) {
     3340          break;
     3341        }
    32173342        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
    32183343        switch (Key.UnicodeChar) {
     
    32403365      *Resp = ShellPromptResponseMax;
    32413366      while (*Resp == ShellPromptResponseMax) {
     3367        if (ShellGetExecutionBreakFlag()) {
     3368          Status = EFI_ABORTED;
     3369          break;
     3370        }
    32423371        gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
    32433372        Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
    3244         ASSERT_EFI_ERROR(Status);
     3373        if (EFI_ERROR(Status)) {
     3374          break;
     3375        }
    32453376        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
    32463377        switch (Key.UnicodeChar) {
     
    32743405      *Resp = ShellPromptResponseMax;
    32753406      while (*Resp == ShellPromptResponseMax) {
     3407        if (ShellGetExecutionBreakFlag()) {
     3408          Status = EFI_ABORTED;
     3409          break;
     3410        }
    32763411        gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
    32773412        if (Type == ShellPromptResponseTypeEnterContinue) {
    32783413          Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
    3279           ASSERT_EFI_ERROR(Status);
     3414          if (EFI_ERROR(Status)) {
     3415            break;
     3416          }
    32803417          ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
    32813418          if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
     
    33013438      *Resp = ShellPromptResponseMax;
    33023439      while (*Resp == ShellPromptResponseMax) {
     3440        if (ShellGetExecutionBreakFlag()) {
     3441          Status = EFI_ABORTED;
     3442          break;
     3443        }
    33033444        gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
    33043445        Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
    3305         ASSERT_EFI_ERROR(Status);
     3446        if (EFI_ERROR(Status)) {
     3447          break;
     3448        }
    33063449        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
    33073450        switch (Key.UnicodeChar) {
     
    33223465      }
    33233466      while(1) {
     3467        if (ShellGetExecutionBreakFlag()) {
     3468          Status = EFI_ABORTED;
     3469          break;
     3470        }
    33243471        gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
    33253472        Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
    3326         ASSERT_EFI_ERROR(Status);
     3473        if (EFI_ERROR(Status)) {
     3474          break;
     3475        }
    33273476        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
    33283477        if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
     
    33353484    //
    33363485    // This is the location to add new prompt types.
     3486    // If your new type loops remember to add ExecutionBreak support.
    33373487    //
    33383488    default:
     
    36463796
    36473797    //
    3648     // Skip spaces if requested
    3649     //
    3650     while (StopAtSpace && *String == L' ') {
    3651       String++;
     3798    // stop at spaces if requested
     3799    //
     3800    if (StopAtSpace && *String == L' ') {
     3801      break;
    36523802    }
    36533803  }
     
    40014151  return (Status);
    40024152}
     4153
     4154/**
     4155  Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function.
     4156
     4157  @param[in] CommandToGetHelpOn  Pointer to a string containing the command name of help file to be printed.
     4158  @param[in] SectionToGetHelpOn  Pointer to the section specifier(s).
     4159  @param[in] PrintCommandText    If TRUE, prints the command followed by the help content, otherwise prints
     4160                                 the help content only.
     4161  @retval EFI_DEVICE_ERROR       The help data format was incorrect.
     4162  @retval EFI_NOT_FOUND          The help data could not be found.
     4163  @retval EFI_SUCCESS            The operation was successful.
     4164**/
     4165EFI_STATUS
     4166EFIAPI
     4167ShellPrintHelp (
     4168  IN CONST CHAR16     *CommandToGetHelpOn,
     4169  IN CONST CHAR16     *SectionToGetHelpOn,
     4170  IN BOOLEAN          PrintCommandText
     4171  )
     4172{
     4173        EFI_STATUS          Status;
     4174        CHAR16              *OutText;
     4175         
     4176        OutText = NULL;
     4177       
     4178  //
     4179  // Get the string to print based
     4180  //
     4181        Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);
     4182 
     4183  //
     4184  // make sure we got a valid string
     4185  //
     4186  if (EFI_ERROR(Status)){
     4187    return Status;
     4188        }
     4189  if (OutText == NULL || StrLen(OutText) == 0) {
     4190    return EFI_NOT_FOUND; 
     4191        }
     4192 
     4193  //
     4194  // Chop off trailing stuff we dont need
     4195  //
     4196  while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {
     4197    OutText[StrLen(OutText)-1] = CHAR_NULL;
     4198  }
     4199 
     4200  //
     4201  // Print this out to the console
     4202  //
     4203  if (PrintCommandText) {
     4204    ShellPrintEx(-1, -1, L"%H%-14s%N- %s\r\n", CommandToGetHelpOn, OutText);
     4205  } else {
     4206    ShellPrintEx(-1, -1, L"%N%s\r\n", OutText);
     4207  }
     4208 
     4209  SHELL_FREE_NON_NULL(OutText);
     4210
     4211        return EFI_SUCCESS;
     4212}
     4213
     4214/**
     4215  Function to delete a file by name
     4216 
     4217  @param[in]       FileName       Pointer to file name to delete.
     4218 
     4219  @retval EFI_SUCCESS             the file was deleted sucessfully
     4220  @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
     4221                                  deleted
     4222  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.
     4223  @retval EFI_NOT_FOUND           The specified file could not be found on the
     4224                                  device or the file system could not be found
     4225                                  on the device.
     4226  @retval EFI_NO_MEDIA            The device has no medium.
     4227  @retval EFI_MEDIA_CHANGED       The device has a different medium in it or the
     4228                                  medium is no longer supported.
     4229  @retval EFI_DEVICE_ERROR        The device reported an error.
     4230  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.
     4231  @retval EFI_WRITE_PROTECTED     The file or medium is write protected.
     4232  @retval EFI_ACCESS_DENIED       The file was opened read only.
     4233  @retval EFI_OUT_OF_RESOURCES    Not enough resources were available to open the
     4234                                  file.
     4235  @retval other                   The file failed to open
     4236**/
     4237EFI_STATUS
     4238EFIAPI
     4239ShellDeleteFileByName(
     4240  IN CONST CHAR16               *FileName
     4241  )
     4242{
     4243  EFI_STATUS                Status;
     4244  SHELL_FILE_HANDLE         FileHandle;
     4245 
     4246  Status = ShellFileExists(FileName);
     4247 
     4248  if (Status == EFI_SUCCESS){
     4249    Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);
     4250    if (Status == EFI_SUCCESS){
     4251      Status = ShellDeleteFile(&FileHandle);
     4252    }
     4253  }
     4254
     4255  return(Status);
     4256 
     4257}
     4258
     4259/**
     4260  Cleans off all the quotes in the string.
     4261
     4262  @param[in]     OriginalString   pointer to the string to be cleaned.
     4263  @param[out]   CleanString      The new string with all quotes removed.
     4264                                                  Memory allocated in the function and free
     4265                                                  by caller.
     4266
     4267  @retval EFI_SUCCESS   The operation was successful.
     4268**/
     4269EFI_STATUS
     4270EFIAPI
     4271InternalShellStripQuotes (
     4272  IN  CONST CHAR16     *OriginalString,
     4273  OUT CHAR16           **CleanString
     4274  )
     4275{
     4276  CHAR16            *Walker;
     4277 
     4278  if (OriginalString == NULL || CleanString == NULL) {
     4279    return EFI_INVALID_PARAMETER;
     4280  }
     4281
     4282  *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);
     4283  if (*CleanString == NULL) {
     4284    return EFI_OUT_OF_RESOURCES;
     4285  }
     4286
     4287  for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
     4288    if (*Walker == L'\"') {
     4289      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
     4290    }
     4291  }
     4292
     4293  return EFI_SUCCESS;
     4294}
     4295
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLib/UefiShellLib.h

    r48674 r58459  
    7373  );
    7474
     75/**
     76  Cleans off all the quotes in the string.
     77
     78  @param[in]     OriginalString   pointer to the string to be cleaned.
     79  @param[out]   CleanString      The new string with all quotes removed.
     80                                                  Memory allocated in the function and free
     81                                                  by caller.
     82
     83  @retval EFI_SUCCESS   The operation was successful.
     84**/
     85EFI_STATUS
     86EFIAPI
     87InternalShellStripQuotes (
     88  IN  CONST CHAR16     *OriginalString,
     89  OUT CHAR16           **CleanString
     90  );
     91
     92
    7593#endif
    7694
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellLib/UefiShellLib.inf

    r48674 r58459  
    2020  MODULE_TYPE                    = UEFI_DRIVER
    2121  VERSION_STRING                 = 1.0
    22   LIBRARY_CLASS                  = ShellLib|UEFI_APPLICATION UEFI_DRIVER
     22  LIBRARY_CLASS                  = ShellLib|UEFI_APPLICATION UEFI_DRIVER DXE_RUNTIME_DRIVER DXE_DRIVER
    2323  CONSTRUCTOR                    = ShellLibConstructor
    2424  DESTRUCTOR                     = ShellLibDestructor
     
    5151
    5252[Protocols]
    53   gEfiSimpleFileSystemProtocolGuid              # ALWAYS_CONSUMED
     53  gEfiSimpleFileSystemProtocolGuid              ## CONSUMES
    5454
    5555  # shell 2.0
    56   gEfiShellProtocolGuid                         # SOMETIMES_CONSUMED
    57   gEfiShellParametersProtocolGuid               # SOMETIMES_CONSUMED
     56  gEfiShellProtocolGuid                         ## SOMETIMES_CONSUMES
     57  gEfiShellParametersProtocolGuid               ## SOMETIMES_CONSUMES
    5858
    5959  # 'old' shell
    60   gEfiShellEnvironment2Guid                     # SOMETIMES_CONSUMED
    61   gEfiShellInterfaceGuid                        # SOMETIMES_CONSUMED
     60  gEfiShellEnvironment2Guid                     ## SOMETIMES_CONSUMES
     61  gEfiShellInterfaceGuid                        ## SOMETIMES_CONSUMES
    6262
    6363[Guids]
    64   gEfiFileInfoGuid                              # ALWAYS_CONSUMED
    65   gEfiShellEnvironment2ExtGuid                  # ALWAYS_CONSUMED
     64  gEfiFileInfoGuid                              ## CONSUMES ## GUID
     65  gEfiShellEnvironment2ExtGuid                  ## CONSUMES ## GUID
    6666
    6767[Pcd.common]
    68   gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize     # ALWAYS_CONSUMED
    69   gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize       # ALWAYS_CONSUMED
     68  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize     ## CONSUMES
     69  gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize       ## CONSUMES
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ifconfig.c

    r48674 r58459  
    22  The implementation for ifcommand shell command.
    33
    4   Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
     5  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
    56
    67  This program and the accompanying materials
     
    271272  OriString = String;
    272273
    273   StrCpy (String, L"&OFFSET=");
     274  StrnCpy (String, L"&OFFSET=", 9);
    274275  String += StrLen (L"&OFFSET=");
    275276  String += UnicodeSPrint (String, 20, L"%x", Offset);
    276277
    277   StrCpy (String,L"&WIDTH=");
     278  StrnCpy (String,L"&WIDTH=", 8);
    278279  String += StrLen (L"&WIDTH=");
    279280  String += UnicodeSPrint (String, 20, L"%x", Width);
    280281
    281282  if (Block != NULL) {
    282     StrCpy (String,L"&VALUE=");
     283    StrnCpy (String,L"&VALUE=", 8);
    283284    String += StrLen (L"&VALUE=");
    284285    while ((Width--) != 0) {
     
    369370
    370371  String = ConfigHdr;
    371   StrCpy (String, L"GUID=");
     372  StrnCpy (String, L"GUID=", 6);
    372373  String += StrLen (L"GUID=");
    373374
     
    382383  // Append L"&NAME="
    383384  //
    384   StrCpy (String, L"&NAME=");
     385  StrnCpy (String, L"&NAME=", 7);
    385386  String += StrLen (L"&NAME=");
    386387  for (Index = 0; Index < NameLength ; Index++) {
     
    391392  // Append L"&PATH="
    392393  //
    393   StrCpy (String, L"&PATH=");
     394  StrnCpy (String, L"&PATH=", 7);
    394395  String += StrLen (L"&PATH=");
    395396  for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {
     
    618619    }
    619620    if (ConfigHdr != NULL) {
    620       StrCpy (ConfigResp, ConfigHdr);
     621      StrnCpy (ConfigResp, ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
    621622    }
    622623 
     
    791792  }
    792793  if (ConfigHdr != NULL) {
    793     StrCpy (ConfigResp, ConfigHdr);
     794    StrnCpy (ConfigResp, ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
    794795  }
    795796
     
    10431044
    10441045/**
    1045   Create an IP child, use it to start the auto configuration, then destory it.
     1046  Create an IP child, use it to start the auto configuration, then destroy it.
    10461047
    10471048  @param[in] NicInfo    The pointer to the NIC_INFO of the Nic to be configured.
     
    11161117    Status  = gBS->CreateEvent (
    11171118                    EVT_NOTIFY_SIGNAL | EVT_TIMER,
    1118                     TPL_CALLBACK - 1,
     1119                    TPL_CALLBACK,
    11191120                    TimeoutToGetMap,
    11201121                    NULL,
     
    12501251  if (StringNoCaseCompare(&Temp, &DhcpTemp) == 0) {
    12511252    //
    1252     // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP perment
     1253    // Validate the parameter for DHCP, two valid forms: eth0 DHCP and eth0 DHCP permanent
    12531254    //
    12541255    if ((Argc != 2) && (Argc!= 3)) {
     
    12751276
    12761277    if ((OldConfig != NULL) && (OldConfig->Source == IP4_CONFIG_SOURCE_DHCP) &&
    1277         (OldConfig->Perment == Permanent)) {
     1278        (OldConfig->Permanent == Permanent)) {
    12781279
    12791280      ShellPrintHiiEx(-1, -1, NULL,STRING_TOKEN (STR_IFCONFIG_INTERFACE_CONFIGURED), gShellNetwork1HiiHandle, Info->Name);
     
    12861287    //
    12871288    // validate the parameter, two forms: eth0 static IP NETMASK GATEWAY and
    1288     // eth0 static IP NETMASK GATEWAY perment
     1289    // eth0 static IP NETMASK GATEWAY permanent
    12891290    //
    12901291    if ((Argc != 5) && (Argc != 6)) {
     
    13891390
    13901391  CopyMem (&Config->NicAddr, &Info->NicAddress, sizeof (NIC_ADDR));
    1391   Config->Perment = Permanent;
     1392  Config->Permanent = Permanent;
    13921393
    13931394  //
     
    14751476
    14761477    ShellPrintHiiEx(-1, -1, NULL,
    1477       STRING_TOKEN (STR_IFCONFIG_PERMENT_STATUS),
     1478      STRING_TOKEN (STR_IFCONFIG_PERMANENT_STATUS),
    14781479      gShellNetwork1HiiHandle,
    1479       (NicInfo->ConfigInfo->Perment? L"TRUE":L"FALSE")
     1480      (NicInfo->ConfigInfo->Permanent? L"TRUE":L"FALSE")
    14801481      );
    14811482
     
    17171718    //
    17181719    // The correct command line arguments for setting address are:
    1719     // IfConfig -s eth0 DHCP [perment]
    1720     // IfConfig -s eth0 static ip netmask gateway [perment]
     1720    // IfConfig -s eth0 DHCP [permanent]
     1721    // IfConfig -s eth0 static ip netmask gateway [permanent]
    17211722    //
    17221723    if (Item == NULL || (CountSubItems(Item) < 2) || (CountSubItems(Item) > 6) || (CountSubItems(Item) == 4)) {
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellNetwork1CommandsLib/Ping.c

    r48674 r58459  
    22  The implementation for Ping shell command.
    33
    4   Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
    55
    66  This program and the accompanying materials
     
    11911191
    11921192/**
    1193   Destory the IP instance.
     1193  Destroy the IP instance.
    11941194
    11951195  @param[in]    Private    The pointer of PING_PRIVATE_DATA.
     
    11981198VOID
    11991199EFIAPI
    1200 Ping6DestoryIp6Instance (
     1200Ping6DestroyIp6Instance (
    12011201  IN PING_PRIVATE_DATA    *Private
    12021202  )
     
    14151415
    14161416    if (Private->IpChildHandle != NULL) {
    1417       Ping6DestoryIp6Instance (Private);
     1417      Ping6DestroyIp6Instance (Private);
    14181418    }
    14191419
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf

    r48674 r58459  
    22# Provides shell network1 functions
    33#
    4 # Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved. <BR>
     4# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>
    55#
    66#  This program and the accompanying materials
     
    5252
    5353[Pcd]
    54   gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask # ALWAYS_CONSUMED
     54  gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask ## CONSUMES
    5555
    5656[Protocols]
    57   gEfiCpuArchProtocolGuid                       # ALWAYS_CONSUMED
    58   gEfiIp6ProtocolGuid                           # SOMETIMES_CONSUMED
    59   gEfiIp6ServiceBindingProtocolGuid             # SOMETIMES_CONSUMED
    60   gEfiIp6ConfigProtocolGuid                     # SOMETIMES_CONSUMED
     57  gEfiCpuArchProtocolGuid                       ## CONSUMES
     58  gEfiIp6ProtocolGuid                           ## SOMETIMES_CONSUMES
     59  gEfiIp6ServiceBindingProtocolGuid             ## SOMETIMES_CONSUMES
     60  gEfiIp6ConfigProtocolGuid                     ## SOMETIMES_CONSUMES
    6161
    62   gEfiIp6ProtocolGuid                           # SOMETIMES_CONSUMED
    63   gEfiIp6ServiceBindingProtocolGuid             # SOMETIMES_CONSUMED
    64   gEfiIp6ConfigProtocolGuid                     # SOMETIMES_CONSUMED
     62  gEfiIp6ProtocolGuid                           ## SOMETIMES_CONSUMES
     63  gEfiIp6ServiceBindingProtocolGuid             ## SOMETIMES_CONSUMES
     64  gEfiIp6ConfigProtocolGuid                     ## SOMETIMES_CONSUMES
    6565 
    6666[Guids]
    67   gShellNetwork1HiiGuid
     67  gShellNetwork1HiiGuid                         ## SOMETIMES_CONSUMES ## HII
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiSortLib/UefiSortLib.c

    r48674 r58459  
    1818#include <Protocol/UnicodeCollation.h>
    1919#include <Protocol/DevicePath.h>
    20 #include <Protocol/DevicePathToText.h>
    2120
    2221#include <Library/UefiBootServicesTableLib.h>
     
    2625#include <Library/MemoryAllocationLib.h>
    2726#include <Library/SortLib.h>
    28 
    29 STATIC EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathToText = NULL;
     27#include <Library/DevicePathLib.h>
     28
    3029STATIC EFI_UNICODE_COLLATION_PROTOCOL   *mUnicodeCollation = NULL;
    3130
     
    225224  }
    226225
    227   if (mDevicePathToText == NULL) {
    228     Status = gBS->LocateProtocol(
    229       &gEfiDevicePathToTextProtocolGuid,
    230       NULL,
    231       (VOID**)&mDevicePathToText);
    232 
    233     ASSERT_EFI_ERROR(Status);
    234   }
    235 
    236226  if (mUnicodeCollation == NULL) {
    237227    Status = gBS->LocateProtocol(
     
    243233  }
    244234
    245   TextPath1 = mDevicePathToText->ConvertDevicePathToText(
     235  TextPath1 = ConvertDevicePathToText(
    246236    DevicePath1,
    247237    FALSE,
    248238    FALSE);
    249239
    250   TextPath2 = mDevicePathToText->ConvertDevicePathToText(
     240  TextPath2 = ConvertDevicePathToText(
    251241    DevicePath2,
    252242    FALSE,
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/Library/UefiSortLib/UefiSortLib.inf

    r48674 r58459  
    22#   Library used for sorting routines.
    33#
    4 #  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved. <BR>
     4#  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved. <BR>
    55#
    66#  This program and the accompanying materials
     
    2020  MODULE_TYPE                    = UEFI_DRIVER
    2121  VERSION_STRING                 = 1.0
    22   LIBRARY_CLASS                  = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER
     22  LIBRARY_CLASS                  = SortLib|UEFI_APPLICATION UEFI_DRIVER UEFI_DRIVER DXE_RUNTIME_DRIVER DXE_DRIVER
    2323
    2424#
     
    3939  DebugLib
    4040  UefiBootServicesTableLib
     41  DevicePathLib
    4142
    4243[Protocols]
    43   gEfiUnicodeCollation2ProtocolGuid                       # ALWAYS_CONSUMED
    44   gEfiDevicePathProtocolGuid                              # ALWAYS_CONSUMED
    45   gEfiDevicePathToTextProtocolGuid                        # ALWAYS_CONSUMED
     44  gEfiUnicodeCollation2ProtocolGuid                       ## CONSUMES
     45  gEfiDevicePathProtocolGuid                              ## CONSUMES
    4646
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/ShellPkg.dec

    r48674 r58459  
    11## @file ShellPkg.dec
    2 #
    32# This Package provides all definitions for EFI and UEFI Shell
    43#
    5 # Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
     4# (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
     5# Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
    66#
    77# This program and the accompanying materials are licensed and made available under
     
    4646  PathLib|Include/Library/PathLib.h
    4747
     48  ## @libraryclass   provides BCFG command
     49  BcfgCommandLib|Include/Library/BcfgCommandLib.h
     50
    4851[Guids]
    4952  gEfiShellEnvironment2ExtGuid    = {0xd2c18636, 0x40e5, 0x4eb5, {0xa3, 0x1b, 0x36, 0x69, 0x5f, 0xd4, 0x2c, 0x87}}
    50   gEfiShellPkgTokenSpaceGuid        = {0x171e9188, 0x31d3, 0x40f5, {0xb1, 0x0c, 0x53, 0x9b, 0x2d, 0xb9, 0x40, 0xcd}}
     53  gEfiShellPkgTokenSpaceGuid      = {0x171e9188, 0x31d3, 0x40f5, {0xb1, 0x0c, 0x53, 0x9b, 0x2d, 0xb9, 0x40, 0xcd}}
    5154  gShellVariableGuid              = {0x158def5a, 0xf656, 0x419c, {0xb0, 0x27, 0x7a, 0x31, 0x92, 0xc0, 0x79, 0xd2}}
    5255  gShellMapGuid                   = {0x51271e13, 0x7de3, 0x43af, {0x8b, 0xc2, 0x71, 0xad, 0x3b, 0x82, 0x43, 0x25}}
     
    6063  gShellLevel3HiiGuid             = {0x4344558d, 0x4ef9, 0x4725, {0xb1, 0xe4, 0x33, 0x76, 0xe8, 0xd6, 0x97, 0x4f}}
    6164  gShellNetwork1HiiGuid           = {0xf3d301bb, 0xf4a5, 0x45a8, {0xb0, 0xb7, 0xfa, 0x99, 0x9c, 0x62, 0x37, 0xae}}
     65  gShellBcfgHiiGuid               = {0x5f5f605d, 0x1583, 0x4a2d, {0xa6, 0xb2, 0xeb, 0x12, 0xda, 0xb4, 0xa2, 0xb6}}
    6266
    6367[Protocols]
    64   gEfiShellProtocolGuid           = {0x6302d008, 0x7f9b, 0x4f30, {0x87, 0xac, 0x60, 0xc9, 0xfe, 0xf5, 0xda, 0x4e}}
    65   gEfiShellParametersProtocolGuid = {0x752f3136, 0x4e16, 0x4fdc, {0xa2, 0x2a, 0xe5, 0xf4, 0x68, 0x12, 0xf4, 0xca}}
    66   gEfiShellEnvironment2Guid       = {0x47c7b221, 0xc42a, 0x11d2, {0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
    67   gEfiShellInterfaceGuid          = {0x47c7b223, 0xc42a, 0x11d2, {0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
     68  gEfiShellProtocolGuid               = {0x6302d008, 0x7f9b, 0x4f30, {0x87, 0xac, 0x60, 0xc9, 0xfe, 0xf5, 0xda, 0x4e}}
     69  gEfiShellParametersProtocolGuid     = {0x752f3136, 0x4e16, 0x4fdc, {0xa2, 0x2a, 0xe5, 0xf4, 0x68, 0x12, 0xf4, 0xca}}
     70  gEfiShellEnvironment2Guid           = {0x47c7b221, 0xc42a, 0x11d2, {0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
     71  gEfiShellInterfaceGuid              = {0x47c7b223, 0xc42a, 0x11d2, {0x8e, 0x57, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b}}
     72  gEfiShellDynamicCommandProtocolGuid = {0x3c7200e9, 0x005f, 0x4ea4, {0x87, 0xde, 0xa3, 0xdf, 0xac, 0x8a, 0x27, 0xc3}}
    6873
    6974[PcdsFeatureFlag]
     
    103108  gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength|50|UINT8|0x00000009
    104109
    105   ## This determins how many bytes are read out of files at a time for file operations (type, copy, etc...)
    106   gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|1000|UINT16|0x0000000A
     110  ## This determines how many bytes are read out of files at a time for file operations (type, copy, etc...)
     111  gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|1000|UINT32|0x0000000A
    107112
    108113[PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
     
    111116  gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols|FALSE|BOOLEAN|0x00000002
    112117
    113   ## this flag determins whether Page Break (-b) defaults to on or off in the shell
     118  ## this flag determines whether Page Break (-b) defaults to on or off in the shell
    114119  gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault|FALSE|BOOLEAN|0x00000006
    115120
    116   ## this flag determins whether insert mode for typing is default (FALSE means typeover)
     121  ## this flag determines whether insert mode for typing is default (FALSE means typeover)
    117122  gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault|TRUE|BOOLEAN|0x00000007
    118123
    119   ## this flag determins the default number of screens kept for history log.
     124  ## this flag determines the default number of screens kept for history log.
    120125  #  the spec defines 3 as the minimum
    121126  gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount|3|UINT8|0x00000008
     127
     128  ## Unicode string of the shell supplier
     129  gEfiShellPkgTokenSpaceGuid.PcdShellSupplier|L"EDK II"|VOID*|0x00000010
  • trunk/src/VBox/Devices/EFI/Firmware/ShellPkg/ShellPkg.dsc

    r48674 r58459  
    22# Shell Package
    33#
    4 # Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
     4# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
    55#
    66#    This program and the accompanying materials
     
    2020  DSC_SPECIFICATION              = 0x00010006
    2121  OUTPUT_DIRECTORY               = Build/Shell
    22   SUPPORTED_ARCHITECTURES        = IA32|IPF|X64|EBC|ARM
     22  SUPPORTED_ARCHITECTURES        = IA32|IPF|X64|EBC|ARM|AARCH64
    2323  BUILD_TARGETS                  = DEBUG|RELEASE
    2424  SKUID_IDENTIFIER               = DEFAULT
     
    2727  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
    2828  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
    29   DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
     29  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
    3030  DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
    3131  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf 
     
    5050  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
    5151  PathLib|ShellPkg/Library/BasePathLib/BasePathLib.inf
     52  BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
    5253
    5354[LibraryClasses.ARM]
     
    5960  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
    6061
     62  # Add support for GCC stack protector
     63  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
     64
     65[LibraryClasses.AARCH64]
     66  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
     67
    6168[PcdsFixedAtBuild]
    6269  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF
     
    6572!ifdef $(NO_SHELL_PROFILES)
    6673  gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask|0x00
    67 !endif
     74!endif #$(NO_SHELL_PROFILES)
    6875
    6976[Components]
     
    7380  ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
    7481  ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
     82
     83  ShellPkg/Library/UefiDpLib/UefiDpLib.inf {
     84    <LibraryClasses>
     85      TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
     86      PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
     87      DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
     88  }
    7589
    7690  ShellPkg/Application/Shell/Shell.inf {
     
    8498      NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
    8599      NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
    86 !endif
     100!ifdef $(INCLUDE_DP)
     101      NULL|ShellPkg/Library/UefiDpLib/UefiDpLib.inf
     102!endif #$(INCLUDE_DP)
     103!endif #$(NO_SHELL_PROFILES)
    87104  }
    88105
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette