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

Fix stk500v2 READ_EEPROM to properly read EEPROM #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mlasevich
Copy link

Fix for #23. READ_EEPROM was not reading EEPROM correctly, assuming each EEPROM address points to a 16bit location, but reading only 8 bit, so it would return every other byte.

This fixes it to read every byte correctly.

(This was originally submitted as arduino/Arduino#6456 before the code was split off of that repo. Re-submitting so that it goes against right repo)

Copy link
Collaborator

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused with this change, which seems to somehow do the inverse of what you describe at first. Digging deeper, I think the problem here is:

  • LOAD_ADDRESS doubles the passed address before putting it into the address variable.
  • This doubling makes sense for flash, since that passes word addresses to LOAD_ADDRESS and this doubling makes it a byte address.
  • This doubling makes no sense for eeprom, since there you already pass a byte address. Effectively, your patch undoes the doubling, by halving the address before using it.

I wonder if this is the right fix, since it makes things complicated. IMHO it could be better to instead not do the doubling in LOAD_ADDRESS, but only when access flash, so it is only applied when needed.

Also, I'm not sure if this particular bootloader is still being updated. I can imagine that if a new bootloader version is going to be used for the Mega2560 (Which, I think, is the board that uses this bootloader), it will switch to optiboot instead (which has support for the 2560 since a while).

@facchinm, perhaps you can comment about that?

@facchinm
Copy link
Member

We normally update bootloaders on the repo only when the boards are being factory flashed with that bootloader.
The validation phase usually requires quite a long time and it's rather unusual to "live patch" a board except for special cases (like Nano's WDT problem).
Moreover, I'd say that we'd probably switch to optiboot for the 2560 if we change the BL in production.

@mlasevich
Copy link
Author

@matthijskooijman I am by no means intimately familiar with this bootloader code. I simply came across what seemed like a pretty severe (to me, at least) bug and tried to fix it with minimum code changes to minimize potential impact to other things. I would not be surprised if there is a better way to fix this, and what you describe makes prefect sense, I was just not comfortable enough to be making larger scale changes, since I was not sure what I might break...

@facchinm I understand your point, but it has been a year and a half since I reported this, and still, a bootloader that is not capable of reading EEPROM without corrupting it is shipped on every new 2560 board(though I am not sure where that comes from), as well as is included with Arduino IDE/SDK.

That said, this has been out for years and years, and in all that time I do not think I have seen anyone else mention or be concerned about this problem - so perhaps nobody besides me really wants to read EEPROM via bootloader or cares that this is broken - so maybe this is all moot :-)

@CLAassistant
Copy link

CLAassistant commented Apr 9, 2021

CLA assistant check
All committers have signed the CLA.

phlebos pushed a commit to phlebos/ArduinoCore-avr that referenced this pull request May 24, 2022
@mcuee
Copy link

mcuee commented Jun 3, 2022

This may be related. It does not seem to be an avrdude issue but rather the issue of the bootloader.

@mcuee
Copy link

mcuee commented Jun 4, 2022

Ref: yes the following is exactly because of the long standing bug in the bootloader.

Moreover, I'd say that we'd probably switch to optiboot for the 2560 if we change the BL in production.

This was mentioned on 26-Nov-2018, and now it is June 2022. So it seems this will not happen any time soon.

@mcuee
Copy link

mcuee commented Jun 5, 2022

@mlasevich @facchinm Yes I can confirm that this pull request fixed the EEPROM read issue.

Ref: run log and hex file here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stk500v2 bootloader corrupts data when reading EEPROM stk500v2 bootloader corrupts data when reading EEPROM
6 participants