Skip to contentSkip to conversation

TFTP: add host ip addr support

PATCH New Jean-Christophe PLAGNIOL-VILLARD 5 participants 27 messages Jan 11, 2008 – Feb 4, 2008 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 TFTP: add host ip addr support

allow to use a different server as set in serverip

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 
 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +15 -7
index 8b95bcf..9d87e2c 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 
-
+static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
 static int	TftpTimeoutCount;
@@ -55,7 +55,7 @@ static int	TftpState;
 
 #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+static char tftp_filename[2048];
 
 #ifdef CFG_DIRECT_FLASH_TFTP
 extern flash_info_t flash_info[];
@@ -231,7 +231,7 @@ TftpSend (void)
 		break;
 	}
 
-	NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort, TftpOurPort, len);
+	NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, TftpOurPort, len);
 }
 
 
@@ -453,30 +453,38 @@ TftpStart (void)
 	char *ep;             /* Environment pointer */
 #endif
 
+	TftpServerIP = NetServerIP;
 	if (BootFile[0] == '\0') {
 		sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
 			(NetOurIP >> 24) & 0xFF	);
-		tftp_filename = default_filename;
+		strcpy (tftp_filename, default_filename);
 
 		printf ("*** Warning: no boot file name; using '%s'\n",
 			tftp_filename);
 	} else {
-		tftp_filename = BootFile;
+		char *p=BootFile;
+		p = strchr (p, ':');
+		if (p != NULL) {
+			TftpServerIP = string_to_ip (BootFile);
+			++p;
+			strcpy (tftp_filename, p);
+		} else 
+			strcpy (tftp_filename, BootFile);
 	}
 
 #if defined(CONFIG_NET_MULTI)
 	printf ("Using %s device\n", eth_get_name());
 #endif
-	puts ("TFTP from server ");	print_IPaddr (NetServerIP);
+	puts ("TFTP from server ");	print_IPaddr (TftpServerIP);
 	puts ("; our IP address is ");	print_IPaddr (NetOurIP);
 
 	/* Check if we need to send across this subnet */
 	if (NetOurGatewayIP && NetOurSubnetMask) {
 	    IPaddr_t OurNet 	= NetOurIP    & NetOurSubnetMask;
-	    IPaddr_t ServerNet 	= NetServerIP & NetOurSubnetMask;
+	    IPaddr_t ServerNet 	= TftpServerIP & NetOurSubnetMask;
 
 	    if (OurNet != ServerNet) {
 		puts ("; sending through gateway ");
Signature · 1 line
1.5.3.7
#2 lore raw

PATCH 1/1 TFTP: add host ip addr support

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 31 lines · Jean-Christophe PLAGNIOL-VILLARD

allow to use a different server as set in serverip

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 
 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +1 -1
index 8b95bcf..9d87e2c 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 
-
+static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
 static int	TftpTimeoutCount;

net/tftp.c static int TftpState; · line 59

Quoted 6 lines
net/tftp.c +1 -1
@@ -55,7 +55,7 @@ static int	TftpState;
 
 #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+static char tftp_filename[2048];
 

A 2k filename??? How about something more reasonable like 80 or 100 bytes. Use a #define for the size so you can use it later.

Quoted 17 lines
net/tftp.c +2 -1
 #ifdef CFG_DIRECT_FLASH_TFTP
 extern flash_info_t flash_info[];
@@ -231,7 +231,7 @@ TftpSend (void)
 		break;
 	}
 
-	NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort, TftpOurPort, len);
+	NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, TftpOurPort, len);
 }
 
 
@@ -453,30 +453,38 @@ TftpStart (void)
 	char *ep;             /* Environment pointer */
 #endif
 
+	TftpServerIP = NetServerIP;

net/tftp.c TftpStart (void) · line 465

Quoted 10 lines
net/tftp.c +1 -1
 	if (BootFile[0] == '\0') {
 		sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
 			(NetOurIP >> 24) & 0xFF	);
-		tftp_filename = default_filename;
+		strcpy (tftp_filename, default_filename);
 
 

Use strncpy, please, with the buffer length defined above.

net/tftp.c TftpStart (void) · line 477

Quoted 11 lines
net/tftp.c +6 -1
 		printf ("*** Warning: no boot file name; using '%s'\n",
 			tftp_filename);
 	} else {
-		tftp_filename = BootFile;
+		char *p=BootFile;
+		p = strchr (p, ':');
+		if (p != NULL) {
+			TftpServerIP = string_to_ip (BootFile);
+			++p;
+			strcpy (tftp_filename, p);
 

Again, strncpy please

Quoted 18 lines
net/tftp.c +4 -2
+		} else 
+			strcpy (tftp_filename, BootFile);
 	}
 
 #if defined(CONFIG_NET_MULTI)
 	printf ("Using %s device\n", eth_get_name());
 #endif
-	puts ("TFTP from server ");	print_IPaddr (NetServerIP);
+	puts ("TFTP from server ");	print_IPaddr (TftpServerIP);
 	puts ("; our IP address is ");	print_IPaddr (NetOurIP);
 
 	/* Check if we need to send across this subnet */
 	if (NetOurGatewayIP && NetOurSubnetMask) {
 	    IPaddr_t OurNet 	= NetOurIP    & NetOurSubnetMask;
-	    IPaddr_t ServerNet 	= NetServerIP & NetOurSubnetMask;
+	    IPaddr_t ServerNet 	= TftpServerIP & NetOurSubnetMask;
 

net/tftp.c TftpStart (void) · line 490

Quoted 2 lines
net/tftp.c +0 -0
 	    if (OurNet != ServerNet) {
 		puts ("; sending through gateway ");

This now works for me. Fix the file name buffer and I'll pull it in pronto.

regards,
Ben

#3 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 30 lines · Ben Warren
Quoted 29 lines · Jean-Christophe PLAGNIOL-VILLARD

allow to use a different server as set in serverip

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char 
 *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
  int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +1 -0
index 8b95bcf..9d87e2c 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 -
+static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
 static int	TftpTimeoutCount;
Quoted 8 lines

net/tftp.c static int TftpState; · line 58

Quoted 6 lines
net/tftp.c +1 -1
@@ -55,7 +55,7 @@ static int	TftpState;
  #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+static char tftp_filename[2048];
 

A 2k filename??? How about something more reasonable like 80 or 100 bytes. Use a #define for the size so you can use it later.

I've chosed to use the same filename size as nfs.

Quoted 16 lines
Quoted 16 lines
net/tftp.c +1 -0
  #ifdef CFG_DIRECT_FLASH_TFTP
 extern flash_info_t flash_info[];
@@ -231,7 +231,7 @@ TftpSend (void)
 		break;
 	}
 -	NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort, 
 TftpOurPort, len);
+	NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, 
 TftpOurPort, len);
 }
  @@ -453,30 +453,38 @@ TftpStart (void)
 	char *ep;             /* Environment pointer */
 #endif
 +	TftpServerIP = NetServerIP;
 	if (BootFile[0] == '\0') {
 		sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
Quoted 8 lines

net/tftp.c TftpStart (void) · line 463

Quoted 7 lines
net/tftp.c +1 -1
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
 			(NetOurIP >> 24) & 0xFF	);
-		tftp_filename = default_filename;
+		strcpy (tftp_filename, default_filename);

Use strncpy, please, with the buffer length defined above.

idem as my las comment copy from nfs

Quoted 4 lines
Quoted 4 lines
net/tftp.c +0 -1
 		printf ("*** Warning: no boot file name; using '%s'\n",
 			tftp_filename);
 	} else {
-		tftp_filename = BootFile;
Quoted 8 lines

net/tftp.c TftpStart (void) · line 473

Quoted 7 lines
net/tftp.c +6 -0
+		char *p=BootFile;
+		p = strchr (p, ':');
+		if (p != NULL) {
+			TftpServerIP = string_to_ip (BootFile);
+			++p;
+			strcpy (tftp_filename, p);

Again, strncpy please

idem as my las comment copy from nfs

Quoted 18 lines
Quoted 6 lines
net/tftp.c +1 -0
+		} else +			strcpy (tftp_filename, BootFile);
 	}
  #if defined(CONFIG_NET_MULTI)
 	printf ("Using %s device\n", eth_get_name());
 #endif

net/tftp.c TftpStart (void) · line 490

Quoted 10 lines
net/tftp.c +2 -2
-	puts ("TFTP from server ");	print_IPaddr (NetServerIP);
+	puts ("TFTP from server ");	print_IPaddr (TftpServerIP);
 	puts ("; our IP address is ");	print_IPaddr (NetOurIP);
  	/* Check if we need to send across this subnet */
 	if (NetOurGatewayIP && NetOurSubnetMask) {
 	    IPaddr_t OurNet 	= NetOurIP    & NetOurSubnetMask;
-	    IPaddr_t ServerNet 	= NetServerIP & NetOurSubnetMask;
+	    IPaddr_t ServerNet 	= TftpServerIP & NetOurSubnetMask;
  	    if (OurNet != ServerNet) {
 		puts ("; sending through gateway ");

This now works for me. Fix the file name buffer and I'll pull it in pronto.

Quoted 2 lines

regards,
Ben

Best Regards,
J.

#4 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 43 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 32 lines · Ben Warren
Quoted 30 lines · Jean-Christophe PLAGNIOL-VILLARD

allow to use a different server as set in serverip

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char 
 *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
  int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +1 -0
index 8b95bcf..9d87e2c 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 -
+static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
 static int	TftpTimeoutCount;
@@ -55,7 +55,7 @@ static int	TftpState;
Quoted 9 lines

net/tftp.c static int TftpState;

Quoted 6 lines
net/tftp.c +1 -1
  #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+static char tftp_filename[2048];
 
 

A 2k filename??? How about something more reasonable like 80 or 100 bytes. Use a #define for the size so you can use it later.

Quoted 2 lines

I've chosed to use the same filename size as nfs.

Then NFS uses too big a buffer. Please make this one smaller, use a #define and strncpy.
<snip>

regards,
Ben

#5 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 44 lines · Ben Warren
Quoted 43 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 41 lines · Ben Warren
Quoted 30 lines · Jean-Christophe PLAGNIOL-VILLARD

allow to use a different server as set in serverip

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char 
 *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
  int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +1 -0
index 8b95bcf..9d87e2c 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 -
+static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
 static int	TftpTimeoutCount;

net/tftp.c static int TftpState; · line 59

Quoted 6 lines
net/tftp.c +1 -1
@@ -55,7 +55,7 @@ static int	TftpState;
  #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+static char tftp_filename[2048];
 
 

A 2k filename??? How about something more reasonable like 80 or 100 bytes. Use a #define for the size so you can use it later.

Quoted 5 lines
Quoted 2 lines

I've chosed to use the same filename size as nfs.

Then NFS uses too big a buffer. Please make this one smaller, use a #define and strncpy.
<snip>

OK about the buffer size.

But I diaagree about strncpy because you need to known the size of the string and we know it only when we use the default_filename otherwise we need to strlen and in this strcpy do every thing itself.

Best Regards,
J.

#6 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 58 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 49 lines · Ben Warren
Quoted 47 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 44 lines · Ben Warren
Quoted 30 lines · Jean-Christophe PLAGNIOL-VILLARD

allow to use a different server as set in serverip

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char 
 *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
  int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +1 -0
index 8b95bcf..9d87e2c 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 -
+static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
 static int	TftpTimeoutCount;

net/tftp.c static int TftpState; · line 60

Quoted 7 lines
net/tftp.c +1 -1
@@ -55,7 +55,7 @@ static int	TftpState;
  #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+static char tftp_filename[2048];
 
 
 

A 2k filename??? How about something more reasonable like 80 or 100 bytes. Use a #define for the size so you can use it later.

Quoted 7 lines
Quoted 3 lines

I've chosed to use the same filename size as nfs.

Then NFS uses too big a buffer. Please make this one smaller, use a #define and strncpy.
<snip>

Quoted 7 lines

OK about the buffer size.

But I diaagree about strncpy because you need to known the size of the string and we know it only when we use the default_filename otherwise we need to strlen and in this strcpy do every thing itself.

strncpy copies AT MOST 'n' bytes.

#define MAX_FILE_NAME_LEN 80
static char tftp_filename[MAX_FILE_NAME_LEN];

strncpy(tftp_filename, str, MAX_FILE_NAME_LEN);

Standard buffer overrun protection.

regards,
Ben

#7 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 6 lines

But I diaagree about strncpy because you need to known the size of the string and we know it only when we use the default_filename otherwise we need to strlen and in this strcpy do every thing itself.

strncpy copies AT MOST 'n' bytes.

...and doesn't necessarily NUL-terminate.

Quoted 6 lines

#define MAX_FILE_NAME_LEN 80
static char tftp_filename[MAX_FILE_NAME_LEN];

strncpy(tftp_filename, str, MAX_FILE_NAME_LEN);

Standard buffer overrun protection.

...only if you make sure that tftp_filename[] gets terminated independent of the length; otherwise you fix the problem when writing the srting but create one when reading it.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Every program has at least one bug and can be shortened by  at  least
one instruction - from which, by induction, one can deduce that every
program can be reduced to one instruction which doesn't work.
#8 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 22 lines · Wolfgang Denk
Quoted 8 lines · In message <[email protected]> you wrote:
Quoted 6 lines

But I diaagree about strncpy because you need to known the size of the string and we know it only when we use the default_filename otherwise we need to strlen and in this strcpy do every thing itself.

strncpy copies AT MOST 'n' bytes.

...and doesn't necessarily NUL-terminate.

Quoted 7 lines

#define MAX_FILE_NAME_LEN 80
static char tftp_filename[MAX_FILE_NAME_LEN];

strncpy(tftp_filename, str, MAX_FILE_NAME_LEN);

Standard buffer overrun protection.

Quoted 9 lines

...only if you make sure that tftp_filename[] gets terminated independent of the length; otherwise you fix the problem when writing the srting but create one when reading it.

Best regards,

Wolfgang Denk

#define MAX_LEN 80
static char tftp_filename[MAX_LEN + 1];
memset(tftp_filename[MAX_LEN], 0, 1);

strncpy(tftp_filename, str, MAX_LEN);

Better?

regards,
Ben

#9 lore raw

PATCH 1/1 TFTP: add host ip addr support

This one gets my vote:

#define MAX_LEN 80
static char tftp_filename[MAX_LEN];

strncpy(tftp_filename, str, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0;

May be truncated, but never overruns.

-
Jason McMullan
Network Appliance, Inc.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.denx.de/pipermail/u-boot/attachments/20080116/5d558cdf/attachment.pgp

#10 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 8 lines · In message <1200517000.31842.70.camel@localhost> you wrote:

#define MAX_LEN 80
static char tftp_filename[MAX_LEN];

strncpy(tftp_filename, str, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0;

May be truncated, but never overruns.

Acked-by wd at denx.de :-)

Except that the length should be 128 to match the boot file name length that BOOTP / DHCP can pass as per RFC.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A committee is a group that keeps the minutes and loses hours.
                                                      -- Milton Berle
#11 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 8 lines · Wolfgang Denk
Quoted 7 lines · In message <1200517000.31842.70.camel@localhost> you wrote:

#define MAX_LEN 80
static char tftp_filename[MAX_LEN];

strncpy(tftp_filename, str, MAX_LEN);
tftp_filename[MAX_LEN-1] = 0;

Quoted 7 lines
Quoted 1 line

May be truncated, but never overruns.

Acked-by wd at denx.de :-)

Except that the length should be 128 to match the boot file name length that BOOTP / DHCP can pass as per RFC.

Personnaly, I'll prefer 1K length because if you use as I use a lost of time a full path when downloading uImage or other so a path with a length over than 512 arrive often.

And with nfs it's the same

Best Regards,
J.

#12 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 3 lines

Except that the length should be 128 to match the boot file name length that BOOTP / DHCP can pass as per RFC.

Personnaly, I'll prefer 1K length because if you use as I use a lost of time a full path when downloading uImage or other so a path with a length over than 512 arrive often.

So is there a newer RFC that changes this? IIRC the max length is defined as 128 bytes.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
There is, however, a strange, musty smell in the air that reminds  me
of something...hmm...yes...I've got it...there's a VMS nearby, or I'm
a Blit.          - Larry Wall in Configure from the perl distribution
#13 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 10 lines · Wolfgang Denk
Quoted 7 lines · In message <[email protected]> you wrote:
Quoted 3 lines

Except that the length should be 128 to match the boot file name length that BOOTP / DHCP can pass as per RFC.

Personnaly, I'll prefer 1K length because if you use as I use a lost of time a full path when downloading uImage or other so a path with a length over than 512 arrive often.

Quoted 8 lines

So is there a newer RFC that changes this? IIRC the max length is defined as 128 bytes.

Best regards,

Wolfgang Denk

My 2c is that we go with 128, and have a CONFIG_LONG_TFTP_FILE_NAME that allows 1k for people with ridiculously long paths.

regards,
Ben

#14 lore raw

cover TFTP: add host ip addr support

allow to use a different server as set in serverip
add CONFIG_LONG_TFTP_FILE_NAME to allow long file name default as 1024 can be reconfigured whit CONFIG_LONG_TFTP_FILE_NAME_MAX_LEN

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 
 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +34 -10

99 lines not on this page · raw message

Signature · 1 line
1.5.3.7
#15 lore raw

PATCH 1/1 Fix nfs command help to reflect that the serverip is optional

common/cmd_net.c +1 -1
index b86ca86..dbf6b86 100644
@@ -87,7 +87,7 @@ int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
 	nfs,	3,	1,	do_nfs,
 	"nfs\t- boot image via network using NFS protocol\n",
-	"[loadAddress] [host ip addr:bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 #endif
 
Signature · 1 line
1.5.3.7
#16 lore raw

PATCH 1/1 Fix nfs command help to reflect that the serverip is optional

Quoted 8 lines · Jean-Christophe PLAGNIOL-VILLARD
common/cmd_net.c +0 -0
index b86ca86..dbf6b86 100644

common/cmd_net.c int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) · line 93

Quoted 8 lines
common/cmd_net.c +1 -1
@@ -87,7 +87,7 @@ int do_nfs (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
 	nfs,	3,	1,	do_nfs,
 	"nfs\t- boot image via network using NFS protocol\n",
-	"[loadAddress] [host ip addr:bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 #endif
 

This one's already in.

regards,
Ben

#17 lore raw

cover TFTP: add host ip addr support

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 10 lines · In message <[email protected]> you wrote:

allow to use a different server as set in serverip
add CONFIG_LONG_TFTP_FILE_NAME to allow long file name default as 1024 can be reconfigured whit CONFIG_LONG_TFTP_FILE_NAME_MAX_LEN

net/tftp.c +0 -0
index 8b95bcf..262ff79 100644

...

Quoted 7 lines
net/tftp.c +2 -1
@@ -55,7 +55,18 @@ static int	TftpState;
 
 #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+
+#ifdef CONFIG_LONG_TFTP_FILE_NAME

net/tftp.c static int TftpState; · line 69

Quoted 10 lines
net/tftp.c +10 -0
+# ifndef CONFIG_LONG_TFTP_FILE_NAME_MAX_LEN
+#  define MAX_LEN 1024
+# else
+#  define MAX_LEN CONFIG_LONG_TFTP_FILE_NAME_MAX_LEN
+# endif
+#else
+#define MAX_LEN 128
+#endif
+
+static char tftp_filename[MAX_LEN];

We don't need *two* new defines. Just use one, say CONFIG_TFTP_FILE_NAME_MAX_LEN

Quoted 21 lines
net/tftp.c +2 -2
@@ -372,7 +383,7 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
 #ifdef CONFIG_MCAST_TFTP
 		/* if I am the MasterClient, actively calculate what my next
 		 * needed block is; else I'm passive; not ACKING
- 		 */
+		 */
 		if (Multicast) {
 			if (len < TftpBlkSize)  {
 				TftpEndingBlock = TftpBlock;
@@ -453,30 +464,43 @@ TftpStart (void)
 	char *ep;             /* Environment pointer */
 #endif
 
+	TftpServerIP = NetServerIP;
 	if (BootFile[0] == '\0') {
 		sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
 			(NetOurIP >> 24) & 0xFF	);
-		tftp_filename = default_filename;

net/tftp.c TftpStart (void) · line 482

Quoted 10 lines
net/tftp.c +5 -1
+
+		strncpy(tftp_filename, default_filename, MAX_LEN);
+		tftp_filename[MAX_LEN-1] = 0;
 
 		printf ("*** Warning: no boot file name; using '%s'\n",
 			tftp_filename);
 	} else {
-		tftp_filename = BootFile;
+		char *p=BootFile;
+		p = strchr (p, ':');

Blank line after declarations. And make this:

		char *p = strchr (BootFile, ':');

net/tftp.c TftpStart (void) · line 483

Quoted 1 line
net/tftp.c +1 -0
+		if (p != NULL) {

Please swap the "if" and "else" branches and use "if (p == NULL)"

net/tftp.c TftpStart (void) · line 484

Quoted 1 line
net/tftp.c +1 -0
+			TftpServerIP = string_to_ip (BootFile);

Note that there is no terminating '0' at *p ! You might want to insert one for robustness.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Vulcans worship peace above all.
	-- McCoy, "Return to Tomorrow", stardate 4768.3
#18 lore raw

cover TFTP: add host ip addr support

In reply to Jean-Christophe PLAGNIOL-VILLARD

Couldn't this be done as follows instead? This way there is no need to allocate any more memory on the stack, and no need for a new configuration option.

Andre

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
     tftpboot,    3,    1,    do_tftpb,
     "tftpboot- boot image via network using TFTP protocol\n",
-    "[loadAddress] [bootfilename]\n"
+    "[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 
 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +14 -5
index 8b95bcf..262ff79 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR    5
 #define TFTP_OACK    6
 
-
+static IPaddr_t TftpServerIP;
 static int    TftpServerPort;        /* The UDP port at their end        */
 static int    TftpOurPort;        /* The UDP port at our end        */
 static int    TftpTimeoutCount;
@@ -231,7 +242,7 @@ TftpSend (void)
         break;
     }
 
-    NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort, TftpOurPort, len);
+    NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, TftpOurPort, len);
 }
 
 
@@ -453,30 +464,43 @@ TftpStart (void)
     char *ep;             /* Environment pointer */
 #endif
 
+    TftpServerIP = NetServerIP;
     if (BootFile[0] == '\0') {
         sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
             NetOurIP & 0xFF,
             (NetOurIP >>  8) & 0xFF,
             (NetOurIP >> 16) & 0xFF,
             (NetOurIP >> 24) & 0xFF    );
         tftp_filename = default_filename;
 
         printf ("*** Warning: no boot file name; using '%s'\n",
             tftp_filename);
     } else {
+        char *p=BootFile;
+        p = strchr (p, ':');
+        if (p != NULL) {
+            TftpServerIP = string_to_ip (BootFile);
+            ++p;
+            tftp_filename = p;
+        } else
+            tftp_filename = BootFile;
     }
 
 #if defined(CONFIG_NET_MULTI)
     printf ("Using %s device\n", eth_get_name());
 #endif
-    puts ("TFTP from server ");    print_IPaddr (NetServerIP);
+    puts ("TFTP from server ");    print_IPaddr (TftpServerIP);
     puts ("; our IP address is ");    print_IPaddr (NetOurIP);
 
     /* Check if we need to send across this subnet */
     if (NetOurGatewayIP && NetOurSubnetMask) {
-        IPaddr_t OurNet     = NetOurIP    & NetOurSubnetMask;
-        IPaddr_t ServerNet     = NetServerIP & NetOurSubnetMask;
+        IPaddr_t OurNet    = NetOurIP    & NetOurSubnetMask;
+        IPaddr_t ServerNet    = TftpServerIP & NetOurSubnetMask;
 
         if (OurNet != ServerNet) {
         puts ("; sending through gateway ");
#19 lore raw

cover TFTP: add host ip addr support

Quoted 4 lines · Andre Renaud

Couldn't this be done as follows instead? This way there is no need to allocate any more memory on the stack, and no need for a new configuration option.

This is nice, because it works in-place and doesn't need the second buffer. One concern, though (see below)

Quoted 50 lines

Andre

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
     tftpboot,    3,    1,    do_tftpb,
     "tftpboot- boot image via network using TFTP protocol\n",
-    "[loadAddress] [bootfilename]\n"
+    "[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 
 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +3 -2
index 8b95bcf..262ff79 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR    5
 #define TFTP_OACK    6
 
-
+static IPaddr_t TftpServerIP;
 static int    TftpServerPort;        /* The UDP port at their end        */
 static int    TftpOurPort;        /* The UDP port at our end        */
 static int    TftpTimeoutCount;
@@ -231,7 +242,7 @@ TftpSend (void)
         break;
     }
 
-    NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort, TftpOurPort, len);
+    NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, TftpOurPort, len);
 }
 
 
@@ -453,30 +464,43 @@ TftpStart (void)
     char *ep;             /* Environment pointer */
 #endif
 
+    TftpServerIP = NetServerIP;
     if (BootFile[0] == '\0') {
         sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
             NetOurIP & 0xFF,
             (NetOurIP >>  8) & 0xFF,
             (NetOurIP >> 16) & 0xFF,
             (NetOurIP >> 24) & 0xFF    );

net/tftp.c TftpStart (void) · line 483

Quoted 10 lines
net/tftp.c +4 -0
         tftp_filename = default_filename;
 
         printf ("*** Warning: no boot file name; using '%s'\n",
             tftp_filename);
     } else {
+        char *p=BootFile;
+        p = strchr (p, ':');
+        if (p != NULL) {
+            TftpServerIP = string_to_ip (BootFile);
 

I don't know if string_to_ip() works properly on a string of the format a.b.c.d:filename

net/tftp.c TftpStart (void) · line 494

Quoted 7 lines
net/tftp.c +4 -0
+            ++p;
+            tftp_filename = p;
+        } else
+            tftp_filename = BootFile;
     }
 
 

Alternatively:

	char *p = strchr(Bootfile, ':');
	if (p && *(p+1) != '\0') {
		tftp_filename = P + 1;
		*p = '\0';
		TftpServerIP = string_to_ip(Bootfile);
	} else
		tftp_filename = Bootfile;

*** Note: I haven't tried compiling this and it was written quickly, so may be garbage! Just ask Wolfgang...

regards,
Ben

#21 lore raw

PATCH 1/1 TFTP: add host ip addr support

In reply to Ben Warren
Quoted 4 lines · In message <[email protected]> you wrote:

#define MAX_LEN 80
static char tftp_filename[MAX_LEN + 1];
memset(tftp_filename[MAX_LEN], 0, 1);

warning: passing argument 1 of 'memset' makes pointer from integer without a cast

Quoted 4 lines

strncpy(tftp_filename, str, MAX_LEN);

Better?

No, definitely not.

First, the compiler will issue a warning; second, using memcpy() to store a single character is serious overkill - why don't you simply use "tftp_filename[MAX_LEN] = '\0';" ?;and third - the real bug - the strncpy will happily overwrite the 0 you placed there before.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"I can call spirits from the vasty deep."
"Why so can I, or so can any man; but will they come when you do call
for them?"          - Shakespeare, 1 King Henry IV, Act III, Scene I.
#22 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 10 lines · Wolfgang Denk
Quoted 4 lines · In message <[email protected]> you wrote:

#define MAX_LEN 80
static char tftp_filename[MAX_LEN + 1];
memset(tftp_filename[MAX_LEN], 0, 1);

warning: passing argument 1 of 'memset' makes pointer from integer without a cast

10-second response, brain not fully engaged. Compiler not used (duh?)

Quoted 6 lines
Quoted 5 lines

strncpy(tftp_filename, str, MAX_LEN);

Better?

Quoted 8 lines

No, definitely not.

First, the compiler will issue a warning; second, using memcpy() to store a single character is serious overkill - why don't you simply use "tftp_filename[MAX_LEN] = '\0';" ?;and third - the real bug - the strncpy will happily overwrite the 0 you placed there before.

strncpy won't touch the zero, since it's in the 81st byte and strncpy will only copy 80. True about the warnings and memset overkill, though.

OK, let's move on...

Jean-Christophe - Jason McMullen has given you a nice prototype. Please use it.

regards,
Ben

#23 lore raw

PATCH 1/1 TFTP: add host ip addr support

In reply to Wolfgang Denk

allow to use a different server as set in serverip
add CONFIG_TFTP_FILE_NAME_MAX_LEN to configure the file name length if not defined the max length will be at 128

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 
 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +29 -10
index 8b95bcf..2096178 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 
-
+static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
 static int	TftpTimeoutCount;
@@ -55,7 +55,14 @@ static int	TftpState;
 
 #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+
+#ifndef CONFIG_TFTP_FILE_NAME_MAX_LEN
+#define MAX_LEN 128
+#else
+#define MAX_LEN CONFIG_TFTP_FILE_NAME_MAX_LEN
+#endif
+
+static char tftp_filename[MAX_LEN];
 
 #ifdef CFG_DIRECT_FLASH_TFTP
 extern flash_info_t flash_info[];
@@ -231,7 +238,7 @@ TftpSend (void)
 		break;
 	}
 
-	NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort, TftpOurPort, len);
+	NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, TftpOurPort, len);
 }
 
 
@@ -372,7 +379,7 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
 #ifdef CONFIG_MCAST_TFTP
 		/* if I am the MasterClient, actively calculate what my next
 		 * needed block is; else I'm passive; not ACKING
- 		 */
+		 */
 		if (Multicast) {
 			if (len < TftpBlkSize)  {
 				TftpEndingBlock = TftpBlock;
@@ -453,30 +460,42 @@ TftpStart (void)
 	char *ep;             /* Environment pointer */
 #endif
 
+	TftpServerIP = NetServerIP;
 	if (BootFile[0] == '\0') {
 		sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
 			(NetOurIP >> 24) & 0xFF	);
-		tftp_filename = default_filename;
+
+		strncpy(tftp_filename, default_filename, MAX_LEN);
+		tftp_filename[MAX_LEN-1] = 0;
 
 		printf ("*** Warning: no boot file name; using '%s'\n",
 			tftp_filename);
 	} else {
-		tftp_filename = BootFile;
+		char *p = strchr (p, ':');
+		if (p == NULL) {
+			strncpy(tftp_filename, BootFile, MAX_LEN);
+			tftp_filename[MAX_LEN-1] = 0;
+		} else {
+			*p++ = '\0';
+			TftpServerIP = string_to_ip (BootFile);
+			strncpy(tftp_filename, p, MAX_LEN);
+			tftp_filename[MAX_LEN-1] = 0;
+		}
 	}
 
 #if defined(CONFIG_NET_MULTI)
 	printf ("Using %s device\n", eth_get_name());
 #endif
-	puts ("TFTP from server ");	print_IPaddr (NetServerIP);
+	puts ("TFTP from server ");	print_IPaddr (TftpServerIP);
 	puts ("; our IP address is ");	print_IPaddr (NetOurIP);
 
 	/* Check if we need to send across this subnet */
 	if (NetOurGatewayIP && NetOurSubnetMask) {
-	    IPaddr_t OurNet 	= NetOurIP    & NetOurSubnetMask;
-	    IPaddr_t ServerNet 	= NetServerIP & NetOurSubnetMask;
+	    IPaddr_t OurNet	= NetOurIP    & NetOurSubnetMask;
+	    IPaddr_t ServerNet	= TftpServerIP & NetOurSubnetMask;
 
 	    if (OurNet != ServerNet) {
 		puts ("; sending through gateway ");
@@ -522,7 +541,7 @@ TftpStart (void)
 	/* Revert TftpBlkSize to dflt */
 	TftpBlkSize = TFTP_BLOCK_SIZE;
 #ifdef CONFIG_MCAST_TFTP
-    	mcast_cleanup();
+	mcast_cleanup();
 #endif
 
 	TftpSend ();
Signature · 1 line
1.5.3.7
#24 lore raw

PATCH 1/1 TFTP: add host ip addr support

allow to use a different server as set in serverip
add CONFIG_TFTP_FILE_NAME_MAX_LEN to configure the file name length if not defined the max length will be at 128

common/cmd_net.c +1 -1
index 21682c0..b86ca86 100644
@@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
 	tftpboot,	3,	1,	do_tftpb,
 	"tftpboot- boot image via network using TFTP protocol\n",
-	"[loadAddress] [bootfilename]\n"
+	"[loadAddress] [[hostIPaddr:]bootfilename]\n"
 );
 
 int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
net/tftp.c +30 -10
index 8b95bcf..3dd2b06 100644
@@ -34,7 +34,7 @@
 #define TFTP_ERROR	5
 #define TFTP_OACK	6
 
-
+static IPaddr_t TftpServerIP;
 static int	TftpServerPort;		/* The UDP port at their end		*/
 static int	TftpOurPort;		/* The UDP port at our end		*/
 static int	TftpTimeoutCount;
@@ -55,7 +55,14 @@ static int	TftpState;
 
 #define DEFAULT_NAME_LEN	(8 + 4 + 1)
 static char default_filename[DEFAULT_NAME_LEN];
-static char *tftp_filename;
+
+#ifndef CONFIG_TFTP_FILE_NAME_MAX_LEN
+#define MAX_LEN 128
+#else
+#define MAX_LEN CONFIG_TFTP_FILE_NAME_MAX_LEN
+#endif
+
+static char tftp_filename[MAX_LEN];
 
 #ifdef CFG_DIRECT_FLASH_TFTP
 extern flash_info_t flash_info[];
@@ -231,7 +238,7 @@ TftpSend (void)
 		break;
 	}
 
-	NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort, TftpOurPort, len);
+	NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, TftpOurPort, len);
 }
 
 
@@ -372,7 +379,7 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
 #ifdef CONFIG_MCAST_TFTP
 		/* if I am the MasterClient, actively calculate what my next
 		 * needed block is; else I'm passive; not ACKING
- 		 */
+		 */
 		if (Multicast) {
 			if (len < TftpBlkSize)  {
 				TftpEndingBlock = TftpBlock;
@@ -453,30 +460,43 @@ TftpStart (void)
 	char *ep;             /* Environment pointer */
 #endif
 
+	TftpServerIP = NetServerIP;
 	if (BootFile[0] == '\0') {
 		sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
 			NetOurIP & 0xFF,
 			(NetOurIP >>  8) & 0xFF,
 			(NetOurIP >> 16) & 0xFF,
 			(NetOurIP >> 24) & 0xFF	);
-		tftp_filename = default_filename;
+
+		strncpy(tftp_filename, default_filename, MAX_LEN);
+		tftp_filename[MAX_LEN-1] = 0;
 
 		printf ("*** Warning: no boot file name; using '%s'\n",
 			tftp_filename);
 	} else {
-		tftp_filename = BootFile;
+		char *p = strchr (p, ':');
+
+		if (p == NULL) {
+			strncpy(tftp_filename, BootFile, MAX_LEN);
+			tftp_filename[MAX_LEN-1] = 0;
+		} else {
+			*p++ = '\0';
+			TftpServerIP = string_to_ip (BootFile);
+			strncpy(tftp_filename, p, MAX_LEN);
+			tftp_filename[MAX_LEN-1] = 0;
+		}
 	}
 
 #if defined(CONFIG_NET_MULTI)
 	printf ("Using %s device\n", eth_get_name());
 #endif
-	puts ("TFTP from server ");	print_IPaddr (NetServerIP);
+	puts ("TFTP from server ");	print_IPaddr (TftpServerIP);
 	puts ("; our IP address is ");	print_IPaddr (NetOurIP);
 
 	/* Check if we need to send across this subnet */
 	if (NetOurGatewayIP && NetOurSubnetMask) {
-	    IPaddr_t OurNet 	= NetOurIP    & NetOurSubnetMask;
-	    IPaddr_t ServerNet 	= NetServerIP & NetOurSubnetMask;
+	    IPaddr_t OurNet	= NetOurIP    & NetOurSubnetMask;
+	    IPaddr_t ServerNet	= TftpServerIP & NetOurSubnetMask;
 
 	    if (OurNet != ServerNet) {
 		puts ("; sending through gateway ");
@@ -522,7 +542,7 @@ TftpStart (void)
 	/* Revert TftpBlkSize to dflt */
 	TftpBlkSize = TFTP_BLOCK_SIZE;
 #ifdef CONFIG_MCAST_TFTP
-    	mcast_cleanup();
+	mcast_cleanup();
 #endif
 
 	TftpSend ();
Signature · 1 line
1.5.3.7
#25 lore raw

PATCH 1/1 TFTP: add host ip addr support

Quoted 5 lines · In message <[email protected]> you wrote:

allow to use a different server as set in serverip
add CONFIG_TFTP_FILE_NAME_MAX_LEN to configure the file name length if not defined the max length will be at 128

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"And it should be the law: If you use  the  word  `paradigm'  without
knowing  what  the  dictionary  says  it  means,  you  go to jail. No
exceptions."                     - David Jones @ Megatest Corporation
#26 lore raw

PATCH 1/1 TFTP: add host ip addr support

In reply to Jean-Christophe PLAGNIOL-VILLARD

Wolfgang,

Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD

allow to use a different server as set in serverip
add CONFIG_TFTP_FILE_NAME_MAX_LEN to configure the file name length if not defined the max length will be at 128

I'm not fussy whether this version or a modified Andre Renaud version goes in. Please pick one and apply directly.

regards,
Ben