title: Burning Arduino bootloader with Atmel-ICE results in avrdude throwing a "verification error"
body: <p>I'm trying to burn an Arduino bootloader on an <code>Arduino UNO</code> board with the <code>Atmel-ICE</code> probe. Unfortunately, <code>avrdude</code> throws an error message when verifying the bytes.</p>
  <h1>1. Hardware setup</h1>
  <p>My hardware setup looks like this:</p>
  <p><a href="https://i.stack.imgur.com/ZqRfn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZqRfn.png" alt="enter image description here" /></a></p>
  <p>By the way - I'm working on a 64-bit Windows 10 PC.</p>
  <h1>2. Atmel-ICE driver</h1>
  <p>At first I thought that the <code>Atmel-ICE</code> doesn't require installation, because Windows recognizes it as an HID-device. However, I quickly learned that <code>avrdude</code> - launched by the Arduino IDE - needs another driver to interact with the <code>Atmel-ICE</code>. Therefore, I installed the <code>libusb-win32</code> driver with Zadig (just as suggested on the GitHub thread <a href="https://github.com/arduino/Arduino/issues/4368" rel="nofollow noreferrer">https://github.com/arduino/Arduino/issues/4368</a>):</p>
  <p><a href="https://i.stack.imgur.com/L7Tvb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L7Tvb.png" alt="enter image description here" /></a></p>
  <p>The driver installation succeeded, and I observe a change in the Windows Device Manager. The <code>Atmel-ICE</code> probe no longer appears as an HID-device but as a <code>libusb-win32</code> device instead:</p>
  <p><a href="https://i.stack.imgur.com/y6JNZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y6JNZ.png" alt="enter image description here" /></a></p>
  <p>I believe the <code>Atmel-ICE</code> is now ready to be used with <code>avrdude</code>.</p>
  <h1>3. Software setup</h1>
  <p>I'm running a fresh-installed Arduino IDE (version 1.8.13) on a Windows 10 PC. First I activate maximal verbosity for the console output (<code>File</code> &gt; <code>Preferences</code> &gt; <code>Show verbose output</code>). Next, I select the probe: <code>Tools</code> &gt; <code>Programmer</code> &gt; <code>Atmel-ICE (AVR)</code></p>
  <p><a href="https://i.stack.imgur.com/VvJpI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VvJpI.png" alt="enter image description here" /></a></p>
  <p>Next I select my board: <code>Tools</code> &gt; <code>Board</code> &gt; <code>Arduino AVR Boards</code> &gt; <code>Arduino UNO</code></p>
  <p><a href="https://i.stack.imgur.com/H7c5T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H7c5T.png" alt="enter image description here" /></a></p>
  <p>Finally, I burn the bootloader: <code>Tools</code> &gt; <code>Burn Bootloader</code></p>
  <p><a href="https://i.stack.imgur.com/C1MMH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C1MMH.png" alt="enter image description here" /></a></p>
  <p>In the console output, I can see two <code>avrdude</code> commands being launched.</p>
  <h3>3.1 First avrdude command</h3>
  <p>The first <code>avrdude</code> command looks like this:</p>
  <pre class="lang-sh prettyprint-override"><code>avrdude -CC:\Program Files (x86)\.../avrdude.conf
          -v
          -patmega328p
          -catmelice_isp
          -Pusb
          -e
          -Ulock:w:0x3F:m
          -Uefuse:w:0xFD:m
          -Uhfuse:w:0xDE:m
          -Ulfuse:w:0xFF:m
  </code></pre>
  <p>the output for this command is:</p>
  <pre class="lang-sh prettyprint-override"><code>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 &quot;C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf&quot;
  
           Using Port                    : usb
           Using Programmer              : atmelice_isp
  avrdude: usbhid_open(): No device found
  avrdude: usbdev_open(): Found Atmel-ICE CMSIS-DAP, serno: J42700007942
  avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
           AVR Part                      : ATmega328P
           Chip Erase delay              : 9000 us
           PAGEL                         : PD7
           BS2                           : PC2
           RESET disposition             : dedicated
           RETRY pulse                   : SCK
           serial program mode           : yes
           parallel program mode         : yes
           Timeout                       : 200
           StabDelay                     : 100
           CmdexeDelay                   : 25
           SyncLoops                     : 32
           ByteDelay                     : 0
           PollIndex                     : 3
           PollValue                     : 0x53
           Memory Detail                 :
  
                                    Block Poll               Page                       Polled
             Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
             ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
             eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
             flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
             lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
             hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
             efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
             lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
             calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
             signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
  
           Programmer Type : JTAG3_ISP
           Description     : Atmel-ICE (ARM/AVR) in ISP mode
           Vtarget         : 5.0 V
           SCK period      : 125.00 us
  
  avrdude: AVR device initialized and ready to accept instructions
  
  Reading | ################################################## | 100% 0.01s
  
  avrdude: Device signature = 0x1e950f (probably m328p)
  avrdude: erasing chip
  avrdude: reading input file &quot;0x3F&quot;
  avrdude: writing lock (1 bytes):
  
  Writing | ################################################## | 100% 0.00s
  
  avrdude: 1 bytes of lock written
  avrdude: verifying lock memory against 0x3F:
  avrdude: load data lock data from input file 0x3F:
  avrdude: input file 0x3F contains 1 bytes
  avrdude: reading on-chip lock data:
  
  Reading | ################################################## | 100% 0.01s
  
  avrdude: verifying ...
  avrdude: WARNING: invalid value for unused bits in fuse &quot;lock&quot;, 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 0xff instead of 0x3f (double check with your datasheet first).
  avrdude: 1 bytes of lock verified
  avrdude: reading input file &quot;0xFD&quot;
  avrdude: writing efuse (1 bytes):
  
  Writing | ################################################## | 100% 0.09s
  
  avrdude: 1 bytes of efuse written
  avrdude: verifying efuse memory against 0xFD:
  avrdude: load data efuse data from input file 0xFD:
  avrdude: input file 0xFD contains 1 bytes
  avrdude: reading on-chip efuse data:
  
  Reading | ################################################## | 100% 0.00s
  
  avrdude: verifying ...
  avrdude: 1 bytes of efuse verified
  avrdude: reading input file &quot;0xDE&quot;
  avrdude: writing hfuse (1 bytes):
  
  Writing | ################################################## | 100% 0.09s
  
  avrdude: 1 bytes of hfuse written
  avrdude: verifying hfuse memory against 0xDE:
  avrdude: load data hfuse data from input file 0xDE:
  avrdude: input file 0xDE contains 1 bytes
  avrdude: reading on-chip hfuse data:
  
  Reading | ################################################## | 100% 0.00s
  
  avrdude: verifying ...
  avrdude: 1 bytes of hfuse verified
  avrdude: reading input file &quot;0xFF&quot;
  avrdude: writing lfuse (1 bytes):
  
  Writing | ################################################## | 100% 0.09s
  
  avrdude: 1 bytes of lfuse written
  avrdude: verifying lfuse memory against 0xFF:
  avrdude: load data lfuse data from input file 0xFF:
  avrdude: input file 0xFF contains 1 bytes
  avrdude: reading on-chip lfuse data:
  
  Reading | ################################################## | 100% 0.00s
  
  avrdude: verifying ...
  avrdude: 1 bytes of lfuse verified
  
  avrdude done.  Thank you.
  </code></pre>
  <p>That looks good.</p>
  <h3>3.2 Second avrdude command</h3>
  <p>The second <code>avrdude</code> command is:</p>
  <pre class="lang-sh prettyprint-override"><code>avrdude -CC:\Program Files (x86)\.../avrdude.conf
          -v
          -patmega328p
          -catmelice_isp
          -Pusb
          -Uflash:w:C:\Program Files (x86)\.../optiboot_atmega328.hex:i
          -Ulock:w:0x0F:m 
  </code></pre>
  <p>with the following output:</p>
  <pre class="lang-sh prettyprint-override"><code>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 &quot;C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf&quot;
  
           Using Port                    : usb
           Using Programmer              : atmelice_isp
  avrdude: usbhid_open(): No device found
  avrdude: usbdev_open(): Found Atmel-ICE CMSIS-DAP, serno: J42700007942
  avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
           AVR Part                      : ATmega328P
           Chip Erase delay              : 9000 us
           PAGEL                         : PD7
           BS2                           : PC2
           RESET disposition             : dedicated
           RETRY pulse                   : SCK
           serial program mode           : yes
           parallel program mode         : yes
           Timeout                       : 200
           StabDelay                     : 100
           CmdexeDelay                   : 25
           SyncLoops                     : 32
           ByteDelay                     : 0
           PollIndex                     : 3
           PollValue                     : 0x53
           Memory Detail                 :
  
                                    Block Poll               Page                       Polled
             Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
             ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
             eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
             flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
             lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
             hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
             efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
             lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
             calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
             signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
  
           Programmer Type : JTAG3_ISP
           Description     : Atmel-ICE (ARM/AVR) in ISP mode
           Vtarget         : 5.0 V
           SCK period      : 125.00 us
  
  avrdude: AVR device initialized and ready to accept instructions
  
  Reading | ################################################## | 100% 0.01s
  
  avrdude: Device signature = 0x1e950f (probably m328p)
  avrdude: NOTE: &quot;flash&quot; memory has been specified, an erase cycle will be performed
           To disable this feature, specify the -D option.
  avrdude: erasing chip
  avrdude: reading input file &quot;C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex&quot;
  avrdude: writing flash (32768 bytes):
  
  Writing | ################################################## | 100% -0.00s
  
  avrdude: 32768 bytes of flash written
  avrdude: verifying flash memory against C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex:
  avrdude: load data flash data from input file C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex:
  avrdude: input file C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/optiboot/optiboot_atmega328.hex contains 32768 bytes
  avrdude: reading on-chip flash data:
  
  Reading | ################################################## | 100% -0.00s
  
  avrdude: verifying ...
  avrdude: 32768 bytes of flash verified
  avrdude: reading input file &quot;0x0F&quot;
  avrdude: writing lock (1 bytes):
  
  Error while burning bootloader.
  Writing | ################################################## | 100% 0.00s
  
  avrdude: 1 bytes of lock written
  avrdude: verifying lock memory against 0x0F:
  avrdude: load data lock data from input file 0x0F:
  avrdude: input file 0x0F contains 1 bytes
  avrdude: reading on-chip lock data:
  
  Reading | ################################################## | 100% 0.01s
  
  avrdude: verifying ...
  avrdude: verification error, first mismatch at byte 0x0000
           0xff != 0x0f
  avrdude: verification error; content mismatch
  
  avrdude done.  Thank you.
  </code></pre>
  <h3>3.3 The error message</h3>
  <p>As you can see, <code>avrdude</code> throws this error message:</p>
  <pre class="lang-sh prettyprint-override"><code>avrdude: verifying ...
  avrdude: verification error, first mismatch at byte 0x0000
           0xff != 0x0f
  avrdude: verification error; content mismatch
  </code></pre>
  <p>What should I do to solve this?</p>