2 Main file for attrib shell level 2 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2011, 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 "UefiShellLevel2CommandsLib.h"
18 // This function was from from the BdsLib implementation in
19 // IntelFrameworkModulePkg\Library\GenericBdsLib\BdsConnect.c
20 // function name: BdsLibConnectAllEfi
22 This function will connect all current system handles recursively. The
23 connection will finish until every handle's child handle created if it have.
25 @retval EFI_SUCCESS All handles and it's child handle have been
27 @retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().
38 EFI_HANDLE
*HandleBuffer
;
41 Status
= gBS
->LocateHandleBuffer (
48 if (EFI_ERROR (Status
)) {
52 for (Index
= 0; Index
< HandleCount
; Index
++) {
53 Status
= gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
56 if (HandleBuffer
!= NULL
) {
57 FreePool (HandleBuffer
);
64 function to load a .EFI driver into memory and possible connect the driver.
66 if FileName is NULL then ASSERT.
68 @param[in] FileName FileName of the driver to load
69 @param[in] Connect Whether to connect or not
71 @retval EFI_SUCCESS the driver was loaded and if Connect was
72 true then connect was attempted. Connection may
74 @retval EFI_OUT_OF_RESOURCES there was insufficient memory
79 IN CONST CHAR16
*FileName
,
80 IN CONST BOOLEAN Connect
83 EFI_HANDLE LoadedDriverHandle
;
85 EFI_DEVICE_PATH_PROTOCOL
*FilePath
;
86 EFI_LOADED_IMAGE_PROTOCOL
*LoadedDriverImage
;
88 LoadedDriverImage
= NULL
;
90 LoadedDriverHandle
= NULL
;
93 ASSERT (FileName
!= NULL
);
96 // Fix local copies of the protocol pointers
98 Status
= CommandInit();
99 ASSERT_EFI_ERROR(Status
);
102 // Convert to DEVICE_PATH
104 FilePath
= gEfiShellProtocol
->GetDevicePathFromFilePath(FileName
);
106 if (FilePath
== NULL
) {
108 return (EFI_INVALID_PARAMETER
);
112 // Use LoadImage to get it into memory
114 Status
= gBS
->LoadImage(
120 &LoadedDriverHandle
);
122 if (EFI_ERROR(Status
)) {
123 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_LOAD_NOT_IMAGE
), gShellLevel2HiiHandle
, FileName
, Status
);
126 // Make sure it is a driver image
128 Status
= gBS
->HandleProtocol (LoadedDriverHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
*) &LoadedDriverImage
);
130 ASSERT (LoadedDriverImage
!= NULL
);
132 if ( EFI_ERROR(Status
)
133 || ( LoadedDriverImage
->ImageCodeType
!= EfiBootServicesCode
134 && LoadedDriverImage
->ImageCodeType
!= EfiRuntimeServicesCode
)
136 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_LOAD_NOT_DRIVER
), gShellLevel2HiiHandle
, FileName
);
139 // Exit and unload the non-driver image
141 gBS
->Exit(LoadedDriverHandle
, EFI_INVALID_PARAMETER
, 0, NULL
);
142 Status
= EFI_INVALID_PARAMETER
;
146 if (!EFI_ERROR(Status
)) {
150 Status
= gBS
->StartImage(LoadedDriverHandle
, NULL
, NULL
);
151 if (EFI_ERROR(Status
)) {
152 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_LOAD_ERROR
), gShellLevel2HiiHandle
, FileName
, Status
);
154 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_LOAD_LOADED
), gShellLevel2HiiHandle
, FileName
, LoadedDriverImage
->ImageBase
, Status
);
158 if (!EFI_ERROR(Status
) && Connect
) {
162 Status
= ConnectAllEfi();
166 // clean up memory...
168 if (FilePath
!= NULL
) {
175 STATIC CONST SHELL_PARAM_ITEM LoadParamList
[] = {
181 Function for 'load' command.
183 @param[in] ImageHandle Handle to the Image (NULL if Internal).
184 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
188 ShellCommandRunLoad (
189 IN EFI_HANDLE ImageHandle
,
190 IN EFI_SYSTEM_TABLE
*SystemTable
195 CHAR16
*ProblemParam
;
196 SHELL_STATUS ShellStatus
;
198 EFI_SHELL_FILE_INFO
*ListHead
;
199 EFI_SHELL_FILE_INFO
*Node
;
203 ShellStatus
= SHELL_SUCCESS
;
206 // initialize the shell lib (we must be in non-auto-init...)
208 Status
= ShellInitialize();
209 ASSERT_EFI_ERROR(Status
);
212 // parse the command line
214 Status
= ShellCommandLineParse (LoadParamList
, &Package
, &ProblemParam
, TRUE
);
215 if (EFI_ERROR(Status
)) {
216 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
217 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"load", ProblemParam
);
218 FreePool(ProblemParam
);
219 ShellStatus
= SHELL_INVALID_PARAMETER
;
227 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
229 } else if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
231 // we didnt get a single file to load parameter
233 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel2HiiHandle
, L
"load");
234 ShellStatus
= SHELL_INVALID_PARAMETER
;
237 ; ShellCommandLineGetRawValue(Package
, ParamCount
) != NULL
240 Status
= ShellOpenFileMetaArg((CHAR16
*)ShellCommandLineGetRawValue(Package
, ParamCount
), EFI_FILE_MODE_READ
, &ListHead
);
241 if (!EFI_ERROR(Status
)) {
242 for ( Node
= (EFI_SHELL_FILE_INFO
*)GetFirstNode(&ListHead
->Link
)
243 ; !IsNull(&ListHead
->Link
, &Node
->Link
)
244 ; Node
= (EFI_SHELL_FILE_INFO
*)GetNextNode(&ListHead
->Link
, &Node
->Link
)
247 // once we have an error preserve that value, but finish the loop.
249 if (EFI_ERROR(Status
)) {
250 LoadDriver(Node
->FullName
, (BOOLEAN
)(ShellCommandLineGetFlag(Package
, L
"-nc")==FALSE
));
252 Status
= LoadDriver(Node
->FullName
, (BOOLEAN
)(ShellCommandLineGetFlag(Package
, L
"-nc")==FALSE
));
254 } // for loop for multi-open
255 if (EFI_ERROR(Status
)) {
256 ShellCloseFileMetaArg(&ListHead
);
258 Status
= ShellCloseFileMetaArg(&ListHead
);;
264 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_FILE_NF
), gShellLevel2HiiHandle
, L
"load", (CHAR16
*)ShellCommandLineGetRawValue(Package
, ParamCount
));
265 ShellStatus
= SHELL_NOT_FOUND
;
267 } // for loop for params
271 // free the command line package
273 ShellCommandLineFreeVarList (Package
);
276 if (EFI_ERROR(Status
) && ShellStatus
== SHELL_SUCCESS
) {
277 ShellStatus
= SHELL_DEVICE_ERROR
;
280 return (ShellStatus
);