Skip to contentSkip to conversation

add TCP and HTTP for downloading images

PATCH Superseded Ying-Chun Liu 2 participants 4 messages Mar 16, 2022 – Mar 20, 2022

Subsystems (2)

v13 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v13 cover add TCP and HTTP for downloading images

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

This patch is a refresh from previous patches made by Duncan Hare <[email protected]>. I've contacted him and continue to work on this patch.

This patch introduce a TCP stack with SACK. And a simple wget command to download images from http server.

v13: Fix some issues which is reviewed by Christian

Ying-Chun Liu (PaulLiu) (2):
net: Add TCP protocol
net: Add wget application

 cmd/Kconfig        |   7 +
 cmd/net.c          |  13 +
 include/net.h      |  13 +-
 include/net/tcp.h  | 222 ++++++++++++++
 include/net/wget.h |  19 ++
 net/Kconfig        |   6 +
 net/Makefile       |   2 +
 net/net.c          |  36 +++
 net/tcp.c          | 698 +++++++++++++++++++++++++++++++++++++++++++++
 net/wget.c         | 436 ++++++++++++++++++++++++++++
 10 files changed, 1450 insertions(+), 2 deletions(-)
 create mode 100644 include/net/tcp.h
 create mode 100644 include/net/wget.h
 create mode 100644 net/tcp.c
 create mode 100644 net/wget.c
Signature · 1 line
2.35.1
#1 lore raw

PATCH v13 1/2 net: Add TCP protocol

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

Currently file transfers are done using tftp or NFS both over udp. This requires a request to be sent from client (u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

---
v13: Fix some issues which is reviewed by Christian

---
 include/net.h     |  11 +-
 include/net/tcp.h | 222 +++++++++++++++
 net/Kconfig       |   6 +
 net/Makefile      |   1 +
 net/net.c         |  30 ++
 net/tcp.c         | 698 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 967 insertions(+), 1 deletion(-)
 create mode 100644 include/net/tcp.h
 create mode 100644 net/tcp.c
include/net.h +10 -1
index b02e4f630c..03f3271dcb 100644
@@ -36,6 +36,9 @@ struct udevice;
  *
  */
 
+#if defined(CONFIG_PROT_TCP)	/* Protected UDP uses less bufferes than TCP */
+#define CONFIG_SYS_RX_ETH_BUFFER 12
+#endif
 #ifdef CONFIG_SYS_RX_ETH_BUFFER
 # define PKTBUFSRX	CONFIG_SYS_RX_ETH_BUFFER
 #else
@@ -371,6 +374,7 @@ struct vlan_ethernet_hdr {
 #define PROT_NCSI	0x88f8		/* NC-SI control packets        */
 
 #define IPPROTO_ICMP	 1	/* Internet Control Message Protocol	*/
+#define IPPROTO_TCP	 6	/* Transmission Control Protocol	*/
 #define IPPROTO_UDP	17	/* User Datagram Protocol		*/
 
 /*
@@ -693,7 +697,7 @@ static inline void net_send_packet(uchar *pkt, int len)
 }
 
 /*
- * Transmit "net_tx_packet" as UDP packet, performing ARP request if needed
+ * Transmit "net_tx_packet" as UDP or TCP packet, send ARP request if needed
  *  (ether will be populated)
  *
  * @param ether Raw packet buffer
@@ -701,10 +705,15 @@ static inline void net_send_packet(uchar *pkt, int len)
  * @param dport Destination UDP port
  * @param sport Source UDP port
  * @param payload_len Length of data after the UDP header
+ * @param action TCP action to be performed
+ * @param tcp_seq_num TCP sequence number of this transmission
+ * @param tcp_ack_num TCP stream acknolegement number
  */
 int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport,
 		       int payload_len, int proto, u8 action, u32 tcp_seq_num,
 		       u32 tcp_ack_num);
+int net_send_tcp_packet(int payload_len, int dport, int sport, u8 action,
+			u32 tcp_seq_num, u32 tcp_ack_num);
 int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport,
 			int sport, int payload_len);
 
include/net/tcp.h new file +222 -0

222 lines not on this page · raw message

net/Kconfig +6 -0
index 2ae9d6a020..d927c9defa 100644
@@ -123,4 +123,10 @@ config BOOTP_SERVERIP
 	  variable, not the BOOTP server. This affects the operation of both
 	  bootp and tftp.
 
+config PROT_TCP
+	bool "TCP stack"
+	help
+	  TCP protocol support with SACK. Selecting this will provide the
+	  fastest file transfer possible.
+
 endif   # if NET
net/Makefile +1 -0
index fb3eba840f..f68ad94767 100644
@@ -29,6 +29,7 @@ obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
 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
 
 # Disable this warning as it is triggered by:
 # sprintf(buf, index ? "foo%d" : "foo", index)
net/net.c +30 -0
index 072a82d8f9..28d9fbd227 100644
@@ -116,6 +116,7 @@
 #if defined(CONFIG_CMD_WOL)
 #include "wol.h"
 #endif
+#include <net/tcp.h>
 
 /** BOOTP EXTENTIONS **/
 
@@ -386,6 +387,8 @@ int net_init(void)
 
 		/* Only need to setup buffer pointers once. */
 		first_call = 0;
+		if (IS_ENABLED(CONFIG_PROT_TCP))
+			tcp_set_tcp_state(TCP_CLOSED);
 	}
 
 	return net_init_loop();
@@ -816,6 +819,16 @@ int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, int sport,
 				  IPPROTO_UDP, 0, 0, 0);
 }
 
+#if defined(CONFIG_PROT_TCP)
+int net_send_tcp_packet(int payload_len, int dport, int sport, u8 action,
+			u32 tcp_seq_num, u32 tcp_ack_num)
+{
+	return net_send_ip_packet(net_server_ethaddr, net_server_ip, dport,
+				  sport, payload_len, IPPROTO_TCP, action,
+				  tcp_seq_num, tcp_ack_num);
+}
+#endif
+
 int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport,
 		       int payload_len, int proto, u8 action, u32 tcp_seq_num,
 		       u32 tcp_ack_num)
@@ -847,6 +860,14 @@ int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport,
 				   payload_len);
 		pkt_hdr_size = eth_hdr_size + IP_UDP_HDR_SIZE;
 		break;
+#if defined(CONFIG_PROT_TCP)
+	case IPPROTO_TCP:
+		pkt_hdr_size = eth_hdr_size +
+		tcp_set_tcp_header(pkt + eth_hdr_size, dport, sport,
+				   payload_len, action, tcp_seq_num,
+				   tcp_ack_num);
+	break;
+#endif
 	default:
 		return -EINVAL;
 	}
@@ -1253,6 +1274,15 @@ void net_process_received_packet(uchar *in_packet, int len)
 		if (ip->ip_p == IPPROTO_ICMP) {
 			receive_icmp(ip, len, src_ip, et);
 			return;
+#if defined(CONFIG_PROT_TCP)
+		} else if (ip->ip_p == IPPROTO_TCP) {
+			debug_cond(DEBUG_DEV_PKT,
+				   "TCP PH (to=%pI4, from=%pI4, len=%d)\n",
+				   &dst_ip, &src_ip, len);
+
+			rxhand_tcp_f((union tcp_build_pkt *)ip, len);
+			return;
+#endif
 		} else if (ip->ip_p != IPPROTO_UDP) {	/* Only UDP packets */
 			return;
 		}
net/tcp.c new file +698 -0

698 lines not on this page · raw message

Signature · 1 line
2.35.1
#2 lore raw

Re: [PATCH v13 1/2] net: Add TCP protocol

Quoted 15 lines · Ying-Chun Liu

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

Currently file transfers are done using tftp or NFS both over udp. This requires a request to be sent from client (u-boot) to the boot server.

The current standard is TCP with selective acknowledgment.

Quoted 3 lines

---
v13: Fix some issues which is reviewed by Christian
---

Hi Ying,
You woke up an old can, Can you elaborate on the changes you did to the original patchset ?
I'm reviewing this instead of Joe, so I want to get some context.

I would appreciate it if you could separate the SACK support to a separate patch, preferably option based.
The TCP stack is complicated enough and will require a lot of tinkering / bug fixing in the future. It's best if we could turn on/off specific RFC which are not originally part of the TCP protocol.

Thanks,
Ramon

#3 lore raw

PATCH v13 2/2 net: Add wget application

In reply to Ying-Chun Liu

From: "Ying-Chun Liu (PaulLiu)" <[email protected]>

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

Cc Christian Gmeiner <[email protected]>
Cc Joe Hershberger <[email protected]>
Cc Ramon Fried <[email protected]>

---
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
cmd/Kconfig +7 -0
index 5e25e45fd2..5c4aec7fd5 100644
@@ -1613,6 +1613,13 @@ config CMD_NFS
 	help
 	  Boot image via network using NFS protocol.
 
+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
cmd/net.c +13 -0
index 3619c843d8..60fd785061 100644
@@ -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];
include/net.h +1 -1
index 03f3271dcb..9ce85eccb8 100644
@@ -566,7 +566,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 */
include/net/wget.h new file +19 -0
new file mode 100644
index 0000000000..61bdd851f9
@@ -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
+};
+
+#define	DEBUG_WGET		0	/* Set to 1 for debug messges */
+#define	SERVER_PORT		80
+#define	WGET_RETRY_COUNT	30
+#define	WGET_TIMEOUT		2000UL
net/Makefile +1 -0
index f68ad94767..54ef337e80 100644
@@ -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)
net/net.c +6 -0
index 28d9fbd227..5044c42add 100644
@@ -117,6 +117,7 @@
 #include "wol.h"
 #endif
 #include <net/tcp.h>
+#include <net/wget.h>
 
 /** 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();
net/wget.c new file +436 -0

436 lines not on this page · raw message

Signature · 1 line
2.35.1