]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - net/tftp.c
karo: tx6ul: disable the PMIC for '_noenv' U-Boot
[karo-tx-uboot.git] / net / tftp.c
index 14acf04e1f1e5798510f8dfe207f723f808efc1a..dd880af30f8f9f461a5d40ea30e7aebd3e83d3a5 100644 (file)
 /* Well known TFTP port # */
 #define WELL_KNOWN_PORT        69
 /* Millisecs to timeout for lost pkt */
-#define TIMEOUT                5000UL
+#define TIMEOUT                1000UL
 #ifndef        CONFIG_NET_RETRY_COUNT
 /* # of timeouts before giving up */
-# define TIMEOUT_COUNT 10
+# define TIMEOUT_COUNT 1000
 #else
 # define TIMEOUT_COUNT  (CONFIG_NET_RETRY_COUNT * 2)
 #endif
@@ -249,6 +249,8 @@ static void show_block_marker(void)
        if (tftp_tsize) {
                ulong pos = tftp_cur_block * tftp_block_size +
                        tftp_block_wrap_offset;
+               if (pos > tftp_tsize)
+                       pos = tftp_tsize;
 
                while (tftp_tsize_num_hash < pos * 50 / tftp_tsize) {
                        putc('#');
@@ -275,7 +277,7 @@ static void restart(const char *msg)
 #ifdef CONFIG_MCAST_TFTP
        mcast_cleanup();
 #endif
-       NetStartAgain();
+       net_start_again();
 }
 
 /*
@@ -359,7 +361,7 @@ static void tftp_send(void)
                pkt += 5 /*strlen("octet")*/ + 1;
                strcpy((char *)pkt, "timeout");
                pkt += 7 /*strlen("timeout")*/ + 1;
-               sprintf((char *)pkt, "%lu", timeout_ms / 1000);
+               sprintf((char *)pkt, "%lu", DIV_ROUND_UP(timeout_ms, 1000));
                debug("send option \"timeout %s\"\n", (char *)pkt);
                pkt += strlen((char *)pkt) + 1;
 #ifdef CONFIG_TFTP_TSIZE
@@ -589,7 +591,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
                                printf("First block is not block 1 (%ld)\n",
                                       tftp_cur_block);
                                puts("Starting again\n\n");
-                               NetStartAgain();
+                               net_start_again();
                                break;
                        }
                }
@@ -601,7 +603,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 
                tftp_prev_block = tftp_cur_block;
                timeout_count_max = TIMEOUT_COUNT;
-               NetSetTimeout(timeout_ms, tftp_timeout_handler);
+               net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
 
                store_block(tftp_cur_block - 1, pkt + 2, len);
 
@@ -628,7 +630,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
                                        /* try to double it and retry */
                                        tftp_mcast_bitmap_size <<= 1;
                                        mcast_cleanup();
-                                       NetStartAgain();
+                                       net_start_again();
                                        return;
                                }
                                tftp_prev_block = tftp_cur_block;
@@ -672,7 +674,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
 #ifdef CONFIG_MCAST_TFTP
                        mcast_cleanup();
 #endif
-                       NetStartAgain();
+                       net_start_again();
                        break;
                }
                break;
@@ -686,7 +688,7 @@ static void tftp_timeout_handler(void)
                restart("Retry count exceeded");
        } else {
                puts("T ");
-               NetSetTimeout(timeout_ms, tftp_timeout_handler);
+               net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
                if (tftp_state != STATE_RECV_WRQ)
                        tftp_send();
        }
@@ -707,12 +709,12 @@ void tftp_start(enum proto_t protocol)
 
        ep = getenv("tftptimeout");
        if (ep != NULL)
-               timeout_ms = simple_strtol(ep, NULL, 10);
+               timeout_ms = simple_strtol(ep, NULL, 10) * 1000;
 
-       if (timeout_ms < 1000) {
-               printf("TFTP timeout (%ld ms) too low, set min = 1000 ms\n",
-                      timeout_ms);
-               timeout_ms = 1000;
+       if (timeout_ms < TIMEOUT) {
+               printf("TFTP timeout (%lu s) too low, set min = %lu s\n",
+                       timeout_ms / 1000, TIMEOUT / 1000);
+               timeout_ms = TIMEOUT;
        }
 
        debug("TFTP blocksize = %i, timeout = %ld ms\n",
@@ -794,7 +796,7 @@ void tftp_start(enum proto_t protocol)
        time_start = get_timer(0);
        timeout_count_max = tftp_timeout_count_max;
 
-       NetSetTimeout(timeout_ms, tftp_timeout_handler);
+       net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
        net_set_udp_handler(tftp_handler);
 #ifdef CONFIG_CMD_TFTPPUT
        net_set_icmp_handler(icmp_handler);
@@ -843,7 +845,7 @@ void tftp_start_server(void)
        timeout_count_max = TIMEOUT_COUNT;
        timeout_count = 0;
        timeout_ms = TIMEOUT;
-       NetSetTimeout(timeout_ms, tftp_timeout_handler);
+       net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
 
        /* Revert tftp_block_size to dflt */
        tftp_block_size = TFTP_BLOCK_SIZE;
@@ -951,7 +953,7 @@ static void parse_multicast_oack(char *pkt, int len)
                        printf("Fail to set mcast, revert to TFTP\n");
                        tftp_mcast_disabled = 1;
                        mcast_cleanup();
-                       NetStartAgain();
+                       net_start_again();
                }
        }
        tftp_mcast_master_client = simple_strtoul((char *)mc, NULL, 10);