Skip to contentSkip to conversation

TCP and wget implementation. Patch V5, 3 of 3.

PATCH New DH at synoia.com 2 participants 2 messages Jan 29, 2018 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 TCP and wget implementation. Patch V5, 3 of 3.

From: Duncan Hare <[email protected]>

This is the wget, tftp and Kconfig files for introducing TCP and wget into u-boot.

tftp.c was enhanced to check a downloaded kernel by being able to compile it as a verification tool. The switch detween download program and tool is by c #define directive in tftp.c. Should this directive be configured by Kconfig?

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

---

 cmd/Kconfig |   6 +
 cmd/net.c   |  13 ++
 net/tftp.c  |  35 ++++-
 net/wget.c  | 417 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/wget.h  |  22 ++++
 5 files changed, 487 insertions(+), 6 deletions(-)
 create mode 100644 net/wget.c
 create mode 100644 net/wget.h
cmd/Kconfig +6 -0
index 5a6afab99b..46b489a966 100644
@@ -1035,6 +1035,12 @@ config CMD_ETHSW
 	  operations such as enabling / disabling a port and
 	  viewing/maintaining the filtering database (FDB)
 
+config CMD_WGET
+	bool "wget"
+	select TCP
+	help
+	  Download a kernel, or other files, from a web server over TCP.
+
 endmenu
 
 menu "Misc commands"
cmd/net.c +13 -0
index d7c776aacf..f5c2d0f8ed 100644
@@ -110,6 +110,19 @@ U_BOOT_CMD(
 );
 #endif
 
+#if defined(CONFIG_CMD_WGET)
+static int do_wget(cmd_tbl_t *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:]bootfilename]"
+);
+#endif
+
 static void netboot_update_env(void)
 {
 	char tmp[22];
net/tftp.c +29 -6
index 6671b1f7ca..c3f8fd3053 100644
@@ -6,6 +6,9 @@
  *                Luca Ceresoli <[email protected]>
  */
 
+/* define if kernel load or verify kernal from a previous load */
+#define K_LOAD 1
+
 #include <common.h>
 #include <command.h>
 #include <efi_loader.h>
@@ -16,6 +19,9 @@
 #ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
 #include <flash.h>
 #endif
+#ifndef K_LOAD
+#include "tcp.h"
+#endif
 
 /* Well known TFTP port # */
 #define WELL_KNOWN_PORT	69
@@ -29,7 +35,6 @@
 #endif
 /* Number of "loading" hashes per line (for checking the image size) */
 #define HASHES_PER_LINE	65
-
 /*
  *	TFTP operations.
  */
@@ -166,7 +171,7 @@ static void mcast_cleanup(void)
 
 static inline void store_block(int block, uchar *src, unsigned len)
 {
-	ulong offset = block * tftp_block_size + tftp_block_wrap_offset;
+	uint offset = block * tftp_block_size + tftp_block_wrap_offset;
 	ulong newsize = offset + len;
 #ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
 	int i, rc = 0;
@@ -188,14 +193,29 @@ static inline void store_block(int block, uchar *src, unsigned len)
 			net_set_state(NETLOOP_FAIL);
 			return;
 		}
-	} else
+	} else {
 #endif /* CONFIG_SYS_DIRECT_FLASH_TFTP */
-	{
-		void *ptr = map_sysmem(load_addr + offset, len);
 
+		void *ptr = map_sysmem(load_addr + offset, len);
+#ifdef K_LOAD
 		memcpy(ptr, src, len);
+#endif
+#ifndef K_LOAD
+		if (memcmp(ptr, src, len) != 0) {
+			debug_cond(1,
+				   "File Xfer Mismatch, offset=%d, error=%d\n",
+				   offset, memcmp(ptr, src, len));
+			printf("TFTP Download Verification - Memory\n");
+			tcp_print_buffer(ptr, len, len, -1, 0);
+			printf("TFTP Download Verification - Packet\n");
+			tcp_print_buffer(src, len, len, -1, 0);
+			net_set_state(NETLOOP_FAIL);
+		}
+#endif
 		unmap_sysmem(ptr);
+#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
 	}
+#endif
 #ifdef CONFIG_MCAST_TFTP
 	if (tftp_mcast_active)
 		ext2_set_bit(block, tftp_mcast_bitmap);
@@ -761,6 +781,7 @@ void tftp_start(enum proto_t protocol)
 	}
 
 	printf("Using %s device\n", eth_get_name());
+
 	printf("TFTP %s server %pI4; our IP address is %pI4",
 #ifdef CONFIG_CMD_TFTPPUT
 	       protocol == TFTPPUT ? "to" : "from",
@@ -780,7 +801,9 @@ void tftp_start(enum proto_t protocol)
 			printf("; sending through gateway %pI4", &net_gateway);
 	}
 	putc('\n');
-
+#ifndef K_LOAD
+	printf("TFTP Download Verification\n");
+#endif
 	printf("Filename '%s'.", tftp_filename);
 
 	if (net_boot_file_expected_size_in_blocks) {
net/wget.c new file +417 -0

417 lines not on this page · raw message

net/wget.h new file +22 -0
new file mode 100644
index 0000000000..504943d9c8
@@ -0,0 +1,22 @@
+/*
+ * Duncan Hare Copyright 2017
+ */
+
+void wget_start(void);			/* Begin wget */
+
+enum FILE_STATE {
+	FILE_CLOSED,
+	FILE_CONNECTING,
+	FILE_CONNECTED,
+	FILE_TRANSFERRING,
+	FILE_TRANSFERRED};
+
+#define K_LOAD			1	/* Load and run kernel */
+
+#define	FILE_TEST		0	/* Set to 1 for debug messges */
+#define	SERVER_PORT		80
+#define	FILE_RETRY_COUNT	30
+#define	FILE_TIMEOUT		2000UL
+
+void file_fail(char *error_message, unsigned int tcp_seq_num,
+	       unsigned int tcp_ack_num, u8 action);
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/1 TCP and wget implementation. Patch V5, 3 of 3.

Hi Duncan Hare,

Quoted 9 lines

-----Original Message-----
From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of DH at synoia.com
Sent: Monday, January 29, 2018 9:24 AM
To: DuncanCHare at yahoo.com
Cc: u-boot at lists.denx.de; Joe Hershberger <[email protected]>; Maxime Ripard <[email protected]>; Jagan Teki <[email protected]>
Subject: [U-Boot] [PATCH] TCP and wget implementation. Patch V5, 3 of 3.

I guess you are manually adding the patch version and number. If so, I would suggest to use the following command, to allow git to prefix "PATCH v5" tag to the series and to prepare a cover letter.

git format-patch --subject-prefix="PATCH v5" -3 --cover-letter

While using git send-email command the following command can be used:

git send-email --to=u-boot at linux.freescale.net *.patch

Refer:- https://www.denx.de/wiki/U-Boot/Patches

Patman is a nice tool for all this.

http://git.denx.de/?p=u-boot.git;a=blob;f=tools/patman/README

regards
Calvin