2 Main file for Unload shell Driver1 function.
4 Copyright (c) 2010, 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 translate the EFI_MEMORY_TYPE into a string.
20 @param[in] Memory The memory type.
22 @retval A string representation of the type allocated from BS Pool.
27 IN CONST EFI_MEMORY_TYPE Memory
34 case EfiReservedMemoryType
: StrnCatGrow(&RetVal
, NULL
, L
"EfiReservedMemoryType", 0); break;
35 case EfiLoaderCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiLoaderCode", 0); break;
36 case EfiLoaderData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiLoaderData", 0); break;
37 case EfiBootServicesCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiBootServicesCode", 0); break;
38 case EfiBootServicesData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiBootServicesData", 0); break;
39 case EfiRuntimeServicesCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiRuntimeServicesCode", 0); break;
40 case EfiRuntimeServicesData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiRuntimeServicesData", 0); break;
41 case EfiConventionalMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiConventionalMemory", 0); break;
42 case EfiUnusableMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiUnusableMemory", 0); break;
43 case EfiACPIReclaimMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiACPIReclaimMemory", 0); break;
44 case EfiACPIMemoryNVS
: StrnCatGrow(&RetVal
, NULL
, L
"EfiACPIMemoryNVS", 0); break;
45 case EfiMemoryMappedIO
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMemoryMappedIO", 0); break;
46 case EfiMemoryMappedIOPortSpace
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMemoryMappedIOPortSpace", 0); break;
47 case EfiPalCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiPalCode", 0); break;
48 case EfiMaxMemoryType
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMaxMemoryType", 0); break;
49 default: ASSERT(FALSE
);
55 Function to dump LoadedImage info from TheHandle.
57 @param[in] TheHandle The handle to dump info from.
59 @retval EFI_SUCCESS The info was dumped.
60 @retval EFI_INVALID_PARAMETER The handle did not have LoadedImage
64 DumpLoadedImageProtocolInfo (
65 IN EFI_HANDLE TheHandle
68 EFI_LOADED_IMAGE_PROTOCOL
*Image
;
70 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevicePathToText
;
71 CHAR16
*DevicePathText
;
78 Status
= gBS
->OpenProtocol(TheHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**)&Image
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
79 if (EFI_ERROR(Status
)) {
80 return (EFI_INVALID_PARAMETER
);
83 Status
= gBS
->LocateProtocol(
84 &gEfiDevicePathToTextProtocolGuid
,
86 (VOID
**)&DevicePathToText
);
88 // we now have the device path to text protocol
90 if (!EFI_ERROR(Status
)) {
91 DevicePathText
= DevicePathToText
->ConvertDevicePathToText(Image
->FilePath
, TRUE
, TRUE
);
93 DevicePathText
= NULL
;
96 CodeTypeText
= ConvertMemoryType(Image
->ImageCodeType
);
97 DataTypeText
= ConvertMemoryType(Image
->ImageDataType
);
98 PdbPointer
= (CHAR8
*)PeCoffLoaderGetPdbPointer(Image
->ImageBase
);
99 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_UNLOAD_VERBOSE
), gShellDriver1HiiHandle
,
100 ConvertHandleToHandleIndex(TheHandle
),
114 SHELL_FREE_NON_NULL(DevicePathText
);
115 SHELL_FREE_NON_NULL(CodeTypeText
);
116 SHELL_FREE_NON_NULL(DataTypeText
);
118 return (EFI_SUCCESS
);
121 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
124 {L
"-verbose", TypeFlag
},
129 Function for 'unload' command.
131 @param[in] ImageHandle Handle to the Image (NULL if Internal).
132 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
136 ShellCommandRunUnload (
137 IN EFI_HANDLE ImageHandle
,
138 IN EFI_SYSTEM_TABLE
*SystemTable
143 CHAR16
*ProblemParam
;
144 SHELL_STATUS ShellStatus
;
145 EFI_HANDLE TheHandle
;
146 CONST CHAR16
*Param1
;
147 SHELL_PROMPT_RESPONSE
*Resp
;
149 ShellStatus
= SHELL_SUCCESS
;
154 // initialize the shell lib (we must be in non-auto-init...)
156 Status
= ShellInitialize();
157 ASSERT_EFI_ERROR(Status
);
160 // parse the command line
162 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
163 if (EFI_ERROR(Status
)) {
164 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
165 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, ProblemParam
);
166 FreePool(ProblemParam
);
167 ShellStatus
= SHELL_INVALID_PARAMETER
;
172 if (ShellCommandLineGetCount(Package
) > 2){
174 // error for too many parameters
176 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
);
177 ShellStatus
= SHELL_INVALID_PARAMETER
;
178 } else if (ShellCommandLineGetCount(Package
) < 2) {
179 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
);
180 ShellStatus
= SHELL_INVALID_PARAMETER
;
182 Param1
= ShellCommandLineGetRawValue(Package
, 1);
183 if (Param1
== NULL
|| ConvertHandleIndexToHandle(StrHexToUintn(Param1
)) == NULL
){
184 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, Param1
);
185 ShellStatus
= SHELL_INVALID_PARAMETER
;
187 TheHandle
= ConvertHandleIndexToHandle(StrHexToUintn(Param1
));
188 ASSERT(TheHandle
!= NULL
);
189 if (ShellCommandLineGetFlag(Package
, L
"-v") || ShellCommandLineGetFlag(Package
, L
"-verbose")) {
190 DumpLoadedImageProtocolInfo(TheHandle
);
193 if (!ShellCommandLineGetFlag(Package
, L
"-n")) {
194 Status
= ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_UNLOAD_CONF
), gShellDriver1HiiHandle
, StrHexToUintn(Param1
));
195 Status
= ShellPromptForResponse(ShellPromptResponseTypeYesNo
, NULL
, (VOID
**)&Resp
);
197 if (ShellCommandLineGetFlag(Package
, L
"-n") || (Resp
!= NULL
&& *Resp
== ShellPromptResponseYes
)) {
198 Status
= gBS
->UnloadImage(TheHandle
);
199 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HANDLE_RESULT
), gShellDriver1HiiHandle
, L
"Unload", StrHexToUintn(Param1
), Status
);
201 SHELL_FREE_NON_NULL(Resp
);
205 if (ShellStatus
== SHELL_SUCCESS
) {
206 if (Status
== EFI_SECURITY_VIOLATION
) {
207 ShellStatus
= SHELL_SECURITY_VIOLATION
;
208 } else if (Status
== EFI_INVALID_PARAMETER
) {
209 ShellStatus
= SHELL_INVALID_PARAMETER
;
210 } else if (EFI_ERROR(Status
)) {
211 ShellStatus
= SHELL_NOT_FOUND
;
215 if (Package
!= NULL
) {
216 ShellCommandLineFreeVarList(Package
);
219 return (ShellStatus
);