2 Main file for Unload shell Driver1 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2014, 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"
19 Function to dump LoadedImage info from TheHandle.
21 @param[in] TheHandle The handle to dump info from.
23 @retval EFI_SUCCESS The info was dumped.
24 @retval EFI_INVALID_PARAMETER The handle did not have LoadedImage
28 DumpLoadedImageProtocolInfo (
29 IN EFI_HANDLE TheHandle
34 TheString
= GetProtocolInformationDump(TheHandle
, &gEfiLoadedImageProtocolGuid
, TRUE
);
36 ShellPrintEx(-1, -1, L
"%s", TheString
);
38 SHELL_FREE_NON_NULL(TheString
);
43 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
46 {L
"-verbose", TypeFlag
},
51 Function for 'unload' command.
53 @param[in] ImageHandle Handle to the Image (NULL if Internal).
54 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
58 ShellCommandRunUnload (
59 IN EFI_HANDLE ImageHandle
,
60 IN EFI_SYSTEM_TABLE
*SystemTable
66 SHELL_STATUS ShellStatus
;
69 SHELL_PROMPT_RESPONSE
*Resp
;
72 ShellStatus
= SHELL_SUCCESS
;
79 // initialize the shell lib (we must be in non-auto-init...)
81 Status
= ShellInitialize();
82 ASSERT_EFI_ERROR(Status
);
85 // parse the command line
87 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
88 if (EFI_ERROR(Status
)) {
89 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
90 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
,L
"unload", ProblemParam
);
91 FreePool(ProblemParam
);
92 ShellStatus
= SHELL_INVALID_PARAMETER
;
97 if (ShellCommandLineGetCount(Package
) > 2){
99 // error for too many parameters
101 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"unload");
102 ShellStatus
= SHELL_INVALID_PARAMETER
;
103 } else if (ShellCommandLineGetCount(Package
) < 2) {
104 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
, L
"unload");
105 ShellStatus
= SHELL_INVALID_PARAMETER
;
107 Param1
= ShellCommandLineGetRawValue(Package
, 1);
108 if (Param1
!= NULL
) {
109 Status
= ShellConvertStringToUint64(Param1
, &Value
, TRUE
, FALSE
);
110 TheHandle
= ConvertHandleIndexToHandle((UINTN
)Value
);
113 if (EFI_ERROR(Status
) || Param1
== NULL
|| TheHandle
== NULL
){
114 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"unload", Param1
);
115 ShellStatus
= SHELL_INVALID_PARAMETER
;
117 ASSERT(TheHandle
!= NULL
);
118 if (ShellCommandLineGetFlag(Package
, L
"-v") || ShellCommandLineGetFlag(Package
, L
"-verbose")) {
119 DumpLoadedImageProtocolInfo(TheHandle
);
122 if (!ShellCommandLineGetFlag(Package
, L
"-n")) {
123 Status
= ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_UNLOAD_CONF
), gShellDriver1HiiHandle
, (UINTN
)TheHandle
);
124 Status
= ShellPromptForResponse(ShellPromptResponseTypeYesNo
, NULL
, (VOID
**)&Resp
);
126 if (ShellCommandLineGetFlag(Package
, L
"-n") || (Resp
!= NULL
&& *Resp
== ShellPromptResponseYes
)) {
127 Status
= gBS
->UnloadImage(TheHandle
);
128 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HANDLE_RESULT
), gShellDriver1HiiHandle
, L
"Unload", (UINTN
)TheHandle
, Status
);
130 SHELL_FREE_NON_NULL(Resp
);
134 if (ShellStatus
== SHELL_SUCCESS
) {
135 if (Status
== EFI_SECURITY_VIOLATION
) {
136 ShellStatus
= SHELL_SECURITY_VIOLATION
;
137 } else if (Status
== EFI_INVALID_PARAMETER
) {
138 ShellStatus
= SHELL_INVALID_PARAMETER
;
139 } else if (EFI_ERROR(Status
)) {
140 ShellStatus
= SHELL_NOT_FOUND
;
144 if (Package
!= NULL
) {
145 ShellCommandLineFreeVarList(Package
);
148 return (ShellStatus
);