How to burn arduino mega 2560 bootloader?

I have my new Arduino Mega 2560 and I might have overwritten the bootloader when uploading another program through AVR studio.

I really need advice and instruction of how to burn it using AVR Studio 4 and AVR ISP external programmer.

I have tried to do everything mentioned on the Arduino website but it was not a successful attempt.

-
Can you load a custom C program onto it, like a blinky LED? Or can you download the fuse data from the chip (within AVR Studio)? This would guarantee communication, first. –  tyblu Dec 12 '10 at 12:33
I can load a blinky LED to the chip using the AVR Studio with AVR ISP.. But I am not able to burn it using the Arduino Software.. –  Levin Dec 15 '10 at 5:09

You should be able to burn it using the Arduino software with the AVR ISP. See the Tools menu.

If that doesn't work, try the Arduino forum.

-
I have tried to burn it using the Arduino software with the AVR ISP but it gave no result.. Also I have tried to ask in the arduino forum but nobody can answer it as well.. –  Levin Dec 15 '10 at 5:11

you can see here that your mega 2560 normally have an stk500v2 bootloader. (ctrl-F "2560")

So you'll find the .hex to upload (and c to compile if needed), via avr studio and your external programmer in :

pay attention that the version of avrdude using to upload via the bootloader (in arduino/hardware/tools/avrdude is a patched version of the normal one you should have in avr-studio.

• to upload via isp -> normal avrdude (don't know avr-studio and where it has instal it.

as an extra, you can see the command line used by the arduino software to communicate with the bootloader by pressing MAJ when compiling/uploading.

To upload a bootloader, somme tricks with the fuse are needed, to lock his part of the memory.

I reload the bootloader with an external programmer and those command line (arduino uno):

avrdude -p atmega328p -c stk500 -P /dev/STK500 -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xde:m -Ulfuse:w:0xff:m
avrdude -p atmega328p -c stk500 -P /dev/STK500 -Uflash:w:optiboot_atmega328.hex:i -Ulock:w:0x0f:m


Again, I found those with the arduino software, using MAJ to see what it does.

-
hi jojo l'abricot, I have found the hex but I still don't understand about the avrdude.. I have tried to program it using my external programmer, just the same way I program the chip to blink, but it doesn't give any visible result.. maybe I still got the avrdude stuffs wrong.. Any idea for that? Thanks –  Levin Jan 1 '11 at 12:57

The following steps worked for me using the Pololu USB AVR Programmer on MacOS.

Unlock fuses, erase, verify:

avrdude -p m2560 -c avrispmkii -P /dev/tty.usbmodem00056541 -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m -e -v


Write the bootloader, set the lock fuse, verify:

avrdude -p m2560 -c avrispmkii -P /dev/tty.usbmodem00056541 -Uflash:w:stk500boot_v2_mega2560.hex:i -Ulock:w:0x0f:m -v

-