2 Main file for DrvCfg shell Driver1 function.
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
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 "UefiShellDriver1CommandsLib.h"
16 #include <Protocol/HiiConfigAccess.h>
17 #include <Protocol/HiiDatabase.h>
20 Function to validate configuration information on a configurable handle.
22 @param[in] Handle The handle to validate info on.
23 @param[in] HiiDb A pointer to the HII Database protocol.
25 @retval EFI_SUCCESS The operation was successful.
29 ValidateConfigInfoOnSingleHandleHii(
30 IN CONST EFI_HANDLE Handle
,
31 IN EFI_HII_DATABASE_PROTOCOL
*HiiDb
36 EFI_HII_HANDLE
*HiiHandle
;
37 EFI_HII_HANDLE
*CurrentHandle
;
38 EFI_HANDLE NormalHandle
;
40 if (HiiDb
== NULL
|| Handle
== NULL
) {
41 return (EFI_INVALID_PARAMETER
);
47 Status
= HiiDb
->ListPackageLists(
49 EFI_HII_PACKAGE_TYPE_ALL
,
54 if (Status
== EFI_BUFFER_TOO_SMALL
) {
55 HiiHandle
= AllocateZeroPool(Size
);
56 if (HiiHandle
== NULL
) {
57 return (EFI_OUT_OF_RESOURCES
);
59 Status
= HiiDb
->ListPackageLists(
61 EFI_HII_PACKAGE_TYPE_ALL
,
66 if (EFI_ERROR(Status
)) {
67 SHELL_FREE_NON_NULL(HiiHandle
);
71 for (CurrentHandle
= HiiHandle
; CurrentHandle
!= NULL
&& *CurrentHandle
!= NULL
; CurrentHandle
++) {
73 Status
= HiiDb
->GetPackageListHandle(
77 if (NormalHandle
== Handle
) {
86 SHELL_FREE_NON_NULL(HiiHandle
);
91 Function to validate configuration information on all configurable handles.
93 @param[in] ChildrenToo TRUE to tewst for children.
95 @retval SHELL_SUCCESS The operation was successful.
100 IN CONST BOOLEAN ChildrenToo
103 EFI_HANDLE
*HandleList
;
104 EFI_HANDLE
*CurrentHandle
;
105 SHELL_STATUS ShellStatus
;
108 EFI_HII_DATABASE_PROTOCOL
*HiiDb
;
112 ShellStatus
= SHELL_SUCCESS
;
113 Status
= EFI_SUCCESS
;
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
);
121 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DRVCFG_HEADER
), gShellDriver1HiiHandle
);
124 // First do HII method
126 HandleList
= GetHandleListByProtocol(&gEfiHiiConfigAccessProtocolGuid
);
127 for (CurrentHandle
= HandleList
; CurrentHandle
!= NULL
&& *CurrentHandle
!= NULL
&& ShellStatus
== SHELL_SUCCESS
; CurrentHandle
++){
131 SHELL_FREE_NON_NULL(HandleList
);
134 // Now do EFI 1.10 & UEFI 2.0 drivers
136 HandleList
= GetHandleListByProtocol(&gEfiDriverConfigurationProtocolGuid
);
137 for (CurrentHandle
= HandleList
; CurrentHandle
!= NULL
&& *CurrentHandle
!= NULL
&& ShellStatus
== SHELL_SUCCESS
; CurrentHandle
++){
143 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DRVCFG_NONE
), gShellDriver1HiiHandle
);
144 return (SHELL_SUCCESS
);
147 SHELL_FREE_NON_NULL(HandleList
);
148 return (ShellStatus
);
152 Function to print out configuration information on a configurable handle.
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.
159 @retval SHELL_SUCCESS The operation was successful.
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
172 EFI_HANDLE
*ChildHandleList
;
176 Index1
= DriverHandle
== NULL
? 0 : ConvertHandleToHandleIndex(DriverHandle
);
177 Index2
= ControllerHandle
== NULL
? 0 : ConvertHandleToHandleIndex(ControllerHandle
);
179 if ((ProtocolMask
& BIT0
) == BIT0
) {
185 STRING_TOKEN (STR_DRVCFG_LINE_HII
),
186 gShellDriver1HiiHandle
,
190 if ((ProtocolMask
& BIT1
) == BIT1
) {
191 PARSE_HANDLE_DATABASE_MANAGED_CHILDREN(DriverHandle
, ControllerHandle
, &Count
, &ChildHandleList
);
192 for (LoopVar
= 0 ; LoopVar
<= Count
; LoopVar
++) {
197 STRING_TOKEN (STR_DRVCFG_LINE_DRV
),
198 gShellDriver1HiiHandle
,
201 Count
!= 0 ? ChildHandleList
[LoopVar
] : 0
205 return (SHELL_SUCCESS
);
209 Function to print out configuration information on all configurable handles.
211 @param[in] ChildrenToo TRUE to tewst for children.
213 @retval SHELL_SUCCESS The operation was successful.
217 PrintConfigInfoOnAll(
218 IN CONST BOOLEAN ChildrenToo
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
;
230 SHELL_STATUS ShellStatus
;
238 CurrentHandle
= NULL
;
239 DriverHandleList
= NULL
;
240 CurrentDriver
= NULL
;
241 ShellStatus
= SHELL_SUCCESS
;
243 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DRVCFG_HEADER
), gShellDriver1HiiHandle
);
245 // First do HII method
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
);
253 // get its driver and print options for it.
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
);
264 ShellStatus
= PrintConfigInfoOnSingleHandle(NULL
, *CurrentHandle
, ChildrenToo
, BIT0
);
265 } else if (DriverHandleList
!= NULL
) {
266 for (LoopVar
= 0 ; LoopVar
< Count
; LoopVar
++) {
268 ShellStatus
= PrintConfigInfoOnSingleHandle(DriverHandleList
[LoopVar
], *CurrentHandle
, ChildrenToo
, BIT0
);
271 SHELL_FREE_NON_NULL(DriverHandleList
);
274 SHELL_FREE_NON_NULL(HandleList
);
277 // Now do EFI 1.10 & UEFI 2.0 drivers
279 HandleList
= GetHandleListByProtocol(&gEfiDriverConfigurationProtocolGuid
);
280 for (CurrentHandle
= HandleList
; CurrentHandle
!= NULL
&& *CurrentHandle
!= NULL
&& ShellStatus
== SHELL_SUCCESS
; CurrentHandle
++){
282 ShellStatus
= PrintConfigInfoOnSingleHandle(*CurrentHandle
, NULL
, ChildrenToo
, BIT1
);
284 SHELL_FREE_NON_NULL(HandleList
);
286 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DRVCFG_NONE
), gShellDriver1HiiHandle
);
287 return (SHELL_SUCCESS
);
289 return (ShellStatus
);
292 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
305 ShellCommandRunDrvCfg (
306 IN EFI_HANDLE ImageHandle
,
307 IN EFI_SYSTEM_TABLE
*SystemTable
312 CHAR16
*ProblemParam
;
313 SHELL_STATUS ShellStatus
;
318 ShellStatus
= SHELL_SUCCESS
;
319 Status
= EFI_SUCCESS
;
323 // initialize the shell lib (we must be in non-auto-init...)
325 Status
= ShellInitialize();
326 ASSERT_EFI_ERROR(Status
);
328 Status
= CommandInit();
329 ASSERT_EFI_ERROR(Status
);
332 // parse the command line
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
;
344 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
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");
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
);
359 // Should be DriverHandle
361 Temp2
= ShellCommandLineGetRawValue(Package
, 1);
364 // no driver specified. cannot be export, inport, or set (and no specified language)
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
;
374 // do a loop for validation, forcing, or printing
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")){
383 ShellStatus
= ValidOptionsOnAll(ShellCommandLineGetFlag(Package
, L
"-c"));
384 } else if (ShellCommandLineGetFlag(Package
, L
"-f")){
388 ASSERT(FALSE
);// ShellStatus = ForceOptionsOnAll(ShellCommandLineGetFlag(Package, L"-c"));
391 // display all that are configurable
393 ShellStatus
= PrintConfigInfoOnAll(ShellCommandLineGetFlag(Package
, L
"-c"));
398 // we have a driver handle, make sure it's valid then process it...
403 ShellCommandLineFreeVarList (Package
);
404 SHELL_FREE_NON_NULL(Language
);
405 return (ShellStatus
);