mirror of https://github.com/acidanthera/audk.git
ShellPkg: Add argument to set block size for tftp command.
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>
This commit is contained in:
parent
1f1ec99dea
commit
2be45bfe27
|
@ -2,7 +2,7 @@
|
||||||
The implementation for the 'tftp' Shell command.
|
The implementation for the 'tftp' Shell command.
|
||||||
|
|
||||||
Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
|
Copyright (c) 2015, ARM Ltd. All rights reserved.<BR>
|
||||||
Copyright (c) 2015, Intel Corporation. All rights reserved. <BR>
|
Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved. <BR>
|
||||||
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
|
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
|
||||||
|
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
|
@ -163,6 +163,7 @@ GetFileSize (
|
||||||
@param[in] FilePath Path of the file, Unicode encoded
|
@param[in] FilePath Path of the file, Unicode encoded
|
||||||
@param[in] AsciiFilePath Path of the file, ASCII encoded
|
@param[in] AsciiFilePath Path of the file, ASCII encoded
|
||||||
@param[in] FileSize Size of the file in number of bytes
|
@param[in] FileSize Size of the file in number of bytes
|
||||||
|
@param[in] BlockSize Value of the TFTP blksize option
|
||||||
@param[out] Data Address where to store the address of the buffer
|
@param[out] Data Address where to store the address of the buffer
|
||||||
where the data of the file were downloaded in
|
where the data of the file were downloaded in
|
||||||
case of success.
|
case of success.
|
||||||
|
@ -180,6 +181,7 @@ DownloadFile (
|
||||||
IN CONST CHAR16 *FilePath,
|
IN CONST CHAR16 *FilePath,
|
||||||
IN CONST CHAR8 *AsciiFilePath,
|
IN CONST CHAR8 *AsciiFilePath,
|
||||||
IN UINTN FileSize,
|
IN UINTN FileSize,
|
||||||
|
IN UINT16 BlockSize,
|
||||||
OUT VOID **Data
|
OUT VOID **Data
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -223,9 +225,21 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
||||||
{L"-r", TypeValue},
|
{L"-r", TypeValue},
|
||||||
{L"-c", TypeValue},
|
{L"-c", TypeValue},
|
||||||
{L"-t", TypeValue},
|
{L"-t", TypeValue},
|
||||||
|
{L"-s", TypeValue},
|
||||||
{NULL , TypeMax}
|
{NULL , TypeMax}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The default block size (512) of tftp is defined in the RFC1350.
|
||||||
|
///
|
||||||
|
#define MTFTP_DEFAULT_BLKSIZE 512
|
||||||
|
///
|
||||||
|
/// The valid range of block size option is defined in the RFC2348.
|
||||||
|
///
|
||||||
|
#define MTFTP_MIN_BLKSIZE 8
|
||||||
|
#define MTFTP_MAX_BLKSIZE 65464
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Function for 'tftp' command.
|
Function for 'tftp' command.
|
||||||
|
|
||||||
|
@ -271,6 +285,7 @@ ShellCommandRunTftp (
|
||||||
UINTN FileSize;
|
UINTN FileSize;
|
||||||
VOID *Data;
|
VOID *Data;
|
||||||
SHELL_FILE_HANDLE FileHandle;
|
SHELL_FILE_HANDLE FileHandle;
|
||||||
|
UINT16 BlockSize;
|
||||||
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
ProblemParam = NULL;
|
ProblemParam = NULL;
|
||||||
|
@ -278,6 +293,7 @@ ShellCommandRunTftp (
|
||||||
AsciiRemoteFilePath = NULL;
|
AsciiRemoteFilePath = NULL;
|
||||||
Handles = NULL;
|
Handles = NULL;
|
||||||
FileSize = 0;
|
FileSize = 0;
|
||||||
|
BlockSize = MTFTP_DEFAULT_BLKSIZE;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize the Shell library (we must be in non-auto-init...)
|
// Initialize the Shell library (we must be in non-auto-init...)
|
||||||
|
@ -404,6 +420,20 @@ ShellCommandRunTftp (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ValueStr = ShellCommandLineGetValue (CheckPackage, L"-s");
|
||||||
|
if (ValueStr != NULL) {
|
||||||
|
if (!StringToUint16 (ValueStr, &BlockSize)) {
|
||||||
|
goto Error;
|
||||||
|
}
|
||||||
|
if (BlockSize < MTFTP_MIN_BLKSIZE || BlockSize > MTFTP_MAX_BLKSIZE) {
|
||||||
|
ShellPrintHiiEx (
|
||||||
|
-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV),
|
||||||
|
gShellTftpHiiHandle, L"tftp", ValueStr
|
||||||
|
);
|
||||||
|
goto Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Locate all MTFTP4 Service Binding protocols
|
// Locate all MTFTP4 Service Binding protocols
|
||||||
//
|
//
|
||||||
|
@ -478,7 +508,7 @@ ShellCommandRunTftp (
|
||||||
goto NextHandle;
|
goto NextHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, &Data);
|
Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, BlockSize, &Data);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
ShellPrintHiiEx (
|
ShellPrintHiiEx (
|
||||||
-1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD),
|
-1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD),
|
||||||
|
@ -843,6 +873,7 @@ Error :
|
||||||
@param[in] FilePath Path of the file, Unicode encoded
|
@param[in] FilePath Path of the file, Unicode encoded
|
||||||
@param[in] AsciiFilePath Path of the file, ASCII encoded
|
@param[in] AsciiFilePath Path of the file, ASCII encoded
|
||||||
@param[in] FileSize Size of the file in number of bytes
|
@param[in] FileSize Size of the file in number of bytes
|
||||||
|
@param[in] BlockSize Value of the TFTP blksize option
|
||||||
@param[out] Data Address where to store the address of the buffer
|
@param[out] Data Address where to store the address of the buffer
|
||||||
where the data of the file were downloaded in
|
where the data of the file were downloaded in
|
||||||
case of success.
|
case of success.
|
||||||
|
@ -860,6 +891,7 @@ DownloadFile (
|
||||||
IN CONST CHAR16 *FilePath,
|
IN CONST CHAR16 *FilePath,
|
||||||
IN CONST CHAR8 *AsciiFilePath,
|
IN CONST CHAR8 *AsciiFilePath,
|
||||||
IN UINTN FileSize,
|
IN UINTN FileSize,
|
||||||
|
IN UINT16 BlockSize,
|
||||||
OUT VOID **Data
|
OUT VOID **Data
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -868,6 +900,8 @@ DownloadFile (
|
||||||
VOID *Buffer;
|
VOID *Buffer;
|
||||||
DOWNLOAD_CONTEXT *TftpContext;
|
DOWNLOAD_CONTEXT *TftpContext;
|
||||||
EFI_MTFTP4_TOKEN Mtftp4Token;
|
EFI_MTFTP4_TOKEN Mtftp4Token;
|
||||||
|
EFI_MTFTP4_OPTION ReqOpt;
|
||||||
|
UINT8 OptBuf[10];
|
||||||
|
|
||||||
// Downloaded file can be large. BS.AllocatePages() is more faster
|
// Downloaded file can be large. BS.AllocatePages() is more faster
|
||||||
// than AllocatePool() and avoid fragmentation.
|
// than AllocatePool() and avoid fragmentation.
|
||||||
|
@ -900,6 +934,14 @@ DownloadFile (
|
||||||
Mtftp4Token.Buffer = Buffer;
|
Mtftp4Token.Buffer = Buffer;
|
||||||
Mtftp4Token.CheckPacket = CheckPacket;
|
Mtftp4Token.CheckPacket = CheckPacket;
|
||||||
Mtftp4Token.Context = (VOID*)TftpContext;
|
Mtftp4Token.Context = (VOID*)TftpContext;
|
||||||
|
if (BlockSize != MTFTP_DEFAULT_BLKSIZE) {
|
||||||
|
ReqOpt.OptionStr = "blksize";
|
||||||
|
AsciiSPrint (OptBuf, sizeof (OptBuf), "%d", BlockSize);
|
||||||
|
ReqOpt.ValueStr = OptBuf;
|
||||||
|
|
||||||
|
Mtftp4Token.OptionCount = 1;
|
||||||
|
Mtftp4Token.OptionList = &ReqOpt;
|
||||||
|
}
|
||||||
|
|
||||||
ShellPrintHiiEx (
|
ShellPrintHiiEx (
|
||||||
-1, -1, NULL, STRING_TOKEN (STR_TFTP_DOWNLOADING),
|
-1, -1, NULL, STRING_TOKEN (STR_TFTP_DOWNLOADING),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// /**
|
// /**
|
||||||
//
|
//
|
||||||
// (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
|
// (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
|
||||||
// Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved. <BR>
|
// Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved. <BR>
|
||||||
// This program and the accompanying materials
|
// This program and the accompanying materials
|
||||||
// are licensed and made available under the terms and conditions of the BSD License
|
// are licensed and made available under the terms and conditions of the BSD License
|
||||||
// which accompanies this distribution. The full text of the license may be found at
|
// which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
".SH SYNOPSIS\r\n"
|
".SH SYNOPSIS\r\n"
|
||||||
" \r\n"
|
" \r\n"
|
||||||
"TFTP [-i interface] [-l <port>] [-r <port>] [-c <retry count>] [-t <timeout>]\r\n"
|
"TFTP [-i interface] [-l <port>] [-r <port>] [-c <retry count>] [-t <timeout>]\r\n"
|
||||||
" host remotefilepath [localfilepath]\r\n"
|
" [-s <block size>] host remotefilepath [localfilepath]\r\n"
|
||||||
".SH OPTIONS\r\n"
|
".SH OPTIONS\r\n"
|
||||||
" \r\n"
|
" \r\n"
|
||||||
" -i interface - Specifies an adapter name, i.e., eth0.\r\n"
|
" -i interface - Specifies an adapter name, i.e., eth0.\r\n"
|
||||||
|
@ -61,6 +61,8 @@
|
||||||
" wait for a response. The default value is 6.\r\n"
|
" wait for a response. The default value is 6.\r\n"
|
||||||
" -t <timeout> - The number of seconds to wait for a response after\r\n"
|
" -t <timeout> - The number of seconds to wait for a response after\r\n"
|
||||||
" sending a request packet. Default value is 4s.\r\n"
|
" sending a request packet. Default value is 4s.\r\n"
|
||||||
|
" -s <block size> - Specifies the TFTP blksize option as defined in RFC 2348.\r\n"
|
||||||
|
" Valid range is between 8 and 65464, default value is 512.\r\n"
|
||||||
" host - Specify TFTP Server IPv4 address.\r\n"
|
" host - Specify TFTP Server IPv4 address.\r\n"
|
||||||
" remotefilepath - TFTP server file path to download the file.\r\n"
|
" remotefilepath - TFTP server file path to download the file.\r\n"
|
||||||
" localfilepath - Local destination file path.\r\n"
|
" localfilepath - Local destination file path.\r\n"
|
||||||
|
|
Loading…
Reference in New Issue