Skip to contentSkip to conversation

Integrating TCP and wget into u-boot v7

PATCH Superseded DH at synoia.com 1 participant 1 message Mar 1, 2018 Networking

v1 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 Integrating TCP and wget into u-boot v7

From: Duncan Hare <[email protected]>

All the code is new, and not copied from any source.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

<<<<

Commit-notes

Routine tcp_print_buffer() is used to print portions of non zero terminated buffers. If there is an existing routine please let me know. I'm from the world of length fields not zero terminated strings (zOS).

TCP Prtocol stack,

Why TCP:

Currently u-boot 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 for every block of data.

In networks with large latency, for example: the internet, UDP is even slower. What is a 30 second transfer on a local boot server and LAN increase to over 3 minutes, because of all the requests/response traffic.

This was anticipated in the evolution of the IP protocols and TCP was developed and then enhanced for high latency high bandwidth networks.

The current standard is TCP with selective acknowledgment.

In our testing we have reduce kernel transmission time to around 0.4 seconds for a 4Mbyte kernel, with a 100 Mbps downlink.

END

---

Changes in v7:
Integrating TCP and wget into u-boot

 include/net.h |  31 ++-
 net/Kconfig   |  35 +--
 net/Makefile  |   2 +-
 net/net.c     |  89 +++++--
 net/ping.c    |   9 +-
 net/tcp.c     | 749 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/tcp.h     | 218 +++++++++++++++++
 7 files changed, 1071 insertions(+), 62 deletions(-)
 create mode 100644 net/tcp.c
 create mode 100644 net/tcp.h
include/net.h +24 -7
index 455b48f6c7..e29d804a23 100644
@@ -15,17 +15,26 @@
 #include <asm/cache.h>
 #include <asm/byteorder.h>	/* for nton* / ntoh* stuff */
 
-#define DEBUG_LL_STATE 0	/* Link local state machine changes */
-#define DEBUG_DEV_PKT 0		/* Packets or info directed to the device */
-#define DEBUG_NET_PKT 0		/* Packets on info on the network at large */
+#define DEBUG_LL_STATE  0	/* Link local state machine changes */
+#define DEBUG_DEV_PKT   0	/* Packets or info directed to the device */
+#define DEBUG_NET_PKT   0	/* Packets on info on the network at large */
 #define DEBUG_INT_STATE 0	/* Internal network state changes */
 
 /*
  *	The number of receive packet buffers, and the required packet buffer
  *	alignment in memory.
  *
+ *	The number of buffers for TCP is used to calculate a static TCP window
+ *	size, becuse TCP window size is a promise to the sending TCP to be able
+ *	to buffer up to the window size of data.
+ *	When the sending TCP has a window size of outstanding unacknowledged
+ *	data, the sending TCP will stop sending.
  */
 
+#if defined(CONFIG_TCP)
+#define CONFIG_SYS_RX_ETH_BUFFER 12	/* For TCP */
+#endif
+
 #ifdef CONFIG_SYS_RX_ETH_BUFFER
 # define PKTBUFSRX	CONFIG_SYS_RX_ETH_BUFFER
 #else
@@ -354,6 +363,7 @@ struct vlan_ethernet_hdr {
 
 #define IPPROTO_ICMP	 1	/* Internet Control Message Protocol	*/
 #define IPPROTO_UDP	17	/* User Datagram Protocol		*/
+#define IPPROTO_TCP	 6	/* Transmission Control Protocol        */
 
 /*
  *	Internet Protocol (IP) header.
@@ -538,7 +548,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
+	TFTPSRV, TFTPPUT, LINKLOCAL, WGET
 };
 
 extern char	net_boot_file_name[1024];/* Boot File name */
@@ -596,10 +606,10 @@ int net_set_ether(uchar *xet, const uchar *dest_ethaddr, uint prot);
 int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot);
 
 /* Set IP header */
-void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source);
+void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source,
+		       u16  pkt_len, u8 prot);
 void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport,
-				int sport, int len);
-
+			int sport, int len);
 /**
  * compute_ip_checksum() - Compute IP checksum
  *
@@ -670,9 +680,16 @@ static inline void net_send_packet(uchar *pkt, int len)
  * @param sport Source UDP port
  * @param payload_len Length of data after the UDP header
  */
+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_udp_packet(uchar *ether, struct in_addr dest, int dport,
 			int sport, int payload_len);
 
+int net_send_tcp_packet(int payload_len, int dport, int sport, u8 action,
+			u32 tcp_seq_num, u32 tcp_ack_num);
+
 /* Processes a received packet */
 void net_process_received_packet(uchar *in_packet, int len);
 
net/Kconfig +6 -29
index 143c4416cd..895b93dea9 100644
@@ -4,12 +4,12 @@
 
 menuconfig NET
 	bool "Networking support"
-	default y
 
 if NET
 
 config NET_RANDOM_ETHADDR
 	bool "Random ethaddr if unset"
+	select LIB_RAND
 	help
 	  Selecting this will allow the Ethernet interface to function
 	  even when the ethaddr variable for that interface is unset.
@@ -24,7 +24,6 @@ config NETCONSOLE
 
 config NET_TFTP_VARS
 	bool "Control TFTP timeout and count through environment"
-	depends on CMD_NET
 	default y
 	help
 	  If set, allows controlling the TFTP timeout through the
@@ -33,44 +32,22 @@ config NET_TFTP_VARS
 	  If unset, timeout and maximum are hard-defined as 1 second
 	  and 10 timouts per TFTP transfer.
 
-config BOOTP_BOOTPATH
-	bool "Enable BOOTP BOOTPATH"
-	depends on CMD_NET
-
-config BOOTP_DNS
-	bool "Enable bootp DNS"
-	depends on CMD_NET
-
-config BOOTP_GATEWAY
-	bool "Enable BOOTP gateway"
-	depends on CMD_NET
-
-config BOOTP_HOSTNAME
-	bool "Enable BOOTP hostname"
-	depends on CMD_NET
-
-config BOOTP_PXE
-	bool "Enable BOOTP PXE"
-	depends on CMD_NET
-
-config BOOTP_SUBNETMASK
-	bool "Enable BOOTP subnetmask"
-	depends on CMD_NET
-	depends on CMD_NET
-
 config BOOTP_PXE_CLIENTARCH
 	hex
-	depends on CMD_NET
         default 0x16 if ARM64
         default 0x15 if ARM
         default 0 if X86
 
 config BOOTP_VCI_STRING
 	string
-	depends on CMD_NET
 	default "U-Boot.armv7" if CPU_V7 || CPU_V7M
 	default "U-Boot.armv8" if ARM64
 	default "U-Boot.arm" if ARM
 	default "U-Boot"
 
+config TCP
+	bool "Include TCP for receiving files"
+	help
+	  TCP support for receiving files.
+
 endif   # if NET
net/Makefile +1 -1
index ae54eee5af..25729ebeeb 100644
@@ -25,7 +25,7 @@ obj-$(CONFIG_CMD_PING) += ping.o
 obj-$(CONFIG_CMD_RARP) += rarp.o
 obj-$(CONFIG_CMD_SNTP) += sntp.o
 obj-$(CONFIG_CMD_NET)  += tftp.o
-
+obj-$(CONFIG_TCP)      += tcp.o
 # Disable this warning as it is triggered by:
 # sprintf(buf, index ? "foo%d" : "foo", index)
 # and this is intentional usage.
net/net.c +71 -18

171 lines not on this page · raw message

net/ping.c +2 -7
index 9508cf1160..254b646193 100644
@@ -20,16 +20,11 @@ struct in_addr net_ping_ip;
 static void set_icmp_header(uchar *pkt, struct in_addr dest)
 {
 	/*
-	 *	Construct an IP and ICMP header.
+	 *	Construct an ICMP header.
 	 */
-	struct ip_hdr *ip = (struct ip_hdr *)pkt;
 	struct icmp_hdr *icmp = (struct icmp_hdr *)(pkt + IP_HDR_SIZE);
 
-	net_set_ip_header(pkt, dest, net_ip);
-
-	ip->ip_len   = htons(IP_ICMP_HDR_SIZE);
-	ip->ip_p     = IPPROTO_ICMP;
-	ip->ip_sum   = compute_ip_checksum(ip, IP_HDR_SIZE);
+	net_set_ip_header(pkt, dest, net_ip, IP_ICMP_HDR_SIZE, IPPROTO_ICMP);
 
 	icmp->type = ICMP_ECHO_REQUEST;
 	icmp->code = 0;
net/tcp.c new file +749 -0

749 lines not on this page · raw message

net/tcp.h new file +218 -0

218 lines not on this page · raw message

Signature · 1 line
2.11.0