[U-Boot-Users] [PATCH] TFTP: add host ip addr support

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Wed Jan 16 08:19:39 CET 2008


On 22:19 Tue 15 Jan     , Ben Warren wrote:
> Jean-Christophe PLAGNIOL-VILLARD wrote:
>> allow to use a different server as set in serverip
>>
>> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
>>
>> diff --git a/common/cmd_net.c b/common/cmd_net.c
>> index 21682c0..b86ca86 100644
>> --- a/common/cmd_net.c
>> +++ b/common/cmd_net.c
>> @@ -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[])
>> diff --git a/net/tftp.c b/net/tftp.c
>> index 8b95bcf..9d87e2c 100644
>> --- a/net/tftp.c
>> +++ b/net/tftp.c
>> @@ -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];
>>   
> 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.
>>   #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);
>>    
> Use strncpy, please, with the buffer length defined above.
idem as my las comment copy from nfs
>>  		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
idem as my las comment copy from nfs
>> +		} 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 ");
>>   
> This now works for me. Fix the file name buffer and I'll pull it in pronto.
>
> regards,
> Ben
Best Regards,
J.




More information about the U-Boot mailing list