2 Main file for DmpStore shell Debug1 function.
4 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellDebug1CommandsLib.h"
18 #define INIT_NAME_BUFFER_SIZE 128
19 #define INIT_DATA_BUFFER_SIZE 1024
20 #define INIT_ATTS_BUFFER_SIZE 64
26 IN OUT CHAR16
*RetString
29 StrCpy(RetString
, L
"");
31 if (Atts
& EFI_VARIABLE_NON_VOLATILE
) {
32 StrCat(RetString
, L
"+NV");
34 if (Atts
& EFI_VARIABLE_RUNTIME_ACCESS
) {
35 StrCat(RetString
, L
"+RS+BS");
36 } else if (Atts
& EFI_VARIABLE_BOOTSERVICE_ACCESS
) {
37 StrCat(RetString
, L
"+BS");
39 if (Atts
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) {
40 StrCat(RetString
, L
"+HR");
42 if (Atts
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) {
43 StrCat(RetString
, L
"+AW");
45 if (Atts
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) {
46 StrCat(RetString
, L
"+AT");
49 if (RetString
[0] == L
'+') {
52 if (RetString
[0] == CHAR_NULL
) {
53 StrCpy(RetString
, L
"invalid");
60 Function to display or delete variables.
62 @param[in] VariableName The variable name of the EFI variable (or NULL).
63 @param[in] Guid The GUID of the variable set (or NULL).
64 @param[in] Delete TRUE to delete, FALSE otherwise.
66 @retval SHELL_SUCCESS The operation was successful.
67 @retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
68 @retval SHELL_ABORTED The abort message was received.
69 @retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
70 @retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
75 IN CONST CHAR16
*VariableName OPTIONAL
,
76 IN CONST EFI_GUID
*Guid OPTIONAL
,
82 EFI_GUID FoundVarGuid
;
86 SHELL_STATUS ShellStatus
;
88 UINTN NameBufferSize
; // Allocated Name buffer size
91 UINTN OldNameBufferSize
;
92 UINTN DataBufferSize
; // Allocated data buffer size
93 CHAR16 RetString
[INIT_ATTS_BUFFER_SIZE
];
96 ShellStatus
= SHELL_SUCCESS
;
99 NameBufferSize
= INIT_NAME_BUFFER_SIZE
;
100 DataBufferSize
= INIT_DATA_BUFFER_SIZE
;
101 FoundVarName
= AllocateZeroPool (NameBufferSize
);
102 if (FoundVarName
== NULL
) {
103 return (SHELL_OUT_OF_RESOURCES
);
105 DataBuffer
= AllocatePool (DataBufferSize
);
106 if (DataBuffer
== NULL
) {
107 FreePool (FoundVarName
);
108 return (SHELL_OUT_OF_RESOURCES
);
112 if (ShellGetExecutionBreakFlag()) {
113 ShellStatus
= SHELL_ABORTED
;
117 NameSize
= NameBufferSize
;
118 Status
= gRT
->GetNextVariableName (&NameSize
, FoundVarName
, &FoundVarGuid
);
119 if (Status
== EFI_BUFFER_TOO_SMALL
) {
120 OldName
= FoundVarName
;
121 OldNameBufferSize
= NameBufferSize
;
123 // Expand at least twice to avoid reallocate many times
125 NameBufferSize
= NameSize
> NameBufferSize
* 2 ? NameSize
: NameBufferSize
* 2;
126 FoundVarName
= AllocateZeroPool (NameBufferSize
);
127 if (FoundVarName
== NULL
) {
128 Status
= EFI_OUT_OF_RESOURCES
;
133 // Preserve the original content to get correct iteration for GetNextVariableName() call
135 CopyMem (FoundVarName
, OldName
, OldNameBufferSize
);
137 NameSize
= NameBufferSize
;
138 Status
= gRT
->GetNextVariableName (&NameSize
, FoundVarName
, &FoundVarGuid
);
140 if (Status
== EFI_NOT_FOUND
) {
143 ASSERT_EFI_ERROR(Status
);
146 // Check if it matches
148 if (VariableName
!= NULL
) {
149 if (!gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, FoundVarName
, (CHAR16
*)VariableName
)) {
154 if (!CompareGuid(&FoundVarGuid
, Guid
)) {
159 DataSize
= DataBufferSize
;
160 Status
= gRT
->GetVariable (FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
161 if (Status
== EFI_BUFFER_TOO_SMALL
) {
163 // Expand at least twice to avoid reallocate many times
165 FreePool (DataBuffer
);
166 DataBufferSize
= DataSize
> DataBufferSize
* 2 ? DataSize
: DataBufferSize
* 2;
167 DataBuffer
= AllocatePool (DataBufferSize
);
168 if (DataBuffer
== NULL
) {
169 Status
= EFI_OUT_OF_RESOURCES
;
172 DataSize
= DataBufferSize
;
173 Status
= gRT
->GetVariable (FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
175 ASSERT_EFI_ERROR(Status
);
178 // do the print or delete
186 STRING_TOKEN(STR_DMPSTORE_HEADER_LINE
),
187 gShellDebug1HiiHandle
,
188 GetAttrType(Atts
, RetString
),
192 DumpHex(2, 0, DataSize
, DataBuffer
);
198 STRING_TOKEN(STR_DMPSTORE_DELETE_LINE
),
199 gShellDebug1HiiHandle
,
206 STRING_TOKEN(STR_DMPSTORE_DELETE_DONE
),
207 gShellDebug1HiiHandle
,
208 gRT
->SetVariable(FoundVarName
, &FoundVarGuid
, Atts
, 0, NULL
));
209 FoundVarName
[0] = CHAR_NULL
;
213 if (FoundVarName
!= NULL
) {
214 FreePool(FoundVarName
);
216 if (DataBuffer
!= NULL
) {
217 FreePool(DataBuffer
);
220 if (Status
== EFI_OUT_OF_RESOURCES
) {
221 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
);
222 return SHELL_OUT_OF_RESOURCES
;
225 if (VariableName
!= NULL
&& Guid
== NULL
) {
226 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N
), gShellDebug1HiiHandle
, VariableName
);
227 } else if (VariableName
!= NULL
&& Guid
!= NULL
) {
228 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN
), gShellDebug1HiiHandle
, Guid
, VariableName
);
229 } else if (VariableName
== NULL
&& Guid
== NULL
) {
230 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND
), gShellDebug1HiiHandle
);
231 } else if (VariableName
== NULL
&& Guid
!= NULL
) {
232 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G
), gShellDebug1HiiHandle
, Guid
);
234 return (SHELL_NOT_FOUND
);
236 return (SHELL_SUCCESS
);
239 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
244 {L
"-guid", TypeValue
},
249 Function for 'dmpstore' command.
251 @param[in] ImageHandle Handle to the Image (NULL if Internal).
252 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
256 ShellCommandRunDmpStore (
257 IN EFI_HANDLE ImageHandle
,
258 IN EFI_SYSTEM_TABLE
*SystemTable
263 CHAR16
*ProblemParam
;
264 SHELL_STATUS ShellStatus
;
268 CONST CHAR16
*VariableName
;
270 ShellStatus
= SHELL_SUCCESS
;
273 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
274 if (EFI_ERROR(Status
)) {
275 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
276 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
277 FreePool(ProblemParam
);
278 ShellStatus
= SHELL_INVALID_PARAMETER
;
283 if (ShellCommandLineGetCount(Package
) > 2) {
284 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
285 ShellStatus
= SHELL_INVALID_PARAMETER
;
286 } else if (ShellCommandLineGetFlag(Package
, L
"-all") && ShellCommandLineGetFlag(Package
, L
"-guid")) {
287 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-all", L
"-guid");
288 ShellStatus
= SHELL_INVALID_PARAMETER
;
289 } else if ((ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) && ShellCommandLineGetFlag(Package
, L
"-d")) {
290 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-l or -s", L
"-d");
291 ShellStatus
= SHELL_INVALID_PARAMETER
;
293 if (!ShellCommandLineGetFlag(Package
, L
"-all")) {
294 Temp
= ShellCommandLineGetValue(Package
, L
"-guid");
296 Status
= ConvertStringToGuid(Temp
, &GuidData
);
297 if (EFI_ERROR(Status
)) {
298 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Temp
);
299 ShellStatus
= SHELL_INVALID_PARAMETER
;
303 Guid
= &gEfiGlobalVariableGuid
;
305 VariableName
= ShellCommandLineGetRawValue(Package
, 1);
310 if (ShellStatus
== SHELL_SUCCESS
) {
311 if (ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) {
312 ///@todo fix this after lib ready...
313 ShellPrintEx(-1, -1, L
"Not implemeneted yet.\r\n");
314 ShellStatus
= SHELL_UNSUPPORTED
;
316 ShellStatus
= ProcessVariables (VariableName
, Guid
, ShellCommandLineGetFlag(Package
, L
"-d"));
322 if (Package
!= NULL
) {
323 ShellCommandLineFreeVarList (Package
);