From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ben Warren Date: Thu, 17 Jan 2008 19:19:19 -0500 Subject: [U-Boot-Users] [PATCH 0/1] TFTP: add host ip addr support In-Reply-To: <478FD9E3.3060700@bluewatersys.com> References: <478E944F.2090406@gmail.com> <1200607712-1381-1-git-send-email-plagnioj@jcrosoft.com> <478FD9E3.3060700@bluewatersys.com> Message-ID: <478FF087.2080106@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Andre Renaud wrote: > 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) > Andre > > Signed-off-by: Andre Renaud > > 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..262ff79 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; > @@ -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); > I don't know if string_to_ip() works properly on a string of the format a.b.c.d:filename > + ++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