2 Main file for DmpStore shell Debug1 function.
4 Copyright (c) 2005 - 2011, 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
));
151 if (FoundVarName
!= NULL
) {
152 FreePool(FoundVarName
);
154 if (DataBuffer
!= NULL
) {
155 FreePool(DataBuffer
);
158 if (VariableName
!= NULL
&& Guid
== NULL
) {
159 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_N
), gShellDebug1HiiHandle
, VariableName
);
160 } else if (VariableName
!= NULL
&& Guid
!= NULL
) {
161 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_GN
), gShellDebug1HiiHandle
, Guid
, VariableName
);
162 } else if (VariableName
== NULL
&& Guid
== NULL
) {
163 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND
), gShellDebug1HiiHandle
);
164 } else if (VariableName
== NULL
&& Guid
!= NULL
) {
165 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DMPSTORE_NO_VAR_FOUND_G
), gShellDebug1HiiHandle
, Guid
);
167 return (SHELL_NOT_FOUND
);
169 return (SHELL_SUCCESS
);
172 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
177 {L
"-guid", TypeValue
},
182 Function for 'dmpstore' command.
184 @param[in] ImageHandle Handle to the Image (NULL if Internal).
185 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
189 ShellCommandRunDmpStore (
190 IN EFI_HANDLE ImageHandle
,
191 IN EFI_SYSTEM_TABLE
*SystemTable
196 CHAR16
*ProblemParam
;
197 SHELL_STATUS ShellStatus
;
201 CONST CHAR16
*VariableName
;
203 ShellStatus
= SHELL_SUCCESS
;
206 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
207 if (EFI_ERROR(Status
)) {
208 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
209 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
210 FreePool(ProblemParam
);
211 ShellStatus
= SHELL_INVALID_PARAMETER
;
216 if (ShellCommandLineGetCount(Package
) > 2) {
217 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
218 ShellStatus
= SHELL_INVALID_PARAMETER
;
219 } else if (ShellCommandLineGetFlag(Package
, L
"-all") && ShellCommandLineGetFlag(Package
, L
"-guid")) {
220 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-all", L
"-guid");
221 ShellStatus
= SHELL_INVALID_PARAMETER
;
222 } else if ((ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) && ShellCommandLineGetFlag(Package
, L
"-d")) {
223 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-l or -s", L
"-d");
224 ShellStatus
= SHELL_INVALID_PARAMETER
;
226 if (!ShellCommandLineGetFlag(Package
, L
"-all")) {
227 Temp
= ShellCommandLineGetValue(Package
, L
"-guid");
229 Status
= ConvertStringToGuid(Temp
, &GuidData
);
230 if (EFI_ERROR(Status
)) {
231 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, Temp
);
232 ShellStatus
= SHELL_INVALID_PARAMETER
;
236 Guid
= &gEfiGlobalVariableGuid
;
238 VariableName
= ShellCommandLineGetRawValue(Package
, 1);
243 if (ShellStatus
== SHELL_SUCCESS
) {
244 if (ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) {
245 ///@todo fix this after Jordan makes lib...
246 ShellPrintEx(-1, -1, L
"Not implemeneted yet.\r\n");
247 ShellStatus
= SHELL_UNSUPPORTED
;
249 ShellStatus
= ProcessVariables (VariableName
, Guid
, ShellCommandLineGetFlag(Package
, L
"-d"));
255 if (Package
!= NULL
) {
256 ShellCommandLineFreeVarList (Package
);