-
Notifications
You must be signed in to change notification settings - Fork 139
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
Do STK500/arduino/xbee programmers fail EEPROM r/w for some parts? #967
Comments
I wonder how an attached STK500 (v1) programmer would suss out whether to expect from AVRDUDE a byte address (eg, ATmega128) or a word address (eg, ATmega328) for the (STK500-protocol) paged EEPROM access (which I guess will be emulated with EEPROM byte read/writes in the physical programmer). It's possible (in theory the firmware is told a device code), but not really plausible. I have managed to find a couple of sources for the AVRISP firmware: both clearly always expect word addresses (as does optiboot). So looks like the Currently, the tally programmers vs stk500.c stands at 2:0 Anyone with a real STK500v1 programmer and some of the above chips with more intel? |
If you're interested, I could get you a genuine STK500v1 firmware image for testing. ;-) |
Maybe I even have one STK that's still at v1, I'm not sure. I used to keep one as a reference … |
Thanks, but would need chips/boards of some of the 23 affected chips, too... So no, and best to leave that with the hardware experts :-). Actually, only the firmware source is needed (but I guess Atmel's will be closed?) But for me this is one more reason to write a dedicated SPM programmer for AVRDUDE that does not rely on the current stk500 implementation. In fact, I noticed this issue when looking through stk500.c to implement "backward compatibility" in that SPM programmer. |
So it is. All we've got is a binary blurb, to fit into the AT90S8535 on the STK. Please provide a few commands you'd like me to test, and I'll see whether I can run some tests. At least, ATmega8 and ATmega128, I do have some. |
Btw., I'd normally consider the STK500v1 protocol quite obsolete anyway. Atmel did that many years ago. ;-) Let's spend not too much time into such a dead horse. |
The stk500.c protocol implementation is used for some programmers and optiboot (with millions and millions of uploads), so we might as well get this right. It's probably more that EEPROM upload/download with the affected parts do not happen that often.
I'd generate a random hex file with as many bytes as the EEPROM holds (512 for the ATmega8, I think)
Upload that to the ATmega8's EEPROM; verification should fail. (Note if you do the same with a file that is half the EEPROM size then verification should pass, but the data would be at the wrong location.) Or, could prepare two different .hex files:
Upload Look at the eeprom with the reliable programmer:
Should be something like (but not literally so)
If the real STK500v1 programmer passes, I predict that AVRISP programmers fails the test. Optiboot does above when AVRDUDE pretends the 328p is an 8 using |
The "srec_cat" is not needed: AVRDUDE could always write raw binary files (file type "r").
I guess that is proof enough that the AVRDUDE stk500v1 protocol implementation matches an STK500v1 firmware … Device: ATmega8A (after all, they're still in production), STK500 firmware version 1.14 (decimal, as usually in AVRDUDE). I believe that to be the latest V1 firmware. I just keep the firmware in the STK until tonight, in case you'd like me to perform more tests. Afterwards, will reflash it to V2. |
Just wondering how I can check if an STK500 is of V1 or V2 firmware. I have found an unused genuine Atmel STK500 from 2006 (or earlier?) and it does not seem to work with either avrdude (error message: |
If you call AVRDUDE with |
Btw., IMHO AVRDUDE's STK500v1 protocol implementation mostly wraps around the |
Cool! And thanks for going to the trouble of verifying that. Which makes dealing with the derived AVRDUDE programmers somewhat harder, because the attached programmers (AVRISP, ATmega8 boards with optiboot's vector bootloader, ...) don't for a moment think that any STK500v1 address could be a byte address:
I know what modification in |
... and read from pipeline. Cool. I initially tried constructing a pattern and pipe with the file type "d", which does not allow reads:
|
It would be interesting to dig out an old version of AVR Studio (4.something), and see what it does when being faced with such a bootloader. |
Does the STK500 v1 communication protocol can explain the question? Or we really have to test on a real STK500 with V1 FW? STK500 v2 is also documented. |
That's what I did. |
Now the thing is that probably there is no real need to support real STK500 with V1 protocol any more since it has be obsolete for many years (only V2 support is needed, V2 FW was distributed with AVR Studio 4.11 build 401 or later), that probably means in 2005. The things to support is the derived programmers which may not exactly follow the STK500 v1 protocol to the letter. Does this make the solution a bit easier? |
Then you need really old version of Atmel Studio (prior to 4.11 build 401) which is no longer available from Atmel/Microchip (earliest version is 4.13). Google does find a link. Not so sure how good the Russian link mentioned in the forum post is good or not. |
@mcuee Atmel's STK500 v1 docu is non-committal about whether the addresses are byte or word addresses and certainly does not say anything about which memories of which parts will be treated as what. Whoever wrote the lines Lines 819 to 822 in 4601bee
clearly knew something that cannot be augured from Atmel's 31 page v1 docu. In contrast to this, the STK500 v2 docu on this point is lucid, sane and simple: flash addresses to be sent as word addresses, all other memory addresses as byte addresses. Given the closed-source nature of Atmel's implementation of its protocol it is quite understandable that others have interpreted the protocol to mean both flash and EEPROM access is always done with word addresses. AVRDUE only invokes the programmer's *_paged_load() and *_paged_write() when the memory page size exceeds 1. It so turns out that only EEPROM r/w for Jörg has proven AVRDUDE's stk500 implementation correct in these cases. Well, the ATmega8A, but I take the extrapolation to the others as given. I see some possible solutions:
Thoughts? |
@stefanrueger Option 2 is of course okay as well but it is a bit wasted (kind of redundant codes). |
I have got avrdude 3.56 and 4.10 installed under Windows 11. Just wondering how to test this case. I have the official Arduino Leonardo board and clone Arduino Uno with CH340.
|
Doesn't have to be an arduino board to use Triggering the bootloader is its own artform. Most simply need to be reset shortly before talking to them (the main difference between Afraid I cannot help with windows driver etc to connect COMx to the various FTDI/CH340/CH330N/... chips. |
I'd be happy to do a PR for 1 or 2 if/when the current PRs are processed one way or another. The second option isn't too much code duplication, as the code base is vvv modular and requires essentially two functions to be overloaded (paged access). And it's neat because it is backwards compatible to very early and old programmer boards/FW. |
No problems. I am kind of cross-platform guy (at least Linux, macOS and Windows, sometimes also BSDs) since I carry out testing for cross-platform projects (eg: libusb, hidapi, libftdi, pyusb, libusbdotnet and OpenOCD). Interestingly I do not have problems to set the FTDI/CH340/CP2102/etc based USB to Serial Converter to use COM1/2/3/4 under Windows but not the two Arduino boards. Very strange. This seems to be an interesting question from @dl8dtl.
|
Good to know that. In that case, maybe Option 2 is better as we know that this types of bootloaders are not really the same as stk500v1, but rather a subset only. Ref: https://github.com/Optiboot/optiboot/wiki/HowOptibootWorks |
OK, seeing that this is the known Issue #421 we might consider doing nothing here. @dl8dtl has proven the I still think it is a good idea to provide an alternative programmer to |
Yes I agree. I beliver what I mentioned below in #970 is in line with what you are saying. Correct me if I am wrong. Thanks.
|
@mcuee So, you put Atmel's original FW version 1.x on your STK 500 kit, prepared an
What is returned by
|
Yes that is correct.
Note: |
Another test, using usbasp to write the eeprom correctly and then use STK500V1 to read back, the results are wrong.
|
Same problem for ATmega2560. This time the test is under Linux.
|
Looks like the issue has always been there. I went back to release 5.6 which is the first release to support ATmega328p and the issue is already there. I also tested 6.3, 6.01, 5.10 and checked that 5.4/5/5 do not support ATmega328p. Good thing is that all the old version can be built under Ubuntu 20.04, include version 4.4 and 5.0.
|
Using ATtiny13A and I can see that version 5.2 is broken and version 5.1 is fine. 5.2 is the first release version with STK500v1/v2 support. Both were released in 2006. I guess most of the people would upgarde the STK500 to V2 FW later.
|
@mcuee Thanks. This has now peeled off all layers in the software archeology going back to 2006, and would indicate that Lines 809 to 822 in 4601bee
is a bug in that the a_div initialisation should only apply to flash, where for EEPROM it should simply be a_div = 1 throughout.
It seems that the world (optiboot, arduino as as ISP, ...) has compensated for this bug by assuming AVRDUDE sends all EEPROM addresses as word address ( Given that piece of new info from @mcuee, I now also think Option 1 of #967 (comment) would best deal with the situation. This is how I would write it up in the code (twice, once for
Note that, somewhat unusually, this willfully makes the existing bug worse in the sense that the current implementation "only" fails paged EEPROM r/w for all but six SPI programmable parts with EEPROM If the bug was corrected now to reflect the gold reference STK500 FW v1.x, this would upset quite a few programmers that have adopted AVRDUDE's apparent implementation. Above automagically helps those (physical) programmer firmware implementations and optiboot that simply expect |
@WestfW's comments here is interesting.
|
@stefanrueger
@dl8dtl Any comments here? Thanks. |
Indeed the proposed patch (with
|
@stefanrueger |
I think the above does help the Arduino compatible bootloader and things like Reading test. git main failed. The patched version (with with
|
Write test using
|
I guess pure STK500v1 support is something that could be deprecated, indeed. I can't imagine a good reason for why not upgrade any (real) STK500 to v2. |
What does that mean WRT the STK500v1-subset used by bootloaders like Optiboot? |
@stefanrueger's options are as following.
So option 1 is to deprecate the "pure" STK500 v1" (usually genunine STK500 with V1 FW, or rare clones which support V1 FW), and then apply @stefanrueger's proposed fix ( Impact analysis by @stefanrueger for Option 1.
|
The proposed change is good for Optiboot. With that Those bootloader writers who understood better what AVRDUDE does and implemented EEPROM byte addresses for these six devices will see a "regression" problem. I think that's the minority (given the popularity of optiboot). |
Absolutely correct. On both accounts. Thanks for all the testing! |
@stefanrueger From @dl8dtl
|
Closed by PR #1046 |
Just an update, I got the simple ATmega8A core board and an Arduino AVR ISP Shield, and the test shows "Arduino as ISP" works fine now (failed if using the 7.0 release version). Verified using usbasp.
The release 7.0 version will fail.
|
Reading stk500.c I noticed that for paged load/writes typically word addresses are passed to the external programmer for both flash and EEPROM but under certain circumstances byte addresses (eg, for EEPROM access of parts without EEPROM loadpage SPI programming). Now, I don't have any STK500 programmer at hand, and more crucially neither their firmware source, but does the STK500 communication protocol really switch between word and byte addresses on such a condition without rhyme or reason?
If not, and it's always word addresses, then
avrdude -c stk500
should fail to properly read/write EEPROM of the following devices:ATtiny12
ATtiny15
AT90S1200
AT90S4414
AT90S2313
AT90S2333
AT90S2343
AT90S4433
AT90S4434
AT90S8515
AT90S8535
ATmega103
ATmega64
ATmega64A
ATmega128
ATmega128A
ATmega163
ATmega161
ATmega8
ATmega8A
ATmega8515
ATmega8535
ATtiny26
[edit: Actually, only affects
ATmega64
ATmega64A
ATmega128
ATmega128A
ATmega8
ATmega8A
, see Issue #970 and below]Also affects derived programmers, eg, arduino, xbee. I verified that
with an EEPROM enabled bootloader reads 512 bytes (as it should) but these are wrongly sourced from every other 4-byte page of the 1024 byte EEPROM on the connected 328p (obvs you'd have to store some suitable pattern in the EEPROM to notice).
If stk500.c is right (and my suspicion wrong) then optiboot would need do something about EEPROM addresses of the parts mentioned...
The text was updated successfully, but these errors were encountered: