/** Fill in SPD_ENTRY_INDEXER through ParamPackage list. @param[in, out] Indexer The pointer to the SPD_ENTRY_INDEXER structure. @param[in] ParamPackage The pointer to the ParamPackage list. @retval EFI_SUCCESS Filled in SPD_ENTRY_INDEXER successfully. **/ EFI_STATUS ConstructSpdIndexer ( IN OUT SPD_ENTRY_INDEXER *Indexer, IN LIST_ENTRY *ParamPackage ) { EFI_STATUS Status; UINT64 Value64; CONST CHAR16 *ValueStr; ValueStr = NULL; if (ShellCommandLineGetFlag (ParamPackage, L"-i")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-i"); } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d"); } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e"); } else { ASSERT (FALSE); } ASSERT (ValueStr != NULL); Value64 = StrToUInteger (ValueStr, &Status); if (!EFI_ERROR (Status)) { Indexer->Index = (UINTN) Value64; Indexer->Name = NULL; } else { UnicodeStrToAsciiStr (ValueStr, (CHAR8 *) Indexer->Name); } return EFI_SUCCESS; }
/** Function for 'reconnect' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunReconnect ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { SHELL_STATUS ShellStatus; LIST_ENTRY *Package; CHAR16 *ProblemParam; EFI_STATUS Status; gInReconnect = TRUE; ShellStatus = SHELL_SUCCESS; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, "reconnect", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { ShellStatus = ShellCommandRunDisconnect(ImageHandle, SystemTable); if (ShellStatus == SHELL_SUCCESS) { if (ShellCommandLineGetFlag(Package, L"-r")) { ConnectAllConsoles(); } ShellStatus = ShellCommandRunConnect(ImageHandle, SystemTable); } } gInReconnect = FALSE; return (ShellStatus); }
/** Flush or delete entry information in the database according to datatype. @param[in] DataType The value of EFI_IPSEC_CONFIG_DATA_TYPE. @param[in] ParamPackage The pointer to the ParamPackage list. @retval EFI_SUCCESS Delete entry information successfully. @retval EFI_NOT_FOUND Can't find the specified entry. @retval Others Some mistaken case. **/ EFI_STATUS FlushOrDeletePolicyEntry ( IN EFI_IPSEC_CONFIG_DATA_TYPE DataType, IN LIST_ENTRY *ParamPackage ) { EFI_STATUS Status; DELETE_POLICY_ENTRY_CONTEXT Context; CONST CHAR16 *ValueStr; // // If user wants to remove all. // if (ShellCommandLineGetFlag (ParamPackage, L"-f")) { Status = mIpSecConfig->SetData ( mIpSecConfig, DataType, NULL, NULL, NULL ); } else { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d"); if (ValueStr == NULL) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_INDEX_NOT_SPECIFIED), mHiiHandle, mAppName, ValueStr); return EFI_NOT_FOUND; } Status = mConstructPolicyEntryIndexer[DataType] (&Context.Indexer, ParamPackage); if (!EFI_ERROR (Status)) { Context.DataType = DataType; Context.Status = EFI_NOT_FOUND; ForeachPolicyEntry (DataType, (VISIT_POLICY_ENTRY) DeletePolicyEntry, &Context); Status = Context.Status; if (Status == EFI_NOT_FOUND) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_INDEX_NOT_FOUND), mHiiHandle, mAppName, ValueStr); } else if (EFI_ERROR (Status)) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_DELETE_FAILED), mHiiHandle, mAppName); } } } return Status; }
STATIC SHELL_STATUS EFIAPI ShellCommandRunFUpdate ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { IN SHELL_FILE_HANDLE FileHandle; SPI_DEVICE *Slave = NULL; UINT64 FileSize; UINTN *FileBuffer = NULL; CHAR16 *ProblemParam; LIST_ENTRY *CheckPackage; EFI_STATUS Status; // Locate SPI protocols Status = gBS->LocateProtocol ( &gMarvellSpiFlashProtocolGuid, NULL, (VOID **)&SpiFlashProtocol ); if (EFI_ERROR(Status)) { Print (L"%s: Cannot locate SpiFlash protocol\n", CMD_NAME_STRING); return SHELL_ABORTED; } Status = gBS->LocateProtocol ( &gMarvellSpiMasterProtocolGuid, NULL, (VOID **)&SpiMasterProtocol ); if (EFI_ERROR(Status)) { Print (L"%s: Cannot locate SpiMaster protocol\n", CMD_NAME_STRING); return SHELL_ABORTED; } // Parse command line Status = ShellInitialize (); if (EFI_ERROR (Status)) { Print (L"%s: Error while initializing Shell\n", CMD_NAME_STRING); ASSERT_EFI_ERROR (Status); return SHELL_ABORTED; } Status = ShellCommandLineParse (ParamList, &CheckPackage, &ProblemParam, TRUE); if (EFI_ERROR (Status)) { Print (L"%s: Invalid parameter\n", CMD_NAME_STRING); return SHELL_ABORTED; } if (ShellCommandLineGetFlag (CheckPackage, L"help")) { FUpdateUsage(); return EFI_SUCCESS; } // Prepare local file to be burned into flash Status = PrepareFirmwareImage (CheckPackage, &FileHandle, &FileBuffer, &FileSize); if (EFI_ERROR(Status)) { return SHELL_ABORTED; } // Check image checksum and magic Status = CheckImageHeader (FileBuffer); if (EFI_ERROR(Status)) { goto HeaderError; } // Setup and probe SPI flash Slave = SpiMasterProtocol->SetupDevice (SpiMasterProtocol, Slave, 0, 0); if (Slave == NULL) { Print(L"%s: Cannot allocate SPI device!\n", CMD_NAME_STRING); goto HeaderError; } Status = SpiFlashProbe (Slave); if (EFI_ERROR(Status)) { Print (L"%s: Error while performing SPI flash probe\n", CMD_NAME_STRING); goto FlashProbeError; } // Update firmware image in flash at offset 0x0 Status = SpiFlashProtocol->Update (Slave, 0, FileSize, (UINT8 *)FileBuffer); // Release resources SpiMasterProtocol->FreeDevice(Slave); FreePool (FileBuffer); ShellCloseFile (&FileHandle); if (EFI_ERROR(Status)) { Print (L"%s: Error while performing flash update\n", CMD_NAME_STRING); return SHELL_ABORTED; } Print (L"%s: Update %d bytes at offset 0x0 succeeded!\n", CMD_NAME_STRING, FileSize); return EFI_SUCCESS; FlashProbeError: SpiMasterProtocol->FreeDevice(Slave); HeaderError: FreePool (FileBuffer); ShellCloseFile (&FileHandle); return SHELL_ABORTED; }
/** Function for 'time' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunTime ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; EFI_TIME TheTime; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; INT16 Tz; UINT8 Daylight; CONST CHAR16 *TempLocation; UINTN TzMinutes; // // Initialize variables // ShellStatus = SHELL_SUCCESS; ProblemParam = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // if (PcdGet8(PcdShellSupportLevel) == 2) { Status = ShellCommandLineParseEx (TimeParamList2, &Package, &ProblemParam, TRUE, TRUE); } else { ASSERT(PcdGet8(PcdShellSupportLevel) == 3); Status = ShellCommandLineParseEx (TimeParamList3, &Package, &ProblemParam, TRUE, TRUE); } if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"time", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // Status = gRT->GetTime(&TheTime, NULL); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"time", L"gRT->GetTime", Status); return (SHELL_DEVICE_ERROR); } if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"time"); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // If there are no parameters, then print the current time // if (ShellCommandLineGetRawValue(Package, 1) == NULL && !ShellCommandLineGetFlag(Package, L"-d") && !ShellCommandLineGetFlag(Package, L"-tz")) { // // ShellPrintEx the current time // if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) { TzMinutes = 0; } else { TzMinutes = (ABS(TheTime.TimeZone)) % 60; } if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TIME_FORMAT), gShellLevel2HiiHandle, TheTime.Hour, TheTime.Minute, TheTime.Second, (TheTime.TimeZone > 0?L"-":L"+"), ((ABS(TheTime.TimeZone)) / 60), TzMinutes ); } else { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TIME_FORMAT_LOCAL), gShellLevel2HiiHandle, TheTime.Hour, TheTime.Minute, TheTime.Second ); } ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle); } else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) { if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TIME_FORMAT_LOCAL), gShellLevel2HiiHandle, TheTime.Hour, TheTime.Minute, TheTime.Second ); } else { TzMinutes = (ABS(TheTime.TimeZone)) % 60; ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TIME_FORMAT), gShellLevel2HiiHandle, TheTime.Hour, TheTime.Minute, TheTime.Second, (TheTime.TimeZone > 0?L"-":L"+"), ((ABS(TheTime.TimeZone)) / 60), TzMinutes ); } switch (TheTime.Daylight) { case 0: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST0), gShellLevel2HiiHandle); break; case EFI_TIME_ADJUST_DAYLIGHT: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST1), gShellLevel2HiiHandle); break; case EFI_TIME_IN_DAYLIGHT: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST2), gShellLevel2HiiHandle); break; case EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST3), gShellLevel2HiiHandle); break; default: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"time", L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight); } } else { if (PcdGet8(PcdShellSupportLevel) == 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"time"); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // perform level 3 operation here. // if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) { if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16 *)TempLocation, L"_local") == 0) { Tz = EFI_UNSPECIFIED_TIMEZONE; } else if (TempLocation[0] == L'-') { Tz = (INT16) ShellStrToUintn (++TempLocation); // // When the argument of "time [-tz tz]" is not numeric, ShellStrToUintn() returns "-1". // Here we can detect the argument error by checking the return of ShellStrToUintn(). // if (Tz == -1) { Tz = 1441; //make it to be out of bounds value } else { Tz *= (-1); //sign convert } } else { if (TempLocation[0] == L'+') { Tz = (INT16)ShellStrToUintn (++TempLocation); } else { Tz = (INT16)ShellStrToUintn (TempLocation); } // // Detect the return of ShellStrToUintn() to make sure the argument is valid. // if (Tz == -1) { Tz = 1441; //make it to be out of bounds value } } if (!(Tz >= -1440 && Tz <= 1440) && Tz != EFI_UNSPECIFIED_TIMEZONE) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"time", TempLocation, L"-tz"); ShellStatus = SHELL_INVALID_PARAMETER; } } else { // // intentionally out of bounds value will prevent changing it... // Tz = 1441; } TempLocation = ShellCommandLineGetValue(Package, L"-d"); if (TempLocation != NULL) { Daylight = (UINT8)ShellStrToUintn(TempLocation); // // The argument of "time [-d dl]" is unsigned, if the first character is '-', // the argument is incorrect. That's because ShellStrToUintn() will skip past // any '-' sign and convert what's next, forgetting the sign is here. // if (TempLocation[0] == '-') { Daylight = 0xff; //make it invalid = will not use } if (Daylight != 0 && Daylight != 1 && Daylight != 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"time", TempLocation, L"-d"); ShellStatus = SHELL_INVALID_PARAMETER; } } else { // // invalid = will not use // Daylight = 0xFF; } if (ShellStatus == SHELL_SUCCESS) { ShellStatus = CheckAndSetTime(ShellCommandLineGetRawValue(Package, 1), Tz, Daylight); if (ShellStatus != SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"time", ShellCommandLineGetRawValue(Package, 1)); ShellStatus = SHELL_INVALID_PARAMETER; } } } } } } // // free the command line package // ShellCommandLineFreeVarList (Package); // // return the status // return (ShellStatus); }
/** Function for 'getmtc' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunGetMtc ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINT64 Mtc; ProblemParam = NULL; ShellStatus = SHELL_SUCCESS; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } else if (ShellCommandLineGetRawValue(Package, 1) != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // Get the monotonic counter count // Status = gBS->GetNextMonotonicCount(&Mtc); switch(Status) { case EFI_DEVICE_ERROR: ShellStatus = SHELL_DEVICE_ERROR; break; case EFI_SECURITY_VIOLATION: ShellStatus = SHELL_SECURITY_VIOLATION; break; default: if (EFI_ERROR(Status)) { ShellStatus = SHELL_DEVICE_ERROR; } } // // print it... // if (ShellStatus == SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GET_MTC_OUTPUT), gShellLevel3HiiHandle, Mtc); } } // // free the command line package // ShellCommandLineFreeVarList (Package); } return (ShellStatus); }
/** Fill in PAD_ENTRY_INDEXER through ParamPackage list. @param[in, out] Indexer The pointer to the PAD_ENTRY_INDEXER structure. @param[in] ParamPackage The pointer to the ParamPackage list. @retval EFI_SUCCESS Filled in PAD_ENTRY_INDEXER successfully. @retval EFI_INVALID_PARAMETER The mistaken user input in ParamPackage list. **/ EFI_STATUS ConstructPadIndexer ( IN OUT PAD_ENTRY_INDEXER *Indexer, IN LIST_ENTRY *ParamPackage ) { EFI_STATUS Status; UINT64 Value64; CONST CHAR16 *ValueStr; ValueStr = NULL; if (ShellCommandLineGetFlag (ParamPackage, L"-i")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-i"); } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d"); } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e"); } else { ASSERT (FALSE); } ASSERT (ValueStr != NULL); Value64 = StrToUInteger (ValueStr, &Status); if (!EFI_ERROR (Status)) { Indexer->Index = (UINTN) Value64; ZeroMem (&Indexer->PadId, sizeof (EFI_IPSEC_PAD_ID)); } else { if (ShellCommandLineGetFlag (ParamPackage, L"--lookup-peer-address")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"--lookup-peer-address"); ASSERT (ValueStr != NULL); Indexer->PadId.PeerIdValid = FALSE; Status = EfiInetAddrRange ((CHAR16 *) ValueStr, &Indexer->PadId.Id.IpAddress); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_INCORRECT_PARAMETER_VALUE), mHiiHandle, mAppName, L"--lookup-peer-address", ValueStr ); return EFI_INVALID_PARAMETER; } } else { ValueStr = ShellCommandLineGetValue (ParamPackage, L"--lookup-peer-id"); if (ValueStr == NULL) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_MISSING_ONE_OF_PARAMETERS), mHiiHandle, mAppName, L"--lookup-peer-address --lookup-peer-id" ); return EFI_INVALID_PARAMETER; } Indexer->PadId.PeerIdValid = TRUE; ZeroMem (Indexer->PadId.Id.PeerId, MAX_PEERID_LEN); StrnCpy ((CHAR16 *) Indexer->PadId.Id.PeerId, ValueStr, ARRAY_SIZE (Indexer->PadId.Id.PeerId) - 1); } } return EFI_SUCCESS; }
/** Function for 'mv' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunMv ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; CHAR16 *Cwd; UINTN CwdSize; SHELL_STATUS ShellStatus; UINTN ParamCount; UINTN LoopCounter; EFI_SHELL_FILE_INFO *FileList; VOID *Response; ProblemParam = NULL; ShellStatus = SHELL_SUCCESS; ParamCount = 0; FileList = NULL; Response = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mv", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } switch (ParamCount = ShellCommandLineGetCount(Package)) { case 0: case 1: // // we have insufficient parameters // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mv"); ShellStatus = SHELL_INVALID_PARAMETER; break; case 2: // // must have valid CWD for single parameter... // if (ShellGetCurrentDir(NULL) == NULL){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"mv"); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, 1)); ShellStatus = SHELL_NOT_FOUND; } else { // // ValidateAndMoveFiles will report errors to the screen itself // CwdSize = StrSize(ShellGetCurrentDir(NULL)) + sizeof(CHAR16); Cwd = AllocateZeroPool(CwdSize); ASSERT (Cwd != NULL); StrCpyS(Cwd, CwdSize/sizeof(CHAR16), ShellGetCurrentDir(NULL)); StrCatS(Cwd, CwdSize/sizeof(CHAR16), L"\\"); ShellStatus = ValidateAndMoveFiles(FileList, &Response, Cwd); FreePool(Cwd); } } break; default: ///@todo make sure this works with error half way through and continues... for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount ; LoopCounter++) { if (ShellGetExecutionBreakFlag()) { break; } Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, LoopCounter)); ShellStatus = SHELL_NOT_FOUND; } else { // // ValidateAndMoveFiles will report errors to the screen itself // Only change ShellStatus if it's sucessful // if (ShellStatus == SHELL_SUCCESS) { ShellStatus = ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount)); } else { ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount)); } } if (FileList != NULL && !IsListEmpty(&FileList->Link)) { Status = ShellCloseFileMetaArg(&FileList); if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) { ShellStatus = SHELL_ACCESS_DENIED; ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT); } } } break; } // switch on parameter count if (FileList != NULL) { ShellCloseFileMetaArg(&FileList); } // // free the command line package // ShellCommandLineFreeVarList (Package); } SHELL_FREE_NON_NULL(Response); if (ShellGetExecutionBreakFlag()) { return (SHELL_ABORTED); } return (ShellStatus); }
/** Function for 'time' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunTime ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *Message; EFI_TIME TheTime; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; INT16 Tz; UINT8 Daylight; CONST CHAR16 *TempLocation; UINTN TzMinutes; ShellStatus = SHELL_SUCCESS; ProblemParam = NULL; // // Initialize variables // Message = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // if (PcdGet8(PcdShellSupportLevel) == 2) { Status = ShellCommandLineParseEx (TimeParamList2, &Package, &ProblemParam, TRUE, TRUE); } else { ASSERT(PcdGet8(PcdShellSupportLevel) == 3); Status = ShellCommandLineParseEx (TimeParamList3, &Package, &ProblemParam, TRUE, TRUE); } if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // Status = gRT->GetTime(&TheTime, NULL); ASSERT_EFI_ERROR(Status); if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // If there are no parameters, then print the current time // if (ShellCommandLineGetRawValue(Package, 1) == NULL && !ShellCommandLineGetFlag(Package, L"-d") && !ShellCommandLineGetFlag(Package, L"-tz")) { // // ShellPrintEx the current time // if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) { TzMinutes = 0; } else { TzMinutes = (ABS(TheTime.TimeZone)) % 60; } ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TIME_FORMAT), gShellLevel2HiiHandle, TheTime.Hour, TheTime.Minute, TheTime.Second, TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"), TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60, TzMinutes ); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle); } else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) { if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) { TzMinutes = 0; } else { TzMinutes = (ABS(TheTime.TimeZone)) % 60; } ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TIME_FORMAT), gShellLevel2HiiHandle, TheTime.Hour, TheTime.Minute, TheTime.Second, TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"), TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60, TzMinutes ); switch (TheTime.Daylight) { case 0: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST0), gShellLevel2HiiHandle); break; case EFI_TIME_ADJUST_DAYLIGHT: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST1), gShellLevel2HiiHandle); break; case EFI_TIME_IN_DAYLIGHT: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST2), gShellLevel2HiiHandle); break; case EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TIME_DST3), gShellLevel2HiiHandle); break; default: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_ERROR), gShellLevel2HiiHandle, L"gRT->GetTime", L"TheTime.Daylight", TheTime.Daylight); } } else { if (PcdGet8(PcdShellSupportLevel) == 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // perform level 3 operation here. // if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) { if (TempLocation[0] == L'-') { Tz = (INT16)(0 - ShellStrToUintn(++TempLocation)); } else { Tz = (INT16)ShellStrToUintn(TempLocation); } if (!(Tz >= -1440 && Tz <= 1440) && Tz != EFI_UNSPECIFIED_TIMEZONE) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-tz"); ShellStatus = SHELL_INVALID_PARAMETER; } } else { // // intentionally out of bounds value will prevent changing it... // Tz = 1441; } TempLocation = ShellCommandLineGetValue(Package, L"-d"); if (TempLocation != NULL) { Daylight = (UINT8)ShellStrToUintn(TempLocation); if (Daylight != 0 && Daylight != 1 && Daylight != 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-d"); ShellStatus = SHELL_INVALID_PARAMETER; } } else { // // invalid = will not use // Daylight = 0xFF; } if (ShellStatus == SHELL_SUCCESS) { ShellStatus = CheckAndSetTime(ShellCommandLineGetRawValue(Package, 1), Tz, Daylight); if (ShellStatus != SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1)); ShellStatus = SHELL_INVALID_PARAMETER; } } } } } } // // free the command line package // ShellCommandLineFreeVarList (Package); // // return the status // return (ShellStatus); }
/** Function for 'loadpcirom' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunLoadPciRom ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_SHELL_FILE_INFO *FileList; UINTN SourceSize; UINT8 *File1Buffer; EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; BOOLEAN Connect; CONST CHAR16 *Param; UINTN ParamCount; EFI_SHELL_FILE_INFO *Node; // // Local variable initializations // File1Buffer = NULL; ShellStatus = SHELL_SUCCESS; FileList = NULL; // // verify number of arguments // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) < 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (ShellCommandLineGetFlag(Package, L"-nc")) { Connect = FALSE; } else { Connect = TRUE; } // // get a list with each file specified by parameters // if parameter is a directory then add all the files below it to the list // for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount) ; Param != NULL ; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount) ){ Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, Param, Status); ShellStatus = SHELL_ACCESS_DENIED; break; } } if (ShellStatus == SHELL_SUCCESS && FileList != NULL) { // // loop through the list and make sure we are not aborting... // for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link) ; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag() ; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link) ){ if (EFI_ERROR(Node->Status)){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, Node->FullName); ShellStatus = SHELL_INVALID_PARAMETER; continue; } if (FileHandleIsDirectory(Node->Handle) == EFI_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, Node->FullName); ShellStatus = SHELL_INVALID_PARAMETER; continue; } SourceSize = (UINTN) Node->Info->FileSize; File1Buffer = AllocateZeroPool (SourceSize); ASSERT(File1Buffer != NULL); Status = gEfiShellProtocol->ReadFile(Node->Handle, &SourceSize, File1Buffer); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_READ_FAIL), gShellDebug1HiiHandle, Node->FullName); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = LoadEfiDriversFromRomImage ( File1Buffer, SourceSize, Node->FullName ); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_PCI_ROM_RES), gShellDebug1HiiHandle, Node->FullName, Status); } FreePool(File1Buffer); } } else if (ShellStatus == SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle); ShellStatus = SHELL_NOT_FOUND; } if (FileList != NULL && !IsListEmpty(&FileList->Link)) { Status = ShellCloseFileMetaArg(&FileList); } FileList = NULL; if (Connect) { Status = LoadPciRomConnectAllDriversToAllControllers (); } } } return (ShellStatus); }
/** Function for 'disconnect' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunDisconnect ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Param1; CONST CHAR16 *Param2; CONST CHAR16 *Param3; EFI_HANDLE Handle1; EFI_HANDLE Handle2; EFI_HANDLE Handle3; UINT64 Intermediate1; UINT64 Intermediate2; UINT64 Intermediate3; ShellStatus = SHELL_SUCCESS; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetFlag(Package, L"-r")){ if (ShellCommandLineGetCount(Package) > 1){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) < 1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = DisconnectAll(); } } else { if (ShellCommandLineGetCount(Package) > 4){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) < 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // must have between 1 and 3 handles passed in ... // Param1 = ShellCommandLineGetRawValue(Package, 1); Param2 = ShellCommandLineGetRawValue(Package, 2); Param3 = ShellCommandLineGetRawValue(Package, 3); ShellConvertStringToUint64(Param1, &Intermediate1, TRUE, FALSE); Handle1 = Param1!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate1):NULL; ShellConvertStringToUint64(Param2, &Intermediate2, TRUE, FALSE); Handle2 = Param2!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate2):NULL; ShellConvertStringToUint64(Param3, &Intermediate3, TRUE, FALSE); Handle3 = Param3!=NULL?ConvertHandleIndexToHandle((UINTN)Intermediate3):NULL; if (Param1 != NULL && Handle1 == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param1); ShellStatus = SHELL_INVALID_PARAMETER; } else if (Param2 != NULL && Handle2 == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param2); ShellStatus = SHELL_INVALID_PARAMETER; } else if (Param3 != NULL && Handle3 == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, Param3); ShellStatus = SHELL_INVALID_PARAMETER; } else if (EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiDevicePathProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { ASSERT(Param1 != NULL); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, ShellStrToUintn(Param1), L"controller handle"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (Handle2 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle2, &gEfiDriverBindingProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { ASSERT(Param2 != NULL); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, ShellStrToUintn(Param2), L"driver handle"); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(Param1 != NULL); Status = gBS->DisconnectController(Handle1, Handle2, Handle3); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_3P_RESULT), gShellDriver1HiiHandle, L"Disconnect", (UINTN)Intermediate1, (UINTN)Intermediate2, (UINTN)Intermediate3, Status); } } } } if (ShellStatus == SHELL_SUCCESS) { if (Status == EFI_SECURITY_VIOLATION) { ShellStatus = SHELL_SECURITY_VIOLATION; } else if (Status == EFI_INVALID_PARAMETER) { ShellStatus = SHELL_INVALID_PARAMETER; } else if (EFI_ERROR(Status)) { ShellStatus = SHELL_NOT_FOUND; } } return (ShellStatus); }
/** Function for 'devices' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunDevices ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CHAR8 *Language; EFI_HANDLE *HandleList; EFI_HANDLE *HandleListWalker; CHAR16 Type; BOOLEAN Cfg; BOOLEAN Diag; UINTN Parents; UINTN Devices; UINTN Children; CHAR16 *Name; CONST CHAR16 *Lang; BOOLEAN SfoFlag; ShellStatus = SHELL_SUCCESS; Language = NULL; SfoFlag = FALSE; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); // ASSERT_EFI_ERROR(Status); Status = CommandInit(); // ASSERT_EFI_ERROR(Status); if (EFI_ERROR(Status)) { return SHELL_UNSUPPORTED; } // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"devices", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } /* else { ASSERT(FALSE); } */ } else { // // if more than 0 'value' parameters we have too many parameters // if (ShellCommandLineGetRawValue(Package, 1) != NULL){ // // error for too many parameters // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"devices"); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // get the language if necessary // Lang = ShellCommandLineGetValue(Package, L"-l"); if (Lang != NULL) { Language = AllocateZeroPool(StrSize(Lang)); AsciiSPrint(Language, StrSize(Lang), "%S", Lang); } else if (!ShellCommandLineGetFlag(Package, L"-l")){ ASSERT(Language == NULL); // Language = AllocateZeroPool(10); // AsciiSPrint(Language, 10, "en-us"); } else { ASSERT(Language == NULL); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"devices", L"-l"); ShellCommandLineFreeVarList (Package); return (SHELL_INVALID_PARAMETER); } // // Print Header // if (ShellCommandLineGetFlag (Package, L"-sfo")) { ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDriver1HiiHandle, L"devices"); SfoFlag = TRUE; } else { ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle); } // // loop through each handle // HandleList = GetHandleListByProtocol(NULL); ASSERT(HandleList != NULL); for (HandleListWalker = HandleList ; HandleListWalker != NULL && *HandleListWalker != NULL /*&& !EFI_ERROR(Status)*/ ; HandleListWalker++ ){ // // get all the info on each handle // Name = NULL; Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language); if (Name != NULL && (Parents != 0 || Devices != 0 || Children != 0)) { ShellPrintHiiEx ( -1, -1, Language, SfoFlag?STRING_TOKEN (STR_DEVICES_ITEM_LINE_SFO):STRING_TOKEN (STR_DEVICES_ITEM_LINE), gShellDriver1HiiHandle, ConvertHandleToHandleIndex (*HandleListWalker), Type, Cfg?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'), Diag?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'), Parents, Devices, Children, Name!=NULL?Name:L"<UNKNOWN>"); } if (Name != NULL) { FreePool(Name); } if (ShellGetExecutionBreakFlag ()) { ShellStatus = SHELL_ABORTED; break; } } if (HandleList != NULL) { FreePool(HandleList); } } SHELL_FREE_NON_NULL(Language); ShellCommandLineFreeVarList (Package); } return (ShellStatus); }
/** Function for 'hexedit' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunHexEdit ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; CHAR16 *Buffer; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; LIST_ENTRY *Package; CHAR16 *NewName; CONST CHAR16 *Name; UINTN Offset; UINTN Size; EDIT_FILE_TYPE WhatToDo; Buffer = NULL; ShellStatus = SHELL_SUCCESS; NewName = NULL; Buffer = NULL; Name = NULL; Offset = 0; Size = 0; WhatToDo = FileTypeNone; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); // ASSERT_EFI_ERROR(Status); Status = CommandInit(); // ASSERT_EFI_ERROR(Status); if (EFI_ERROR(Status)) { return SHELL_UNSUPPORTED; } // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"hexedit", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } /* else { ASSERT(FALSE); } */ } else { // // Check for -d // if (ShellCommandLineGetFlag(Package, L"-d")){ if (ShellCommandLineGetCount(Package) < 4) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) > 4) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } else { WhatToDo = FileTypeDiskBuffer; Name = ShellCommandLineGetRawValue(Package, 1); Offset = ShellStrToUintn(ShellCommandLineGetRawValue(Package, 2)); Size = ShellStrToUintn(ShellCommandLineGetRawValue(Package, 3)); } if (Offset == (UINTN)-1 || Size == (UINTN)-1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"hexedit", L"-d"); ShellStatus = SHELL_INVALID_PARAMETER; } } // // check for -f // if (ShellCommandLineGetFlag(Package, L"-f") && (WhatToDo == FileTypeNone)){ if (ShellCommandLineGetCount(Package) < 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) > 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } else { Name = ShellCommandLineGetRawValue(Package, 1); if (Name == NULL || !IsValidFileName(Name)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"hexedit", Name); ShellStatus = SHELL_INVALID_PARAMETER; } else { WhatToDo = FileTypeFileBuffer; } } } // // check for -m // if (ShellCommandLineGetFlag(Package, L"-m") && (WhatToDo == FileTypeNone)){ if (ShellCommandLineGetCount(Package) < 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) > 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } else { WhatToDo = FileTypeMemBuffer; Offset = ShellStrToUintn(ShellCommandLineGetRawValue(Package, 1)); Size = ShellStrToUintn(ShellCommandLineGetRawValue(Package, 2)); } } Name = ShellCommandLineGetRawValue(Package, 1); if (WhatToDo == FileTypeNone && Name != NULL) { if (ShellCommandLineGetCount(Package) > 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (!IsValidFileName(Name)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"hexedit", Name); ShellStatus = SHELL_INVALID_PARAMETER; } else { WhatToDo = FileTypeFileBuffer; } } else if (WhatToDo == FileTypeNone) { if (gEfiShellProtocol->GetCurDir(NULL) == NULL) { ShellStatus = SHELL_NOT_FOUND; ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellDebug1HiiHandle, L"hexedit"); } else { NewName = EditGetDefaultFileName(L"bin"); Name = NewName; WhatToDo = FileTypeFileBuffer; } } if (ShellStatus == SHELL_SUCCESS && WhatToDo == FileTypeNone) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (WhatToDo == FileTypeFileBuffer && ShellGetCurrentDir(NULL) == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellDebug1HiiHandle, L"hexedit"); ShellStatus = SHELL_INVALID_PARAMETER; } if (ShellStatus == SHELL_SUCCESS) { // // Do the editor // Status = HMainEditorInit (); if (EFI_ERROR (Status)) { gST->ConOut->ClearScreen (gST->ConOut); gST->ConOut->EnableCursor (gST->ConOut, TRUE); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_INIT_FAILED), gShellDebug1HiiHandle); } else { HMainEditorBackup (); switch (WhatToDo) { case FileTypeFileBuffer: Status = HBufferImageRead ( Name==NULL?L"":Name, NULL, 0, 0, 0, 0, FileTypeFileBuffer, FALSE ); break; case FileTypeDiskBuffer: Status = HBufferImageRead ( NULL, Name==NULL?L"":Name, Offset, Size, 0, 0, FileTypeDiskBuffer, FALSE ); break; case FileTypeMemBuffer: Status = HBufferImageRead ( NULL, NULL, 0, 0, (UINT32) Offset, Size, FileTypeMemBuffer, FALSE ); break; default: Status = EFI_NOT_FOUND; break; } if (!EFI_ERROR (Status)) { HMainEditorRefresh (); Status = HMainEditorKeyInput (); } if (Status != EFI_OUT_OF_RESOURCES) { // // back up the status string // Buffer = CatSPrint (NULL, L"%s\r\n", StatusBarGetString()); } } // // cleanup // HMainEditorCleanup (); if (EFI_ERROR (Status)) { if (ShellStatus == SHELL_SUCCESS) { ShellStatus = SHELL_UNSUPPORTED; } } // // print editor exit code on screen // if (Status == EFI_OUT_OF_RESOURCES) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"hexedit"); } else if (EFI_ERROR(Status)){ if (Buffer != NULL) { if (StrCmp (Buffer, L"") != 0) { // // print out the status string // ShellPrintEx(-1, -1, L"%s", Buffer); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_UNKNOWN_EDITOR), gShellDebug1HiiHandle); } } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HEXEDIT_UNKNOWN_EDITOR), gShellDebug1HiiHandle); } } } ShellCommandLineFreeVarList (Package); } SHELL_FREE_NON_NULL (Buffer); SHELL_FREE_NON_NULL (NewName); return ShellStatus; }
/** Function for 'memmap' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunMemMap ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINTN Size; EFI_MEMORY_DESCRIPTOR *Buffer; UINTN MapKey; UINTN ItemSize; UINT32 Version; UINT8 *Walker; UINT64 ReservedPages; UINT64 LoadCodePages; UINT64 LoadDataPages; UINT64 BSCodePages; UINT64 BSDataPages; UINT64 RTDataPages; UINT64 RTCodePages; UINT64 AvailPages; UINT64 TotalPages; UINT64 ReservedPagesSize; UINT64 LoadCodePagesSize; UINT64 LoadDataPagesSize; UINT64 BSCodePagesSize; UINT64 BSDataPagesSize; UINT64 RTDataPagesSize; UINT64 RTCodePagesSize; UINT64 AvailPagesSize; UINT64 TotalPagesSize; UINT64 AcpiReclaimPages; UINT64 AcpiNvsPages; UINT64 MmioSpacePages; UINT64 AcpiReclaimPagesSize; UINT64 AcpiNvsPagesSize; UINT64 MmioSpacePagesSize; UINT64 MmioPortPages; UINT64 MmioPortPagesSize; UINT64 UnusableMemoryPages; UINT64 UnusableMemoryPagesSize; UINT64 PalCodePages; UINT64 PalCodePagesSize; BOOLEAN Sfo; AcpiReclaimPages = 0; AcpiNvsPages = 0; MmioSpacePages = 0; TotalPages = 0; ReservedPages = 0; LoadCodePages = 0; LoadDataPages = 0; BSCodePages = 0; BSDataPages = 0; RTDataPages = 0; RTCodePages = 0; AvailPages = 0; MmioPortPages = 0; UnusableMemoryPages = 0; PalCodePages = 0; Size = 0; Buffer = NULL; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (SfoParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) > 1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = gBS->GetMemoryMap(&Size, Buffer, &MapKey, &ItemSize, &Version); if (Status == EFI_BUFFER_TOO_SMALL){ Size += SIZE_1KB; Buffer = AllocateZeroPool(Size); Status = gBS->GetMemoryMap(&Size, Buffer, &MapKey, &ItemSize, &Version); } if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_GET_FAILED), gShellDebug1HiiHandle, Status); ShellStatus = SHELL_ACCESS_DENIED; } else { ASSERT(Version == EFI_MEMORY_DESCRIPTOR_VERSION); Sfo = ShellCommandLineGetFlag(Package, L"-sfo"); if (!Sfo) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_HEAD), gShellDebug1HiiHandle); } else { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDebug1HiiHandle, L"memmap"); } for (Walker = (UINT8*)Buffer; Walker < (((UINT8*)Buffer)+Size) && Walker != NULL; Walker += ItemSize){ switch (((EFI_MEMORY_DESCRIPTOR*)Walker)->Type) { case EfiReservedMemoryType: 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); ReservedPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiLoaderCode: ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiLoaderCode, ((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); LoadCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiLoaderData: ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiLoaderData, ((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); LoadDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiBootServicesCode: 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); BSCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiBootServicesData: 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); BSDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiRuntimeServicesCode: 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); RTCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiRuntimeServicesData: 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); RTDataPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiConventionalMemory: ShellPrintHiiEx(-1, -1, NULL, (EFI_STRING_ID)(!Sfo?STRING_TOKEN (STR_MEMMAP_LIST_ITEM):STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiConventionalMemory, ((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); AvailPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiUnusableMemory: 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); UnusableMemoryPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiACPIReclaimMemory: 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); TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; AcpiReclaimPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiACPIMemoryNVS: 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); TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; AcpiNvsPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiMemoryMappedIO: 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); MmioSpacePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiMemoryMappedIOPortSpace: 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); MmioPortPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; case EfiPalCode: 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); TotalPages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; PalCodePages += ((EFI_MEMORY_DESCRIPTOR*)Walker)->NumberOfPages; break; default: ASSERT(FALSE); } } // // print the summary // ReservedPagesSize = MultU64x64(SIZE_4KB,ReservedPages); LoadCodePagesSize = MultU64x64(SIZE_4KB,LoadCodePages); LoadDataPagesSize = MultU64x64(SIZE_4KB,LoadDataPages); BSCodePagesSize = MultU64x64(SIZE_4KB,BSCodePages); BSDataPagesSize = MultU64x64(SIZE_4KB,BSDataPages); RTDataPagesSize = MultU64x64(SIZE_4KB,RTDataPages); RTCodePagesSize = MultU64x64(SIZE_4KB,RTCodePages); AvailPagesSize = MultU64x64(SIZE_4KB,AvailPages); TotalPagesSize = MultU64x64(SIZE_4KB,TotalPages); AcpiReclaimPagesSize = MultU64x64(SIZE_4KB,AcpiReclaimPages); AcpiNvsPagesSize = MultU64x64(SIZE_4KB,AcpiNvsPages); MmioSpacePagesSize = MultU64x64(SIZE_4KB,MmioSpacePages); MmioPortPagesSize = MultU64x64(SIZE_4KB,MmioPortPages); PalCodePagesSize = MultU64x64(SIZE_4KB,PalCodePages); UnusableMemoryPagesSize = MultU64x64(SIZE_4KB,UnusableMemoryPages); if (!Sfo) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_SUMM), gShellDebug1HiiHandle, ReservedPages, ReservedPagesSize, LoadCodePages, LoadCodePagesSize, LoadDataPages, LoadDataPagesSize, BSCodePages, BSCodePagesSize, BSDataPages, BSDataPagesSize, RTCodePages, RTCodePagesSize, RTDataPages, RTDataPagesSize, AcpiReclaimPages, AcpiReclaimPagesSize, AcpiNvsPages, AcpiNvsPagesSize, MmioSpacePages, MmioSpacePagesSize, MmioPortPages, MmioPortPagesSize, PalCodePages, PalCodePagesSize, AvailPages, AvailPagesSize, DivU64x32(MultU64x64(SIZE_4KB,TotalPages), SIZE_1MB), TotalPagesSize ); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MEMMAP_LIST_SUMM_SFO), gShellDebug1HiiHandle, TotalPagesSize, ReservedPagesSize, BSCodePagesSize, BSDataPagesSize, RTCodePagesSize, RTDataPagesSize, LoadCodePagesSize, LoadDataPagesSize, AvailPagesSize, MmioSpacePagesSize, MmioPortPagesSize, UnusableMemoryPagesSize, AcpiReclaimPagesSize, AcpiNvsPagesSize, PalCodePagesSize ); } } } ShellCommandLineFreeVarList (Package); } if (Buffer != NULL) { FreePool(Buffer); } return (ShellStatus); }
/** Function for 'setvar' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunSetVar ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; RETURN_STATUS RStatus; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *VariableName; EFI_GUID Guid; CONST CHAR16 *StringGuid; UINT32 Attributes; VOID *Buffer; UINTN Size; UINTN LoopVar; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; Buffer = NULL; Size = 0; Attributes = 0; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); // ASSERT_EFI_ERROR(Status); Status = CommandInit(); // ASSERT_EFI_ERROR(Status); if (EFI_ERROR(Status)) { return SHELL_UNSUPPORTED; } // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setvar", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } /* else { ASSERT(FALSE); } */ } else if (ShellCommandLineCheckDuplicate (Package,&ProblemParam) != EFI_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DUPLICATE), gShellDebug1HiiHandle, L"setvar", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (ShellCommandLineGetCount(Package) < 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setvar"); ShellStatus = SHELL_INVALID_PARAMETER; } else { VariableName = ShellCommandLineGetRawValue(Package, 1); if (!ShellCommandLineGetFlag(Package, L"-guid")){ CopyGuid(&Guid, &gEfiGlobalVariableGuid); } else { StringGuid = ShellCommandLineGetValue(Package, L"-guid"); RStatus = StrToGuid (StringGuid, &Guid); if (RETURN_ERROR (RStatus) || (StringGuid[GUID_STRING_LENGTH] != L'\0')) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"setvar", StringGuid); ShellStatus = SHELL_INVALID_PARAMETER; } } if (ShellCommandLineGetCount(Package) == 2) { // // Display // Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, &Size, Buffer); if (Status == EFI_BUFFER_TOO_SMALL) { Buffer = AllocateZeroPool(Size); Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, &Size, Buffer); } if (!EFI_ERROR(Status) && Buffer != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_SETVAR_PRINT), gShellDebug1HiiHandle, &Guid, VariableName, Size); for (LoopVar = 0; LoopVar < Size; LoopVar++) { ShellPrintEx(-1, -1, L"%02x ", ((UINT8*)Buffer)[LoopVar]); } ShellPrintEx(-1, -1, L"\r\n"); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_GET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); ShellStatus = SHELL_ACCESS_DENIED; } } else { // // Create, Delete or Modify. // Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, &Size, Buffer); if (Status == EFI_BUFFER_TOO_SMALL) { Buffer = AllocateZeroPool(Size); Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes, &Size, Buffer); } if (EFI_ERROR(Status) || Buffer == NULL) { // // Creating a new variable. determine attributes from command line. // Attributes = 0; if (ShellCommandLineGetFlag(Package, L"-bs")) { Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS; } if (ShellCommandLineGetFlag(Package, L"-rt")) { Attributes |= EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS; } if (ShellCommandLineGetFlag(Package, L"-nv")) { Attributes |= EFI_VARIABLE_NON_VOLATILE; } } SHELL_FREE_NON_NULL(Buffer); Size = 0; Status = GetVariableDataFromParameter(Package, (UINT8 **)&Buffer, &Size); if (!EFI_ERROR(Status)) { Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, Size, Buffer); } if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, L"setvar", &Guid, VariableName); ShellStatus = SHELL_ACCESS_DENIED; } else { ASSERT(ShellStatus == SHELL_SUCCESS); } } } ShellCommandLineFreeVarList (Package); } if (Buffer != NULL) { FreePool(Buffer); } return (ShellStatus); }
/** Dump performance data. @param[in] ImageHandle The image handle. @param[in] SystemTable The system table. @retval EFI_SUCCESS Command completed successfully. @retval EFI_INVALID_PARAMETER Command usage error. @retval EFI_ABORTED The user aborts the operation. @retval value Unknown error. **/ EFI_STATUS EFIAPI InitializeDp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { UINT64 Freq; UINT64 Ticker; UINT32 ListIndex; LIST_ENTRY *ParamPackage; CONST CHAR16 *CmdLineArg; EFI_STRING StringPtr; UINTN Number2Display; EFI_STATUS Status; BOOLEAN SummaryMode; BOOLEAN VerboseMode; BOOLEAN AllMode; BOOLEAN RawMode; BOOLEAN TraceMode; BOOLEAN ProfileMode; BOOLEAN ExcludeMode; BOOLEAN CumulativeMode; CONST CHAR16 *CustomCumulativeToken; PERF_CUM_DATA *CustomCumulativeData; EFI_STRING StringDpOptionQh; EFI_STRING StringDpOptionLh; EFI_STRING StringDpOptionUh; EFI_STRING StringDpOptionLv; EFI_STRING StringDpOptionUs; EFI_STRING StringDpOptionLs; EFI_STRING StringDpOptionUa; EFI_STRING StringDpOptionUr; EFI_STRING StringDpOptionUt; EFI_STRING StringDpOptionUp; EFI_STRING StringDpOptionLx; EFI_STRING StringDpOptionLn; EFI_STRING StringDpOptionLt; EFI_STRING StringDpOptionLi; EFI_STRING StringDpOptionLc; SummaryMode = FALSE; VerboseMode = FALSE; AllMode = FALSE; RawMode = FALSE; TraceMode = FALSE; ProfileMode = FALSE; ExcludeMode = FALSE; CumulativeMode = FALSE; CustomCumulativeData = NULL; StringDpOptionQh = NULL; StringDpOptionLh = NULL; StringDpOptionUh = NULL; StringDpOptionLv = NULL; StringDpOptionUs = NULL; StringDpOptionLs = NULL; StringDpOptionUa = NULL; StringDpOptionUr = NULL; StringDpOptionUt = NULL; StringDpOptionUp = NULL; StringDpOptionLx = NULL; StringDpOptionLn = NULL; StringDpOptionLt = NULL; StringDpOptionLi = NULL; StringDpOptionLc = NULL; StringPtr = NULL; // Get DP's entry time as soon as possible. // This is used as the Shell-Phase end time. // Ticker = GetPerformanceCounter (); // Register our string package with HII and return the handle to it. // gHiiHandle = HiiAddPackages (&gEfiCallerIdGuid, ImageHandle, DPStrings, NULL); ASSERT (gHiiHandle != NULL); // Initial the command list // InitialShellParamList (); /**************************************************************************** **** Process Command Line arguments **** ****************************************************************************/ Status = ShellCommandLineParse (DpParamList, &ParamPackage, NULL, TRUE); if (EFI_ERROR(Status)) { PrintToken (STRING_TOKEN (STR_DP_INVALID_ARG)); ShowHelp(); } else { StringDpOptionQh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_QH), NULL); StringDpOptionLh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LH), NULL); StringDpOptionUh = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UH), NULL); if (ShellCommandLineGetFlag (ParamPackage, StringDpOptionQh) || ShellCommandLineGetFlag (ParamPackage, StringDpOptionLh) || ShellCommandLineGetFlag (ParamPackage, StringDpOptionUh)) { ShowHelp(); } else { StringDpOptionLv = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LV), NULL); StringDpOptionUs = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_US), NULL); StringDpOptionLs = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LS), NULL); StringDpOptionUa = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UA), NULL); StringDpOptionUr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UR), NULL); StringDpOptionUt = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UT), NULL); StringDpOptionUp = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_UP), NULL); StringDpOptionLx = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LX), NULL); StringDpOptionLn = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LN), NULL); StringDpOptionLt = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LT), NULL); StringDpOptionLi = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LI), NULL); StringDpOptionLc = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LC), NULL); // Boolean Options // VerboseMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLv); SummaryMode = (BOOLEAN) (ShellCommandLineGetFlag (ParamPackage, StringDpOptionUs) || ShellCommandLineGetFlag (ParamPackage, StringDpOptionLs)); AllMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUa); RawMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUr); #if PROFILING_IMPLEMENTED TraceMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUt); ProfileMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionUp); #endif // PROFILING_IMPLEMENTED ExcludeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLx); mShowId = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLi); CumulativeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLc); // Options with Values CmdLineArg = ShellCommandLineGetValue (ParamPackage, StringDpOptionLn); if (CmdLineArg == NULL) { Number2Display = DEFAULT_DISPLAYCOUNT; } else { Number2Display = StrDecimalToUintn(CmdLineArg); if (Number2Display == 0) { Number2Display = MAXIMUM_DISPLAYCOUNT; } } CmdLineArg = ShellCommandLineGetValue (ParamPackage, StringDpOptionLt); if (CmdLineArg == NULL) { mInterestThreshold = DEFAULT_THRESHOLD; // 1ms := 1,000 us } else { mInterestThreshold = StrDecimalToUint64(CmdLineArg); } // Handle Flag combinations and default behaviors // If both TraceMode and ProfileMode are FALSE, set them both to TRUE if ((! TraceMode) && (! ProfileMode)) { TraceMode = TRUE; #if PROFILING_IMPLEMENTED ProfileMode = TRUE; #endif // PROFILING_IMPLEMENTED } // // Init the custom cumulative data. // CustomCumulativeToken = ShellCommandLineGetValue (ParamPackage, StringDpOptionLc); if (CustomCumulativeToken != NULL) { CustomCumulativeData = AllocateZeroPool (sizeof (PERF_CUM_DATA)); ASSERT (CustomCumulativeData != NULL); CustomCumulativeData->MinDur = 0; CustomCumulativeData->MaxDur = 0; CustomCumulativeData->Count = 0; CustomCumulativeData->Duration = 0; CustomCumulativeData->Name = AllocateZeroPool (StrLen (CustomCumulativeToken) + 1); UnicodeStrToAsciiStr (CustomCumulativeToken, CustomCumulativeData->Name); } /**************************************************************************** **** Timer specific processing **** ****************************************************************************/ // Get the Performance counter characteristics: // Freq = Frequency in Hz // StartCount = Value loaded into the counter when it starts counting // EndCount = Value counter counts to before it needs to be reset // Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount); // Convert the Frequency from Hz to KHz TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000); // Determine in which direction the performance counter counts. TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount); /**************************************************************************** **** Print heading **** ****************************************************************************/ // print DP's build version PrintToken (STRING_TOKEN (STR_DP_BUILD_REVISION), DP_MAJOR_VERSION, DP_MINOR_VERSION); // print performance timer characteristics PrintToken (STRING_TOKEN (STR_DP_KHZ), TimerInfo.Frequency); // Print Timer frequency in KHz if ((VerboseMode) && (! RawMode) ) { StringPtr = HiiGetString (gHiiHandle, (EFI_STRING_ID) (TimerInfo.CountUp ? STRING_TOKEN (STR_DP_UP) : STRING_TOKEN (STR_DP_DOWN)), NULL); ASSERT (StringPtr != NULL); PrintToken (STRING_TOKEN (STR_DP_TIMER_PROPERTIES), // Print Timer count range and direction StringPtr, TimerInfo.StartCount, TimerInfo.EndCount ); PrintToken (STRING_TOKEN (STR_DP_VERBOSE_THRESHOLD), mInterestThreshold); } /* ************************************************************************** **** Print Sections based on command line options **** **** Option modes have the following priority: **** v Verbose -- Valid in combination with any other options **** t Threshold -- Modifies All, Raw, and Cooked output **** Default is 0 for All and Raw mode **** Default is DEFAULT_THRESHOLD for "Cooked" mode **** n Number2Display Used by All and Raw mode. Otherwise ignored. **** A All -- R and S options are ignored **** R Raw -- S option is ignored **** s Summary -- Modifies "Cooked" output only **** Cooked (Default) **** **** The All, Raw, and Cooked modes are modified by the Trace and Profile **** options. **** !T && !P := (0) Default, Both are displayed **** T && !P := (1) Only Trace records are displayed **** !T && P := (2) Only Profile records are displayed **** T && P := (3) Same as Default, both are displayed ****************************************************************************/ GatherStatistics (CustomCumulativeData); if (CumulativeMode) { ProcessCumulative (CustomCumulativeData); } else if (AllMode) { if (TraceMode) { Status = DumpAllTrace( Number2Display, ExcludeMode); if (Status == EFI_ABORTED) { goto Done; } } if (ProfileMode) { DumpAllProfile( Number2Display, ExcludeMode); } } else if (RawMode) { if (TraceMode) { Status = DumpRawTrace( Number2Display, ExcludeMode); if (Status == EFI_ABORTED) { goto Done; } } if (ProfileMode) { DumpRawProfile( Number2Display, ExcludeMode); } } else { //------------- Begin Cooked Mode Processing if (TraceMode) { ProcessPhases ( Ticker ); if ( ! SummaryMode) { Status = ProcessHandles ( ExcludeMode); if (Status == EFI_ABORTED) { goto Done; } Status = ProcessPeims (); if (Status == EFI_ABORTED) { goto Done; } Status = ProcessGlobal (); if (Status == EFI_ABORTED) { goto Done; } ProcessCumulative (NULL); } } if (ProfileMode) { DumpAllProfile( Number2Display, ExcludeMode); } } //------------- End of Cooked Mode Processing if ( VerboseMode || SummaryMode) { DumpStatistics(); } } } Done: // // Free the memory allocate from HiiGetString // ListIndex = 0; while (DpParamList[ListIndex].Name != NULL) { FreePool (DpParamList[ListIndex].Name); ListIndex ++; } FreePool (DpParamList); SafeFreePool (StringDpOptionQh); SafeFreePool (StringDpOptionLh); SafeFreePool (StringDpOptionUh); SafeFreePool (StringDpOptionLv); SafeFreePool (StringDpOptionUs); SafeFreePool (StringDpOptionLs); SafeFreePool (StringDpOptionUa); SafeFreePool (StringDpOptionUr); SafeFreePool (StringDpOptionUt); SafeFreePool (StringDpOptionUp); SafeFreePool (StringDpOptionLx); SafeFreePool (StringDpOptionLn); SafeFreePool (StringDpOptionLt); SafeFreePool (StringDpOptionLi); SafeFreePool (StringDpOptionLc); SafeFreePool (StringPtr); SafeFreePool (mPrintTokenBuffer); if (CustomCumulativeData != NULL) { SafeFreePool (CustomCumulativeData->Name); } SafeFreePool (CustomCumulativeData); HiiRemovePackages (gHiiHandle); return Status; }
/** as the real entry point for the application. @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The entry point is executed successfully. @retval other Some error occurs when executing this entry point. **/ EFI_STATUS EFIAPI UefiMain ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_FILE_HANDLE FileHandle; EFI_STATUS Status; CHAR16 FileName[100]; UINTN BufferSize; UINT64 Position; UINT8 Buffer[200]; EFI_FILE_INFO *pFileInfo; UINT64 Size; BOOLEAN NoFile; EFI_SHELL_FILE_INFO *pShellFileInfo; LIST_ENTRY *List; // CONST CHAR16 *Tester; FileHandle = NULL; StrCpy(FileName, L"testfile.txt"); // Position = 0; pFileInfo = NULL; Size = 0; NoFile = FALSE; pShellFileInfo = NULL; List = NULL; // command line param functions Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE); // if you put an invalid parameter you SHOULD hit this assert. ASSERT_EFI_ERROR(Status); if (List) { ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE); ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE); ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0); ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0); // Tester = ShellCommandLineGetValue(List, L"/Param3"); // Tester = ShellCommandLineGetValue(List, L"/Param4"); ShellCommandLineFreeVarList(List); } else { Print(L"param checking skipped.\r\n"); } // return (EFI_SUCCESS); ASSERT(ShellGetExecutionBreakFlag() == FALSE); ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f10:\\") == 0); Print(L"execution break and get cur dir - pass\r\n"); ShellSetPageBreakMode(TRUE); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); BufferSize = StrSize(FileName); Status = ShellWriteFile(FileHandle, &BufferSize, FileName); ASSERT_EFI_ERROR(Status); Status = ShellGetFilePosition(FileHandle, &Position); ASSERT_EFI_ERROR(Status); ASSERT(Position == 0x1A); Status = ShellSetFilePosition(FileHandle, 0); ASSERT_EFI_ERROR(Status); BufferSize = sizeof(Buffer) * sizeof(Buffer[0]); Status = ShellReadFile(FileHandle, &BufferSize, Buffer); ASSERT_EFI_ERROR(Status); ASSERT(BufferSize == 0x1A); ASSERT(StrCmp((CHAR16*)Buffer, FileName) == 0); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->FileSize == 0x1A); FreePool(pFileInfo); pFileInfo = NULL; Status = ShellCloseFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"read, write, create, getinfo - pass\r\n"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); pFileInfo->FileSize = 0x20; Status = ShellSetFileInfo(FileHandle, pFileInfo); FreePool(pFileInfo); pFileInfo = NULL; ASSERT_EFI_ERROR(Status); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->PhysicalSize == 0x20); ASSERT(pFileInfo->FileSize == 0x20); ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0); FreePool(pFileInfo); Status = ShellGetFileSize(FileHandle, &Size); ASSERT(Size == 0x20); ASSERT_EFI_ERROR(Status); Status = ShellCloseFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"setinfo and change size, getsize - pass\r\n"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->PhysicalSize == 0x20); ASSERT(pFileInfo->FileSize == 0x20); ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0); FreePool(pFileInfo); pFileInfo = NULL; Status = ShellDeleteFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"reopen file - pass\r\n"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->PhysicalSize == 0x0); ASSERT(pFileInfo->FileSize == 0x0); ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0); FreePool(pFileInfo); Status = ShellDeleteFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"size of empty - pass\r\n"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT(Status == EFI_NOT_FOUND); ASSERT(FileHandle == NULL); Status = ShellCreateDirectory(FileName, &FileHandle); ASSERT_EFI_ERROR(Status); ASSERT(FileHandle != NULL); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->Attribute&EFI_FILE_DIRECTORY); Status = ShellDeleteFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"Directory create - pass\r\n"); // FindFirst and FindNext StrCpy(FileName, L"testDir"); Status = ShellCreateDirectory(FileName, &FileHandle); Status = ShellCloseFile(&FileHandle); StrCat(FileName, L"\\File.txt"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); Status = ShellCloseFile(&FileHandle); StrCpy(FileName, L"testDir"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); Status = ShellFindFirstFile(FileHandle, &pFileInfo); ASSERT_EFI_ERROR(Status); Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile); ASSERT_EFI_ERROR(Status); ASSERT(NoFile == FALSE); Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile); ASSERT_EFI_ERROR(Status); ASSERT(NoFile == FALSE); Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile); ASSERT_EFI_ERROR(Status); ///@todo - why is NoFile never set? limitation of NT32 file system? Status = ShellDeleteFile(&FileHandle); ASSERT(Status == RETURN_WARN_DELETE_FAILURE); Print(L"FindFirst - pass\r\n"); Print(L"FindNext - Verify with real EFI system. Cant verify NoFile under NT32\r\n"); // open and close meta arg Status = ShellOpenFileMetaArg(L"testDir\\*.*", EFI_FILE_MODE_READ, &pShellFileInfo); ASSERT_EFI_ERROR(Status); ASSERT(pShellFileInfo->Status == 0); ASSERT(StrCmp(pShellFileInfo->FileName, L"File.txt") == 0); ASSERT(pShellFileInfo->Handle); ASSERT(pShellFileInfo->Info); ASSERT(pShellFileInfo->Info->FileSize == 0); ASSERT(StrCmp(pShellFileInfo->Info->FileName, L"File.txt") == 0); ASSERT(pShellFileInfo->Info->Attribute == 0); Status = ShellCloseFileMetaArg(&pShellFileInfo); ASSERT_EFI_ERROR(Status); Print(L"Open/Close Meta Arg - pass\r\n"); // now delete that file and that directory StrCat(FileName, L"\\File.txt"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); Status = ShellDeleteFile(&FileHandle); StrCpy(FileName, L"testDir"); ASSERT_EFI_ERROR(Status); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); Status = ShellDeleteFile(&FileHandle); ASSERT_EFI_ERROR(Status); // get environment variable // made for testing under nt32 ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f10:\\efi\\tools;f10:\\efi\\boot;f10:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0); Print(L"ShellGetEnvironmentVariable - pass\r\n"); // set environment variable Status = ShellSetEnvironmentVariable(L"", L"", FALSE); ASSERT(Status == EFI_UNSUPPORTED); Print(L"ShellSetEnvironmentVariable - pass\r\n"); // ShellExecute Status = ShellExecute(&ImageHandle, L"EmptyApplication.efi", TRUE, NULL, NULL); ASSERT_EFI_ERROR(Status); // the pass printout for this is performed by EmptyApplication Print(L"\r\n"); // page break mode (done last so we can see the results) // we set this true at the begining of the program // this is enough lines to trigger the page... Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n"); ShellSetPageBreakMode(FALSE); Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n56\r\n57\r\n58\r\n59\r\n60\r\n"); return EFI_SUCCESS; }
/** Function for 'cls' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunCls ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; UINTN Background; UINTN ForeColor; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Param1; // // Initialize variables // ShellStatus = SHELL_SUCCESS; ProblemParam = NULL; Background = 0; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } else { // // If there are 0 value parameters, clear sceen // Param1 = ShellCommandLineGetRawValue(Package, 1); if (Param1 == NULL) { // // clear screen // gST->ConOut->ClearScreen (gST->ConOut); } else if (ShellCommandLineGetCount(Package) > 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (ShellStrToUintn(Param1) > 7 || StrLen(Param1) > 1 || !ShellIsDecimalDigitCharacter(*Param1)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, Param1); ShellStatus = SHELL_INVALID_PARAMETER; } else { switch (ShellStrToUintn(Param1)) { case 0: Background = EFI_BACKGROUND_BLACK; break; case 1: Background = EFI_BACKGROUND_BLUE; break; case 2: Background = EFI_BACKGROUND_GREEN; break; case 3: Background = EFI_BACKGROUND_CYAN; break; case 4: Background = EFI_BACKGROUND_RED; break; case 5: Background = EFI_BACKGROUND_MAGENTA; break; case 6: Background = EFI_BACKGROUND_BROWN; break; case 7: Background = EFI_BACKGROUND_LIGHTGRAY; break; } ForeColor = (~ShellStrToUintn(Param1)) & 0xF; Status = gST->ConOut->SetAttribute (gST->ConOut, (ForeColor | Background) & 0x7F ); ASSERT_EFI_ERROR(Status); Status = gST->ConOut->ClearScreen (gST->ConOut); ASSERT_EFI_ERROR(Status); } } } } // // free the command line package // ShellCommandLineFreeVarList (Package); // // return the status // return (ShellStatus); }
/** Function for 'ls' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunLs ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; CONST CHAR16 *Attribs; SHELL_STATUS ShellStatus; UINT64 RequiredAttributes; CONST CHAR16 *PathName; CONST CHAR16 *CurDir; UINTN Count; CHAR16 *FullPath; UINTN Size; EFI_TIME TheTime; CHAR16 *SearchString; Size = 0; FullPath = NULL; ProblemParam = NULL; Attribs = NULL; ShellStatus = SHELL_SUCCESS; RequiredAttributes = 0; PathName = NULL; SearchString = NULL; CurDir = NULL; Count = 0; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // Fix local copies of the protocol pointers // Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (LsParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"ls", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } if (ShellCommandLineGetCount(Package) > 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"ls"); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // check for -a // if (ShellCommandLineGetFlag(Package, L"-a")) { for ( Attribs = ShellCommandLineGetValue(Package, L"-a") ; Attribs != NULL && *Attribs != CHAR_NULL && ShellStatus == SHELL_SUCCESS ; Attribs++ ){ switch (*Attribs) { case L'a': case L'A': RequiredAttributes |= EFI_FILE_ARCHIVE; Count++; continue; case L's': case L'S': RequiredAttributes |= EFI_FILE_SYSTEM; Count++; continue; case L'h': case L'H': RequiredAttributes |= EFI_FILE_HIDDEN; Count++; continue; case L'r': case L'R': RequiredAttributes |= EFI_FILE_READ_ONLY; Count++; continue; case L'd': case L'D': RequiredAttributes |= EFI_FILE_DIRECTORY; Count++; continue; default: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ATTRIBUTE), gShellLevel2HiiHandle, L"ls", ShellCommandLineGetValue(Package, L"-a")); ShellStatus = SHELL_INVALID_PARAMETER; break; } // switch } // for loop // // if nothing is specified all are specified // if (RequiredAttributes == 0) { RequiredAttributes = EFI_FILE_VALID_ATTR; } } // if -a present if (ShellStatus == SHELL_SUCCESS) { PathName = ShellCommandLineGetRawValue(Package, 1); if (PathName == NULL) { // // Nothing specified... must start from current directory // CurDir = gEfiShellProtocol->GetCurDir(NULL); if (CurDir == NULL) { ShellStatus = SHELL_NOT_FOUND; ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls"); } // // Copy to the 2 strings for starting path and file search string // ASSERT(SearchString == NULL); ASSERT(FullPath == NULL); StrnCatGrow(&SearchString, NULL, L"*", 0); StrnCatGrow(&FullPath, NULL, CurDir, 0); Size = FullPath != NULL? StrSize(FullPath) : 0; StrnCatGrow(&FullPath, &Size, L"\\", 0); } else { if (StrStr(PathName, L":") == NULL && gEfiShellProtocol->GetCurDir(NULL) == NULL) { // // If we got something and it doesnt have a fully qualified path, then we needed to have a CWD. // ShellStatus = SHELL_NOT_FOUND; ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls"); } else { // // We got a valid fully qualified path or we have a CWD // ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL)); if (StrStr(PathName, L":") == NULL) { StrnCatGrow(&FullPath, &Size, gEfiShellProtocol->GetCurDir(NULL), 0); if (FullPath == NULL) { ShellCommandLineFreeVarList (Package); return SHELL_OUT_OF_RESOURCES; } Size = FullPath != NULL? StrSize(FullPath) : 0; StrnCatGrow(&FullPath, &Size, L"\\", 0); } StrnCatGrow(&FullPath, &Size, PathName, 0); if (FullPath == NULL) { ShellCommandLineFreeVarList (Package); return SHELL_OUT_OF_RESOURCES; } if (ShellIsDirectory(PathName) == EFI_SUCCESS) { // // is listing ends with a directory, then we list all files in that directory // StrnCatGrow(&SearchString, NULL, L"*", 0); } else { // // must split off the search part that applies to files from the end of the directory part // StrnCatGrow(&SearchString, NULL, FullPath, 0); if (SearchString == NULL) { FreePool (FullPath); ShellCommandLineFreeVarList (Package); return SHELL_OUT_OF_RESOURCES; } PathRemoveLastItem (FullPath); CopyMem (SearchString, SearchString + StrLen (FullPath), StrSize (SearchString + StrLen (FullPath))); } } } Status = gRT->GetTime(&TheTime, NULL); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"ls", L"gRT->GetTime", Status); TheTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE; } if (ShellStatus == SHELL_SUCCESS) { ShellStatus = PrintLsOutput( ShellCommandLineGetFlag(Package, L"-r"), RequiredAttributes, ShellCommandLineGetFlag(Package, L"-sfo"), FullPath, SearchString, NULL, Count, TheTime.TimeZone ); if (ShellStatus == SHELL_NOT_FOUND) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle, L"ls", FullPath); } else if (ShellStatus == SHELL_INVALID_PARAMETER) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"ls", FullPath); } else if (ShellStatus == SHELL_ABORTED) { // // Ignore aborting. // } else if (ShellStatus != SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"ls", FullPath); } } } } } // // Free memory allocated // SHELL_FREE_NON_NULL(SearchString); SHELL_FREE_NON_NULL(FullPath); ShellCommandLineFreeVarList (Package); return (ShellStatus); }
/** Function for 'smbiosview' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunSmbiosView ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { UINT8 StructType; UINT16 StructHandle; EFI_STATUS Status; EFI_STATUS Status1; EFI_STATUS Status2; BOOLEAN RandomView; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Temp; mStatisticsTable = NULL; mSmbios64BitStatisticsTable = NULL; Package = NULL; ShellStatus = SHELL_SUCCESS; Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"smbiosview", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) > 1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetValue(Package, L"-t") == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-t"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetValue(Package, L"-h") == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"smbiosview", L"-h"); ShellStatus = SHELL_INVALID_PARAMETER; } else if ( (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-h")) || (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-s")) || (ShellCommandLineGetFlag(Package, L"-t") && ShellCommandLineGetFlag(Package, L"-a")) || (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-s")) || (ShellCommandLineGetFlag(Package, L"-h") && ShellCommandLineGetFlag(Package, L"-a")) || (ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-a")) ) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"smbiosview"); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // Init Lib // Status1 = LibSmbiosInit (); Status2 = LibSmbios64BitInit (); if (EFI_ERROR (Status1) && EFI_ERROR (Status2)) { ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_LIBSMBIOSVIEW_CANNOT_GET_TABLE), gShellDebug1HiiHandle); ShellStatus = SHELL_NOT_FOUND; goto Done; } StructType = STRUCTURE_TYPE_RANDOM; RandomView = TRUE; Temp = ShellCommandLineGetValue(Package, L"-t"); if (Temp != NULL) { StructType = (UINT8) ShellStrToUintn (Temp); } if (ShellCommandLineGetFlag(Package, L"-a")) { gShowType = SHOW_ALL; } if (!EFI_ERROR (Status1)) { // // Initialize the StructHandle to be the first handle // StructHandle = INVALID_HANDLE; LibGetSmbiosStructure (&StructHandle, NULL, NULL); Temp = ShellCommandLineGetValue(Package, L"-h"); if (Temp != NULL) { RandomView = FALSE; StructHandle = (UINT16) ShellStrToUintn(Temp); } // // build statistics table // Status = InitSmbiosTableStatistics (); if (EFI_ERROR (Status)) { ShellStatus = SHELL_NOT_FOUND; goto Done; } if (ShellCommandLineGetFlag(Package, L"-s")) { Status = DisplayStatisticsTable (SHOW_DETAIL); if (EFI_ERROR(Status)) { ShellStatus = SHELL_NOT_FOUND; } goto Show64Bit; } // // Show SMBIOS structure information // Status = SMBiosView (StructType, StructHandle, gShowType, RandomView); if (EFI_ERROR(Status)) { ShellStatus = SHELL_NOT_FOUND; goto Done; } } Show64Bit: if (!EFI_ERROR (Status2)) { // // build statistics table // Status = InitSmbios64BitTableStatistics (); if (EFI_ERROR (Status)) { ShellStatus = SHELL_NOT_FOUND; goto Done; } // // Initialize the StructHandle to be the first handle // StructHandle = INVALID_HANDLE; LibGetSmbios64BitStructure (&StructHandle, NULL, NULL); Temp = ShellCommandLineGetValue(Package, L"-h"); if (Temp != NULL) { RandomView = FALSE; StructHandle = (UINT16) ShellStrToUintn(Temp); } if (ShellCommandLineGetFlag(Package, L"-s")) { Status = DisplaySmbios64BitStatisticsTable (SHOW_DETAIL); if (EFI_ERROR(Status)) { ShellStatus = SHELL_NOT_FOUND; } goto Done; } // // Show SMBIOS structure information // Status = SMBios64View (StructType, StructHandle, gShowType, RandomView); if (EFI_ERROR(Status)) { ShellStatus = SHELL_NOT_FOUND; } } } } Done: // // Release resources // if (mStatisticsTable != NULL) { // // Release statistics table // FreePool (mStatisticsTable); mStatisticsTable = NULL; } if (mSmbios64BitStatisticsTable != NULL) { // // Release statistics table // FreePool (mSmbios64BitStatisticsTable); mSmbios64BitStatisticsTable = NULL; } if (Package != NULL) { ShellCommandLineFreeVarList (Package); } LibSmbiosCleanup (); LibSmbios64BitCleanup (); return ShellStatus; }
/** Function for 'date' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunDate ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; EFI_TIME TheTime; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Param1; ShellStatus = SHELL_SUCCESS; ProblemParam = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (SfoParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // If there are 0 value parameters, then print the current date // else If there are any value paramerers, then print error // if (ShellCommandLineGetRawValue(Package, 1) == NULL) { // // get the current date // Status = gRT->GetTime(&TheTime, NULL); ASSERT_EFI_ERROR(Status); // // ShellPrintEx the date in SFO or regular format // if (ShellCommandLineGetFlag(Package, L"-sfo")) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_SFO_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DATE_FORMAT), gShellLevel2HiiHandle, TheTime.Month, TheTime.Day, TheTime.Year); } } else { if (PcdGet8(PcdShellSupportLevel) == 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // perform level 3 operation here. // Param1 = ShellCommandLineGetRawValue(Package, 1); if (Param1 == NULL) { ShellStatus = SHELL_INVALID_PARAMETER; } else { ShellStatus = CheckAndSetDate(Param1); } if (ShellStatus != SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, Param1); ShellStatus = SHELL_INVALID_PARAMETER; } } } } } // // free the command line package // ShellCommandLineFreeVarList (Package); // // return the status // return (ShellStatus); }
/** Function for 'drvcfg' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunDrvCfg ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CHAR8 *Language; CONST CHAR16 *Lang; CONST CHAR16 *HandleIndex1; CONST CHAR16 *HandleIndex2; CONST CHAR16 *HandleIndex3; CONST CHAR16 *ForceTypeString; BOOLEAN Force; BOOLEAN Set; BOOLEAN Validate; BOOLEAN InFromFile; BOOLEAN OutToFile; BOOLEAN AllChildren; BOOLEAN UseHii; UINT32 ForceType; UINT64 Intermediate; EFI_HANDLE Handle1; EFI_HANDLE Handle2; EFI_HANDLE Handle3; CONST CHAR16 *FileName; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; Language = NULL; UseHii = TRUE; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (ParamListHii, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status) || ShellCommandLineGetCount(Package) > 2) { UseHii = FALSE; if (Package != NULL) { ShellCommandLineFreeVarList (Package); } SHELL_FREE_NON_NULL(ProblemParam); Status = ShellCommandLineParse (ParamListPreHii, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } else { ASSERT(FALSE); } } } if (ShellStatus == SHELL_SUCCESS) { Lang = ShellCommandLineGetValue(Package, L"-l"); if (Lang != NULL) { Language = AllocateZeroPool(StrSize(Lang)); AsciiSPrint(Language, StrSize(Lang), "%S", Lang); } else if (ShellCommandLineGetFlag(Package, L"-l")){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } Set = ShellCommandLineGetFlag (Package, L"-s"); Validate = ShellCommandLineGetFlag (Package, L"-v"); InFromFile = ShellCommandLineGetFlag (Package, L"-i"); OutToFile = ShellCommandLineGetFlag (Package, L"-o"); AllChildren = ShellCommandLineGetFlag (Package, L"-c"); Force = ShellCommandLineGetFlag (Package, L"-f"); ForceTypeString = ShellCommandLineGetValue(Package, L"-f"); if (OutToFile) { FileName = ShellCommandLineGetValue(Package, L"-o"); } else if (InFromFile) { FileName = ShellCommandLineGetValue(Package, L"-i"); } else { FileName = NULL; } if (InFromFile && EFI_ERROR(ShellFileExists(FileName))) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FIND_FAIL), gShellDriver1HiiHandle, FileName); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (OutToFile && !EFI_ERROR(ShellFileExists(FileName))) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_EXIST), gShellDriver1HiiHandle, FileName); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (Force && ForceTypeString == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-f"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (Force) { Status = ShellConvertStringToUint64(ForceTypeString, &Intermediate, FALSE, FALSE); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDriver1HiiHandle, L"-f"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } ForceType = (UINT32)Intermediate; } else { ForceType = 0; } HandleIndex1 = ShellCommandLineGetRawValue(Package, 1); Handle1 = NULL; if (HandleIndex1 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex1, &Intermediate, TRUE, FALSE))) { Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); if (Handle1 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex1); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } HandleIndex2 = ShellCommandLineGetRawValue(Package, 2); Handle2 = NULL; if (HandleIndex2 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex2, &Intermediate, TRUE, FALSE))) { Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); if (Handle2 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex2); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } HandleIndex3 = ShellCommandLineGetRawValue(Package, 3); Handle3 = NULL; if (HandleIndex3 != NULL && !EFI_ERROR(ShellConvertStringToUint64(HandleIndex3, &Intermediate, TRUE, FALSE))) { Handle3 = ConvertHandleIndexToHandle((UINTN)Intermediate); if (Handle3 == NULL || (UINT64)(UINTN)Intermediate != Intermediate) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, HandleIndex3); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } if ((InFromFile || OutToFile) && (FileName == NULL)) { if (FileName == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, InFromFile?L"-i":L"-o"); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_REQ), gShellDriver1HiiHandle); } ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (!UseHii && (InFromFile || OutToFile)) { if (InFromFile) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"-i"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (OutToFile) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"-o"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } if (Validate && Force) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-v", L"-f"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (Validate && Set) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-v", L"-s"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (Set && Force) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-s", L"-f"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (OutToFile && InFromFile) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-i", L"-o"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } // // We do HII first. // if (UseHii) { if (Handle1 != NULL && EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { // // no HII on this handle. // ShellStatus = SHELL_UNSUPPORTED; } else if (Validate) { } else if (Force) { } else if (Set) { } else if (InFromFile) { ShellStatus = ConfigFromFile(Handle1, FileName); if (Handle1 != NULL && ShellStatus == SHELL_SUCCESS) { goto Done; } } else if (OutToFile) { ShellStatus = ConfigToFile(Handle1, FileName); if (Handle1 != NULL && ShellStatus == SHELL_SUCCESS) { goto Done; } } else if (HandleIndex1 == NULL) { // // display all that are configurable // ShellStatus = PrintConfigInfoOnAll(AllChildren, Language, UseHii); goto Done; } else { if (!EFI_ERROR(gBS->OpenProtocol(Handle1, &gEfiHiiConfigAccessProtocolGuid, NULL, gImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_DRVCFG_LINE_HII), gShellDriver1HiiHandle, ConvertHandleToHandleIndex(Handle1) ); goto Done; } } } // // We allways need to do this one since it does both by default. // if (!InFromFile && !OutToFile) { ShellStatus = PreHiiDrvCfg ( Language, Force, ForceType, AllChildren, Validate, Set, Handle1, Handle2, Handle3); } if (ShellStatus == SHELL_UNSUPPORTED) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NOT_SUPPORT), gShellDriver1HiiHandle, ConvertHandleToHandleIndex(Handle1) ); } } Done: ShellCommandLineFreeVarList (Package); SHELL_FREE_NON_NULL(Language); return (ShellStatus); }
/** Function for 'timezone' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunTimeZone ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { // // non interactive // EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINT8 LoopVar; EFI_TIME TheTime; BOOLEAN Found; UINTN TzMinutes; ShellStatus = SHELL_SUCCESS; ProblemParam = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // if (PcdGet8(PcdShellSupportLevel) == 2) { Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, TRUE); } else { ASSERT(PcdGet8(PcdShellSupportLevel) == 3); Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, TRUE, TRUE); } if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetCount(Package) > 1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } else if (ShellCommandLineGetFlag(Package, L"-s")) { if ((ShellCommandLineGetFlag(Package, L"-l")) || (ShellCommandLineGetFlag(Package, L"-f"))) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"-l or -f"); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(PcdGet8(PcdShellSupportLevel) == 3); if (ShellCommandLineGetValue(Package, L"-s") == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-s"); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // Set the time zone // ShellStatus = CheckAndSetTimeZone(ShellCommandLineGetValue(Package, L"-s")); if (ShellStatus != SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetValue(Package, L"-s")); ShellStatus = SHELL_INVALID_PARAMETER; } } } } else if (ShellCommandLineGetFlag(Package, L"-l")) { // // Print a list of all time zones // for ( LoopVar = 0 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0]) ; LoopVar++ ){ ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle); } } else { // // Get Current Time Zone Info // Status = gRT->GetTime(&TheTime, NULL); ASSERT_EFI_ERROR(Status); if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) { Found = FALSE; for ( LoopVar = 0 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0]) ; LoopVar++ ){ if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) { if (ShellCommandLineGetFlag(Package, L"-f")) { // // Print all info about current time zone // ShellPrintHiiEx (-1, -1, NULL, TimeZoneList[LoopVar].StringId, gShellLevel2HiiHandle); } else { // // Print basic info only // if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) { TzMinutes = 0; } else { TzMinutes = (ABS(TheTime.TimeZone)) % 60; } ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_SIMPLE), gShellLevel2HiiHandle, TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"), TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60, TzMinutes); } Found = TRUE; break; } } if (!Found) { // // Print basic info only // if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) { TzMinutes = 0; } else { TzMinutes = (ABS(TheTime.TimeZone)) % 60; } ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_SIMPLE), gShellLevel2HiiHandle, TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"), TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60, TzMinutes); if (ShellCommandLineGetFlag(Package, L"-f")) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle); } } } else { // // TimeZone was EFI_UNSPECIFIED_TIMEZONE (unknown) from GetTime() // } } } // // free the command line package // ShellCommandLineFreeVarList (Package); return (ShellStatus); }
/** Fill in SAD_ENTRY_INDEXER through ParamPackage list. @param[in, out] Indexer The pointer to the SAD_ENTRY_INDEXER structure. @param[in] ParamPackage The pointer to the ParamPackage list. @retval EFI_SUCCESS Filled in SPD_ENTRY_INDEXER successfully. @retval EFI_INVALID_PARAMETER The mistaken user input in ParamPackage list. **/ EFI_STATUS ConstructSadIndexer ( IN OUT SAD_ENTRY_INDEXER *Indexer, IN LIST_ENTRY *ParamPackage ) { EFI_STATUS Status; EFI_STATUS Status1; UINT64 Value64; CONST CHAR16 *ValueStr; ValueStr = NULL; if (ShellCommandLineGetFlag (ParamPackage, L"-i")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-i"); } else if (ShellCommandLineGetFlag (ParamPackage, L"-d")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-d"); } else if (ShellCommandLineGetFlag (ParamPackage, L"-e")) { ValueStr = ShellCommandLineGetValue (ParamPackage, L"-e"); } else { ASSERT (FALSE); } ASSERT (ValueStr != NULL); Value64 = StrToUInteger (ValueStr, &Status); if (!EFI_ERROR (Status)) { Indexer->Index = (UINTN) Value64; ZeroMem (&Indexer->SaId, sizeof (EFI_IPSEC_SA_ID)); } else { if ((!ShellCommandLineGetFlag (ParamPackage, L"--lookup-spi")) || (!ShellCommandLineGetFlag (ParamPackage, L"--lookup-ipsec-proto")) || (!ShellCommandLineGetFlag (ParamPackage, L"--lookup-dest"))) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_MISSING_ONE_OF_PARAMETERS), mHiiHandle, mAppName, L"--lookup-spi --lookup-ipsec-proto --lookup-dest" ); return EFI_INVALID_PARAMETER; } Status = GetNumber ( L"--lookup-spi", (UINT32) -1, &Indexer->SaId.Spi, sizeof (UINT32), NULL, ParamPackage, FORMAT_NUMBER ); Status1 = GetNumber ( L"--lookup-ipsec-proto", 0, &Indexer->SaId.Proto, sizeof (EFI_IPSEC_PROTOCOL_TYPE), mMapIpSecProtocol, ParamPackage, FORMAT_STRING ); if (EFI_ERROR (Status) || EFI_ERROR (Status1)) { return EFI_INVALID_PARAMETER; } ValueStr = ShellCommandLineGetValue (ParamPackage, L"--lookup-dest"); ASSERT (ValueStr != NULL); Status = EfiInetAddr2 ((CHAR16 *) ValueStr, &Indexer->SaId.DestAddress); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_IPSEC_CONFIG_INCORRECT_PARAMETER_VALUE), mHiiHandle, mAppName, L"--lookup-dest", ValueStr ); return EFI_INVALID_PARAMETER; } } return EFI_SUCCESS; }
/** Function for 'touch' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunTouch ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; CONST CHAR16 *Param; SHELL_STATUS ShellStatus; UINTN ParamCount; EFI_SHELL_FILE_INFO *FileList; EFI_SHELL_FILE_INFO *Node; ProblemParam = NULL; ShellStatus = SHELL_SUCCESS; ParamCount = 0; FileList = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"touch", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } if (ShellCommandLineGetRawValue(Package, 1) == NULL) { // // we insufficient parameters // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle, L"touch"); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // get a list with each file specified by parameters // if parameter is a directory then add all the files below it to the list // for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount) ; Param != NULL ; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount) ){ Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, &FileList); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"touch", (CHAR16*)Param); ShellStatus = SHELL_NOT_FOUND; break; } // // make sure we completed the param parsing sucessfully... // Also make sure that any previous action was sucessful // if (ShellStatus == SHELL_SUCCESS) { // // check that we have at least 1 file // if (FileList == NULL || IsListEmpty(&FileList->Link)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, L"touch", Param); continue; } else { // // loop through the list and make sure we are not aborting... // for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link) ; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag() ; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link) ){ // // make sure the file opened ok // if (EFI_ERROR(Node->Status)){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Node->FileName); ShellStatus = SHELL_NOT_FOUND; continue; } Status = DoTouchByHandle(Node->FullName, NULL, Node->Handle, ShellCommandLineGetFlag(Package, L"-r")); if (EFI_ERROR(Status) && Status != EFI_ACCESS_DENIED) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Node->FileName); ShellStatus = SHELL_NOT_FOUND; } } } } // // Free the fileList // if (FileList != NULL && !IsListEmpty(&FileList->Link)) { Status = ShellCloseFileMetaArg(&FileList); ASSERT_EFI_ERROR(Status); } FileList = NULL; } } // // free the command line package // ShellCommandLineFreeVarList (Package); } if (ShellGetExecutionBreakFlag()) { return (SHELL_ABORTED); } return (ShellStatus); }
/** Function for 'drvdiag' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunDrvDiag ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; DRV_DIAG_TEST_MODE Mode; CHAR8 *Language; CONST CHAR16 *DriverHandleStr; CONST CHAR16 *ControllerHandleStr; CONST CHAR16 *ChildHandleStr; CONST CHAR16 *Lang; EFI_HANDLE Handle1; EFI_HANDLE Handle2; EFI_HANDLE Handle3; UINT64 Intermediate; ShellStatus = SHELL_SUCCESS; Mode = TestModeMax; Language = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // if more than 3 'value' parameters (plus the name one) or we have any 2 mode flags // if ((ShellCommandLineGetCount(Package) > 4) ||(ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-e")) ||(ShellCommandLineGetFlag(Package, L"-s") && ShellCommandLineGetFlag(Package, L"-m")) ||(ShellCommandLineGetFlag(Package, L"-e") && ShellCommandLineGetFlag(Package, L"-m")) ){ // // error for too many parameters // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if ((ShellCommandLineGetFlag(Package, L"-s")) || (ShellCommandLineGetFlag(Package, L"-e")) || (ShellCommandLineGetFlag(Package, L"-m")) ){ // // Run the apropriate test // if (ShellCommandLineGetFlag(Package, L"-s")) { Mode = TestModeStandard; } else if (ShellCommandLineGetFlag(Package, L"-e")) { Mode = TestModeExtended; } else if (ShellCommandLineGetFlag(Package, L"-m")) { Mode = TestModeManufacturing; } else { ASSERT(FALSE); } } else { // // Do a listing of what's available to test // Mode = TestModeList; } Lang = ShellCommandLineGetValue(Package, L"-l"); if (ShellCommandLineGetFlag(Package, L"-l") && Lang == NULL) { ASSERT(Language == NULL); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l"); ShellCommandLineFreeVarList (Package); return (SHELL_INVALID_PARAMETER); } else if (Lang != NULL) { Language = AllocateZeroPool(StrSize(Lang)); AsciiSPrint(Language, StrSize(Lang), "%S", Lang); } DriverHandleStr = ShellCommandLineGetRawValue(Package, 1); ControllerHandleStr = ShellCommandLineGetRawValue(Package, 2); ChildHandleStr = ShellCommandLineGetRawValue(Package, 3); if (DriverHandleStr == NULL) { Handle1 = NULL; } else { ShellConvertStringToUint64(DriverHandleStr, &Intermediate, TRUE, FALSE); Handle1 = ConvertHandleIndexToHandle((UINTN)Intermediate); } if (ControllerHandleStr == NULL) { Handle2 = NULL; } else { ShellConvertStringToUint64(ControllerHandleStr, &Intermediate, TRUE, FALSE); Handle2 = ConvertHandleIndexToHandle((UINTN)Intermediate); } if (ChildHandleStr == NULL) { Handle3 = NULL; } else { ShellConvertStringToUint64(ChildHandleStr, &Intermediate, TRUE, FALSE); Handle3 = ConvertHandleIndexToHandle((UINTN)Intermediate); } Status = DoDiagnostics ( Mode, Language, ShellCommandLineGetFlag(Package, L"-c"), Handle1, Handle2, Handle3 ); SHELL_FREE_NON_NULL(Language); ShellCommandLineFreeVarList (Package); } if (ShellStatus == SHELL_SUCCESS) { if (Status == EFI_SECURITY_VIOLATION) { ShellStatus = SHELL_SECURITY_VIOLATION; } else if (Status == EFI_INVALID_PARAMETER) { ShellStatus = SHELL_INVALID_PARAMETER; } else if (Status == EFI_NOT_FOUND) { ShellStatus = SHELL_NOT_FOUND; } else if (EFI_ERROR(Status)) { ShellStatus = SHELL_NOT_FOUND; } } return (ShellStatus); }
/** Function for 'exit' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunExit ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINT64 RetVal; CONST CHAR16 *Return; ShellStatus = SHELL_SUCCESS; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // return the specified error code // Return = ShellCommandLineGetRawValue(Package, 1); if (Return != NULL) { Status = ShellConvertStringToUint64(Return, &RetVal, FALSE, FALSE); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, Return); ShellStatus = SHELL_INVALID_PARAMETER; } else { // // If we are in a batch file and /b then pass TRUE otherwise false... // ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), RetVal); ShellStatus = SHELL_SUCCESS; } } else { // If we are in a batch file and /b then pass TRUE otherwise false... // ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), 0); ShellStatus = SHELL_SUCCESS; } ShellCommandLineFreeVarList (Package); } return (ShellStatus); }
/** Function for 'mkdir' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunMkDir ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; CONST CHAR16 *NewDirName; UINTN DirCreateCount; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_FILE_HANDLE FileHandle; SHELL_STATUS ShellStatus; ShellStatus = SHELL_SUCCESS; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mkdir", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } // // create a set of directories // if (ShellCommandLineGetRawValue(Package, 1) == NULL) { // // we didnt get a single parameter // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mkdir"); ShellStatus = SHELL_INVALID_PARAMETER; } else { for ( DirCreateCount = 1 ; ; DirCreateCount++ ){ // // loop through each directory specified // NewDirName = ShellCommandLineGetRawValue(Package, DirCreateCount); if (NewDirName == NULL) { break; } // // check if that already exists... if yes fail // FileHandle = NULL; Status = ShellOpenFileByName(NewDirName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, EFI_FILE_DIRECTORY ); if (!EFI_ERROR(Status)) { ShellCloseFile(&FileHandle); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName); ShellStatus = SHELL_INVALID_PARAMETER; break; } else { ASSERT(FileHandle == NULL); // // create the directory named NewDirName // Status = ShellCreateDirectory(NewDirName, &FileHandle); if (FileHandle != NULL) { gEfiShellProtocol->CloseFile(FileHandle); } if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName); ShellStatus = SHELL_ACCESS_DENIED; break; } } } } } // // free the command line package // ShellCommandLineFreeVarList (Package); return (ShellStatus); }
/** Function for 'mm' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunMm ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *IoDev; UINT64 Address; UINT64 PciEAddress; UINT64 Value; UINT32 SegmentNumber; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width; EFI_ACCESS_TYPE AccessType; UINT64 Buffer; UINTN Index; UINTN Size; // CHAR16 *ValueStr; BOOLEAN Complete; CHAR16 *InputStr; BOOLEAN Interactive; EFI_HANDLE *HandleBuffer; UINTN BufferSize; UINTN ItemValue; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Temp; Value = 0; Address = 0; PciEAddress = 0; IoDev = NULL; HandleBuffer = NULL; BufferSize = 0; SegmentNumber = 0; ShellStatus = SHELL_SUCCESS; InputStr = NULL; // // Parse arguments // Width = EfiPciWidthUint8; Size = 1; AccessType = EfiMemory; // ValueStr = NULL; Interactive = TRUE; Package = NULL; Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) < 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } else if (ShellCommandLineGetCount(Package) > 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } else if (ShellCommandLineGetFlag(Package, L"-w") && ShellCommandLineGetValue(Package, L"-w") == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"-w"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } else { if (ShellCommandLineGetFlag(Package, L"-mmio")) { AccessType = EFIMemoryMappedIo; if (ShellCommandLineGetFlag(Package, L"-mem") ||ShellCommandLineGetFlag(Package, L"-io") ||ShellCommandLineGetFlag(Package, L"-pci") ||ShellCommandLineGetFlag(Package, L"-pcie") ){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } else if (ShellCommandLineGetFlag(Package, L"-mem")) { AccessType = EfiMemory; if (ShellCommandLineGetFlag(Package, L"-io") ||ShellCommandLineGetFlag(Package, L"-pci") ||ShellCommandLineGetFlag(Package, L"-pcie") ){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } else if (ShellCommandLineGetFlag(Package, L"-io")) { AccessType = EfiIo; if (ShellCommandLineGetFlag(Package, L"-pci") ||ShellCommandLineGetFlag(Package, L"-pcie") ){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } else if (ShellCommandLineGetFlag(Package, L"-pci")) { AccessType = EfiPciConfig; if (ShellCommandLineGetFlag(Package, L"-pcie") ){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } else if (ShellCommandLineGetFlag(Package, L"-pcie")) { AccessType = EfiPciEConfig; } } // // Non interactive for a script file or for the specific parameter // if (gEfiShellProtocol->BatchIsActive() || ShellCommandLineGetFlag (Package, L"-n")) { Interactive = FALSE; } Temp = ShellCommandLineGetValue(Package, L"-w"); if (Temp != NULL) { ItemValue = ShellStrToUintn (Temp); switch (ItemValue) { case 1: Width = EfiPciWidthUint8; Size = 1; break; case 2: Width = EfiPciWidthUint16; Size = 2; break; case 4: Width = EfiPciWidthUint32; Size = 4; break; case 8: Width = EfiPciWidthUint64; Size = 8; break; default: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"-w"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } Temp = ShellCommandLineGetRawValue(Package, 1); if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, (UINT64*)&Address, TRUE, FALSE))) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } Temp = ShellCommandLineGetRawValue(Package, 2); if (Temp != NULL) { // // Per spec if value is specified, then -n is assumed. // Interactive = FALSE; if (!ShellIsHexOrDecimalNumber(Temp, TRUE, FALSE) || EFI_ERROR(ShellConvertStringToUint64(Temp, &Value, TRUE, FALSE))) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } switch (Size) { case 1: if (Value > 0xFF) { ShellStatus = SHELL_INVALID_PARAMETER; } break; case 2: if (Value > 0xFFFF) { ShellStatus = SHELL_INVALID_PARAMETER; } break; case 4: if (Value > 0xFFFFFFFF) { ShellStatus = SHELL_INVALID_PARAMETER; } break; default: break; } if (ShellStatus != SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } if ((Address & (Size - 1)) != 0) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_NOT_ALIGNED), gShellDebug1HiiHandle, Address); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } // // locate DeviceIO protocol interface // if (AccessType != EfiMemory) { Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiPciRootBridgeIoProtocolGuid, NULL, &BufferSize, &HandleBuffer ); if (EFI_ERROR (Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PCIRBIO_NF), gShellDebug1HiiHandle); ShellStatus = SHELL_NOT_FOUND; goto Done; } // // In the case of PCI or PCIE // Get segment number and mask the segment bits in Address // if (AccessType == EfiPciEConfig) { SegmentNumber = (UINT32) RShiftU64 (Address, 36) & 0xff; Address &= 0xfffffffffULL; } else { if (AccessType == EfiPciConfig) { SegmentNumber = (UINT32) RShiftU64 (Address, 32) & 0xff; Address &= 0xffffffff; } } // // Find the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL of the specified segment number // for (Index = 0; Index < BufferSize; Index++) { Status = gBS->HandleProtocol ( HandleBuffer[Index], &gEfiPciRootBridgeIoProtocolGuid, (VOID *) &IoDev ); if (EFI_ERROR (Status)) { continue; } if (IoDev->SegmentNumber != SegmentNumber) { IoDev = NULL; } } if (IoDev == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_SEGMENT_NOT_FOUND), gShellDebug1HiiHandle, SegmentNumber); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } if (AccessType == EfiIo && Address + Size > 0x10000) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } if (AccessType == EfiPciEConfig) { GetPciEAddressFromInputAddress (Address, &PciEAddress); } // // Set value // if (ShellCommandLineGetRawValue(Package, 2) != NULL) { if (AccessType == EFIMemoryMappedIo) { IoDev->Mem.Write (IoDev, Width, Address, 1, &Value); } else if (AccessType == EfiIo) { IoDev->Io.Write (IoDev, Width, Address, 1, &Value); } else if (AccessType == EfiPciConfig) { IoDev->Pci.Write (IoDev, Width, Address, 1, &Value); } else if (AccessType == EfiPciEConfig) { IoDev->Pci.Write (IoDev, Width, PciEAddress, 1, &Value); } else { WriteMem (Width, Address, 1, &Value); } ASSERT(ShellStatus == SHELL_SUCCESS); goto Done; } // // non-interactive mode // if (!Interactive) { Buffer = 0; if (AccessType == EFIMemoryMappedIo) { if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle); } IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiIo) { if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle); } IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiPciConfig) { if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle); } IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiPciEConfig) { if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle); } IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer); } else { if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle); } ReadMem (Width, Address, 1, &Buffer); } if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address); } if (Size == 1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, (UINTN)Buffer); } else if (Size == 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, (UINTN)Buffer); } else if (Size == 4) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, (UINTN)Buffer); } else if (Size == 8) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer); } ShellPrintEx(-1, -1, L"\r\n"); ASSERT(ShellStatus == SHELL_SUCCESS); goto Done; } // // interactive mode // Complete = FALSE; do { if (AccessType == EfiIo && Address + Size > 0x10000) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS_RANGE2), gShellDebug1HiiHandle); break; } Buffer = 0; if (AccessType == EFIMemoryMappedIo) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MMIO), gShellDebug1HiiHandle); IoDev->Mem.Read (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiIo) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_IO), gShellDebug1HiiHandle); IoDev->Io.Read (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiPciConfig) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCI), gShellDebug1HiiHandle); IoDev->Pci.Read (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiPciEConfig) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_PCIE), gShellDebug1HiiHandle); IoDev->Pci.Read (IoDev, Width, PciEAddress, 1, &Buffer); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_MEM), gShellDebug1HiiHandle); ReadMem (Width, Address, 1, &Buffer); } ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ADDRESS), gShellDebug1HiiHandle, Address); if (Size == 1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF2), gShellDebug1HiiHandle, (UINTN)Buffer); } else if (Size == 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF4), gShellDebug1HiiHandle, (UINTN)Buffer); } else if (Size == 4) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF8), gShellDebug1HiiHandle, (UINTN)Buffer); } else if (Size == 8) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_BUF16), gShellDebug1HiiHandle, Buffer); } ShellPrintEx(-1, -1, L" > "); // // wait user input to modify // if (InputStr != NULL) { FreePool(InputStr); InputStr = NULL; } ShellPromptForResponse(ShellPromptResponseTypeFreeform, NULL, (VOID**)&InputStr); // // skip space characters // for (Index = 0; InputStr != NULL && InputStr[Index] == ' '; Index++); // // parse input string // if (InputStr != NULL && (InputStr[Index] == '.' || InputStr[Index] == 'q' || InputStr[Index] == 'Q')) { Complete = TRUE; } else if (InputStr == NULL || InputStr[Index] == CHAR_NULL) { // // Continue to next address // } else if (GetHex (InputStr + Index, &Buffer) && Buffer <= MaxNum[Width]) { if (AccessType == EFIMemoryMappedIo) { IoDev->Mem.Write (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiIo) { IoDev->Io.Write (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiPciConfig) { IoDev->Pci.Write (IoDev, Width, Address, 1, &Buffer); } else if (AccessType == EfiPciEConfig) { IoDev->Pci.Write (IoDev, Width, PciEAddress, 1, &Buffer); } else { WriteMem (Width, Address, 1, &Buffer); } } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MM_ERROR), gShellDebug1HiiHandle); continue; // PrintToken (STRING_TOKEN (STR_IOMOD_ERROR), HiiHandle); } Address += Size; if (AccessType == EfiPciEConfig) { GetPciEAddressFromInputAddress (Address, &PciEAddress); } ShellPrintEx(-1, -1, L"\r\n"); // Print (L"\n"); } while (!Complete); } ASSERT(ShellStatus == SHELL_SUCCESS); Done: if (InputStr != NULL) { FreePool(InputStr); } if (HandleBuffer != NULL) { FreePool (HandleBuffer); } if (Package != NULL) { ShellCommandLineFreeVarList (Package); } return ShellStatus; }
/** Function for 'cp' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunCp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINTN ParamCount; UINTN LoopCounter; EFI_SHELL_FILE_INFO *FileList; BOOLEAN SilentMode; BOOLEAN RecursiveMode; CONST CHAR16 *Cwd; ProblemParam = NULL; ShellStatus = SHELL_SUCCESS; ParamCount = 0; FileList = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } // // Initialize SilentMode and RecursiveMode // if (gEfiShellProtocol->BatchIsActive()) { SilentMode = TRUE; } else { SilentMode = ShellCommandLineGetFlag(Package, L"-q"); } RecursiveMode = ShellCommandLineGetFlag(Package, L"-r"); switch (ParamCount = ShellCommandLineGetCount(Package)) { case 0: case 1: // // we have insufficient parameters // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; break; case 2: // // must have valid CWD for single parameter... // Cwd = ShellGetCurrentDir(NULL); if (Cwd == NULL){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1)); ShellStatus = SHELL_NOT_FOUND; } else { ShellStatus = ProcessValidateAndCopyFiles(FileList, Cwd, SilentMode, RecursiveMode); } } break; default: // // Make a big list of all the files... // for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) { if (ShellGetExecutionBreakFlag()) { break; } Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, LoopCounter)); ShellStatus = SHELL_NOT_FOUND; } } if (ShellStatus != SHELL_SUCCESS) { Status = ShellCloseFileMetaArg(&FileList); } else { // // now copy them all... // if (FileList != NULL && !IsListEmpty(&FileList->Link)) { ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode); Status = ShellCloseFileMetaArg(&FileList); if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT); ShellStatus = SHELL_ACCESS_DENIED; } } } break; } // switch on parameter count if (FileList != NULL) { ShellCloseFileMetaArg(&FileList); } // // free the command line package // ShellCommandLineFreeVarList (Package); } if (ShellGetExecutionBreakFlag()) { return (SHELL_ABORTED); } return (ShellStatus); }