/** Check and convert the UINT16 option values of the 'tftp' command @param[in] ValueStr Value as an Unicode encoded string @param[out] Value UINT16 value @return TRUE The value was returned. @return FALSE A parsing error occured. **/ STATIC BOOLEAN StringToUint16 ( IN CONST CHAR16 *ValueStr, OUT UINT16 *Value ) { UINTN Val; Val = ShellStrToUintn (ValueStr); if (Val > MAX_UINT16) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellTftpHiiHandle, L"tftp", ValueStr ); return FALSE; } *Value = (UINT16)Val; return TRUE; }
/** Verify that the TimeString is valid and if so set that as the current time. @param[in] TimeString The pointer to a string representation of the time. @param[in] Tz The value to set for TimeZone. @param[in] Daylight The value to set for Daylight. @retval SHELL_INVALID_PARAMETER TimeString was NULL. @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted. @retval SHELL_SUCCESS The operation was successful. **/ SHELL_STATUS EFIAPI CheckAndSetTime ( IN CONST CHAR16 *TimeString, IN CONST INT16 Tz, IN CONST UINT8 Daylight ) { EFI_TIME TheTime; EFI_STATUS Status; CHAR16 *TimeStringCopy; CHAR16 *Walker1; CHAR16 *Walker2; if (TimeString != NULL && !InternalIsTimeLikeString(TimeString, L':', 1, 2, FALSE)) { return (SHELL_INVALID_PARAMETER); } if (Daylight != 0xFF &&((Daylight & (EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT)) != Daylight)) { return (SHELL_INVALID_PARAMETER); } Status = gRT->GetTime(&TheTime, NULL); ASSERT_EFI_ERROR(Status); if (TimeString != NULL) { TimeStringCopy = NULL; TimeStringCopy = StrnCatGrow(&TimeStringCopy, NULL, TimeString, 0); Walker1 = TimeStringCopy; TheTime.Hour = 0xFF; TheTime.Minute = 0xFF; Walker2 = Walker1!=NULL?StrStr(Walker1, L":"):NULL; if (Walker2 != NULL && *Walker2 == L':') { *Walker2 = CHAR_NULL; } TheTime.Hour = (UINT8)ShellStrToUintn (Walker1); if (Walker2 != NULL) { Walker1 = Walker2 + 1; } Walker2 = Walker1!=NULL?StrStr(Walker1, L":"):NULL; if (Walker2 != NULL && *Walker2 == L':') { *Walker2 = CHAR_NULL; } if (Walker1 != NULL && Walker1[0] != CHAR_NULL) { TheTime.Minute = (UINT8)ShellStrToUintn (Walker1); if (Walker2 != NULL) { Walker1 = Walker2 + 1; } if (Walker1 != NULL && Walker1[0] != CHAR_NULL) { TheTime.Second = (UINT8)ShellStrToUintn (Walker1); } } SHELL_FREE_NON_NULL(TimeStringCopy); } if ((Tz >= -1440 && Tz <= 1440)||(Tz == 0x7FF)) { TheTime.TimeZone = Tz; } if (Daylight != 0xFF) { TheTime.Daylight = Daylight; } Status = gRT->SetTime(&TheTime); if (!EFI_ERROR(Status)){ return (SHELL_SUCCESS); } return (SHELL_INVALID_PARAMETER); }
/** Verify that the TimeZoneString is valid and if so set that as the current timezone. @param[in] TimeZoneString The pointer to a string representation of the timezone. @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL. @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted. @retval SHELL_SUCCESS The operation was successful. **/ SHELL_STATUS CheckAndSetTimeZone ( IN CONST CHAR16 *TimeZoneString ) { EFI_TIME TheTime; EFI_STATUS Status; CHAR16 *TimeZoneCopy; CHAR16 *Walker; CHAR16 *Walker2; UINTN LoopVar; if (TimeZoneString == NULL) { return (SHELL_INVALID_PARAMETER); } if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16 *)TimeZoneString, L"_local") == 0) { Status = gRT->GetTime (&TheTime, NULL); if (EFI_ERROR (Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status); return (SHELL_DEVICE_ERROR); } TheTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE; Status = gRT->SetTime (&TheTime); if (!EFI_ERROR(Status)){ return (SHELL_SUCCESS); } return (SHELL_INVALID_PARAMETER); } if (TimeZoneString != NULL && !InternalIsTimeLikeString(TimeZoneString, L':', 1, 1, TRUE)) { return (SHELL_INVALID_PARAMETER); } Status = gRT->GetTime(&TheTime, NULL); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"timezone", L"gRT->GetTime", Status); return (SHELL_DEVICE_ERROR); } TimeZoneCopy = NULL; TimeZoneCopy = StrnCatGrow(&TimeZoneCopy, NULL, TimeZoneString, 0); if (TimeZoneCopy == NULL) { return (SHELL_OUT_OF_RESOURCES); } Walker = TimeZoneCopy; Walker2 = StrStr(Walker, L":"); if (Walker2 != NULL && *Walker2 == L':') { *Walker2 = CHAR_NULL; } if (*Walker == L'-') { TheTime.TimeZone = (INT16)((ShellStrToUintn (++Walker)) * 60); } else { TheTime.TimeZone = (INT16)((INT16)(ShellStrToUintn (Walker)) * -60); } if (Walker2 != NULL) { Walker = Walker2 + 1; } if (Walker != NULL && Walker[0] != CHAR_NULL) { if (TheTime.TimeZone < 0) { TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)ShellStrToUintn (Walker)); } else { TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)ShellStrToUintn (Walker)); } } Status = EFI_INVALID_PARAMETER; for ( LoopVar = 0 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0]) ; LoopVar++ ){ if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) { Status = gRT->SetTime(&TheTime); break; } } FreePool(TimeZoneCopy); if (!EFI_ERROR(Status)){ return (SHELL_SUCCESS); } return (SHELL_INVALID_PARAMETER); }
/** Function for 'mode' 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 ShellCommandRunMode ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINTN NewCol; UINTN NewRow; UINTN Col; UINTN Row; CONST CHAR16 *Temp; BOOLEAN Done; INT32 LoopVar; 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 (EmptyParamList, &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) > 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) == 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) == 3) { Temp = ShellCommandLineGetRawValue(Package, 1); if (!ShellIsHexOrDecimalNumber(Temp, FALSE, FALSE)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp); ShellStatus = SHELL_INVALID_PARAMETER; } NewCol = ShellStrToUintn(Temp); Temp = ShellCommandLineGetRawValue(Package, 2); if (!ShellIsHexOrDecimalNumber(Temp, FALSE, FALSE)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, Temp); ShellStatus = SHELL_INVALID_PARAMETER; } NewRow = ShellStrToUintn(Temp); for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS ; LoopVar++) { Status = gST->ConOut->QueryMode(gST->ConOut, LoopVar, &Col, &Row); if (EFI_ERROR(Status)) { continue; } if (Col == NewCol && Row == NewRow) { Status = gST->ConOut->SetMode(gST->ConOut, LoopVar); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MODE_SET_FAIL), gShellDebug1HiiHandle, Status); ShellStatus = SHELL_DEVICE_ERROR; } else { // worked fine... Done = TRUE; } break; } } if (!Done) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MODE_NO_MATCH), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } } else if (ShellCommandLineGetCount(Package) == 1) { // // print out valid // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MODE_LIST_HEAD), gShellDebug1HiiHandle); for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS ; LoopVar++) { Status = gST->ConOut->QueryMode(gST->ConOut, LoopVar, &Col, &Row); if (EFI_ERROR(Status)) { continue; } ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MODE_LIST_ITEM), gShellDebug1HiiHandle, Col, Row, LoopVar == gST->ConOut->Mode->Mode?L'*':L' '); } } ShellCommandLineFreeVarList (Package); } return (ShellStatus); }
/** Process an if statement and determine if its is valid or not. @param[in, out] PassingState Opon entry, the current state. Upon exit, the new state. @param[in] StartParameterNumber The number of the first parameter of this statement. @param[in] EndParameterNumber The number of the final parameter of this statement. @param[in] OperatorToUse The type of termination operator. @param[in] CaseInsensitive TRUE for case insensitive, FALSE otherwise. @param[in] ForceStringCompare TRUE for all string based, FALSE otherwise. @retval EFI_INVALID_PARAMETER A parameter was invalid. @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS EFIAPI ProcessStatement ( IN OUT BOOLEAN *PassingState, IN UINTN StartParameterNumber, IN UINTN EndParameterNumber, IN CONST END_TAG_TYPE OperatorToUse, IN CONST BOOLEAN CaseInsensitive, IN CONST BOOLEAN ForceStringCompare ) { EFI_STATUS Status; BOOLEAN OperationResult; BOOLEAN NotPresent; CHAR16 *StatementWalker; BIN_OPERATOR_TYPE BinOp; CHAR16 *Compare1; CHAR16 *Compare2; CHAR16 HexString[20]; CHAR16 *TempSpot; ASSERT((END_TAG_TYPE)OperatorToUse != EndTagThen); Status = EFI_SUCCESS; BinOp = OperatorMax; OperationResult = FALSE; StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber]; if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"not")) { NotPresent = TRUE; StatementWalker = gEfiShellParametersProtocol->Argv[++StartParameterNumber]; } else { NotPresent = FALSE; } // // now check for 'boolfunc' operators // if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"isint")) { if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') { StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL; OperationResult = ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE); } else { Status = EFI_INVALID_PARAMETER; ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"isint"); } } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exists") || IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exist")) { if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') { StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL; // // is what remains a file in CWD??? // OperationResult = (BOOLEAN)(ShellFileExists(StatementWalker)==EFI_SUCCESS); } else if (StatementWalker[0] == CHAR_NULL && StartParameterNumber+1 == EndParameterNumber) { OperationResult = (BOOLEAN)(ShellFileExists(gEfiShellParametersProtocol->Argv[++StartParameterNumber])==EFI_SUCCESS); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"exist(s)"); Status = EFI_INVALID_PARAMETER; } } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"available")) { if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') { StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL; // // is what remains a file in the CWD or path??? // OperationResult = (BOOLEAN)(ShellIsFileInPath(StatementWalker)==EFI_SUCCESS); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"available"); Status = EFI_INVALID_PARAMETER; } } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"profile")) { if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') { // // Chop off that ')' // StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL; OperationResult = IsValidProfile(StatementWalker); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"profile"); Status = EFI_INVALID_PARAMETER; } } else if (StartParameterNumber+1 >= EndParameterNumber) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[StartParameterNumber]); Status = EFI_INVALID_PARAMETER; } else { // // must be 'item binop item' style // Compare1 = NULL; Compare2 = NULL; BinOp = OperatorMax; // // get the first item // StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber]; if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror")) { TempSpot = StrStr(StatementWalker, L")"); if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) { *TempSpot = CHAR_NULL; if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) { UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT); ASSERT(Compare1 == NULL); Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0); StatementWalker += StrLen(StatementWalker) + 1; } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror"); Status = EFI_INVALID_PARAMETER; } } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror"); Status = EFI_INVALID_PARAMETER; } } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror")) { TempSpot = StrStr(StatementWalker, L")"); if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) { *TempSpot = CHAR_NULL; if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) { UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>2)); ASSERT(Compare1 == NULL); Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0); StatementWalker += StrLen(StatementWalker) + 1; } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror"); Status = EFI_INVALID_PARAMETER; } } else {
/** 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 '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; }
/** Verify that the DateString is valid and if so set that as the current date. @param[in] DateString The pointer to a string representation of the date. @retval SHELL_INVALID_PARAMETER DateString was NULL. @retval SHELL_INVALID_PARAMETER DateString was mis-formatted. @retval SHELL_SUCCESS The operation was successful. **/ SHELL_STATUS EFIAPI CheckAndSetDate ( IN CONST CHAR16 *DateString ) { EFI_TIME TheTime; EFI_STATUS Status; CHAR16 *DateStringCopy; CHAR16 *Walker; CHAR16 *Walker1; if (!InternalIsTimeLikeString(DateString, L'/', 2, 2, FALSE)) { return (SHELL_INVALID_PARAMETER); } Status = gRT->GetTime(&TheTime, NULL); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status); return (SHELL_DEVICE_ERROR); } DateStringCopy = NULL; DateStringCopy = StrnCatGrow(&DateStringCopy, NULL, DateString, 0); if (DateStringCopy == NULL) { return (SHELL_OUT_OF_RESOURCES); } Walker = DateStringCopy; TheTime.Month = 0xFF; TheTime.Day = 0xFF; TheTime.Year = 0xFFFF; Walker1 = StrStr(Walker, L"/"); if (Walker1 != NULL && *Walker1 == L'/') { *Walker1 = CHAR_NULL; } TheTime.Month = (UINT8)ShellStrToUintn (Walker); if (Walker1 != NULL) { Walker = Walker1 + 1; } Walker1 = Walker!=NULL?StrStr(Walker, L"/"):NULL; if (Walker1 != NULL && *Walker1 == L'/') { *Walker1 = CHAR_NULL; } if (Walker != NULL && Walker[0] != CHAR_NULL) { TheTime.Day = (UINT8)ShellStrToUintn (Walker); if (Walker1 != NULL) { Walker = Walker1 + 1; } Walker1 = Walker!=NULL?StrStr(Walker, L"/"):NULL; if (Walker1 != NULL && *Walker1 == L'/') { *Walker1 = CHAR_NULL; } if (Walker != NULL && Walker[0] != CHAR_NULL) { TheTime.Year = (UINT16)ShellStrToUintn (Walker); } } if (TheTime.Year < 100) { if (TheTime.Year >= 98) { TheTime.Year = (UINT16)(1900 + TheTime.Year); } else { TheTime.Year = (UINT16)(2000 + TheTime.Year); } } Status = gRT->SetTime(&TheTime); if (!EFI_ERROR(Status)){ return (SHELL_SUCCESS); } return (SHELL_INVALID_PARAMETER); }
/** Function for 'parse' 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 ShellCommandRunParse ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; CONST CHAR16 *FileName; CONST CHAR16 *TableName; CONST CHAR16 *ColumnString; SHELL_STATUS ShellStatus; UINTN ShellCommandInstance; UINTN TableNameInstance; 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 (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 { if (ShellCommandLineGetCount(Package) < 4) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) > 4) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { FileName = ShellCommandLineGetRawValue(Package, 1); TableName = ShellCommandLineGetRawValue(Package, 2); ColumnString = ShellCommandLineGetRawValue(Package, 3); if (ShellCommandLineGetValue(Package, L"-i") == NULL) { TableNameInstance = (UINTN)-1; } else { TableNameInstance = ShellStrToUintn(ShellCommandLineGetValue(Package, L"-i")); } if (ShellCommandLineGetValue(Package, L"-s") == NULL) { ShellCommandInstance = 1; } else { ShellCommandInstance = ShellStrToUintn(ShellCommandLineGetValue(Package, L"-s")); } ShellStatus = PerformParsing(FileName, TableName, ShellStrToUintn(ColumnString), TableNameInstance, ShellCommandInstance); } } // // free the command line package // ShellCommandLineFreeVarList (Package); return (ShellStatus); }
/** 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 '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 '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 'setsize' 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 ShellCommandRunSetSize ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Temp1; UINTN NewSize; UINTN LoopVar; SHELL_FILE_HANDLE FileHandle; 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 (EmptyParamList, &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"setsize", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) < 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_INVALID_PARAMETER; NewSize = 0; } else { Temp1 = ShellCommandLineGetRawValue(Package, 1); if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_INVALID_PARAMETER; NewSize = 0; } else { NewSize = ShellStrToUintn(Temp1); } } for (LoopVar = 2 ; LoopVar < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS ; LoopVar++) { Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); if (EFI_ERROR(Status)) { Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); } if (EFI_ERROR(Status) && LoopVar == 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue(Package, LoopVar)); ShellStatus = SHELL_INVALID_PARAMETER; break; } else { Status = FileHandleSetSize(FileHandle, NewSize); if (Status == EFI_VOLUME_FULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_VOLUME_FULL), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_VOLUME_FULL; } else if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue(Package, LoopVar)); ShellStatus = SHELL_INVALID_PARAMETER; } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_DONE), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, LoopVar)); } ShellCloseFile(&FileHandle); } } ShellCommandLineFreeVarList (Package); } 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 'sermode' 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 ShellCommandRunSerMode ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; SHELL_STATUS ShellStatus; UINTN Index; UINTN NoHandles; EFI_HANDLE *Handles; EFI_PARITY_TYPE Parity; EFI_STOP_BITS_TYPE StopBits; UINTN HandleIdx; UINTN BaudRate; UINTN DataBits; UINTN Value; EFI_SERIAL_IO_PROTOCOL *SerialIo; LIST_ENTRY *Package; CHAR16 *ProblemParam; CONST CHAR16 *Temp; UINT64 Intermediate; ShellStatus = SHELL_SUCCESS; HandleIdx = 0; Parity = DefaultParity; Handles = NULL; NoHandles = 0; Index = 0; Package = NULL; 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), gShellDebug1HiiHandle, L"sermode", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) < 6 && ShellCommandLineGetCount(Package) > 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"sermode"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) > 6) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"sermode"); ShellStatus = SHELL_INVALID_PARAMETER; } else { Temp = ShellCommandLineGetRawValue(Package, 1); if (Temp != NULL) { Status = ShellConvertStringToUint64(Temp, &Intermediate, TRUE, FALSE); HandleIdx = (UINTN)Intermediate; Temp = ShellCommandLineGetRawValue(Package, 2); if (Temp == NULL) { ShellStatus = DisplaySettings (HandleIdx, TRUE); goto Done; } } else { ShellStatus = DisplaySettings (0, FALSE); goto Done; } Temp = ShellCommandLineGetRawValue(Package, 2); if (Temp != NULL) { BaudRate = ShellStrToUintn(Temp); } else { ASSERT(FALSE); BaudRate = 0; } Temp = ShellCommandLineGetRawValue(Package, 3); if (Temp == NULL || StrLen(Temp)>1) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; } else { switch(Temp[0]){ case 'd': case 'D': Parity = DefaultParity; break; case 'n': case 'N': Parity = NoParity; break; case 'e': case 'E': Parity = EvenParity; break; case 'o': case 'O': Parity = OddParity; break; case 'm': case 'M': Parity = MarkParity; break; case 's': case 'S': Parity = SpaceParity; break; default: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } } Temp = ShellCommandLineGetRawValue(Package, 4); if (Temp != NULL) { DataBits = ShellStrToUintn(Temp); } else { // // make sure this is some number not in the list below. // DataBits = 0; } switch (DataBits) { case 4: case 7: case 8: break; default: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } Temp = ShellCommandLineGetRawValue(Package, 5); Value = ShellStrToUintn(Temp); switch (Value) { case 0: StopBits = DefaultStopBits; break; case 1: StopBits = OneStopBit; break; case 2: StopBits = TwoStopBits; break; case 15: StopBits = OneFiveStopBits; break; default: ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"sermode", Temp); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSerialIoProtocolGuid, NULL, &NoHandles, &Handles); if (EFI_ERROR (Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_NO_FOUND), gShellDebug1HiiHandle, L"sermode"); ShellStatus = SHELL_INVALID_PARAMETER; goto Done; } for (Index = 0; Index < NoHandles; Index++) { if (ConvertHandleIndexToHandle (HandleIdx) != Handles[Index]) { continue; } Status = gBS->HandleProtocol (Handles[Index], &gEfiSerialIoProtocolGuid, (VOID**)&SerialIo); if (!EFI_ERROR (Status)) { Status = SerialIo->SetAttributes ( SerialIo, (UINT64) BaudRate, SerialIo->Mode->ReceiveFifoDepth, SerialIo->Mode->Timeout, Parity, (UINT8) DataBits, StopBits ); if (EFI_ERROR (Status)) { if (Status == EFI_INVALID_PARAMETER) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_UNSUPPORTED), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex(Handles[Index])); ShellStatus = SHELL_UNSUPPORTED; } else if (Status == EFI_DEVICE_ERROR) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_DEV_ERROR), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex(Handles[Index])); ShellStatus = SHELL_ACCESS_DENIED; } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_FAIL), gShellDebug1HiiHandle, L"sermode", ConvertHandleToHandleIndex(Handles[Index])); ShellStatus = SHELL_ACCESS_DENIED; } } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_SET_HANDLE), gShellDebug1HiiHandle, ConvertHandleToHandleIndex(Handles[Index])); } break; } } } } if (ShellStatus == SHELL_SUCCESS && Index == NoHandles) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SERMODE_BAD_HANDLE), gShellDebug1HiiHandle, L"sermode", HandleIdx); ShellStatus = SHELL_INVALID_PARAMETER; } Done: if (Package != NULL) { ShellCommandLineFreeVarList (Package); } if (Handles != NULL) { FreePool (Handles); } return ShellStatus; }
/** Verify that the TimeZoneString is valid and if so set that as the current timezone. @param[in] TimeZoneString The pointer to a string representation of the timezone. @retval SHELL_INVALID_PARAMETER TimeZoneString was NULL. @retval SHELL_INVALID_PARAMETER TimeZoneString was mis-formatted. @retval SHELL_SUCCESS The operation was successful. **/ SHELL_STATUS EFIAPI CheckAndSetTimeZone ( IN CONST CHAR16 *TimeZoneString ) { EFI_TIME TheTime; EFI_STATUS Status; CHAR16 *TimeZoneCopy; CHAR16 *Walker; CHAR16 *Walker2; UINTN LoopVar; if (TimeZoneString == NULL) { return (SHELL_INVALID_PARAMETER); } if (TimeZoneString != NULL && !InternalIsTimeLikeString(TimeZoneString, L':', 1, 1, TRUE)) { return (SHELL_INVALID_PARAMETER); } Status = gRT->GetTime(&TheTime, NULL); if (EFI_ERROR(Status)) { return (SHELL_DEVICE_ERROR); } TimeZoneCopy = NULL; TimeZoneCopy = StrnCatGrow(&TimeZoneCopy, NULL, TimeZoneString, 0); if (TimeZoneCopy == NULL) { return (SHELL_OUT_OF_RESOURCES); } Walker = TimeZoneCopy; Walker2 = StrStr(Walker, L":"); if (Walker2 != NULL && *Walker2 == L':') { *Walker2 = CHAR_NULL; } if (*Walker == L'-') { TheTime.TimeZone = (INT16)((ShellStrToUintn (++Walker)) * 60); } else { TheTime.TimeZone = (INT16)((ShellStrToUintn (Walker)) * -60); } if (Walker2 != NULL) { Walker = Walker2 + 1; } if (Walker != NULL && Walker[0] != CHAR_NULL) { if (TheTime.TimeZone < 0) { TheTime.TimeZone = (INT16)(TheTime.TimeZone - (UINT8)ShellStrToUintn (Walker)); } else { TheTime.TimeZone = (INT16)(TheTime.TimeZone + (UINT8)ShellStrToUintn (Walker)); } } Status = EFI_INVALID_PARAMETER; for ( LoopVar = 0 ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0]) ; LoopVar++ ){ if (TheTime.TimeZone == TimeZoneList[LoopVar].TimeZone) { Status = gRT->SetTime(&TheTime); break; } } FreePool(TimeZoneCopy); if (!EFI_ERROR(Status)){ return (SHELL_SUCCESS); } return (SHELL_INVALID_PARAMETER); }
/** Verify that the TimeString is valid and if so set that as the current time. @param[in] TimeString The pointer to a string representation of the time. @param[in] Tz The value to set for TimeZone. @param[in] Daylight The value to set for Daylight. @retval SHELL_INVALID_PARAMETER TimeString was NULL. @retval SHELL_INVALID_PARAMETER TimeString was mis-formatted. @retval SHELL_SUCCESS The operation was successful. **/ SHELL_STATUS CheckAndSetTime ( IN CONST CHAR16 *TimeString, IN CONST INT16 Tz, IN CONST UINT8 Daylight ) { EFI_TIME TheTime; EFI_STATUS Status; CHAR16 *TimeStringCopy; CHAR16 *Walker1; CHAR16 *Walker2; if (TimeString != NULL && !InternalIsTimeLikeString(TimeString, L':', 1, 2, FALSE)) { return (SHELL_INVALID_PARAMETER); } if (Daylight != 0xFF &&((Daylight & (EFI_TIME_IN_DAYLIGHT|EFI_TIME_ADJUST_DAYLIGHT)) != Daylight)) { return (SHELL_INVALID_PARAMETER); } 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 (TimeString != NULL) { TimeStringCopy = NULL; TimeStringCopy = StrnCatGrow(&TimeStringCopy, NULL, TimeString, 0); Walker1 = TimeStringCopy; TheTime.Hour = 0xFF; TheTime.Minute = 0xFF; Walker2 = Walker1!=NULL?StrStr(Walker1, L":"):NULL; if (Walker2 != NULL && *Walker2 == L':') { *Walker2 = CHAR_NULL; } TheTime.Hour = (UINT8)ShellStrToUintn (Walker1); if (Walker2 != NULL) { Walker1 = Walker2 + 1; } Walker2 = Walker1!=NULL?StrStr(Walker1, L":"):NULL; if (Walker2 != NULL && *Walker2 == L':') { *Walker2 = CHAR_NULL; TheTime.Second = (UINT8)0; } else if (Walker2 == NULL) { TheTime.Second = (UINT8)0; } if (Walker1 != NULL && Walker1[0] != CHAR_NULL) { TheTime.Minute = (UINT8)ShellStrToUintn (Walker1); if (Walker2 != NULL) { Walker1 = Walker2 + 1; if (Walker1 != NULL && Walker1[0] != CHAR_NULL) { TheTime.Second = (UINT8)ShellStrToUintn (Walker1); } } } SHELL_FREE_NON_NULL(TimeStringCopy); } if (Tz >= -1440 && Tz <= 1440) { // // EFI_TIME TimeZone is stored to meet the following calculation (see UEFI Spec): // Localtime = UTC - TimeZone // This means the sign must be changed for the user provided Tz. // EX: User wants to set TimeZone to Pacific Standard Time, so runs // time -tz -480 # set to UTC-08:00 // To meet the calculation, the sign must be changed. // TheTime.TimeZone = -Tz; } else if (Tz == EFI_UNSPECIFIED_TIMEZONE) { TheTime.TimeZone = Tz; } if (Daylight != 0xFF) { TheTime.Daylight = Daylight; } Status = gRT->SetTime(&TheTime); if (!EFI_ERROR(Status)){ return (SHELL_SUCCESS); } return (SHELL_INVALID_PARAMETER); }
/** 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; }
/** Do a comparison between 2 things. @param[in] Compare1 The first item to compare. @param[in] Compare2 The second item to compare. @param[in] BinOp The type of comparison to perform. @param[in] CaseInsensitive TRUE to do non-case comparison, FALSE otherwise. @param[in] ForceStringCompare TRUE to force string comparison, FALSE otherwise. @return The result of the comparison. **/ BOOLEAN EFIAPI TestOperation ( IN CONST CHAR16 *Compare1, IN CONST CHAR16 *Compare2, IN CONST BIN_OPERATOR_TYPE BinOp, IN CONST BOOLEAN CaseInsensitive, IN CONST BOOLEAN ForceStringCompare ) { INTN Cmp1; INTN Cmp2; // // "Compare1 BinOp Compare2" // switch (BinOp) { case OperatorUnisgnedGreaterThan: case OperatorGreaterThan: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare // if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) > 0) || (StringCompare(&Compare1, &Compare2) > 0)) { return (TRUE); } } else { // // numeric compare // if (Compare1[0] == L'-') { Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { Cmp2 = (INTN)ShellStrToUintn(Compare2); } if (BinOp == OperatorGreaterThan) { if (Cmp1 > Cmp2) { return (TRUE); } } else { if ((UINTN)Cmp1 > (UINTN)Cmp2) { return (TRUE); } } } return (FALSE); break; case OperatorUnsignedLessThan: case OperatorLessThan: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare // if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) < 0) || (StringCompare(&Compare1, &Compare2) < 0)) { return (TRUE); } } else { // // numeric compare // if (Compare1[0] == L'-') { Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { Cmp2 = (INTN)ShellStrToUintn(Compare2); } if (BinOp == OperatorLessThan) { if (Cmp1 < Cmp2) { return (TRUE); } } else { if ((UINTN)Cmp1 < (UINTN)Cmp2) { return (TRUE); } } } return (FALSE); break; case OperatorEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare // if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) == 0) || (StringCompare(&Compare1, &Compare2) == 0)) { return (TRUE); } } else { // // numeric compare // if (Compare1[0] == L'-') { Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { Cmp2 = (INTN)ShellStrToUintn(Compare2); } if (Cmp1 == Cmp2) { return (TRUE); } } return (FALSE); break; case OperatorNotEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare // if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) != 0) || (StringCompare(&Compare1, &Compare2) != 0)) { return (TRUE); } } else { // // numeric compare // if (Compare1[0] == L'-') { Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { Cmp2 = (INTN)ShellStrToUintn(Compare2); } if (Cmp1 != Cmp2) { return (TRUE); } } return (FALSE); break; case OperatorUnsignedGreaterOrEqual: case OperatorGreatorOrEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare // if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) >= 0) || (StringCompare(&Compare1, &Compare2) >= 0)) { return (TRUE); } } else { // // numeric compare // if (Compare1[0] == L'-') { Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { Cmp2 = (INTN)ShellStrToUintn(Compare2); } if (BinOp == OperatorGreatorOrEqual) { if (Cmp1 >= Cmp2) { return (TRUE); } } else { if ((UINTN)Cmp1 >= (UINTN)Cmp2) { return (TRUE); } } } return (FALSE); break; case OperatorLessOrEqual: case OperatorUnsignedLessOrEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare // if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) <= 0) || (StringCompare(&Compare1, &Compare2) <= 0)) { return (TRUE); } } else { // // numeric compare // if (Compare1[0] == L'-') { Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { Cmp2 = (INTN)ShellStrToUintn(Compare2); } if (BinOp == OperatorLessOrEqual) { if (Cmp1 <= Cmp2) { return (TRUE); } } else { if ((UINTN)Cmp1 <= (UINTN)Cmp2) { return (TRUE); } } } return (FALSE); break; default: ASSERT(FALSE); return (FALSE); } }