2 Main file for DmpStore shell Debug1 function.
4 Copyright (c) 2005 - 2014, 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 Base on the input attribute value to return the attribute string.
20 @param[in] Atts The input attribute value
22 @retval The attribute string info.
36 if ((Atts
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
37 StrnCatGrow (&RetString
, &BufLen
, L
"+NV", 0);
39 if ((Atts
& EFI_VARIABLE_RUNTIME_ACCESS
) != 0) {
40 StrnCatGrow (&RetString
, &BufLen
, L
"+RS+BS", 0);
41 } else if ((Atts
& EFI_VARIABLE_BOOTSERVICE_ACCESS
) != 0) {
42 StrnCatGrow (&RetString
, &BufLen
, L
"+BS", 0);
44 if ((Atts
& EFI_VARIABLE_HARDWARE_ERROR_RECORD
) != 0) {
45 StrnCatGrow (&RetString
, &BufLen
, L
"+HR", 0);
47 if ((Atts
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) != 0) {
48 StrnCatGrow (&RetString
, &BufLen
, L
"+AW", 0);
50 if ((Atts
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) != 0) {
51 StrnCatGrow (&RetString
, &BufLen
, L
"+AT", 0);
54 if (RetString
== NULL
) {
55 RetString
= StrnCatGrow(&RetString
, &BufLen
, L
"Invalid", 0);
58 if ((RetString
!= NULL
) && (RetString
[0] == L
'+')) {
59 CopyMem(RetString
, RetString
+ 1, StrSize(RetString
+ 1));
66 Recursive function to display or delete variables.
68 This function will call itself to create a stack-based list of allt he variables to process,
69 then fromt he last to the first, they will do either printing or deleting.
71 This is necessary since once a delete happens GetNextVariableName() will work.
73 @param[in] VariableName The variable name of the EFI variable (or NULL).
74 @param[in] Guid The GUID of the variable set (or NULL).
75 @param[in] Delete TRUE to delete, FALSE otherwise.
76 @param[in] PrevName The previous variable name from GetNextVariableName. L"" to start.
77 @param[in] FoundVarGuid The previous GUID from GetNextVariableName. ignored at start.
78 @param[in] FoundOne If a VariableName or Guid was specified and one was printed or
79 deleted, then set this to TRUE, otherwise ignored.
81 @retval SHELL_SUCCESS The operation was successful.
82 @retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
83 @retval SHELL_ABORTED The abort message was received.
84 @retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
85 @retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
89 CascadeProcessVariables (
90 IN CONST CHAR16
*VariableName OPTIONAL
,
91 IN CONST EFI_GUID
*Guid OPTIONAL
,
93 IN CONST CHAR16
* CONST PrevName
,
94 IN EFI_GUID FoundVarGuid
,
103 SHELL_STATUS ShellStatus
;
107 if (ShellGetExecutionBreakFlag()) {
108 return (SHELL_ABORTED
);
114 if (PrevName
!=NULL
) {
115 StrnCatGrow(&FoundVarName
, &NameSize
, PrevName
, 0);
117 FoundVarName
= AllocateZeroPool(sizeof(CHAR16
));
120 Status
= gRT
->GetNextVariableName (&NameSize
, FoundVarName
, &FoundVarGuid
);
121 if (Status
== EFI_BUFFER_TOO_SMALL
) {
122 SHELL_FREE_NON_NULL(FoundVarName
);
123 FoundVarName
= AllocateZeroPool (NameSize
);
124 if (PrevName
!= NULL
) {
125 StrCpy(FoundVarName
, PrevName
);
128 Status
= gRT
->GetNextVariableName (&NameSize
, FoundVarName
, &FoundVarGuid
);
134 if (Status
== EFI_NOT_FOUND
) {
135 SHELL_FREE_NON_NULL(FoundVarName
);
136 return (SHELL_SUCCESS
);
137 } else if (EFI_ERROR(Status
)) {
138 SHELL_FREE_NON_NULL(FoundVarName
);
139 return (SHELL_DEVICE_ERROR
);
143 // Recurse to the next iteration. We know "our" variable's name.
145 ShellStatus
= CascadeProcessVariables(VariableName
, Guid
, Delete
, FoundVarName
, FoundVarGuid
, FoundOne
);
148 // No matter what happened we process our own variable
149 // Only continue if Guid and VariableName are each either NULL or a match
151 if ( ( VariableName
== NULL
152 || gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, FoundVarName
, (CHAR16
*)VariableName
) )
154 || CompareGuid(&FoundVarGuid
, Guid
) )
159 // do the print or delete
162 Status
= gRT
->GetVariable (FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
163 if (Status
== EFI_BUFFER_TOO_SMALL
) {
164 SHELL_FREE_NON_NULL (DataBuffer
);
165 DataBuffer
= AllocatePool (DataSize
);
166 if (DataBuffer
== NULL
) {
167 Status
= EFI_OUT_OF_RESOURCES
;
169 Status
= gRT
->GetVariable (FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
174 // Last error check then print this variable out.
176 if (!EFI_ERROR(Status
) && DataBuffer
!= NULL
) {
177 RetString
= GetAttrType(Atts
);
182 STRING_TOKEN(STR_DMPSTORE_HEADER_LINE
),
183 gShellDebug1HiiHandle
,
188 DumpHex(2, 0, DataSize
, DataBuffer
);
189 SHELL_FREE_NON_NULL(RetString
);
193 // We only need name to delete it...
199 STRING_TOKEN(STR_DMPSTORE_DELETE_LINE
),
200 gShellDebug1HiiHandle
,
207 STRING_TOKEN(STR_DMPSTORE_DELETE_DONE
),
208 gShellDebug1HiiHandle
,
209 gRT
->SetVariable(FoundVarName
, &FoundVarGuid
, Atts
, 0, NULL
));
211 SHELL_FREE_NON_NULL(DataBuffer
);
214 SHELL_FREE_NON_NULL(FoundVarName
);
216 if (Status
== EFI_DEVICE_ERROR
) {
217 ShellStatus
= SHELL_DEVICE_ERROR
;
218 } else if (Status
== EFI_SECURITY_VIOLATION
) {
219 ShellStatus
= SHELL_SECURITY_VIOLATION
;
220 } else if (EFI_ERROR(Status
)) {
221 ShellStatus
= SHELL_NOT_READY
;
224 return (ShellStatus
);
228 Function to display or delete variables. This will set up and call into the recursive function.
230 @param[in] VariableName The variable name of the EFI variable (or NULL).
231 @param[in] Guid The GUID of the variable set (or NULL).
232 @param[in] Delete TRUE to delete, FALSE otherwise.
234 @retval SHELL_SUCCESS The operation was successful.
235 @retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
236 @retval SHELL_ABORTED The abort message was received.
237 @retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
238 @retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
243 IN CONST CHAR16
*VariableName OPTIONAL
,
244 IN CONST EFI_GUID
*Guid OPTIONAL
,
248 SHELL_STATUS ShellStatus
;
250 EFI_GUID FoundVarGuid
;
253 ShellStatus
= SHELL_SUCCESS
;
254 ZeroMem (&FoundVarGuid
, sizeof(EFI_GUID
));
256 ShellStatus
= CascadeProcessVariables(VariableName
, Guid
, Delete
, NULL
, FoundVarGuid
, &Found
);
259 if (ShellStatus
== SHELL_OUT_OF_RESOURCES
) {
260 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
);
261 return (ShellStatus
);
262 } else if (VariableName
!= NULL
&& Guid
== NULL
) {
263 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N
), gShellDebug1HiiHandle
, VariableName
);
264 } else if (VariableName
!= NULL
&& Guid
!= NULL
) {
265 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN
), gShellDebug1HiiHandle
, Guid
, VariableName
);
266 } else if (VariableName
== NULL
&& Guid
== NULL
) {
267 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND
), gShellDebug1HiiHandle
);
268 } else if (VariableName
== NULL
&& Guid
!= NULL
) {
269 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G
), gShellDebug1HiiHandle
, Guid
);
271 return (SHELL_NOT_FOUND
);
273 return (ShellStatus
);
276 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
281 {L
"-guid", TypeValue
},
286 Function for 'dmpstore' command.
288 @param[in] ImageHandle Handle to the Image (NULL if Internal).
289 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
293 ShellCommandRunDmpStore (
294 IN EFI_HANDLE ImageHandle
,
295 IN EFI_SYSTEM_TABLE
*SystemTable
300 CHAR16
*ProblemParam
;
301 SHELL_STATUS ShellStatus
;
305 CONST CHAR16
*VariableName
;
307 ShellStatus
= SHELL_SUCCESS
;
310 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
311 if (EFI_ERROR(Status
)) {
312 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
313 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
314 FreePool(ProblemParam
);
315 ShellStatus
= SHELL_INVALID_PARAMETER
;
320 if (ShellCommandLineGetCount(Package
) > 2) {
321 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
322 ShellStatus
= SHELL_INVALID_PARAMETER
;
323 } else if (ShellCommandLineGetFlag(Package
, L
"-all") && ShellCommandLineGetFlag(Package
, L
"-guid")) {
324 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-all", L
"-guid");
325 ShellStatus
= SHELL_INVALID_PARAMETER
;
326 } else if ((ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) && ShellCommandLineGetFlag(Package
, L
"-d")) {
327 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-l or -s", L
"-d");
328 ShellStatus
= SHELL_INVALID_PARAMETER
;
330 if (!ShellCommandLineGetFlag(Package
, L
"-all")) {
331 Temp
= ShellCommandLineGetValue(Package
, L
"-guid");
333 Status
= ConvertStringToGuid(Temp
, &GuidData
);
334 if (EFI_ERROR(Status
)) {
335 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Temp
);
336 ShellStatus
= SHELL_INVALID_PARAMETER
;
340 Guid
= &gEfiGlobalVariableGuid
;
342 VariableName
= ShellCommandLineGetRawValue(Package
, 1);
347 if (ShellStatus
== SHELL_SUCCESS
) {
348 if (ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) {
349 ///@todo fix this after lib ready...
350 ShellPrintEx(-1, -1, L
"Not implemeneted yet.\r\n");
351 ShellStatus
= SHELL_UNSUPPORTED
;
353 ShellStatus
= ProcessVariables (VariableName
, Guid
, ShellCommandLineGetFlag(Package
, L
"-d"));
359 if (Package
!= NULL
) {
360 ShellCommandLineFreeVarList (Package
);