2 Main file for Unload shell Driver1 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellDriver1CommandsLib.h"
13 Function to dump LoadedImage info from TheHandle.
15 @param[in] TheHandle The handle to dump info from.
17 @retval EFI_SUCCESS The info was dumped.
18 @retval EFI_INVALID_PARAMETER The handle did not have LoadedImage
21 DumpLoadedImageProtocolInfo (
22 IN EFI_HANDLE TheHandle
27 TheString
= GetProtocolInformationDump (TheHandle
, &gEfiLoadedImageProtocolGuid
, TRUE
);
29 ShellPrintEx (-1, -1, L
"%s", TheString
);
31 SHELL_FREE_NON_NULL (TheString
);
36 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
39 { L
"-verbose", TypeFlag
},
44 Function for 'unload' command.
46 @param[in] ImageHandle Handle to the Image (NULL if Internal).
47 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
51 ShellCommandRunUnload (
52 IN EFI_HANDLE ImageHandle
,
53 IN EFI_SYSTEM_TABLE
*SystemTable
59 SHELL_STATUS ShellStatus
;
62 SHELL_PROMPT_RESPONSE
*Resp
;
65 ShellStatus
= SHELL_SUCCESS
;
72 // initialize the shell lib (we must be in non-auto-init...)
74 Status
= ShellInitialize ();
75 ASSERT_EFI_ERROR (Status
);
78 // parse the command line
80 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
81 if (EFI_ERROR (Status
)) {
82 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
83 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"unload", ProblemParam
);
84 FreePool (ProblemParam
);
85 ShellStatus
= SHELL_INVALID_PARAMETER
;
90 if (ShellCommandLineGetCount (Package
) > 2) {
92 // error for too many parameters
94 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"unload");
95 ShellStatus
= SHELL_INVALID_PARAMETER
;
96 } else if (ShellCommandLineGetCount (Package
) < 2) {
97 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellDriver1HiiHandle
, L
"unload");
98 ShellStatus
= SHELL_INVALID_PARAMETER
;
100 Param1
= ShellCommandLineGetRawValue (Package
, 1);
101 if (Param1
!= NULL
) {
102 Status
= ShellConvertStringToUint64 (Param1
, &Value
, TRUE
, FALSE
);
103 TheHandle
= ConvertHandleIndexToHandle ((UINTN
)Value
);
106 if (EFI_ERROR (Status
) || (Param1
== NULL
) || (TheHandle
== NULL
)) {
107 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_INV_HANDLE
), gShellDriver1HiiHandle
, L
"unload", Param1
);
108 ShellStatus
= SHELL_INVALID_PARAMETER
;
110 ASSERT (TheHandle
!= NULL
);
111 if (ShellCommandLineGetFlag (Package
, L
"-v") || ShellCommandLineGetFlag (Package
, L
"-verbose")) {
112 DumpLoadedImageProtocolInfo (TheHandle
);
115 if (!ShellCommandLineGetFlag (Package
, L
"-n")) {
116 Status
= ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_UNLOAD_CONF
), gShellDriver1HiiHandle
, (UINTN
)TheHandle
);
117 Status
= ShellPromptForResponse (ShellPromptResponseTypeYesNo
, NULL
, (VOID
**)&Resp
);
120 if (ShellCommandLineGetFlag (Package
, L
"-n") || ((Resp
!= NULL
) && (*Resp
== ShellPromptResponseYes
))) {
121 Status
= gBS
->UnloadImage (TheHandle
);
122 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_HANDLE_RESULT
), gShellDriver1HiiHandle
, L
"Unload", (UINTN
)TheHandle
, Status
);
125 SHELL_FREE_NON_NULL (Resp
);
130 if (ShellStatus
== SHELL_SUCCESS
) {
131 if (Status
== EFI_SECURITY_VIOLATION
) {
132 ShellStatus
= SHELL_SECURITY_VIOLATION
;
133 } else if (Status
== EFI_INVALID_PARAMETER
) {
134 ShellStatus
= SHELL_INVALID_PARAMETER
;
135 } else if (EFI_ERROR (Status
)) {
136 ShellStatus
= SHELL_NOT_FOUND
;
140 if (Package
!= NULL
) {
141 ShellCommandLineFreeVarList (Package
);
144 return (ShellStatus
);