X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=EmbeddedPkg%2FEbl%2FCommand.c;h=e75c6a2e5c32cc8fd794b7e685776b35d6ef453d;hb=6f6bf5c77214ae2449bffbe36c33faeca4663e01;hp=3efe6ee671e6e6e1376055d374eb9c59b165024e;hpb=a6d7123ebc57243b405fa12cf5a6e2da9eb73895;p=mirror_edk2.git diff --git a/EmbeddedPkg/Ebl/Command.c b/EmbeddedPkg/Ebl/Command.c index 3efe6ee671..e75c6a2e5c 100644 --- a/EmbeddedPkg/Ebl/Command.c +++ b/EmbeddedPkg/Ebl/Command.c @@ -1,10 +1,11 @@ /** @file Basic commands and command processing infrastructure for EBL - Copyright (c) 2007, Intel Corporation
- Portions copyright (c) 2008-2009, Apple Inc. All rights reserved. + Copyright (c) 2007, Intel Corporation. All rights reserved.
+ Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+ (C) Copyright 2015 Hewlett Packard Enterprise Development LP
- All rights reserved. This program and the accompanying materials + This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -32,7 +33,7 @@ EBL_COMMAND_TABLE *mCmdTable[EBL_MAX_COMMAND_COUNT]; @param chr one Ascii character - @return The uppercase value of Ascii character + @return The uppercase value of Ascii character **/ STATIC @@ -46,7 +47,7 @@ AsciiToUpper ( /** - Case insensitve comparison of two Null-terminated Unicode strings with maximum + Case insensitive comparison of two Null-terminated Unicode strings with maximum lengths, and returns the difference between the first mismatched Unicode characters. This function compares the Null-terminated Unicode string FirstString to the @@ -55,11 +56,11 @@ AsciiToUpper ( FirstString is identical to SecondString, then 0 is returned. Otherwise, the value returned is the first mismatched Unicode character in SecondString subtracted from the first mismatched Unicode character in FirstString. - - @param FirstString Pointer to a Null-terminated ASCII string. + + @param FirstString Pointer to a Null-terminated ASCII string. @param SecondString Pointer to a Null-terminated ASCII string. @param Length Max length to compare. - + @retval 0 FirstString is identical to SecondString using case insensitive comparisons. @retval !=0 FirstString is not identical to SecondString using case @@ -85,18 +86,18 @@ AsciiStrniCmp ( SecondString++; Length--; } - + return AsciiToUpper (*FirstString) - AsciiToUpper (*SecondString); } /** - Add a command to the mCmdTable. If there is no free space in the command - table ASSERT. The mCmdTable is maintained in alphabetical order and the - new entry is inserted into its sorted possition. + Add a command to the mCmdTable. If there is no free space in the command + table ASSERT. The mCmdTable is maintained in alphabetical order and the + new entry is inserted into its sorted position. - @param Entry Commnad Entry to add to the CmdTable + @param Entry Command Entry to add to the CmdTable **/ VOID @@ -124,7 +125,7 @@ EblAddCommand ( if (AsciiStriCmp (mCmdTable[Count - 1]->Name, Entry->Name) <= 0) { break; } - + mCmdTable[Count] = mCmdTable[Count - 1]; } mCmdTable[Count] = (EBL_COMMAND_TABLE *)Entry; @@ -135,11 +136,11 @@ EblAddCommand ( /** - Add an set of commands to the command table. Most commonly used on static + Add an set of commands to the command table. Most commonly used on static array of commands. @param EntryArray Pointer to array of command entries - @param ArrayCount Number of commnad entries to add + @param ArrayCount Number of command entries to add **/ VOID @@ -167,9 +168,9 @@ EBL_ADD_COMMAND_PROTOCOL gEblAddCommand = { /** - Return the best matching command for the passed in command name. The match - does not have to be exact, it just needs to be unqiue. This enables commands - to be shortend to the smallest set of starting characters that is unique. + Return the best matching command for the passed in command name. The match + does not have to be exact, it just needs to be unique. This enables commands + to be shortened to the smallest set of starting characters that is unique. @param CommandName Name of command to search for @@ -193,9 +194,9 @@ EblGetCommand ( if (Str != NULL) { // If the command includes a trailing . command extension skip it for the match. // Example: hexdump.4 - Length = (UINTN)(Str - CommandName); + Length = (UINTN)(Str - CommandName); } - + for (Index = 0, BestMatchCount = 0, Match = NULL; Index < mCmdTableNextFreeIndex; Index++) { if (AsciiStriCmp (mCmdTable[Index]->Name, CommandName) == 0) { // match a command exactly @@ -220,22 +221,43 @@ EblGetCommand ( } +UINTN +CountNewLines ( + IN CHAR8 *Str + ) +{ + UINTN Count; + + if (Str == NULL) { + return 0; + } + + for (Count = 0; *Str != '\0'; Str++) { + if (Str[Count] == '\n') { + Count++; + } + } + + return Count; +} + /** - List out help information on all the commands or print extended information + List out help information on all the commands or print extended information about a specific passed in command. Argv[0] - "help" Argv[1] - Command to display help about @param Argc Number of command arguments in Argv - @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + @param Argv Array of strings that represent the parsed command line. + Argv[0] is the command name @return EFI_SUCCESS **/ EFI_STATUS +EFIAPI EblHelpCmd ( IN UINTN Argc, IN CHAR8 **Argv @@ -243,23 +265,31 @@ EblHelpCmd ( { UINTN Index; CHAR8 *Ptr; - UINTN CurrentRow; + UINTN CurrentRow = 0; if (Argc == 1) { // Print all the commands AsciiPrint ("Embedded Boot Loader (EBL) commands (help command for more info):\n"); + CurrentRow++; for (Index = 0; Index < mCmdTableNextFreeIndex; Index++) { EblSetTextColor (EFI_YELLOW); AsciiPrint (" %a", mCmdTable[Index]->Name); EblSetTextColor (0); AsciiPrint ("%a\n", mCmdTable[Index]->HelpSummary); + // Handle multi line help summaries + CurrentRow += CountNewLines (mCmdTable[Index]->HelpSummary); + if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) { + break; + } } } else if (Argv[1] != NULL) { - // Print specific help + // Print specific help for (Index = 0, CurrentRow = 0; Index < mCmdTableNextFreeIndex; Index++) { if (AsciiStriCmp (Argv[1], mCmdTable[Index]->Name) == 0) { Ptr = (mCmdTable[Index]->Help == NULL) ? mCmdTable[Index]->HelpSummary : mCmdTable[Index]->Help; AsciiPrint ("%a%a\n", Argv[1], Ptr); + // Handle multi line help summaries + CurrentRow += CountNewLines (Ptr); if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) { break; } @@ -272,19 +302,20 @@ EblHelpCmd ( /** - Exit the EBL. If the commnad processor sees EFI_ABORTED return status it will + Exit the EBL. If the command processor sees EFI_ABORTED return status it will exit the EBL. Argv[0] - "exit" @param Argc Number of command arguments in Argv - @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + @param Argv Array of strings that represent the parsed command line. + Argv[0] is the command name @return EFI_ABORTED **/ EFI_STATUS +EFIAPI EblExitCmd ( IN UINTN Argc, IN CHAR8 **Argv @@ -298,14 +329,14 @@ EblExitCmd ( UINT32 DescriptorVersion; UINTN Pages; - if (Argc > 1) { + if (Argc > 1) { if (AsciiStriCmp (Argv[1], "efi") != 0) { return EFI_ABORTED; } } else if (Argc == 1) { return EFI_ABORTED; } - + MemoryMap = NULL; MemoryMapSize = 0; do { @@ -320,7 +351,7 @@ EblExitCmd ( Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1; MemoryMap = AllocatePages (Pages); - + // // Get System MemoryMap // @@ -347,9 +378,9 @@ EblExitCmd ( // At this point it is very dangerous to do things EFI as most of EFI is now gone. // This command is useful if you are working with a debugger as it will shutdown // DMA and other things that could break a soft resets. - // + // CpuDeadLoop (); - + // Should never get here, but makes the compiler happy return EFI_ABORTED; } @@ -357,10 +388,10 @@ EblExitCmd ( /** Update the screen by decrementing the timeout value. - This AsciiPrint has to match the AsciiPrint in - EblPauseCmd. + This AsciiPrint has to match the AsciiPrint in + EblPauseCmd. - @param ElaspedTime Current timout value remaining + @param ElaspedTime Current timeout value remaining **/ VOID @@ -382,14 +413,15 @@ EblPauseCallback ( Argv[1] - timeout value is decimal seconds @param Argc Number of command arguments in Argv - @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + @param Argv Array of strings that represent the parsed command line. + Argv[0] is the command name @return EFI_SUCCESS Timeout expired with no input - @return EFI_TIMEOUT Stop procesing other commands on the same command line + @return EFI_TIMEOUT Stop processing other commands on the same command line **/ EFI_STATUS +EFIAPI EblPauseCmd ( IN UINTN Argc, IN CHAR8 **Argv @@ -405,8 +437,8 @@ EblPauseCmd ( Status = EblGetCharKey (&Key, Delay, EblPauseCallback); AsciiPrint ("\n"); - // If we timeout then the pause succeded thus return success - // If we get a key return timout to stop other commnad on this cmd line + // If we timeout then the pause succeeded thus return success + // If we get a key return timeout to stop other command on this cmd line return (Status == EFI_SUCCESS) ? EFI_TIMEOUT : EFI_SUCCESS;; } @@ -417,13 +449,14 @@ EblPauseCmd ( Argv[0] - "break" @param Argc Number of command arguments in Argv - @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + @param Argv Array of strings that represent the parsed command line. + Argv[0] is the command name @return EFI_SUCCESS **/ EFI_STATUS +EFIAPI EblBreakPointCmd ( IN UINTN Argc, IN CHAR8 **Argv @@ -443,13 +476,14 @@ EblBreakPointCmd ( Argv[1] - warm or shutdown reset type @param Argc Number of command arguments in Argv - @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + @param Argv Array of strings that represent the parsed command line. + Argv[0] is the command name @return EFI_SUCCESS **/ EFI_STATUS +EFIAPI EblResetCmd ( IN UINTN Argc, IN CHAR8 **Argv @@ -468,7 +502,7 @@ EblResetCmd ( case 's': ResetType = EfiResetShutdown; } - } + } gRT->ResetSystem (ResetType, EFI_SUCCESS, 0, NULL); return EFI_SUCCESS; @@ -483,20 +517,21 @@ EblResetCmd ( Argv[1] - on or off @param Argc Number of command arguments in Argv - @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + @param Argv Array of strings that represent the parsed command line. + Argv[0] is the command name @return EFI_SUCCESS **/ EFI_STATUS +EFIAPI EblPageCmd ( IN UINTN Argc, IN CHAR8 **Argv ) { if (Argc <= 1) { - // toggle setting + // toggle setting gPageBreak = (gPageBreak) ? FALSE : TRUE; } else { // use argv to set the value @@ -514,6 +549,7 @@ EblPageCmd ( } EFI_STATUS +EFIAPI EblSleepCmd ( IN UINTN Argc, IN CHAR8 **Argv @@ -553,7 +589,7 @@ GetBytes ( } if (Bytes >= 2) { Result = (Result << 8) + *Address++; - } + } if (Bytes >= 3) { Result = (Result << 8) + *Address++; } @@ -583,7 +619,7 @@ OutputData ( AsciiPrint ("%08x: ", Offset); for (Line = 0; (Line < 0x10) && (Address < EndAddress);) { Bytes = EndAddress - Address; - + switch (Width) { case 4: if (Bytes >= 4) { @@ -616,9 +652,9 @@ OutputData ( TextLine[Line++] = ConvertToTextLine(*Address++); break; - default: - AsciiPrint ("Width must be 1, 2, or 4!\n"); - return EFI_INVALID_PARAMETER; + default: + AsciiPrint ("Width must be 1, 2, or 4!\n"); + return EFI_INVALID_PARAMETER; } } @@ -639,7 +675,7 @@ OutputData ( Blanks[Spaces] = '\0'; AsciiPrint(Blanks); - + Blanks[Spaces] = ' '; } @@ -654,18 +690,18 @@ OutputData ( if (Length % Width != 0) { AsciiPrint ("%08x\n", Offset); } - + return EFI_SUCCESS; } /** See if command contains .# where # is a number. Return # as the Width - or 1 as the default Width for commands. - + or 1 as the default Width for commands. + Example hexdump.4 returns a width of 4. - @param Argv Argv[0] is the comamnd name + @param Argv Argv[0] is the command name @return Width of command @@ -678,7 +714,7 @@ WidthFromCommandName ( { CHAR8 *Str; UINTN Width; - + //Hexdump.2 HexDump.4 mean use a different width Str = AsciiStrStr (Argv, "."); if (Str != NULL) { @@ -700,19 +736,20 @@ WidthFromCommandName ( Toggle page break global. This turns on and off prompting to Quit or hit any key to continue when a command is about to scroll the screen with its output - Argv[0] - "hexdump"[.#] # is optional 1,2, or 4 for width - Argv[1] - Device or File to dump. + Argv[0] - "hexdump"[.#] # is optional 1,2, or 4 for width + Argv[1] - Device or File to dump. Argv[2] - Optional offset to start dumping Argv[3] - Optional number of bytes to dump @param Argc Number of command arguments in Argv - @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + @param Argv Array of strings that represent the parsed command line. + Argv[0] is the command name @return EFI_SUCCESS **/ EFI_STATUS +EFIAPI EblHexdumpCmd ( IN UINTN Argc, IN CHAR8 **Argv @@ -729,7 +766,7 @@ EblHexdumpCmd ( if ((Argc < 2) || (Argc > 4)) { return EFI_INVALID_PARAMETER; } - + Width = WidthFromCommandName (Argv[0], 1); if ((Width != 1) && (Width != 2) && (Width != 4)) { return EFI_INVALID_PARAMETER; @@ -750,13 +787,13 @@ EblHexdumpCmd ( // Make sure size includes the part of the file we have skipped Size += Offset; } - } + } Status = EfiSeek (File, Offset, EfiSeekStart); if (EFI_ERROR (Status)) { goto Exit; } - + for (; Offset + HEXDUMP_CHUNK <= Size; Offset += Chunk) { Chunk = HEXDUMP_CHUNK; Status = EfiRead (File, Location, &Chunk); @@ -773,7 +810,7 @@ EblHexdumpCmd ( goto Exit; } } - + // Any left over? if (Offset < Size) { Chunk = Size - Offset; @@ -847,7 +884,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdTemplate[] = }, { "hexdump", - "[.{1|2|4}] filename [Offset] [Size]; dump a file as hex bytes at a given width", + "[.{1|2|4}] filename [Offset] [Size]; dump a file as hex .width", NULL, EblHexdumpCmd } @@ -866,7 +903,7 @@ EblInitializeCmdTable ( { EblAddCommands (mCmdTemplate, sizeof (mCmdTemplate)/sizeof (EBL_COMMAND_TABLE)); - + gBS->InstallProtocolInterface ( &gExternalCmdHandle, &gEfiEblAddCommandProtocolGuid,