/** DebuggerCommand - InstructionBranch. @param CommandArg The argument for this command @param DebuggerPrivate EBC Debugger private data structure @param ExceptionType Exception type. @param SystemContext EBC system context. @retval EFI_DEBUG_CONTINUE formal return value **/ EFI_DEBUG_STATUS DebuggerInstructionBranch ( IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext ) { UINTN Index; // // Check argument // if (CommandArg != NULL) { if (StriCmp (CommandArg, L"c") == 0) { // // Clear Trace // DebuggerPrivate->TraceEntryCount = 0; ZeroMem (DebuggerPrivate->TraceEntry, sizeof(DebuggerPrivate->TraceEntry)); EDBPrint (L"Instruction Trace is cleared\n"); } else { EDBPrint (L"Trace argument Invalid\n"); } return EFI_DEBUG_CONTINUE; } // // Check Trace Entry Count // if (DebuggerPrivate->TraceEntryCount == 0) { EDBPrint (L"No Instruction Trace\n"); return EFI_DEBUG_CONTINUE; } else if (DebuggerPrivate->TraceEntryCount > EFI_DEBUGGER_TRACE_MAX) { EDBPrint (L"Instruction Trace Crash, re-initialize!\n"); DebuggerPrivate->TraceEntryCount = 0; return EFI_DEBUG_CONTINUE; } // // Go through each Trace entry and print // EDBPrint (L"Instruction Trace (->Latest):\n"); EDBPrint (L" Source Addr Destination Addr Type\n"); EDBPrint (L" ================== ================== ========\n"); //EDBPrint (L" 0x00000000FFFFFFFF 0xFFFFFFFF00000000 (CALLEX)\n"); for (Index = 0; Index < DebuggerPrivate->TraceEntryCount; Index++) { EDBPrint ( L" 0x%016lx 0x%016lx %s\n", DebuggerPrivate->TraceEntry[Index].SourceAddress, DebuggerPrivate->TraceEntry[Index].DestAddress, EdbBranchTypeToStr (DebuggerPrivate->TraceEntry[Index].Type) ); } // // Done // return EFI_DEBUG_CONTINUE; }
VARIABLE_ID * SEnvFindVar ( IN EFI_LIST_ENTRY *Head, IN CHAR16 *Name ) /*++ Routine Description: Find the specified variable in the specified variable list Arguments: Head - The head of the variable list to find in Name - The name of the variable to find Returns: If not found, return NULL. Otherwise, return the pointer to the variable. --*/ { EFI_LIST_ENTRY *Link; VARIABLE_ID *Var; VARIABLE_ID *Found; Found = NULL; for (Link = Head->Flink; Link != Head; Link = Link->Flink) { Var = CR (Link, VARIABLE_ID, Link, VARIABLE_SIGNATURE); if (StriCmp (Var->Name, Name) == 0) { Found = Var; break; } } return Found; }
EFI_STATUS AddMenuItemCheckValue ( IN CHAR16 *ItemNameText, IN UINTN MaxValue, IN UINTN MinValue, IN UINTN DefaultValue, IN OUT EFI_MENU_PAGE *Page ) /*++ Routine Description: Add number range for a number edit menu item in menu page Arguments: ItemNameText - A name string of the menu item MaxValue - The maximum value of the menu item MinValue - The minimum value of the menu item DefaultValue - The default value of the menu item Page - A pointer to the menu page Returns: EFI_SUCCESS - Add Edit menu item successfully Other Value - Something failed --*/ { EFI_MENU_ITEM *MenuItem; if (ItemNameText == NULL || Page == NULL) { return EFI_INVALID_PARAMETER; } MenuItem = Page->Body.ItemList; // //Go through meun item list to search for the required menu item according to its name. // while(MenuItem != NULL) { if (StriCmp (MenuItem->ItemString.Text, ItemNameText) == 0) { // //Find a menu item matching the name, check its type // if ((MenuItem->ItemType & EFI_EDIT_SUB_TYPE_MASK) != EFI_ITEM_EDIT_NUMBER) { return EFI_INVALID_PARAMETER; } MenuItem->CheckValue = TRUE; MenuItem->MaxValue = MaxValue; MenuItem->MinValue = MinValue; MenuItem->DefaultValue = DefaultValue; break; } MenuItem = MenuItem->Next; } return EFI_SUCCESS; }
BOOLEAN _IsReserved ( IN CHAR16 *Name, IN CHAR16 *Cmd ) { UINTN Index; for (Index = 0; mSpecVarTable[Index].CmdName != NULL; Index++) { if (!StriCmp (Cmd, mSpecVarTable[Index].CmdName) && !StriCmp (Name, mSpecVarTable[Index].VarName)) { return TRUE; } } return FALSE; }
EFI_STATUS SEnvCheckForGotoTarget ( IN CHAR16 *Candidate, IN UINT64 GotoFilePos, IN UINT64 FilePosition, OUT UINTN *GotoTargetStatus ) /*++ Routine Description: Check to see if we have found the target label of a GOTO command. Arguments: Candidate String to be checked for goto target GotoFilePos File position of the goto statement FilePosition Current file position GotoTargetStatus The status of searching goto target Returns: EFI_SUCCESS The command finished sucessfully EFI_INVALID_PARAMETER Invalid parameter --*/ { if (!Candidate) { return EFI_INVALID_PARAMETER; } // // See if we found the label (strip the leading ':' off the candidate) // or if we have searched the whole file without finding it. // if (GotoFilePos == FilePosition) { *GotoTargetStatus = GOTO_TARGET_DOESNT_EXIST; return EFI_SUCCESS; } else if (Candidate[0] != ':') { *GotoTargetStatus = GOTO_TARGET_NOT_FOUND; return EFI_SUCCESS; } else if (StriCmp (&Candidate[1], TargetLabel) == 0) { *GotoTargetStatus = GOTO_TARGET_FOUND; return EFI_SUCCESS; } else { *GotoTargetStatus = GOTO_TARGET_NOT_FOUND; return EFI_SUCCESS; } }
EFIAPI SEnvGetEnv ( IN CHAR16 *Name ) /*++ Routine Description: Arguments: Name - The variable name Returns: --*/ { UINTN Index; CHAR16 *Str; EFI_STATUS Status; for (Index = 0; mSpecVarTable[Index].CmdName != NULL; Index++) { if (StriCmp (mSpecVarTable[Index].CmdName, L"set") == 0 && StriCmp (mSpecVarTable[Index].VarName, Name) == 0 && mSpecVarTable[Index].SpecGetFun != NULL ) { Status = mSpecVarTable[Index].SpecGetFun (&Str); if (EFI_ERROR (Status)) { return NULL; } return Str; } } return SEnvIGetStr (Name, &SEnvEnv); }
/** DebuggerCommand - Help. @param CommandArg - The argument for this command @param DebuggerPrivate - EBC Debugger private data structure @param ExceptionType - Interrupt type. @param SystemContext - EBC system context. @retval EFI_DEBUG_CONTINUE - formal return value **/ EFI_DEBUG_STATUS DebuggerHelp ( IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext ) { UINTN Index; // // if no argument, print all the command title // if (CommandArg == NULL) { for (Index = 0; DebuggerPrivate->DebuggerCommandSet[Index].CommandName != NULL; Index++) { EDBPrint (DebuggerPrivate->DebuggerCommandSet[Index].ClassName); if (StrCmp (DebuggerPrivate->DebuggerCommandSet[Index].CommandTitle, L"") != 0) { EDBPrint (L" "); EDBPrint (DebuggerPrivate->DebuggerCommandSet[Index].CommandTitle); } } return EFI_DEBUG_CONTINUE; } // // If there is argument, the argument should be command name. // Find the command and print the detail information. // for (Index = 0; DebuggerPrivate->DebuggerCommandSet[Index].CommandName != NULL; Index++) { if (StriCmp (CommandArg, DebuggerPrivate->DebuggerCommandSet[Index].CommandName) == 0) { EDBPrint (DebuggerPrivate->DebuggerCommandSet[Index].CommandHelp); EDBPrint (DebuggerPrivate->DebuggerCommandSet[Index].CommandSyntax); return EFI_DEBUG_CONTINUE; } } // // Command not found. // EDBPrint (L"No help info for this command\n"); // // Done // return EFI_DEBUG_CONTINUE; }
/* Validate file name to match the embedded release string */ EFI_STATUS loader_filename_parse(EFI_FILE_HANDLE f, const CHAR16 *release, UINTN release_len, INTN *boot_countp) { EFI_FILE_INFO *info; UINTN name_len; INTN boot_count = -1; info = LibFileInfo(f); if (!info) return EFI_LOAD_ERROR; name_len = StrLen(info->FileName); if (name_len < release_len + 4) return EFI_INVALID_PARAMETER; /* Require .efi extension. */ if (StriCmp(info->FileName + name_len - 4, L".efi") != 0) return EFI_INVALID_PARAMETER; /* Require the file name to start with the release name. */ if (StrniCmp(info->FileName, release, release_len) != 0) return EFI_INVALID_PARAMETER; /* Accept optional boot count extension. */ if (name_len != release_len + 4) { CHAR16 c; if (name_len != release_len + 6 + 4) return EFI_INVALID_PARAMETER; if (StrniCmp(info->FileName + release_len, L"-boot", 5) != 0) return EFI_INVALID_PARAMETER; c = info->FileName[release_len + 5]; if (c < '0' || c > '9') return EFI_INVALID_PARAMETER; boot_count = c - '0'; } if (boot_countp) *boot_countp = boot_count; return EFI_SUCCESS; }
/** Find the command according to name. @param CommandName - Command Name @param CommandArg - Command Argument @return Not NULL - The DebuggerCommand is found successfully @return NULL - not found **/ EFI_DEBUGGER_COMMAND MatchDebuggerCommand ( IN CHAR16 *CommandName, IN CHAR16 **CommandArg ) { UINTN Index; CHAR16 *Temp; // // Get Command Name // Temp = StrGetNewTokenLine (CommandName, L" "); CommandName = Temp; // // Get Command Argument // Temp = StrGetNextTokenLine (L" "); *CommandArg = Temp; if (CommandName == NULL) { return NULL; } // // Go through each command, check the CommandName // for (Index = 0; mDebuggerCommandSet[Index].CommandName != NULL; Index++) { if (StriCmp (CommandName, mDebuggerCommandSet[Index].CommandName) == 0) { // // Found // return mDebuggerCommandSet[Index].CommandFunc; } } // // Not found // return NULL; }
EFI_STATUS CheckGraphicalConsoleProtocols ( IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, IN EFI_INI_FILE_HANDLE IniFile ) { EFI_STATUS Status; UINT32 MaxLength; CHAR16 String[10]; BOOLEAN ValueA; BOOLEAN ValueB; VOID *Interface; EFI_TEST_ASSERTION AssertionType; // // Check the UGA_DRAW protocol // Status = gtBS->LocateProtocol ( &gEfiUgaDrawProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueA = TRUE; } else { ValueA = FALSE; } // // Check the UGA_IO protocol // Status = gtBS->LocateProtocol ( &gEfiUgaIoProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueB = TRUE; } else { ValueB = FALSE; } // // UEFI forum may want to drop UGA I/O protocol as a required implementation. // So here we skip the check to this protocol. // // // Need *one* or warning // AssertionType = NeedOneOrWarning (ValueA); // // For platform-specific elements, throw out a warning in default // if (AssertionType == EFI_TEST_ASSERTION_FAILED) { AssertionType = EFI_TEST_ASSERTION_WARNING; } // // If warning, check with INI file to decide they must exist or not // if ((AssertionType == EFI_TEST_ASSERTION_WARNING) && (IniFile != NULL_HANDLE )) { MaxLength = 10; Status = IniFile->GetString ( IniFile, SECTION_NAME_PLATFORM_SPECIFIC, L"GraphicalConsoleDevices", String, &MaxLength ); if (!EFI_ERROR (Status) && (StriCmp (String, L"yes") == 0)) { AssertionType = EFI_TEST_ASSERTION_FAILED; } } // // Record test result // StandardLib->RecordAssertion ( StandardLib, AssertionType, gEfiCompliantBbTestPlatformAssertionGuid002, L"EFI Compliant - Graphical console protocols must be implemented", L"%a:%d:UGA Draw - %s, UGA IO (not required) - %s", __FILE__, (UINTN)__LINE__, ValueA ? L"Yes" : L"No", ValueB ? L"Yes" : L"No" ); // // Done // return EFI_SUCCESS; }
EFI_STATUS MainMenuSaveSeqFunc ( IN EFI_MENU_PAGE *Page ) { EFI_STATUS Status; EFI_FILE_DIALOG_CONTEXT *DialogContext; CHAR16 *FileName; EFI_DIALOG_CONTEXT MsgDialogContext; CHAR16 *MsgDialogTitle; DialogContext = NULL; // //allocate a new efi file dialog context. // Status = BS->AllocatePool ( EfiBootServicesData, sizeof(EFI_FILE_DIALOG_CONTEXT), (VOID **)&DialogContext ); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } BS->SetMem (DialogContext, sizeof(EFI_FILE_DIALOG_CONTEXT), 0); DialogContext->DialogType = EFI_FILE_DIALOG_TYPE_SAVE_FILE; DialogContext->FileType = EFI_FILTER_FILE_TYPE_SEQ; // //get devicepath and filename through FileDialog // Status = DoFileDialog (DialogContext); if (EFI_ERROR (Status)) { MsgDialogTitle = StrDuplicate (L"Save Sequence Error!"); MsgDialogContext.Type = EFI_DIALOG_TYPE_MESSAGE; MenuPageRefresh (Page); DoDialog (MsgDialogTitle, &MsgDialogContext); } else if (DialogContext->DevicePath != NULL && DialogContext->FileName != NULL && DialogContext->FileName[0] != L'\0') { // //make up file name // if (StrLen (DialogContext->FileName) > 4 && StriCmp (DialogContext->FileName + StrLen (DialogContext->FileName) - 4, L".seq") == 0) { FileName = StrDuplicate (DialogContext->FileName); }else if ( StrLen (DialogContext->FileName) > 1 && StriCmp (DialogContext->FileName + StrLen (DialogContext->FileName) - 1, L".") == 0) { FileName = PoolPrint (L"%sseq", DialogContext->FileName); }else { FileName = PoolPrint (L"%s.seq", DialogContext->FileName); } if (FileName == NULL) { BS->FreePool (DialogContext->DevicePath); BS->FreePool (DialogContext->FileName); BS->FreePool (DialogContext); return EFI_DEVICE_ERROR; } Status = SaveTestSequence ( gFT->DevicePath, FileName, &gFT->TestCaseList ); if (EFI_ERROR (Status)) { MsgDialogTitle = StrDuplicate (L"Save sequence Error!"); } else { MsgDialogTitle = StrDuplicate (L"Save sequence Succeed!"); } MsgDialogContext.Type = EFI_DIALOG_TYPE_MESSAGE; MenuPageRefresh (Page); DoDialog (MsgDialogTitle, &MsgDialogContext); BS->FreePool (FileName); BS->FreePool (DialogContext->DevicePath); BS->FreePool (DialogContext->FileName); } else { if (DialogContext->FileName != NULL) { BS->FreePool (DialogContext->FileName); } if (DialogContext->DevicePath != NULL) { BS->FreePool (DialogContext->DevicePath); } } BS->FreePool (DialogContext); MenuPageRefresh (Page); return EFI_SUCCESS; }
VOID DisplayLog ( IN EFI_MENU_PAGE *Page ) { EFI_STATUS Status; EFI_FILE_DIALOG_CONTEXT *DialogContext; CHAR16 *FileName; EFI_DIALOG_CONTEXT MsgDialogContext; CHAR16 *MsgDialogTitle; CHAR16 *CmdLine; DialogContext = NULL; // //allocate a new efi file dialog context. // Status = BS->AllocatePool ( EfiBootServicesData, sizeof(EFI_FILE_DIALOG_CONTEXT), (VOID **)&DialogContext ); if (EFI_ERROR (Status)) { return; } BS->SetMem (DialogContext, sizeof(EFI_FILE_DIALOG_CONTEXT), 0); DialogContext->DialogType = EFI_FILE_DIALOG_TYPE_OPEN_FILE; DialogContext->FileType = EFI_FILTER_FILE_TYPE_LOG; // //get filename through FileDialog // Status = DoLogFileDialog (DialogContext); if (EFI_ERROR (Status)) { MsgDialogTitle = StrDuplicate (L"Display Log Error!"); MsgDialogContext.Type = EFI_DIALOG_TYPE_MESSAGE; MenuPageRefresh (Page); DoDialog (MsgDialogTitle, &MsgDialogContext); } else if (DialogContext->DevicePath != NULL && DialogContext->FileName != NULL && DialogContext->FileName[0] != L'\0') { // //make up file name // if (StrLen (DialogContext->FileName) > 4 && StriCmp (DialogContext->FileName + StrLen (DialogContext->FileName) - 4, L".log") == 0) { FileName = StrDuplicate (DialogContext->FileName); }else if ( StrLen (DialogContext->FileName) > 1 && StriCmp (DialogContext->FileName + StrLen (DialogContext->FileName) - 1, L".") == 0) { FileName = PoolPrint (L"%slog", DialogContext->FileName); }else { FileName = PoolPrint (L"%s.log", DialogContext->FileName); } if (FileName == NULL) { BS->FreePool (DialogContext->DevicePath); BS->FreePool (DialogContext->FileName); BS->FreePool (DialogContext); return; } MsgDialogTitle = StrDuplicate (L"Wait a few minutes..."); MsgDialogContext.Type = EFI_DIALOG_TYPE_REMINDER; // //set default Console Attribute and clear the screen // ST->ConOut->SetAttribute (ST->ConOut, EFI_BACKGROUND_BLACK | EFI_WHITE); ST->ConOut->ClearScreen (ST->ConOut); CmdLine = PoolPrint (L"%s \"%s\"", gFT->ConfigData->EditCommandString, FileName); if (CmdLine != NULL) { Status = ShellExecute ( gFT->ImageHandle, CmdLine, FALSE ); if (EFI_ERROR (Status)) { MsgDialogTitle = StrDuplicate (L"Cannot open the log file! Please check the edit command in the configuration page."); MsgDialogContext.Type = EFI_DIALOG_TYPE_MESSAGE; DoDialog (MsgDialogTitle, &MsgDialogContext); } BS->FreePool (CmdLine); } BS->FreePool (FileName); BS->FreePool (DialogContext->DevicePath); BS->FreePool (DialogContext->FileName); } else { if (DialogContext->FileName != NULL) { BS->FreePool (DialogContext->FileName); } if (DialogContext->DevicePath != NULL) { BS->FreePool (DialogContext->DevicePath); } } BS->FreePool (DialogContext); MenuPageRefresh (Page); return; }
VOID DisplayReportGenerator( IN EFI_MENU_PAGE *Page ) { EFI_STATUS Status; EFI_FILE_DIALOG_CONTEXT *DialogContext; CHAR16 *FileName; EFI_DIALOG_CONTEXT MsgDialogContext; CHAR16 *MsgDialogTitle; CHAR16 *LogFilePath; DialogContext = NULL; // //allocate a new efi file dialog context. // Status = BS->AllocatePool ( EfiBootServicesData, sizeof(EFI_FILE_DIALOG_CONTEXT), (VOID **)&DialogContext ); if (EFI_ERROR (Status)) { return; } BS->SetMem (DialogContext, sizeof(EFI_FILE_DIALOG_CONTEXT), 0); DialogContext->DialogType = EFI_FILE_DIALOG_TYPE_SAVE_FILE; DialogContext->FileType = EFI_FILTER_FILE_TYPE_CSV; // //get filename through FileDialog // Status = DoFileDialog (DialogContext); if (EFI_ERROR (Status)) { MsgDialogTitle = StrDuplicate (L"Generate Report Error!"); MsgDialogContext.Type = EFI_DIALOG_TYPE_MESSAGE; MenuPageRefresh (Page); DoDialog (MsgDialogTitle, &MsgDialogContext); } else if (DialogContext->DevicePath != NULL && DialogContext->FileName != NULL && DialogContext->FileName[0] != L'\0') { // //make up file name // if (StrLen (DialogContext->FileName) > 4 && StriCmp (DialogContext->FileName + StrLen (DialogContext->FileName) - 4, L".csv") == 0) { FileName = StrDuplicate (DialogContext->FileName); } else if ( StrLen (DialogContext->FileName) > 1 && StriCmp (DialogContext->FileName + StrLen (DialogContext->FileName) - 1, L".") == 0) { FileName = PoolPrint (L"%scsv", DialogContext->FileName); } else { FileName = PoolPrint (L"%s.csv", DialogContext->FileName); } if (FileName == NULL) { BS->FreePool (DialogContext->DevicePath); BS->FreePool (DialogContext->FileName); BS->FreePool (DialogContext); return; } MsgDialogTitle = StrDuplicate (L"Wait a few minutes..."); MsgDialogContext.Type = EFI_DIALOG_TYPE_REMINDER; MenuPageRefresh (Page); DoDialog (MsgDialogTitle, &MsgDialogContext); LogFilePath = PoolPrint ( L"%s\\%s", gFT->FilePath, EFI_SCT_PATH_LOG ); if (LogFilePath == NULL) { return; } // // Generate the report file // Status = GenerateReport ( gFT->DevicePath, LogFilePath, DialogContext->DevicePath, FileName ); if (EFI_ERROR (Status)) { MsgDialogTitle = StrDuplicate (L"Generate Report Error!"); } else { MsgDialogTitle = StrDuplicate (L"Generate Report Succeed!"); } MsgDialogContext.Type = EFI_DIALOG_TYPE_MESSAGE; DoDialog (MsgDialogTitle, &MsgDialogContext); BS->FreePool (FileName); BS->FreePool (DialogContext->DevicePath); BS->FreePool (DialogContext->FileName); } else { if (DialogContext->FileName != NULL) { BS->FreePool (DialogContext->FileName); } if (DialogContext->DevicePath != NULL) { BS->FreePool (DialogContext->DevicePath); } } BS->FreePool (DialogContext); MenuPageRefresh (Page); return; }
/** The default Exception Callback for the VM interpreter. In this function, we report status code, and print debug information about EBC_CONTEXT, then dead loop. @param ExceptionType Exception type. @param SystemContext EBC system context. **/ VOID EFIAPI EdbExceptionHandler ( IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext ) { CHAR16 InputBuffer[EFI_DEBUG_INPUS_BUFFER_SIZE]; CHAR16 *CommandArg; EFI_DEBUGGER_COMMAND DebuggerCommand; EFI_DEBUG_STATUS DebugStatus; STATIC BOOLEAN mInitialized; mInitialized = FALSE; DEBUG ((DEBUG_ERROR, "Hello EBC Debugger!\n")); if (!mInitialized) { // // Print version // EDBPrint ( L"EBC Interpreter Version - %d.%d\n", (UINTN)VM_MAJOR_VERSION, (UINTN)VM_MINOR_VERSION ); EDBPrint ( L"EBC Debugger Version - %d.%d\n", (UINTN)EBC_DEBUGGER_MAJOR_VERSION, (UINTN)EBC_DEBUGGER_MINOR_VERSION ); } // // Init Private Data // InitDebuggerPrivateData (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized); // // EDBPrint basic info // PrintExceptionReason (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized); EdbShowDisasm (&mDebuggerPrivate, SystemContext); // EFI_BREAKPOINT (); if (!mInitialized) { // // Interactive with user // EDBPrint (L"\nPlease enter command now, \'h\' for help.\n"); EDBPrint (L"(Using <Command> -b <...> to enable page break.)\n"); } mInitialized = TRUE; // // Dispatch each command // while (TRUE) { // // Get user input // Input (L"\n\r" EFI_DEBUG_PROMPT_STRING, InputBuffer, EFI_DEBUG_INPUS_BUFFER_SIZE); EDBPrint (L"\n"); // // Get command // DebuggerCommand = MatchDebuggerCommand (InputBuffer, &CommandArg); if (DebuggerCommand == NULL) { EDBPrint (L"ERROR: Command not found!\n"); continue; } // // Check PageBreak; // if (CommandArg != NULL) { if (StriCmp (CommandArg, L"-b") == 0) { CommandArg = StrGetNextTokenLine (L" "); mDebuggerPrivate.EnablePageBreak = TRUE; } } // // Dispatch command // DebugStatus = DebuggerCommand (CommandArg, &mDebuggerPrivate, ExceptionType, SystemContext); mDebuggerPrivate.EnablePageBreak = FALSE; // // Check command return status // if (DebugStatus == EFI_DEBUG_RETURN) { mInitialized = FALSE; break; } else if (DebugStatus == EFI_DEBUG_BREAK) { break; } else if (DebugStatus == EFI_DEBUG_CONTINUE) { continue; } else { ASSERT (FALSE); } } // // Deinit Private Data // DeinitDebuggerPrivateData (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized); DEBUG ((DEBUG_ERROR, "Goodbye EBC Debugger!\n")); return; }
VOID EdbConfigBreak ( EFI_DEBUGGER_CONFIGURATION_PROTOCOL *DebuggerConfiguration, CHAR16 *Command, CHAR16 *CommandArg ) { EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate; DebuggerPrivate = (EFI_DEBUGGER_PRIVATE_DATA *)DebuggerConfiguration->DebuggerPrivateData; if (StriCmp (Command, L"BOC") == 0) { if (CommandArg == NULL) { if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOC) == EFI_DEBUG_FLAG_EBC_BOC) { Print (L"BOC on\n"); } else { Print (L"BOC off\n"); } } else if (StriCmp (CommandArg, L"ON") == 0) { DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOC; } else if (StriCmp (CommandArg, L"OFF") == 0) { DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOC; } else { Print (L"Invalid parameter\n"); } } else if (StriCmp (Command, L"BOCX") == 0) { if (CommandArg == NULL) { if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOCX) == EFI_DEBUG_FLAG_EBC_BOCX) { Print (L"BOCX on\n"); } else { Print (L"BOCX off\n"); } } else if (StriCmp (CommandArg, L"ON") == 0) { DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOCX; } else if (StriCmp (CommandArg, L"OFF") == 0) { DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOCX; } else { Print (L"Invalid parameter\n"); } } else if (StriCmp (Command, L"BOR") == 0) { if (CommandArg == NULL) { if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOR) == EFI_DEBUG_FLAG_EBC_BOR) { Print (L"BOR on\n"); } else { Print (L"BOR off\n"); } } else if (StriCmp (CommandArg, L"ON") == 0) { DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOR; } else if (StriCmp (CommandArg, L"OFF") == 0) { DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOR; } else { Print (L"Invalid parameter\n"); } } else if (StriCmp (Command, L"BOE") == 0) { if (CommandArg == NULL) { if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOE) == EFI_DEBUG_FLAG_EBC_BOE) { Print (L"BOE on\n"); } else { Print (L"BOE off\n"); } } else if (StriCmp (CommandArg, L"ON") == 0) { DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOE; } else if (StriCmp (CommandArg, L"OFF") == 0) { DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOE; } else { Print (L"Invalid parameter\n"); } } else if (StriCmp (Command, L"BOT") == 0) { if (CommandArg == NULL) { if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOT) == EFI_DEBUG_FLAG_EBC_BOT) { Print (L"BOT on\n"); } else { Print (L"BOT off\n"); } } else if (StriCmp (CommandArg, L"ON") == 0) { DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOT; } else if (StriCmp (CommandArg, L"OFF") == 0) { DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOT; } else { Print (L"Invalid parameter\n"); } } else if (StriCmp (Command, L"BOK") == 0) { if (CommandArg == NULL) { if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOK) == EFI_DEBUG_FLAG_EBC_BOK) { Print (L"BOK on\n"); } else { Print (L"BOK off\n"); } } else if (StriCmp (CommandArg, L"ON") == 0) { DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOK; } else if (StriCmp (CommandArg, L"OFF") == 0) { DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOK; } else { Print (L"Invalid parameter\n"); } } return ; }
/** Alter the EBC Debugger configuration. @param[in] ImageHandle The image handle. @param[in] SystemTable The system table. @retval EFI_SUCCESS Operation completed successfully. @retval EFI_INVALID_PARAMETER Usage error. @retval EFI_NOT_FOUND A running debugger cannot be located. **/ EFI_STATUS EFIAPI InitializeEbcDebuggerConfig ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { UINTN Argc; CHAR16 **Argv; EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters; EFI_DEBUGGER_CONFIGURATION_PROTOCOL *DebuggerConfiguration; EFI_STATUS Status; Status = gBS->HandleProtocol ( gImageHandle, &gEfiShellParametersProtocolGuid, (VOID**)&ShellParameters ); if (EFI_ERROR(Status)) { Print (L"Please use UEFI Shell to run this application.\n"); return EFI_INVALID_PARAMETER; } Argc = ShellParameters->Argc; Argv = ShellParameters->Argv; if (Argc < 2) { PrintUsage (); return EFI_INVALID_PARAMETER; } if (Argc == 2) { if ((StrCmp (Argv[1], L"/?") == 0) || (StrCmp (Argv[1], L"-?") == 0) || (StrCmp (Argv[1], L"-h") == 0) || (StrCmp (Argv[1], L"-H") == 0) ) { PrintUsage (); return EFI_SUCCESS; } } Status = gBS->LocateProtocol ( &gEfiDebuggerConfigurationProtocolGuid, NULL, (VOID**)&DebuggerConfiguration ); if (EFI_ERROR(Status)) { Print (L"Error: DebuggerConfiguration protocol not found.\n"); return EFI_NOT_FOUND; } if (StriCmp (Argv[1], L"SHOWINFO") == 0) { EdbShowInfo (DebuggerConfiguration); return EFI_SUCCESS; } if (((Argc == 2) || (Argc == 3)) && ((StriCmp (Argv[1], L"BOC") == 0) || (StriCmp (Argv[1], L"BOCX") == 0) || (StriCmp (Argv[1], L"BOR") == 0) || (StriCmp (Argv[1], L"BOE") == 0) || (StriCmp (Argv[1], L"BOT") == 0) || (StriCmp (Argv[1], L"BOK") == 0))) { if (Argc == 3) { EdbConfigBreak (DebuggerConfiguration, Argv[1], Argv[2]); } else { EdbConfigBreak (DebuggerConfiguration, Argv[1], NULL); } return EFI_SUCCESS; } Print (L"Error: Invalid Command.\n"); return EFI_INVALID_PARAMETER; }
EFI_STATUS CheckUartProtocols ( IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, IN EFI_INI_FILE_HANDLE IniFile ) { EFI_STATUS Status; UINT32 MaxLength; CHAR16 String[10]; BOOLEAN ValueA; VOID *Interface; EFI_TEST_ASSERTION AssertionType; // // Check the SERIAL_IO protocol // Status = gtBS->LocateProtocol ( &gEfiSerialIoProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueA = TRUE; } else { ValueA = FALSE; } // // Need one or warning // AssertionType = NeedOneOrWarning (ValueA); // // For platform-specific elements, throw out a warning in default // if (AssertionType == EFI_TEST_ASSERTION_FAILED) { AssertionType = EFI_TEST_ASSERTION_WARNING; } // // If warning, check with INI file to decide they must exist or not // if ((AssertionType == EFI_TEST_ASSERTION_WARNING) && (IniFile != NULL_HANDLE )) { MaxLength = 10; Status = IniFile->GetString ( IniFile, SECTION_NAME_PLATFORM_SPECIFIC, L"UartDevices", String, &MaxLength ); if (!EFI_ERROR (Status) && (StriCmp (String, L"yes") == 0)) { AssertionType = EFI_TEST_ASSERTION_FAILED; } } // // Record test result // StandardLib->RecordAssertion ( StandardLib, AssertionType, gEfiCompliantBbTestPlatformAssertionGuid006, L"EFI Compliant - UART protocols must be implemented", L"%a:%d:Serial IO - %s", __FILE__, (UINTN)__LINE__, ValueA ? L"Yes" : L"No" ); // // Done // return EFI_SUCCESS; }
EFI_STATUS SEnvCmdSA ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable, IN EFI_LIST_ENTRY *Head, IN EFI_GUID *Guid, IN CHAR16 *CmdName, IN UINT16 VHlpToken ) /*++ Routine Description: Code for shell "set" & "alias" command Arguments: ImageHandle - The image handle SystemTable - The system table Head - The variable list head Guid - The guid CmdName - The command name VHlpToken - The help token Returns: --*/ { EFI_LIST_ENTRY *Link; VARIABLE_ID *Var; VARIABLE_ID *Found; CHAR16 *Name; CHAR16 *Value; UINTN SLen; UINTN Len; BOOLEAN Delete; EFI_STATUS Status; BOOLEAN Volatile; UINTN Index; SHELL_VAR_CHECK_CODE RetCode; CHAR16 *Useful; SHELL_VAR_CHECK_PACKAGE ChkPck; SHELL_ARG_LIST *ArgItem; EFI_SHELL_APP_INIT (ImageHandle, SystemTable); Status = LibFilterNullArgs (); if (EFI_ERROR (Status)) { goto Quit; } ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); ArgItem = NULL; RetCode = LibCheckVariables (SI, VarCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckConflict: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_FLAG_CONFLICT), HiiEnvHandle, CmdName, Useful); break; case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiEnvHandle, CmdName, Useful); break; case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiEnvHandle, CmdName, Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Quit; } // // Initializing variable to aVOID level 4 warning // Name = NULL; Value = NULL; Delete = FALSE; Status = EFI_SUCCESS; Found = NULL; Var = NULL; Volatile = FALSE; // // Crack arguments // if (ChkPck.ValueCount > 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle); goto Quit; } if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } PrintToken (VHlpToken, HiiEnvHandle); Status = EFI_SUCCESS; goto Quit; } if (LibCheckVarGetFlag (&ChkPck, L"-d") != NULL) { if (ChkPck.ValueCount > 1) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } else if (ChkPck.ValueCount < 1) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } Delete = TRUE; } if (LibCheckVarGetFlag (&ChkPck, L"-v") != NULL) { if (ChkPck.ValueCount < 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } Volatile = TRUE; } ArgItem = GetFirstArg (&ChkPck); if (NULL != ArgItem) { if (SEnvGetCmdDispath (ArgItem->VarStr) && (StriCmp (CmdName, L"alias") == 0)) { PrintToken (STRING_TOKEN (STR_SHELLENV_VAR_INTERNAL_COMAMND), HiiEnvHandle, CmdName, ArgItem->VarStr); Status = EFI_INVALID_PARAMETER; goto Quit; } else if (StrSubCmp (L"*", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"?", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"<", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L">", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"#", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L":", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"^", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"%", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"/", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"|", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"\"", ArgItem->VarStr, 1) == TRUE ) { // // we donot allow *,?,<,>,#,:,^,%,/,|," in alias or variable name // PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiEnvHandle, CmdName, ArgItem->VarStr); Status = EFI_INVALID_PARAMETER; goto Quit; } else { Name = ArgItem->VarStr; } ArgItem = GetNextArg (ArgItem); } if (NULL != ArgItem) { Value = ArgItem->VarStr; } if (Delete && Value) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } if (Name != NULL) { for (Index = 0; mSpecVarTable[Index].CmdName != NULL; Index++) { if (StriCmp (mSpecVarTable[Index].CmdName, CmdName) == 0 && StriCmp (mSpecVarTable[Index].VarName, Name) == 0 && mSpecVarTable[Index].SpecCheckFun != NULL ) { Status = mSpecVarTable[Index].SpecCheckFun (Value, Delete, Volatile); if (EFI_ERROR (Status)) { goto Quit; } } } } // // Process // AcquireLock (&SEnvLock); if (!Name) { // // dump the list // SEnvSortVarList (Head); SLen = 0; for (Link = Head->Flink; Link != Head; Link = Link->Flink) { Var = CR (Link, VARIABLE_ID, Link, VARIABLE_SIGNATURE); if (_IsReserved (Var->Name, CmdName)) { continue; } Len = StrLen (Var->Name); if (Len > SLen) { SLen = Len; } } for (Link = Head->Flink; Link != Head; Link = Link->Flink) { // // Break the execution? // if (GetExecutionBreak ()) { goto Done; } Var = CR (Link, VARIABLE_ID, Link, VARIABLE_SIGNATURE); if (_IsReserved (Var->Name, CmdName)) { continue; } if (Var->Flags & VAR_ID_NON_VOL) { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_DUMP_VAR_LIST), HiiEnvHandle, L' ', SLen, Var->Name, Var->u.Str ); } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_DUMP_VAR_LIST), HiiEnvHandle, L'*', SLen, Var->Name, Var->u.Str ); } } } else { // // Find the specified value // Found = SEnvFindVar (Head, Name); if (Found && Delete) { // // Remove it from the store // Status = RT->SetVariable (Found->Name, Guid, 0, 0, NULL); if (Status == EFI_NOT_FOUND) { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_NOT_FOUND), HiiEnvHandle, CmdName, Found->Name ); } } else if (Value) { // // Add it to the store // if (Found && ((Volatile && (Found->Flags & VAR_ID_NON_VOL)) || (!Volatile && !(Found->Flags & VAR_ID_NON_VOL)))) { if (Found->Flags & VAR_ID_NON_VOL) { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_ALREADY_EXISTS_NONVOLATILE), HiiEnvHandle, CmdName, Found->Name ); } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_ALREADY_EXISTS_VOLATILE), HiiEnvHandle, CmdName, Found->Name ); } Found = NULL; Status = EFI_ACCESS_DENIED; } else { Status = SEnvAddVar ( Head, Guid, Found ? Found->Name : Name, (UINT8 *) Value, StrSize (Value), Volatile ); } } else { if (Found) { if (Found->Flags & VAR_ID_NON_VOL) { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_DISPLAY_VAR), HiiEnvHandle, L' ', Found->Name, Found->u.Str ); } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_DISPLAY_VAR), HiiEnvHandle, L'*', Found->Name, Found->u.Str ); } } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_NOT_FOUND), HiiEnvHandle, CmdName, Name ); } Found = NULL; } // // Remove the old in memory copy if there was one // if (Found && !EFI_ERROR (Status)) { RemoveEntryList (&Found->Link); FreePool (Found); } } Done: ReleaseLock (&SEnvLock); Quit: LibCheckVarFreeVarList (&ChkPck); return Status; }
/** Internal helper function. Update the BBS Table so that devices of DeviceType have their boot priority updated to a high/bootable value. See "DeviceType values" in http://www.intel.com/content/dam/doc/reference-guide/efi-compatibility-support-module-specification-v097.pdf NOTE: This function should probably be refactored! Currently, all devices of type are enabled. This should be updated so that only a specific device is enabled. The wrong device could boot if there are multiple targets of the same type. @param DeviceType The device type that we wish to enable **/ VOID UpdateBbsTable (BDS_COMMON_OPTION *Option) { UINT16 Idx; EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; EFI_STATUS Status; UINT16 HddCount = 0; HDD_INFO *HddInfo = NULL; UINT16 BbsCount = 0; BBS_TABLE *LocalBbsTable = NULL; BBS_BBS_DEVICE_PATH *OptionBBS; CHAR16 Desc[100]; Status = refit_call3_wrapper(gBS->LocateProtocol, &gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios); if (EFI_ERROR (Status) || (Option == NULL)) { return; } OptionBBS = (BBS_BBS_DEVICE_PATH *) Option->DevicePath; Status = refit_call5_wrapper(LegacyBios->GetBbsInfo, LegacyBios, &HddCount, &HddInfo, &BbsCount, &LocalBbsTable); // Print (L"\n"); // Print (L" NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n"); // Print (L"=============================================\n"); for (Idx = 0; Idx < BbsCount; Idx++) { if(LocalBbsTable[Idx].DeviceType == 0) { continue; } BdsBuildLegacyDevNameString (&LocalBbsTable[Idx], Idx, sizeof (Desc), Desc); // Set devices of a particular type to BootPriority of 0 or 1. 0 is the highest priority. if (LocalBbsTable[Idx].DeviceType == OptionBBS->DeviceType) { if (StriCmp(Desc, Option->Description) == 0) { // This entry exactly matches what we're looking for; make it highest priority LocalBbsTable[Idx].BootPriority = 0; } else { // This entry doesn't exactly match, but is the right disk type; make it a bit lower // in priority. Done mainly as a fallback in case of string-matching weirdness. LocalBbsTable[Idx].BootPriority = 1; } // if/else } else if (LocalBbsTable[Idx].BootPriority <= 1) { // Something's got a high enough boot priority to interfere with booting // our chosen entry, so bump it down a bit.... LocalBbsTable[Idx].BootPriority = 2; } // if/else if // Print ( // L" %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n", // (UINTN) Idx, // (UINTN) LocalBbsTable[Idx].BootPriority, // (UINTN) LocalBbsTable[Idx].Bus, // (UINTN) LocalBbsTable[Idx].Device, // (UINTN) LocalBbsTable[Idx].Function, // (UINTN) LocalBbsTable[Idx].Class, // (UINTN) LocalBbsTable[Idx].SubClass, // (UINTN) LocalBbsTable[Idx].DeviceType, // (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags, // (UINTN) LocalBbsTable[Idx].BootHandlerSegment, // (UINTN) LocalBbsTable[Idx].BootHandlerOffset, // (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset), // (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset) // ); // Print(L"%s\n", Desc); } // for // PauseForKey(); }
EFI_STATUS CheckPciProtocols ( IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, IN EFI_INI_FILE_HANDLE IniFile ) { EFI_STATUS Status; UINT32 MaxLength; CHAR16 String[10]; BOOLEAN ValueA; BOOLEAN ValueB; BOOLEAN ValueC; VOID *Interface; EFI_TEST_ASSERTION AssertionType; // // Check the PCI_ROOT_BRIDGE_IO protocol // Status = gtBS->LocateProtocol ( &gEfiPciRootBridgeIoProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueA = TRUE; } else { ValueA = FALSE; } // // Check the PCI_IO protocol // Status = gtBS->LocateProtocol ( &gEfiPciIoProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueB = TRUE; } else { ValueB = FALSE; } // // Check the DEVICE_IO protocol // Status = gtBS->LocateProtocol ( &gEfiDeviceIoProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueC = TRUE; } else { ValueC = FALSE; } // // UEFI forum may want to eliminate Device IO protocol and require all drivers // today to use PCI I/O protocols. So here we skip the check to this protocol. // // // Need *two* or warning // AssertionType = NeedTwoOrWarning (ValueA, ValueB); // // For platform-specific elements, throw out a warning in default // if (AssertionType == EFI_TEST_ASSERTION_FAILED) { AssertionType = EFI_TEST_ASSERTION_WARNING; } // // If warning, check with INI file to decide they must exist or not // if ((AssertionType == EFI_TEST_ASSERTION_WARNING) && (IniFile != NULL_HANDLE )) { MaxLength = 10; Status = IniFile->GetString ( IniFile, SECTION_NAME_PLATFORM_SPECIFIC, L"PciBusSupport", String, &MaxLength ); if (!EFI_ERROR (Status) && (StriCmp (String, L"yes") == 0)) { AssertionType = EFI_TEST_ASSERTION_FAILED; } } // // Record test result // StandardLib->RecordAssertion ( StandardLib, AssertionType, gEfiCompliantBbTestPlatformAssertionGuid007, L"EFI Compliant - PCI Bus support protocols must be implemented", L"%a:%d:PCI Root Bridge - %s, PCI IO - %s, Device IO (not required) - %s", __FILE__, (UINTN)__LINE__, ValueA ? L"Yes" : L"No", ValueB ? L"Yes" : L"No", ValueC ? L"Yes" : L"No" ); // // Done // return EFI_SUCCESS; }
EFI_STATUS EFIAPI SEnvCmdGoto ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Transfers execution of batch file to location following a label (:labelname). Arguments: ImageHandle The image handle SystemTable The system table Returns: EFI_SUCCESS The command finished sucessfully EFI_UNSUPPORTED Unsupported EFI_INVALID_PARAMETER Invalid parameter EFI_OUT_OF_RESOURCES Out of resources --*/ { EFI_STATUS Status; EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Output help // if (SI->Argc == 2) { if (StriCmp (SI->Argv[1], L"-?") == 0) { if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle); } else { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_VERBOSE_HELP), HiiEnvHandle); } return EFI_SUCCESS; } } else if (SI->Argc == 3) { if ((StriCmp (SI->Argv[1], L"-?") == 0 && StriCmp (SI->Argv[2], L"-b") == 0) || (StriCmp (SI->Argv[2], L"-?") == 0 && StriCmp (SI->Argv[1], L"-b") == 0) ) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle); } else { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_VERBOSE_HELP), HiiEnvHandle); } return EFI_SUCCESS; } } if (!SEnvBatchIsActive ()) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_ONLY_SUPPORTED_SCRIPT), HiiEnvHandle); return EFI_UNSUPPORTED; } if (SI->Argc > 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_TOO_MANY_ARGS), HiiEnvHandle, SEnvGetLineNumber ()); SEnvSetBatchAbort (); return EFI_INVALID_PARAMETER; } if (SI->Argc < 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_TOO_FEW_ARGS), HiiEnvHandle, SEnvGetLineNumber ()); SEnvSetBatchAbort (); return EFI_INVALID_PARAMETER; } TargetLabel = StrDuplicate (SI->Argv[1]); if (TargetLabel == NULL) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_OUT_OF_RESOURCES), HiiEnvHandle); SEnvSetBatchAbort (); return EFI_OUT_OF_RESOURCES; } SEnvBatchSetGotoActive (); Status = SEnvBatchResetJumpStmt (); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_CANNOT_EXECUTE_SCRIPT), HiiEnvHandle, Status); SEnvSetBatchAbort (); return Status; } return Status; }
/** DebuggerCommand - CallStack. @param CommandArg The argument for this command @param DebuggerPrivate EBC Debugger private data structure @param ExceptionType Exception type. @param SystemContext EBC system context. @retval EFI_DEBUG_CONTINUE formal return value **/ EFI_DEBUG_STATUS DebuggerCallStack ( IN CHAR16 *CommandArg, IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, IN EFI_EXCEPTION_TYPE ExceptionType, IN OUT EFI_SYSTEM_CONTEXT SystemContext ) { INTN Index; UINTN SubIndex; CHAR8 *FuncName; EFI_DEBUGGER_CALLSTACK_CONTEXT *CallStackEntry; BOOLEAN ShowParameter; UINTN ParameterNumber; ShowParameter = FALSE; ParameterNumber = EFI_DEBUGGER_CALL_DEFAULT_PARAMETER; // // Check argument // if (CommandArg != NULL) { if (StriCmp (CommandArg, L"c") == 0) { // // Clear Call-Stack // DebuggerPrivate->CallStackEntryCount = 0; ZeroMem (DebuggerPrivate->CallStackEntry, sizeof(DebuggerPrivate->CallStackEntry)); EDBPrint (L"Call-Stack is cleared\n"); return EFI_DEBUG_CONTINUE; } else if (StriCmp (CommandArg, L"p") == 0) { // // Print Call-Stack with parameter // ShowParameter = TRUE; CommandArg = StrGetNextTokenLine (L" "); if (CommandArg != NULL) { // // Try to get the parameter number // ParameterNumber = Atoi (CommandArg); if (ParameterNumber > 16) { EDBPrint (L"Call-Stack argument Invalid\n"); return EFI_DEBUG_CONTINUE; } } } else { EDBPrint (L"Call-Stack argument Invalid\n"); return EFI_DEBUG_CONTINUE; } } // // Check CallStack Entry Count // if (DebuggerPrivate->CallStackEntryCount == 0) { EDBPrint (L"No Call-Stack\n"); return EFI_DEBUG_CONTINUE; } else if (DebuggerPrivate->CallStackEntryCount > EFI_DEBUGGER_CALLSTACK_MAX) { EDBPrint (L"Call-Stack Crash, re-initialize!\n"); DebuggerPrivate->CallStackEntryCount = 0; return EFI_DEBUG_CONTINUE; } // // Go through each CallStack entry and print // EDBPrint (L"Call-Stack (TOP):\n"); EDBPrint (L" Caller Callee Name\n"); EDBPrint (L" ================== ================== ========\n"); //EDBPrint (L" 0x00000000FFFFFFFF 0xFFFFFFFF00000000 EfiMain\n"); for (Index = (INTN)(DebuggerPrivate->CallStackEntryCount - 1); Index >= 0; Index--) { // // Get CallStack and print // CallStackEntry = &DebuggerPrivate->CallStackEntry[Index]; EDBPrint ( L" 0x%016lx 0x%016lx", CallStackEntry->SourceAddress, CallStackEntry->DestAddress ); FuncName = FindSymbolStr ((UINTN)CallStackEntry->DestAddress); if (FuncName != NULL) { EDBPrint (L" %a()", FuncName); } EDBPrint (L"\n"); if (ShowParameter) { // // Print parameter // if (sizeof(UINTN) == sizeof(UINT64)) { EDBPrint ( L" Parameter Address (0x%016lx) (\n", CallStackEntry->ParameterAddr ); if (ParameterNumber == 0) { EDBPrint (L" )\n"); continue; } // // Print each parameter // for (SubIndex = 0; SubIndex < ParameterNumber - 1; SubIndex++) { if (SubIndex % 2 == 0) { EDBPrint (L" "); } EDBPrint ( L"0x%016lx, ", CallStackEntry->Parameter[SubIndex] ); if (SubIndex % 2 == 1) { EDBPrint (L"\n"); } } if (SubIndex % 2 == 0) { EDBPrint (L" "); } EDBPrint ( L"0x%016lx\n", CallStackEntry->Parameter[SubIndex] ); EDBPrint (L" )\n"); // // break only for parameter // if ((((DebuggerPrivate->CallStackEntryCount - Index) % (16 / ParameterNumber)) == 0) && (Index != 0)) { if (SetPageBreak ()) { break; } } } else { EDBPrint ( L" Parameter Address (0x%08x) (\n", CallStackEntry->ParameterAddr ); if (ParameterNumber == 0) { EDBPrint (L" )\n"); continue; } // // Print each parameter // for (SubIndex = 0; SubIndex < ParameterNumber - 1; SubIndex++) { if (SubIndex % 4 == 0) { EDBPrint (L" "); } EDBPrint ( L"0x%08x, ", CallStackEntry->Parameter[SubIndex] ); if (SubIndex % 4 == 3) { EDBPrint (L"\n"); } } if (SubIndex % 4 == 0) { EDBPrint (L" "); } EDBPrint ( L"0x%08x\n", CallStackEntry->Parameter[SubIndex] ); EDBPrint (L" )\n"); // // break only for parameter // if ((((DebuggerPrivate->CallStackEntryCount - Index) % (32 / ParameterNumber)) == 0) && (Index != 0)) { if (SetPageBreak ()) { break; } } } } } // // Done // return EFI_DEBUG_CONTINUE; }
EFI_STATUS CheckBootFromDiskProtocols ( IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, IN EFI_INI_FILE_HANDLE IniFile ) { EFI_STATUS Status; UINT32 MaxLength; CHAR16 String[10]; BOOLEAN ValueA; BOOLEAN ValueB; BOOLEAN ValueC; BOOLEAN ValueD; VOID *Interface; EFI_TEST_ASSERTION AssertionType; // // Check the BLOCK_IO protocol // Status = gtBS->LocateProtocol ( &gEfiBlockIoProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueA = TRUE; } else { ValueA = FALSE; } // // Check the DISK_IO protocol // Status = gtBS->LocateProtocol ( &gEfiDiskIoProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueB = TRUE; } else { ValueB = FALSE; } // // Check the SIMPLE_FILE_SYSTEM protocol // Status = gtBS->LocateProtocol ( &gEfiSimpleFileSystemProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueC = TRUE; } else { ValueC = FALSE; } // // Check the UNICODE_COLLATION protocol // Status = gtBS->LocateProtocol ( &gEfiUnicodeCollationProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueD = TRUE; } else { ValueD = FALSE; } // // Need four or warning // AssertionType = NeedFourOrWarning (ValueA, ValueB, ValueC, ValueD); // // For platform-specific elements, throw out a warning in default // if (AssertionType == EFI_TEST_ASSERTION_FAILED) { AssertionType = EFI_TEST_ASSERTION_WARNING; } // // If warning, check with INI file to decide they must exist or not // if ((AssertionType == EFI_TEST_ASSERTION_WARNING) && (IniFile != NULL_HANDLE )) { MaxLength = 10; Status = IniFile->GetString ( IniFile, SECTION_NAME_PLATFORM_SPECIFIC, L"BootFromDiskDevices", String, &MaxLength ); if (!EFI_ERROR (Status) && (StriCmp (String, L"yes") == 0)) { AssertionType = EFI_TEST_ASSERTION_FAILED; } } // // Record test result // StandardLib->RecordAssertion ( StandardLib, AssertionType, gEfiCompliantBbTestPlatformAssertionGuid004, L"EFI Compliant - Boot from disk protocols must be implemented", L"%a:%d:Block IO - %s, Disk IO - %s, Simple FS - %s, Unicode Collation - %s", __FILE__, (UINTN)__LINE__, ValueA ? L"Yes" : L"No", ValueB ? L"Yes" : L"No", ValueC ? L"Yes" : L"No", ValueD ? L"Yes" : L"No" ); // // Done // return EFI_SUCCESS; }
EFI_STATUS CheckBootFromNetworkProtocols ( IN EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib, IN EFI_INI_FILE_HANDLE IniFile ) { EFI_STATUS Status; UINT32 MaxLength; CHAR16 String[10]; BOOLEAN ValueA; BOOLEAN ValueB; BOOLEAN ValueC; VOID *Interface; EFI_TEST_ASSERTION AssertionType; // // Check the SIMPLE_NETWORK protocol // Status = gtBS->LocateProtocol ( &gEfiSimpleNetworkProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueA = TRUE; } else { ValueA = FALSE; } // // Check the PXE_BASE_CODE protocol // Status = gtBS->LocateProtocol ( &gEfiPxeBaseCodeProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueB = TRUE; } else { ValueB = FALSE; } // // Check the BIS protocol // Status = gtBS->LocateProtocol ( &gEfiBisProtocolGuid, NULL, &Interface ); if (!EFI_ERROR (Status)) { ValueC = TRUE; } else { ValueC = FALSE; } // // BIS protocol indicates the ability to validate a boot image received // through a network device. UEFI forum may think it is not one of platform // specific elements. So here we skip the check to this protocol. // // // Need *two* or warning // AssertionType = NeedTwoOrWarning (ValueA, ValueB); // // For platform-specific elements, throw out a warning in default // if (AssertionType == EFI_TEST_ASSERTION_FAILED) { AssertionType = EFI_TEST_ASSERTION_WARNING; } // // If warning, check with INI file to decide they must exist or not // if ((AssertionType == EFI_TEST_ASSERTION_WARNING) && (IniFile != NULL_HANDLE )) { MaxLength = 10; Status = IniFile->GetString ( IniFile, SECTION_NAME_PLATFORM_SPECIFIC, L"BootFromNetworkDevices", String, &MaxLength ); if (!EFI_ERROR (Status) && (StriCmp (String, L"yes") == 0)) { AssertionType = EFI_TEST_ASSERTION_FAILED; } } // // Record test result // StandardLib->RecordAssertion ( StandardLib, AssertionType, gEfiCompliantBbTestPlatformAssertionGuid005, L"EFI Compliant - Boot from network protocols must be implemented", L"%a:%d:SNP - %s, PXE BC - %s, BIS (not required) - %s", __FILE__, (UINTN)__LINE__, ValueA ? L"Yes" : L"No", ValueB ? L"Yes" : L"No", ValueC ? L"Yes" : L"No" ); // // Done // return EFI_SUCCESS; }
EFI_STATUS GatherConfigHandles ( IN EFI_HANDLE SupportHandle, OUT UINTN *NoConfigHandles, OUT EFI_HANDLE **ConfigHandleBuffer ) { EFI_STATUS Status; EFI_TEST_PROFILE_LIBRARY_PROTOCOL *ProfileLib; EFI_DEVICE_PATH_PROTOCOL *DevicePath; CHAR16 *FilePath; CHAR16 *ConfigFilePath; EFI_INI_FILE_HANDLE IniFile; UINT32 Order; UINT32 OrderNum; CHAR16 Buffer[EFI_SCT_MAX_BUFFER_SIZE]; UINTN Index; UINTN NoHandles; EFI_HANDLE *HandleBuffer; CHAR16 *DevicePathStr; // // Locate test profile library protocol // Status = gtBS->HandleProtocol ( SupportHandle, &gEfiTestProfileLibraryGuid, &ProfileLib ); if (EFI_ERROR (Status)) { return Status; } // // Get the system device path and file path // Status = ProfileLib->EfiGetSystemDevicePath ( ProfileLib, &DevicePath, &FilePath ); if (EFI_ERROR (Status)) { return Status; } ConfigFilePath = PoolPrint (L"%s\\%s", FilePath, EFI_SCT_FILE_DEVICE_CONFIG); if (ConfigFilePath == NULL) { gtBS->FreePool (DevicePath); gtBS->FreePool (FilePath); return EFI_OUT_OF_RESOURCES; } gtBS->FreePool (FilePath); // // Open the device configuration file // Status = ProfileLib->EfiIniOpen ( ProfileLib, DevicePath, ConfigFilePath, &IniFile ); if (EFI_ERROR (Status)) { gtBS->FreePool (DevicePath); gtBS->FreePool (ConfigFilePath); return Status; } gtBS->FreePool (DevicePath); gtBS->FreePool (ConfigFilePath); // // Get the number of device configuration data // Status = DeviceConfigGetOrderNum ( IniFile, &OrderNum ); if (EFI_ERROR (Status)) { ProfileLib->EfiIniClose (ProfileLib, IniFile); return Status; } // // Get all handles // Status = gtBS->LocateHandleBuffer ( AllHandles, NULL, NULL, &NoHandles, &HandleBuffer ); if (EFI_ERROR (Status)) { ProfileLib->EfiIniClose (ProfileLib, IniFile); return Status; } // // Initialize the output variables // *NoConfigHandles = 0; Status = gtBS->AllocatePool ( EfiBootServicesData, sizeof(EFI_HANDLE) * NoHandles, (VOID **)ConfigHandleBuffer ); if (EFI_ERROR (Status)) { ProfileLib->EfiIniClose (ProfileLib, IniFile); gtBS->FreePool (HandleBuffer); return Status; } // // Scan each device configuration data // for (Order = 0; Order < OrderNum; Order++) { // // Here, need to check the setting in configuration file and find the // matched device path in the system // Status = DeviceConfigGetString ( IniFile, Order, L"DriverConfiguration", Buffer ); if (EFI_ERROR (Status)) { continue; } if (StriCmp (Buffer, L"Yes") != 0) { continue; } Status = DeviceConfigGetString ( IniFile, Order, L"DevicePath", Buffer ); if (EFI_ERROR (Status)) { continue; } // // Search the matched device path in the system // for (Index = 0; Index < NoHandles; Index++) { Status = gtBS->HandleProtocol ( HandleBuffer[Index], &gEfiDevicePathProtocolGuid, &DevicePath ); if (EFI_ERROR (Status)) { continue; } DevicePathStr = DevicePathToStr (DevicePath); if (StrCmp (Buffer, DevicePathStr) == 0) { gtBS->FreePool (DevicePathStr); break; } gtBS->FreePool (DevicePathStr); } // // Found it? // if (Index < NoHandles) { InsertChildHandles ( NoConfigHandles, *ConfigHandleBuffer, HandleBuffer[Index], FALSE // Only for the handles on this controller ); } } // // Free resources // gtBS->FreePool (HandleBuffer); // // Close the device configuration file // ProfileLib->EfiIniClose (ProfileLib, IniFile); // // Done // return EFI_SUCCESS; }
/** * get the device path and file path based on the loaded image name. * @param Name the iamge file name such as framework.efi * @param DevicePath the Device path of this file is loaded from. * @param FilePath the file path of this file. * @return EFI_SUCCESS the device path and file path was found successfully. * @return EFI_INVALID_PARAMETER the Parameter is invalid */ EFI_STATUS GetFilePathByName ( IN CHAR16 *Name, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, OUT CHAR16 **FilePath ) { EFI_STATUS Status; UINTN Index; EFI_LOADED_IMAGE_PROTOCOL *Image; EFI_HANDLE *HandleBuffer; UINTN HandleNum; EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; EFI_DEVICE_PATH_PROTOCOL *TempDeviceNode; CHAR16 *TempFilePath; CHAR16 FullFilePath[MAX_FILE_PATH]; BOOLEAN Found; // //verify parameters. // if (Name == NULL || DevicePath == NULL || FilePath == NULL) { return EFI_INVALID_PARAMETER; } if (StrLen (Name) == 0) { return EFI_INVALID_PARAMETER; } // //get all the load image protocol instance. // Found = FALSE; HandleNum = 0; HandleBuffer = NULL; Status = LibLocateHandle( ByProtocol, &gEfiLoadedImageProtocolGuid, NULL, &HandleNum, &HandleBuffer ); if (EFI_ERROR(Status) || HandleNum == 0) { return EFI_ABORTED; } // //for all the LoadedImage protocol found the image file name to match the //given file name. // TempDevicePath = NULL; for (Index = 0; Index < HandleNum; Index ++ ) { FullFilePath[0] = '\0'; // // Get the image instance from the image handle // Status = tBS->HandleProtocol ( HandleBuffer[Index], &gEfiLoadedImageProtocolGuid, &Image ); if (EFI_ERROR(Status)) { return Status; } if (Image->FilePath == NULL) { continue; } // //get the file path and parse the file name. // TempDevicePath = UnpackDevicePath (Image->FilePath); TempFilePath = NULL; TempDeviceNode = TempDevicePath; while (!IsDevicePathEnd(TempDeviceNode)) { if ((DevicePathType(TempDeviceNode) == MEDIA_DEVICE_PATH) && (DevicePathSubType(TempDeviceNode) == MEDIA_FILEPATH_DP)) { StrCat(FullFilePath, L"\\"); TempFilePath = ((FILEPATH_DEVICE_PATH *)TempDeviceNode)->PathName; if (StrLen (TempFilePath) == 1 && TempFilePath[0] == '\\') { // //if this the "\\" path then we need not append it,or else there will //have 3 '\\' in the device path. // ; } else { StrCat(FullFilePath, TempFilePath); } } TempDeviceNode = NextDevicePathNode (TempDeviceNode); } tBS->FreePool (TempDevicePath); if (StrLen (FullFilePath) <= StrLen (Name)) { continue; } TempFilePath = FullFilePath + (StrLen(FullFilePath) - StrLen(Name)); if ((*(TempFilePath - 1)) == L'\\' && StriCmp (TempFilePath, Name) == 0) { TempFilePath[0] = '\0'; // // Get the device instance from the device handle // Status = tBS->HandleProtocol ( Image->DeviceHandle, &gEfiDevicePathProtocolGuid, &TempDevicePath ); if (EFI_ERROR(Status)) { return Status; } Found = TRUE; break; } } if (HandleBuffer != NULL) { tBS->FreePool (HandleBuffer); } if (!Found) { return EFI_NOT_FOUND; } // // If the file path is only a root directory "\\", remove it // if (StrLen(FullFilePath) > 1) { if (FullFilePath[StrLen(FullFilePath) - 1] == L'\\') { FullFilePath[StrLen(FullFilePath) - 1] = '\0'; } } *DevicePath = DuplicateDevicePath (TempDevicePath); if (*DevicePath == NULL) { return EFI_OUT_OF_RESOURCES; } // //skip the first '\\'. // *FilePath = StrDuplicate (FullFilePath + 1); if (*FilePath == NULL) { tBS->FreePool (*DevicePath); *DevicePath = NULL; return EFI_OUT_OF_RESOURCES; } // // Done, return status code EFI_SUCCESS // return EFI_SUCCESS; }