INTN EFIAPI ShellAppMain ( IN UINTN Argc, IN CHAR16 **Argv ) { EFI_STATUS Status; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize ( ); if ( !EFI_ERROR ( Status )) { // // Run the application // Status = GpioEg20tMain ( Argc, Argv ); } // // Return the command status // return (INTN)Status; }
/** Function for 'stall' 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 ShellCommandRunStall ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINT64 Intermediate; 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 (EmptyParamList, &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 { if (ShellCommandLineGetRawValue(Package, 2) != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = ShellConvertStringToUint64(ShellCommandLineGetRawValue(Package, 1), &Intermediate, FALSE, FALSE); if (EFI_ERROR(Status) || ((UINT64)(UINTN)(Intermediate)) != Intermediate) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel1HiiHandle, ShellCommandLineGetRawValue(Package, 1)); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = gBS->Stall((UINTN)Intermediate); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_STALL_FAILED), gShellLevel1HiiHandle, Status); ShellStatus = SHELL_DEVICE_ERROR; } } } ShellCommandLineFreeVarList (Package); } return (ShellStatus); }
/** This is the shell command "dumpfdt" handler function. This function handles the command when it is invoked in the shell. @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL. @param[in] SystemTable The pointer to the UEFI system table. @param[in] ShellParameters The parameters associated with the command. @param[in] Shell The instance of the shell protocol used in the context of processing this command. @return SHELL_SUCCESS The operation was successful. @return SHELL_ABORTED Operation aborted due to internal error. @return SHELL_NOT_FOUND Failed to locate the Device Tree into the EFI Configuration Table @return SHELL_OUT_OF_RESOURCES A memory allocation failed. **/ SHELL_STATUS EFIAPI ShellDynCmdDumpFdtHandler ( IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, IN EFI_SYSTEM_TABLE *SystemTable, IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, IN EFI_SHELL_PROTOCOL *Shell ) { SHELL_STATUS ShellStatus; EFI_STATUS Status; VOID *FdtBlob; ShellStatus = SHELL_SUCCESS; // // Install the Shell and Shell Parameters Protocols on the driver // image. This is necessary for the initialisation of the Shell // Library to succeed in the next step. // Status = gBS->InstallMultipleProtocolInterfaces ( &gImageHandle, &gEfiShellProtocolGuid, Shell, &gEfiShellParametersProtocolGuid, ShellParameters, NULL ); if (EFI_ERROR (Status)) { return SHELL_ABORTED; } // // Initialise the Shell Library as we are going to use it. // Assert that the return code is EFI_SUCCESS as it should. // To anticipate any change is the codes returned by // ShellInitialize(), leave in case of error. // Status = ShellInitialize (); if (EFI_ERROR (Status)) { ASSERT_EFI_ERROR (Status); return SHELL_ABORTED; } Status = EfiGetSystemConfigurationTable (&gFdtTableGuid, &FdtBlob); if (EFI_ERROR (Status)) { Print (L"ERROR: Did not find the Fdt Blob.\n"); return EfiCodeToShellCode (Status); } DumpFdt (FdtBlob); gBS->UninstallMultipleProtocolInterfaces ( gImageHandle, &gEfiShellProtocolGuid, Shell, &gEfiShellParametersProtocolGuid, ShellParameters, NULL ); return ShellStatus; }
/** 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); }
/** 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 'for' 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 ShellCommandRunFor ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; SHELL_STATUS ShellStatus; SCRIPT_FILE *CurrentScriptFile; CHAR16 *ArgSet; CHAR16 *ArgSetWalker; UINTN ArgSize; UINTN LoopVar; SHELL_FOR_INFO *Info; CHAR16 *TempString; CHAR16 *TempSpot; BOOLEAN FirstPass; EFI_SHELL_FILE_INFO *Node; EFI_SHELL_FILE_INFO *FileList; UINTN NewSize; ArgSet = NULL; ArgSize = 0; ShellStatus = SHELL_SUCCESS; ArgSetWalker = NULL; TempString = NULL; FirstPass = 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 (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"For"); return (SHELL_UNSUPPORTED); } if (gEfiShellParametersProtocol->Argc < 4) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle); return (SHELL_INVALID_PARAMETER); } CurrentScriptFile = ShellCommandGetCurrentScriptFile(); ASSERT(CurrentScriptFile != NULL); if (CurrentScriptFile->CurrentCommand->Data == NULL) { FirstPass = TRUE; // // Make sure that an End exists. // if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", CurrentScriptFile->CurrentCommand!=NULL ?CurrentScriptFile->CurrentCommand->Line:0); return (SHELL_DEVICE_ERROR); } // // Process the line. // if (gEfiShellParametersProtocol->Argv[1][0] != L'%' || gEfiShellParametersProtocol->Argv[1][2] != CHAR_NULL ||!((gEfiShellParametersProtocol->Argv[1][1] >= L'a' && gEfiShellParametersProtocol->Argv[1][1] <= L'z') ||(gEfiShellParametersProtocol->Argv[1][1] >= L'A' && gEfiShellParametersProtocol->Argv[1][1] <= L'Z')) ) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[1]); return (SHELL_INVALID_PARAMETER); } if (gUnicodeCollation->StriColl( gUnicodeCollation, L"in", gEfiShellParametersProtocol->Argv[2]) == 0) { for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) { ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL)); if (StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"[") != NULL ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"]") != NULL) { FileList = NULL; Status = ShellOpenFileMetaArg ((CHAR16*)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList); if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) { ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0); ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0); ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0); } else { for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link) ; !IsNull(&FileList->Link, &Node->Link) ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link) ){ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0); ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Node->FullName, 0); ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0); } ShellCloseFileMetaArg(&FileList); } } else { ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0); ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0); ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0); } } if (ArgSet == NULL) { ShellStatus = SHELL_OUT_OF_RESOURCES; } else { // // set up for an 'in' for loop // NewSize = StrSize(ArgSet); NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]); Info = AllocateZeroPool(NewSize); ASSERT(Info != NULL); Info->Signature = SHELL_FOR_INFO_SIGNATURE; CopyMem(Info->Set, ArgSet, StrSize(ArgSet)); NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]); CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize); Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]); Info->CurrentValue = (CHAR16*)Info->Set; Info->Step = 0; Info->Current = 0; Info->End = 0; if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) { Info->RemoveSubstAlias = FALSE; } else { Info->RemoveSubstAlias = TRUE; } CurrentScriptFile->CurrentCommand->Data = Info; } } else if (gUnicodeCollation->StriColl( gUnicodeCollation, L"run", gEfiShellParametersProtocol->Argv[2]) == 0) { for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) { ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL)); if (ArgSet == NULL) { // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0); } else { ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0); } ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0); // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0); } if (ArgSet == NULL) { ShellStatus = SHELL_OUT_OF_RESOURCES; } else { // // set up for a 'run' for loop // Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1])); ASSERT(Info != NULL); Info->Signature = SHELL_FOR_INFO_SIGNATURE; CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1])); Info->ReplacementName = Info->Set; Info->CurrentValue = NULL; ArgSetWalker = ArgSet; if (ArgSetWalker[0] != L'(') { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_INVALID_PARAMETER; } else { TempSpot = StrStr(ArgSetWalker, L")"); if (TempSpot != NULL) { TempString = TempSpot+1; if (*(TempString) != CHAR_NULL) { while(TempString != NULL && *TempString == L' ') { TempString++; } if (StrLen(TempString) > 0) { TempSpot = NULL; } } } if (TempSpot == NULL) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_INVALID_PARAMETER; } else { *TempSpot = CHAR_NULL; ArgSetWalker++; while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') { ArgSetWalker++; } if (!ShellIsValidForNumber(ArgSetWalker)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (ArgSetWalker[0] == L'-') { Info->Current = 0 - (INTN)ReturnUintn(ArgSetWalker+1); } else { Info->Current = (INTN)ReturnUintn(ArgSetWalker); } ArgSetWalker = StrStr(ArgSetWalker, L" "); while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') { ArgSetWalker++; } if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){ ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (ArgSetWalker[0] == L'-') { Info->End = 0 - (INTN)ReturnUintn(ArgSetWalker+1); } else { Info->End = (INTN)ReturnUintn(ArgSetWalker); } if (Info->Current < Info->End) { Info->Step = 1; } else { Info->Step = -1; } ArgSetWalker = StrStr(ArgSetWalker, L" "); while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') { ArgSetWalker++; } if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) { if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){ ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (*ArgSetWalker == L')') { ASSERT(Info->Step == 1 || Info->Step == -1); } else { if (ArgSetWalker[0] == L'-') { Info->Step = 0 - (INTN)ReturnUintn(ArgSetWalker+1); } else { Info->Step = (INTN)ReturnUintn(ArgSetWalker); } if (StrStr(ArgSetWalker, L" ") != NULL) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_INVALID_PARAMETER; } } } } } } } } if (ShellStatus == SHELL_SUCCESS) { if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) { Info->RemoveSubstAlias = FALSE; } else { Info->RemoveSubstAlias = TRUE; } } if (CurrentScriptFile->CurrentCommand != NULL) { CurrentScriptFile->CurrentCommand->Data = Info; } } } else { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_INVALID_PARAMETER; } } else { // // These need to be NULL since they are used to determine if this is the first pass later on... // ASSERT(ArgSetWalker == NULL); ASSERT(ArgSet == NULL); } if (CurrentScriptFile != NULL && CurrentScriptFile->CurrentCommand != NULL) { Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data; if (CurrentScriptFile->CurrentCommand->Reset) { Info->CurrentValue = (CHAR16*)Info->Set; FirstPass = TRUE; CurrentScriptFile->CurrentCommand->Reset = FALSE; } } else { ShellStatus = SHELL_UNSUPPORTED; Info = NULL; } if (ShellStatus == SHELL_SUCCESS) { ASSERT(Info != NULL); if (Info->Step != 0) { // // only advance if not the first pass // if (!FirstPass) { // // sequence version of for loop... // Info->Current += Info->Step; } TempString = AllocateZeroPool(50*sizeof(CHAR16)); UnicodeSPrint(TempString, 50*sizeof(CHAR16), L"%d", Info->Current); InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList); FreePool(TempString); if ((Info->Step > 0 && Info->Current > Info->End) || (Info->Step < 0 && Info->Current < Info->End)) { CurrentScriptFile->CurrentCommand->Data = NULL; // // find the matching endfor (we're done with the loop) // if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_DEVICE_ERROR; } if (Info->RemoveSubstAlias) { // // remove item from list // InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList); } FreePool(Info); } } else { // // Must be in 'in' version of for loop... // ASSERT(Info->Set != NULL); if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) { if (Info->CurrentValue[0] == L' ') { Info->CurrentValue++; } if (Info->CurrentValue[0] == L'\"') { Info->CurrentValue++; } // // do the next one of the set // ASSERT(TempString == NULL); TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0); if (TempString == NULL) { ShellStatus = SHELL_OUT_OF_RESOURCES; } else { TempSpot = StrStr(TempString, L"\" \""); if (TempSpot != NULL) { *TempSpot = CHAR_NULL; } while (TempString[StrLen(TempString)-1] == L'\"') { TempString[StrLen(TempString)-1] = CHAR_NULL; } InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList); Info->CurrentValue += StrLen(TempString); if (Info->CurrentValue[0] == L'\"') { Info->CurrentValue++; } while (Info->CurrentValue[0] == L' ') { Info->CurrentValue++; } if (Info->CurrentValue[0] == L'\"') { Info->CurrentValue++; } FreePool(TempString); } } else { CurrentScriptFile->CurrentCommand->Data = NULL; // // find the matching endfor (we're done with the loop) // if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"EndFor", L"For", CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_DEVICE_ERROR; } if (Info->RemoveSubstAlias) { // // remove item from list // InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList); } FreePool(Info); } } } if (ArgSet != NULL) { FreePool(ArgSet); } 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); }
/** 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 '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 '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); }
/** 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 '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 '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 'goto' 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 ShellCommandRunGoto ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CHAR16 *CompareString; UINTN Size; SCRIPT_FILE *CurrentScriptFile; ShellStatus = SHELL_SUCCESS; CompareString = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); if (!gEfiShellProtocol->BatchIsActive()) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto"); return (SHELL_UNSUPPORTED); } // // 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), gShellLevel1HiiHandle, L"goto", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetRawValue(Package, 2) != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"goto"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"goto"); ShellStatus = SHELL_INVALID_PARAMETER; } else { Size = 0; ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL)); CompareString = StrnCatGrow(&CompareString, &Size, L":", 0); CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0); // // Check forwards and then backwards for a label... // if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) { CurrentScriptFile = ShellCommandGetCurrentScriptFile(); ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, CompareString, L"Goto", CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_NOT_FOUND; } FreePool(CompareString); } ShellCommandLineFreeVarList (Package); } 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); }
/** 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); }
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 '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 'tftp' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). @return SHELL_SUCCESS The 'tftp' command completed successfully. @return SHELL_ABORTED The Shell Library initialization failed. @return SHELL_INVALID_PARAMETER At least one of the command's arguments is not valid. @return SHELL_OUT_OF_RESOURCES A memory allocation failed. @return SHELL_NOT_FOUND Network Interface Card not found or server error or file error. **/ SHELL_STATUS EFIAPI ShellCommandRunTftp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { SHELL_STATUS ShellStatus; EFI_STATUS Status; LIST_ENTRY *CheckPackage; CHAR16 *ProblemParam; UINTN ParamCount; CONST CHAR16 *UserNicName; BOOLEAN NicFound; CONST CHAR16 *ValueStr; CONST CHAR16 *RemoteFilePath; CHAR8 *AsciiRemoteFilePath; CONST CHAR16 *Walker; CONST CHAR16 *LocalFilePath; EFI_MTFTP4_CONFIG_DATA Mtftp4ConfigData; EFI_HANDLE *Handles; UINTN HandleCount; UINTN NicNumber; CHAR16 NicName[IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH]; EFI_HANDLE ControllerHandle; EFI_HANDLE Mtftp4ChildHandle; EFI_MTFTP4_PROTOCOL *Mtftp4; UINTN FileSize; VOID *Data; SHELL_FILE_HANDLE FileHandle; ShellStatus = SHELL_INVALID_PARAMETER; ProblemParam = NULL; NicFound = FALSE; AsciiRemoteFilePath = NULL; Handles = NULL; FileSize = 0; // // Initialize the Shell library (we must be in non-auto-init...) // Status = ShellInitialize (); if (EFI_ERROR (Status)) { ASSERT_EFI_ERROR (Status); return SHELL_ABORTED; } // // Parse the command line. // Status = ShellCommandLineParse (ParamList, &CheckPackage, &ProblemParam, TRUE); if (EFI_ERROR (Status)) { if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL) ) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellTftpHiiHandle, L"tftp", ProblemParam ); FreePool (ProblemParam); } else { ASSERT (FALSE); } goto Error; } // // Check the number of parameters // ParamCount = ShellCommandLineGetCount (CheckPackage); if (ParamCount > 4) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellTftpHiiHandle, L"tftp" ); goto Error; } if (ParamCount < 3) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellTftpHiiHandle, L"tftp" ); goto Error; } Mtftp4ConfigData = DefaultMtftp4ConfigData; // // Check the host IPv4 address // ValueStr = ShellCommandLineGetRawValue (CheckPackage, 1); Status = NetLibStrToIp4 (ValueStr, &Mtftp4ConfigData.ServerIp); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellTftpHiiHandle, L"tftp", ValueStr ); goto Error; } RemoteFilePath = ShellCommandLineGetRawValue (CheckPackage, 2); AsciiRemoteFilePath = AllocatePool ( (StrLen (RemoteFilePath) + 1) * sizeof (CHAR8) ); if (AsciiRemoteFilePath == NULL) { ShellStatus = SHELL_OUT_OF_RESOURCES; goto Error; } UnicodeStrToAsciiStr (RemoteFilePath, AsciiRemoteFilePath); if (ParamCount == 4) { LocalFilePath = ShellCommandLineGetRawValue (CheckPackage, 3); } else { Walker = RemoteFilePath + StrLen (RemoteFilePath); while ((--Walker) >= RemoteFilePath) { if ((*Walker == L'\\') || (*Walker == L'/' ) ) { break; } } LocalFilePath = Walker + 1; } // // Get the name of the Network Interface Card to be used if any. // UserNicName = ShellCommandLineGetValue (CheckPackage, L"-i"); ValueStr = ShellCommandLineGetValue (CheckPackage, L"-l"); if (ValueStr != NULL) { if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.LocalPort)) { goto Error; } } ValueStr = ShellCommandLineGetValue (CheckPackage, L"-r"); if (ValueStr != NULL) { if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.InitialServerPort)) { goto Error; } } ValueStr = ShellCommandLineGetValue (CheckPackage, L"-c"); if (ValueStr != NULL) { if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.TryCount)) { goto Error; } } ValueStr = ShellCommandLineGetValue (CheckPackage, L"-t"); if (ValueStr != NULL) { if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.TimeoutValue)) { goto Error; } if (Mtftp4ConfigData.TimeoutValue == 0) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellTftpHiiHandle, L"tftp", ValueStr ); goto Error; } } // // Locate all MTFTP4 Service Binding protocols // ShellStatus = SHELL_NOT_FOUND; Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiManagedNetworkServiceBindingProtocolGuid, NULL, &HandleCount, &Handles ); if (EFI_ERROR (Status) || (HandleCount == 0)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NO_NIC), gShellTftpHiiHandle ); goto Error; } for (NicNumber = 0; (NicNumber < HandleCount) && (ShellStatus != SHELL_SUCCESS); NicNumber++) { ControllerHandle = Handles[NicNumber]; Data = NULL; Status = GetNicName (ControllerHandle, NicNumber, NicName); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NAME), gShellTftpHiiHandle, NicNumber, Status ); continue; } if (UserNicName != NULL) { if (StrCmp (NicName, UserNicName) != 0) { continue; } NicFound = TRUE; } Status = CreateServiceChildAndOpenProtocol ( ControllerHandle, &gEfiMtftp4ServiceBindingProtocolGuid, &gEfiMtftp4ProtocolGuid, &Mtftp4ChildHandle, (VOID**)&Mtftp4 ); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_OPEN_PROTOCOL), gShellTftpHiiHandle, NicName, Status ); continue; } Status = Mtftp4->Configure (Mtftp4, &Mtftp4ConfigData); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_CONFIGURE), gShellTftpHiiHandle, NicName, Status ); goto NextHandle; } Status = GetFileSize (Mtftp4, AsciiRemoteFilePath, &FileSize); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_FILE_SIZE), gShellTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, &Data); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD), gShellTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } if (!EFI_ERROR (ShellFileExists (LocalFilePath))) { ShellDeleteFileByName (LocalFilePath); } Status = ShellOpenFileByName ( LocalFilePath, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0 ); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellTftpHiiHandle, L"tftp", LocalFilePath ); goto NextHandle; } Status = ShellWriteFile (FileHandle, &FileSize, Data); if (!EFI_ERROR (Status)) { ShellStatus = SHELL_SUCCESS; } else { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_WRITE), gShellTftpHiiHandle, LocalFilePath, Status ); } ShellCloseFile (&FileHandle); NextHandle: if (Data != NULL) { gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Data, EFI_SIZE_TO_PAGES (FileSize)); } CloseProtocolAndDestroyServiceChild ( ControllerHandle, &gEfiMtftp4ServiceBindingProtocolGuid, &gEfiMtftp4ProtocolGuid, Mtftp4ChildHandle ); } if ((UserNicName != NULL) && (!NicFound)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NOT_FOUND), gShellTftpHiiHandle, UserNicName ); } Error: ShellCommandLineFreeVarList (CheckPackage); if (AsciiRemoteFilePath != NULL) { FreePool (AsciiRemoteFilePath); } if (Handles != NULL) { FreePool (Handles); } return ShellStatus; }
/** Function for 'openinfo' 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 ShellCommandRunOpenInfo ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; EFI_HANDLE TheHandle; CONST CHAR16 *Param1; UINT64 Intermediate; 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 (EmptyParamList, &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"openinfo", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) > 2){ // // error for too many parameters // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"openinfo"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) == 0) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"openinfo"); ShellStatus = SHELL_INVALID_PARAMETER; } else { Param1 = ShellCommandLineGetRawValue(Package, 1); Status = ShellConvertStringToUint64(Param1, &Intermediate, TRUE, FALSE); if (EFI_ERROR(Status) || Param1 == NULL || ConvertHandleIndexToHandle((UINTN)Intermediate) == NULL){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1); ShellStatus = SHELL_INVALID_PARAMETER; } else { TheHandle = ConvertHandleIndexToHandle((UINTN)Intermediate); ASSERT(TheHandle != NULL); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_OPENINFO_HEADER_LINE), gShellDriver1HiiHandle, (UINTN)Intermediate, TheHandle); Status = TraverseHandleDatabase (TheHandle); if (!EFI_ERROR(Status)) { } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"openinfo", Param1); ShellStatus = SHELL_NOT_FOUND; } } } } return (ShellStatus); }
/** Function for 'dblk' 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 ShellCommandRunDblk ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *BlockName; CONST CHAR16 *LbaString; CONST CHAR16 *BlockCountString; UINT64 Lba; UINT64 BlockCount; EFI_DEVICE_PATH_PROTOCOL *DevPath; 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) > 4) { 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 { // // Parse the params // BlockName = ShellCommandLineGetRawValue(Package, 1); LbaString = ShellCommandLineGetRawValue(Package, 2); BlockCountString = ShellCommandLineGetRawValue(Package, 3); if (LbaString == NULL) { Lba = 0; } else { if (!ShellIsHexOrDecimalNumber(LbaString, TRUE, FALSE)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, LbaString); ShellStatus = SHELL_INVALID_PARAMETER; } ShellConvertStringToUint64(LbaString, &Lba, TRUE, FALSE); } if (BlockCountString == NULL) { BlockCount = 1; } else { if (!ShellIsHexOrDecimalNumber(BlockCountString, TRUE, FALSE)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, BlockCountString); ShellStatus = SHELL_INVALID_PARAMETER; } ShellConvertStringToUint64(BlockCountString, &BlockCount, TRUE, FALSE); if (BlockCount > 0x10) { BlockCount = 0x10; } else if (BlockCount == 0) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, BlockCountString); ShellStatus = SHELL_INVALID_PARAMETER; } } if (ShellStatus == SHELL_SUCCESS) { // // do the work if we have a valid block identifier // if (gEfiShellProtocol->GetDevicePathFromMap(BlockName) == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, BlockName); ShellStatus = SHELL_INVALID_PARAMETER; } else { DevPath = (EFI_DEVICE_PATH_PROTOCOL*)gEfiShellProtocol->GetDevicePathFromMap(BlockName); if (gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid, &DevPath, NULL) == EFI_NOT_FOUND) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MAP_PROTOCOL), gShellDebug1HiiHandle, BlockName, L"BlockIo"); ShellStatus = SHELL_INVALID_PARAMETER; } else { ShellStatus = DisplayTheBlocks(gEfiShellProtocol->GetDevicePathFromMap(BlockName), Lba, (UINT8)BlockCount); } } } } ShellCommandLineFreeVarList (Package); } return (ShellStatus); }
/** 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 '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 '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); }
INTN EFIAPI ShellAppMain ( IN UINTN Argc, IN CHAR16 **Argv ) { UINTN Attributes; UINTN ArgIndex; UINTN BufferLengthInBytes; BOOLEAN Delete; BOOLEAN DisplayAll; BOOLEAN DisplayHelp; EFI_GUID GuidBuffer; EFI_STATUS Status; EFI_GUID * VendorGuid; CHAR16 * VariableName; CHAR16 * VariableData; // // initialize the shell lib (we must be in non-auto-init...) // for ( ; ; ) { Status = ShellInitialize ( ); if ( EFI_ERROR ( Status )) { break; } // // Get the HII handle // GetHiiHandle ( ); if ( NULL == mHiiHandle ) { Status = EFI_NO_MAPPING; ASSERT ( NULL != mHiiHandle ); break; } // // Display help by default // DisplayHelp = TRUE; // // Get the command attributes // ArgIndex = 1; Attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS; Delete = FALSE; DisplayAll = FALSE; VendorGuid = &mVendorGuid; VariableName = NULL; VariableData = NULL; while ( ArgIndex < Argc ) { // // -all: Display all variables // if ( 0 == StrCmp ( L"-all", Argv [ ArgIndex ])) { ArgIndex += 1; DisplayAll = TRUE; continue; } // // -nv: Store in non-volatile storage // if ( 0 == StrCmp ( L"-nv", Argv [ ArgIndex ])) { ArgIndex += 1; Attributes |= EFI_VARIABLE_NON_VOLATILE; continue; } // // -rt: Runtime access // if ( 0 == StrCmp ( L"-rt", Argv [ ArgIndex ])) { ArgIndex += 1; Attributes |= EFI_VARIABLE_RUNTIME_ACCESS; continue; } // // -delete: Delete a variable // if ( 0 == StrCmp ( L"-delete", Argv [ ArgIndex ])) { Delete = TRUE; ArgIndex += 1; Attributes = 0; break; } // // No more qualifiers // if ( '-' == *Argv [ ArgIndex ]) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_UNSUPPORTED_QUALIFIER), mHiiHandle, Argv [ ArgIndex ]); Status = EFI_INVALID_PARAMETER; break; } break; } if ( !EFI_ERROR ( Status )) { // // Verify the name and value // VariableName = Argv [ ArgIndex ]; if ( Delete && ( 1 == ( Argc - ArgIndex ))) { DisplayHelp = FALSE; } else if (( !Delete ) && ( 2 == ( Argc - ArgIndex ))) { DisplayHelp = FALSE; VariableData = Argv [ ArgIndex + 1 ]; } else if ( 2 <= ( Argc - ArgIndex )) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TOO_MANY_PARAMETERS), mHiiHandle ); Status = EFI_INVALID_PARAMETER; } else { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TOO_FEW_PARAMETERS), mHiiHandle ); Status = EFI_INVALID_PARAMETER; } } if ( DisplayHelp ) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN(STR_GET_HELP_VAR), mHiiHandle ); } else if ( !EFI_ERROR ( Status )) { BufferLengthInBytes = 0; if ( NULL != VariableData ) { BufferLengthInBytes = ( StrLen ( VariableData ) + 1 ) << 1; } Status = gRT->SetVariable ( VariableName, VendorGuid, Attributes, BufferLengthInBytes, VariableData ); if ( EFI_ERROR ( Status )) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_SET_VARIABLE_FAILED), mHiiHandle, Status ); } else { // // Display the variables // VariableName = &mVariableNameBuffer [ 0 ]; mVariableNameBuffer [ 0 ] = 0; do { BufferLengthInBytes = sizeof ( mVariableNameBuffer ); Status = gRT->GetNextVariableName ( &BufferLengthInBytes, VariableName, &GuidBuffer ); if ( !EFI_ERROR ( Status )) { if ( DisplayAll || ( 0 == CompareMem ( &mVendorGuid, &GuidBuffer, sizeof ( GuidBuffer )))) { Print ( L"\r\n%08x-%04x-%04x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x (0x%08x): %s\r\n", GuidBuffer.Data1, GuidBuffer.Data2, GuidBuffer.Data3, GuidBuffer.Data4 [ 0 ], GuidBuffer.Data4 [ 1 ], GuidBuffer.Data4 [ 2 ], GuidBuffer.Data4 [ 3 ], GuidBuffer.Data4 [ 4 ], GuidBuffer.Data4 [ 5 ], GuidBuffer.Data4 [ 6 ], GuidBuffer.Data4 [ 7 ], Attributes, VariableName ); BufferLengthInBytes = sizeof ( mBuffer ); Status = gRT->GetVariable ( VariableName, &GuidBuffer, &Attributes, &BufferLengthInBytes, &mBuffer ); if ( !EFI_ERROR ( Status )) { AsciiDump ( NULL, mBuffer, BufferLengthInBytes ); } } } } while ( !EFI_ERROR ( Status )); } } break; } // // Return the command status // return Status; }
/** 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 'compress' 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 ShellCommandRunEfiCompress ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; SHELL_FILE_HANDLE InShellFileHandle; SHELL_FILE_HANDLE OutShellFileHandle; UINT64 OutSize; UINTN OutSize2; VOID *OutBuffer; UINT64 InSize; UINTN InSize2; VOID *InBuffer; CHAR16 *InFileName; CONST CHAR16 *OutFileName; CONST CHAR16 *TempParam; InFileName = NULL; OutFileName = NULL; OutSize = 0; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; OutBuffer = NULL; InShellFileHandle = NULL; OutShellFileHandle = NULL; InBuffer = 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 (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"eficompress", 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, L"eficompress"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) < 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"eficompress"); ShellStatus = SHELL_INVALID_PARAMETER; } else { TempParam = ShellCommandLineGetRawValue(Package, 1); ASSERT(TempParam != NULL); InFileName = ShellFindFilePath(TempParam); OutFileName = ShellCommandLineGetRawValue(Package, 2); if (InFileName == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"eficompress", TempParam); ShellStatus = SHELL_NOT_FOUND; } else { if (ShellIsDirectory(InFileName) == EFI_SUCCESS){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", InFileName); ShellStatus = SHELL_INVALID_PARAMETER; } if (ShellIsDirectory(OutFileName) == EFI_SUCCESS){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", OutFileName); ShellStatus = SHELL_INVALID_PARAMETER; } if (ShellStatus == SHELL_SUCCESS) { Status = ShellOpenFileByName(InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue(Package, 1)); ShellStatus = SHELL_NOT_FOUND; } Status = ShellOpenFileByName(OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue(Package, 2)); ShellStatus = SHELL_NOT_FOUND; } } if (ShellStatus == SHELL_SUCCESS) { Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize); ASSERT_EFI_ERROR(Status); InBuffer = AllocateZeroPool((UINTN)InSize); if (InBuffer == NULL) { Status = EFI_OUT_OF_RESOURCES; } else { InSize2 = (UINTN) InSize; Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer); InSize = InSize2; ASSERT_EFI_ERROR (Status); Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); if (Status == EFI_BUFFER_TOO_SMALL) { OutBuffer = AllocateZeroPool ((UINTN) OutSize); if (OutBuffer == NULL) { Status = EFI_OUT_OF_RESOURCES; } else { Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); } } } if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); } else { OutSize2 = (UINTN)OutSize; Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &OutSize2, OutBuffer); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"eficompress", OutFileName); ShellStatus = SHELL_DEVICE_ERROR; } } } } } ShellCommandLineFreeVarList (Package); } if (InShellFileHandle != NULL) { gEfiShellProtocol->CloseFile(InShellFileHandle); } if (OutShellFileHandle != NULL) { gEfiShellProtocol->CloseFile(OutShellFileHandle); } SHELL_FREE_NON_NULL(InFileName); SHELL_FREE_NON_NULL(InBuffer); SHELL_FREE_NON_NULL(OutBuffer); 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 '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 '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); }