Commit 4fccb818e7ee1190602e79aa5729a23bc349bf0c

Authored by Robin Getz
Committed by Ben Warren
1 parent 488feef852

Add Transfer Size Option to tftp

Optionally add RFC 2349 "Transfer Size Option", so we can minimize the
time spent sending data over the UART (now print a single line during a
tftp transfer).

 - If turned on (CONFIG_TFTP_TSIZE), U-Boot asks for the size of the file.
 - if receives the file size, a single line (50 chars) are printed.
     one hash mark == 2% of the file downloaded.
 - if it doesn't receive the file size (the server doesn't support RFC
     2349, prints standard hash marks (one mark for each UDP frame).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

Showing 1 changed file with 36 additions and 2 deletions Side-by-side Diff

... ... @@ -56,6 +56,10 @@
56 56 static ulong TftpBlockWrap; /* count of sequence number wraparounds */
57 57 static ulong TftpBlockWrapOffset; /* memory offset due to wrapping */
58 58 static int TftpState;
  59 +#ifdef CONFIG_TFTP_TSIZE
  60 +static int TftpTsize; /* The file size reported by the server */
  61 +static short TftpNumchars; /* The number of hashes we printed */
  62 +#endif
59 63  
60 64 #define STATE_RRQ 1
61 65 #define STATE_DATA 2
... ... @@ -202,6 +206,10 @@
202 206 sprintf((char *)pkt, "%lu", TIMEOUT / 1000);
203 207 debug("send option \"timeout %s\"\n", (char *)pkt);
204 208 pkt += strlen((char *)pkt) + 1;
  209 +#ifdef CONFIG_TFTP_TSIZE
  210 + memcpy((char *)pkt, "tsize\0000\0", 8);
  211 + pkt += 8;
  212 +#endif
205 213 /* try for more effic. blk size */
206 214 pkt += sprintf((char *)pkt,"blksize%c%d%c",
207 215 0,TftpBlkSizeOption,0);
208 216  
... ... @@ -313,8 +321,14 @@
313 321 simple_strtoul((char*)pkt+i+8,NULL,10);
314 322 debug("Blocksize ack: %s, %d\n",
315 323 (char*)pkt+i+8,TftpBlkSize);
316   - break;
317 324 }
  325 +#ifdef CONFIG_TFTP_TSIZE
  326 + if (strcmp ((char*)pkt+i,"tsize") == 0) {
  327 + TftpTsize = simple_strtoul((char*)pkt+i+6,NULL,10);
  328 + debug("size = %s, %d\n",
  329 + (char*)pkt+i+6, TftpTsize);
  330 + }
  331 +#endif
318 332 }
319 333 #ifdef CONFIG_MCAST_TFTP
320 334 parse_multicast_oack((char *)pkt,len-1);
... ... @@ -340,7 +354,16 @@
340 354 TftpBlockWrap++;
341 355 TftpBlockWrapOffset += TftpBlkSize * TFTP_SEQUENCE_SIZE;
342 356 printf ("\n\t %lu MB received\n\t ", TftpBlockWrapOffset>>20);
343   - } else {
  357 + }
  358 +#ifdef CONFIG_TFTP_TSIZE
  359 + else if (TftpTsize) {
  360 + while (TftpNumchars < NetBootFileXferSize * 50 / TftpTsize) {
  361 + putc('#');
  362 + TftpNumchars++;
  363 + }
  364 + }
  365 +#endif
  366 + else {
344 367 if (((TftpBlock - 1) % 10) == 0) {
345 368 putc ('#');
346 369 } else if ((TftpBlock % (10 * HASHES_PER_LINE)) == 0) {
... ... @@ -434,6 +457,13 @@
434 457 * We received the whole thing. Try to
435 458 * run it.
436 459 */
  460 +#ifdef CONFIG_TFTP_TSIZE
  461 + /* Print out the hash marks for the last packet received */
  462 + while (TftpTsize && TftpNumchars < 49) {
  463 + putc('#');
  464 + TftpNumchars++;
  465 + }
  466 +#endif
437 467 puts ("\ndone\n");
438 468 NetState = NETLOOP_SUCCESS;
439 469 }
... ... @@ -562,6 +592,10 @@
562 592 TftpBlkSize = TFTP_BLOCK_SIZE;
563 593 #ifdef CONFIG_MCAST_TFTP
564 594 mcast_cleanup();
  595 +#endif
  596 +#ifdef CONFIG_TFTP_TSIZE
  597 + TftpTsize = 0;
  598 + TftpNumchars = 0;
565 599 #endif
566 600  
567 601 TftpSend ();