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

Introduce memory types in lieu of string comparisons with memory names #1538

Merged
merged 23 commits into from
Nov 3, 2023

Conversation

stefanrueger
Copy link
Collaborator

Fixes #1330

This PR introduces an integer memory component type that encodes the memory type and some of its attributes in bitfields allowing us to separate the name of a memory from its function. This means that instead of a string compare with the memory name, AVRDUDE now bases its programming strategy on testing bits in the type integer.

Nothing in the functionality has changed, and actually the type bits are still determined by the memory name, albeit once when parsing the avrdude.conf file rather than 391 times in 30 source files. There is now only a small step left of externalising the type in avrdude.conf and fully separating name from function but this is not part of this PR.

This is one of the unthankful PRs that do not improve functionality but that attempt to bring clarity to the role and properties of the memories that AVRDUDE deals with. As such this needs a careful review (@MCUdude?) and good testing (@mcuee?) as virtually all programmers will have seen a code change.

The first thing to look at is how memory types are modelled in avr.c. The other, perhaps, how the new type is accessed in libavrdude.h macros.

Most of the string comparisons could be replaced automatically with bit tests, but the fuses were dealt with mostly by hand.

The name memtype can mean different things in the AVRDUDE src.
Mostly it means the name string of the memory, eg, "flash" or
"eeprom"; sometimes it is a character designating a memory, eg, 'E'
for "eeprom"; and yet at other times it means a programmer-defined
memory type, eg, MTYPE_BOOT_FLASH. The occurrences of memtype in
the code have now neen renamed appropriately.
@mcuee mcuee added the enhancement New feature or request label Oct 26, 2023
@MCUdude
Copy link
Collaborator

MCUdude commented Oct 27, 2023

Thanks for the PR! I'll read through it carefully and see if I can spot something that seems odd. However, what would have to be someday next week, because I'm away (without my computer) this weekend.

@mcuee
Copy link
Collaborator

mcuee commented Oct 27, 2023

I will carry out some simple tests as part of my tests toward 7.3 release.

@mcuee
Copy link
Collaborator

mcuee commented Oct 27, 2023

My first test shows the results are positive: no behavior differences between this PR and git main.

I am tesing the MinGW build sleep issue of serialupdi and this PR has the same results as git main:

  1. mingw64build: without -v it works, with -v it will fail
  2. VS2022 build: no issues with -v and -vvvv.

@mcuee
Copy link
Collaborator

mcuee commented Oct 29, 2023

Second simple tests using -c urclock or -c arduino are also positive, using an Arduino Nano CH340 clone.

Edit: need to redo the test with the correct avrdude.conf file.
Edit: it is still okay.

`P> .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c urclock -P ch340 -p m328p -qq -xshowall
0000ffffffff 0000-00-00 00.00  application 0 store 0 meta 1 boot 512 
u7.7 wes-hprac vector 0 (RESET) ATmega328P

P> .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c urclock -P ch340 -p m328p 
-U .\hex3\blink_m328p_readback.hex -qq && echo OK
OK

PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c arduino -P ch340 -p m328p 
-U .\hex3\blink_m328p_readback.hex -qq && echo OK
OK

PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c urclock -P ch340 -p m328p 
-U .\hex3\blink_m328p_readback.hex -qq && echo OK
OK

PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c urclock -P ch340 -p m328p -qq -xshowall
0000ffffffff 2022-11-16 19.36 blink_m328p_readback.hex 960 store 31260 meta 36 boot 512 
u7.7 wes-hprac vector 0 (RESET) ATmega328P

@mcuee
Copy link
Collaborator

mcuee commented Oct 29, 2023

-c usbasp is also fine.

Edit: need to redo the test with the correct avrdude.conf file.
Edit: it is still okay.

PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c usbasp -p m328p 
-U .\urboot_m328p_1s_autobaud_uart0_rxd0_txd1_led+b5_ee_ce_hw_stk500.hex -qq && echo OK
OK

PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c urclock -P ch340 -p m328p 
-U .\hex3\blink_m328p_readback.hex -qq && echo OK
OK

P> .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c urclock -P ch340 -p m328p -qq -xshowall
0000ffffffff 2022-11-16 19.36 blink_m328p_readback.hex 960 store 31260 meta 36 boot 512 
u7.7 wes-hprac vector 0 (RESET) ATmega328P

PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -p m328p -c usbasp -qqt
avrdude> dump calibration
0000  93                                                |.               |
avrdude> dump io
avrdude_pr1538 error: (dump) error reading io address 0x00000 of part ATmega328P
                      read operation not supported on memory io
avrdude> dump lock
0000  ff                                                |.               |
avrdude> dump lfuse
0000  ff                                                |.               |
avrdude> dump hfuse
0000  de                                                |.               |
avrdude> dump efuse
0000  fd                                                |.               |
avrdude> dump signature
0000  1e 95 0f                                          |...             |
avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Oct 29, 2023

jtag2updi may be a bit strange. It seems to fix some issues of git main but create some new issues.
Edit: I will redo jtag2updi test later.

serialupdi is also okay.

PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c serialupdi -p avr64dd32 -P ch340 -qqt
avrdude> dump fuses
0000  00 00 00 ff ff d0 08 00  00 ff ff ff ff ff ff ff  |................|
avrdude> dump prodsig
0000  1e 96 1a ff 7e 03 a4 0d  ff ff ff ff ff ff ff ff  |....~.. ........|
0010  42 22 53 61 51 00 55 16  01 07 01 46 00 00 00 00  |B"SaQ.U....F....|
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  74 36 e3 00 cb ae 97 ff  ff ff dd fe ff ff ff ff  |t6..............|
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  aa 55 aa 55 ff ff ff ff  |.........U.U....|
avrdude> dump data
avrdude_pr1538 error: (dump) cannot read memory data of size 0
avrdude> dump io
0000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0010  00 00 00 00 00 00 80 00  00 00 00 00 00 00 00 00  |................|
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 ff 7f 35  |...............5|
0040  21 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |!...............|
0050  00 00 00 00 44 76 0e 00  00 00 00 00 00 00 00 00  |....Dv..........|
0060  00 00 00 00 00 02 00 01  0c 00 00 00 27 02 12 00  |........ ...'...|
0070  01 00 00 00 00 06 00 00  00 1e 00 00 00 00 00 00  |................|
0080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00a0  00 00 14 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00b0  00 00 00 00 00 00 5c 00  00 00 00 00 00 00 00 00  |......\.........|
00c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> dump sib
0000  41 56 52 20 20 20 20 20  50 3a 32 44 3a 31 2d 33  |AVR     P:2D:1-3|
0010  4d 32 20 28 41 33 2e 4b  56 30 30 4b 2e 30 29 00  |M2 (A3.KV00K.0).|
avrdude> dump userrow
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  |................|
avrdude> dump tempsense
0000  7e 03 a4 0d                                       |~..             |
avrdude> dump sernum
0000  42 22 53 61 51 00 55 16  01 07 01 46 00 00 00 00  |B"SaQ.U....F....|
avrdude> dump lock
0000  5c c5 c5 5c                                       |\..\            |
avrdude> quit

git main.

PS>.\avrdude_git -c serialupdi -p avr64dd32 -P ch340 -qqt
avrdude> dump fuses
0000  00 00 00 ff ff d0 08 00  00 ff ff ff ff ff ff ff  |................|
avrdude> dump prodsig
0000  1e 96 1a ff 7e 03 a4 0d  ff ff ff ff ff ff ff ff  |....~.. ........|
0010  42 22 53 61 51 00 55 16  01 07 01 46 00 00 00 00  |B"SaQ.U....F....|
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  74 36 e3 00 cb ae 97 ff  ff ff dd fe ff ff ff ff  |t6..............|
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  aa 55 aa 55 ff ff ff ff  |.........U.U....|
avrdude> dump data
avrdude_git error: (dump) cannot read memory data of size 0
avrdude> dump io
0000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0010  00 00 00 00 00 00 80 00  00 00 00 00 00 00 00 00  |................|
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 ff 7f 35  |...............5|
0040  21 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |!...............|
0050  00 00 00 00 44 76 0e 00  00 00 00 00 00 00 00 00  |....Dv..........|
0060  00 00 00 00 00 02 00 01  0c 00 00 00 27 02 12 00  |........ ...'...|
0070  01 00 00 00 00 06 00 00  00 1e 00 00 00 00 00 00  |................|
0080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00a0  00 00 14 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00b0  00 00 00 00 00 00 5c 00  00 00 00 00 00 00 00 00  |......\.........|
00c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> dump sib
0000  41 56 52 20 20 20 20 20  50 3a 32 44 3a 31 2d 33  |AVR     P:2D:1-3|
0010  4d 32 20 28 41 33 2e 4b  56 30 30 4b 2e 30 29 00  |M2 (A3.KV00K.0).|
avrdude> dump tempsense
0000  7e 03 a4 0d                                       |~..             |
avrdude> dump userrow
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  |................|
avrdude> dump sernum
0000  42 22 53 61 51 00 55 16  01 07 01 46 00 00 00 00  |B"SaQ.U....F....|
avrdude> dump lock
0000  5c c5 c5 5c                                       |\..\            |
avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Oct 29, 2023

jtag2updi using Arduino Nano Every (offical version from Arduino) -- this PR behaves the same as git main.

Note: ignore the timeout as this is a known issue for Windows terminal mode using MinGW and GNU Readline.

This PR.

PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c jtag2updi -p m4809 -P COM12 -qqt -r
avrdude> dump fuses
0000  00 54 01 ff 00 c9 06 00  02 ff                    |.T........      |
avrdude> dump prodsig
0000  1e 96 51 30 42 42 37 52  41 cc 80 22 06 ff 44 0e  |..Q0BB7RA.."..D.|
0010  06 ff ff ff 13 06 aa 05  aa 05 29 05 29 05 ef f8  |..........).)...|
0020  92 f3 00 00 ff fe 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  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> dump data
avrdude_pr1538 error: (dump) cannot read memory data of size 0
avrdude> dump io
0000  00 00 f6 00 00 00 3f 00  00 00 f3 00 00 00 37 00  |......?.......7.|
0010  00 00 0b 00 00 00 76 00  00 00 00 00 00 00 00 00  |.. ...v.........|
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 ff 3f 02  |..............?.|
0040  20 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  | ...............|
0050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0060  00 07 00 10 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0070  00 aa 05 00 00 06 00 00  00 13 00 00 00 00 00 00  |................|
0080  04 02 06 02 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0090  00 44 0e 00 00 00 00 00  00 00 00 00 00 00 00 00  |.D..............|
00a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00b0  21 31 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |!1..............|
00c0  00 00 00 00 00 00 ff bf  00 00 00 00 00 00 00 00  |................|
00d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> dump sib
avrdude_pr1538 error: unknown memory sib
avrdude_pr1538 error: (dump) error reading sib address 0x00000 of part ATmega4809
                      read operation not supported on memory sib
avrdude> dump userrow
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  |................|
avrdude> dump tempsense
avrdude_pr1538 error: unknown memory tempsense
avrdude_pr1538 error: (dump) error reading tempsense address 0x00000 of part ATmega4809
                      read operation not supported on memory tempsense
avrdude> dump sernum
avrdude_pr1538 error: unknown memory sernum
avrdude_pr1538 error: (dump) error reading sernum address 0x00000 of part ATmega4809
                      read operation not supported on memory sernum
avrdude> dump lock
avrdude_pr1538 warning: timeout/error communicating with programmer (status -1)
avrdude_pr1538 warning: timeout/error communicating with programmer (status -1)
avrdude_pr1538 warning: timeout/error communicating with programmer (status -1)
avrdude_pr1538 warning: timeout/error communicating with programmer (status -1)
avrdude_pr1538 error: timeout/error communicating with programmer (status -1)
avrdude_pr1538 error: (dump) error reading lock address 0x00000 of part ATmega4809
                      read operation not supported on memory lock
avrdude> quit
avrdude_pr1538 error: timeout/error communicating with programmer (status -1)
CTRL-C
PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c jtag2updi -p m4809 -P COM12 -qqt -r
avrdude> dump lock
0000  c5                                                |.               |
avrdude> quit

git main

PS>.\avrdude_git -c jtag2updi -p m4809 -P COM12 -qqt -r
avrdude> dump fuses
0000  00 54 01 ff 00 c9 06 00  02 ff                    |.T........      |
avrdude> dump prodsig
0000  1e 96 51 30 42 42 37 52  41 cc 80 22 06 ff 44 0e  |..Q0BB7RA.."..D.|
0010  06 ff ff ff 13 06 aa 05  aa 05 29 05 29 05 ef f8  |..........).)...|
0020  92 f3 00 00 ff fe 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  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> dump data
avrdude_git error: (dump) cannot read memory data of size 0
avrdude> dump io
0000  00 00 f6 00 00 00 3d 00  00 00 f3 00 00 00 37 00  |......=.......7.|
0010  00 00 0b 00 00 00 76 00  00 00 00 00 00 00 00 00  |.. ...v.........|
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 ff 3f 02  |..............?.|
0040  20 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  | ...............|
0050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0060  00 07 00 10 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0070  00 aa 05 00 00 06 00 00  00 13 00 00 00 00 00 00  |................|
0080  04 02 06 02 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0090  00 44 0e 00 00 00 00 00  00 00 00 00 00 00 00 00  |.D..............|
00a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00b0  21 31 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |!1..............|
00c0  00 00 00 00 00 00 ff bf  00 00 00 00 00 00 00 00  |................|
00d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> dump sib
avrdude_git error: unknown memory sib in jtagmkII_read_byte()
avrdude_git error: (dump) error reading sib address 0x00000 of part ATmega4809
                   read operation not supported on memory type sib
avrdude> dump userrow
avrdude_git warning: timeout/error communicating with programmer (status -1)
avrdude_git warning: timeout/error communicating with programmer (status -1)
avrdude_git warning: timeout/error communicating with programmer (status -1)
avrdude_git warning: timeout/error communicating with programmer (status -1)
avrdude_git warning: timeout/error communicating with programmer (status -1)
avrdude_git error: timeout/error communicating with programmer (status -1)
avrdude_git warning: timeout/error communicating with programmer (status -1)
CTRL-C
PS>.\avrdude_git -c jtag2updi -p m4809 -P COM12 -qqt -r
avrdude> dump userrow
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  |................|
avrdude> dump tempsense
avrdude_git error: unknown memory tempsense in jtagmkII_read_byte()
avrdude_git error: (dump) error reading tempsense address 0x00000 of part ATmega4809
                   read operation not supported on memory type tempsense
avrdude> dump sernum
avrdude_git error: unknown memory sernum in jtagmkII_read_byte()
avrdude_git error: (dump) error reading sernum address 0x00000 of part ATmega4809
                   read operation not supported on memory type sernum
avrdude> dump lock
0000  c5                                                |.               |
avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Oct 29, 2023

Tested jtag2updi again with Nano 4808 and it behaves the same as git main as well.

src/jtag3.c Outdated
u32_to_b4(xd.nvm_fuse_offset, m->offset & ~15);
} else if (str_starts(m->desc, "lock")) {
} else if (mem_is_a_fuse(m) && !fuseinit++) { // Any fuse is OK
u32_to_b4(xd.nvm_fuse_offset, m->offset & ~15);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indent accidentally added?

Copy link
Collaborator

@MCUdude MCUdude left a comment

Choose a reason for hiding this comment

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

I've read through the entire PR, and I've not seen a single error.
I think this is safe to merge as is, but I'd like to double-check that the way stk500v2.c deals with fuse memory offsets works as intended.

Excellent work @stefanrueger!

@mcuee
Copy link
Collaborator

mcuee commented Oct 29, 2023

Simple test using AVR ISPmkII clone and ATmega2560 -- looks okay.

PS C:\work\avr\avrdude_test\avrdude_bin> function prompt {$null}
PS>.\avrdude_pr1538 -C .\avrdude_pr1538.conf -c avrispmkii -p m2560 -qqt
avrdude> dump lfuse
0000  f7                                                |.               |
avrdude> dump efuse
0000  fd                                                |.               |
avrdude> dump lock
0000  ff                                                |.               |
avrdude> dump signature
0000  1e 98 01                                          |...             |
avrdude> dump calibration
0000  85                                                |.               |
avrdude> dump io
avrdude_pr1538 error: unsupported memory io
avrdude_pr1538 error: (dump) error reading io address 0x00000 of part ATmega2560
                      read operation not supported on memory io
avrdude> dump eeprom 0 0x10
0000  55 55 55 55 71 75 69 63  aa aa aa aa aa aa aa aa  |UUUUquic........|
avrdude> dump flash 0 0x10
00000  76 c0 00 00 86 c0 00 00  84 c0 00 00 82 c0 00 00  |v...............|
avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Oct 29, 2023

Simple test using the wiring bootloader and ATmega2560 -- results are good as well. I have to use pipes to avoid time out in terminal mode.

P> echo "dump hfuse" | .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c wiring -P COM4 -p m2560 -qqt
avrdude> dump hfuse
0000  d0                                                |.               |
avrdude>
PS>echo "dump lfuse" | .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c wiring -P COM4 -p m2560 -qqt
avrdude> dump lfuse
0000  f7                                                |.               |
avrdude>
PS>echo "dump hfuse" | .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c wiring -P COM4 -p m2560 -qqt
avrdude> dump hfuse
0000  d0                                                |.               |
avrdude>
PS>echo "dump efuse" | .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c wiring -P COM4 -p m2560 -qqt
avrdude> dump efuse
0000  fd                                                |.               |
avrdude>
PS>echo "dump lock" | .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c wiring -P COM4 -p m2560 -qqt
avrdude> dump lock
0000  ff                                                |.               |
avrdude>
PS>echo "dump signature" | .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c wiring -P COM4 -p m2560 -qqt
avrdude> dump signature
0000  1e 98 01                                          |...             |
avrdude>
PS>echo "dump calibration" | .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c wiring -P COM4 -p m2560 -qqt
avrdude> dump calibration
avrdude_pr1538 error: command failed
avrdude_pr1538 error: timeout/error communicating with programmer
avrdude_pr1538 error: (dump) error reading calibration address 0x00000 of part ATmega2560
                      read operation not supported on memory calibration
avrdude>
PS>echo "dump io" | .\avrdude_pr1538 -C .\avrdude_pr1538.conf -c wiring -P COM4 -p m2560 -qqt
avrdude> dump io
avrdude_pr1538 error: unsupported memory io
avrdude_pr1538 error: (dump) error reading io address 0x00000 of part ATmega2560
                      read operation not supported on memory io
avrdude>

@mcuee
Copy link
Collaborator

mcuee commented Oct 29, 2023

I've read through the entire PR, and I've not seen a single error. I think this is safe to merge as is, but I'd like to double-check that the way stk500v2.c deals with fuse memory offsets works as intended.

Excellent work @stefanrueger!

Indeed!

This PR should be good to go from my side.

Rather than finding memories by name this finds memories by the correct
type further separating memory names from their functionality.

Also fixes a few unchecked avr_locate_mem() calls that could lead to
segmentation faults.
@stefanrueger
Copy link
Collaborator Author

Thanks for testing and reviewing @MCUdude and @mcuee. I have left the PR open b/c @MCUdude wanted to test stk500v2 programmers, and I have pushed one commit onto this PR to fix #1544 rather than a new PR (to avoid merge conflicts).

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 30, 2023

@stefanrueger your last commit looks good as well. I'll do a little more testing this evening just to be sure.

@mcuee
Copy link
Collaborator

mcuee commented Oct 30, 2023

Sanity check with latest commit: no regression compared to git main when it comes to using old config file.

PS>.\avrdude_pr1538v1 -C .\avrdude_pr1538v1.conf -c urclock -P ch340 -p m328p -qq -xshowall
00006420797a 2022-10-17 09.23 Blink_Uno.ino.hex 924 store 31431 meta 29 boot 384 u7.7 weu-jPrac 
vector 25 (SPM_Ready) ATmega328P

PS>.\avrdude_pr1538v1 -C .\avrdude72.conf -c urclock -P ch340 -p m328p -qq -xshowall
avrdude_pr1538v1 error: cannot open port ch340: The system cannot find the file specified.

avrdude_pr1538v1 error: unable to open port ch340 for programmer urclock
Possible candidate serial ports are:
  -P COM3
  -P COM4 or -P usb:1a86:7523
Note that above ports might not be connected to a target board or an AVR programmer.
Also note there may be other direct serial ports not listed above.

PS>.\avrdude_pr1538v1 -C .\avrdude72.conf -c urclock -P COM4 -p m328p -qq -xshowall
00006420797a 2022-10-17 09.23 Blink_Uno.ino.hex 924 store 31431 meta 29 boot 384 u7.7 weu-jPrac 
vector 25 (SPM_Ready) ATmega328P

PS>.\avrdude_git -C .\avrdude72.conf -c urclock -P ch340 -p m328p -qq -xshowall
avrdude_git error: cannot open port ch340: The system cannot find the file specified.

avrdude_git error: unable to open port ch340 for programmer urclock
Possible candidate serial ports are:
  -P COM3
  -P COM4 or -P usb:1a86:7523
Note that above ports might not be connected to a target board or an AVR programmer.
Also note there may be other direct serial ports not listed above.

PS>.\avrdude_git -C .\avrdude72.conf -c urclock -P COM4 -p m328p -qq -xshowall
00006420797a 2022-10-17 09.23 Blink_Uno.ino.hex 924 store 31431 meta 29 boot 384 u7.7 weu-jPrac 
vector 25 (SPM_Ready) ATmega328P

@mcuee
Copy link
Collaborator

mcuee commented Oct 31, 2023

It seems to work with xmega as well. Tested with ATxmega32A4 and AVRISP mkII clone.

PS>.\avrdude_pr1538v3 -C .\avrdude_pr1538v3.conf -c avrisp2 -p x32a4 -qqt
avrdude> dump fuse0
0000  55                                                |U               |
avrdude> dump fuse1
0000  00                                                |.               |
avrdude> dump fuse2
0000  63                                                |c               |
avrdude> dump fuse4
0000  1e                                                |.               |
avrdude> dump fuse5
0000  3f                                                |?               |
avrdude> dump prodsig
0000  0d 40 7b 0a 40 7f ff 01  38 55 30 31 35 32 ff ff  | @{ @...8U0152..|
0010  03 ff 05 00 16 00 ff ff  ff ff cf 07 24 40 ff ff  |............$@..|
0020  00 00 00 ff ff ff ff ff  ff ff ff ff ff ff 5e 09  |..............^ |
0030  ff ff 02 15                                       |....            |
avrdude> dump signature
0000  1e 95 41                                          |..A             |
avrdude> dump usersig
0000  55 aa 55 aa 71 75 69 63  6b 20 62 72 6f 77 6e 20  |U.U.quick brown |
0010  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0020  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
0030  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 6f 78 20  |quick brown fox |
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> dump data
avrdude_pr1538v3 error: (dump) cannot read memory data of size 0
avrdude> dump io
0000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 ff 2f 00  |............../.|
0040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0050  01 00 00 00 7b 02 00 00  00 00 00 00 00 00 00 01  |....{...........|
0060  00 00 40 0a 00 12 7a 00  00 00 40 0d 00 a1 07 00  |..@ ..z...@ ....|
0070  00 00 00 00 00 00 00 00  13 00 00 00 00 00 00 00  |................|
0080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0090  1e 95 41 04 00 00 00 00  00 00 00 00 00 00 00 00  |..A.............|
00a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> quit

git main

PS>.\avrdude_git -c avrisp2 -p x32a4 -qqt
avrdude> dump fuse0
0000  55                                                |U               |
avrdude> dump fuse1
0000  00                                                |.               |
avrdude> dump fuse2
0000  63                                                |c               |
avrdude> dump fuse4
0000  1e                                                |.               |
avrdude> dump fuse5
0000  3f                                                |?               |
avrdude> dump prodsig
0000  0d 40 7b 0a 40 7f ff 01  38 55 30 31 35 32 ff ff  | @{ @...8U0152..|
0010  03 ff 05 00 16 00 ff ff  ff ff cf 07 24 40 ff ff  |............$@..|
0020  00 00 00 ff ff ff ff ff  ff ff ff ff ff ff 5e 09  |..............^ |
0030  ff ff 02 15                                       |....            |
avrdude> dump signature
0000  1e 95 41                                          |..A             |
avrdude> dump usersig
0000  55 aa 55 aa 71 75 69 63  6b 20 62 72 6f 77 6e 20  |U.U.quick brown |
0010  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0020  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
0030  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 6f 78 20  |quick brown fox |
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> dump data
avrdude_git error: (dump) cannot read memory data of size 0
avrdude> dump io
0000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 ff 2f 00  |............../.|
0040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0050  01 00 00 00 7b 02 00 00  00 00 00 00 00 00 00 01  |....{...........|
0060  00 00 40 0a 00 12 7a 00  00 00 40 0d 00 a1 07 00  |..@ ..z...@ ....|
0070  00 00 00 00 00 00 00 00  13 00 00 00 00 00 00 00  |................|
0080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0090  1e 95 41 04 00 00 00 00  00 00 00 00 00 00 00 00  |..A.............|
00a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> quit

@stefanrueger
Copy link
Collaborator Author

@MCUdude Clearly, reading -p t824 -c jtag2updi -U prodsig:r:-:I results in the wrong memory region being displayed (should contain signature sernum etc but doesn't) in @askn37's tests. Could you run this please and show a -vv output for PR #1538 and git main. I am a bit perplexed how this could have worked in 6.3 or git main. Thanks!

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 31, 2023

Git main:

$  ./avrdude -p atmega4808 -c jtag2updi -P ch340 -U prodsig:r:-:I
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9650 (probably m4808)

avrdude: processing -U prodsig:r:-:I
avrdude: reading prodsig/sigrow memory ...
Reading | ################################################## | 100% 0.02 s 
avrdude: writing output file <stdout>
:200000001E965051504A5353204F782C23FF411006FFFFFF1207BF03BF033E033E03EFF8BC // 00000> ..PQPJSS_Ox,#.A.......?.?.>.>.ox
:2000200091F102010302FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF50 // 00020> .q..............................
:200040000000000000000000000000000000000000000000000000000000000000000000A0 // 00040> ................................
:20006000000000000000000000000000000000000000000000000000000000000000000080 // 00060> ................................
:00000001FF

avrdude done.  Thank you.

PR #1538:

$  ./avrdude -p atmega4808 -c jtag2updi -P ch340 -U prodsig:r:-:I
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9650 (probably m4808)

avrdude: processing -U prodsig:r:-:I
avrdude: reading prodsig/sigrow memory ...
Reading | ################################################## | 100% 0.02 s 
avrdude: writing output file <stdout>
:200000001E965051504A5353204F782C23FF411006FFFFFF1207BF03BF033E033E03EFF8BC // 00000> ..PQPJSS_Ox,#.A.......?.?.>.>.ox
:2000200091F102010302FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF50 // 00020> .q..............................
:200040000000000000000000000000000000000000000000000000000000000000000000A0 // 00040> ................................
:20006000000000000000000000000000000000000000000000000000000000000000000080 // 00060> ................................
:00000001FF

avrdude done.  Thank you.

@stefanrueger
Copy link
Collaborator Author

@MCUdude Thanks! Looks correct to me (starts with correct signature for the m4808). What about the parts that were used here? If you find a part where prodsig is not correct, please show the -vv notice2 output. Thanks!

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 31, 2023

Sorry, but I don't have a 2-series I can test with. But here are the results for AVR64DD32 and AVR64EA48.

AVR64DD32

Git main:

$ ./avrdude -p avr64dd32 -c jtag2updi -P ch340 -U prodsig:r:-:I -qq
:200000001E961AFFCB03FE0CFFFFFFFFFFFFFFFF422351792000572201470123000000000F // 00000> ....K.~.........B#Qy_.W".G.#....
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 // 00020> ................................
:200040007447F400CBAE97FFFFFFDDFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1D // 00040> tGt.K.....]~....................
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA55AA55FFFFFFFF9E // 00060> ........................*U*U....
:00000001FF

PR #1538:

$  ./avrdude -p avr64dd32 -c jtag2updi -P ch340 -U prodsig:r:-:I -qq
:200000001E961AFFCB03FE0CFFFFFFFFFFFFFFFF422351792000572201470123000000000F // 00000> ....K.~.........B#Qy_.W".G.#....
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 // 00020> ................................
:200040007447F400CBAE97FFFFFFDDFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1D // 00040> tGt.K.....]~....................
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA55AA55FFFFFFFF9E // 00060> ........................*U*U....
:00000001FF

AVR64EA48

Git main:

$ ./avrdude -p avr64ea48 -c jtag2updi -P ch340 -U prodsig:r:-:I -qq
:200000001E961EFFF501E8FFFFFFFFFFFFFFFFFF622192214FFFB608F018F061FFFFFFFFA3 // 00000> ....u.h.........b!.!O.6.p.pa....
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 // 00020> ................................
:20004000238B0069EE05003B03FF0200FFFFFFFFA25423BC00FFFFFFFFFFFFFFFFFFFFFF91 // 00040> #..in..;........"T#<............
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA55AA55FFFFFFFF9E // 00060> ........................*U*U....
:00000001FF

PR #1538:

$ ./avrdude -p avr64ea48 -c jtag2updi -P ch340 -U prodsig:r:-:I -qq
:200000001E961EFFF501E8FFFFFFFFFFFFFFFFFF622192214FFFB608F018F061FFFFFFFFA3 // 00000> ....u.h.........b!.!O.6.p.pa....
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 // 00020> ................................
:20004000238B0069EE05003B03FF0200FFFFFFFFA25423BC00FFFFFFFFFFFFFFFFFFFFFF91 // 00040> #..in..;........"T#<............
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA55AA55FFFFFFFF9E // 00060> ........................*U*U....
:00000001FF

@stefanrueger
Copy link
Collaborator Author

stefanrueger commented Oct 31, 2023

So, we cannot reproduce the type of failure I saw in @askn37's results. One last try: What about -U fuses:r:-:I -U lock:r:-:I -U prodsig:r:-:I in a row? Does that alter how prodsig is read?

@MCUdude
Copy link
Collaborator

MCUdude commented Oct 31, 2023

Git main:

$ ./avrdude -p avr64ea48 -c jtag2updi -P ch340 -U fuses:r:-:I -U lock:r:-:I -U prodsig:r:-:I
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e961e (probably avr64ea48)

avrdude: processing -U fuses:r:-:I
avrdude: reading fuses memory ...
avrdude: writing output file <stdout>
:10000000000000FFFFD0070000FFFFFFFFFFFFFF22                                 // 00000> .....P..........
:00000001FF

avrdude: processing -U lock:r:-:I
avrdude: reading lock memory ...
avrdude: writing output file <stdout>
:040000005CC5C55CBA                                                         // 00000> \EE\
:00000001FF

avrdude: processing -U prodsig:r:-:I
avrdude: reading prodsig/sigrow memory ...
Reading | ################################################## | 100% 0.02 s 
avrdude: writing output file <stdout>
:200000001E961EFFF501E8FFFFFFFFFFFFFFFFFF622192214FFFB608F018F061FFFFFFFFA3 // 00000> ....u.h.........b!.!O.6.p.pa....
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 // 00020> ................................
:20004000238B0069EE05003B03FF0200FFFFFFFFA25423BC00FFFFFFFFFFFFFFFFFFFFFF91 // 00040> #..in..;........"T#<............
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA55AA55FFFFFFFF9E // 00060> ........................*U*U....
:00000001FF

avrdude done.  Thank you.


$ ./avrdude -p avr64dd32 -c jtag2updi -P ch340 -U fuses:r:-:I -U lock:r:-:I -U prodsig:r:-:I
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e961a (probably avr64dd32)

avrdude: processing -U fuses:r:-:I
avrdude: reading fuses memory ...
avrdude: writing output file <stdout>
:10000000000000FFFFD0080000FFFFFFFFFFFFFF21                                 // 00000> .....P..........
:00000001FF

avrdude: processing -U lock:r:-:I
avrdude: reading lock memory ...
avrdude: writing output file <stdout>
:040000005CC5C55CBA                                                         // 00000> \EE\
:00000001FF

avrdude: processing -U prodsig:r:-:I
avrdude: reading prodsig/sigrow memory ...
Reading | ################################################## | 100% 0.02 s 
avrdude: writing output file <stdout>
:200000001E961AFFCB03FE0CFFFFFFFFFFFFFFFF422351792000572201470123000000000F // 00000> ....K.~.........B#Qy_.W".G.#....
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 // 00020> ................................
:200040007447F400CBAE97FFFFFFDDFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1D // 00040> tGt.K.....]~....................
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA55AA55FFFFFFFF9E // 00060> ........................*U*U....
:00000001FF

avrdude done.  Thank you.

PR #1538:

$ ./avrdude -p avr64ea48 -c jtag2updi -P ch340 -U fuses:r:-:I -U lock:r:-:I -U prodsig:r:-:I
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e961e (probably avr64ea48)

avrdude: processing -U fuses:r:-:I
avrdude: reading fuses memory ...
avrdude: writing output file <stdout>
:10000000000000FFFFD0070000FFFFFFFFFFFFFF22                                 // 00000> .....P..........
:00000001FF

avrdude: processing -U lock:r:-:I
avrdude: reading lock memory ...
avrdude: writing output file <stdout>
:040000005CC5C55CBA                                                         // 00000> \EE\
:00000001FF

avrdude: processing -U prodsig:r:-:I
avrdude: reading prodsig/sigrow memory ...
Reading | ################################################## | 100% 0.02 s 
avrdude: writing output file <stdout>
:200000001E961EFFF501E8FFFFFFFFFFFFFFFFFF622192214FFFB608F018F061FFFFFFFFA3 // 00000> ....u.h.........b!.!O.6.p.pa....
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 // 00020> ................................
:20004000238B0069EE05003B03FF0200FFFFFFFFA25423BC00FFFFFFFFFFFFFFFFFFFFFF91 // 00040> #..in..;........"T#<............
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA55AA55FFFFFFFF9E // 00060> ........................*U*U....
:00000001FF

avrdude done.  Thank you.


$ ./avrdude -p avr64dd32 -c jtag2updi -P ch340 -U fuses:r:-:I -U lock:r:-:I -U prodsig:r:-:I
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e961a (probably avr64dd32)

avrdude: processing -U fuses:r:-:I
avrdude: reading fuses memory ...
avrdude: writing output file <stdout>
:10000000000000FFFFD0080000FFFFFFFFFFFFFF21                                 // 00000> .....P..........
:00000001FF

avrdude: processing -U lock:r:-:I
avrdude: reading lock memory ...
avrdude: writing output file <stdout>
:040000005CC5C55CBA                                                         // 00000> \EE\
:00000001FF

avrdude: processing -U prodsig:r:-:I
avrdude: reading prodsig/sigrow memory ...
Reading | ################################################## | 100% 0.02 s 
avrdude: writing output file <stdout>
:200000001E961AFFCB03FE0CFFFFFFFFFFFFFFFF422351792000572201470123000000000F // 00000> ....K.~.........B#Qy_.W".G.#....
:20002000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE0 // 00020> ................................
:200040007447F400CBAE97FFFFFFDDFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1D // 00040> tGt.K.....]~....................
:20006000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAA55AA55FFFFFFFF9E // 00060> ........................*U*U....
:00000001FF

avrdude done.  Thank you.

@stefanrueger
Copy link
Collaborator Author

OK, brilliant. So all seems good. Thank you. Might be different FW in @askn37's programmer.

@mcuee
Copy link
Collaborator

mcuee commented Nov 1, 2023

No regression for AVR64EA48 with onboard -c pkobn_updi.

PS>.\avrdude_pr1538v4 -C .\avrdude_pr1538v4.conf -c pkobn_updi -p avr64ea48 -qqt
avrdude> read fuses
0000  00 00 00 ff ff d0 07 00  00 ff ff ff ff ff ff ff  |................|
avrdude> read lock
0000  5c c5 c5 5c                                       |\..\            |
avrdude> read signature
0000  1e 96 1e                                          |...             |
avrdude> read tempsense
0000  d1 fd 94 ec                                       |....            |
avrdude> read sernum
0000  62 23 21 15 9f ff ce 13  f0 59 f0 39 ff ff ff ff  |b#!......Y.9....|
avrdude> read userrow
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  |................|
avrdude> read data
avrdude_pr1538v4 error: (read) cannot read memory data of size 0
avrdude> read io
0000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0010  00 00 00 00 00 00 80 00  00 00 00 00 00 00 00 00  |................|
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 ff 7f 02  |................|
0040  21 00 07 00 21 00 07 00  21 00 07 00 21 00 07 00  |!...!...!...!...|
0050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0060  07 00 00 00 00 00 00 05  00 00 00 00 30 00 06 00  |............0...|
0070  00 00 00 00 00 10 00 00  00 31 00 00 00 00 00 00  |.........1......|
0080  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0090  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00b0  00 00 00 00 00 00 08 00  00 00 00 00 00 00 08 00  |................|
00c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> read sib
0000  41 56 52 20 20 20 20 20  50 3a 33 44 3a 31 2d 33  |AVR     P:3D:1-3|
0010  4d 32 20 28 42 31 2e 35  39 46 30 32 2e 30 29 00  |M2 (B1.59F02.0).|
avrdude> read eeprom 0 0x10
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
avrdude> read flash 0 0x10
0000  5c c0 00 00 0c 94 60 08  0c 94 60 08 0c 94 60 08  |\... .`. .`. .`.|
avrdude> quit

@mcuee
Copy link
Collaborator

mcuee commented Nov 1, 2023

Sorry, but I don't have a 2-series I can test with. But here are the results for AVR64DD32 and AVR64EA48.

I have the 2-series and it is okay with serialupdi. Need to test jtag2updi later this week.

PS>.\avrdude_pr1538v4 -C .\avrdude_pr1538v4.conf -c serialupdi -P COM17 -p t3227 -qqt
avrdude> read fuses
0000  00 00 00 ff ff fe 04 00  02 ff                    |..........      |
avrdude> read lock
0000  c5                                                |.               |
avrdude> read prodsig
0000  1e 95 26 30 4b 41 41 33  30 e5 22 40 43 ff 47 0e  |..&0KAA30."@C.G.|
0010  04 ff ff ff 0f 07 ff ff  a8 05 27 05 ff ff e0 f8  |..........'.....|
0020  8c 24 ff ff ff ff ff ff  ae f4 e3 fc 1f ff ff ff  |.$..............|
0030  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff 4c a9  |..............L.|
avrdude> read signature
0000  1e 95 26                                          |..&             |
avrdude> read tempsense
0000  8c 24                                             |.$              |
avrdude> read sernum
0000  30 4b 41 41 33 30 e5 22  40 43                    |0KAA30."@C      |
avrdude> read osccal16
0000  a8 05                                             |..              |
avrdude> read osccal20
0000  27 05                                             |'.              |
avrdude> read osc16err
0000  ff ff                                             |..              |
avrdude> read osc20err
0000  ff ff                                             |..              |
avrdude> read data
avrdude_pr1538v4 error: (read) cannot read memory data of size 0
avrdude> read io
0000  00 00 47 00 00 00 10 00  00 00 00 00 00 00 00 00  |..G.............|
0010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0030  00 00 00 00 00 00 00 00  00 00 00 00 00 ff 3f 02  |..............?.|
0040  21 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |!...............|
0050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0060  00 07 00 10 00 00 00 00  00 00 00 00 00 00 00 00  |................|
0070  00 40 8f 00 00 07 00 00  00 0f 00 00 00 00 00 00  |.@..............|
0080  05 00 04 02 80 00 00 00  00 00 00 00 00 00 00 00  |................|
0090  00 47 0e 00 00 00 00 00  00 00 00 00 00 00 00 00  |.G..............|
00a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00b0  20 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  | ...............|
00c0  00 00 00 00 00 00 ff 7f  00 00 00 00 00 00 00 00  |................|
00d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
avrdude> read sib
0000  74 69 6e 79 41 56 52 20  50 3a 30 44 3a 31 2d 33  |tinyAVR P:0D:1-3|
0010  4d 32 20 28 30 30 2e 35  39 42 30 45 2e 30 29 00  |M2 (00.59B0E.0).|
avrdude> read userrow
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  |................|
avrdude> read eeprom 0 0x10
0000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
avrdude> read flash 0 0x10
0000  0c 94 3c 00 0c 94 46 00  0c 94 46 00 0c 94 46 00  | .<. .F. .F. .F.|
avrdude> quit

@askn37
Copy link
Contributor

askn37 commented Nov 2, 2023

Testcase JTAGICEmkII FWV=7

src/jtagmkII.c Outdated Show resolved Hide resolved
@stefanrueger
Copy link
Collaborator Author

I think this PR is almost ready to merge. @mcuee I would like to see how communication traces in windows look like. Could you test the traces for

  • Serial send and receive in windows (-vvvv)
  • Serial send and receive in windows over ethernet (-vvvv) --- these are the net_send() and net_recv() functions

Then I'd like to merge.

@mcuee
Copy link
Collaborator

mcuee commented Nov 3, 2023

@stefanrueger

Yes I will carry out some testing today.

@mcuee
Copy link
Collaborator

mcuee commented Nov 3, 2023

@stefanrueger

  • Serial send and receive in windows (-vvvv)

Done.

  • Serial send and receive in windows over ethernet (-vvvv) --- these are the net_send() and net_recv() functions

Sorry I can not test this one.

I have also provided the traces for the other two under Windows.

  • Usbhid send and receive (-vvvvv) --- one more v the code uses msg_trace2()
  • Usbdev send and reveive (-vvvvv) --- funnily send requires 4 v and recv 5 v?! Probably a mistake

@mcuee
Copy link
Collaborator

mcuee commented Nov 3, 2023

Then I'd like to merge.

@stefanrueger
I think it is still okay to merge this PR.

@askn37
Copy link
Contributor

askn37 commented Nov 3, 2023

This is a proposed patch for issue#1534.

The data section start address 0x10000000 required by the PM_PDI chip is not required by the PM_UPDI chip, so modify the corresponding code in jtagmkII_read_byte.

Additionally, printf will also be fixed since the display will be distorted if read_chip_rev receives a negative number.

Reference: This is in Japanese, but it is a memo for patch production.
askn37#2 (comment)

diff --git a/src/jtagmkII.c b/src/jtagmkII.c
index c8d330d9..3478da2e 100644
--- a/src/jtagmkII.c
+++ b/src/jtagmkII.c
@@ -1336,7 +1336,7 @@ static int jtagmkII_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
   if (pgm->read_chip_rev && p->prog_modes & (PM_PDI | PM_UPDI)) {
     char chip_rev[AVR_CHIP_REVLEN];
     pgm->read_chip_rev(pgm, p, chip_rev);
-    pmsg_notice("silicon revision: %x.%x\n", chip_rev[0] >> 4, chip_rev[0] & 0x0f);
+    pmsg_notice("silicon revision: %x.%x\n", (unsigned char)(chip_rev[0]) >> 4, chip_rev[0] & 0x0f);
   }
 
   return 0;
@@ -2225,7 +2225,8 @@ static int jtagmkII_read_byte(const PROGRAMMER *pgm, const AVRPART *p, const AVR
     pmsg_notice2("in_sigrow addr 0x%05lx\n", addr);
   } else if (mem_is_io(mem)) {
     cmd[1] = MTYPE_FLASH;
-    addr += avr_data_offset(p);
+    if (!(p->prog_modes & (PM_UPDI)))
+      addr += avr_data_offset(p);
   } else {
     pmsg_error("unknown memory %s\n", mem->desc);
     return -1;

@stefanrueger
Copy link
Collaborator Author

The data section start address 0x10000000 required by the PM_PDI chip is not required by the PM_UPDI chip, so modify the corresponding code in jtagmkII_read_byte.

This will require a separate PR. I have no doubt this helps the updi4avr firmware, but we would have to check whether other firmware, in particular jtag2updi is (negatively) affected by this. Also, similar code addr += avr_data_offset(p); happens in other programmers; we would want to review the role of the data memory for UPDI parts and the offset of the data memory.

@stefanrueger
Copy link
Collaborator Author

| read_chip_rev receives a negative number

@askn37 Good catch. I have reviewed chip_rev usage and made this an unsigned character throughout, not only in jtagmkII.c.

@stefanrueger
Copy link
Collaborator Author

@mcuee Thanks for testing the ser send/recv comms traces.

@stefanrueger stefanrueger merged commit d8b9b92 into avrdudes:main Nov 3, 2023
10 checks passed
@stefanrueger stefanrueger deleted the memory-types branch November 3, 2023 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using an old "avrdude.conf" can result in a segmentation fault. avrdude memory type enhancement
4 participants