UINTN BestMatchCount;\r
UINTN Length;\r
EBL_COMMAND_TABLE *Match;\r
+ CHAR8 *Str;\r
\r
Length = AsciiStrLen (CommandName);\r
+ Str = AsciiStrStr (CommandName, ".");\r
+ if (Str != NULL) {\r
+ // If the command includes a trailing . command extension skip it for the match.\r
+ // Example: hexdump.4\r
+ Length = (UINTN)(Str - CommandName); \r
+ }\r
+ \r
for (Index = 0, BestMatchCount = 0, Match = NULL; Index < mCmdTableNextFreeIndex; Index++) {\r
if (AsciiStriCmp (mCmdTable[Index]->Name, CommandName) == 0) {\r
// match a command exactly\r
return EFI_SUCCESS;\r
}\r
\r
+\r
+/**\r
+ See if command contains .# where # is a number. Return # as the Width\r
+ or 1 as the default Width for commands. \r
+ \r
+ Example hexdump.4 returns a width of 4.\r
+\r
+ @param Argv Argv[0] is the comamnd name\r
+\r
+ @return Width of command\r
+\r
+**/\r
+UINTN\r
+WidthFromCommandName (\r
+ IN CHAR8 *Argv,\r
+ IN UINTN Default\r
+ )\r
+{\r
+ CHAR8 *Str;\r
+ UINTN Width;\r
+ \r
+ //Hexdump.2 HexDump.4 mean use a different width\r
+ Str = AsciiStrStr (Argv, ".");\r
+ if (Str != NULL) {\r
+ Width = AsciiStrDecimalToUintn (Str + 1);\r
+ if (Width == 0) {\r
+ Width = Default;\r
+ }\r
+ } else {\r
+ // Default answer\r
+ return Default;\r
+ }\r
+\r
+ return Width;\r
+}\r
+\r
#define HEXDUMP_CHUNK 1024\r
\r
+/**\r
+ Toggle page break global. This turns on and off prompting to Quit or hit any\r
+ key to continue when a command is about to scroll the screen with its output\r
+\r
+ Argv[0] - "hexdump"[.#] # is optional 1,2, or 4 for width \r
+ Argv[1] - Device or File to dump. \r
+ Argv[2] - Optional offset to start dumping\r
+ Argv[3] - Optional number of bytes to dump\r
+\r
+ @param Argc Number of command arguments in Argv\r
+ @param Argv Array of strings that represent the parsed command line. \r
+ Argv[0] is the comamnd name\r
+\r
+ @return EFI_SUCCESS\r
+\r
+**/\r
EFI_STATUS\r
EblHexdumpCmd (\r
IN UINTN Argc,\r
EFI_OPEN_FILE *File;\r
VOID *Location;\r
UINTN Size;\r
- UINTN Width = 1;\r
+ UINTN Width;\r
UINTN Offset = 0;\r
EFI_STATUS Status;\r
UINTN Chunk = HEXDUMP_CHUNK;\r
\r
- if ((Argc < 2) || (Argc > 3)) {\r
+ if ((Argc < 2) || (Argc > 4)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if (Argc == 3) {\r
- Width = AsciiStrDecimalToUintn(Argv[2]);\r
- }\r
- \r
+ Width = WidthFromCommandName (Argv[0], 1);\r
if ((Width != 1) && (Width != 2) && (Width != 4)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
}\r
\r
Location = AllocatePool (Chunk);\r
- Size = EfiTell(File, NULL);\r
+ Size = (Argc > 3) ? AsciiStrHexToUintn (Argv[3]) : EfiTell (File, NULL);\r
+\r
+ Offset = 0;\r
+ if (Argc > 2) {\r
+ Offset = AsciiStrHexToUintn (Argv[2]);\r
+ if (Offset > 0) {\r
+ // Make sure size includes the part of the file we have skipped\r
+ Size += Offset;\r
+ }\r
+ } \r
\r
- for (Offset = 0; Offset + HEXDUMP_CHUNK <= Size; Offset += Chunk) {\r
+ Status = EfiSeek (File, Offset, EfiSeekStart);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Exit;\r
+ }\r
+ \r
+ for (; Offset + HEXDUMP_CHUNK <= Size; Offset += Chunk) {\r
Chunk = HEXDUMP_CHUNK;\r
- \r
Status = EfiRead (File, Location, &Chunk);\r
- if (EFI_ERROR(Status))\r
- {\r
+ if (EFI_ERROR(Status)) {\r
AsciiPrint ("Error reading file content\n");\r
goto Exit;\r
}\r
},\r
{\r
"hexdump",\r
- " filename ; dump a file as hex bytes",\r
+ "[.{1|2|4}] filename [Offset] [Size]; dump a file as hex bytes at a given width",\r
NULL,\r
EblHexdumpCmd\r
}\r