2 Main file for Unload shell Driver1 function.
4 Copyright (c) 2010 - 2013, 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"
18 Function to dump LoadedImage info from TheHandle.
20 @param[in] TheHandle The handle to dump info from.
22 @retval EFI_SUCCESS The info was dumped.
23 @retval EFI_INVALID_PARAMETER The handle did not have LoadedImage
27 DumpLoadedImageProtocolInfo (
28 IN EFI_HANDLE TheHandle
31 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
33 CHAR16
*DevicePathText
;
40 Status
= gBS
->OpenProtocol(TheHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**)&Image
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
41 if (EFI_ERROR(Status
)) {
42 return (EFI_INVALID_PARAMETER
);
44 DevicePathText
= ConvertDevicePathToText(Image
->FilePath
, TRUE
, TRUE
);
45 CodeTypeText
= ConvertMemoryType(Image
->ImageCodeType
);
46 DataTypeText
= ConvertMemoryType(Image
->ImageDataType
);
47 PdbPointer
= (CHAR8
*)PeCoffLoaderGetPdbPointer(Image
->ImageBase
);
48 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_UNLOAD_VERBOSE
), gShellDriver1HiiHandle
,
49 ConvertHandleToHandleIndex(TheHandle
),
63 SHELL_FREE_NON_NULL(DevicePathText
);
64 SHELL_FREE_NON_NULL(CodeTypeText
);
65 SHELL_FREE_NON_NULL(DataTypeText
);
70 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
73 {L
"-verbose", TypeFlag
},
78 Function for 'unload' command.
80 @param[in] ImageHandle Handle to the Image (NULL if Internal).
81 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
85 ShellCommandRunUnload (
86 IN EFI_HANDLE ImageHandle
,
87 IN EFI_SYSTEM_TABLE
*SystemTable
93 SHELL_STATUS ShellStatus
;
96 SHELL_PROMPT_RESPONSE
*Resp
;
99 ShellStatus
= SHELL_SUCCESS
;
106 // initialize the shell lib (we must be in non-auto-init...)
108 Status
= ShellInitialize();
109 ASSERT_EFI_ERROR(Status
);
112 // parse the command line
114 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
115 if (EFI_ERROR(Status
)) {
116 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
117 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, ProblemParam
);
118 FreePool(ProblemParam
);
119 ShellStatus
= SHELL_INVALID_PARAMETER
;
124 if (ShellCommandLineGetCount(Package
) > 2){
126 // error for too many parameters
128 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
);
129 ShellStatus
= SHELL_INVALID_PARAMETER
;
130 } else if (ShellCommandLineGetCount(Package
) < 2) {
131 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
);
132 ShellStatus
= SHELL_INVALID_PARAMETER
;
134 Param1
= ShellCommandLineGetRawValue(Package
, 1);
135 if (Param1
!= NULL
) {
136 Status
= ShellConvertStringToUint64(Param1
, &Value
, TRUE
, FALSE
);
137 TheHandle
= ConvertHandleIndexToHandle((UINTN
)Value
);
140 if (EFI_ERROR(Status
) || Param1
== NULL
|| TheHandle
== NULL
){
141 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, Param1
);
142 ShellStatus
= SHELL_INVALID_PARAMETER
;
144 ASSERT(TheHandle
!= NULL
);
145 if (ShellCommandLineGetFlag(Package
, L
"-v") || ShellCommandLineGetFlag(Package
, L
"-verbose")) {
146 DumpLoadedImageProtocolInfo(TheHandle
);
149 if (!ShellCommandLineGetFlag(Package
, L
"-n")) {
150 Status
= ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_UNLOAD_CONF
), gShellDriver1HiiHandle
, (UINTN
)TheHandle
);
151 Status
= ShellPromptForResponse(ShellPromptResponseTypeYesNo
, NULL
, (VOID
**)&Resp
);
153 if (ShellCommandLineGetFlag(Package
, L
"-n") || (Resp
!= NULL
&& *Resp
== ShellPromptResponseYes
)) {
154 Status
= gBS
->UnloadImage(TheHandle
);
155 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HANDLE_RESULT
), gShellDriver1HiiHandle
, L
"Unload", (UINTN
)TheHandle
, Status
);
157 SHELL_FREE_NON_NULL(Resp
);
161 if (ShellStatus
== SHELL_SUCCESS
) {
162 if (Status
== EFI_SECURITY_VIOLATION
) {
163 ShellStatus
= SHELL_SECURITY_VIOLATION
;
164 } else if (Status
== EFI_INVALID_PARAMETER
) {
165 ShellStatus
= SHELL_INVALID_PARAMETER
;
166 } else if (EFI_ERROR(Status
)) {
167 ShellStatus
= SHELL_NOT_FOUND
;
171 if (Package
!= NULL
) {
172 ShellCommandLineFreeVarList(Package
);
175 return (ShellStatus
);