]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Add argument to set block size for tftp command.
authorFu Siyuan <siyuan.fu@intel.com>
Fri, 6 May 2016 02:30:09 +0000 (10:30 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Fri, 20 May 2016 03:30:47 +0000 (11:30 +0800)
TFTP block size has a big impact on the transmit performance, this patch is to
add new argument [-s <block size>] for shell "tftp" command to configure the
block size for file download.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c
ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.uni

index 831b9c3d0250c342a4c19ee0073d5be65fe90981..cb8cb9fb16cd11bdca00759d6b9087d6a452f2c4 100644 (file)
@@ -2,7 +2,7 @@
   The implementation for the 'tftp' Shell command.\r
 \r
   Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>\r
-  Copyright (c) 2015, Intel Corporation. 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
@@ -163,6 +163,7 @@ GetFileSize (
   @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
@@ -180,6 +181,7 @@ DownloadFile (
   IN   CONST CHAR16         *FilePath,\r
   IN   CONST CHAR8          *AsciiFilePath,\r
   IN   UINTN                FileSize,\r
+  IN   UINT16               BlockSize,\r
   OUT  VOID                 **Data\r
   );\r
 \r
@@ -223,9 +225,21 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {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
@@ -271,6 +285,7 @@ ShellCommandRunTftp (
   UINTN                   FileSize;\r
   VOID                    *Data;\r
   SHELL_FILE_HANDLE       FileHandle;\r
+  UINT16                  BlockSize;\r
 \r
   ShellStatus         = SHELL_INVALID_PARAMETER;\r
   ProblemParam        = NULL;\r
@@ -278,6 +293,7 @@ ShellCommandRunTftp (
   AsciiRemoteFilePath = NULL;\r
   Handles             = NULL;\r
   FileSize            = 0;\r
+  BlockSize           = MTFTP_DEFAULT_BLKSIZE;\r
 \r
   //\r
   // Initialize the Shell library (we must be in non-auto-init...)\r
@@ -404,6 +420,20 @@ ShellCommandRunTftp (
     }\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
@@ -478,7 +508,7 @@ ShellCommandRunTftp (
       goto NextHandle;\r
     }\r
 \r
-    Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, &Data);\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
@@ -843,6 +873,7 @@ Error :
   @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
@@ -860,6 +891,7 @@ DownloadFile (
   IN   CONST CHAR16         *FilePath,\r
   IN   CONST CHAR8          *AsciiFilePath,\r
   IN   UINTN                FileSize,\r
+  IN   UINT16               BlockSize,\r
   OUT  VOID                 **Data\r
   )\r
 {\r
@@ -868,6 +900,8 @@ DownloadFile (
   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
@@ -900,6 +934,14 @@ DownloadFile (
   Mtftp4Token.Buffer      = Buffer;\r
   Mtftp4Token.CheckPacket = CheckPacket;\r
   Mtftp4Token.Context     = (VOID*)TftpContext;\r
+  if (BlockSize != MTFTP_DEFAULT_BLKSIZE) {\r
+    ReqOpt.OptionStr = "blksize";\r
+    AsciiSPrint (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
index 33a8944504c3484ebaf53e9caed7c624b192a136..a16265c16ebb57a53c5eca978a0aa31427b605fa 100644 (file)
@@ -1,7 +1,7 @@
 // /**\r
 //\r
 // (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
-// Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved. <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
@@ -50,7 +50,7 @@
 ".SH SYNOPSIS\r\n"\r
 " \r\n"\r
 "TFTP [-i interface] [-l <port>] [-r <port>] [-c <retry count>] [-t <timeout>]\r\n"\r
-"     host remotefilepath [localfilepath]\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
@@ -61,6 +61,8 @@
 "                     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