-
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
avrftdi.c: paged write can fail at addr 0 #1073
Comments
The paged read write/routines (which in this case call the function you try to fix) are not meant to be called with less than page size length. And I don't think AVRDUDE ever calls them with anything different from mem->page_size or mem->readsize/blocksize. Could you give an example hex file and AVRDUDE command that fails, so we can reproduce. The suggested change pretends there was a non-0xff byte in the buffer when there might be none. Not sure this is a cure. |
Dear mcuee and stefanrueger, I attached patched/no-patched log with avrdude commands(verbose level was -v -v -v). Please comfirm this. |
Indeed I can reproduce with the 202B test hex file in the zip file.
|
Then I tried the patch mentione in #303 but it does not seem to help.
|
Then I tried @nemuisan's patch and it does seem to sort out the issue. But if I read @stefanrueger's reply correctly, there may be other issue in the code so the fix may not be complete.
|
#303 patch was too old and not suitable for newest dude commit. |
The problem is that the address and loop variables are unsigned. Downward loops with Lines 1062 to 1064 in 38aa131
addr-1 ticks over to the largest unsigned int (and nothing is larger than that).
The following would do the job
That is not sufficient, though. The
|
Well, actually it is sufficient to test
|
@stefanrueger
@nemuisan Please help to test as well. Do you agree with @stefanrueger's patch? |
See PR #1074 @nemuisan your patch was almost correct, the loop condition should have been |
@stefanrueger
Interestingly the current git only has issues with the test_202B.hex file but not the other two. PR #1074 is good for all three test cases.
No regression with old test file as well.
|
Same if I use offset of 0x100.
|
Interestingly this fixed the remaining issue from #425. Thanks.
|
@mcuee Thank you for extensive tests. Glad to know empty (only 0xff) are not harmful in FYI, the error occurred whenever the last byte in the first flash page was 0xff and the first page had (at least) one non-0xff byte elsewhere. In this case the first page would not be written. AVRDUDE fills unset bytes in a page with 0xff, so it can write full flash pages. This means that input flash files shorter than a page trigger that problem, too, which @nemuisan found out (thanks for reporting!).
This is not necessarily true. When I wrote this I had not considered that casts of unsigned variables ( Anyway, I since changed the wrong loop condition |
Not sure about this. The test input file contains a 0xff at byte 128 (counting from 1), ie, the last page of the input file, which is why this particular error has been triggered.
|
This is nice. Learned some about compiler implementation. Thanks. |
Thanks for pointing out the root cause. Yes I mean to say one of the remaining thing for issue #425 is to check why avrftdi still has issues with the test hex file since it should have fixed the issue caused by the mega commit which still affect the stk500v2 based programmers in the current git main. Ref: Just a summary of issue #425. The mega commit affects multiple programmers but some of them (like jtagmki, usbasp and usbtiny) have since fixed the issue. It does not seem to affect avr109 bootloader and STK500v1.
|
Dear stefanrueger, I tested your fix and got works fine. and continue to evaluate next patch #1074 |
I found possibly bug in avrftdi.c.
It impacts when do sector writes less than sector-size binary.
(e.g. write 202bytes into atmega1284p(256 sector size)
I suggest patch to fix this problem.
It prevents that invalid poll_index value if "addr(unsigned int)" is "0".
I met same problem for 9 yeas ago,using atmega1284p and JTAGKey2 till now.
#303
The text was updated successfully, but these errors were encountered: