]>
Commit | Line | Data |
---|---|---|
a6caee65 | 1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2011, ARM Limited. All rights reserved.\r | |
50c6a4d2 | 4 | * (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r |
a6caee65 | 5 | *\r |
3402aac7 RC |
6 | * This program and the accompanying materials\r |
7 | * are licensed and made available under the terms and conditions of the BSD License\r | |
8 | * which accompanies this distribution. The full text of the license may be found at\r | |
9 | * http://opensource.org/licenses/bsd-license.php\r | |
10 | *\r | |
11 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
a6caee65 | 13 | *\r |
14 | **/\r | |
fb334ef6 | 15 | \r |
16 | #include "Ebl.h"\r | |
a6caee65 | 17 | \r |
18 | #include <Guid/GlobalVariable.h>\r | |
fb334ef6 | 19 | \r |
20 | EFI_STATUS\r | |
50c6a4d2 | 21 | EFIAPI\r |
fb334ef6 | 22 | EblGetCmd (\r |
23 | IN UINTN Argc,\r | |
24 | IN CHAR8 **Argv\r | |
25 | )\r | |
26 | {\r | |
27 | EFI_STATUS Status = EFI_INVALID_PARAMETER;\r | |
a6caee65 | 28 | UINTN Size;\r |
29 | VOID* Value;\r | |
30 | CHAR8* AsciiVariableName = NULL;\r | |
31 | CHAR16* VariableName;\r | |
32 | UINT32 Index;\r | |
33 | \r | |
34 | if (Argc == 1) {\r | |
35 | AsciiPrint("Variable name is missing.\n");\r | |
36 | return Status;\r | |
37 | }\r | |
38 | \r | |
39 | for (Index = 1; Index < Argc; Index++) {\r | |
40 | if (Argv[Index][0] == '-') {\r | |
41 | AsciiPrint("Warning: '%a' not recognized.\n",Argv[Index]);\r | |
42 | } else {\r | |
43 | AsciiVariableName = Argv[Index];\r | |
44 | }\r | |
45 | }\r | |
46 | \r | |
47 | if (AsciiVariableName == NULL) {\r | |
48 | AsciiPrint("Variable name is missing.\n");\r | |
49 | return Status;\r | |
50 | } else {\r | |
51 | VariableName = AllocatePool((AsciiStrLen (AsciiVariableName) + 1) * sizeof (CHAR16));\r | |
52 | AsciiStrToUnicodeStr (AsciiVariableName,VariableName);\r | |
53 | }\r | |
54 | \r | |
55 | // Try to get the variable size.\r | |
56 | Value = NULL;\r | |
57 | Size = 0;\r | |
58 | Status = gRT->GetVariable (VariableName, &gEfiGlobalVariableGuid, NULL, &Size, Value);\r | |
59 | if (Status == EFI_NOT_FOUND) {\r | |
60 | AsciiPrint("Variable name '%s' not found.\n",VariableName);\r | |
61 | } else if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
62 | // Get the environment variable value\r | |
63 | Value = AllocatePool (Size);\r | |
64 | if (Value == NULL) {\r | |
65 | return EFI_OUT_OF_RESOURCES;\r | |
66 | }\r | |
67 | \r | |
68 | Status = gRT->GetVariable ((CHAR16 *)VariableName, &gEfiGlobalVariableGuid, NULL, &Size, Value);\r | |
69 | if (EFI_ERROR (Status)) {\r | |
70 | AsciiPrint("Error: '%r'\n",Status);\r | |
71 | } else {\r | |
72 | AsciiPrint("%a=%a\n",AsciiVariableName,Value);\r | |
73 | }\r | |
74 | FreePool(Value);\r | |
75 | } else {\r | |
76 | AsciiPrint("Error: '%r'\n",Status);\r | |
fb334ef6 | 77 | }\r |
78 | \r | |
79 | FreePool(VariableName);\r | |
80 | return Status;\r | |
81 | }\r | |
82 | \r | |
83 | EFI_STATUS\r | |
50c6a4d2 | 84 | EFIAPI\r |
fb334ef6 | 85 | EblSetCmd (\r |
86 | IN UINTN Argc,\r | |
87 | IN CHAR8 **Argv\r | |
88 | )\r | |
89 | {\r | |
90 | EFI_STATUS Status = EFI_INVALID_PARAMETER;\r | |
a6caee65 | 91 | CHAR8* AsciiVariableSetting = NULL;\r |
92 | CHAR8* AsciiVariableName;\r | |
93 | CHAR8* AsciiValue;\r | |
94 | UINT32 AsciiValueLength;\r | |
95 | CHAR16* VariableName;\r | |
fb334ef6 | 96 | UINT32 Index;\r |
97 | UINT32 EscapedQuotes = 0;\r | |
98 | BOOLEAN Volatile = FALSE;\r | |
99 | \r | |
a6caee65 | 100 | if (Argc == 1) {\r |
101 | AsciiPrint("Variable name is missing.\n");\r | |
102 | return Status;\r | |
103 | }\r | |
104 | \r | |
105 | for (Index = 1; Index < Argc; Index++) {\r | |
106 | if (AsciiStrCmp(Argv[Index],"-v") == 0) {\r | |
107 | Volatile = 0;\r | |
108 | } else if (Argv[Index][0] == '-') {\r | |
109 | AsciiPrint("Warning: '%a' not recognized.\n",Argv[Index]);\r | |
110 | } else {\r | |
111 | AsciiVariableSetting = Argv[Index];\r | |
112 | }\r | |
113 | }\r | |
114 | \r | |
115 | if (AsciiVariableSetting == NULL) {\r | |
116 | AsciiPrint("Variable name is missing.\n");\r | |
117 | return Status;\r | |
118 | }\r | |
3402aac7 | 119 | \r |
a6caee65 | 120 | // Check if it is a valid variable setting\r |
fb334ef6 | 121 | AsciiValue = AsciiStrStr (AsciiVariableSetting,"=");\r |
a6caee65 | 122 | if (AsciiValue == NULL) {\r |
123 | //\r | |
124 | // There is no value. It means this variable will be deleted\r | |
125 | //\r | |
126 | \r | |
127 | // Convert VariableName into Unicode\r | |
128 | VariableName = AllocatePool((AsciiStrLen (AsciiVariableSetting) + 1) * sizeof (CHAR16));\r | |
129 | AsciiStrToUnicodeStr (AsciiVariableSetting,VariableName);\r | |
130 | \r | |
131 | Status = gRT->SetVariable (\r | |
132 | VariableName,\r | |
133 | &gEfiGlobalVariableGuid,\r | |
134 | ( !Volatile ? EFI_VARIABLE_NON_VOLATILE : 0) |\r | |
135 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
136 | 0,\r | |
137 | NULL\r | |
138 | );\r | |
139 | if (!EFI_ERROR(Status)) {\r | |
140 | AsciiPrint("Variable '%s' deleted\n",VariableName);\r | |
141 | } else {\r | |
142 | AsciiPrint("Variable setting is incorrect. It should be VariableName=Value\n");\r | |
143 | }\r | |
144 | return Status;\r | |
fb334ef6 | 145 | }\r |
146 | \r | |
147 | AsciiValue[0] = '\0';\r | |
148 | AsciiVariableName = AsciiVariableSetting;\r | |
149 | AsciiValue++;\r | |
150 | \r | |
151 | // Clean AsciiValue from quote\r | |
152 | if (AsciiValue[0] == '"') {\r | |
153 | AsciiValue++;\r | |
154 | }\r | |
155 | AsciiValueLength = AsciiStrLen (AsciiValue);\r | |
156 | if ((AsciiValue[AsciiValueLength-2] != '\\') && (AsciiValue[AsciiValueLength-1] == '"')) {\r | |
157 | AsciiValue[AsciiValueLength-1] = '\0';\r | |
158 | }\r | |
159 | \r | |
160 | // Clean AsciiValue from escaped quotes\r | |
161 | for (Index = 0; Index < AsciiValueLength; Index++) {\r | |
162 | if ((Index > 0) && (AsciiValue[Index-1] == '\\') && (AsciiValue[Index] == '"')) {\r | |
163 | EscapedQuotes++;\r | |
164 | }\r | |
165 | AsciiValue[Index-EscapedQuotes] = AsciiValue[Index];\r | |
166 | }\r | |
167 | // Fill the end of the value with '\0'\r | |
168 | for (Index = 0; Index < EscapedQuotes; Index++) {\r | |
169 | AsciiValue[AsciiValueLength-1-Index] = '\0';\r | |
170 | }\r | |
171 | \r | |
172 | // Convert VariableName into Unicode\r | |
a6caee65 | 173 | VariableName = AllocatePool((AsciiStrLen (AsciiVariableName) + 1) * sizeof (CHAR16));\r |
fb334ef6 | 174 | AsciiStrToUnicodeStr (AsciiVariableName,VariableName);\r |
175 | \r | |
a6caee65 | 176 | Status = gRT->SetVariable (\r |
177 | VariableName,\r | |
178 | &gEfiGlobalVariableGuid,\r | |
179 | ( !Volatile ? EFI_VARIABLE_NON_VOLATILE : 0) |\r | |
180 | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
181 | AsciiStrLen (AsciiValue)+1,\r | |
182 | AsciiValue\r | |
fb334ef6 | 183 | );\r |
20fd35dc | 184 | if (!EFI_ERROR(Status)) {\r |
185 | AsciiPrint("'%a'='%a'\n",AsciiVariableName,AsciiValue);\r | |
a6caee65 | 186 | }\r |
fb334ef6 | 187 | \r |
188 | return Status;\r | |
189 | }\r | |
190 | \r | |
191 | GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdVariableTemplate[] =\r | |
192 | {\r | |
193 | {\r | |
194 | "get",\r | |
195 | " ; get UEFI variable\n\r [v]; verbose",\r | |
196 | NULL,\r | |
197 | EblGetCmd\r | |
198 | },\r | |
199 | {\r | |
200 | "set",\r | |
201 | " ; set UEFI variable\n\r [v]; create volatile variable",\r | |
202 | NULL,\r | |
203 | EblSetCmd\r | |
204 | }\r | |
205 | };\r | |
206 | \r | |
207 | /**\r | |
208 | Initialize the commands in this in this file\r | |
209 | **/\r | |
210 | VOID\r | |
211 | EblInitializeVariableCmds (\r | |
212 | VOID\r | |
213 | )\r | |
214 | {\r | |
215 | EblAddCommands (mCmdVariableTemplate, sizeof (mCmdVariableTemplate)/sizeof (EBL_COMMAND_TABLE));\r | |
216 | }\r |