Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate: Ariadne Misuses W5100 and W5200 #19

Closed
phillipjohnston opened this issue Dec 12, 2019 · 2 comments · Fixed by #89
Closed

Investigate: Ariadne Misuses W5100 and W5200 #19

phillipjohnston opened this issue Dec 12, 2019 · 2 comments · Fixed by #89
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@phillipjohnston
Copy link
Member

From original project:

From @davidhaenggi on February 9, 2015 14:40
Hi
I downloaded the Ariadne-Bootloader to use it with a OpenMediaController.
It's based on a Atmega2560 and includes a Wiznet W5100 ethernet chip.
In general the bootloader works great, thanks for the nice work.
While trying to upload bigger firmware files I was running into the "64-Package" Problem.
For me it looks like the arduino is receiving a completely messed up message instead of package number 64. When it tries to read the source IP address of the package it gets some random IP and therefor tries to send a response to this random IP. Thats why the Wiznet chip tries to reach to gateway, because the random IP is not in its IP range.

  • The solution to set the gateway address to the same IP as the TFTP client was not satisfying to me, as I would like to send firmwares from different client-IPs.
  • As a workaround I did some modification to the code:
  1. Don't set return IP address and port if the message is not a valid tftp message. I moved the regarding code to the end of funtion processPacket() and add some validation check.
-  // Set up return IP address and port
    * uint8_t i;
    * for(i = 0; i < 6; i++) spiWriteReg(REG_S3_DIPR0 + i, buffer[i]);
+ // only set return address if paket received is wellformed, to avoid sending to random IP address.
    * if(returnCode != ERROR_INVALID && returnCode != ERROR_UNKNOWN){
    * // Set up return IP address and port
    * uint8_t i;
    * for(i = 0; i < 6; i++) spiWriteReg(REG_S3_DIPR0 + i, buffer[i]);
    * }
  1. And I added the same validation check before sending any response messages in tftpPoll().
+ if(response != ERROR_INVALID && response != ERROR_UNKNOWN)
sendResponse(response);

Like this the arduino does not send any error for packet 64. The client repeats the packet and the transfer continues. With this changes I was able to set the TFTP_PACKET_DELAY to 0 and have a fast tftp transfer without any failures.
I know this is not a proper solution, but it works for me and I thought it may help someone.

@phillipjohnston phillipjohnston added bug Something isn't working help wanted Extra attention is needed labels Dec 12, 2019
@hagaigold
Copy link
Contributor

hagaigold commented Jan 13, 2022

this is probably because of misuses of the RX Read Pointer Register (REG_S3_RX_RD0) and the TX Write Pointer Register (REG_S3_TX_WR0).

this was reported by @MarekLew here and then copy to here

A suggested fix can be found in misuses-Read-and-Write-Pointers branch
diff: hagaigold/athena-bootloader@master...fix/misuses-Read-and-Write-Pointers

Currently, I don't have a W5100 (or W5200), so it has still not been tested

@hagaigold
Copy link
Contributor

hagaigold commented Jan 21, 2022

Currently, I don't have a W5100 (or W5200), so it has still not been tested

Tested with Mega+W5100.
This fix helps resolve issue #18 as well- when working properly with the WIZnet chip, we can decrease TFTP_PACKET_DELAY.

Attached are logs with the issue and without, after applying the suggested fix:
Mega_w5100_bigimage_working.txt
Mega_w5100_bigimage_fail.txt

the issue is obvious if you follow the message Processing packet of size nnnn:

[2022-01-20 20:39:40.326] Tftp: Processing packet of size 0x8A0C
[2022-01-20 20:39:40.326] Tftp: Overflow
[2022-01-20 20:39:40.341] Tftp: Set up return address
[2022-01-20 20:39:40.341] Tftp: This is block 0x0002 with opcode 0x0003 and data length 0x0200
[2022-01-20 20:39:40.341] Tftp: Data block
[2022-01-20 20:39:40.341] Tftp: Writing data from address 0x000200
[2022-01-20 20:39:40.357] Tftp: Packet length adjusted to 0x0200
[2022-01-20 20:39:40.373] Tftp: Sent ACK
[2022-01-20 20:39:40.373] Tftp: Response sent
[2022-01-20 20:39:40.779] Tftp: Processing packet of size 0x8A0C
[2022-01-20 20:39:40.779] Tftp: Overflow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants