Re: [PATCH v14 2/2] net: Add wget application

2022-05-18 Thread Michal Simek




On 4/21/22 18:54, Ying-Chun Liu wrote:

From: "Ying-Chun Liu (PaulLiu)" 

This commit adds a simple wget command that can download files
from http server.


I think description can be much bigger. I was running just wget and it did 
something.




Signed-off-by: Duncan Hare 
Signed-off-by: Ying-Chun Liu (PaulLiu) 
Cc: Christian Gmeiner 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
v13: Fix some issues which is reviewed by Christian
---
  cmd/Kconfig|   7 +
  cmd/net.c  |  13 ++
  include/net.h  |   2 +-
  include/net/wget.h |  19 ++
  net/Makefile   |   1 +
  net/net.c  |   6 +
  net/wget.c | 436 +
  7 files changed, 483 insertions(+), 1 deletion(-)
  create mode 100644 include/net/wget.h
  create mode 100644 net/wget.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index d3abe3a06b..6eff068feb 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1667,6 +1667,13 @@ config NFS_TIMEOUT
  "ERROR: Cannot umount" in nfs command, try longer timeout such as
  1.
  
+config CMD_WGET

+   bool "wget"
+   select TCP
+   help
+ Download kernel, or other files, from a web server over TCP.
+ Fast file transfer over networks with latenc


latenc?



+
  config CMD_MII
bool "mii"
imply CMD_MDIO
diff --git a/cmd/net.c b/cmd/net.c
index 3619c843d8..60fd785061 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -124,6 +124,19 @@ U_BOOT_CMD(
  );
  #endif
  
+#if defined(CONFIG_CMD_WGET)

+static int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const 
argv[])
+{
+   return netboot_common(WGET, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+   wget,   3,  1,  do_wget,
+   "boot image via network using HTTP protocol",
+   "[loadAddress] [[hostIPaddr:]path and image name]"
+);
+#endif
+
  static void netboot_update_env(void)
  {
char tmp[22];
diff --git a/include/net.h b/include/net.h
index 220eba2e21..3553f17a8e 100644
--- a/include/net.h
+++ b/include/net.h
@@ -557,7 +557,7 @@ extern int  net_restart_wrap;   /* Tried all 
network devices */
  
  enum proto_t {

BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
-   TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP
+   TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, WGET
  };
  
  extern char	net_boot_file_name[1024];/* Boot File name */

diff --git a/include/net/wget.h b/include/net/wget.h
new file mode 100644
index 00..61bdd851f9
--- /dev/null
+++ b/include/net/wget.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Duncan Hare Copyright 2017
+ */
+
+void wget_start(void); /* Begin wget */


comment on previous line.


+
+enum WGET_STATE {
+   WGET_CLOSED,
+   WGET_CONNECTING,
+   WGET_CONNECTED,
+   WGET_TRANSFERRING,
+   WGET_TRANSFERRED
+};


Please initialize them.



+
+#defineDEBUG_WGET  0   /* Set to 1 for debug messges */


comment has typo there.



+#defineSERVER_PORT 80
+#defineWGET_RETRY_COUNT30
+#defineWGET_TIMEOUT2000UL


fix that indenatation.


diff --git a/net/Makefile b/net/Makefile
index f68ad94767..54ef337e80 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_UDP_FUNCTION_FASTBOOT)  += fastboot.o
  obj-$(CONFIG_CMD_WOL)  += wol.o
  obj-$(CONFIG_PROT_UDP) += udp.o
  obj-$(CONFIG_PROT_TCP) += tcp.o
+obj-$(CONFIG_CMD_WGET) += wget.o
  
  # Disable this warning as it is triggered by:

  # sprintf(buf, index ? "foo%d" : "foo", index)
diff --git a/net/net.c b/net/net.c
index 28d9fbd227..5044c42add 100644
--- a/net/net.c
+++ b/net/net.c
@@ -117,6 +117,7 @@
  #include "wol.h"
  #endif
  #include 
+#include 
  
  /** BOOTP EXTENTIONS **/
  
@@ -505,6 +506,11 @@ restart:

nfs_start();
break;
  #endif
+#if defined(CONFIG_CMD_WGET)
+   case WGET:
+   wget_start();
+   break;
+#endif
  #if defined(CONFIG_CMD_CDP)
case CDP:
cdp_start();
diff --git a/net/wget.c b/net/wget.c
new file mode 100644
index 00..e3d1c8cc28
--- /dev/null
+++ b/net/wget.c
@@ -0,0 +1,436 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * WGET/HTTP support driver based on U-BOOT's nfs.c
+ * Copyright Duncan Hare  2017
+ */
+
+#include 
+#include 
+#include 
+#include 


please sort it.



+#include 
+#include 
+#include 
+#include 
+
+static const char bootfile1[]   = "GET ";
+static const char bootfile3[]   = " HTTP/1.0\r\n\r\n";
+static const char http_eom[] = "\r\n\r\n";
+static const char http_ok[]  = "200";
+static const char content_len[]  = "Content-Length";
+static const char linefeed[] = "\r\n";


fix indentation


+static struct in_addr web_server_ip;
+static int our_port;
+static int wget_timeout_count;
+
+struct pkt_qd {
+   uchar *pkt;
+   unsigned int 

[PATCH v14 2/2] net: Add wget application

2022-04-21 Thread Ying-Chun Liu
From: "Ying-Chun Liu (PaulLiu)" 

This commit adds a simple wget command that can download files
from http server.

Signed-off-by: Duncan Hare 
Signed-off-by: Ying-Chun Liu (PaulLiu) 
Cc: Christian Gmeiner 
Cc: Joe Hershberger 
Cc: Ramon Fried 
---
v13: Fix some issues which is reviewed by Christian
---
 cmd/Kconfig|   7 +
 cmd/net.c  |  13 ++
 include/net.h  |   2 +-
 include/net/wget.h |  19 ++
 net/Makefile   |   1 +
 net/net.c  |   6 +
 net/wget.c | 436 +
 7 files changed, 483 insertions(+), 1 deletion(-)
 create mode 100644 include/net/wget.h
 create mode 100644 net/wget.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index d3abe3a06b..6eff068feb 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1667,6 +1667,13 @@ config NFS_TIMEOUT
  "ERROR: Cannot umount" in nfs command, try longer timeout such as
  1.
 
+config CMD_WGET
+   bool "wget"
+   select TCP
+   help
+ Download kernel, or other files, from a web server over TCP.
+ Fast file transfer over networks with latenc
+
 config CMD_MII
bool "mii"
imply CMD_MDIO
diff --git a/cmd/net.c b/cmd/net.c
index 3619c843d8..60fd785061 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -124,6 +124,19 @@ U_BOOT_CMD(
 );
 #endif
 
+#if defined(CONFIG_CMD_WGET)
+static int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const 
argv[])
+{
+   return netboot_common(WGET, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+   wget,   3,  1,  do_wget,
+   "boot image via network using HTTP protocol",
+   "[loadAddress] [[hostIPaddr:]path and image name]"
+);
+#endif
+
 static void netboot_update_env(void)
 {
char tmp[22];
diff --git a/include/net.h b/include/net.h
index 220eba2e21..3553f17a8e 100644
--- a/include/net.h
+++ b/include/net.h
@@ -557,7 +557,7 @@ extern int  net_restart_wrap;   /* Tried all 
network devices */
 
 enum proto_t {
BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
-   TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP
+   TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT, WOL, UDP, WGET
 };
 
 extern charnet_boot_file_name[1024];/* Boot File name */
diff --git a/include/net/wget.h b/include/net/wget.h
new file mode 100644
index 00..61bdd851f9
--- /dev/null
+++ b/include/net/wget.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Duncan Hare Copyright 2017
+ */
+
+void wget_start(void); /* Begin wget */
+
+enum WGET_STATE {
+   WGET_CLOSED,
+   WGET_CONNECTING,
+   WGET_CONNECTED,
+   WGET_TRANSFERRING,
+   WGET_TRANSFERRED
+};
+
+#defineDEBUG_WGET  0   /* Set to 1 for debug messges */
+#defineSERVER_PORT 80
+#defineWGET_RETRY_COUNT30
+#defineWGET_TIMEOUT2000UL
diff --git a/net/Makefile b/net/Makefile
index f68ad94767..54ef337e80 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -30,6 +30,7 @@ obj-$(CONFIG_UDP_FUNCTION_FASTBOOT)  += fastboot.o
 obj-$(CONFIG_CMD_WOL)  += wol.o
 obj-$(CONFIG_PROT_UDP) += udp.o
 obj-$(CONFIG_PROT_TCP) += tcp.o
+obj-$(CONFIG_CMD_WGET) += wget.o
 
 # Disable this warning as it is triggered by:
 # sprintf(buf, index ? "foo%d" : "foo", index)
diff --git a/net/net.c b/net/net.c
index 28d9fbd227..5044c42add 100644
--- a/net/net.c
+++ b/net/net.c
@@ -117,6 +117,7 @@
 #include "wol.h"
 #endif
 #include 
+#include 
 
 /** BOOTP EXTENTIONS **/
 
@@ -505,6 +506,11 @@ restart:
nfs_start();
break;
 #endif
+#if defined(CONFIG_CMD_WGET)
+   case WGET:
+   wget_start();
+   break;
+#endif
 #if defined(CONFIG_CMD_CDP)
case CDP:
cdp_start();
diff --git a/net/wget.c b/net/wget.c
new file mode 100644
index 00..e3d1c8cc28
--- /dev/null
+++ b/net/wget.c
@@ -0,0 +1,436 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * WGET/HTTP support driver based on U-BOOT's nfs.c
+ * Copyright Duncan Hare  2017
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const char bootfile1[]   = "GET ";
+static const char bootfile3[]   = " HTTP/1.0\r\n\r\n";
+static const char http_eom[] = "\r\n\r\n";
+static const char http_ok[]  = "200";
+static const char content_len[]  = "Content-Length";
+static const char linefeed[] = "\r\n";
+static struct in_addr web_server_ip;
+static int our_port;
+static int wget_timeout_count;
+
+struct pkt_qd {
+   uchar *pkt;
+   unsigned int tcp_seq_num;
+   unsigned int len;
+};
+
+/*
+ * This is a control structure for out of order packets received.
+ * The actual packet bufers are in the kernel space, and are
+ * expected to be overwritten by the downloaded image.
+ */
+
+static struct pkt_qd pkt_q[PKTBUFSRX / 4];
+static int pkt_q_idx;
+static unsigned long content_length;