(:redirect Hacking/Bootloader:)

Bootloader

The bootloader is a small piece of software that we've burned onto the chips that come with your Arduino boards. It allows you to upload sketches to the board without external hardware.

When you reset the Arduino board, it runs the bootloader (if present). The bootloader pulses digital pin 13 (you can connect an LED to make sure that the bootloader is installed). The bootloader then waits a few seconds for commands or data to arrive from the the computer. Usually, this is a sketch that the bootloader writes to the flash memory on the ATmega8 chip. A few seconds later, the bootloader launches the newly-uploaded program. If no data arrives from the computer, the bootloader launches whatever program was last uploaded onto the chip. If the chip is still "virgin" the bootloader is the only program in memory and will start itself again.

Why are we using a bootloader?

The use of a bootloader allows us to avoid the use of external hardware programmers. (Burning the bootloader onto the chip, however, requires one of these external programmers.)

Not using a bootloader

If you want to use the full program space (flash) of the chip or avoid the bootloader delay, you can burn your sketches using an external programmer.

Burning the Bootloader

To burn the bootloader, you'll need to buy an AVR-ISP (in-system programmer) or build a ParallelProgrammer. The programmer should be connected to the ICSP pins (the 2 by 3 pin header) - make sure you plug it in the right way. The board must be powered by an external power supply or the USB port.

Then, just launch the "Burn Bootloader" (for AVR-ISP) or "Burn Bootloader Parallel" command from the Tools menu of the Arduino environment. Burning the bootloader may take 15 seconds or more, so be patient.

It still doesn't work! (parallel programmer on Windows XP)

Windows XP may be polling your parallel port and disrupting the bootloader burning process. You'll need this registry patch:

 
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Parport\Parameters]
"DisableWarmPoll"=dword:00000001

See this forum thread for details.

Note for older boards.

Newer versions of the bootloader communicate with the computer at 19200 baud; older versions use 9600 baud. In order to successfully upload programs to the board, this rate needs to match the serial.download_rate in your preferences.txt file (which defaults to 19200). See the FAQ for instructions on changing it.

How does it work?

A precompiled bootloader (.hex file) comes with the Arduino environment; it communicates at 19200 baud (but see the note for older boards above). The "Burn Bootloader" commands in the Arduino environment use an open-source tool, uisp. There are four steps (each a separate call to uisp): unlocking the bootloader section of the chip, setting the the fuses on the chip, uploading the bootloader code to the chip, and locking the bootloader section of the chip. These are controlled by a number of preferences in the Arduino preferences file:

  • bootloader.programmer (default value: stk500) is the protocal used by the bootloader.

  • bootloader.unlock_bits (default value: 0xFF) is the value to write to the ATmega8 lock byte to unlock the bootloader section.

  • bootloader.high_fuses (default value for an ATmega8 on an Arduino board: 0xca) is the value to write to the high byte of the ATmega8 fuses.

  • bootloader.low_fuses (default value for an ATmega8 on an Arduino board: 0xdf) is the value to write to the low byte of the ATmega8 fuses.

  • bootloader.path (default value: bootloader) is the path (relative to the Arduino application directory) containing the precompiled bootloader.

  • bootloader.file (default value: ATmegaBOOT.hex) is the name of the file containing the precompiled bootloader code (in bootloader.path).

  • bootloader.lock_bits (default value: 0xCF) is the value to write to the ATmega8 lock byte to lock the bootloader section (so it doesn't get accidently overwritten when you upload a sketch).

Source Code

The bootloader source code is available.

For historical reasons we maintain the following link, that will give you access to the release of the bootloader's source code we used in the first prototype we made, it is including two batch files to do the compilation and download of it under windows.