12

I was instructed to "burn the bootloader" to my Arduino to fix an error I was getting. How can I do this? (And what exactly is the bootloader?)

13

The bootloader is a small program that is (almost) always on an Arduino. It manages uploading and starting the sketches you make, and blinks the pin 13 LED whenever the board resets.


To burn the bootloader:

  1. Obtain an AVR ISP, USBtinyISP, ParallelProgrammer, or another Arduino board. This will be your ISP.
  2. Unless otherwise instructed, connect the ISP to the ICSP pins on your board.
  3. Power your board with either a USB cable or an external power supply.
  4. Open up the Arduino IDE.
  5. Make sure you selected the correct board that you are burning to at Tools ► Board ► in the IDE. Double-check this even if you could upload programs correctly; uploading doesn't always require the right board.
  6. Select the appropriate programmer at Tools ► Programmer ►.
  7. Click Tools ► Burn Bootloader, and wait. It shouldn't take more than a minute, and often takes only a few seconds.

Sources:

  • 1
    The AVRISP is pretty much EOL (end-of-life) at this point. At minimum, you want a AVRISPmk2. There are also lots of other, fancier tools (AVR One! for example). You should probably just say {line 1} or other dedicated ISP programmer. – Connor Wolf Feb 27 '14 at 0:39
  • On boards like the Arduino Yun, each time you "upload via wifi", you're burning the bootloader merged with your sketch. This thanks to the fact that the Linux CPU is connected to the AVR MCU through SPI, so that you can mimic an ISP with software. – Federico Fissore Feb 27 '14 at 8:28
  • @FedericoFissore - is that why it take so long? – TheDoctor Mar 1 '14 at 15:37
  • Yes, that and the fact that GPIO bitbanging is slower. There is an ongoing effort to speed it up. – Federico Fissore Mar 1 '14 at 19:48
6

What is a bootloader?

And what exactly is the bootloader?

The bootloader is a small piece of code residing in the "high" part of program memory. Normally it is not erased when you upload new sketches. Its purpose it to be activated immediately after a reset (the fuses are configured to commence code at the bootloader address rather than address 0x0000). The bootloader will wait a short time (such as one second) to see if "programming" data is arriving on the serial port.

  • If so, it reads that data, and decodes it to reprogram the rest of the flash memory. Working in conjunction with the uploading program (normally avrdude) the new sketch is sent via the serial port. The bootloader erases pages of flash memory, and replaces them with the new code. Once done, it executes the new code.

  • If no instructions arrive, the bootloader jumps to address 0x0000 to execute the existing sketch on the board.


How to replace the bootloader

An alternative method to program a bootloader is to use a sketch I wrote a while ago which runs on a:

  • Uno (or similar, such as Duemilanove)
  • Leonardo
  • Mega2560

The "programming" board runs the sketch which has bootloaders for a number of boards hard-coded into it. You connect the programming board to the target board (the board wanting the bootloader) with 6 hook-up wires as shown.

Bootloader programmer for Uno

That particular photo illustrates one Uno programming another one.

You run the sketch (operating via the Serial Monitor to give it commands). First it identifies the target chip:

Atmega chip programmer.
Written by Nick Gammon.
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F 
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xFF 
HFuse = 0xDE 
EFuse = 0xFD 
Lock byte = 0xCF 
Bootloader address = 0x7E00
Bootloader length = 512 bytes.
Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ...
Type 'G' to program the chip with the bootloader ...

The you press G to program it.

Erasing chip ...
Writing bootloader ...
Committing page starting at 0x7E00
Committing page starting at 0x7E80
Committing page starting at 0x7F00
Committing page starting at 0x7F80
Written.
Verifying ...
No errors found.
Writing fuses ...
LFuse = 0xFF 
HFuse = 0xDE 
EFuse = 0xFD 
Lock byte = 0xCF 
Done.
Type 'C' when ready to continue with another chip ...

For a Uno this takes one second. To program a Mega2560 takes 3 seconds.

Detailed instructions at Atmega bootloader programmer

Code can be downloaded from Github: nickgammon/arduino_sketches

  • Do you have to select the type of chip your are burning to (Tools->Board..)? What board do I select when I am burning the bootloader to stand alone chip? – Camilo Dec 11 '16 at 18:45
  • You select the type of board you are using to burn the bootloader in the IDE. The bootloader sketch auto-detects the target board type. – Nick Gammon Dec 11 '16 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.