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
27 DumpLoadedImageProtocolInfo (
28 IN EFI_HANDLE TheHandle
33 TheString
= GetProtocolInformationDump(TheHandle
, &gEfiLoadedImageProtocolGuid
, TRUE
);
35 ShellPrintEx(-1, -1, L
"%s", TheString
);
37 SHELL_FREE_NON_NULL(TheString
);
42 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
45 {L
"-verbose", TypeFlag
},
50 Function for 'unload' command.
52 @param[in] ImageHandle Handle to the Image (NULL if Internal).
53 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
57 ShellCommandRunUnload (
58 IN EFI_HANDLE ImageHandle
,
59 IN EFI_SYSTEM_TABLE
*SystemTable
65 SHELL_STATUS ShellStatus
;
68 SHELL_PROMPT_RESPONSE
*Resp
;
71 ShellStatus
= SHELL_SUCCESS
;
78 // initialize the shell lib (we must be in non-auto-init...)
80 Status
= ShellInitialize();
81 ASSERT_EFI_ERROR(Status
);
84 // parse the command line
86 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
87 if (EFI_ERROR(Status
)) {
88 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
89 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
,L
"unload", ProblemParam
);
90 FreePool(ProblemParam
);
91 ShellStatus
= SHELL_INVALID_PARAMETER
;
96 if (ShellCommandLineGetCount(Package
) > 2){
98 // error for too many parameters
100 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"unload");
101 ShellStatus
= SHELL_INVALID_PARAMETER
;
102 } else if (ShellCommandLineGetCount(Package
) < 2) {
103 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
, L
"unload");
104 ShellStatus
= SHELL_INVALID_PARAMETER
;
106 Param1
= ShellCommandLineGetRawValue(Package
, 1);
107 if (Param1
!= NULL
) {
108 Status
= ShellConvertStringToUint64(Param1
, &Value
, TRUE
, FALSE
);
109 TheHandle
= ConvertHandleIndexToHandle((UINTN
)Value
);
112 if (EFI_ERROR(Status
) || Param1
== NULL
|| TheHandle
== NULL
){
113 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"unload", Param1
);
114 ShellStatus
= SHELL_INVALID_PARAMETER
;
116 ASSERT(TheHandle
!= NULL
);
117 if (ShellCommandLineGetFlag(Package
, L
"-v") || ShellCommandLineGetFlag(Package
, L
"-verbose")) {
118 DumpLoadedImageProtocolInfo(TheHandle
);
121 if (!ShellCommandLineGetFlag(Package
, L
"-n")) {
122 Status
= ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_UNLOAD_CONF
), gShellDriver1HiiHandle
, (UINTN
)TheHandle
);
123 Status
= ShellPromptForResponse(ShellPromptResponseTypeYesNo
, NULL
, (VOID
**)&Resp
);
125 if (ShellCommandLineGetFlag(Package
, L
"-n") || (Resp
!= NULL
&& *Resp
== ShellPromptResponseYes
)) {
126 Status
= gBS
->UnloadImage(TheHandle
);
127 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_HANDLE_RESULT
), gShellDriver1HiiHandle
, L
"Unload", (UINTN
)TheHandle
, Status
);
129 SHELL_FREE_NON_NULL(Resp
);
133 if (ShellStatus
== SHELL_SUCCESS
) {
134 if (Status
== EFI_SECURITY_VIOLATION
) {
135 ShellStatus
= SHELL_SECURITY_VIOLATION
;
136 } else if (Status
== EFI_INVALID_PARAMETER
) {
137 ShellStatus
= SHELL_INVALID_PARAMETER
;
138 } else if (EFI_ERROR(Status
)) {
139 ShellStatus
= SHELL_NOT_FOUND
;
143 if (Package
!= NULL
) {
144 ShellCommandLineFreeVarList(Package
);
147 return (ShellStatus
);