Improving TFTP performance in U-boot and Linux for noisy environments


A project I worked on had terrible TFTP download speeds in u-boot due to poor cabling. The setup used Power-line communication (PLC) and the noisy environment caused a lot of timeouts. Adjusting timeout length didn't help too much but the TFTP server patch below did.

Basically for every TFTP data packet send a duplicate. The loss in bandwidth is well worth the performance hit that occurs when a missed packet times out and is re-sent.

--- tftp-hpa-5.2/tftp/tftp.c.orig 2024-11-29 10:21:34.691055755 -0600
+++ tftp-hpa-5.2/tftp/tftp.c 2024-11-29 10:21:44.610093754 -0600
@@ -110,6 +110,11 @@ void tftp_sendfile(int fd, const char *n
perror("tftp: sendto");
goto abort;
}
+
+ /* Send packet one more time just in case last packet didn't make it */
+ usleep(1000);
+ sendto(f, dp, size + 4, 0, &peeraddr.sa, SOCKLEN(&peeraddr));
+
read_ahead(file, convert);
for (;;) {
alarm(rexmtval);

This link below has an excellent write-up
https://lupyuen.github.io/articles/tftp2

Reach out to me at chadhewitt@gmail.com for source code and questions