Arduino UNO Bootloader - Using PICKit2

Hi and good evening.

I have a problem with my UNO R3 bootloader.

  1. I don't know which .hex file to upload using ISP programmer.

  2. I am using PICKit2 as my AVR programmer, based on wiring and instruction from My Stuff: Using PicKit2 Programmer to program Atmel's microcontrollers.

  3. First try, I use "ATmegaBOOT_168_atmega328.hex" from "C:\Program Files\Arduino\hardware\arduino\avr\bootloaders\atmega". Result:-

C:\WinAVR\bin>avrdude -c pickit2 -p m328p -v -V -U boot:w:"ATmegaBOOT_168_atmega
328.hex":a

avrdude: Version 6.2, compiled on Nov 20 2015 at 23:33:37
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\WinAVR\bin\avrdude.conf"

         Using Port                    : usb
         Using Programmer              : pickit2
         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  Max
W   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  36
00 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  45
00 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  45
00 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  45
00 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  45
00 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  45
00 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 : PICkit 2 Microcontroller Programmer
         Description     : MicroChip's PICkit2 Programmer

avrdude: MicroChip's PICkit2 Programmer firmware version 2.32.0
avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
"boot" memory type not defined for part "ATmega328P"

avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:D9, L:62)

avrdude done.  Thank you.


C:\WinAVR\bin>
  1. I use "optiboot_atmega328.hex" from "C:\Program Files\Arduino\hardware\arduino\avr\bootloaders\optiboot". Result:-
C:\WinAVR\bin>avrdude -c pickit2 -p m328p -v -V -U boot:w:"optiboot_atmega328.he
x":a

avrdude: Version 6.2, compiled on Nov 20 2015 at 23:33:37
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\WinAVR\bin\avrdude.conf"

         Using Port                    : usb
         Using Programmer              : pickit2
         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  Max
W   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ---
-- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  36
00 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  45
00 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  45
00 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  45
00 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  45
00 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  45
00 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 : PICkit 2 Microcontroller Programmer
         Description     : MicroChip's PICkit2 Programmer

avrdude: MicroChip's PICkit2 Programmer firmware version 2.32.0
avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
"boot" memory type not defined for part "ATmega328P"

avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:D9, L:62)

avrdude done.  Thank you.
  1. This means that the bootloader upload failed. Any idea, comment, suggestion on this issue?
    Thanks.

Both bootloaders are good for ATmega328P. The optiboot is better to use in my opinion. You are using 'boot' param for memory type but this is for ATxmega devices only. Parameter should be 'flash' instead. Don't forget to burn fuses also because they define boot vector and boot region, external crystal etc. Here is fuse setting for UNO:
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
Hope it helps.

EDIT:
Try this
avrdude -c pickit2 -p m328p -v -V -U flash:w:optiboot_atmega328.hex:i -Ulock:w:0x0F:m

  1. I'm using this command "avrdude -c pickit2 -p m328p -v -V -U flash:w:optiboot_atmega328.hex:a" without "-U lock...".
  2. Is the "-U lock" is important?
  3. Some info I got from "boards.txt" from "C:\Program Files\Arduino\hardware\arduino\avr".
uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.maximum_data_size=2048
uno.upload.speed=115200

uno.bootloader.tool=avrdude
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xDE
uno.bootloader.extended_fuses=0x05
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.bootloader.file=optiboot/optiboot_atmega328.hex

uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.board=AVR_UNO
uno.build.core=arduino
  1. From info above, do I need to set "-U lock:w:0x3F:m" first, then upload the code, then "-U lock:w:0x0F:m"?
  2. I first using command "avrdude -c pickit2 -p m328p -v" to gather information from on-board m328p.

My UNO fuses it: (L=FF, H=DE, E=FD).
Arduino UNO defaul: (L=FF, H=DE, E=05).

Will this make any difference/performance/error/problem/issue with my UNO R3? Is so, what will you recommend me to do?

Lock 0x0F disables read and write from boot region, 0x3F enables RW. ATmega has all flash usable for program. Fuses define whether the end of flash have to be used for bootloader so this is a protection for the boot region - lock bit 4,5.
Extended fuse - only first 3 bits have meaning for 328P (0-7), the rest is unused. Extended fuse byte defines brown out detection level 2.7V for 0x05. 0xFD is the same. All is described in the datasheet, chapter 28.
It is good to gather information from MCU first. It can save unnecessary writes to flash and so wearing.
I think this is all you need for now, just note only to be sure that your setting is for external clock source so the crystal or other kind of clock must be used otherwise MCU will not start. Try it and post the result for a feedback.

avrdude  -c pickit2 -p m328p -e -u -U lock:w:0x3f:m -U efuse:w:0x05:m -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m -U flash:w:optiboot_atmega328.hex -U lock:w:0x2f:m

2f vs 0f for the final lock bit value is a personal preference. 2f allows the sketch to read the bootloader area (and report the optiboot version, for example.) 0f is the current arduino default.