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 - 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 10 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. 13 14 **/ 15 16 #include "UefiShellDriver1CommandsLib.h" 17 18 /** 19 Function to dump LoadedImage info from TheHandle. 20 21 @param[in] TheHandle The handle to dump info from. 22 23 @retval EFI_SUCCESS The info was dumped. 24 @retval EFI_INVALID_PARAMETER The handle did not have LoadedImage 25 **/ 26 EFI_STATUS 27 EFIAPI 28 DumpLoadedImageProtocolInfo ( 29 IN EFI_HANDLE TheHandle 30 ) 31 { 32 CHAR16 *TheString; 33 34 TheString = GetProtocolInformationDump(TheHandle, &gEfiLoadedImageProtocolGuid, TRUE); 35 36 ShellPrintEx(-1, -1, L"%s", TheString); 37 38 SHELL_FREE_NON_NULL(TheString); 39 40 return (EFI_SUCCESS); 41 } 42 43 STATIC CONST SHELL_PARAM_ITEM ParamList[] = { 44 {L"-n", TypeFlag}, 45 {L"-v", TypeFlag}, 46 {L"-verbose", TypeFlag}, 47 {NULL, TypeMax} 48 }; 49 50 /** 51 Function for 'unload' command. 52 53 @param[in] ImageHandle Handle to the Image (NULL if Internal). 54 @param[in] SystemTable Pointer to the System Table (NULL if Internal). 55 **/ 56 SHELL_STATUS 57 EFIAPI 58 ShellCommandRunUnload ( 59 IN EFI_HANDLE ImageHandle, 60 IN EFI_SYSTEM_TABLE *SystemTable 61 ) 62 { 63 EFI_STATUS Status; 64 LIST_ENTRY *Package; 65 CHAR16 *ProblemParam; 66 SHELL_STATUS ShellStatus; 67 EFI_HANDLE TheHandle; 68 CONST CHAR16 *Param1; 69 SHELL_PROMPT_RESPONSE *Resp; 70 UINT64 Value; 71 72 ShellStatus = SHELL_SUCCESS; 73 Package = NULL; 74 Resp = NULL; 75 Value = 0; 76 TheHandle = NULL; 77 78 // 79 // initialize the shell lib (we must be in non-auto-init...) 80 // 81 Status = ShellInitialize(); 82 ASSERT_EFI_ERROR(Status); 83 84 // 85 // parse the command line 86 // 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; 93 } else { 94 ASSERT(FALSE); 95 } 96 } else { 97 if (ShellCommandLineGetCount(Package) > 2){ 98 // 99 // error for too many parameters 100 // 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; 106 } else { 107 Param1 = ShellCommandLineGetRawValue(Package, 1); 108 if (Param1 != NULL) { 109 Status = ShellConvertStringToUint64(Param1, &Value, TRUE, FALSE); 110 TheHandle = ConvertHandleIndexToHandle((UINTN)Value); 111 } 112 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; 116 } else { 117 ASSERT(TheHandle != NULL); 118 if (ShellCommandLineGetFlag(Package, L"-v") || ShellCommandLineGetFlag(Package, L"-verbose")) { 119 DumpLoadedImageProtocolInfo(TheHandle); 120 } 121 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); 125 } 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); 129 } 130 SHELL_FREE_NON_NULL(Resp); 131 } 132 } 133 } 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; 141 } 142 } 143 144 if (Package != NULL) { 145 ShellCommandLineFreeVarList(Package); 146 } 147 148 return (ShellStatus); 149 } 150