TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiShellDebug1CommandsLib.c
Go to the documentation of this file.
1
11
12STATIC CONST CHAR16 mFileName[] = L"Debug1Commands";
13EFI_HII_HANDLE gShellDebug1HiiHandle = NULL;
14
21CONST CHAR16 *
22EFIAPI
24 VOID
25 )
26{
27 return (mFileName);
28}
29
40EFIAPI
42 IN EFI_HANDLE ImageHandle,
43 IN EFI_SYSTEM_TABLE *SystemTable
44 )
45{
46 //
47 // check our bit of the profiles mask
48 //
49 if ((PcdGet8 (PcdShellProfileMask) & BIT1) == 0) {
50 return (EFI_SUCCESS);
51 }
52
53 //
54 // install the HII stuff.
55 //
56 gShellDebug1HiiHandle = HiiAddPackages (&gShellDebug1HiiGuid, gImageHandle, UefiShellDebug1CommandsLibStrings, NULL);
57 if (gShellDebug1HiiHandle == NULL) {
58 return (EFI_DEVICE_ERROR);
59 }
60
61 //
62 // install our shell command handlers that are always installed
63 //
64 ShellCommandRegisterCommandName (L"setsize", ShellCommandRunSetSize, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_SETSIZE));
65 ShellCommandRegisterCommandName (L"comp", ShellCommandRunComp, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_COMP));
66 ShellCommandRegisterCommandName (L"mode", ShellCommandRunMode, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_MODE));
67 ShellCommandRegisterCommandName (L"memmap", ShellCommandRunMemMap, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_MEMMAP));
68 ShellCommandRegisterCommandName (L"eficompress", ShellCommandRunEfiCompress, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_EFICOMPRESS));
69 ShellCommandRegisterCommandName (L"efidecompress", ShellCommandRunEfiDecompress, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_EFIDCOMPRESS));
70 ShellCommandRegisterCommandName (L"dmem", ShellCommandRunDmem, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_DMEM));
71 ShellCommandRegisterCommandName (L"loadpcirom", ShellCommandRunLoadPciRom, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_LOAD_PCI_ROM));
72 ShellCommandRegisterCommandName (L"mm", ShellCommandRunMm, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_MM));
73 ShellCommandRegisterCommandName (L"setvar", ShellCommandRunSetVar, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_SETVAR));
74 ShellCommandRegisterCommandName (L"sermode", ShellCommandRunSerMode, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_SERMODE));
75 ShellCommandRegisterCommandName (L"pci", ShellCommandRunPci, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_PCI));
76 ShellCommandRegisterCommandName (L"smbiosview", ShellCommandRunSmbiosView, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_SMBIOSVIEW));
77 ShellCommandRegisterCommandName (L"dmpstore", ShellCommandRunDmpStore, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_DMPSTORE));
78 ShellCommandRegisterCommandName (L"dblk", ShellCommandRunDblk, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_DBLK));
79 ShellCommandRegisterCommandName (L"edit", ShellCommandRunEdit, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_EDIT));
80 ShellCommandRegisterCommandName (L"hexedit", ShellCommandRunHexEdit, ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN (STR_GET_HELP_HEXEDIT));
81
82 ShellCommandRegisterAlias (L"dmem", L"mem");
83
84 BcfgLibraryRegisterBcfgCommand (ImageHandle, SystemTable, L"Debug1");
85
86 return (EFI_SUCCESS);
87}
88
96EFIAPI
98 IN EFI_HANDLE ImageHandle,
99 IN EFI_SYSTEM_TABLE *SystemTable
100 )
101{
102 if (gShellDebug1HiiHandle != NULL) {
103 HiiRemovePackages (gShellDebug1HiiHandle);
104 }
105
106 BcfgLibraryUnregisterBcfgCommand (ImageHandle, SystemTable);
107 return (EFI_SUCCESS);
108}
109
122 IN EFI_GUID *TableGuid,
123 IN OUT VOID **Table
124 )
125{
126 UINTN Index;
127
128 ASSERT (Table != NULL);
129
130 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
131 if (CompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {
132 *Table = gST->ConfigurationTable[Index].VendorTable;
133 return EFI_SUCCESS;
134 }
135 }
136
137 return EFI_NOT_FOUND;
138}
139
147VOID
149 IN UINTN Row,
150 IN UINTN LastCol,
151 IN UINTN LastRow
152 )
153{
154 UINTN Col;
155 CHAR16 Line[200];
156
157 if (Row == 0) {
158 Row = 1;
159 }
160
161 //
162 // prepare a blank line
163 // If max column is larger, split to multiple prints.
164 //
165 SetMem16 (Line, sizeof (Line), L' ');
166 Line[ARRAY_SIZE (Line) - 1] = CHAR_NULL;
167
168 for (Col = 1; Col <= LastCol; Col += ARRAY_SIZE (Line) - 1) {
169 if (Col + ARRAY_SIZE (Line) - 1 > LastCol) {
170 if (Row == LastRow) {
171 //
172 // if CHAR_NULL is still at position LastCol, it will cause first line error
173 //
174 Line[(LastCol - 1) % (ARRAY_SIZE (Line) - 1)] = CHAR_NULL;
175 } else {
176 Line[LastCol % (ARRAY_SIZE (Line) - 1)] = CHAR_NULL;
177 }
178 }
179
180 //
181 // print out the blank line
182 //
183 ShellPrintEx ((INT32)Col - 1, (INT32)Row - 1, Line);
184 }
185}
186
195BOOLEAN
197 IN CONST CHAR16 Ch
198 )
199{
200 //
201 // See if there are any illegal characters within the name
202 //
203 if ((Ch < 0x20) || (Ch == L'\"') || (Ch == L'*') || (Ch == L'/') || (Ch == L'<') || (Ch == L'>') || (Ch == L'?') || (Ch == L'|')) {
204 return FALSE;
205 }
206
207 return TRUE;
208}
209
218BOOLEAN
220 IN CONST CHAR16 *Name
221 )
222{
223 UINTN Index;
224 UINTN Len;
225
226 //
227 // check the length of Name
228 //
229 for (Len = 0, Index = StrLen (Name) - 1; Index + 1 != 0; Index--, Len++) {
230 if ((Name[Index] == '\\') || (Name[Index] == ':')) {
231 break;
232 }
233 }
234
235 if ((Len == 0) || (Len > 255)) {
236 return FALSE;
237 }
238
239 //
240 // check whether any char in Name not appears in valid file name char
241 //
242 for (Index = 0; Index < StrLen (Name); Index++) {
243 if (!IsValidFileNameChar (Name[Index])) {
244 return FALSE;
245 }
246 }
247
248 return TRUE;
249}
250
259CHAR16 *
261 IN CONST CHAR16 *Extension
262 )
263{
264 EFI_STATUS Status;
265 UINTN Suffix;
266 CHAR16 *FileNameTmp;
267
268 Suffix = 0;
269
270 do {
271 FileNameTmp = CatSPrint (NULL, L"NewFile%d.%s", Suffix, Extension);
272 if (FileNameTmp == NULL) {
273 ASSERT (FileNameTmp != NULL);
274 return NULL;
275 }
276
277 //
278 // after that filename changed to path
279 //
280 Status = ShellFileExists (FileNameTmp);
281
282 if (Status == EFI_NOT_FOUND) {
283 return FileNameTmp;
284 }
285
286 FreePool (FileNameTmp);
287 FileNameTmp = NULL;
288 Suffix++;
289 } while (Suffix != 0);
290
291 FreePool (FileNameTmp);
292 return NULL;
293}
294
318 IN CONST CHAR16 *FileName,
319 OUT VOID **Buffer,
320 OUT UINTN *BufferSize OPTIONAL,
321 OUT BOOLEAN *ReadOnly
322 )
323{
324 VOID *InternalBuffer;
325 UINTN FileSize;
326 SHELL_FILE_HANDLE FileHandle;
327 BOOLEAN CreateFile;
328 EFI_STATUS Status;
329 EFI_FILE_INFO *Info;
330
331 InternalBuffer = NULL;
332 FileSize = 0;
333 FileHandle = NULL;
334 CreateFile = FALSE;
335 Status = EFI_SUCCESS;
336 Info = NULL;
337
338 if ((FileName == NULL) || (Buffer == NULL) || (ReadOnly == NULL)) {
339 return (EFI_INVALID_PARAMETER);
340 }
341
342 //
343 // try to open the file
344 //
345 Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
346
347 if (!EFI_ERROR (Status)) {
348 ASSERT (CreateFile == FALSE);
349 if (FileHandle == NULL) {
350 return EFI_LOAD_ERROR;
351 }
352
353 Info = ShellGetFileInfo (FileHandle);
354
355 if (Info->Attribute & EFI_FILE_DIRECTORY) {
356 FreePool (Info);
357 return EFI_INVALID_PARAMETER;
358 }
359
360 if (Info->Attribute & EFI_FILE_READ_ONLY) {
361 *ReadOnly = TRUE;
362 } else {
363 *ReadOnly = FALSE;
364 }
365
366 //
367 // get file size
368 //
369 FileSize = (UINTN)Info->FileSize;
370
371 FreePool (Info);
372 } else if (Status == EFI_NOT_FOUND) {
373 //
374 // file not exists. add create and try again
375 //
376 Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
377 if (EFI_ERROR (Status)) {
378 return Status;
379 } else {
380 //
381 // it worked. now delete it and move on with the name (now validated)
382 //
383 Status = ShellDeleteFile (&FileHandle);
384 if (Status == EFI_WARN_DELETE_FAILURE) {
385 Status = EFI_ACCESS_DENIED;
386 }
387
388 if (EFI_ERROR (Status)) {
389 return Status;
390 }
391 }
392
393 //
394 // file doesn't exist, so set CreateFile to TRUE and can't be read-only
395 //
396 CreateFile = TRUE;
397 *ReadOnly = FALSE;
398 }
399
400 //
401 // the file exists
402 //
403 if (!CreateFile) {
404 //
405 // allocate buffer to read file
406 //
407 InternalBuffer = AllocateZeroPool (FileSize);
408 if (InternalBuffer == NULL) {
409 return EFI_OUT_OF_RESOURCES;
410 }
411
412 //
413 // read file into InternalBuffer
414 //
415 Status = ShellReadFile (FileHandle, &FileSize, InternalBuffer);
416 ShellCloseFile (&FileHandle);
417 FileHandle = NULL;
418 if (EFI_ERROR (Status)) {
419 SHELL_FREE_NON_NULL (InternalBuffer);
420 return EFI_LOAD_ERROR;
421 }
422 }
423
424 *Buffer = InternalBuffer;
425 if (BufferSize != NULL) {
426 *BufferSize = FileSize;
427 }
428
429 return (EFI_SUCCESS);
430}
UINT64 UINTN
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI SetMem16(OUT VOID *Buffer, IN UINTN Length, IN UINT16 Value)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS EFIAPI BcfgLibraryUnregisterBcfgCommand(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI BcfgLibraryRegisterBcfgCommand(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable, IN CONST CHAR16 *Name)
SHELL_STATUS EFIAPI ShellCommandRunComp(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Comp.c:202
SHELL_STATUS EFIAPI ShellCommandRunDblk(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Dblk.c:98
SHELL_STATUS EFIAPI ShellCommandRunDmem(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Dmem.c:359
SHELL_STATUS EFIAPI ShellCommandRunDmpStore(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: DmpStore.c:747
SHELL_STATUS EFIAPI ShellCommandRunEdit(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Edit.c:21
SHELL_STATUS EFIAPI ShellCommandRunEfiCompress(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: EfiCompress.c:21
SHELL_STATUS EFIAPI ShellCommandRunEfiDecompress(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: EfiDecompress.c:21
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
SHELL_STATUS EFIAPI ShellCommandRunHexEdit(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: HexEdit.c:31
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
Definition: HiiLib.c:141
VOID EFIAPI HiiRemovePackages(IN EFI_HII_HANDLE HiiHandle)
Definition: HiiLib.c:253
SHELL_STATUS EFIAPI ShellCommandRunLoadPciRom(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: LoadPciRom.c:60
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
SHELL_STATUS EFIAPI ShellCommandRunMemMap(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: MemMap.c:110
SHELL_STATUS EFIAPI ShellCommandRunMm(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Mm.c:417
SHELL_STATUS EFIAPI ShellCommandRunMode(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Mode.c:20
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
SHELL_STATUS EFIAPI ShellCommandRunPci(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Pci.c:2435
SHELL_STATUS EFIAPI ShellCommandRunSerMode(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: SerMode.c:164
SHELL_STATUS EFIAPI ShellCommandRunSetSize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: SetSize.c:20
SHELL_STATUS EFIAPI ShellCommandRunSetVar(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: SetVar.c:352
RETURN_STATUS EFIAPI ShellCommandRegisterCommandName(IN CONST CHAR16 *CommandString, IN SHELL_RUN_COMMAND CommandHandler, IN SHELL_GET_MAN_FILENAME GetManFileName, IN UINT32 ShellMinSupportLevel, IN CONST CHAR16 *ProfileName, IN CONST BOOLEAN CanAffectLE, IN CONST EFI_HII_HANDLE HiiHandle, IN CONST EFI_STRING_ID ManFormatHelp)
RETURN_STATUS EFIAPI ShellCommandRegisterAlias(IN CONST CHAR16 *Command, IN CONST CHAR16 *Alias)
EFI_FILE_INFO *EFIAPI ShellGetFileInfo(IN SHELL_FILE_HANDLE FileHandle)
Definition: UefiShellLib.c:573
EFI_STATUS EFIAPI ShellDeleteFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:992
EFI_STATUS EFIAPI ShellOpenFileByName(IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiShellLib.c:720
EFI_STATUS EFIAPI ShellFileExists(IN CONST CHAR16 *Name)
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
EFI_STATUS EFIAPI ShellCloseFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:969
EFI_STATUS EFIAPI ShellReadFile(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
Definition: UefiShellLib.c:912
SHELL_STATUS EFIAPI ShellCommandRunSmbiosView(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: SmbiosView.c:43
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_HANDLE gImageHandle
#define STRING_TOKEN(t)
VOID * EFI_HII_HANDLE
CHAR16 *EFIAPI CatSPrint(IN CHAR16 *String OPTIONAL, IN CONST CHAR16 *FormatString,...)
Definition: UefiLibPrint.c:827
EFI_STATUS EFIAPI UefiShellDebug1CommandsLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS GetSystemConfigurationTable(IN EFI_GUID *TableGuid, IN OUT VOID **Table)
BOOLEAN IsValidFileName(IN CONST CHAR16 *Name)
CONST CHAR16 *EFIAPI ShellCommandGetManFileNameDebug1(VOID)
CHAR16 * EditGetDefaultFileName(IN CONST CHAR16 *Extension)
BOOLEAN IsValidFileNameChar(IN CONST CHAR16 Ch)
EFI_STATUS ReadFileIntoBuffer(IN CONST CHAR16 *FileName, OUT VOID **Buffer, OUT UINTN *BufferSize OPTIONAL, OUT BOOLEAN *ReadOnly)
VOID EditorClearLine(IN UINTN Row, IN UINTN LastCol, IN UINTN LastRow)
EFI_STATUS EFIAPI UefiShellDebug1CommandsLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
UINT64 Attribute
Definition: FileInfo.h:47
UINT64 FileSize
Definition: FileInfo.h:27
EFI_CONFIGURATION_TABLE * ConfigurationTable
Definition: UefiSpec.h:2092
UINTN NumberOfTableEntries
Definition: UefiSpec.h:2087
Definition: Base.h:213