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
23 Base on the input attribute value to return the attribute string.
25 @param[in] Atts The input attribute value
26 @param[in,out] RetString The buffer to save the attribute string.
28 @retval The attribute string info.
34 IN OUT CHAR16
*RetString
37 StrCpy(RetString
, L
"");
39 if ((Atts
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
40 StrCat(RetString
, L
"+NV");
42 if ((Atts
& EFI_VARIABLE_RUNTIME_ACCESS
) != 0) {
43 StrCat(RetString
, L
"+RS+BS");
44 } else if ((Atts
& EFI_VARIABLE_BOOTSERVICE_ACCESS
) != 0) {
45 StrCat(RetString
, L
"+BS");
47 if ((Atts
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0) {
48 StrCat(RetString
, L
"+HR");
50 if ((Atts
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) != 0) {
51 StrCat(RetString
, L
"+AW");
53 if ((Atts
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) != 0) {
54 StrCat(RetString
, L
"+AT");
57 if (RetString
[0] == L
'+') {
60 if (RetString
[0] == CHAR_NULL
) {
61 StrCpy(RetString
, L
"invalid");
68 Function to display or delete variables.
70 @param[in] VariableName The variable name of the EFI variable (or NULL).
71 @param[in] Guid The GUID of the variable set (or NULL).
72 @param[in] Delete TRUE to delete, FALSE otherwise.
74 @retval SHELL_SUCCESS The operation was successful.
75 @retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
76 @retval SHELL_ABORTED The abort message was received.
77 @retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
78 @retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
83 IN CONST CHAR16
*VariableName OPTIONAL
,
84 IN CONST EFI_GUID
*Guid OPTIONAL
,
90 EFI_GUID FoundVarGuid
;
94 SHELL_STATUS ShellStatus
;
96 UINTN NameBufferSize
; // Allocated Name buffer size
99 UINTN OldNameBufferSize
;
100 UINTN DataBufferSize
; // Allocated data buffer size
101 CHAR16 RetString
[INIT_ATTS_BUFFER_SIZE
];
104 ShellStatus
= SHELL_SUCCESS
;
105 Status
= EFI_SUCCESS
;
107 NameBufferSize
= INIT_NAME_BUFFER_SIZE
;
108 DataBufferSize
= INIT_DATA_BUFFER_SIZE
;
109 FoundVarName
= AllocateZeroPool (NameBufferSize
);
110 if (FoundVarName
== NULL
) {
111 return (SHELL_OUT_OF_RESOURCES
);
113 DataBuffer
= AllocatePool (DataBufferSize
);
114 if (DataBuffer
== NULL
) {
115 FreePool (FoundVarName
);
116 return (SHELL_OUT_OF_RESOURCES
);
120 if (ShellGetExecutionBreakFlag()) {
121 ShellStatus
= SHELL_ABORTED
;
125 NameSize
= NameBufferSize
;
126 Status
= gRT
->GetNextVariableName (&NameSize
, FoundVarName
, &FoundVarGuid
);
127 if (Status
== EFI_BUFFER_TOO_SMALL
) {
128 OldName
= FoundVarName
;
129 OldNameBufferSize
= NameBufferSize
;
131 // Expand at least twice to avoid reallocate many times
133 NameBufferSize
= NameSize
> NameBufferSize
* 2 ? NameSize
: NameBufferSize
* 2;
134 FoundVarName
= AllocateZeroPool (NameBufferSize
);
135 if (FoundVarName
== NULL
) {
136 Status
= EFI_OUT_OF_RESOURCES
;
141 // Preserve the original content to get correct iteration for GetNextVariableName() call
143 CopyMem (FoundVarName
, OldName
, OldNameBufferSize
);
145 NameSize
= NameBufferSize
;
146 Status
= gRT
->GetNextVariableName (&NameSize
, FoundVarName
, &FoundVarGuid
);
148 if (Status
== EFI_NOT_FOUND
) {
151 ASSERT_EFI_ERROR(Status
);
154 // Check if it matches
156 if (VariableName
!= NULL
) {
157 if (!gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, FoundVarName
, (CHAR16
*)VariableName
)) {
162 if (!CompareGuid(&FoundVarGuid
, Guid
)) {
167 DataSize
= DataBufferSize
;
168 Status
= gRT
->GetVariable (FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
169 if (Status
== EFI_BUFFER_TOO_SMALL
) {
171 // Expand at least twice to avoid reallocate many times
173 FreePool (DataBuffer
);
174 DataBufferSize
= DataSize
> DataBufferSize
* 2 ? DataSize
: DataBufferSize
* 2;
175 DataBuffer
= AllocatePool (DataBufferSize
);
176 if (DataBuffer
== NULL
) {
177 Status
= EFI_OUT_OF_RESOURCES
;
180 DataSize
= DataBufferSize
;
181 Status
= gRT
->GetVariable (FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
183 ASSERT_EFI_ERROR(Status
);
186 // do the print or delete
194 STRING_TOKEN(STR_DMPSTORE_HEADER_LINE
),
195 gShellDebug1HiiHandle
,
196 GetAttrType(Atts
, RetString
),
200 DumpHex(2, 0, DataSize
, DataBuffer
);
206 STRING_TOKEN(STR_DMPSTORE_DELETE_LINE
),
207 gShellDebug1HiiHandle
,
214 STRING_TOKEN(STR_DMPSTORE_DELETE_DONE
),
215 gShellDebug1HiiHandle
,
216 gRT
->SetVariable(FoundVarName
, &FoundVarGuid
, Atts
, 0, NULL
));
217 FoundVarName
[0] = CHAR_NULL
;
221 if (FoundVarName
!= NULL
) {
222 FreePool(FoundVarName
);
224 if (DataBuffer
!= NULL
) {
225 FreePool(DataBuffer
);
228 if (Status
== EFI_OUT_OF_RESOURCES
) {
229 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
);
230 return SHELL_OUT_OF_RESOURCES
;
233 if (VariableName
!= NULL
&& Guid
== NULL
) {
234 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N
), gShellDebug1HiiHandle
, VariableName
);
235 } else if (VariableName
!= NULL
&& Guid
!= NULL
) {
236 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN
), gShellDebug1HiiHandle
, Guid
, VariableName
);
237 } else if (VariableName
== NULL
&& Guid
== NULL
) {
238 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND
), gShellDebug1HiiHandle
);
239 } else if (VariableName
== NULL
&& Guid
!= NULL
) {
240 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G
), gShellDebug1HiiHandle
, Guid
);
242 return (SHELL_NOT_FOUND
);
244 return (SHELL_SUCCESS
);
247 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
252 {L
"-guid", TypeValue
},
257 Function for 'dmpstore' command.
259 @param[in] ImageHandle Handle to the Image (NULL if Internal).
260 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
264 ShellCommandRunDmpStore (
265 IN EFI_HANDLE ImageHandle
,
266 IN EFI_SYSTEM_TABLE
*SystemTable
271 CHAR16
*ProblemParam
;
272 SHELL_STATUS ShellStatus
;
276 CONST CHAR16
*VariableName
;
278 ShellStatus
= SHELL_SUCCESS
;
281 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
282 if (EFI_ERROR(Status
)) {
283 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
284 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
285 FreePool(ProblemParam
);
286 ShellStatus
= SHELL_INVALID_PARAMETER
;
291 if (ShellCommandLineGetCount(Package
) > 2) {
292 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
293 ShellStatus
= SHELL_INVALID_PARAMETER
;
294 } else if (ShellCommandLineGetFlag(Package
, L
"-all") && ShellCommandLineGetFlag(Package
, L
"-guid")) {
295 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-all", L
"-guid");
296 ShellStatus
= SHELL_INVALID_PARAMETER
;
297 } else if ((ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) && ShellCommandLineGetFlag(Package
, L
"-d")) {
298 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-l or -s", L
"-d");
299 ShellStatus
= SHELL_INVALID_PARAMETER
;
301 if (!ShellCommandLineGetFlag(Package
, L
"-all")) {
302 Temp
= ShellCommandLineGetValue(Package
, L
"-guid");
304 Status
= ConvertStringToGuid(Temp
, &GuidData
);
305 if (EFI_ERROR(Status
)) {
306 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Temp
);
307 ShellStatus
= SHELL_INVALID_PARAMETER
;
311 Guid
= &gEfiGlobalVariableGuid
;
313 VariableName
= ShellCommandLineGetRawValue(Package
, 1);
318 if (ShellStatus
== SHELL_SUCCESS
) {
319 if (ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) {
320 ///@todo fix this after lib ready...
321 ShellPrintEx(-1, -1, L
"Not implemeneted yet.\r\n");
322 ShellStatus
= SHELL_UNSUPPORTED
;
324 ShellStatus
= ProcessVariables (VariableName
, Guid
, ShellCommandLineGetFlag(Package
, L
"-d"));
330 if (Package
!= NULL
) {
331 ShellCommandLineFreeVarList (Package
);