Arduino bootloader

What is the arduino bootloader ?

 

It’s the thing that loads stuff when booting.

 

Done

 

Not funny you say ? … ok , ok I’ll try this again…

 

It’s a special program that on boot waits for a signal from the PC that is connected to the arduino for a new sketch and when that signal does not come it runs the program that is already in the memory. If that signal does come, it writes the sketch that we upload to memory and then reboots the ATmega chip.

 

Why is this necessary ?

 

Well, the ATmega at the core of the arduino is made to run the program that is in memory once it is powered on. Reprogramming it is usually done through special pins witch are tied to the ICSP connectors. Having to connect a programmer to these pins every time we want the arduino programmed is rather cumbersome. It’s much easier to have the ATmega wait for a new program through serial communications (the USB interface) than to have to tie a special programmer to it.

 

Where does the bootloader live ?

 

At the beginning of the memory of the ATmega. The chip is made so it starts running instructions form the first memory address so the bootloader is located there. It gets control and then either passes it on to the program or starts writing to the program address. The old bootloaders use to take up 2000 bytes of memory. After about 2017 Arduino started shipping with optiboot. This new bootloader reduced the memory requirement to 500 bytes of memory. A second question arising from this is where does the main program sit in the Arduino. The answer is starting from the next free unreserver byte. The bootloader does not rewrite itself while uploading a sketch.

 

How do I get a bootloader ?

 

If you just got your Arduino board it should have come with a bootloader. You can just plug the arduino , upload a sketch and go. If you are using a factory fresh ATmega chip and need to upload a bootloader unto it then there are two options.

  • Using an Arduino board as an ISP
  • Building a parallel programmer

The first one is prefered and I will go through the procedure at a future time. For now all you need to know is that one arduino sends data to the target arduino using the ICSP header instead of the normal way and also configures the fuse bits.

 

Do I really need it ?

 

Well , no. You most definitely can go without it. As a bonus you get all the space of the ATmerga chip. Space you can even go without the bootloader. Sadly you will have a hard time uploading new sketches. This should not be a problem if you plan on having the circuit just have one function for a long time, if you have the patience you can even prototype like this.

 

Ok , how do I get rid of my bootloader ?

 

Simple you overwrite it with your program. Normally the bootloader receives the new sketch and writes it to addresses that are not reserved for itself. But it is powerless if it receives new data through the ICSP header. Writing through this grants access to the whole arduino memory. After writing your sketch like this you also need to set the fuse bits manually. The chip has special fuse bit that tell it that it that it’s using a bootloader as well as the size of said bootloader so they need to be sorted. Once all of this is done you can enjoy the extra 500 bytes of space free witch is 0.5k or about 1.5% 🙂