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 addresses for jtag3_pdi boot and apptable #1887

Merged
merged 3 commits into from
Aug 14, 2024

Conversation

stefanrueger
Copy link
Collaborator

Might fix a bug discovered here.

@MCUdude The jtag3.c code looks like it would never have worked on apptable and boot memories what with jtag3_mtype() not even considering the memory just the address and jtag3_memaddr() making no distinction between a flash and an apptable/boot memory.

@stefanrueger stefanrueger added the bug Something isn't working label Aug 13, 2024
@MCUdude
Copy link
Collaborator

MCUdude commented Aug 13, 2024

It works, neat!

$ avrdude -cpickit4_pdi -patxmega128a3u -T 'read apptable'
Reading | ################################################## | 100% 0.10 s 
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

Avrdude done.  Thank you.

$ avrdude -cpickit4_pdi -patxmega128a3u -T 'write apptable 0 "Apptable test"'
Caching | ################################################## | 100% 0.10 s 
Synching cache to device ... 
Writing | ################################################## | 100% 0.19 s 

Avrdude done.  Thank you.

$ avrdude -cpickit4_pdi -patxmega128a3u -T 'read apptable'
Reading | ################################################## | 100% 0.10 s 
0000  41 70 70 74 61 62 6c 65  20 74 65 73 74 00 ff ff  |Apptable test...|
0010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
0090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

Avrdude done.  Thank you.

@MCUdude
Copy link
Collaborator

MCUdude commented Aug 13, 2024

This PR seems to break flash writing when using the Xplained Pro and the ATmega256RFR2:

$ avrdude -cxplainedpro_jtag -patmega256rfr2 -t
avrdude> read flash
Reading | ################################################## | 100% 0.02 s 
00000  48 65 6c 6c 6f 00 ff ff  ff ff ff ff ff ff ff ff  |Hello...........|
00010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00020  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00040  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|

avrdude> write flash 0x80 "hello test"
Caching | ################################################## | 100% 0.00 s 
avrdude> flush
Synching cache to device ... 
Writing | -------------------------------------------------- | 0% 0.02 s 
Error: flash access error at addr 0x0080
avrdude> q
Synching cache to device ... 
Writing | -------------------------------------------------- | 0% 0.02 s 
Error: flash access error at addr 0x0080
Synching cache to device ... 
Writing | -------------------------------------------------- | 0% 0.02 s 
Error: flash access error at addr 0x0080

Avrdude done.  Thank you.

Without this PR writing to flash works just fine

src/jtag3.c Outdated
unsigned long addr) {

return mem_is_boot(m)? MTYPE_BOOT_FLASH:
(mem_is_flash(m) && is_pdi(p) && addr >= PDATA(pgm)->boot_start)? MTYPE_BOOT_FLASH: MTYPE_FLASH;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the write issue for classic parts is caused by this return statement. MTYPE_FLASH_PAGE will never be returned.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. My initial suggestion caused -cpowerdebugger_jtag -patxmega256a3bu -T 'write flash 0 "Hello"' to fail.

return mem_is_boot(m)? MTYPE_BOOT_FLASH:
    (mem_is_flash(m) && is_pdi(p) && addr >= PDATA(pgm)->boot_start)? MTYPE_FLASH: MTYPE_FLASH_PAGE;

Can't we just revert back to:

 if (p->prog_modes & PM_PDI) {
    if (addr >= PDATA(pgm)->boot_start)
      return MTYPE_BOOT_FLASH;
    else
      return MTYPE_FLASH;
  } else {
    return MTYPE_FLASH_PAGE;
  }

Since this works perfectly fine, and is IMO easier to read?

Copy link
Collaborator

Choose a reason for hiding this comment

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

On closer inspection, I think this return statement should be OK. Note the addr < PDATA(pgm)->boot_start:

return mem_is_boot(m)? MTYPE_BOOT_FLASH:
    (mem_is_flash(m) && is_pdi(p) && addr < PDATA(pgm)->boot_start)? MTYPE_FLASH: MTYPE_FLASH_PAGE;

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this is some kind of Whack-a-Mole game. Even with the return statement fixed, The powerdebugger_jtag flash write progress suddenly freezes at 97% when flashing an ATxmega256A3BU.

I suggest fixing the issue mentioned in my previous post and then we can look into what's going on this time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note the addr < PDATA(pgm)->boot_start

Great find. What was I thinking?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have redone the fix in a different way and force-pushed that. Now all moles should be hiding incl tpi, isp, pdi, updi...

@stefanrueger stefanrueger merged commit 2b7c9de into avrdudes:main Aug 14, 2024
13 checks passed
@stefanrueger stefanrueger deleted the jtag3_pdi branch August 14, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants