mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-20 22:21:41 +00:00
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 Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
This commit is contained in:
parent
7ec8bb15ee
commit
a93907c43f
2 changed files with 31 additions and 11 deletions
|
@ -51,7 +51,7 @@ int do_tftpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||||
U_BOOT_CMD(
|
U_BOOT_CMD(
|
||||||
tftpboot, 3, 1, do_tftpb,
|
tftpboot, 3, 1, do_tftpb,
|
||||||
"tftpboot- boot image via network using TFTP protocol\n",
|
"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[])
|
int do_rarpb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
|
||||||
|
|
34
net/tftp.c
34
net/tftp.c
|
@ -34,7 +34,7 @@
|
||||||
#define TFTP_ERROR 5
|
#define TFTP_ERROR 5
|
||||||
#define TFTP_OACK 6
|
#define TFTP_OACK 6
|
||||||
|
|
||||||
|
static IPaddr_t TftpServerIP;
|
||||||
static int TftpServerPort; /* The UDP port at their end */
|
static int TftpServerPort; /* The UDP port at their end */
|
||||||
static int TftpOurPort; /* The UDP port at our end */
|
static int TftpOurPort; /* The UDP port at our end */
|
||||||
static int TftpTimeoutCount;
|
static int TftpTimeoutCount;
|
||||||
|
@ -55,7 +55,14 @@ static int TftpState;
|
||||||
|
|
||||||
#define DEFAULT_NAME_LEN (8 + 4 + 1)
|
#define DEFAULT_NAME_LEN (8 + 4 + 1)
|
||||||
static char default_filename[DEFAULT_NAME_LEN];
|
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
|
#ifdef CFG_DIRECT_FLASH_TFTP
|
||||||
extern flash_info_t flash_info[];
|
extern flash_info_t flash_info[];
|
||||||
|
@ -231,7 +238,7 @@ TftpSend (void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetSendUDPPacket(NetServerEther, NetServerIP, TftpServerPort, TftpOurPort, len);
|
NetSendUDPPacket(NetServerEther, TftpServerIP, TftpServerPort, TftpOurPort, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -453,30 +460,43 @@ TftpStart (void)
|
||||||
char *ep; /* Environment pointer */
|
char *ep; /* Environment pointer */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
TftpServerIP = NetServerIP;
|
||||||
if (BootFile[0] == '\0') {
|
if (BootFile[0] == '\0') {
|
||||||
sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
|
sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
|
||||||
NetOurIP & 0xFF,
|
NetOurIP & 0xFF,
|
||||||
(NetOurIP >> 8) & 0xFF,
|
(NetOurIP >> 8) & 0xFF,
|
||||||
(NetOurIP >> 16) & 0xFF,
|
(NetOurIP >> 16) & 0xFF,
|
||||||
(NetOurIP >> 24) & 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",
|
printf ("*** Warning: no boot file name; using '%s'\n",
|
||||||
tftp_filename);
|
tftp_filename);
|
||||||
} else {
|
} 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)
|
#if defined(CONFIG_NET_MULTI)
|
||||||
printf ("Using %s device\n", eth_get_name());
|
printf ("Using %s device\n", eth_get_name());
|
||||||
#endif
|
#endif
|
||||||
puts ("TFTP from server "); print_IPaddr (NetServerIP);
|
puts ("TFTP from server "); print_IPaddr (TftpServerIP);
|
||||||
puts ("; our IP address is "); print_IPaddr (NetOurIP);
|
puts ("; our IP address is "); print_IPaddr (NetOurIP);
|
||||||
|
|
||||||
/* Check if we need to send across this subnet */
|
/* Check if we need to send across this subnet */
|
||||||
if (NetOurGatewayIP && NetOurSubnetMask) {
|
if (NetOurGatewayIP && NetOurSubnetMask) {
|
||||||
IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
|
IPaddr_t OurNet = NetOurIP & NetOurSubnetMask;
|
||||||
IPaddr_t ServerNet = NetServerIP & NetOurSubnetMask;
|
IPaddr_t ServerNet = TftpServerIP & NetOurSubnetMask;
|
||||||
|
|
||||||
if (OurNet != ServerNet) {
|
if (OurNet != ServerNet) {
|
||||||
puts ("; sending through gateway ");
|
puts ("; sending through gateway ");
|
||||||
|
|
Loading…
Add table
Reference in a new issue