2 Main file for Drivers shell Driver1 function.
4 (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellDriver1CommandsLib.h"
18 #define MAX_LEN_DRIVER_NAME 35
20 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
27 Get a device path (in text format) for a given handle.
29 @param[in] TheHandle The handle to get the device path for.
31 @retval NULL An error occured.
32 @return A pointer to the driver path as a string. The callee must
36 GetDevicePathTextForHandle(
37 IN EFI_HANDLE TheHandle
41 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
42 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
43 EFI_DEVICE_PATH_PROTOCOL
*FinalPath
;
48 Status
= gBS
->OpenProtocol (
50 &gEfiLoadedImageProtocolGuid
,
54 EFI_OPEN_PROTOCOL_GET_PROTOCOL
56 if (!EFI_ERROR (Status
)) {
57 Status
= gBS
->OpenProtocol (
58 LoadedImage
->DeviceHandle
,
59 &gEfiDevicePathProtocolGuid
,
60 (VOID
**)&ImageDevicePath
,
63 EFI_OPEN_PROTOCOL_GET_PROTOCOL
65 if (!EFI_ERROR (Status
)) {
66 FinalPath
= AppendDevicePath (ImageDevicePath
, LoadedImage
->FilePath
);
68 LoadedImage
->DeviceHandle
,
69 &gEfiDevicePathProtocolGuid
,
75 &gEfiLoadedImageProtocolGuid
,
80 if (FinalPath
== NULL
) {
83 RetVal
= gEfiShellProtocol
->GetFilePathFromDevicePath(FinalPath
);
85 RetVal
= ConvertDevicePathToText(FinalPath
, TRUE
, TRUE
);
92 Determine if the given handle has Driver Configuration protocol.
94 @param[in] TheHandle The handle to the driver to test.
96 @retval TRUE The driver does have Driver Configuration.
97 @retval FALSE The driver does not have Driver Configuration.
101 IN CONST EFI_HANDLE TheHandle
105 Status
= gBS
->OpenProtocol((EFI_HANDLE
)TheHandle
, &gEfiDriverConfigurationProtocolGuid
, NULL
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
106 if (EFI_ERROR(Status
)) {
113 Determine if the given handle has DriverDiagnostics protocol.
115 @param[in] TheHandle The handle to the driver to test.
117 @retval TRUE The driver does have Driver Diasgnostics.
118 @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.
146 IN CONST EFI_HANDLE TheHandle
149 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
155 Status
= gBS
->OpenProtocol((EFI_HANDLE
)TheHandle
, &gEfiDriverBindingProtocolGuid
, (VOID
**)&DriverBinding
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
156 if (!EFI_ERROR(Status
)) {
157 RetVal
= DriverBinding
->Version
;
158 gBS
->CloseProtocol(TheHandle
, &gEfiDriverBindingProtocolGuid
, gImageHandle
, NULL
);
164 Get image name from Image Handle.
166 @param[in] Handle Image Handle
168 @return A pointer to the image name as a string.
171 GetImageNameFromHandle (
172 IN CONST EFI_HANDLE Handle
176 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
177 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
178 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
182 UINT32 AuthenticationStatus
;
183 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
186 DriverBinding
= NULL
;
189 Status
= gBS
->OpenProtocol (
191 &gEfiDriverBindingProtocolGuid
,
192 (VOID
**) &DriverBinding
,
195 EFI_OPEN_PROTOCOL_GET_PROTOCOL
197 if (EFI_ERROR (Status
)) {
200 Status
= gBS
->OpenProtocol (
201 DriverBinding
->ImageHandle
,
202 &gEfiLoadedImageProtocolGuid
,
203 (VOID
**)&LoadedImage
,
206 EFI_OPEN_PROTOCOL_GET_PROTOCOL
208 if (!EFI_ERROR (Status
)) {
209 DevPathNode
= LoadedImage
->FilePath
;
210 if (DevPathNode
== NULL
) {
213 while (!IsDevicePathEnd (DevPathNode
)) {
214 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)DevPathNode
);
215 if (NameGuid
!= NULL
) {
216 Status
= gBS
->HandleProtocol (
217 LoadedImage
->DeviceHandle
,
218 &gEfiFirmwareVolume2ProtocolGuid
,
221 if (!EFI_ERROR (Status
)) {
222 Status
= Fv2
->ReadSection (
225 EFI_SECTION_USER_INTERFACE
,
229 &AuthenticationStatus
231 if (!EFI_ERROR (Status
)) {
238 // Next device path node
240 DevPathNode
= NextDevicePathNode (DevPathNode
);
242 if (ImageName
== NULL
) {
243 ImageName
= ConvertDevicePathToText (LoadedImage
->FilePath
, TRUE
, TRUE
);
250 Function for 'drivers' command.
252 @param[in] ImageHandle Handle to the Image (NULL if Internal).
253 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
257 ShellCommandRunDrivers (
258 IN EFI_HANDLE ImageHandle
,
259 IN EFI_SYSTEM_TABLE
*SystemTable
264 CHAR16
*ProblemParam
;
265 SHELL_STATUS ShellStatus
;
268 EFI_HANDLE
*HandleList
;
269 EFI_HANDLE
*HandleWalker
;
273 CONST CHAR16
*FullDriverName
;
274 CHAR16
*TruncatedDriverName
;
276 CHAR16
*FormatString
;
277 UINT32 DriverVersion
;
278 BOOLEAN DriverConfig
;
282 ShellStatus
= SHELL_SUCCESS
;
283 Status
= EFI_SUCCESS
;
289 // initialize the shell lib (we must be in non-auto-init...)
291 Status
= ShellInitialize();
292 ASSERT_EFI_ERROR(Status
);
294 Status
= CommandInit();
295 ASSERT_EFI_ERROR(Status
);
298 // parse the command line
300 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
301 if (EFI_ERROR(Status
)) {
302 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
303 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"drivers", ProblemParam
);
304 FreePool(ProblemParam
);
305 ShellStatus
= SHELL_INVALID_PARAMETER
;
310 if (ShellCommandLineGetCount(Package
) > 1) {
311 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"drivers");
312 ShellStatus
= SHELL_INVALID_PARAMETER
;
314 if (ShellCommandLineGetFlag(Package
, L
"-l")){
315 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
317 Language
= AllocateZeroPool(StrSize(Lang
));
318 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
320 ASSERT(Language
== NULL
);
321 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"drivers", L
"-l");
322 ShellCommandLineFreeVarList (Package
);
323 return (SHELL_INVALID_PARAMETER
);
327 if (ShellCommandLineGetFlag (Package
, L
"-sfo")) {
329 FormatString
= HiiGetString (gShellDriver1HiiHandle
, STRING_TOKEN (STR_DRIVERS_ITEM_LINE_SFO
), Language
);
331 // print the SFO header
337 STRING_TOKEN (STR_GEN_SFO_HEADER
),
338 gShellDriver1HiiHandle
,
341 FormatString
= HiiGetString (gShellDriver1HiiHandle
, STRING_TOKEN (STR_DRIVERS_ITEM_LINE
), Language
);
343 // print the header row
349 STRING_TOKEN (STR_DRIVERS_HEADER_LINES
),
350 gShellDriver1HiiHandle
);
353 HandleList
= GetHandleListByProtocol(&gEfiDriverBindingProtocolGuid
);
354 for (HandleWalker
= HandleList
; HandleWalker
!= NULL
&& *HandleWalker
!= NULL
; HandleWalker
++){
357 Status
= ParseHandleDatabaseForChildDevices (*HandleWalker
, &ChildCount
, NULL
);
358 Status
= PARSE_HANDLE_DATABASE_DEVICES (*HandleWalker
, &DeviceCount
, NULL
);
359 Temp2
= GetDevicePathTextForHandle(*HandleWalker
);
360 DriverVersion
= ReturnDriverVersion(*HandleWalker
);
361 DriverConfig
= ReturnDriverConfig(*HandleWalker
);
362 DriverDiag
= ReturnDriverDiag (*HandleWalker
);
363 FullDriverName
= GetStringNameFromHandle(*HandleWalker
, Language
);
364 ImageName
= GetImageNameFromHandle (*HandleWalker
);
366 TruncatedDriverName
= NULL
;
367 if (!SfoFlag
&& (FullDriverName
!= NULL
)) {
368 TruncatedDriverName
= AllocateZeroPool ((MAX_LEN_DRIVER_NAME
+ 1) * sizeof (CHAR16
));
369 StrnCpyS (TruncatedDriverName
, MAX_LEN_DRIVER_NAME
+ 1, FullDriverName
, MAX_LEN_DRIVER_NAME
);
376 ConvertHandleToHandleIndex(*HandleWalker
),
378 ChildCount
> 0?L
'B':(DeviceCount
> 0?L
'D':L
'?'),
379 DriverConfig
?L
'Y':L
'N',
380 DriverDiag
?L
'Y':L
'N',
383 SfoFlag
?FullDriverName
:TruncatedDriverName
,
384 SfoFlag
? (Temp2
== NULL
? L
"" : Temp2
) : (ImageName
== NULL
? L
"" : ImageName
)
386 if (TruncatedDriverName
!= NULL
) {
387 FreePool (TruncatedDriverName
);
392 if (ImageName
!= NULL
) {
393 FreePool (ImageName
);
396 if (ShellGetExecutionBreakFlag ()) {
397 ShellStatus
= SHELL_ABORTED
;
402 SHELL_FREE_NON_NULL(Language
);
403 ShellCommandLineFreeVarList (Package
);
404 SHELL_FREE_NON_NULL(FormatString
);
407 return (ShellStatus
);