VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDriver1CommandsLib/Unload.c@ 108794

Last change on this file since 108794 was 108794, checked in by vboxsync, 2 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/** @file
2 Main file for Unload shell Driver1 function.
3
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
7
8**/
9
10#include "UefiShellDriver1CommandsLib.h"
11
12/**
13 Function to dump LoadedImage info from TheHandle.
14
15 @param[in] TheHandle The handle to dump info from.
16
17 @retval EFI_SUCCESS The info was dumped.
18 @retval EFI_INVALID_PARAMETER The handle did not have LoadedImage
19**/
20EFI_STATUS
21DumpLoadedImageProtocolInfo (
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
46/**
47 Function for 'unload' command.
48
49 @param[in] ImageHandle Handle to the Image (NULL if Internal).
50 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
51**/
52SHELL_STATUS
53EFIAPI
54ShellCommandRunUnload (
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;
65 SHELL_PROMPT_RESPONSE *Resp;
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) {
144 ShellCommandLineFreeVarList (Package);
145 }
146
147 return (ShellStatus);
148}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette