2 Main file for DmpStore shell Debug1 function.
4 Copyright (c) 2005 - 2010, 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
[] = {
31 IN CONST CHAR16
*VariableName OPTIONAL
,
32 IN CONST EFI_GUID
*Guid OPTIONAL
,
42 EFI_GUID FoundVarGuid
;
46 SHELL_STATUS ShellStatus
;
48 ShellStatus
= SHELL_SUCCESS
;
49 Size
= PcdGet16(PcdShellFileOperationSize
);
50 FoundVarName
= AllocatePool(Size
);
52 if (FoundVarName
== NULL
) {
53 return (SHELL_OUT_OF_RESOURCES
);
55 FoundVarName
[0] = CHAR_NULL
;
57 Status
= gRT
->QueryVariableInfo(EFI_VARIABLE_BOOTSERVICE_ACCESS
|EFI_VARIABLE_RUNTIME_ACCESS
|EFI_VARIABLE_NON_VOLATILE
, &MaxStorSize
, &RemStorSize
, &MaxVarSize
);
58 ASSERT_EFI_ERROR(Status
);
60 DataSize
= (UINTN
)MaxVarSize
;
61 DataBuffer
= AllocatePool(DataSize
);
62 if (DataBuffer
== NULL
) {
63 FreePool(FoundVarName
);
64 return (SHELL_OUT_OF_RESOURCES
);
68 if (ShellGetExecutionBreakFlag()) {
69 ShellStatus
= SHELL_ABORTED
;
72 Size
= (UINTN
)PcdGet16(PcdShellFileOperationSize
);
73 DataSize
= (UINTN
)MaxVarSize
;
75 Status
= gRT
->GetNextVariableName(&Size
, FoundVarName
, &FoundVarGuid
);
76 if (Status
== EFI_NOT_FOUND
) {
79 ASSERT_EFI_ERROR(Status
);
81 Status
= gRT
->GetVariable(FoundVarName
, &FoundVarGuid
, &Atts
, &DataSize
, DataBuffer
);
82 ASSERT_EFI_ERROR(Status
);
85 // Check if it matches
87 if (VariableName
!= NULL
) {
88 if (!gUnicodeCollation
->MetaiMatch(gUnicodeCollation
, FoundVarName
, (CHAR16
*)VariableName
)) {
93 if (!CompareGuid(&FoundVarGuid
, Guid
)) {
99 // do the print or delete
106 STRING_TOKEN(STR_DMPSTORE_HEADER_LINE
),
107 gShellDebug1HiiHandle
,
112 DumpHex(2, 0, DataSize
, DataBuffer
);
118 STRING_TOKEN(STR_DMPSTORE_DELETE_LINE
),
119 gShellDebug1HiiHandle
,
126 STRING_TOKEN(STR_DMPSTORE_DELETE_DONE
),
127 gShellDebug1HiiHandle
,
128 gRT
->SetVariable(FoundVarName
, &FoundVarGuid
, Atts
, 0, NULL
));
132 if (FoundVarName
!= NULL
) {
133 FreePool(FoundVarName
);
135 if (DataBuffer
!= NULL
) {
136 FreePool(DataBuffer
);
139 return (SHELL_UNSUPPORTED
);
142 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
147 {L
"-guid", TypeValue
},
153 ShellCommandRunDmpStore (
154 IN EFI_HANDLE ImageHandle
,
155 IN EFI_SYSTEM_TABLE
*SystemTable
160 CHAR16
*ProblemParam
;
161 SHELL_STATUS ShellStatus
;
165 CONST CHAR16
*VariableName
;
167 ShellStatus
= SHELL_SUCCESS
;
170 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
171 if (EFI_ERROR(Status
)) {
172 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
173 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
174 FreePool(ProblemParam
);
175 ShellStatus
= SHELL_INVALID_PARAMETER
;
180 if (ShellCommandLineGetCount(Package
) < 1) {
181 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDebug1HiiHandle
);
182 ShellStatus
= SHELL_INVALID_PARAMETER
;
183 } else if (ShellCommandLineGetCount(Package
) > 2) {
184 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
185 ShellStatus
= SHELL_INVALID_PARAMETER
;
186 } else if (ShellCommandLineGetFlag(Package
, L
"-all") && ShellCommandLineGetFlag(Package
, L
"-guid")) {
187 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-all", L
"-guid");
188 ShellStatus
= SHELL_INVALID_PARAMETER
;
189 } else if ((ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) && ShellCommandLineGetFlag(Package
, L
"-d")) {
190 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PARAM_CONFLICT
), gShellDebug1HiiHandle
, L
"-l or -s", L
"-d");
191 ShellStatus
= SHELL_INVALID_PARAMETER
;
193 if (!ShellCommandLineGetFlag(Package
, L
"-all")) {
194 Temp
= ShellCommandLineGetValue(Package
, L
"-guid");
196 Status
= ConvertStringToGuid(Temp
, &GuidData
);
197 if (EFI_ERROR(Status
)) {
198 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, L
"-guid");
199 ShellStatus
= SHELL_INVALID_PARAMETER
;
203 Guid
= &gEfiGlobalVariableGuid
;
205 VariableName
= ShellCommandLineGetRawValue(Package
, 2);
210 if (ShellStatus
== SHELL_SUCCESS
) {
211 if (ShellCommandLineGetFlag(Package
, L
"-s") || ShellCommandLineGetFlag(Package
, L
"-l")) {
212 ///@todo fix this after Jordan makes lib...
213 ShellPrintEx(-1, -1, L
"Not implemeneted yet (ASSERT follows).\r\n");
214 ShellStatus
= SHELL_INVALID_PARAMETER
;
217 ShellStatus
= ProcessVariables (VariableName
, Guid
, ShellCommandLineGetFlag(Package
, L
"-d"));
223 if (Package
!= NULL
) {
224 ShellCommandLineFreeVarList (Package
);