]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / DynamicCommand / TftpDynamicCommand / TftpDynamicCommand.c
1 /** @file
2 Produce "tftp" shell dynamic command.
3
4 Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>
5 Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10 #include "Tftp.h"
11 #include <Protocol/ShellDynamicCommand.h>
12
13 /**
14 This is the shell command handler function pointer callback type. This
15 function handles the command when it is invoked in the shell.
16
17 @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
18 @param[in] SystemTable The pointer to the system table.
19 @param[in] ShellParameters The parameters associated with the command.
20 @param[in] Shell The instance of the shell protocol used in the context
21 of processing this command.
22
23 @return EFI_SUCCESS the operation was successful
24 @return other the operation failed.
25 **/
26 SHELL_STATUS
27 EFIAPI
28 TftpCommandHandler (
29 IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
30 IN EFI_SYSTEM_TABLE *SystemTable,
31 IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,
32 IN EFI_SHELL_PROTOCOL *Shell
33 )
34 {
35 gEfiShellParametersProtocol = ShellParameters;
36 gEfiShellProtocol = Shell;
37 return RunTftp (gImageHandle, SystemTable);
38 }
39
40 /**
41 This is the command help handler function pointer callback type. This
42 function is responsible for displaying help information for the associated
43 command.
44
45 @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.
46 @param[in] Language The pointer to the language string to use.
47
48 @return string Pool allocated help string, must be freed by caller
49 **/
50 CHAR16 *
51 EFIAPI
52 TftpCommandGetHelp (
53 IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,
54 IN CONST CHAR8 *Language
55 )
56 {
57 return HiiGetString (mTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP), Language);
58 }
59
60 EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mTftpDynamicCommand = {
61 L"tftp",
62 TftpCommandHandler,
63 TftpCommandGetHelp
64 };
65
66 /**
67 Entry point of Tftp Dynamic Command.
68
69 Produce the DynamicCommand protocol to handle "tftp" command.
70
71 @param ImageHandle The image handle of the process.
72 @param SystemTable The EFI System Table pointer.
73
74 @retval EFI_SUCCESS Tftp command is executed successfully.
75 @retval EFI_ABORTED HII package was failed to initialize.
76 @retval others Other errors when executing tftp command.
77 **/
78 EFI_STATUS
79 EFIAPI
80 TftpCommandInitialize (
81 IN EFI_HANDLE ImageHandle,
82 IN EFI_SYSTEM_TABLE *SystemTable
83 )
84 {
85 EFI_STATUS Status;
86
87 mTftpHiiHandle = InitializeHiiPackage (ImageHandle);
88 if (mTftpHiiHandle == NULL) {
89 return EFI_ABORTED;
90 }
91
92 Status = gBS->InstallProtocolInterface (
93 &ImageHandle,
94 &gEfiShellDynamicCommandProtocolGuid,
95 EFI_NATIVE_INTERFACE,
96 &mTftpDynamicCommand
97 );
98 ASSERT_EFI_ERROR (Status);
99 return Status;
100 }
101
102 /**
103 Tftp driver unload handler.
104
105 @param ImageHandle The image handle of the process.
106
107 @retval EFI_SUCCESS The image is unloaded.
108 @retval Others Failed to unload the image.
109 **/
110 EFI_STATUS
111 EFIAPI
112 TftpUnload (
113 IN EFI_HANDLE ImageHandle
114 )
115 {
116 EFI_STATUS Status;
117
118 Status = gBS->UninstallProtocolInterface (
119 ImageHandle,
120 &gEfiShellDynamicCommandProtocolGuid,
121 &mTftpDynamicCommand
122 );
123 if (EFI_ERROR (Status)) {
124 return Status;
125 }
126
127 HiiRemovePackages (mTftpHiiHandle);
128 return EFI_SUCCESS;
129 }