]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDriver1CommandsLib/DrvCfg.c
Update return value.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDriver1CommandsLib / DrvCfg.c
1 /** @file
2 Main file for DrvCfg shell Driver1 function.
3
4 Copyright (c) 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
9
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.
12
13 **/
14
15 #include "UefiShellDriver1CommandsLib.h"
16 #include <Protocol/HiiConfigAccess.h>
17 #include <Protocol/HiiDatabase.h>
18
19 /**
20 Function to validate configuration information on a configurable handle.
21
22 @param[in] Handle The handle to validate info on.
23 @param[in] HiiDb A pointer to the HII Database protocol.
24
25 @retval EFI_SUCCESS The operation was successful.
26 **/
27 EFI_STATUS
28 EFIAPI
29 ValidateConfigInfoOnSingleHandleHii(
30 IN CONST EFI_HANDLE Handle,
31 IN EFI_HII_DATABASE_PROTOCOL *HiiDb
32 )
33 {
34 EFI_STATUS Status;
35 UINTN Size;
36 EFI_HII_HANDLE *HiiHandle;
37 EFI_HII_HANDLE *CurrentHandle;
38 EFI_HANDLE NormalHandle;
39
40 if (HiiDb == NULL || Handle == NULL) {
41 return (EFI_INVALID_PARAMETER);
42 }
43
44 Size = 0;
45 HiiHandle = NULL;
46
47 Status = HiiDb->ListPackageLists(
48 HiiDb,
49 EFI_HII_PACKAGE_TYPE_ALL,
50 NULL,
51 &Size,
52 HiiHandle);
53
54 if (Status == EFI_BUFFER_TOO_SMALL) {
55 HiiHandle = AllocateZeroPool(Size);
56 if (HiiHandle == NULL) {
57 return (EFI_OUT_OF_RESOURCES);
58 }
59 Status = HiiDb->ListPackageLists(
60 HiiDb,
61 EFI_HII_PACKAGE_TYPE_ALL,
62 NULL,
63 &Size,
64 HiiHandle);
65 }
66 if (EFI_ERROR(Status)) {
67 SHELL_FREE_NON_NULL(HiiHandle);
68 return (Status);
69 }
70
71 for (CurrentHandle = HiiHandle ; CurrentHandle != NULL && *CurrentHandle != NULL ; CurrentHandle++) {
72 NormalHandle = NULL;
73 Status = HiiDb->GetPackageListHandle(
74 HiiDb,
75 *CurrentHandle,
76 &NormalHandle);
77 if (NormalHandle == Handle) {
78 break;
79 }
80 }
81
82
83
84
85
86 SHELL_FREE_NON_NULL(HiiHandle);
87 return (Status);
88 }
89
90 /**
91 Function to validate configuration information on all configurable handles.
92
93 @param[in] ChildrenToo TRUE to tewst for children.
94
95 @retval SHELL_SUCCESS The operation was successful.
96 **/
97 SHELL_STATUS
98 EFIAPI
99 ValidOptionsOnAll(
100 IN CONST BOOLEAN ChildrenToo
101 )
102 {
103 EFI_HANDLE *HandleList;
104 EFI_HANDLE *CurrentHandle;
105 SHELL_STATUS ShellStatus;
106 EFI_STATUS Status;
107 BOOLEAN Found;
108 EFI_HII_DATABASE_PROTOCOL *HiiDb;
109
110 Found = FALSE;
111 HandleList = NULL;
112 ShellStatus = SHELL_SUCCESS;
113 Status = EFI_SUCCESS;
114
115 Status = gBS->LocateProtocol(&gEfiHiiDatabaseProtocolGuid, NULL, (VOID**)&HiiDb);
116 if (EFI_ERROR(Status)) {
117 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROTOCOL_NF), gShellDriver1HiiHandle, L"gEfiHiiDatabaseProtocolGuid", &gEfiHiiDatabaseProtocolGuid);
118 return (SHELL_NOT_FOUND);
119 }
120
121 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_HEADER), gShellDriver1HiiHandle);
122
123 //
124 // First do HII method
125 //
126 HandleList = GetHandleListByProtocol(&gEfiHiiConfigAccessProtocolGuid);
127 for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL && ShellStatus == SHELL_SUCCESS; CurrentHandle++){
128 Found = TRUE;
129 ///@todo VALIDATE
130 }
131 SHELL_FREE_NON_NULL(HandleList);
132
133 //
134 // Now do EFI 1.10 & UEFI 2.0 drivers
135 //
136 HandleList = GetHandleListByProtocol(&gEfiDriverConfigurationProtocolGuid);
137 for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL && ShellStatus == SHELL_SUCCESS; CurrentHandle++){
138 Found = TRUE;
139 ///@todo VALIDATE
140 }
141
142 if (!Found) {
143 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle);
144 return (SHELL_SUCCESS);
145 }
146
147 SHELL_FREE_NON_NULL(HandleList);
148 return (ShellStatus);
149 }
150
151 /**
152 Function to print out configuration information on a configurable handle.
153
154 @param[in] DriverHandle The driver handle to print info on.
155 @param[in] ControllerHandle The controllerHandle to print on.
156 @param[in] ChildrenToo TRUE to tewst for children.
157 @param[in] ProtocolMask BIT0 for HII, BIT1 for DirverConfiguration.
158
159 @retval SHELL_SUCCESS The operation was successful.
160 **/
161 SHELL_STATUS
162 EFIAPI
163 PrintConfigInfoOnSingleHandle(
164 IN CONST EFI_HANDLE DriverHandle,
165 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,
166 IN CONST BOOLEAN ChildrenToo,
167 IN CONST UINT8 ProtocolMask // BIT0 - HII, BIT1 - DriverConfiguration
168 )
169 {
170 UINTN Index1;
171 UINTN Index2;
172 EFI_HANDLE *ChildHandleList;
173 UINTN Count;
174 UINTN LoopVar;
175
176 Index1 = DriverHandle == NULL ? 0 : ConvertHandleToHandleIndex(DriverHandle );
177 Index2 = ControllerHandle == NULL ? 0 : ConvertHandleToHandleIndex(ControllerHandle);
178
179 if ((ProtocolMask & BIT0) == BIT0) {
180 ASSERT(Index1 == 0);
181 ShellPrintHiiEx(
182 -1,
183 -1,
184 NULL,
185 STRING_TOKEN (STR_DRVCFG_LINE_HII),
186 gShellDriver1HiiHandle,
187 Index2
188 );
189 }
190 if ((ProtocolMask & BIT1) == BIT1) {
191 PARSE_HANDLE_DATABASE_MANAGED_CHILDREN(DriverHandle, ControllerHandle, &Count, &ChildHandleList);
192 for (LoopVar = 0 ; LoopVar <= Count ; LoopVar++) {
193 ShellPrintHiiEx(
194 -1,
195 -1,
196 NULL,
197 STRING_TOKEN (STR_DRVCFG_LINE_DRV),
198 gShellDriver1HiiHandle,
199 Index1,
200 Index2,
201 Count != 0 ? ChildHandleList[LoopVar] : 0
202 );
203 }
204 }
205 return (SHELL_SUCCESS);
206 }
207
208 /**
209 Function to print out configuration information on all configurable handles.
210
211 @param[in] ChildrenToo TRUE to tewst for children.
212
213 @retval SHELL_SUCCESS The operation was successful.
214 **/
215 SHELL_STATUS
216 EFIAPI
217 PrintConfigInfoOnAll(
218 IN CONST BOOLEAN ChildrenToo
219 )
220 {
221 // lcoate all the HII_CONFIG_ACCESS_PROTOCOL - those are all configurable
222 // then cross reference with EFI_DRIVER_CONFIGURATION_PROTOCOL - those are legacy configurable
223 // can be on chlid, but that is ok... just find the driver
224 EFI_HANDLE *HandleList;
225 EFI_HANDLE *CurrentHandle;
226 EFI_HANDLE *DriverHandleList;
227 EFI_HANDLE *ParentHandleList;
228 EFI_HANDLE *CurrentDriver;
229 UINTN Count;
230 SHELL_STATUS ShellStatus;
231 EFI_STATUS Status;
232 UINTN LoopVar;
233 BOOLEAN Found;
234
235 Found = FALSE;
236 Count = 0;
237 HandleList = NULL;
238 CurrentHandle = NULL;
239 DriverHandleList = NULL;
240 CurrentDriver = NULL;
241 ShellStatus = SHELL_SUCCESS;
242
243 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_HEADER), gShellDriver1HiiHandle);
244 //
245 // First do HII method
246 //
247 HandleList = GetHandleListByProtocol(&gEfiHiiConfigAccessProtocolGuid);
248 for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL && ShellStatus == SHELL_SUCCESS; CurrentHandle++){
249 // is this a driver handle itself? if yes print options for it.
250 if (!EFI_ERROR(gBS->OpenProtocol(*CurrentHandle, &gEfiDriverBindingProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
251 ShellStatus = PrintConfigInfoOnSingleHandle(*CurrentHandle, NULL, ChildrenToo, BIT0);
252 } else {
253 // get its driver and print options for it.
254 Count = 0;
255 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS(*CurrentHandle, &Count, &DriverHandleList);
256 if (EFI_ERROR(Status)) {
257 Status = PARSE_HANDLE_DATABASE_PARENTS(*CurrentHandle, &Count, &ParentHandleList);
258 if (!EFI_ERROR(Status)) {
259 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS(*ParentHandleList, &Count, &DriverHandleList);
260 }
261 }
262 if (Count == 0) {
263 Found = TRUE;
264 ShellStatus = PrintConfigInfoOnSingleHandle(NULL, *CurrentHandle, ChildrenToo, BIT0);
265 } else if (DriverHandleList != NULL) {
266 for (LoopVar = 0 ; LoopVar < Count ; LoopVar++) {
267 Found = TRUE;
268 ShellStatus = PrintConfigInfoOnSingleHandle(DriverHandleList[LoopVar], *CurrentHandle, ChildrenToo, BIT0);
269 }
270 }
271 SHELL_FREE_NON_NULL(DriverHandleList);
272 }
273 }
274 SHELL_FREE_NON_NULL(HandleList);
275
276 //
277 // Now do EFI 1.10 & UEFI 2.0 drivers
278 //
279 HandleList = GetHandleListByProtocol(&gEfiDriverConfigurationProtocolGuid);
280 for (CurrentHandle = HandleList ; CurrentHandle != NULL && *CurrentHandle != NULL && ShellStatus == SHELL_SUCCESS; CurrentHandle++){
281 Found = TRUE;
282 ShellStatus = PrintConfigInfoOnSingleHandle(*CurrentHandle, NULL, ChildrenToo, BIT1);
283 }
284 SHELL_FREE_NON_NULL(HandleList);
285 if (!Found) {
286 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_DRVCFG_NONE), gShellDriver1HiiHandle);
287 return (SHELL_SUCCESS);
288 }
289 return (ShellStatus);
290 }
291
292 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
293 {L"-c", TypeFlag},
294 {L"-s", TypeFlag},
295 {L"-v", TypeFlag},
296 {L"-l", TypeValue},
297 {L"-f", TypeValue},
298 {L"-o", TypeValue},
299 {L"-i", TypeValue},
300 {NULL, TypeMax}
301 };
302
303 SHELL_STATUS
304 EFIAPI
305 ShellCommandRunDrvCfg (
306 IN EFI_HANDLE ImageHandle,
307 IN EFI_SYSTEM_TABLE *SystemTable
308 )
309 {
310 EFI_STATUS Status;
311 LIST_ENTRY *Package;
312 CHAR16 *ProblemParam;
313 SHELL_STATUS ShellStatus;
314 CHAR8 *Language;
315 CONST CHAR16 *Lang;
316 CONST CHAR16 *Temp2;
317
318 ShellStatus = SHELL_SUCCESS;
319 Status = EFI_SUCCESS;
320 Language = NULL;
321
322 //
323 // initialize the shell lib (we must be in non-auto-init...)
324 //
325 Status = ShellInitialize();
326 ASSERT_EFI_ERROR(Status);
327
328 Status = CommandInit();
329 ASSERT_EFI_ERROR(Status);
330
331 //
332 // parse the command line
333 //
334 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
335 if (EFI_ERROR(Status)) {
336 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
337 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
338 FreePool(ProblemParam);
339 ShellStatus = SHELL_INVALID_PARAMETER;
340 } else {
341 ASSERT(FALSE);
342 }
343 } else {
344 Lang = ShellCommandLineGetValue(Package, L"-l");
345 if (Lang != NULL) {
346 Language = AllocateZeroPool(StrSize(Lang));
347 AsciiSPrint(Language, StrSize(Lang), "%S", Lang);
348 } else if (!ShellCommandLineGetFlag(Package, L"-l")){
349 Language = AllocateZeroPool(10);
350 AsciiSPrint(Language, 10, "en-us");
351 } else {
352 ASSERT(Language == NULL);
353 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l");
354 ShellCommandLineFreeVarList (Package);
355 return (SHELL_INVALID_PARAMETER);
356 }
357
358 //
359 // Should be DriverHandle
360 //
361 Temp2 = ShellCommandLineGetRawValue(Package, 1);
362 if (Temp2 == NULL) {
363 //
364 // no driver specified. cannot be export, inport, or set (and no specified language)
365 //
366 if (ShellCommandLineGetFlag(Package, L"-s")
367 ||ShellCommandLineGetFlag(Package, L"-l")
368 ||ShellCommandLineGetFlag(Package, L"-o")
369 ||ShellCommandLineGetFlag(Package, L"-i")) {
370 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_HANDLE_REQ), gShellDriver1HiiHandle);
371 ShellStatus = SHELL_INVALID_PARAMETER;
372 } else {
373 //
374 // do a loop for validation, forcing, or printing
375 //
376 if (ShellCommandLineGetFlag(Package, L"-v") && ShellCommandLineGetFlag(Package, L"-f")) {
377 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONF), gShellDriver1HiiHandle, L"-v", L"-f");
378 ShellStatus = SHELL_INVALID_PARAMETER;
379 } else if (ShellCommandLineGetFlag(Package, L"-v")){
380 //
381 // validate
382 //
383 ShellStatus = ValidOptionsOnAll(ShellCommandLineGetFlag(Package, L"-c"));
384 } else if (ShellCommandLineGetFlag(Package, L"-f")){
385 //
386 // force
387 //
388 ASSERT(FALSE);// ShellStatus = ForceOptionsOnAll(ShellCommandLineGetFlag(Package, L"-c"));
389 } else {
390 //
391 // display all that are configurable
392 //
393 ShellStatus = PrintConfigInfoOnAll(ShellCommandLineGetFlag(Package, L"-c"));
394 }
395 }
396 } else {
397 //
398 // we have a driver handle, make sure it's valid then process it...
399 //
400 ASSERT(FALSE);
401 }
402 }
403 ShellCommandLineFreeVarList (Package);
404 SHELL_FREE_NON_NULL(Language);
405 return (ShellStatus);
406 }