2 Main file for Drivers shell Driver1 function.
4 Copyright (c) 2010 - 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 "UefiShellDriver1CommandsLib.h"
17 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
24 Get a device path (in text format) for a given handle.
26 @param[in] TheHandle The handle to get the device path for.
28 @retval NULL An error occured.
29 @return A pointer to the driver path as a string. The callee must
34 GetDevicePathTextForHandle(
35 IN EFI_HANDLE TheHandle
39 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
40 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
41 EFI_DEVICE_PATH_PROTOCOL
*FinalPath
;
46 Status
= gBS
->OpenProtocol (
48 &gEfiLoadedImageProtocolGuid
,
52 EFI_OPEN_PROTOCOL_GET_PROTOCOL
54 if (!EFI_ERROR (Status
)) {
55 Status
= gBS
->OpenProtocol (
56 LoadedImage
->DeviceHandle
,
57 &gEfiDevicePathProtocolGuid
,
58 (VOID
**)&ImageDevicePath
,
61 EFI_OPEN_PROTOCOL_GET_PROTOCOL
63 if (!EFI_ERROR (Status
)) {
64 FinalPath
= AppendDevicePath (ImageDevicePath
, LoadedImage
->FilePath
);
66 LoadedImage
->DeviceHandle
,
67 &gEfiDevicePathProtocolGuid
,
73 &gEfiLoadedImageProtocolGuid
,
78 if (FinalPath
== NULL
) {
81 RetVal
= gEfiShellProtocol
->GetFilePathFromDevicePath(FinalPath
);
83 RetVal
= gDevPathToText
->ConvertDevicePathToText(FinalPath
, TRUE
, TRUE
);
90 Determine if the given handle has Driver Configuration protocol.
92 @param[in] TheHandle The handle to the driver to test.
94 @retval TRUE The driver does have Driver Configuration.
95 @retval FALSE The driver does not have Driver Configuration.
100 IN CONST EFI_HANDLE TheHandle
104 Status
= gBS
->OpenProtocol((EFI_HANDLE
)TheHandle
, &gEfiDriverConfigurationProtocolGuid
, NULL
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
105 if (EFI_ERROR(Status
)) {
112 Determine if the given handle has DriverDiagnostics protocol.
114 @param[in] TheHandle The handle to the driver to test.
116 @retval TRUE The driver does have Driver Diasgnostics.
117 @retval FALSE The driver does not have Driver Diagnostics.
122 IN CONST EFI_HANDLE TheHandle
126 Status
= gBS
->OpenProtocol((EFI_HANDLE
)TheHandle
, &gEfiDriverDiagnostics2ProtocolGuid
, NULL
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
127 if (EFI_ERROR(Status
)) {
128 Status
= gBS
->OpenProtocol((EFI_HANDLE
)TheHandle
, &gEfiDriverDiagnosticsProtocolGuid
, NULL
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
129 if (EFI_ERROR(Status
)) {
137 Finds and returns the version of the driver specified by TheHandle.
139 @param[in] TheHandle The driver handle to get the version of.
141 @return The version of the driver.
142 @retval 0xFFFFFFFF An error ocurred.
147 IN CONST EFI_HANDLE TheHandle
150 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
156 Status
= gBS
->OpenProtocol((EFI_HANDLE
)TheHandle
, &gEfiDriverBindingProtocolGuid
, (VOID
**)&DriverBinding
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
157 if (!EFI_ERROR(Status
)) {
158 RetVal
= DriverBinding
->Version
;
159 gBS
->CloseProtocol(TheHandle
, &gEfiDriverBindingProtocolGuid
, gImageHandle
, NULL
);
165 Function for 'drivers' command.
167 @param[in] ImageHandle Handle to the Image (NULL if Internal).
168 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
172 ShellCommandRunDrivers (
173 IN EFI_HANDLE ImageHandle
,
174 IN EFI_SYSTEM_TABLE
*SystemTable
179 CHAR16
*ProblemParam
;
180 SHELL_STATUS ShellStatus
;
183 EFI_HANDLE
*HandleList
;
184 EFI_HANDLE
*HandleWalker
;
188 CHAR16
*FormatString
;
189 UINT32 DriverVersion
;
190 BOOLEAN DriverConfig
;
193 ShellStatus
= SHELL_SUCCESS
;
194 Status
= EFI_SUCCESS
;
199 // initialize the shell lib (we must be in non-auto-init...)
201 Status
= ShellInitialize();
202 ASSERT_EFI_ERROR(Status
);
204 Status
= CommandInit();
205 ASSERT_EFI_ERROR(Status
);
208 // parse the command line
210 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
211 if (EFI_ERROR(Status
)) {
212 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
213 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, ProblemParam
);
214 FreePool(ProblemParam
);
215 ShellStatus
= SHELL_INVALID_PARAMETER
;
220 if (ShellCommandLineGetCount(Package
) > 1) {
221 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
);
222 ShellStatus
= SHELL_INVALID_PARAMETER
;
224 if (ShellCommandLineGetFlag(Package
, L
"-l")){
225 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
227 Language
= AllocateZeroPool(StrSize(Lang
));
228 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
230 ASSERT(Language
== NULL
);
231 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"-l");
232 ShellCommandLineFreeVarList (Package
);
233 return (SHELL_INVALID_PARAMETER
);
237 if (ShellCommandLineGetFlag(Package
, L
"-sfo")) {
238 FormatString
= HiiGetString(gShellDriver1HiiHandle
, STRING_TOKEN(STR_DRIVERS_ITEM_LINE_SFO
), Language
);
240 FormatString
= HiiGetString(gShellDriver1HiiHandle
, STRING_TOKEN(STR_DRIVERS_ITEM_LINE
), Language
);
242 // print the header row
248 STRING_TOKEN(STR_DRIVERS_HEADER_LINES
),
249 gShellDriver1HiiHandle
);
252 HandleList
= GetHandleListByProtocol(&gEfiDriverBindingProtocolGuid
);
253 for (HandleWalker
= HandleList
; HandleWalker
!= NULL
&& *HandleWalker
!= NULL
; HandleWalker
++){
256 Status
= ParseHandleDatabaseForChildDevices (*HandleWalker
, &ChildCount
, NULL
);
257 Status
= PARSE_HANDLE_DATABASE_DEVICES (*HandleWalker
, &DeviceCount
, NULL
);
258 Temp2
= GetDevicePathTextForHandle(*HandleWalker
);
259 DriverVersion
= ReturnDriverVersion(*HandleWalker
);
260 DriverConfig
= ReturnDriverConfig(*HandleWalker
);
261 DriverDiag
= ReturnDriverDiag (*HandleWalker
);
262 Lang
= GetStringNameFromHandle(*HandleWalker
, Language
);
268 ConvertHandleToHandleIndex(*HandleWalker
),
270 ChildCount
> 0?L
'B':(DeviceCount
> 0?L
'D':L
'?'),
271 DriverConfig
?L
'Y':L
'N',
272 DriverDiag
?L
'Y':L
'N',
276 Temp2
==NULL
?L
"":Temp2
283 SHELL_FREE_NON_NULL(Language
);
284 ShellCommandLineFreeVarList (Package
);
285 SHELL_FREE_NON_NULL(FormatString
);
288 return (ShellStatus
);