2 Main file for Drivers shell Driver1 function.
4 (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellDriver1CommandsLib.h"
12 #define MAX_LEN_DRIVER_NAME 35
14 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
15 { L
"-sfo", TypeFlag
},
21 Get a device path (in text format) for a given handle.
23 @param[in] TheHandle The handle to get the device path for.
25 @retval NULL An error occurred.
26 @return A pointer to the driver path as a string. The callee must
30 GetDevicePathTextForHandle (
31 IN EFI_HANDLE TheHandle
35 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
36 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
37 EFI_DEVICE_PATH_PROTOCOL
*FinalPath
;
42 Status
= gBS
->OpenProtocol (
44 &gEfiLoadedImageProtocolGuid
,
45 (VOID
**)&LoadedImage
,
48 EFI_OPEN_PROTOCOL_GET_PROTOCOL
50 if (!EFI_ERROR (Status
)) {
51 Status
= gBS
->OpenProtocol (
52 LoadedImage
->DeviceHandle
,
53 &gEfiDevicePathProtocolGuid
,
54 (VOID
**)&ImageDevicePath
,
57 EFI_OPEN_PROTOCOL_GET_PROTOCOL
59 if (!EFI_ERROR (Status
)) {
60 FinalPath
= AppendDevicePath (ImageDevicePath
, LoadedImage
->FilePath
);
62 LoadedImage
->DeviceHandle
,
63 &gEfiDevicePathProtocolGuid
,
71 &gEfiLoadedImageProtocolGuid
,
77 if (FinalPath
== NULL
) {
81 RetVal
= gEfiShellProtocol
->GetFilePathFromDevicePath (FinalPath
);
83 RetVal
= ConvertDevicePathToText (FinalPath
, TRUE
, TRUE
);
91 Determine if the given handle has Driver Configuration protocol.
93 @param[in] TheHandle The handle to the driver to test.
95 @retval TRUE The driver does have Driver Configuration.
96 @retval FALSE The driver does not have Driver Configuration.
100 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
)) {
114 Determine if the given handle has DriverDiagnostics protocol.
116 @param[in] TheHandle The handle to the driver to test.
118 @retval TRUE The driver does have Driver Diasgnostics.
119 @retval FALSE The driver does not have Driver Diagnostics.
123 IN CONST EFI_HANDLE TheHandle
128 Status
= gBS
->OpenProtocol ((EFI_HANDLE
)TheHandle
, &gEfiDriverDiagnostics2ProtocolGuid
, NULL
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
129 if (EFI_ERROR (Status
)) {
130 Status
= gBS
->OpenProtocol ((EFI_HANDLE
)TheHandle
, &gEfiDriverDiagnosticsProtocolGuid
, NULL
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
131 if (EFI_ERROR (Status
)) {
140 Finds and returns the version of the driver specified by TheHandle.
142 @param[in] TheHandle The driver handle to get the version of.
144 @return The version of the driver.
145 @retval 0xFFFFFFFF An error ocurred.
148 ReturnDriverVersion (
149 IN CONST EFI_HANDLE TheHandle
152 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
158 Status
= gBS
->OpenProtocol ((EFI_HANDLE
)TheHandle
, &gEfiDriverBindingProtocolGuid
, (VOID
**)&DriverBinding
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
159 if (!EFI_ERROR (Status
)) {
160 RetVal
= DriverBinding
->Version
;
161 gBS
->CloseProtocol (TheHandle
, &gEfiDriverBindingProtocolGuid
, gImageHandle
, NULL
);
168 Get image name from Image Handle.
170 @param[in] Handle Image Handle
172 @return A pointer to the image name as a string.
175 GetImageNameFromHandle (
176 IN CONST EFI_HANDLE Handle
180 EFI_DRIVER_BINDING_PROTOCOL
*DriverBinding
;
181 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
182 EFI_DEVICE_PATH_PROTOCOL
*DevPathNode
;
186 UINT32 AuthenticationStatus
;
187 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv2
;
190 DriverBinding
= NULL
;
193 Status
= gBS
->OpenProtocol (
195 &gEfiDriverBindingProtocolGuid
,
196 (VOID
**)&DriverBinding
,
199 EFI_OPEN_PROTOCOL_GET_PROTOCOL
201 if (EFI_ERROR (Status
)) {
205 Status
= gBS
->OpenProtocol (
206 DriverBinding
->ImageHandle
,
207 &gEfiLoadedImageProtocolGuid
,
208 (VOID
**)&LoadedImage
,
211 EFI_OPEN_PROTOCOL_GET_PROTOCOL
213 if (!EFI_ERROR (Status
)) {
214 DevPathNode
= LoadedImage
->FilePath
;
215 if (DevPathNode
== NULL
) {
219 while (!IsDevicePathEnd (DevPathNode
)) {
220 NameGuid
= EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*)DevPathNode
);
221 if (NameGuid
!= NULL
) {
222 Status
= gBS
->HandleProtocol (
223 LoadedImage
->DeviceHandle
,
224 &gEfiFirmwareVolume2ProtocolGuid
,
227 if (!EFI_ERROR (Status
)) {
228 Status
= Fv2
->ReadSection (
231 EFI_SECTION_USER_INTERFACE
,
235 &AuthenticationStatus
237 if (!EFI_ERROR (Status
)) {
246 // Next device path node
248 DevPathNode
= NextDevicePathNode (DevPathNode
);
251 if (ImageName
== NULL
) {
252 ImageName
= ConvertDevicePathToText (LoadedImage
->FilePath
, TRUE
, TRUE
);
260 Function for 'drivers' command.
262 @param[in] ImageHandle Handle to the Image (NULL if Internal).
263 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
267 ShellCommandRunDrivers (
268 IN EFI_HANDLE ImageHandle
,
269 IN EFI_SYSTEM_TABLE
*SystemTable
274 CHAR16
*ProblemParam
;
275 SHELL_STATUS ShellStatus
;
278 EFI_HANDLE
*HandleList
;
279 EFI_HANDLE
*HandleWalker
;
282 CHAR16 ChildCountStr
[21];
283 CHAR16 DeviceCountStr
[21];
285 CONST CHAR16
*FullDriverName
;
286 CHAR16
*TruncatedDriverName
;
288 CHAR16
*FormatString
;
289 UINT32 DriverVersion
;
290 BOOLEAN DriverConfig
;
294 ShellStatus
= SHELL_SUCCESS
;
295 Status
= EFI_SUCCESS
;
301 // initialize the shell lib (we must be in non-auto-init...)
303 Status
= ShellInitialize ();
304 ASSERT_EFI_ERROR (Status
);
306 Status
= CommandInit ();
307 ASSERT_EFI_ERROR (Status
);
310 // parse the command line
312 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
313 if (EFI_ERROR (Status
)) {
314 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
315 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"drivers", ProblemParam
);
316 FreePool (ProblemParam
);
317 ShellStatus
= SHELL_INVALID_PARAMETER
;
322 if (ShellCommandLineGetCount (Package
) > 1) {
323 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"drivers");
324 ShellStatus
= SHELL_INVALID_PARAMETER
;
326 if (ShellCommandLineGetFlag (Package
, L
"-l")) {
327 Lang
= ShellCommandLineGetValue (Package
, L
"-l");
329 Language
= AllocateZeroPool (StrSize (Lang
));
330 AsciiSPrint (Language
, StrSize (Lang
), "%S", Lang
);
332 ASSERT (Language
== NULL
);
333 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"drivers", L
"-l");
334 ShellCommandLineFreeVarList (Package
);
335 return (SHELL_INVALID_PARAMETER
);
339 if (ShellCommandLineGetFlag (Package
, L
"-sfo")) {
341 FormatString
= HiiGetString (gShellDriver1HiiHandle
, STRING_TOKEN (STR_DRIVERS_ITEM_LINE_SFO
), Language
);
343 // print the SFO header
349 STRING_TOKEN (STR_GEN_SFO_HEADER
),
350 gShellDriver1HiiHandle
,
354 FormatString
= HiiGetString (gShellDriver1HiiHandle
, STRING_TOKEN (STR_DRIVERS_ITEM_LINE
), Language
);
356 // print the header row
362 STRING_TOKEN (STR_DRIVERS_HEADER_LINES
),
363 gShellDriver1HiiHandle
367 HandleList
= GetHandleListByProtocol (&gEfiDriverBindingProtocolGuid
);
368 for (HandleWalker
= HandleList
; HandleWalker
!= NULL
&& *HandleWalker
!= NULL
; HandleWalker
++) {
371 Status
= ParseHandleDatabaseForChildDevices (*HandleWalker
, &ChildCount
, NULL
);
372 Status
= PARSE_HANDLE_DATABASE_DEVICES (*HandleWalker
, &DeviceCount
, NULL
);
373 Temp2
= GetDevicePathTextForHandle (*HandleWalker
);
374 DriverVersion
= ReturnDriverVersion (*HandleWalker
);
375 DriverConfig
= ReturnDriverConfig (*HandleWalker
);
376 DriverDiag
= ReturnDriverDiag (*HandleWalker
);
377 FullDriverName
= GetStringNameFromHandle (*HandleWalker
, Language
);
378 ImageName
= GetImageNameFromHandle (*HandleWalker
);
380 UnicodeValueToStringS (ChildCountStr
, sizeof (ChildCountStr
), 0, ChildCount
, 0);
381 UnicodeValueToStringS (DeviceCountStr
, sizeof (DeviceCountStr
), 0, DeviceCount
, 0);
382 TruncatedDriverName
= NULL
;
383 if (!SfoFlag
&& (FullDriverName
!= NULL
)) {
384 TruncatedDriverName
= AllocateZeroPool ((MAX_LEN_DRIVER_NAME
+ 1) * sizeof (CHAR16
));
385 StrnCpyS (TruncatedDriverName
, MAX_LEN_DRIVER_NAME
+ 1, FullDriverName
, MAX_LEN_DRIVER_NAME
);
393 ConvertHandleToHandleIndex (*HandleWalker
),
395 ChildCount
> 0 ? L
'B' : (DeviceCount
> 0 ? L
'D' : L
'?'),
396 DriverConfig
? L
'X' : L
'-',
397 DriverDiag
? L
'X' : L
'-',
398 DeviceCount
> 0 ? DeviceCountStr
: L
"-",
399 ChildCount
> 0 ? ChildCountStr
: L
"-",
401 ImageName
== NULL
? L
"" : ImageName
408 ConvertHandleToHandleIndex (*HandleWalker
),
410 ChildCount
> 0 ? L
'B' : (DeviceCount
> 0 ? L
'D' : L
'?'),
411 DriverConfig
? L
'Y' : L
'N',
412 DriverDiag
? L
'Y' : L
'N',
416 Temp2
== NULL
? L
"" : Temp2
420 if (TruncatedDriverName
!= NULL
) {
421 FreePool (TruncatedDriverName
);
428 if (ImageName
!= NULL
) {
429 FreePool (ImageName
);
432 if (ShellGetExecutionBreakFlag ()) {
433 ShellStatus
= SHELL_ABORTED
;
439 SHELL_FREE_NON_NULL (Language
);
440 ShellCommandLineFreeVarList (Package
);
441 SHELL_FREE_NON_NULL (FormatString
);
444 return (ShellStatus
);