logo
logo
Bootloader Overview

Overview

A bootloader is a piece of software that is loaded onto your board which allows you to easly upload your new projects to the board without requiring any special hardware. As such you can think of it as a 'software programmer'. Most boards today come with a bootloader already installed.

Such programming is normally done via USB nowadays - although legacy communications such as RS232 and parallel LPT are still sometimes seen (but your modern laptops may no longer have these sort of ports as they are physically quite large).

Being a software protocol then it has obvious advantages: easy to use, cannot accidentally 'brick' your board, normally just requires a cable connection from the board to your host development environment.

How are bootloaders stored?

You may be wondering how a board has two pieces of software installed:-

  • The bootloader that is always present (but see later) and allows you to upload your latest project code
  • Your latest project code

The way this works is that the bootloader code lives at the top end of your program/flash memory. It never changes, so is a fixed size, and can therefore carve out and live in a lump of memory right at the very end of your available program space.

Your own project code, on the other hand, starts at the low end of memory. As your project gets bigger then it grows towards the end of memory. Obviously it would be 'bad' if your program grew so large that it started overwriting the bootloader in the top area of memory. A well behaved bootloader will detect this and prevent it from happening as it would obviously cause chaos.

How do bootloaders work?

The easiest way to think of it is that when your board is powered on then the bootloader is called.

If nothing talks, sensibly, to the bootloader then it gives up and goes to your existing project code.

If the bootloader recognises what it is being asked to do then it will upload a new version of your project and then call this, now existing, porject code.

So the bootloader is like a piece of code that is called before your own project code and therefore has a chance to replace your project code.

How does the board know where the bootloader lives?

Depending on the complexity/functionality of the bootloader it could be loaded at a different position in memory (ie will be the end of memory minus how large the bootloader is). Since the board has no way of knowing what bootloader you have got and how large it is then you need to tell it where it lives.

On AVR boards this is achieved via editing the 'fuses' with a hardware programmer.

It is imperative that this is done correctly to ensure reliable re-programming via the bootloader.

How to re-install a bootloader and make sure its settings are correct?

First you need to recognise that there are lots of different bootloaders. FBoot is used by the Axon series of boards, Arduino boards have their own, etc. So, for copyright reasons, I can't always give you the code for everything!

But assuming you have the ".hex" file for the required bootloader then you will need to upload it using a hardware programmer. Potentially you will also need to make sure that fuses are configured correctly to run the bootloader. Bootloaders downloadable from this site should tell you about relevant fuse settings. I can't vouch for other sites!

Do bootloaders reduce how large my own project can be?

Yes! The space available to your project is reduced by the size of the bootloader. Simple bootloaders like FBoot are purposely written to be small - say around 1Kb (1024 bytes). The signifance of this overhead depends on your board. An Axon, or other ATMega640 based board, has 64k of memory and so losing 1Kb is less significant than with say an 8k board.

So if your project code is trying to squeeze every last byte from its host board then you may need to overwrite the bootloader by uploading your project with a hardware programmer - which will delete the software bootloader.

What kills a bootloader?

The simplest explanation is:- when you program your board using anything other than the existing bootloader.

So if you program your board with another hardware programmer such as the AVRISP MKII then it will remove the bootloader.

The only way to re-instate a bootloader is to use a hardware programmer to re-install it.

Generally this is ok - ie if you can only remove a bootloader by using a hardware programmer then you must own a hardware programmer. You can therefore re-install the bootloader so long as you have access to the bootloader project code (and I list then here).