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"
17 STATIC CHAR16
*AttrType
[] = {
29 Function to display or delete variables.
31 @param[in] VariableName The variable name of the EFI variable (or NULL).
32 @param[in] Guid The GUID of the variable set (or NULL).
33 @param[in] Delete TRUE to delete, FALSE otherwise.
35 @retval SHELL_SUCCESS The operation was successful.
36 @retval SHELL_OUT_OF_RESOURCES A memorty allocation failed.
37 @retval SHELL_ABORTED The abort message was received.
38 @retval SHELL_DEVICE_ERROR UEFI Variable Services returned an error.
39 @retval SHELL_NOT_FOUND the Name/Guid pair could not be found.
44 IN CONST CHAR16
*VariableName OPTIONAL
,
45 IN CONST EFI_GUID
*Guid OPTIONAL
,
55 EFI_GUID FoundVarGuid
;
59 SHELL_STATUS ShellStatus
;
62 Status
= gRT
->QueryVariableInfo(EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
|EFI_VARIABLE_NON_VOLATILE
, &MaxStorSize
, &RemStorSize
, &MaxVarSize
);
63 if (EFI_ERROR(Status
)) {
64 return (SHELL_DEVICE_ERROR
);
68 ShellStatus
= SHELL_SUCCESS
;
69 Size
= PcdGet16(PcdShellFileOperationSize
);
70 FoundVarName
= AllocateZeroPool(Size
);
72 if (FoundVarName
== NULL
) {
73 return (SHELL_OUT_OF_RESOURCES
);
75 FoundVarName
[0] = CHAR_NULL
;
78 DataSize
= (UINTN
)MaxVarSize
;
79 DataBuffer
= AllocateZeroPool(DataSize
);
80 if (DataBuffer
== NULL
) {
81 FreePool(FoundVarName
);
82 return (SHELL_OUT_OF_RESOURCES
);
86 if (ShellGetExecutionBreakFlag()) {
87 ShellStatus
= SHELL_ABORTED
;
90 Size
= (UINTN
)PcdGet16(PcdShellFileOperationSize
);
91 DataSize
= (UINTN
)MaxVarSize
;
93 Status
= gRT
->GetNextVariableName(&Size
, FoundVarName
, &FoundVarGuid
);
94 if (Status
== EFI_NOT_FOUND
) {
97 ASSERT_EFI_ERROR(Status
);
99 Status
= gRT
->GetVariable(FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
100 ASSERT_EFI_ERROR(Status
);
103 // Check if it matches
105 if (VariableName
!= NULL
) {
106 if (!gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, FoundVarName
, (CHAR16
*)VariableName
)) {
111 if (!CompareGuid(&FoundVarGuid
, Guid
)) {
117 // do the print or delete
125 STRING_TOKEN(STR_DMPSTORE_HEADER_LINE
),
126 gShellDebug1HiiHandle
,
131 DumpHex(2, 0, DataSize
, DataBuffer
);
137 STRING_TOKEN(STR_DMPSTORE_DELETE_LINE
),
138 gShellDebug1HiiHandle
,
145 STRING_TOKEN(STR_DMPSTORE_DELETE_DONE
),
146 gShellDebug1HiiHandle
,
147 gRT
->SetVariable(FoundVarName
, &FoundVarGuid
, Atts
, 0, NULL
));
148 FoundVarName
[0] = CHAR_NULL
;
152 if (FoundVarName
!= NULL
) {
153 FreePool(FoundVarName
);
155 if (DataBuffer
!= NULL
) {
156 FreePool(DataBuffer
);
159 if (VariableName
!= NULL
&& Guid
== NULL
) {
160 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N
), gShellDebug1HiiHandle
, VariableName
);
161 } else if (VariableName
!= NULL
&& Guid
!= NULL
) {
162 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN
), gShellDebug1HiiHandle
, Guid
, VariableName
);
163 } else if (VariableName
== NULL
&& Guid
== NULL
) {
164 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND
), gShellDebug1HiiHandle
);
165 } else if (VariableName
== NULL
&& Guid
!= NULL
) {
166 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G
), gShellDebug1HiiHandle
, Guid
);
168 return (SHELL_NOT_FOUND
);
170 return (SHELL_SUCCESS
);
173 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
178 {L
"-guid", TypeValue
},
183 Function for 'dmpstore' command.
185 @param[in] ImageHandle Handle to the Image (NULL if Internal).
186 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
190 ShellCommandRunDmpStore (
191 IN EFI_HANDLE ImageHandle
,
192 IN EFI_SYSTEM_TABLE
*SystemTable
197 CHAR16
*ProblemParam
;
198 SHELL_STATUS ShellStatus
;
202 CONST CHAR16
*VariableName
;
204 ShellStatus
= SHELL_SUCCESS
;
207 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
208 if (EFI_ERROR(Status
)) {
209 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
210 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
211 FreePool(ProblemParam
);
212 ShellStatus
= SHELL_INVALID_PARAMETER
;
217 if (ShellCommandLineGetCount(Package
) > 2) {
218 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
219 ShellStatus
= SHELL_INVALID_PARAMETER
;
220 } else if (ShellCommandLineGetFlag(Package
, L
"-all") && ShellCommandLineGetFlag(Package
, L
"-guid")) {
221 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-all", L
"-guid");
222 ShellStatus
= SHELL_INVALID_PARAMETER
;
223 } else if ((ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) && ShellCommandLineGetFlag(Package
, L
"-d")) {
224 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-l or -s", L
"-d");
225 ShellStatus
= SHELL_INVALID_PARAMETER
;
227 if (!ShellCommandLineGetFlag(Package
, L
"-all")) {
228 Temp
= ShellCommandLineGetValue(Package
, L
"-guid");
230 Status
= ConvertStringToGuid(Temp
, &GuidData
);
231 if (EFI_ERROR(Status
)) {
232 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Temp
);
233 ShellStatus
= SHELL_INVALID_PARAMETER
;
237 Guid
= &gEfiGlobalVariableGuid
;
239 VariableName
= ShellCommandLineGetRawValue(Package
, 1);
244 if (ShellStatus
== SHELL_SUCCESS
) {
245 if (ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) {
246 ///@todo fix this after lib ready...
247 ShellPrintEx(-1, -1, L
"Not implemeneted yet.\r\n");
248 ShellStatus
= SHELL_UNSUPPORTED
;
250 ShellStatus
= ProcessVariables (VariableName
, Guid
, ShellCommandLineGetFlag(Package
, L
"-d"));
256 if (Package
!= NULL
) {
257 ShellCommandLineFreeVarList (Package
);