
Adds a "tftp" command that gets a specified file from a TFTP Server and stores it in RAM at a specified RAM address. Most of the code already exists in board-specific form (eg in board/hymod) but this patch extracts it and makes it available as a standard u-boot command.
Signed-off-by: Kevin Morfitt kevin.morfitt@fearnside-systems.co.uk --- common/cmd_tftp.c | 59 ++++++++++++++++++++++++++++++++++++++++++ doc/README.tftp | 29 ++++++++++++++++++++ include/config_cmd_all.h | 1 + include/config_cmd_default.h | 1 + 4 files changed, 90 insertions(+), 0 deletions(-) create mode 100755 common/cmd_tftp.c create mode 100755 doc/README.tftp
diff --git a/common/cmd_tftp.c b/common/cmd_tftp.c new file mode 100755 index 0000000..7aa5d0a --- /dev/null +++ b/common/cmd_tftp.c @@ -0,0 +1,59 @@ +/* + * (C) Copyright 2009 + * Kevin Morfitt, Fearnside Systems Ltd, kevin.morfitt@fearnside-systems.co.uk + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include <common.h> +#include <net.h> + +static int get_file_tftp(struct cmd_tbl_s *cmftp, int flag, int argc, + char *argv[]); + +U_BOOT_CMD( + tftp, 3, 0, get_file_tftp, + "tftp\t- Upload a file via TFTP", + "<address> <file name> - Upload <file name> to <address> via TFTP" +); + +static int get_file_tftp(struct cmd_tbl_s *cmftp, int flag, + int argc, char *argv[]) +{ + load_addr = simple_strtoul(argv[1], NULL, 16); + copy_filename(BootFile, argv[2], sizeof (BootFile)); + NetBootFileXferSize = 0; + + debug("TFTP: Filename: %s Address: 0x%08X\n", BootFile, + (unsigned int)load_addr); + + if (NetLoop (TFTP) <= 0) { + printf("ERROR: tftp transfer failed\n"); + return -1; + } + + if (NetBootFileXferSize == 0) { + printf("ERROR: Can't determine file size\n"); + return -1; + } + + printf("File transfer succeeded - file size %lu bytes\n", + NetBootFileXferSize); + return 0; +} diff --git a/doc/README.tftp b/doc/README.tftp new file mode 100755 index 0000000..d13603a --- /dev/null +++ b/doc/README.tftp @@ -0,0 +1,29 @@ +Get a file from a TFTP server +============================= + +Overview +-------- + +The "tftp" command allows a user retrieve a file from a TFTP server and store +it in RAM. The RAM load address and the filename are passed via the command +line and the TFTP server address is that defined by the "serverip" environment +variable. + +Enabling the command +-------------------- + +The command is enabled in the build by the CONFIG_CMD_TFTP macro: + +#define CONFIG_CMD_TFTP 1 + +Using the command +----------------- + +The format of the command is: + + tftp <address> <file name> + +where: + + <address> is the address of the RAM buffer used to receive the file + <file name> is the name of the file to be retrieved via tftp diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h index db1f55c..a7129d4 100644 --- a/include/config_cmd_all.h +++ b/include/config_cmd_all.h @@ -78,6 +78,7 @@ #define CONFIG_CMD_SNTP /* SNTP support */ #define CONFIG_CMD_SPI /* SPI utility */ #define CONFIG_CMD_TERMINAL /* built-in Serial Terminal */ +#define CONFIG_CMD_TFTP /* Get file via TFTP */ #define CONFIG_CMD_UNIVERSE /* Tundra Universe Support */ #define CONFIG_CMD_UNZIP /* unzip from memory to memory */ #define CONFIG_CMD_USB /* USB Support */ diff --git a/include/config_cmd_default.h b/include/config_cmd_default.h index 3667602..cee6a1c 100644 --- a/include/config_cmd_default.h +++ b/include/config_cmd_default.h @@ -37,6 +37,7 @@ #define CONFIG_CMD_NFS /* NFS support */ #define CONFIG_CMD_RUN /* run command in env variable */ #define CONFIG_CMD_SETGETDCR /* DCR support on 4xx */ +#define CONFIG_CMD_TFTP /* Get file via TFTP */ #define CONFIG_CMD_XIMG /* Load part of Multi Image */
#endif /* _CONFIG_CMD_DEFAULT_H */