TianoCore EDK2 master
Loading...
Searching...
No Matches
Unload.c
Go to the documentation of this file.
1
11
22 IN EFI_HANDLE TheHandle
23 )
24{
25 CHAR16 *TheString;
26
27 TheString = GetProtocolInformationDump (TheHandle, &gEfiLoadedImageProtocolGuid, TRUE);
28 if (TheString == NULL) {
29 return (EFI_INVALID_PARAMETER);
30 }
31
32 ShellPrintEx (-1, -1, L"%s", TheString);
33
34 SHELL_FREE_NON_NULL (TheString);
35
36 return (EFI_SUCCESS);
37}
38
39STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
40 { L"-n", TypeFlag },
41 { L"-v", TypeFlag },
42 { L"-verbose", TypeFlag },
43 { NULL, TypeMax }
44};
45
53EFIAPI
55 IN EFI_HANDLE ImageHandle,
56 IN EFI_SYSTEM_TABLE *SystemTable
57 )
58{
59 EFI_STATUS Status;
60 LIST_ENTRY *Package;
61 CHAR16 *ProblemParam;
62 SHELL_STATUS ShellStatus;
63 EFI_HANDLE TheHandle;
64 CONST CHAR16 *Param1;
66 UINT64 Value;
67
68 ShellStatus = SHELL_SUCCESS;
69 Package = NULL;
70 Resp = NULL;
71 Value = 0;
72 TheHandle = NULL;
73
74 //
75 // initialize the shell lib (we must be in non-auto-init...)
76 //
77 Status = ShellInitialize ();
78 ASSERT_EFI_ERROR (Status);
79
80 //
81 // parse the command line
82 //
83 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
84 if (EFI_ERROR (Status)) {
85 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
86 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"unload", ProblemParam);
87 FreePool (ProblemParam);
88 ShellStatus = SHELL_INVALID_PARAMETER;
89 } else {
90 ASSERT (FALSE);
91 }
92 } else {
93 if (ShellCommandLineGetCount (Package) > 2) {
94 //
95 // error for too many parameters
96 //
97 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"unload");
98 ShellStatus = SHELL_INVALID_PARAMETER;
99 } else if (ShellCommandLineGetCount (Package) < 2) {
100 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDriver1HiiHandle, L"unload");
101 ShellStatus = SHELL_INVALID_PARAMETER;
102 } else {
103 Param1 = ShellCommandLineGetRawValue (Package, 1);
104 if (Param1 != NULL) {
105 Status = ShellConvertStringToUint64 (Param1, &Value, TRUE, FALSE);
106 TheHandle = ConvertHandleIndexToHandle ((UINTN)Value);
107 }
108
109 if (EFI_ERROR (Status) || (Param1 == NULL) || (TheHandle == NULL)) {
110 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_HANDLE), gShellDriver1HiiHandle, L"unload", Param1);
111 ShellStatus = SHELL_INVALID_PARAMETER;
112 } else {
113 ASSERT (TheHandle != NULL);
114 if (ShellCommandLineGetFlag (Package, L"-v") || ShellCommandLineGetFlag (Package, L"-verbose")) {
115 DumpLoadedImageProtocolInfo (TheHandle);
116 }
117
118 if (!ShellCommandLineGetFlag (Package, L"-n")) {
119 Status = ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_UNLOAD_CONF), gShellDriver1HiiHandle, (UINTN)TheHandle);
120 Status = ShellPromptForResponse (ShellPromptResponseTypeYesNo, NULL, (VOID **)&Resp);
121 }
122
123 if (ShellCommandLineGetFlag (Package, L"-n") || ((Resp != NULL) && (*Resp == ShellPromptResponseYes))) {
124 Status = gBS->UnloadImage (TheHandle);
125 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_HANDLE_RESULT), gShellDriver1HiiHandle, L"Unload", (UINTN)TheHandle, Status);
126 }
127
128 SHELL_FREE_NON_NULL (Resp);
129 }
130 }
131 }
132
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;
140 }
141 }
142
143 if (Package != NULL) {
145 }
146
147 return (ShellStatus);
148}
UINT64 UINTN
VOID EFIAPI FreePool(IN VOID *Buffer)
CHAR16 *EFIAPI GetProtocolInformationDump(IN CONST EFI_HANDLE TheHandle, IN CONST EFI_GUID *Guid, IN CONST BOOLEAN Verbose)
EFI_HANDLE EFIAPI ConvertHandleIndexToHandle(IN CONST UINTN TheIndex)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_SECURITY_VIOLATION
Definition: Shell.h:141
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
EFI_STATUS EFIAPI ShellPromptForResponse(IN SHELL_PROMPT_REQUEST_TYPE Type, IN CHAR16 *Prompt OPTIONAL, IN OUT VOID **Response OPTIONAL)
SHELL_PROMPT_RESPONSE
Definition: ShellLib.h:1198
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellConvertStringToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
SHELL_STATUS EFIAPI ShellCommandRunUnload(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Unload.c:54
EFI_STATUS DumpLoadedImageProtocolInfo(IN EFI_HANDLE TheHandle)
Definition: Unload.c:21