pepe2k / u-boot_mod

U-Boot 1.1.4 modification for routers
GNU General Public License v2.0
1.08k stars 533 forks source link

Firmware uploading is interrupted randomly by some packets #258

Closed matlinuxer2 closed 1 year ago

matlinuxer2 commented 2 years ago

Descriptions:

Model: Tube-E4G (code base could be different than the latest upstream) Model info

When I uploaded a firmware smaller than 8MB(ex: Openwrt Tube-E4G image ), the process finished smoothly. But when I tried a larger firmware (ex: Alternative Image listed in ALFA docs site , 8.5MB) It failed often, around 80% failed.

Collected information:

I captured the packets logs with the wireshark. The log file is

2022-05-09_uboot-tube-e4g_analysis.log.pcapng.zip

I attach some screenshots for comparison here:

Failed case: reflash_failed

Success case: reflash_success

It looks like some TCP Dup ACK packets interrupt the process, but don't know what's cause this issue in the background. In my debug instance, the failed case's process didn't enter the block here: https://github.com/pepe2k/u-boot_mod/blob/ad5a2135bdba57454c1fb9fe4d8efd7b04d0cfe5/u-boot/httpd/httpd.c#L497

So far these are all clues I can get for now.

matlinuxer2 commented 2 years ago

After trace the issue more deeply, I found the root cause is not TCP Dup ACK but the http request length calculation issue. In some cases, it could be hs->upload is greater than hs->upload_total but the http request still not end.

https://github.com/pepe2k/u-boot_mod/blob/ad5a2135bdba57454c1fb9fe4d8efd7b04d0cfe5/u-boot/httpd/httpd.c#L568

The webfailsafe_post_done change and http_state_reset are trigged before the last packet arrived, which blocks the whole process.

To fix this issue, I add a patch to detect the http request end based on Content-Length parameter: https://github.com/matlinuxer2/u-boot_mod/commit/0c655af7bd502f186438ce891a559c95491303aa

I tested it with Tube-E4G and chrome on Linux, not sure it apply to other cases yet. Hope it helps

pepe2k commented 2 years ago

@matlinuxer2 please, share the binary U-Boot image.

matlinuxer2 commented 2 years ago

Hi @pepe2k I attached the tested bootloader below:

bootloader_binaries.zip

I also split my changes into 3 commits, which could be easier to review and filter debug-only parts, commits are here:

https://github.com/matlinuxer2/u-boot_mod/tree/fix_web_failsafe_stall

The captured logs I upload below:

success_firefox.zip failed_firefox.zip patched_firefox.zip failed_chrome.zip success_chrome.zip failed_curl.zip success_curl.zip

pepe2k commented 1 year ago

Sorry but this project is no longer maintained.