--- /dev/null
+/** @file\r
+ The implementation for the 'tftp' Shell command.\r
+\r
+ Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
+ Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved. <BR>\r
+ (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php.\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#include "Tftp.h"\r
+\r
+#define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH 32\r
+EFI_HANDLE mTftpHiiHandle;\r
+\r
+/*\r
+ Constant strings and definitions related to the message indicating the amount of\r
+ progress in the dowloading of a TFTP file.\r
+*/\r
+\r
+// Frame for the progression slider\r
+STATIC CONST CHAR16 mTftpProgressFrame[] = L"[ ]";\r
+\r
+// Number of steps in the progression slider\r
+#define TFTP_PROGRESS_SLIDER_STEPS ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) - 3)\r
+\r
+// Size in number of characters plus one (final zero) of the message to\r
+// indicate the progress of a TFTP download. The format is "[(progress slider:\r
+// 40 characters)] (nb of KBytes downloaded so far: 7 characters) Kb". There\r
+// are thus the number of characters in mTftpProgressFrame[] plus 11 characters\r
+// (2 // spaces, "Kb" and seven characters for the number of KBytes).\r
+#define TFTP_PROGRESS_MESSAGE_SIZE ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) + 12)\r
+\r
+// String to delete the TFTP progress message to be able to update it :\r
+// (TFTP_PROGRESS_MESSAGE_SIZE-1) '\b'\r
+STATIC CONST CHAR16 mTftpProgressDelete[] = L"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";\r
+\r
+/**\r
+ Check and convert the UINT16 option values of the 'tftp' command\r
+\r
+ @param[in] ValueStr Value as an Unicode encoded string\r
+ @param[out] Value UINT16 value\r
+\r
+ @return TRUE The value was returned.\r
+ @return FALSE A parsing error occured.\r
+**/\r
+STATIC \r
+BOOLEAN \r
+StringToUint16 (\r
+ IN CONST CHAR16 *ValueStr,\r
+ OUT UINT16 *Value\r
+ );\r
+\r
+/**\r
+ Get the name of the NIC.\r
+\r
+ @param[in] ControllerHandle The network physical device handle.\r
+ @param[in] NicNumber The network physical device number.\r
+ @param[out] NicName Address where to store the NIC name.\r
+ The memory area has to be at least\r
+ IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH \r
+ double byte wide.\r
+\r
+ @return EFI_SUCCESS The name of the NIC was returned.\r
+ @return Others The creation of the child for the Managed\r
+ Network Service failed or the opening of\r
+ the Managed Network Protocol failed or\r
+ the operational parameters for the\r
+ Managed Network Protocol could not be\r
+ read.\r
+**/\r
+STATIC \r
+EFI_STATUS \r
+GetNicName (\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN UINTN NicNumber,\r
+ OUT CHAR16 *NicName\r
+ );\r
+\r
+/**\r
+ Create a child for the service identified by its service binding protocol GUID\r
+ and get from the child the interface of the protocol identified by its GUID.\r
+\r
+ @param[in] ControllerHandle Controller handle.\r
+ @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the\r
+ service to be created.\r
+ @param[in] ProtocolGuid GUID of the protocol to be open.\r
+ @param[out] ChildHandle Address where the handler of the\r
+ created child is returned. NULL is\r
+ returned in case of error.\r
+ @param[out] Interface Address where a pointer to the\r
+ protocol interface is returned in\r
+ case of success.\r
+\r
+ @return EFI_SUCCESS The child was created and the protocol opened.\r
+ @return Others Either the creation of the child or the opening\r
+ of the protocol failed.\r
+**/\r
+STATIC \r
+EFI_STATUS \r
+CreateServiceChildAndOpenProtocol (\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_GUID *ServiceBindingProtocolGuid,\r
+ IN EFI_GUID *ProtocolGuid,\r
+ OUT EFI_HANDLE *ChildHandle,\r
+ OUT VOID **Interface\r
+ );\r
+\r
+/**\r
+ Close the protocol identified by its GUID on the child handle of the service\r
+ identified by its service binding protocol GUID, then destroy the child\r
+ handle.\r
+\r
+ @param[in] ControllerHandle Controller handle.\r
+ @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the\r
+ service to be destroyed.\r
+ @param[in] ProtocolGuid GUID of the protocol to be closed.\r
+ @param[in] ChildHandle Handle of the child to be destroyed.\r
+\r
+**/\r
+STATIC \r
+VOID \r
+CloseProtocolAndDestroyServiceChild (\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_GUID *ServiceBindingProtocolGuid,\r
+ IN EFI_GUID *ProtocolGuid,\r
+ IN EFI_HANDLE ChildHandle\r
+ );\r
+\r
+/**\r
+ Worker function that gets the size in numbers of bytes of a file from a TFTP\r
+ server before to download the file.\r
+\r
+ @param[in] Mtftp4 MTFTP4 protocol interface\r
+ @param[in] FilePath Path of the file, ASCII encoded\r
+ @param[out] FileSize Address where to store the file size in number of\r
+ bytes.\r
+\r
+ @retval EFI_SUCCESS The size of the file was returned.\r
+ @retval EFI_UNSUPPORTED The server does not support the "tsize" option.\r
+ @retval Others Error when retrieving the information from the server\r
+ (see EFI_MTFTP4_PROTOCOL.GetInfo() status codes)\r
+ or error when parsing the response of the server.\r
+**/\r
+STATIC \r
+EFI_STATUS \r
+GetFileSize (\r
+ IN EFI_MTFTP4_PROTOCOL *Mtftp4,\r
+ IN CONST CHAR8 *FilePath,\r
+ OUT UINTN *FileSize\r
+ );\r
+\r
+/**\r
+ Worker function that download the data of a file from a TFTP server given\r
+ the path of the file and its size.\r
+\r
+ @param[in] Mtftp4 MTFTP4 protocol interface\r
+ @param[in] FilePath Path of the file, Unicode encoded\r
+ @param[in] AsciiFilePath Path of the file, ASCII encoded\r
+ @param[in] FileSize Size of the file in number of bytes\r
+ @param[in] BlockSize Value of the TFTP blksize option\r
+ @param[out] Data Address where to store the address of the buffer\r
+ where the data of the file were downloaded in\r
+ case of success.\r
+\r
+ @retval EFI_SUCCESS The file was downloaded.\r
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
+ @retval Others The downloading of the file from the server failed\r
+ (see EFI_MTFTP4_PROTOCOL.ReadFile() status codes).\r
+\r
+**/\r
+STATIC \r
+EFI_STATUS \r
+DownloadFile (\r
+ IN EFI_MTFTP4_PROTOCOL *Mtftp4,\r
+ IN CONST CHAR16 *FilePath,\r
+ IN CONST CHAR8 *AsciiFilePath,\r
+ IN UINTN FileSize,\r
+ IN UINT16 BlockSize,\r
+ OUT VOID **Data\r
+ );\r
+\r
+/**\r
+ Update the progress of a file download\r
+ This procedure is called each time a new TFTP packet is received.\r
+\r
+ @param[in] This MTFTP4 protocol interface\r
+ @param[in] Token Parameters for the download of the file\r
+ @param[in] PacketLen Length of the packet\r
+ @param[in] Packet Address of the packet\r
+\r
+ @retval EFI_SUCCESS All packets are accepted.\r
+\r
+**/\r
+STATIC \r
+EFI_STATUS \r
+EFIAPI\r
+CheckPacket (\r
+ IN EFI_MTFTP4_PROTOCOL *This,\r
+ IN EFI_MTFTP4_TOKEN *Token,\r
+ IN UINT16 PacketLen,\r
+ IN EFI_MTFTP4_PACKET *Packet\r
+ );\r
+\r
+EFI_MTFTP4_CONFIG_DATA DefaultMtftp4ConfigData = {\r
+ TRUE, // Use default setting\r
+ { { 0, 0, 0, 0 } }, // StationIp - Not relevant as UseDefaultSetting=TRUE\r
+ { { 0, 0, 0, 0 } }, // SubnetMask - Not relevant as UseDefaultSetting=TRUE\r
+ 0, // LocalPort - Automatically assigned port number.\r
+ { { 0, 0, 0, 0 } }, // GatewayIp - Not relevant as UseDefaultSetting=TRUE\r
+ { { 0, 0, 0, 0 } }, // ServerIp - Not known yet\r
+ 69, // InitialServerPort - Standard TFTP server port\r
+ 6, // TryCount - Max number of retransmissions.\r
+ 4 // TimeoutValue - Retransmission timeout in seconds.\r
+};\r
+\r
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
+ {L"-i", TypeValue},\r
+ {L"-l", TypeValue},\r
+ {L"-r", TypeValue},\r
+ {L"-c", TypeValue},\r
+ {L"-t", TypeValue},\r
+ {L"-s", TypeValue},\r
+ {NULL , TypeMax}\r
+ };\r
+\r
+///\r
+/// The default block size (512) of tftp is defined in the RFC1350.\r
+///\r
+#define MTFTP_DEFAULT_BLKSIZE 512\r
+///\r
+/// The valid range of block size option is defined in the RFC2348.\r
+///\r
+#define MTFTP_MIN_BLKSIZE 8\r
+#define MTFTP_MAX_BLKSIZE 65464\r
+\r
+\r
+/**\r
+ Function for 'tftp' command.\r
+\r
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
+\r
+ @return SHELL_SUCCESS The 'tftp' command completed successfully.\r
+ @return SHELL_ABORTED The Shell Library initialization failed.\r
+ @return SHELL_INVALID_PARAMETER At least one of the command's arguments is\r
+ not valid.\r
+ @return SHELL_OUT_OF_RESOURCES A memory allocation failed.\r
+ @return SHELL_NOT_FOUND Network Interface Card not found or server\r
+ error or file error.\r
+\r
+**/\r
+SHELL_STATUS\r
+RunTftp (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ SHELL_STATUS ShellStatus;\r
+ EFI_STATUS Status;\r
+ LIST_ENTRY *CheckPackage;\r
+ CHAR16 *ProblemParam;\r
+ UINTN ParamCount;\r
+ CONST CHAR16 *UserNicName;\r
+ BOOLEAN NicFound;\r
+ CONST CHAR16 *ValueStr;\r
+ CONST CHAR16 *RemoteFilePath;\r
+ CHAR8 *AsciiRemoteFilePath;\r
+ UINTN FilePathSize;\r
+ CONST CHAR16 *Walker;\r
+ CONST CHAR16 *LocalFilePath;\r
+ EFI_MTFTP4_CONFIG_DATA Mtftp4ConfigData;\r
+ EFI_HANDLE *Handles;\r
+ UINTN HandleCount;\r
+ UINTN NicNumber;\r
+ CHAR16 NicName[IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH];\r
+ EFI_HANDLE ControllerHandle;\r
+ EFI_HANDLE Mtftp4ChildHandle;\r
+ EFI_MTFTP4_PROTOCOL *Mtftp4;\r
+ UINTN FileSize;\r
+ UINTN DataSize;\r
+ VOID *Data;\r
+ SHELL_FILE_HANDLE FileHandle;\r
+ UINT16 BlockSize;\r
+\r
+ ShellStatus = SHELL_INVALID_PARAMETER;\r
+ ProblemParam = NULL;\r
+ NicFound = FALSE;\r
+ AsciiRemoteFilePath = NULL;\r
+ Handles = NULL;\r
+ FileSize = 0;\r
+ DataSize = 0;\r
+ BlockSize = MTFTP_DEFAULT_BLKSIZE;\r
+\r
+ //\r
+ // Initialize the Shell library (we must be in non-auto-init...)\r
+ //\r
+ Status = ShellInitialize ();\r
+ if (EFI_ERROR (Status)) {\r
+ ASSERT_EFI_ERROR (Status);\r
+ return SHELL_ABORTED;\r
+ }\r
+\r
+ //\r
+ // Parse the command line.\r
+ //\r
+ Status = ShellCommandLineParse (ParamList, &CheckPackage, &ProblemParam, TRUE);\r
+ if (EFI_ERROR (Status)) {\r
+ if ((Status == EFI_VOLUME_CORRUPTED) &&\r
+ (ProblemParam != NULL) ) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), mTftpHiiHandle,\r
+ L"tftp", ProblemParam\r
+ );\r
+ FreePool (ProblemParam);\r
+ } else {\r
+ ASSERT (FALSE);\r
+ }\r
+ goto Error;\r
+ }\r
+\r
+ //\r
+ // Check the number of parameters\r
+ //\r
+ ParamCount = ShellCommandLineGetCount (CheckPackage);\r
+ if (ParamCount > 4) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY),\r
+ mTftpHiiHandle, L"tftp"\r
+ );\r
+ goto Error;\r
+ }\r
+ if (ParamCount < 3) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),\r
+ mTftpHiiHandle, L"tftp"\r
+ );\r
+ goto Error;\r
+ }\r
+\r
+ CopyMem (&Mtftp4ConfigData, &DefaultMtftp4ConfigData, sizeof (EFI_MTFTP4_CONFIG_DATA));\r
+\r
+ //\r
+ // Check the host IPv4 address\r
+ //\r
+ ValueStr = ShellCommandLineGetRawValue (CheckPackage, 1);\r
+ Status = NetLibStrToIp4 (ValueStr, &Mtftp4ConfigData.ServerIp);\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),\r
+ mTftpHiiHandle, L"tftp", ValueStr\r
+ );\r
+ goto Error;\r
+ }\r
+\r
+ RemoteFilePath = ShellCommandLineGetRawValue (CheckPackage, 2);\r
+ ASSERT(RemoteFilePath != NULL);\r
+ FilePathSize = StrLen (RemoteFilePath) + 1;\r
+ AsciiRemoteFilePath = AllocatePool (FilePathSize);\r
+ if (AsciiRemoteFilePath == NULL) {\r
+ ShellStatus = SHELL_OUT_OF_RESOURCES;\r
+ goto Error;\r
+ }\r
+ UnicodeStrToAsciiStrS (RemoteFilePath, AsciiRemoteFilePath, FilePathSize);\r
+\r
+ if (ParamCount == 4) {\r
+ LocalFilePath = ShellCommandLineGetRawValue (CheckPackage, 3);\r
+ } else {\r
+ Walker = RemoteFilePath + StrLen (RemoteFilePath);\r
+ while ((--Walker) >= RemoteFilePath) {\r
+ if ((*Walker == L'\\') ||\r
+ (*Walker == L'/' ) ) {\r
+ break;\r
+ }\r
+ }\r
+ LocalFilePath = Walker + 1;\r
+ }\r
+\r
+ //\r
+ // Get the name of the Network Interface Card to be used if any.\r
+ //\r
+ UserNicName = ShellCommandLineGetValue (CheckPackage, L"-i");\r
+\r
+ ValueStr = ShellCommandLineGetValue (CheckPackage, L"-l");\r
+ if (ValueStr != NULL) {\r
+ if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.LocalPort)) {\r
+ goto Error;\r
+ }\r
+ }\r
+\r
+ ValueStr = ShellCommandLineGetValue (CheckPackage, L"-r");\r
+ if (ValueStr != NULL) {\r
+ if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.InitialServerPort)) {\r
+ goto Error;\r
+ }\r
+ }\r
+\r
+ ValueStr = ShellCommandLineGetValue (CheckPackage, L"-c");\r
+ if (ValueStr != NULL) {\r
+ if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.TryCount)) {\r
+ goto Error;\r
+ }\r
+ }\r
+\r
+ ValueStr = ShellCommandLineGetValue (CheckPackage, L"-t");\r
+ if (ValueStr != NULL) {\r
+ if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.TimeoutValue)) {\r
+ goto Error;\r
+ }\r
+ if (Mtftp4ConfigData.TimeoutValue == 0) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),\r
+ mTftpHiiHandle, L"tftp", ValueStr\r
+ );\r
+ goto Error;\r
+ }\r
+ }\r
+\r
+ ValueStr = ShellCommandLineGetValue (CheckPackage, L"-s");\r
+ if (ValueStr != NULL) {\r
+ if (!StringToUint16 (ValueStr, &BlockSize)) {\r
+ goto Error;\r
+ }\r
+ if (BlockSize < MTFTP_MIN_BLKSIZE || BlockSize > MTFTP_MAX_BLKSIZE) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),\r
+ mTftpHiiHandle, L"tftp", ValueStr\r
+ );\r
+ goto Error;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Locate all MTFTP4 Service Binding protocols\r
+ //\r
+ ShellStatus = SHELL_NOT_FOUND;\r
+ Status = gBS->LocateHandleBuffer (\r
+ ByProtocol,\r
+ &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+ NULL,\r
+ &HandleCount,\r
+ &Handles\r
+ );\r
+ if (EFI_ERROR (Status) || (HandleCount == 0)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NO_NIC),\r
+ mTftpHiiHandle\r
+ );\r
+ goto Error;\r
+ }\r
+\r
+ for (NicNumber = 0;\r
+ (NicNumber < HandleCount) && (ShellStatus != SHELL_SUCCESS);\r
+ NicNumber++) {\r
+ ControllerHandle = Handles[NicNumber];\r
+ Data = NULL;\r
+\r
+ Status = GetNicName (ControllerHandle, NicNumber, NicName);\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NAME),\r
+ mTftpHiiHandle, NicNumber, Status\r
+ );\r
+ continue;\r
+ }\r
+\r
+ if (UserNicName != NULL) {\r
+ if (StrCmp (NicName, UserNicName) != 0) {\r
+ continue;\r
+ }\r
+ NicFound = TRUE;\r
+ }\r
+\r
+ Status = CreateServiceChildAndOpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiMtftp4ServiceBindingProtocolGuid,\r
+ &gEfiMtftp4ProtocolGuid,\r
+ &Mtftp4ChildHandle,\r
+ (VOID**)&Mtftp4\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_OPEN_PROTOCOL),\r
+ mTftpHiiHandle, NicName, Status\r
+ );\r
+ continue;\r
+ }\r
+\r
+ Status = Mtftp4->Configure (Mtftp4, &Mtftp4ConfigData);\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_CONFIGURE),\r
+ mTftpHiiHandle, NicName, Status\r
+ );\r
+ goto NextHandle;\r
+ }\r
+\r
+ Status = GetFileSize (Mtftp4, AsciiRemoteFilePath, &FileSize);\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_FILE_SIZE),\r
+ mTftpHiiHandle, RemoteFilePath, NicName, Status\r
+ );\r
+ goto NextHandle;\r
+ }\r
+\r
+ Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, BlockSize, &Data);\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD),\r
+ mTftpHiiHandle, RemoteFilePath, NicName, Status\r
+ );\r
+ goto NextHandle;\r
+ }\r
+\r
+ if (!EFI_ERROR (ShellFileExists (LocalFilePath))) {\r
+ ShellDeleteFileByName (LocalFilePath);\r
+ }\r
+\r
+ Status = ShellOpenFileByName (\r
+ LocalFilePath,\r
+ &FileHandle,\r
+ EFI_FILE_MODE_CREATE |\r
+ EFI_FILE_MODE_WRITE |\r
+ EFI_FILE_MODE_READ,\r
+ 0\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL),\r
+ mTftpHiiHandle, L"tftp", LocalFilePath\r
+ );\r
+ goto NextHandle;\r
+ }\r
+\r
+ DataSize = FileSize;\r
+ Status = ShellWriteFile (FileHandle, &FileSize, Data);\r
+ if (!EFI_ERROR (Status)) {\r
+ ShellStatus = SHELL_SUCCESS;\r
+ } else {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_WRITE),\r
+ mTftpHiiHandle, LocalFilePath, Status\r
+ );\r
+ }\r
+ ShellCloseFile (&FileHandle);\r
+\r
+ NextHandle:\r
+\r
+ if (Data != NULL) {\r
+ gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Data, EFI_SIZE_TO_PAGES (DataSize));\r
+ }\r
+\r
+ CloseProtocolAndDestroyServiceChild (\r
+ ControllerHandle,\r
+ &gEfiMtftp4ServiceBindingProtocolGuid,\r
+ &gEfiMtftp4ProtocolGuid,\r
+ Mtftp4ChildHandle\r
+ );\r
+ }\r
+\r
+ if ((UserNicName != NULL) && (!NicFound)) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NOT_FOUND),\r
+ mTftpHiiHandle, UserNicName\r
+ );\r
+ }\r
+\r
+ Error:\r
+\r
+ ShellCommandLineFreeVarList (CheckPackage);\r
+ if (AsciiRemoteFilePath != NULL) {\r
+ FreePool (AsciiRemoteFilePath);\r
+ }\r
+ if (Handles != NULL) {\r
+ FreePool (Handles);\r
+ }\r
+\r
+ return ShellStatus;\r
+}\r
+\r
+/**\r
+ Check and convert the UINT16 option values of the 'tftp' command\r
+\r
+ @param[in] ValueStr Value as an Unicode encoded string\r
+ @param[out] Value UINT16 value\r
+\r
+ @return TRUE The value was returned.\r
+ @return FALSE A parsing error occured.\r
+**/\r
+STATIC\r
+BOOLEAN\r
+StringToUint16 (\r
+ IN CONST CHAR16 *ValueStr,\r
+ OUT UINT16 *Value\r
+ )\r
+{\r
+ UINTN Val;\r
+\r
+ Val = ShellStrToUintn (ValueStr);\r
+ if (Val > MAX_UINT16) {\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),\r
+ mTftpHiiHandle, L"tftp", ValueStr\r
+ );\r
+ return FALSE;\r
+ }\r
+\r
+ *Value = (UINT16)Val;\r
+ return TRUE;\r
+}\r
+\r
+/**\r
+ Get the name of the NIC.\r
+\r
+ @param[in] ControllerHandle The network physical device handle.\r
+ @param[in] NicNumber The network physical device number.\r
+ @param[out] NicName Address where to store the NIC name.\r
+ The memory area has to be at least\r
+ IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH \r
+ double byte wide.\r
+\r
+ @return EFI_SUCCESS The name of the NIC was returned.\r
+ @return Others The creation of the child for the Managed\r
+ Network Service failed or the opening of\r
+ the Managed Network Protocol failed or\r
+ the operational parameters for the\r
+ Managed Network Protocol could not be\r
+ read.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+GetNicName (\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN UINTN NicNumber,\r
+ OUT CHAR16 *NicName\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE MnpHandle;\r
+ EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r
+ EFI_SIMPLE_NETWORK_MODE SnpMode;\r
+\r
+ Status = CreateServiceChildAndOpenProtocol (\r
+ ControllerHandle,\r
+ &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+ &gEfiManagedNetworkProtocolGuid,\r
+ &MnpHandle,\r
+ (VOID**)&Mnp\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ }\r
+\r
+ Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);\r
+ if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r
+ goto Error;\r
+ }\r
+\r
+ UnicodeSPrint (\r
+ NicName,\r
+ IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH,\r
+ SnpMode.IfType == NET_IFTYPE_ETHERNET ?\r
+ L"eth%d" :\r
+ L"unk%d" ,\r
+ NicNumber\r
+ );\r
+\r
+ Status = EFI_SUCCESS;\r
+\r
+Error:\r
+\r
+ if (MnpHandle != NULL) {\r
+ CloseProtocolAndDestroyServiceChild (\r
+ ControllerHandle,\r
+ &gEfiManagedNetworkServiceBindingProtocolGuid,\r
+ &gEfiManagedNetworkProtocolGuid,\r
+ MnpHandle\r
+ );\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Create a child for the service identified by its service binding protocol GUID\r
+ and get from the child the interface of the protocol identified by its GUID.\r
+\r
+ @param[in] ControllerHandle Controller handle.\r
+ @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the\r
+ service to be created.\r
+ @param[in] ProtocolGuid GUID of the protocol to be open.\r
+ @param[out] ChildHandle Address where the handler of the\r
+ created child is returned. NULL is\r
+ returned in case of error.\r
+ @param[out] Interface Address where a pointer to the\r
+ protocol interface is returned in\r
+ case of success.\r
+\r
+ @return EFI_SUCCESS The child was created and the protocol opened.\r
+ @return Others Either the creation of the child or the opening\r
+ of the protocol failed.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+CreateServiceChildAndOpenProtocol (\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_GUID *ServiceBindingProtocolGuid,\r
+ IN EFI_GUID *ProtocolGuid,\r
+ OUT EFI_HANDLE *ChildHandle,\r
+ OUT VOID **Interface\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ *ChildHandle = NULL;\r
+ Status = NetLibCreateServiceChild (\r
+ ControllerHandle,\r
+ gImageHandle,\r
+ ServiceBindingProtocolGuid,\r
+ ChildHandle\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ Status = gBS->OpenProtocol (\r
+ *ChildHandle,\r
+ ProtocolGuid,\r
+ Interface,\r
+ gImageHandle,\r
+ ControllerHandle,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ NetLibDestroyServiceChild (\r
+ ControllerHandle,\r
+ gImageHandle,\r
+ ServiceBindingProtocolGuid,\r
+ *ChildHandle\r
+ );\r
+ *ChildHandle = NULL;\r
+ }\r
+ }\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Close the protocol identified by its GUID on the child handle of the service\r
+ identified by its service binding protocol GUID, then destroy the child\r
+ handle.\r
+\r
+ @param[in] ControllerHandle Controller handle.\r
+ @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the\r
+ service to be destroyed.\r
+ @param[in] ProtocolGuid GUID of the protocol to be closed.\r
+ @param[in] ChildHandle Handle of the child to be destroyed.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+CloseProtocolAndDestroyServiceChild (\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_GUID *ServiceBindingProtocolGuid,\r
+ IN EFI_GUID *ProtocolGuid,\r
+ IN EFI_HANDLE ChildHandle\r
+ )\r
+{\r
+ gBS->CloseProtocol (\r
+ ChildHandle,\r
+ ProtocolGuid,\r
+ gImageHandle,\r
+ ControllerHandle\r
+ );\r
+\r
+ NetLibDestroyServiceChild (\r
+ ControllerHandle,\r
+ gImageHandle,\r
+ ServiceBindingProtocolGuid,\r
+ ChildHandle\r
+ );\r
+}\r
+\r
+/**\r
+ Worker function that gets the size in numbers of bytes of a file from a TFTP\r
+ server before to download the file.\r
+\r
+ @param[in] Mtftp4 MTFTP4 protocol interface\r
+ @param[in] FilePath Path of the file, ASCII encoded\r
+ @param[out] FileSize Address where to store the file size in number of\r
+ bytes.\r
+\r
+ @retval EFI_SUCCESS The size of the file was returned.\r
+ @retval EFI_UNSUPPORTED The server does not support the "tsize" option.\r
+ @retval Others Error when retrieving the information from the server\r
+ (see EFI_MTFTP4_PROTOCOL.GetInfo() status codes)\r
+ or error when parsing the response of the server.\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+GetFileSize (\r
+ IN EFI_MTFTP4_PROTOCOL *Mtftp4,\r
+ IN CONST CHAR8 *FilePath,\r
+ OUT UINTN *FileSize\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_MTFTP4_OPTION ReqOpt[1];\r
+ EFI_MTFTP4_PACKET *Packet;\r
+ UINT32 PktLen;\r
+ EFI_MTFTP4_OPTION *TableOfOptions;\r
+ EFI_MTFTP4_OPTION *Option;\r
+ UINT32 OptCnt;\r
+ UINT8 OptBuf[128];\r
+\r
+ ReqOpt[0].OptionStr = (UINT8*)"tsize";\r
+ OptBuf[0] = '0';\r
+ OptBuf[1] = 0;\r
+ ReqOpt[0].ValueStr = OptBuf;\r
+\r
+ Status = Mtftp4->GetInfo (\r
+ Mtftp4,\r
+ NULL,\r
+ (UINT8*)FilePath,\r
+ NULL,\r
+ 1,\r
+ ReqOpt,\r
+ &PktLen,\r
+ &Packet\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ }\r
+\r
+ Status = Mtftp4->ParseOptions (\r
+ Mtftp4,\r
+ PktLen,\r
+ Packet,\r
+ (UINT32 *) &OptCnt,\r
+ &TableOfOptions\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ }\r
+\r
+ Option = TableOfOptions;\r
+ while (OptCnt != 0) {\r
+ if (AsciiStrnCmp ((CHAR8 *)Option->OptionStr, "tsize", 5) == 0) {\r
+ *FileSize = AsciiStrDecimalToUintn ((CHAR8 *)Option->ValueStr);\r
+ break;\r
+ }\r
+ OptCnt--;\r
+ Option++;\r
+ }\r
+ FreePool (TableOfOptions);\r
+\r
+ if (OptCnt == 0) {\r
+ Status = EFI_UNSUPPORTED;\r
+ }\r
+\r
+Error :\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Worker function that download the data of a file from a TFTP server given\r
+ the path of the file and its size.\r
+\r
+ @param[in] Mtftp4 MTFTP4 protocol interface\r
+ @param[in] FilePath Path of the file, Unicode encoded\r
+ @param[in] AsciiFilePath Path of the file, ASCII encoded\r
+ @param[in] FileSize Size of the file in number of bytes\r
+ @param[in] BlockSize Value of the TFTP blksize option\r
+ @param[out] Data Address where to store the address of the buffer\r
+ where the data of the file were downloaded in\r
+ case of success.\r
+\r
+ @retval EFI_SUCCESS The file was downloaded.\r
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
+ @retval Others The downloading of the file from the server failed\r
+ (see EFI_MTFTP4_PROTOCOL.ReadFile() status codes).\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+DownloadFile (\r
+ IN EFI_MTFTP4_PROTOCOL *Mtftp4,\r
+ IN CONST CHAR16 *FilePath,\r
+ IN CONST CHAR8 *AsciiFilePath,\r
+ IN UINTN FileSize,\r
+ IN UINT16 BlockSize,\r
+ OUT VOID **Data\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_PHYSICAL_ADDRESS PagesAddress;\r
+ VOID *Buffer;\r
+ DOWNLOAD_CONTEXT *TftpContext;\r
+ EFI_MTFTP4_TOKEN Mtftp4Token;\r
+ EFI_MTFTP4_OPTION ReqOpt;\r
+ UINT8 OptBuf[10];\r
+\r
+ // Downloaded file can be large. BS.AllocatePages() is more faster\r
+ // than AllocatePool() and avoid fragmentation.\r
+ // The downloaded file could be an EFI application. Marking the\r
+ // allocated page as EfiBootServicesCode would allow to execute a\r
+ // potential downloaded EFI application.\r
+ Status = gBS->AllocatePages (\r
+ AllocateAnyPages,\r
+ EfiBootServicesCode,\r
+ EFI_SIZE_TO_PAGES (FileSize),\r
+ &PagesAddress\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Buffer = (VOID*)(UINTN)PagesAddress;\r
+ TftpContext = AllocatePool (sizeof (DOWNLOAD_CONTEXT));\r
+ if (TftpContext == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Error;\r
+ }\r
+ TftpContext->FileSize = FileSize;\r
+ TftpContext->DownloadedNbOfBytes = 0;\r
+ TftpContext->LastReportedNbOfBytes = 0;\r
+\r
+ ZeroMem (&Mtftp4Token, sizeof (EFI_MTFTP4_TOKEN));\r
+ Mtftp4Token.Filename = (UINT8*)AsciiFilePath;\r
+ Mtftp4Token.BufferSize = FileSize;\r
+ Mtftp4Token.Buffer = Buffer;\r
+ Mtftp4Token.CheckPacket = CheckPacket;\r
+ Mtftp4Token.Context = (VOID*)TftpContext;\r
+ if (BlockSize != MTFTP_DEFAULT_BLKSIZE) {\r
+ ReqOpt.OptionStr = (UINT8 *) "blksize";\r
+ AsciiSPrint ((CHAR8 *)OptBuf, sizeof (OptBuf), "%d", BlockSize);\r
+ ReqOpt.ValueStr = OptBuf;\r
+\r
+ Mtftp4Token.OptionCount = 1;\r
+ Mtftp4Token.OptionList = &ReqOpt;\r
+ }\r
+\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_TFTP_DOWNLOADING),\r
+ mTftpHiiHandle, FilePath\r
+ );\r
+\r
+ Status = Mtftp4->ReadFile (Mtftp4, &Mtftp4Token);\r
+ ShellPrintHiiEx (\r
+ -1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF),\r
+ mTftpHiiHandle\r
+ );\r
+\r
+Error :\r
+\r
+ if (TftpContext == NULL) {\r
+ FreePool (TftpContext);\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ gBS->FreePages (PagesAddress, EFI_SIZE_TO_PAGES (FileSize));\r
+ return Status;\r
+ }\r
+\r
+ *Data = Buffer;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Update the progress of a file download\r
+ This procedure is called each time a new TFTP packet is received.\r
+\r
+ @param[in] This MTFTP4 protocol interface\r
+ @param[in] Token Parameters for the download of the file\r
+ @param[in] PacketLen Length of the packet\r
+ @param[in] Packet Address of the packet\r
+\r
+ @retval EFI_SUCCESS All packets are accepted.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+CheckPacket (\r
+ IN EFI_MTFTP4_PROTOCOL *This,\r
+ IN EFI_MTFTP4_TOKEN *Token,\r
+ IN UINT16 PacketLen,\r
+ IN EFI_MTFTP4_PACKET *Packet\r
+ )\r
+{\r
+ DOWNLOAD_CONTEXT *Context;\r
+ CHAR16 Progress[TFTP_PROGRESS_MESSAGE_SIZE];\r
+ UINTN NbOfKb;\r
+ UINTN Index;\r
+ UINTN LastStep;\r
+ UINTN Step;\r
+ EFI_STATUS Status;\r
+\r
+ if ((NTOHS (Packet->OpCode)) != EFI_MTFTP4_OPCODE_DATA) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ Context = (DOWNLOAD_CONTEXT*)Token->Context;\r
+ if (Context->DownloadedNbOfBytes == 0) {\r
+ ShellPrintEx (-1, -1, L"%s 0 Kb", mTftpProgressFrame);\r
+ }\r
+\r
+ //\r
+ // The data in the packet are prepended with two UINT16 :\r
+ // . OpCode = EFI_MTFTP4_OPCODE_DATA\r
+ // . Block = the number of this block of data\r
+ //\r
+ Context->DownloadedNbOfBytes += PacketLen - sizeof (Packet->OpCode)\r
+ - sizeof (Packet->Data.Block);\r
+ NbOfKb = Context->DownloadedNbOfBytes / 1024;\r
+\r
+ Progress[0] = L'\0';\r
+ LastStep = (Context->LastReportedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;\r
+ Step = (Context->DownloadedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;\r
+\r
+ if (Step <= LastStep) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ ShellPrintEx (-1, -1, L"%s", mTftpProgressDelete);\r
+\r
+ Status = StrCpyS (Progress, TFTP_PROGRESS_MESSAGE_SIZE, mTftpProgressFrame);\r
+ if (EFI_ERROR(Status)) {\r
+ return Status;\r
+ }\r
+ for (Index = 1; Index < Step; Index++) {\r
+ Progress[Index] = L'=';\r
+ }\r
+ Progress[Step] = L'>';\r
+\r
+ UnicodeSPrint (\r
+ Progress + (sizeof (mTftpProgressFrame) / sizeof (CHAR16)) - 1,\r
+ sizeof (Progress) - sizeof (mTftpProgressFrame),\r
+ L" %7d Kb",\r
+ NbOfKb\r
+ );\r
+ Context->LastReportedNbOfBytes = Context->DownloadedNbOfBytes;\r
+\r
+ ShellPrintEx (-1, -1, L"%s", Progress);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Retrive HII package list from ImageHandle and publish to HII database.\r
+\r
+ @param ImageHandle The image handle of the process.\r
+\r
+ @return HII handle.\r
+**/\r
+EFI_HANDLE\r
+InitializeHiiPackage (\r
+ EFI_HANDLE ImageHandle\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HII_PACKAGE_LIST_HEADER *PackageList;\r
+ EFI_HANDLE HiiHandle;\r
+\r
+ //\r
+ // Retrieve HII package list from ImageHandle\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ ImageHandle,\r
+ &gEfiHiiPackageListProtocolGuid,\r
+ (VOID **)&PackageList,\r
+ ImageHandle,\r
+ NULL,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ if (EFI_ERROR (Status)) {\r
+ return NULL;\r
+ }\r
+\r
+ //\r
+ // Publish HII package list to HII Database.\r
+ //\r
+ Status = gHiiDatabase->NewPackageList (\r
+ gHiiDatabase,\r
+ PackageList,\r
+ NULL,\r
+ &HiiHandle\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ if (EFI_ERROR (Status)) {\r
+ return NULL;\r
+ }\r
+ return HiiHandle;\r
+}\r
--- /dev/null
+/** @file\r
+ Header file for 'tftp' command functions.\r
+\r
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>\r
+ Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _TFTP_H_\r
+#define _TFTP_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Protocol/HiiPackageList.h>\r
+#include <Protocol/ServiceBinding.h>\r
+#include <Protocol/Mtftp4.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/ShellLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/NetLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/UefiHiiServicesLib.h>\r
+\r
+extern EFI_HANDLE mTftpHiiHandle;\r
+\r
+typedef struct {\r
+ UINTN FileSize;\r
+ UINTN DownloadedNbOfBytes;\r
+ UINTN LastReportedNbOfBytes;\r
+} DOWNLOAD_CONTEXT;\r
+\r
+/**\r
+ Function for 'tftp' command.\r
+\r
+ @param[in] ImageHandle The image handle.\r
+ @param[in] SystemTable The system table.\r
+\r
+ @retval SHELL_SUCCESS Command completed successfully.\r
+ @retval SHELL_INVALID_PARAMETER Command usage error.\r
+ @retval SHELL_ABORTED The user aborts the operation.\r
+ @retval value Unknown error.\r
+**/\r
+SHELL_STATUS\r
+RunTftp (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ );\r
+\r
+/**\r
+ Retrive HII package list from ImageHandle and publish to HII database.\r
+\r
+ @param ImageHandle The image handle of the process.\r
+\r
+ @return HII handle.\r
+**/\r
+EFI_HANDLE\r
+InitializeHiiPackage (\r
+ EFI_HANDLE ImageHandle\r
+ );\r
+#endif // _TFTP_H_\r
--- /dev/null
+// /**\r
+//\r
+// (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
+// Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved. <BR>\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution. The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// Module Name:\r
+//\r
+// UefiShellTftpCommandLib.uni\r
+//\r
+// Abstract:\r
+//\r
+// String definitions for UEFI Shell TFTP command\r
+//\r
+//\r
+// **/\r
+\r
+/=#\r
+\r
+#langdef en-US "english"\r
+\r
+#string STR_GEN_TOO_MANY #language en-US "%H%s%N: Too many arguments\r\n"\r
+#string STR_GEN_TOO_FEW #language en-US "%H%s%N: Too few arguments\r\n"\r
+#string STR_GEN_PARAM_INV #language en-US "%H%s%N: Invalid argument - '%H%s%N'\r\n"\r
+#string STR_GEN_PROBLEM #language en-US "%H%s%N: Unknown flag - '%H%s%N'\r\n"\r
+#string STR_GEN_FILE_OPEN_FAIL #language en-US "%H%s%N: Cannot open file - '%H%s%N'\r\n"\r
+#string STR_GEN_CRLF #language en-US "\r\n"\r
+\r
+#string STR_TFTP_ERR_NO_NIC #language en-US "No network interface card found.\r\n"\r
+#string STR_TFTP_ERR_NIC_NAME #language en-US "Failed to get the name of the network interface card number %d - %r\r\n"\r
+#string STR_TFTP_ERR_OPEN_PROTOCOL #language en-US "Unable to open MTFTP4 protocol on '%H%s%N' - %r\r\n"\r
+#string STR_TFTP_ERR_CONFIGURE #language en-US "Unable to configure MTFTP4 protocol on '%H%s%N' - %r\r\n"\r
+#string STR_TFTP_ERR_FILE_SIZE #language en-US "Unable to get the size of the file '%H%s%N' on '%H%s%N' - %r\r\n"\r
+#string STR_TFTP_ERR_DOWNLOAD #language en-US "Unable to download the file '%H%s%N' on '%H%s%N' - %r\r\n"\r
+#string STR_TFTP_ERR_WRITE #language en-US "Unable to write into file '%H%s%N' - %r\r\n"\r
+#string STR_TFTP_ERR_NIC_NOT_FOUND #language en-US "Network Interface Card '%H%s%N' not found.\r\n"\r
+#string STR_TFTP_DOWNLOADING #language en-US "Downloading the file '%H%s%N'\r\n"\r
+#string STR_TFTP_STRING #language en-US "%s"\r
+\r
+#string STR_GET_HELP_TFTP #language en-US ""\r
+".TH tftp 0 "Download a file from TFTP server."\r\n"\r
+".SH NAME\r\n"\r
+"Download a file from TFTP server.\r\n"\r
+".SH SYNOPSIS\r\n"\r
+" \r\n"\r
+"TFTP [-i interface] [-l <port>] [-r <port>] [-c <retry count>] [-t <timeout>]\r\n"\r
+" [-s <block size>] host remotefilepath [localfilepath]\r\n"\r
+".SH OPTIONS\r\n"\r
+" \r\n"\r
+" -i interface - Specifies an adapter name, i.e., eth0.\r\n"\r
+" -l port - Specifies the local port number. Default value is 0\r\n"\r
+" and the port number is automatically assigned.\r\n"\r
+" -r port - Specifies the remote port number. Default value is 69.\r\n"\r
+" -c <retry count> - The number of times to transmit request packets and\r\n"\r
+" wait for a response. The default value is 6.\r\n"\r
+" -t <timeout> - The number of seconds to wait for a response after\r\n"\r
+" sending a request packet. Default value is 4s.\r\n"\r
+" -s <block size> - Specifies the TFTP blksize option as defined in RFC 2348.\r\n"\r
+" Valid range is between 8 and 65464, default value is 512.\r\n"\r
+" host - Specify TFTP Server IPv4 address.\r\n"\r
+" remotefilepath - TFTP server file path to download the file.\r\n"\r
+" localfilepath - Local destination file path.\r\n"\r
+".SH DESCRIPTION\r\n"\r
+" \r\n"\r
+"NOTES:\r\n"\r
+" 1. The TFTP command allows to get the file specified by its 'remotefilepath'\r\n"\r
+" path from the TFTP server specified by its 'host' IPv4 address. If the\r\n"\r
+" optional 'localfilepath' parameter is provided, the downloaded file is\r\n"\r
+" stored locally using the provided file path. If the local file path is\r\n"\r
+" not specified, the file is stored in the current directory using the file\r\n"\r
+" server's name.\r\n"\r
+" 2. Before using the TFTP command, the network interface intended to be\r\n"\r
+" used to retrieve the file must be configured. This configuration may be\r\n"\r
+" done by means of the 'ifconfig' command.\r\n"\r
+" 3. If a network interface is defined with the '-i' option then only this\r\n"\r
+" interface will be used to retrieve the remote file. Otherwise, all network\r\n"\r
+" interfaces are tried in the order they have been discovered during the\r\n"\r
+" DXE phase.\r\n"\r
+".SH EXAMPLES\r\n"\r
+" \r\n"\r
+"EXAMPLES:\r\n"\r
+" * To get the file "dir1/file1.dat" from the TFTP server 192.168.1.1 and\r\n"\r
+" store it as file2.dat in the current directory :\r\n"\r
+" fs0:\> tftp 192.168.1.1 dir1/file1.dat file2.dat\r\n"\r
+".SH RETURNVALUES\r\n"\r
+" \r\n"\r
+"RETURN VALUES:\r\n"\r
+" SHELL_SUCCESS The action was completed as requested.\r\n"\r
+" SHELL_INVALID_PARAMETER One of the passed-in parameters was incorrectly\r\n"\r
+" formatted or its value was out of bounds.\r\n"\r
+\r
--- /dev/null
+/** @file\r
+ Entrypoint of "tftp" shell standalone application.\r
+\r
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>\r
+ Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include "Tftp.h"\r
+\r
+//\r
+// String token ID of help message text.\r
+// Shell supports to find help message in the resource section of an application image if\r
+// .MAN file is not found. This global variable is added to make build tool recognizes\r
+// that the help string is consumed by user and then build tool will add the string into\r
+// the resource section. Thus the application can use '-?' option to show help message in\r
+// Shell.\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mStringHelpTokenId = STRING_TOKEN (STR_GET_HELP_TFTP);\r
+\r
+/**\r
+ Entry point of Tftp standalone application.\r
+\r
+ @param ImageHandle The image handle of the process.\r
+ @param SystemTable The EFI System Table pointer.\r
+\r
+ @retval EFI_SUCCESS Tftp command is executed sucessfully.\r
+ @retval EFI_ABORTED HII package was failed to initialize.\r
+ @retval others Other errors when executing tftp command.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TftpAppInitialize (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ mTftpHiiHandle = InitializeHiiPackage (ImageHandle);\r
+ if (mTftpHiiHandle == NULL) {\r
+ return EFI_ABORTED;\r
+ }\r
+\r
+ Status = (EFI_STATUS)RunTftp (ImageHandle, SystemTable);\r
+ HiiRemovePackages (mTftpHiiHandle);\r
+ return Status;\r
+}\r
--- /dev/null
+## @file\r
+# Provides Shell 'tftp' standalone application.\r
+#\r
+# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>\r
+# Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010006\r
+ BASE_NAME = tftp\r
+ FILE_GUID = 8DC58D0D-67F5-4B97-9DFC-E442BB9A5648\r
+ MODULE_TYPE = UEFI_APPLICATION\r
+ VERSION_STRING = 1.0\r
+ ENTRY_POINT = TftpAppInitialize\r
+#\r
+# This flag specifies whether HII resource section is generated into PE image.\r
+#\r
+ UEFI_HII_RESOURCE_SECTION = TRUE\r
+\r
+[Sources.common]\r
+ Tftp.uni\r
+ Tftp.h\r
+ Tftp.c\r
+ TftpApp.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ ShellPkg/ShellPkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+ MemoryAllocationLib\r
+ BaseLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ ShellLib\r
+ UefiLib\r
+ UefiRuntimeServicesTableLib\r
+ UefiBootServicesTableLib\r
+ UefiApplicationEntryPoint\r
+ UefiHiiServicesLib\r
+ HiiLib\r
+ FileHandleLib\r
+ NetLib\r
+\r
+[Protocols]\r
+ gEfiManagedNetworkServiceBindingProtocolGuid ## CONSUMES\r
+ gEfiMtftp4ServiceBindingProtocolGuid ## CONSUMES\r
+ gEfiMtftp4ProtocolGuid ## CONSUMES\r
+ gEfiHiiPackageListProtocolGuid ## CONSUMES\r
--- /dev/null
+/** @file\r
+ Produce "tftp" shell dynamic command.\r
+\r
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>\r
+ Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+#include "Tftp.h"\r
+#include <Protocol/ShellDynamicCommand.h>\r
+\r
+/**\r
+ This is the shell command handler function pointer callback type. This\r
+ function handles the command when it is invoked in the shell.\r
+\r
+ @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.\r
+ @param[in] SystemTable The pointer to the system table.\r
+ @param[in] ShellParameters The parameters associated with the command.\r
+ @param[in] Shell The instance of the shell protocol used in the context\r
+ of processing this command.\r
+\r
+ @return EFI_SUCCESS the operation was sucessful\r
+ @return other the operation failed.\r
+**/\r
+SHELL_STATUS\r
+EFIAPI\r
+TftpCommandHandler (\r
+ IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,\r
+ IN EFI_SYSTEM_TABLE *SystemTable,\r
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
+ IN EFI_SHELL_PROTOCOL *Shell\r
+ )\r
+{\r
+ gEfiShellParametersProtocol = ShellParameters;\r
+ return RunTftp (gImageHandle, SystemTable);\r
+}\r
+\r
+/**\r
+ This is the command help handler function pointer callback type. This\r
+ function is responsible for displaying help information for the associated\r
+ command.\r
+\r
+ @param[in] This The instance of the EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL.\r
+ @param[in] Language The pointer to the language string to use.\r
+\r
+ @return string Pool allocated help string, must be freed by caller\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+TftpCommandGetHelp (\r
+ IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This,\r
+ IN CONST CHAR8 *Language\r
+ )\r
+{\r
+ return HiiGetString (mTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP), Language);\r
+}\r
+\r
+EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mTftpDynamicCommand = {\r
+ L"tftp",\r
+ TftpCommandHandler,\r
+ TftpCommandGetHelp\r
+};\r
+\r
+/**\r
+ Entry point of Tftp Dynamic Command.\r
+\r
+ Produce the DynamicCommand protocol to handle "tftp" command.\r
+\r
+ @param ImageHandle The image handle of the process.\r
+ @param SystemTable The EFI System Table pointer.\r
+\r
+ @retval EFI_SUCCESS Tftp command is executed sucessfully.\r
+ @retval EFI_ABORTED HII package was failed to initialize.\r
+ @retval others Other errors when executing tftp command.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TftpCommandInitialize (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ mTftpHiiHandle = InitializeHiiPackage (ImageHandle);\r
+ if (mTftpHiiHandle == NULL) {\r
+ return EFI_ABORTED;\r
+ }\r
+\r
+ Status = gBS->InstallProtocolInterface (\r
+ &ImageHandle,\r
+ &gEfiShellDynamicCommandProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ &mTftpDynamicCommand\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Tftp driver unload handler.\r
+\r
+ @param ImageHandle The image handle of the process.\r
+\r
+ @retval EFI_SUCCESS The image is unloaded.\r
+ @retval Others Failed to unload the image.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TftpUnload (\r
+ IN EFI_HANDLE ImageHandle\r
+)\r
+{\r
+ EFI_STATUS Status;\r
+ Status = gBS->UninstallProtocolInterface (\r
+ ImageHandle,\r
+ &gEfiShellDynamicCommandProtocolGuid,\r
+ &mTftpDynamicCommand\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ HiiRemovePackages (mTftpHiiHandle);\r
+ return EFI_SUCCESS;\r
+}\r
--- /dev/null
+## @file\r
+# Provides Shell 'tftp' dynamic command.\r
+#\r
+# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. <BR>\r
+# Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010006\r
+ BASE_NAME = tftpDynamicCommand\r
+ FILE_GUID = A487A478-51EF-48AA-8794-7BEE2A0562F1\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+ ENTRY_POINT = TftpCommandInitialize\r
+ UNLOAD_IMAGE = TftpUnload\r
+#\r
+# This flag specifies whether HII resource section is generated into PE image.\r
+#\r
+ UEFI_HII_RESOURCE_SECTION = TRUE\r
+\r
+[Sources.common]\r
+ Tftp.uni\r
+ Tftp.h\r
+ Tftp.c\r
+ TftpDynamicCommand.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ ShellPkg/ShellPkg.dec\r
+ MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+ MemoryAllocationLib\r
+ BaseLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ ShellLib\r
+ UefiLib\r
+ UefiRuntimeServicesTableLib\r
+ UefiBootServicesTableLib\r
+ UefiDriverEntryPoint\r
+ UefiHiiServicesLib\r
+ HiiLib\r
+ FileHandleLib\r
+ NetLib\r
+\r
+[Protocols]\r
+ gEfiManagedNetworkServiceBindingProtocolGuid ## CONSUMES\r
+ gEfiMtftp4ServiceBindingProtocolGuid ## CONSUMES\r
+ gEfiMtftp4ProtocolGuid ## CONSUMES\r
+ gEfiHiiPackageListProtocolGuid ## CONSUMES\r
+ gEfiShellDynamicCommandProtocolGuid ## PRODUCES\r
+\r
+[DEPEX]\r
+ TRUE\r
+++ /dev/null
-/** @file\r
- The implementation for the 'tftp' Shell command.\r
-\r
- Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
- Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved. <BR>\r
- (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
-\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php.\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-**/\r
-\r
-#include "UefiShellTftpCommandLib.h"\r
-\r
-#define IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH 32\r
-\r
-/*\r
- Constant strings and definitions related to the message indicating the amount of\r
- progress in the dowloading of a TFTP file.\r
-*/\r
-\r
-// Frame for the progression slider\r
-STATIC CONST CHAR16 mTftpProgressFrame[] = L"[ ]";\r
-\r
-// Number of steps in the progression slider\r
-#define TFTP_PROGRESS_SLIDER_STEPS ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) - 3)\r
-\r
-// Size in number of characters plus one (final zero) of the message to\r
-// indicate the progress of a TFTP download. The format is "[(progress slider:\r
-// 40 characters)] (nb of KBytes downloaded so far: 7 characters) Kb". There\r
-// are thus the number of characters in mTftpProgressFrame[] plus 11 characters\r
-// (2 // spaces, "Kb" and seven characters for the number of KBytes).\r
-#define TFTP_PROGRESS_MESSAGE_SIZE ((sizeof (mTftpProgressFrame) / sizeof (CHAR16)) + 12)\r
-\r
-// String to delete the TFTP progress message to be able to update it :\r
-// (TFTP_PROGRESS_MESSAGE_SIZE-1) '\b'\r
-STATIC CONST CHAR16 mTftpProgressDelete[] = L"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";\r
-\r
-/**\r
- Check and convert the UINT16 option values of the 'tftp' command\r
-\r
- @param[in] ValueStr Value as an Unicode encoded string\r
- @param[out] Value UINT16 value\r
-\r
- @return TRUE The value was returned.\r
- @return FALSE A parsing error occured.\r
-**/\r
-STATIC \r
-BOOLEAN \r
-StringToUint16 (\r
- IN CONST CHAR16 *ValueStr,\r
- OUT UINT16 *Value\r
- );\r
-\r
-/**\r
- Get the name of the NIC.\r
-\r
- @param[in] ControllerHandle The network physical device handle.\r
- @param[in] NicNumber The network physical device number.\r
- @param[out] NicName Address where to store the NIC name.\r
- The memory area has to be at least\r
- IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH \r
- double byte wide.\r
-\r
- @return EFI_SUCCESS The name of the NIC was returned.\r
- @return Others The creation of the child for the Managed\r
- Network Service failed or the opening of\r
- the Managed Network Protocol failed or\r
- the operational parameters for the\r
- Managed Network Protocol could not be\r
- read.\r
-**/\r
-STATIC \r
-EFI_STATUS \r
-GetNicName (\r
- IN EFI_HANDLE ControllerHandle,\r
- IN UINTN NicNumber,\r
- OUT CHAR16 *NicName\r
- );\r
-\r
-/**\r
- Create a child for the service identified by its service binding protocol GUID\r
- and get from the child the interface of the protocol identified by its GUID.\r
-\r
- @param[in] ControllerHandle Controller handle.\r
- @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the\r
- service to be created.\r
- @param[in] ProtocolGuid GUID of the protocol to be open.\r
- @param[out] ChildHandle Address where the handler of the\r
- created child is returned. NULL is\r
- returned in case of error.\r
- @param[out] Interface Address where a pointer to the\r
- protocol interface is returned in\r
- case of success.\r
-\r
- @return EFI_SUCCESS The child was created and the protocol opened.\r
- @return Others Either the creation of the child or the opening\r
- of the protocol failed.\r
-**/\r
-STATIC \r
-EFI_STATUS \r
-CreateServiceChildAndOpenProtocol (\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_GUID *ServiceBindingProtocolGuid,\r
- IN EFI_GUID *ProtocolGuid,\r
- OUT EFI_HANDLE *ChildHandle,\r
- OUT VOID **Interface\r
- );\r
-\r
-/**\r
- Close the protocol identified by its GUID on the child handle of the service\r
- identified by its service binding protocol GUID, then destroy the child\r
- handle.\r
-\r
- @param[in] ControllerHandle Controller handle.\r
- @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the\r
- service to be destroyed.\r
- @param[in] ProtocolGuid GUID of the protocol to be closed.\r
- @param[in] ChildHandle Handle of the child to be destroyed.\r
-\r
-**/\r
-STATIC \r
-VOID \r
-CloseProtocolAndDestroyServiceChild (\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_GUID *ServiceBindingProtocolGuid,\r
- IN EFI_GUID *ProtocolGuid,\r
- IN EFI_HANDLE ChildHandle\r
- );\r
-\r
-/**\r
- Worker function that gets the size in numbers of bytes of a file from a TFTP\r
- server before to download the file.\r
-\r
- @param[in] Mtftp4 MTFTP4 protocol interface\r
- @param[in] FilePath Path of the file, ASCII encoded\r
- @param[out] FileSize Address where to store the file size in number of\r
- bytes.\r
-\r
- @retval EFI_SUCCESS The size of the file was returned.\r
- @retval EFI_UNSUPPORTED The server does not support the "tsize" option.\r
- @retval Others Error when retrieving the information from the server\r
- (see EFI_MTFTP4_PROTOCOL.GetInfo() status codes)\r
- or error when parsing the response of the server.\r
-**/\r
-STATIC \r
-EFI_STATUS \r
-GetFileSize (\r
- IN EFI_MTFTP4_PROTOCOL *Mtftp4,\r
- IN CONST CHAR8 *FilePath,\r
- OUT UINTN *FileSize\r
- );\r
-\r
-/**\r
- Worker function that download the data of a file from a TFTP server given\r
- the path of the file and its size.\r
-\r
- @param[in] Mtftp4 MTFTP4 protocol interface\r
- @param[in] FilePath Path of the file, Unicode encoded\r
- @param[in] AsciiFilePath Path of the file, ASCII encoded\r
- @param[in] FileSize Size of the file in number of bytes\r
- @param[in] BlockSize Value of the TFTP blksize option\r
- @param[out] Data Address where to store the address of the buffer\r
- where the data of the file were downloaded in\r
- case of success.\r
-\r
- @retval EFI_SUCCESS The file was downloaded.\r
- @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
- @retval Others The downloading of the file from the server failed\r
- (see EFI_MTFTP4_PROTOCOL.ReadFile() status codes).\r
-\r
-**/\r
-STATIC \r
-EFI_STATUS \r
-DownloadFile (\r
- IN EFI_MTFTP4_PROTOCOL *Mtftp4,\r
- IN CONST CHAR16 *FilePath,\r
- IN CONST CHAR8 *AsciiFilePath,\r
- IN UINTN FileSize,\r
- IN UINT16 BlockSize,\r
- OUT VOID **Data\r
- );\r
-\r
-/**\r
- Update the progress of a file download\r
- This procedure is called each time a new TFTP packet is received.\r
-\r
- @param[in] This MTFTP4 protocol interface\r
- @param[in] Token Parameters for the download of the file\r
- @param[in] PacketLen Length of the packet\r
- @param[in] Packet Address of the packet\r
-\r
- @retval EFI_SUCCESS All packets are accepted.\r
-\r
-**/\r
-STATIC \r
-EFI_STATUS \r
-EFIAPI\r
-CheckPacket (\r
- IN EFI_MTFTP4_PROTOCOL *This,\r
- IN EFI_MTFTP4_TOKEN *Token,\r
- IN UINT16 PacketLen,\r
- IN EFI_MTFTP4_PACKET *Packet\r
- );\r
-\r
-EFI_MTFTP4_CONFIG_DATA DefaultMtftp4ConfigData = {\r
- TRUE, // Use default setting\r
- { { 0, 0, 0, 0 } }, // StationIp - Not relevant as UseDefaultSetting=TRUE\r
- { { 0, 0, 0, 0 } }, // SubnetMask - Not relevant as UseDefaultSetting=TRUE\r
- 0, // LocalPort - Automatically assigned port number.\r
- { { 0, 0, 0, 0 } }, // GatewayIp - Not relevant as UseDefaultSetting=TRUE\r
- { { 0, 0, 0, 0 } }, // ServerIp - Not known yet\r
- 69, // InitialServerPort - Standard TFTP server port\r
- 6, // TryCount - Max number of retransmissions.\r
- 4 // TimeoutValue - Retransmission timeout in seconds.\r
-};\r
-\r
-STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
- {L"-i", TypeValue},\r
- {L"-l", TypeValue},\r
- {L"-r", TypeValue},\r
- {L"-c", TypeValue},\r
- {L"-t", TypeValue},\r
- {L"-s", TypeValue},\r
- {NULL , TypeMax}\r
- };\r
-\r
-///\r
-/// The default block size (512) of tftp is defined in the RFC1350.\r
-///\r
-#define MTFTP_DEFAULT_BLKSIZE 512\r
-///\r
-/// The valid range of block size option is defined in the RFC2348.\r
-///\r
-#define MTFTP_MIN_BLKSIZE 8\r
-#define MTFTP_MAX_BLKSIZE 65464\r
-\r
-\r
-/**\r
- Function for 'tftp' command.\r
-\r
- @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
- @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
-\r
- @return SHELL_SUCCESS The 'tftp' command completed successfully.\r
- @return SHELL_ABORTED The Shell Library initialization failed.\r
- @return SHELL_INVALID_PARAMETER At least one of the command's arguments is\r
- not valid.\r
- @return SHELL_OUT_OF_RESOURCES A memory allocation failed.\r
- @return SHELL_NOT_FOUND Network Interface Card not found or server\r
- error or file error.\r
-\r
-**/\r
-SHELL_STATUS\r
-EFIAPI\r
-ShellCommandRunTftp (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-{\r
- SHELL_STATUS ShellStatus;\r
- EFI_STATUS Status;\r
- LIST_ENTRY *CheckPackage;\r
- CHAR16 *ProblemParam;\r
- UINTN ParamCount;\r
- CONST CHAR16 *UserNicName;\r
- BOOLEAN NicFound;\r
- CONST CHAR16 *ValueStr;\r
- CONST CHAR16 *RemoteFilePath;\r
- CHAR8 *AsciiRemoteFilePath;\r
- UINTN FilePathSize;\r
- CONST CHAR16 *Walker;\r
- CONST CHAR16 *LocalFilePath;\r
- EFI_MTFTP4_CONFIG_DATA Mtftp4ConfigData;\r
- EFI_HANDLE *Handles;\r
- UINTN HandleCount;\r
- UINTN NicNumber;\r
- CHAR16 NicName[IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH];\r
- EFI_HANDLE ControllerHandle;\r
- EFI_HANDLE Mtftp4ChildHandle;\r
- EFI_MTFTP4_PROTOCOL *Mtftp4;\r
- UINTN FileSize;\r
- UINTN DataSize;\r
- VOID *Data;\r
- SHELL_FILE_HANDLE FileHandle;\r
- UINT16 BlockSize;\r
-\r
- ShellStatus = SHELL_INVALID_PARAMETER;\r
- ProblemParam = NULL;\r
- NicFound = FALSE;\r
- AsciiRemoteFilePath = NULL;\r
- Handles = NULL;\r
- FileSize = 0;\r
- DataSize = 0;\r
- BlockSize = MTFTP_DEFAULT_BLKSIZE;\r
-\r
- //\r
- // Initialize the Shell library (we must be in non-auto-init...)\r
- //\r
- Status = ShellInitialize ();\r
- if (EFI_ERROR (Status)) {\r
- ASSERT_EFI_ERROR (Status);\r
- return SHELL_ABORTED;\r
- }\r
-\r
- //\r
- // Parse the command line.\r
- //\r
- Status = ShellCommandLineParse (ParamList, &CheckPackage, &ProblemParam, TRUE);\r
- if (EFI_ERROR (Status)) {\r
- if ((Status == EFI_VOLUME_CORRUPTED) &&\r
- (ProblemParam != NULL) ) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellTftpHiiHandle,\r
- L"tftp", ProblemParam\r
- );\r
- FreePool (ProblemParam);\r
- } else {\r
- ASSERT (FALSE);\r
- }\r
- goto Error;\r
- }\r
-\r
- //\r
- // Check the number of parameters\r
- //\r
- ParamCount = ShellCommandLineGetCount (CheckPackage);\r
- if (ParamCount > 4) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY),\r
- gShellTftpHiiHandle, L"tftp"\r
- );\r
- goto Error;\r
- }\r
- if (ParamCount < 3) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW),\r
- gShellTftpHiiHandle, L"tftp"\r
- );\r
- goto Error;\r
- }\r
-\r
- CopyMem (&Mtftp4ConfigData, &DefaultMtftp4ConfigData, sizeof (EFI_MTFTP4_CONFIG_DATA));\r
-\r
- //\r
- // Check the host IPv4 address\r
- //\r
- ValueStr = ShellCommandLineGetRawValue (CheckPackage, 1);\r
- Status = NetLibStrToIp4 (ValueStr, &Mtftp4ConfigData.ServerIp);\r
- if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),\r
- gShellTftpHiiHandle, L"tftp", ValueStr\r
- );\r
- goto Error;\r
- }\r
-\r
- RemoteFilePath = ShellCommandLineGetRawValue (CheckPackage, 2);\r
- ASSERT(RemoteFilePath != NULL);\r
- FilePathSize = StrLen (RemoteFilePath) + 1;\r
- AsciiRemoteFilePath = AllocatePool (FilePathSize);\r
- if (AsciiRemoteFilePath == NULL) {\r
- ShellStatus = SHELL_OUT_OF_RESOURCES;\r
- goto Error;\r
- }\r
- UnicodeStrToAsciiStrS (RemoteFilePath, AsciiRemoteFilePath, FilePathSize);\r
-\r
- if (ParamCount == 4) {\r
- LocalFilePath = ShellCommandLineGetRawValue (CheckPackage, 3);\r
- } else {\r
- Walker = RemoteFilePath + StrLen (RemoteFilePath);\r
- while ((--Walker) >= RemoteFilePath) {\r
- if ((*Walker == L'\\') ||\r
- (*Walker == L'/' ) ) {\r
- break;\r
- }\r
- }\r
- LocalFilePath = Walker + 1;\r
- }\r
-\r
- //\r
- // Get the name of the Network Interface Card to be used if any.\r
- //\r
- UserNicName = ShellCommandLineGetValue (CheckPackage, L"-i");\r
-\r
- ValueStr = ShellCommandLineGetValue (CheckPackage, L"-l");\r
- if (ValueStr != NULL) {\r
- if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.LocalPort)) {\r
- goto Error;\r
- }\r
- }\r
-\r
- ValueStr = ShellCommandLineGetValue (CheckPackage, L"-r");\r
- if (ValueStr != NULL) {\r
- if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.InitialServerPort)) {\r
- goto Error;\r
- }\r
- }\r
-\r
- ValueStr = ShellCommandLineGetValue (CheckPackage, L"-c");\r
- if (ValueStr != NULL) {\r
- if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.TryCount)) {\r
- goto Error;\r
- }\r
- }\r
-\r
- ValueStr = ShellCommandLineGetValue (CheckPackage, L"-t");\r
- if (ValueStr != NULL) {\r
- if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.TimeoutValue)) {\r
- goto Error;\r
- }\r
- if (Mtftp4ConfigData.TimeoutValue == 0) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),\r
- gShellTftpHiiHandle, L"tftp", ValueStr\r
- );\r
- goto Error;\r
- }\r
- }\r
-\r
- ValueStr = ShellCommandLineGetValue (CheckPackage, L"-s");\r
- if (ValueStr != NULL) {\r
- if (!StringToUint16 (ValueStr, &BlockSize)) {\r
- goto Error;\r
- }\r
- if (BlockSize < MTFTP_MIN_BLKSIZE || BlockSize > MTFTP_MAX_BLKSIZE) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),\r
- gShellTftpHiiHandle, L"tftp", ValueStr\r
- );\r
- goto Error;\r
- }\r
- }\r
-\r
- //\r
- // Locate all MTFTP4 Service Binding protocols\r
- //\r
- ShellStatus = SHELL_NOT_FOUND;\r
- Status = gBS->LocateHandleBuffer (\r
- ByProtocol,\r
- &gEfiManagedNetworkServiceBindingProtocolGuid,\r
- NULL,\r
- &HandleCount,\r
- &Handles\r
- );\r
- if (EFI_ERROR (Status) || (HandleCount == 0)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NO_NIC),\r
- gShellTftpHiiHandle\r
- );\r
- goto Error;\r
- }\r
-\r
- for (NicNumber = 0;\r
- (NicNumber < HandleCount) && (ShellStatus != SHELL_SUCCESS);\r
- NicNumber++) {\r
- ControllerHandle = Handles[NicNumber];\r
- Data = NULL;\r
-\r
- Status = GetNicName (ControllerHandle, NicNumber, NicName);\r
- if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NAME),\r
- gShellTftpHiiHandle, NicNumber, Status\r
- );\r
- continue;\r
- }\r
-\r
- if (UserNicName != NULL) {\r
- if (StrCmp (NicName, UserNicName) != 0) {\r
- continue;\r
- }\r
- NicFound = TRUE;\r
- }\r
-\r
- Status = CreateServiceChildAndOpenProtocol (\r
- ControllerHandle,\r
- &gEfiMtftp4ServiceBindingProtocolGuid,\r
- &gEfiMtftp4ProtocolGuid,\r
- &Mtftp4ChildHandle,\r
- (VOID**)&Mtftp4\r
- );\r
- if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_OPEN_PROTOCOL),\r
- gShellTftpHiiHandle, NicName, Status\r
- );\r
- continue;\r
- }\r
-\r
- Status = Mtftp4->Configure (Mtftp4, &Mtftp4ConfigData);\r
- if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_CONFIGURE),\r
- gShellTftpHiiHandle, NicName, Status\r
- );\r
- goto NextHandle;\r
- }\r
-\r
- Status = GetFileSize (Mtftp4, AsciiRemoteFilePath, &FileSize);\r
- if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_FILE_SIZE),\r
- gShellTftpHiiHandle, RemoteFilePath, NicName, Status\r
- );\r
- goto NextHandle;\r
- }\r
-\r
- Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, BlockSize, &Data);\r
- if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD),\r
- gShellTftpHiiHandle, RemoteFilePath, NicName, Status\r
- );\r
- goto NextHandle;\r
- }\r
-\r
- if (!EFI_ERROR (ShellFileExists (LocalFilePath))) {\r
- ShellDeleteFileByName (LocalFilePath);\r
- }\r
-\r
- Status = ShellOpenFileByName (\r
- LocalFilePath,\r
- &FileHandle,\r
- EFI_FILE_MODE_CREATE |\r
- EFI_FILE_MODE_WRITE |\r
- EFI_FILE_MODE_READ,\r
- 0\r
- );\r
- if (EFI_ERROR (Status)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL),\r
- gShellTftpHiiHandle, L"tftp", LocalFilePath\r
- );\r
- goto NextHandle;\r
- }\r
-\r
- DataSize = FileSize;\r
- Status = ShellWriteFile (FileHandle, &FileSize, Data);\r
- if (!EFI_ERROR (Status)) {\r
- ShellStatus = SHELL_SUCCESS;\r
- } else {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_WRITE),\r
- gShellTftpHiiHandle, LocalFilePath, Status\r
- );\r
- }\r
- ShellCloseFile (&FileHandle);\r
-\r
- NextHandle:\r
-\r
- if (Data != NULL) {\r
- gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Data, EFI_SIZE_TO_PAGES (DataSize));\r
- }\r
-\r
- CloseProtocolAndDestroyServiceChild (\r
- ControllerHandle,\r
- &gEfiMtftp4ServiceBindingProtocolGuid,\r
- &gEfiMtftp4ProtocolGuid,\r
- Mtftp4ChildHandle\r
- );\r
- }\r
-\r
- if ((UserNicName != NULL) && (!NicFound)) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NOT_FOUND),\r
- gShellTftpHiiHandle, UserNicName\r
- );\r
- }\r
-\r
- Error:\r
-\r
- ShellCommandLineFreeVarList (CheckPackage);\r
- if (AsciiRemoteFilePath != NULL) {\r
- FreePool (AsciiRemoteFilePath);\r
- }\r
- if (Handles != NULL) {\r
- FreePool (Handles);\r
- }\r
-\r
- return ShellStatus;\r
-}\r
-\r
-/**\r
- Check and convert the UINT16 option values of the 'tftp' command\r
-\r
- @param[in] ValueStr Value as an Unicode encoded string\r
- @param[out] Value UINT16 value\r
-\r
- @return TRUE The value was returned.\r
- @return FALSE A parsing error occured.\r
-**/\r
-STATIC\r
-BOOLEAN\r
-StringToUint16 (\r
- IN CONST CHAR16 *ValueStr,\r
- OUT UINT16 *Value\r
- )\r
-{\r
- UINTN Val;\r
-\r
- Val = ShellStrToUintn (ValueStr);\r
- if (Val > MAX_UINT16) {\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),\r
- gShellTftpHiiHandle, L"tftp", ValueStr\r
- );\r
- return FALSE;\r
- }\r
-\r
- *Value = (UINT16)Val;\r
- return TRUE;\r
-}\r
-\r
-/**\r
- Get the name of the NIC.\r
-\r
- @param[in] ControllerHandle The network physical device handle.\r
- @param[in] NicNumber The network physical device number.\r
- @param[out] NicName Address where to store the NIC name.\r
- The memory area has to be at least\r
- IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH \r
- double byte wide.\r
-\r
- @return EFI_SUCCESS The name of the NIC was returned.\r
- @return Others The creation of the child for the Managed\r
- Network Service failed or the opening of\r
- the Managed Network Protocol failed or\r
- the operational parameters for the\r
- Managed Network Protocol could not be\r
- read.\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-GetNicName (\r
- IN EFI_HANDLE ControllerHandle,\r
- IN UINTN NicNumber,\r
- OUT CHAR16 *NicName\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_HANDLE MnpHandle;\r
- EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r
- EFI_SIMPLE_NETWORK_MODE SnpMode;\r
-\r
- Status = CreateServiceChildAndOpenProtocol (\r
- ControllerHandle,\r
- &gEfiManagedNetworkServiceBindingProtocolGuid,\r
- &gEfiManagedNetworkProtocolGuid,\r
- &MnpHandle,\r
- (VOID**)&Mnp\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Error;\r
- }\r
-\r
- Status = Mnp->GetModeData (Mnp, NULL, &SnpMode);\r
- if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {\r
- goto Error;\r
- }\r
-\r
- UnicodeSPrint (\r
- NicName,\r
- IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH,\r
- SnpMode.IfType == NET_IFTYPE_ETHERNET ?\r
- L"eth%d" :\r
- L"unk%d" ,\r
- NicNumber\r
- );\r
-\r
- Status = EFI_SUCCESS;\r
-\r
-Error:\r
-\r
- if (MnpHandle != NULL) {\r
- CloseProtocolAndDestroyServiceChild (\r
- ControllerHandle,\r
- &gEfiManagedNetworkServiceBindingProtocolGuid,\r
- &gEfiManagedNetworkProtocolGuid,\r
- MnpHandle\r
- );\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Create a child for the service identified by its service binding protocol GUID\r
- and get from the child the interface of the protocol identified by its GUID.\r
-\r
- @param[in] ControllerHandle Controller handle.\r
- @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the\r
- service to be created.\r
- @param[in] ProtocolGuid GUID of the protocol to be open.\r
- @param[out] ChildHandle Address where the handler of the\r
- created child is returned. NULL is\r
- returned in case of error.\r
- @param[out] Interface Address where a pointer to the\r
- protocol interface is returned in\r
- case of success.\r
-\r
- @return EFI_SUCCESS The child was created and the protocol opened.\r
- @return Others Either the creation of the child or the opening\r
- of the protocol failed.\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-CreateServiceChildAndOpenProtocol (\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_GUID *ServiceBindingProtocolGuid,\r
- IN EFI_GUID *ProtocolGuid,\r
- OUT EFI_HANDLE *ChildHandle,\r
- OUT VOID **Interface\r
- )\r
-{\r
- EFI_STATUS Status;\r
-\r
- *ChildHandle = NULL;\r
- Status = NetLibCreateServiceChild (\r
- ControllerHandle,\r
- gImageHandle,\r
- ServiceBindingProtocolGuid,\r
- ChildHandle\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- Status = gBS->OpenProtocol (\r
- *ChildHandle,\r
- ProtocolGuid,\r
- Interface,\r
- gImageHandle,\r
- ControllerHandle,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
- );\r
- if (EFI_ERROR (Status)) {\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- gImageHandle,\r
- ServiceBindingProtocolGuid,\r
- *ChildHandle\r
- );\r
- *ChildHandle = NULL;\r
- }\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Close the protocol identified by its GUID on the child handle of the service\r
- identified by its service binding protocol GUID, then destroy the child\r
- handle.\r
-\r
- @param[in] ControllerHandle Controller handle.\r
- @param[in] ServiceBindingProtocolGuid Service binding protocol GUID of the\r
- service to be destroyed.\r
- @param[in] ProtocolGuid GUID of the protocol to be closed.\r
- @param[in] ChildHandle Handle of the child to be destroyed.\r
-\r
-**/\r
-STATIC\r
-VOID\r
-CloseProtocolAndDestroyServiceChild (\r
- IN EFI_HANDLE ControllerHandle,\r
- IN EFI_GUID *ServiceBindingProtocolGuid,\r
- IN EFI_GUID *ProtocolGuid,\r
- IN EFI_HANDLE ChildHandle\r
- )\r
-{\r
- gBS->CloseProtocol (\r
- ChildHandle,\r
- ProtocolGuid,\r
- gImageHandle,\r
- ControllerHandle\r
- );\r
-\r
- NetLibDestroyServiceChild (\r
- ControllerHandle,\r
- gImageHandle,\r
- ServiceBindingProtocolGuid,\r
- ChildHandle\r
- );\r
-}\r
-\r
-/**\r
- Worker function that gets the size in numbers of bytes of a file from a TFTP\r
- server before to download the file.\r
-\r
- @param[in] Mtftp4 MTFTP4 protocol interface\r
- @param[in] FilePath Path of the file, ASCII encoded\r
- @param[out] FileSize Address where to store the file size in number of\r
- bytes.\r
-\r
- @retval EFI_SUCCESS The size of the file was returned.\r
- @retval EFI_UNSUPPORTED The server does not support the "tsize" option.\r
- @retval Others Error when retrieving the information from the server\r
- (see EFI_MTFTP4_PROTOCOL.GetInfo() status codes)\r
- or error when parsing the response of the server.\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-GetFileSize (\r
- IN EFI_MTFTP4_PROTOCOL *Mtftp4,\r
- IN CONST CHAR8 *FilePath,\r
- OUT UINTN *FileSize\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_MTFTP4_OPTION ReqOpt[1];\r
- EFI_MTFTP4_PACKET *Packet;\r
- UINT32 PktLen;\r
- EFI_MTFTP4_OPTION *TableOfOptions;\r
- EFI_MTFTP4_OPTION *Option;\r
- UINT32 OptCnt;\r
- UINT8 OptBuf[128];\r
-\r
- ReqOpt[0].OptionStr = (UINT8*)"tsize";\r
- OptBuf[0] = '0';\r
- OptBuf[1] = 0;\r
- ReqOpt[0].ValueStr = OptBuf;\r
-\r
- Status = Mtftp4->GetInfo (\r
- Mtftp4,\r
- NULL,\r
- (UINT8*)FilePath,\r
- NULL,\r
- 1,\r
- ReqOpt,\r
- &PktLen,\r
- &Packet\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- goto Error;\r
- }\r
-\r
- Status = Mtftp4->ParseOptions (\r
- Mtftp4,\r
- PktLen,\r
- Packet,\r
- (UINT32 *) &OptCnt,\r
- &TableOfOptions\r
- );\r
- if (EFI_ERROR (Status)) {\r
- goto Error;\r
- }\r
-\r
- Option = TableOfOptions;\r
- while (OptCnt != 0) {\r
- if (AsciiStrnCmp ((CHAR8 *)Option->OptionStr, "tsize", 5) == 0) {\r
- *FileSize = AsciiStrDecimalToUintn ((CHAR8 *)Option->ValueStr);\r
- break;\r
- }\r
- OptCnt--;\r
- Option++;\r
- }\r
- FreePool (TableOfOptions);\r
-\r
- if (OptCnt == 0) {\r
- Status = EFI_UNSUPPORTED;\r
- }\r
-\r
-Error :\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Worker function that download the data of a file from a TFTP server given\r
- the path of the file and its size.\r
-\r
- @param[in] Mtftp4 MTFTP4 protocol interface\r
- @param[in] FilePath Path of the file, Unicode encoded\r
- @param[in] AsciiFilePath Path of the file, ASCII encoded\r
- @param[in] FileSize Size of the file in number of bytes\r
- @param[in] BlockSize Value of the TFTP blksize option\r
- @param[out] Data Address where to store the address of the buffer\r
- where the data of the file were downloaded in\r
- case of success.\r
-\r
- @retval EFI_SUCCESS The file was downloaded.\r
- @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
- @retval Others The downloading of the file from the server failed\r
- (see EFI_MTFTP4_PROTOCOL.ReadFile() status codes).\r
-\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-DownloadFile (\r
- IN EFI_MTFTP4_PROTOCOL *Mtftp4,\r
- IN CONST CHAR16 *FilePath,\r
- IN CONST CHAR8 *AsciiFilePath,\r
- IN UINTN FileSize,\r
- IN UINT16 BlockSize,\r
- OUT VOID **Data\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_PHYSICAL_ADDRESS PagesAddress;\r
- VOID *Buffer;\r
- DOWNLOAD_CONTEXT *TftpContext;\r
- EFI_MTFTP4_TOKEN Mtftp4Token;\r
- EFI_MTFTP4_OPTION ReqOpt;\r
- UINT8 OptBuf[10];\r
-\r
- // Downloaded file can be large. BS.AllocatePages() is more faster\r
- // than AllocatePool() and avoid fragmentation.\r
- // The downloaded file could be an EFI application. Marking the\r
- // allocated page as EfiBootServicesCode would allow to execute a\r
- // potential downloaded EFI application.\r
- Status = gBS->AllocatePages (\r
- AllocateAnyPages,\r
- EfiBootServicesCode,\r
- EFI_SIZE_TO_PAGES (FileSize),\r
- &PagesAddress\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- Buffer = (VOID*)(UINTN)PagesAddress;\r
- TftpContext = AllocatePool (sizeof (DOWNLOAD_CONTEXT));\r
- if (TftpContext == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Error;\r
- }\r
- TftpContext->FileSize = FileSize;\r
- TftpContext->DownloadedNbOfBytes = 0;\r
- TftpContext->LastReportedNbOfBytes = 0;\r
-\r
- ZeroMem (&Mtftp4Token, sizeof (EFI_MTFTP4_TOKEN));\r
- Mtftp4Token.Filename = (UINT8*)AsciiFilePath;\r
- Mtftp4Token.BufferSize = FileSize;\r
- Mtftp4Token.Buffer = Buffer;\r
- Mtftp4Token.CheckPacket = CheckPacket;\r
- Mtftp4Token.Context = (VOID*)TftpContext;\r
- if (BlockSize != MTFTP_DEFAULT_BLKSIZE) {\r
- ReqOpt.OptionStr = (UINT8 *) "blksize";\r
- AsciiSPrint ((CHAR8 *)OptBuf, sizeof (OptBuf), "%d", BlockSize);\r
- ReqOpt.ValueStr = OptBuf;\r
-\r
- Mtftp4Token.OptionCount = 1;\r
- Mtftp4Token.OptionList = &ReqOpt;\r
- }\r
-\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_TFTP_DOWNLOADING),\r
- gShellTftpHiiHandle, FilePath\r
- );\r
-\r
- Status = Mtftp4->ReadFile (Mtftp4, &Mtftp4Token);\r
- ShellPrintHiiEx (\r
- -1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF),\r
- gShellTftpHiiHandle\r
- );\r
-\r
-Error :\r
-\r
- if (TftpContext == NULL) {\r
- FreePool (TftpContext);\r
- }\r
-\r
- if (EFI_ERROR (Status)) {\r
- gBS->FreePages (PagesAddress, EFI_SIZE_TO_PAGES (FileSize));\r
- return Status;\r
- }\r
-\r
- *Data = Buffer;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Update the progress of a file download\r
- This procedure is called each time a new TFTP packet is received.\r
-\r
- @param[in] This MTFTP4 protocol interface\r
- @param[in] Token Parameters for the download of the file\r
- @param[in] PacketLen Length of the packet\r
- @param[in] Packet Address of the packet\r
-\r
- @retval EFI_SUCCESS All packets are accepted.\r
-\r
-**/\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-CheckPacket (\r
- IN EFI_MTFTP4_PROTOCOL *This,\r
- IN EFI_MTFTP4_TOKEN *Token,\r
- IN UINT16 PacketLen,\r
- IN EFI_MTFTP4_PACKET *Packet\r
- )\r
-{\r
- DOWNLOAD_CONTEXT *Context;\r
- CHAR16 Progress[TFTP_PROGRESS_MESSAGE_SIZE];\r
- UINTN NbOfKb;\r
- UINTN Index;\r
- UINTN LastStep;\r
- UINTN Step;\r
- EFI_STATUS Status;\r
-\r
- if ((NTOHS (Packet->OpCode)) != EFI_MTFTP4_OPCODE_DATA) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- Context = (DOWNLOAD_CONTEXT*)Token->Context;\r
- if (Context->DownloadedNbOfBytes == 0) {\r
- ShellPrintEx (-1, -1, L"%s 0 Kb", mTftpProgressFrame);\r
- }\r
-\r
- //\r
- // The data in the packet are prepended with two UINT16 :\r
- // . OpCode = EFI_MTFTP4_OPCODE_DATA\r
- // . Block = the number of this block of data\r
- //\r
- Context->DownloadedNbOfBytes += PacketLen - sizeof (Packet->OpCode)\r
- - sizeof (Packet->Data.Block);\r
- NbOfKb = Context->DownloadedNbOfBytes / 1024;\r
-\r
- Progress[0] = L'\0';\r
- LastStep = (Context->LastReportedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;\r
- Step = (Context->DownloadedNbOfBytes * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;\r
-\r
- if (Step <= LastStep) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- ShellPrintEx (-1, -1, L"%s", mTftpProgressDelete);\r
-\r
- Status = StrCpyS (Progress, TFTP_PROGRESS_MESSAGE_SIZE, mTftpProgressFrame);\r
- if (EFI_ERROR(Status)) {\r
- return Status;\r
- }\r
- for (Index = 1; Index < Step; Index++) {\r
- Progress[Index] = L'=';\r
- }\r
- Progress[Step] = L'>';\r
-\r
- UnicodeSPrint (\r
- Progress + (sizeof (mTftpProgressFrame) / sizeof (CHAR16)) - 1,\r
- sizeof (Progress) - sizeof (mTftpProgressFrame),\r
- L" %7d Kb",\r
- NbOfKb\r
- );\r
- Context->LastReportedNbOfBytes = Context->DownloadedNbOfBytes;\r
-\r
- ShellPrintEx (-1, -1, L"%s", Progress);\r
-\r
- return EFI_SUCCESS;\r
-}\r
+++ /dev/null
-/** @file\r
- Main file for NULL named library for 'tftp' Shell command functions.\r
-\r
- Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved. <BR>\r
- Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
-\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-#include "UefiShellTftpCommandLib.h"\r
-\r
-CONST CHAR16 gShellTftpFileName[] = L"ShellCommand";\r
-EFI_HANDLE gShellTftpHiiHandle = NULL;\r
-\r
-/**\r
- Return the file name of the help text file if not using HII.\r
-\r
- @return The string pointer to the file name.\r
-**/\r
-CONST CHAR16*\r
-EFIAPI\r
-ShellCommandGetManFileNameTftp (\r
- VOID\r
- )\r
-{\r
- return gShellTftpFileName;\r
-}\r
-\r
-/**\r
- Constructor for the Shell Tftp Command library.\r
-\r
- Install the handlers for Tftp UEFI Shell command.\r
-\r
- @param ImageHandle The image handle of the process.\r
- @param SystemTable The EFI System Table pointer.\r
-\r
- @retval EFI_SUCCESS The Shell command handlers were installed sucessfully.\r
- @retval EFI_UNSUPPORTED The Shell level required was not found.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ShellTftpCommandLibConstructor (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-{\r
- gShellTftpHiiHandle = NULL;\r
-\r
- //\r
- // check our bit of the profiles mask\r
- //\r
- if ((PcdGet8 (PcdShellProfileMask) & BIT3) == 0) {\r
- return EFI_SUCCESS;\r
- }\r
-\r
- gShellTftpHiiHandle = HiiAddPackages (\r
- &gShellTftpHiiGuid, gImageHandle,\r
- UefiShellTftpCommandLibStrings, NULL\r
- );\r
- if (gShellTftpHiiHandle == NULL) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- //\r
- // Install our Shell command handler\r
- //\r
- ShellCommandRegisterCommandName (\r
- L"tftp", ShellCommandRunTftp, ShellCommandGetManFileNameTftp, 0,\r
- L"tftp", TRUE , gShellTftpHiiHandle, STRING_TOKEN (STR_GET_HELP_TFTP)\r
- );\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Destructor for the library. free any resources.\r
-\r
- @param ImageHandle The image handle of the process.\r
- @param SystemTable The EFI System Table pointer.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ShellTftpCommandLibDestructor (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-{\r
- if (gShellTftpHiiHandle != NULL) {\r
- HiiRemovePackages (gShellTftpHiiHandle);\r
- }\r
- return EFI_SUCCESS;\r
-}\r
+++ /dev/null
-/** @file\r
- header file for NULL named library for 'tftp' Shell command functions.\r
-\r
- Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved. <BR>\r
- Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
-\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#ifndef _UEFI_SHELL_TFTP_COMMAND_LIB_H_\r
-#define _UEFI_SHELL_TFTP_COMMAND_LIB_H_\r
-\r
-#include <Uefi.h>\r
-\r
-#include <Guid/ShellLibHiiGuid.h>\r
-\r
-#include <Protocol/ServiceBinding.h>\r
-#include <Protocol/Mtftp4.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/ShellCommandLib.h>\r
-#include <Library/ShellLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/HiiLib.h>\r
-#include <Library/NetLib.h>\r
-#include <Library/PrintLib.h>\r
-\r
-extern EFI_HANDLE gShellTftpHiiHandle;\r
-\r
-typedef struct {\r
- UINTN FileSize;\r
- UINTN DownloadedNbOfBytes;\r
- UINTN LastReportedNbOfBytes;\r
-} DOWNLOAD_CONTEXT;\r
-\r
-/**\r
- Function for 'tftp' command.\r
-\r
- @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
- @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
-**/\r
-SHELL_STATUS\r
-EFIAPI\r
-ShellCommandRunTftp (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- );\r
-\r
-#endif /* _UEFI_SHELL_TFTP_COMMAND_LIB_H_ */\r
+++ /dev/null
-## @file\r
-# Provides Shell 'tftp' command functions\r
-#\r
-# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved. <BR>\r
-# Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
-#\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution. The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-#\r
-##\r
-\r
-[Defines]\r
- INF_VERSION = 0x00010006\r
- BASE_NAME = UefiShellTftpCommandLib\r
- FILE_GUID = D2B61A25-9835-4E5D-906A-15615E1FF668\r
- MODULE_TYPE = UEFI_APPLICATION\r
- VERSION_STRING = 1.0\r
- LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER\r
- CONSTRUCTOR = ShellTftpCommandLibConstructor\r
- DESTRUCTOR = ShellTftpCommandLibDestructor\r
-\r
-[Sources.common]\r
- UefiShellTftpCommandLib.uni\r
- UefiShellTftpCommandLib.c\r
- UefiShellTftpCommandLib.h\r
- Tftp.c\r
-\r
-[Packages]\r
- MdePkg/MdePkg.dec\r
- ShellPkg/ShellPkg.dec\r
- MdeModulePkg/MdeModulePkg.dec\r
-\r
-[LibraryClasses]\r
- MemoryAllocationLib\r
- BaseLib\r
- BaseMemoryLib\r
- DebugLib\r
- ShellCommandLib\r
- ShellLib\r
- UefiLib\r
- UefiRuntimeServicesTableLib\r
- UefiBootServicesTableLib\r
- PcdLib\r
- HiiLib\r
- FileHandleLib\r
- NetLib\r
-\r
-[Pcd]\r
- gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask ## CONSUMES\r
-\r
-[Protocols]\r
- gEfiManagedNetworkServiceBindingProtocolGuid ## CONSUMES\r
- gEfiMtftp4ServiceBindingProtocolGuid ## CONSUMES\r
-\r
-[Guids]\r
- gShellTftpHiiGuid ## CONSUMES ## HII\r
+++ /dev/null
-// /**\r
-//\r
-// (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
-// Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved. <BR>\r
-// This program and the accompanying materials\r
-// are licensed and made available under the terms and conditions of the BSD License\r
-// which accompanies this distribution. The full text of the license may be found at\r
-// http://opensource.org/licenses/bsd-license.php\r
-//\r
-// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-//\r
-// Module Name:\r
-//\r
-// UefiShellTftpCommandLib.uni\r
-//\r
-// Abstract:\r
-//\r
-// String definitions for UEFI Shell TFTP command\r
-//\r
-//\r
-// **/\r
-\r
-/=#\r
-\r
-#langdef en-US "english"\r
-\r
-#string STR_GEN_TOO_MANY #language en-US "%H%s%N: Too many arguments\r\n"\r
-#string STR_GEN_TOO_FEW #language en-US "%H%s%N: Too few arguments\r\n"\r
-#string STR_GEN_PARAM_INV #language en-US "%H%s%N: Invalid argument - '%H%s%N'\r\n"\r
-#string STR_GEN_PROBLEM #language en-US "%H%s%N: Unknown flag - '%H%s%N'\r\n"\r
-#string STR_GEN_FILE_OPEN_FAIL #language en-US "%H%s%N: Cannot open file - '%H%s%N'\r\n"\r
-#string STR_GEN_CRLF #language en-US "\r\n"\r
-\r
-#string STR_TFTP_ERR_NO_NIC #language en-US "No network interface card found.\r\n"\r
-#string STR_TFTP_ERR_NIC_NAME #language en-US "Failed to get the name of the network interface card number %d - %r\r\n"\r
-#string STR_TFTP_ERR_OPEN_PROTOCOL #language en-US "Unable to open MTFTP4 protocol on '%H%s%N' - %r\r\n"\r
-#string STR_TFTP_ERR_CONFIGURE #language en-US "Unable to configure MTFTP4 protocol on '%H%s%N' - %r\r\n"\r
-#string STR_TFTP_ERR_FILE_SIZE #language en-US "Unable to get the size of the file '%H%s%N' on '%H%s%N' - %r\r\n"\r
-#string STR_TFTP_ERR_DOWNLOAD #language en-US "Unable to download the file '%H%s%N' on '%H%s%N' - %r\r\n"\r
-#string STR_TFTP_ERR_WRITE #language en-US "Unable to write into file '%H%s%N' - %r\r\n"\r
-#string STR_TFTP_ERR_NIC_NOT_FOUND #language en-US "Network Interface Card '%H%s%N' not found.\r\n"\r
-#string STR_TFTP_DOWNLOADING #language en-US "Downloading the file '%H%s%N'\r\n"\r
-#string STR_TFTP_STRING #language en-US "%s"\r
-\r
-#string STR_GET_HELP_TFTP #language en-US ""\r
-".TH tftp 0 "Download a file from TFTP server."\r\n"\r
-".SH NAME\r\n"\r
-"Download a file from TFTP server.\r\n"\r
-".SH SYNOPSIS\r\n"\r
-" \r\n"\r
-"TFTP [-i interface] [-l <port>] [-r <port>] [-c <retry count>] [-t <timeout>]\r\n"\r
-" [-s <block size>] host remotefilepath [localfilepath]\r\n"\r
-".SH OPTIONS\r\n"\r
-" \r\n"\r
-" -i interface - Specifies an adapter name, i.e., eth0.\r\n"\r
-" -l port - Specifies the local port number. Default value is 0\r\n"\r
-" and the port number is automatically assigned.\r\n"\r
-" -r port - Specifies the remote port number. Default value is 69.\r\n"\r
-" -c <retry count> - The number of times to transmit request packets and\r\n"\r
-" wait for a response. The default value is 6.\r\n"\r
-" -t <timeout> - The number of seconds to wait for a response after\r\n"\r
-" sending a request packet. Default value is 4s.\r\n"\r
-" -s <block size> - Specifies the TFTP blksize option as defined in RFC 2348.\r\n"\r
-" Valid range is between 8 and 65464, default value is 512.\r\n"\r
-" host - Specify TFTP Server IPv4 address.\r\n"\r
-" remotefilepath - TFTP server file path to download the file.\r\n"\r
-" localfilepath - Local destination file path.\r\n"\r
-".SH DESCRIPTION\r\n"\r
-" \r\n"\r
-"NOTES:\r\n"\r
-" 1. The TFTP command allows to get the file specified by its 'remotefilepath'\r\n"\r
-" path from the TFTP server specified by its 'host' IPv4 address. If the\r\n"\r
-" optional 'localfilepath' parameter is provided, the downloaded file is\r\n"\r
-" stored locally using the provided file path. If the local file path is\r\n"\r
-" not specified, the file is stored in the current directory using the file\r\n"\r
-" server's name.\r\n"\r
-" 2. Before using the TFTP command, the network interface intended to be\r\n"\r
-" used to retrieve the file must be configured. This configuration may be\r\n"\r
-" done by means of the 'ifconfig' command.\r\n"\r
-" 3. If a network interface is defined with the '-i' option then only this\r\n"\r
-" interface will be used to retrieve the remote file. Otherwise, all network\r\n"\r
-" interfaces are tried in the order they have been discovered during the\r\n"\r
-" DXE phase.\r\n"\r
-".SH EXAMPLES\r\n"\r
-" \r\n"\r
-"EXAMPLES:\r\n"\r
-" * To get the file "dir1/file1.dat" from the TFTP server 192.168.1.1 and\r\n"\r
-" store it as file2.dat in the current directory :\r\n"\r
-" fs0:\> tftp 192.168.1.1 dir1/file1.dat file2.dat\r\n"\r
-".SH RETURNVALUES\r\n"\r
-" \r\n"\r
-"RETURN VALUES:\r\n"\r
-" SHELL_SUCCESS The action was completed as requested.\r\n"\r
-" SHELL_INVALID_PARAMETER One of the passed-in parameters was incorrectly\r\n"\r
-" formatted or its value was out of bounds.\r\n"\r
-\r
\r
[LibraryClasses.common]\r
UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf\r
!if $(TARGET) == RELEASE\r
\r
[PcdsFixedAtBuild]\r
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF\r
- gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE\r
gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|16000\r
!ifdef $(NO_SHELL_PROFILES)\r
gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask|0x00\r
ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf\r
ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf\r
ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf\r
- ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf\r
\r
ShellPkg/Library/UefiDpLib/UefiDpLib.inf {\r
<LibraryClasses>\r
}\r
\r
ShellPkg/Application/Shell/Shell.inf {\r
+ <PcdsFixedAtBuild>\r
+ gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE\r
<LibraryClasses>\r
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf\r
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf\r
!ifdef $(INCLUDE_DP)\r
NULL|ShellPkg/Library/UefiDpLib/UefiDpLib.inf\r
!endif #$(INCLUDE_DP)\r
-!ifdef $(INCLUDE_TFTP_COMMAND)\r
- NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf\r
-!endif #$(INCLUDE_TFTP_COMMAND)\r
!endif #$(NO_SHELL_PROFILES)\r
}\r
\r
+ ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf\r
+ ShellPkg/DynamicCommand/TftpDynamicCommand/TftpApp.inf\r
+\r
[BuildOptions]\r
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES\r