What is avrdude verifying?

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi fellows, when I run avrdude to upload a . HEX file to Arduino, avrdude verification goes wrong. I am a very rookie embedded hobbyist wondering if someone can tell me what it is actually verifying?

 

Detail:

 

I came across a project that uses ATMEGA3209 to perform customized lighthouse VIVE-localization. The firmware runs on ATMEGA3209 and I want to recreate the project. Unfortunately, there is no ATMEGA3209 chip in stock, so I decided to use ATMEGA4809 instead. 

I do have a couple of Arduino UNO WIFI Rev2 in hand and these use ATMEGA4809, so I figure I can upload the firmware onto my Arduino and see if it would work. I downloaded the zip folder from GitHub, which contains c files and h files. I installed AVR GCC toolchain, then also I added the GCC atpacks that contain both ATMEGA3209 and ATMEGA4809. In the make file, I then changed my target device from ATMEGA3209 to ATMEGA4809. I ran make and it did compile and I successfully got the image.hex file(In fact, I generated the image .hex files for both ATMEGA3209 and ATMEGA4809). Here is the make file, I changed the target name (MCU_TARGET) and the path to the supported atpack files (CCDEVS). 

 

PRG            = image
OBJ            = main.o uart.o position.o

MCU_TARGET     = atmega4809
OPTIMIZE       = -O3

F_CPU          = 20000000

DEFS           = -DF_CPU=$(F_CPU)
LIBS           =

# You should not have to change anything below here.

CCDEVS         = /home/xxx/Documents/GCC/atpacks/gcc/dev/atmega4809/
CCINC          = /home/xxx/Documents/GCC/atpacks/include/
CC             = /home/xxx/Documents/GCC/avrtoolchain/bin/avr-gcc -B $(CCDEVS) -I $(CCINC)
OBJCOPY        = /home/xxx/Documents/GCC/avrtoolchain/bin/avr-objcopy
OBJDUMP        = /home/xxx/Documents/GCC/avrtoolchain/bin/avr-objdump

ASFLAGS        = -mmcu=$(MCU_TARGET) $(DEFS)
CFLAGS        = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
LDFLAGS       = -Wl,-Map,$(PRG).map -Wl,-u,vfprintf -lprintf_flt -lm

# Strip unused code
CFLAGS += -ffunction-sections -fno-inline # -fno-unroll-loops -fno-inline -fno-jump-tables
LDFLAGS += -Wl,-gc-sections  

#LDFLAGS += --cref -nostartfiles

all: $(PRG).elf lst text hex

flash: hex
	sudo avrdude -p atmega168p -c avrispmkii -P usb -U flash:w:image.hex 

$(PRG).elf: $(OBJ)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

clean:
	rm -rf $(OBJ) *.o $(PRG).elf
	rm -rf *.lst *.map *.bin *.lss *.sym *.hex $(EXTRA_CLEAN_FILES)

lst:  $(PRG).lst

%.lst: %.elf
	$(OBJDUMP) -h -d $< > $@

# Rules for building the .text rom images

text: bin

hex:  $(PRG).hex
bin:  $(PRG).bin
mem:  $(PRG).mem
srec: $(PRG).srec

%.hex: %.elf
	$(OBJCOPY) -j .text -j .data -j .rodata -O ihex $< $@

%.srec: %.elf
	$(OBJCOPY) -j .text -j .data -O srec $< $@

%.bin: %.elf
	$(OBJCOPY) -j .text -j .data -O binary $< $@

 

Moving on to Arduino. I connected my UNO WIFI Rev2 to my windows via USB. I opened Arduino IDE and I had installed the library for ATMEGA4809. The IDE was able to find my UWR2 and comport. To test my approach. I used the IDE to compile the example Blink project. I then ran upload in the IDE and copied the avrdude command Arduino was using: 

C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cxplainedmini_updi -Pusb -b115200 -e -D -Uflash:w:C:\Users\xxx\AppData\Local\Temp\arduino_build_197951/Blink.ino.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x02:m -Uflash:w:C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex:i 

From the line, I saw my atmega4809 bootloader as a .hex file exists (I think), and after upload, the Arduino blinked.

I changed my Blink speed a bit faster, recompiled, and saved a copy of the new Blink.ino.hex file in the same folder as my image.hex. I then ran the same code above in the command line, except that my directory to my .hex file is at the folder that contains both the copy of Blink.ino.hex file and image.hex file. And the Arduino blinked faster. This suggests that my command line method for .hex file uploading as well as my ATMEGA4809 bootloader are working (I think). 

 

So, I then tried to upload my image.hex. In the command line, nothing was changed instead the name of the .hex file:

C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cxplainedmini_updi -Pusb -b115200 -e -D -Uflash:w:C:\Users\xxx\Documents\Project_spring_2022\MCU_HEX/image.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x02:m -Uflash:w:C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex:i 

And I then got a verification content mismatch error:

C:\Users\xxx>C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cxplainedmini_updi -Pusb -b115200 -e -D -Uflash:w:C:\Users\xxx\Documents\Project_spring_2022\MCU_HEX/image.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x02:m -Uflash:w:C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex:i

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\john\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : usb
         Using Programmer              : xplainedmini_updi
         Overriding Baud Rate          : 115200
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : ATmega4809
         Chip Erase delay              : 0 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 0
         StabDelay                     : 0
         CmdexeDelay                   : 0
         SyncLoops                     : 0
         ByteDelay                     : 0
         PollIndex                     : 0
         PollValue                     : 0x00
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           prodsig        0     0     0    0 no         61   61      0     0     0 0x00 0x00
           fuses          0     0     0    0 no          9    0      0     0     0 0x00 0x00
           fuse0          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse1          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse2          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse4          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse5          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse6          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse7          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           fuse8          0     0     0    0 no          1    0      0     0     0 0x00 0x00
           lock           0     0     0    0 no          1    0      0     0     0 0x00 0x00
           data           0     0     0    0 no          0    0      0     0     0 0x00 0x00
           usersig        0     0     0    0 no         64   64      0     0     0 0x00 0x00
           flash          0     0     0    0 no      49152  128      0     0     0 0x00 0x00
           eeprom         0     0     0    0 no        256   64      0     0     0 0x00 0x00

         Programmer Type : JTAGICE3_UPDI
         Description     : Atmel AVR XplainedMini in UPDI mode
         ICE hardware version: 0
         ICE firmware version: 1.19 (rel. 57)
         Serial number   : 712EB74E0F94B3D4628B
         Vtarget         : 5.00 V
         JTAG clock megaAVR/program: 0 kHz
         JTAG clock megaAVR/debug:   0 kHz
         JTAG clock Xmega: 0 kHz
         PDI clock Xmega : 0 kHz

avrdude: Partial Family_ID returned: "mega"
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.08s

avrdude: Device signature = 0x1e9651 (probably m4809)
avrdude: erasing chip
avrdude: reading input file "C:\Users\john\Documents\Project_spring_2022\MCU_HEX/image.hex"
avrdude: writing flash (28220 bytes):

Writing | ################################################## | 100% 11.33s

avrdude: 28220 bytes of flash written
avrdude: verifying flash memory against C:\Users\john\Documents\Project_spring_2022\MCU_HEX/image.hex:
avrdude: load data flash data from input file C:\Users\john\Documents\Project_spring_2022\MCU_HEX/image.hex:
avrdude: input file C:\Users\john\Documents\Project_spring_2022\MCU_HEX/image.hex contains 28220 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 9.32s

avrdude: verifying ...
avrdude: 28220 bytes of flash verified
avrdude: reading input file "0x01"
avrdude: writing fuse2 (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of fuse2 written
avrdude: verifying fuse2 memory against 0x01:
avrdude: load data fuse2 data from input file 0x01:
avrdude: input file 0x01 contains 1 bytes
avrdude: reading on-chip fuse2 data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: 1 bytes of fuse2 verified
avrdude: reading input file "0xC9"
avrdude: writing fuse5 (1 bytes):

Writing | ################################################## | 100% 0.04s

avrdude: 1 bytes of fuse5 written
avrdude: verifying fuse5 memory against 0xC9:
avrdude: load data fuse5 data from input file 0xC9:
avrdude: input file 0xC9 contains 1 bytes
avrdude: reading on-chip fuse5 data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: WARNING: invalid value for unused bits in fuse "fuse5", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xcd instead of 0xc9 (double check with your datasheet first).
avrdude: 1 bytes of fuse5 verified
avrdude: reading input file "0x02"
avrdude: writing fuse8 (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of fuse8 written
avrdude: verifying fuse8 memory against 0x02:
avrdude: load data fuse8 data from input file 0x02:
avrdude: input file 0x02 contains 1 bytes
avrdude: reading on-chip fuse8 data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: 1 bytes of fuse8 verified
avrdude: reading input file "C:\Users\john\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex"
avrdude: writing flash (280 bytes):

Writing | ################################################## | 100% 0.17s

avrdude: 280 bytes of flash written
avrdude: verifying flash memory against C:\Users\john\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex:
avrdude: load data flash data from input file C:\Users\john\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex:
avrdude: input file C:\Users\john\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex contains 280 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.11s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x00 != 0x11
avrdude: verification error; content mismatch

avrdude: safemode: Fuses OK (E:FF, H:FF, L:FF)

avrdude done.  Thank you.

(Trying x-out my name John but apparently I did a bad job at it)

here is another piece of output after I put -v

C:\Users\john>C:\Users\john\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\john\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cxplainedmini_updi -Pusb -b115200 -e -D -Uflash:w:C:\Users\john\Documents\Project_spring_2022\MCU_HEX/image.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x02:m -Uflash:w:C:\Users\john\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex:i -v

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\john\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : usb
         Using Programmer              : xplainedmini_updi
         Overriding Baud Rate          : 115200
avrdude: jtag3_open_updi()
avrdude: usbhid_open(): No device found
avrdude: jtag3_open_common(): Did not find any device matching VID 0x03eb and PID list: 0x2145

avrdude done.  Thank you.

 

It is not my day 1 working on an engineering project so I don't expect things just click in one try. But it would be helpful if someone can tell me what is avrdude verifying(and more importantly what might possibly go wrong) so that I can have a sense of what to look at next. Currently, I am going over the datasheet between ATMEGA3209 and 4809 to see if there is any difference in register organization. To my knowledge, these 2 MCUs are very similar, and their .hex files look identical by my eyeball inspection (I could be wrong).

This topic has a solution.

after all, I am still pretty bad at it

Last Edited: Wed. Jun 8, 2022 - 08:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

someone can tell me what it is actually verifying?

 It checks that whatever went (or not) into the processor is correct against the file used for programming.

 

Many things can go wrong starting with your hardware, I don't use avrdude  so someone else will add more info.

 

Also remember that the chip uses UPDI for programming and not ISP so it may be the case that the programmer can't do that mode however I don't know.
 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A few thoughts, in no particular order:

 

--  Is that your full log of the 'dude session?  Is there no signature read first?  What are the results of a signature read?

--  Following on, is there no chip erase first?

--  Why are fuses written before erase and flash program/verify?

-- I haven't decoded those fuse values, but if you are doing some kind of lock >>preventing<< readback then indeed any verification will fail.

-- An AVR app with the first flash byte being 0x11, eh?  Unusual to me.

-- The 'dude gurus will chime in soon and say to add more -v on your command line(s), with each -v making it more verbose.  That may give clues.

-- Has this chip and setup and command file and hex file worked before?  Or is this a virgin setup and situation?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\xxx\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cxplainedmini_updi -Pusb -b115200 -e -D -Uflash:w:C:\Users\xxx\Documents\Project_spring_2022\MCU_HEX/image.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x02:m -Uflash:w:C:\Users\xxx\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.7/bootloaders/atmega4809_uart_bl.hex:i 

 

You almost certainly do NOT want to upload the bootloader (or set the bootloader fuses) for a non-arduino sketch.  It's there (I think) so that you can do over-the-air uploading via the wireless module.  The bootloader is almost certainly overwriting part of your program (both being compiled to load at flash address 0x0.)

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see. I had ordered a few ATMEGA4809 CURIOSITY NANO. Do you think if I use MPLAB would I be experiencing less trouble?

 

In GitHub. The original design was to Write firmware to board, e.g.: avrdude -c jtag2updi -P /dev/ttyACM1 -p m3209 -U flash:w:image.hex, and on the hardware side there is just a USB to serial connection from PC to ATMEGA3209. And I also ordered a few USB to serial converters and hopefully that would work.

 

I felt in general, is hard (particularly 4809 model without ISP) to upload a non-Arduino sketch

Thanks!

after all, I am still pretty bad at it

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi thanks, I had updated my command line. Out of curiosity, what do you mean by   lock >>preventing<< readback ?

after all, I am still pretty bad at it

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
--  Is that your full log of the 'dude session?  Is there no signature read first?  What are the results of a signature read?
Umm? This...

Ninjatuna123 wrote:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.08s

avrdude: Device signature = 0x1e9651 (probably m4809)

(as OP's command line said to expect -patmega4809 I'd call this a pretty reasonable result myself)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As pointed out in #4, you are uploading 2 flash sections, the first is your program and the second is the bootloader.

If they overlap, the result of writing flash is the AND between what you write and what was there before, and in general it will be different from what was written, generating an error.

 

The only situation were a write to flash always gives the value that is written, is when you write to freshly erased flash (it contains 0xFF in every byte), because 0xNN AND 0xFF = 0xNN.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why on earth would you split it and write two separate .hex files anyway? Why not combine the two (app and boot) hex files into one before you start ? Use srec_cat or similar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That is right. I got it to upload now.

 

For folks who need to upload a raw c into Arduino in the future, here are the steps:

 

1: make the .hex file

2: Open Arduino IDE and burn the bootloader of your device

3: connect to USB and use avrdude to upload the .hex file in interest. Specific commands of the avrdude can be copied and pasted from Arduino log (just remember to remove the part that flashes the bootloader .hex file)

4: done

 

:-)

 

after all, I am still pretty bad at it

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

 

Umm? This...

The OP looked different when I commented. 

 

Ninjatuna123 wrote:

Last Edited: Wed. Jun 8, 2022 - 03:01 PM [my time, and hours before you digested the thread]

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.