public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: kevin.morfitt at fearnside-systems.co.uk <kevin.morfitt@fearnside-systems.co.uk>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Added a tftp command
Date: Tue, 31 Mar 2009 23:44:21 +0100	[thread overview]
Message-ID: <49D29CC5.2010406@fearnside-systems.co.uk> (raw)

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 */
-- 
1.6.0.6

             reply	other threads:[~2009-03-31 22:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-31 22:44 kevin.morfitt at fearnside-systems.co.uk [this message]
2009-03-31 23:01 ` [U-Boot] [PATCH] Added a tftp command Mike Frysinger
2009-03-31 23:40   ` kevin.morfitt at fearnside-systems.co.uk
2009-03-31 23:48     ` Mike Frysinger
2009-04-01  4:39       ` Ben Warren
2009-03-31 23:20 ` Kumar Gala
2009-03-31 23:47   ` kevin.morfitt at fearnside-systems.co.uk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49D29CC5.2010406@fearnside-systems.co.uk \
    --to=kevin.morfitt@fearnside-systems.co.uk \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox