[U-Boot] [PATCH v2 5/5] Allow tftp server to be different from bootp/dhcp server
Simon Glass
sjg at chromium.org
Wed Apr 13 02:46:12 CEST 2011
In many environments the DHCP server (which provides IP addresses) is not
under control of the individual engineer. While it is required in order to
connect to the corporate network, it doesn't provide useful information for
booting. For example, it may be set up for PC imaging and provide a bootfile
and tftp server for pxelinux.
To deal with this, this commit provides for a separate tftpserverip environment
variable. If this is defined, then this IP address is used in preference
to serverip. A new CONFIG_BOOTP_IGNORE_BOOTFILE option is provided to indicate
that any bootfile name returned by the DHCP server is bogus and should be
ignored.
To use this feature, just setenv tftpserverip to the address of your TFTP
server and define CONFIG_BOOTP_IGNORE_BOOTFILE in your board file.
To use a unified DHCP and TFTP server, don't do either of these steps.
TEST=build U-Boot, try bootp with and without tftpserverip set and with and
without CONFIG_BOOTP_IGNORE_BOOTFILE.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
net/bootp.c | 3 ++-
net/net.c | 12 ++++++++++--
net/tftp.c | 2 +-
3 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/net/bootp.c b/net/bootp.c
index a3d0e63..1f4523f 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -113,9 +113,10 @@ static void BootpCopyNetParams(Bootp_t *bp)
NetCopyIP(&NetServerIP, &bp->bp_siaddr);
memcpy (NetServerEther, ((Ethernet_t *)NetRxPacket)->et_src, 6);
#endif
+#if !defined(CONFIG_BOOTP_IGNORE_BOOTFILE)
if (strlen(bp->bp_file) > 0)
copy_filename (BootFile, bp->bp_file, sizeof(BootFile));
-
+#endif
debug("Bootfile: %s\n", BootFile);
/* Propagate to environment:
diff --git a/net/net.c b/net/net.c
index a609632..77bd192 100644
--- a/net/net.c
+++ b/net/net.c
@@ -138,6 +138,7 @@ uchar NetServerEther[6] = /* Boot server enet address */
{ 0, 0, 0, 0, 0, 0 };
IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */
IPaddr_t NetServerIP; /* Server IP addr (0 = unknown) */
+IPaddr_t NetTftpServerIP; /* Tftp Server IP addr (0 = unknown) */
volatile uchar *NetRxPacket; /* Current receive packet */
int NetRxPacketLen; /* Current rx packet length */
unsigned NetIPID; /* IP packet ID */
@@ -289,6 +290,7 @@ NetInitLoop(proto_t protocol)
NetOurGatewayIP = getenv_IPaddr ("gatewayip");
NetOurSubnetMask= getenv_IPaddr ("netmask");
NetServerIP = getenv_IPaddr ("serverip");
+ NetTftpServerIP = getenv_IPaddr("tftpserverip");
NetOurNativeVLAN = getenv_VLAN("nvlan");
NetOurVLAN = getenv_VLAN("vlan");
#if defined(CONFIG_CMD_DNS)
@@ -1720,8 +1722,14 @@ static int net_check_prereq (proto_t protocol)
#endif
case NETCONS:
case TFTP:
- if (NetServerIP == 0) {
- puts ("*** ERROR: `serverip' not set\n");
+ /*
+ * If there is no specific Tftp server defined, just use the
+ * generic one */
+ if (NetTftpServerIP == 0)
+ NetTftpServerIP = NetServerIP;
+ if (NetTftpServerIP == 0) {
+ puts("*** ERROR: `serverip' and 'tcpserverip'"
+ "not set\n");
return (1);
}
#if defined(CONFIG_CMD_PING) || defined(CONFIG_CMD_SNTP)
diff --git a/net/tftp.c b/net/tftp.c
index ed559b7..4f6b1a2 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -547,7 +547,7 @@ TftpStart (void)
debug("TFTP blocksize = %i, timeout = %ld ms\n",
TftpBlkSizeOption, TftpTimeoutMSecs);
- TftpServerIP = NetServerIP;
+ TftpServerIP = NetTftpServerIP;
if (BootFile[0] == '\0') {
sprintf(default_filename, "%02lX%02lX%02lX%02lX.img",
NetOurIP & 0xFF,
--
1.7.3.1
More information about the U-Boot
mailing list