\chapter{Principle function of a boot-loader}

A boot-loader is a little program, which can receive program data
from a interface and store this data in the instruction memory 
of a processor.
Typically the received program is also started at the end of transmission.
With this method a computer with writable instruction memory
is able to run any application program.

In principle the BIOS of a PC is also a boot-loader,
but the BIOS is extended for the function
to select a interface to fetch the program data.
You can select a chain of peripheral equipment, which is tested
for existence of program data.
Often is a second stage of loader started, which can
choose more selections like different operating systems or
boot options.


For the micro-controllers the function of a boot-loader is designed
more simple. Only one interface is preselected and there are no
further options selectable during operation.
A characteristic for the mode of operation of a boot-loader
is the type of instruction memory. If the instruction memory
of the computer is build with RAM (Random Access Memory),
the boot-loader must be sure to start any application program
only, if it is loaded just before.

For a micro-controller with non-volatile instruction memory (flash),
the boot-loader can assume, that a application program has
been loaded some time ago to the instruction memory.
Therefore the boot-loader try to start a application program every time
after waiting for new program data a appropriate time.
It doesn't matter, if new program data are received before or not.
Even if there was never loaded any application program,
the result is not fatal.
The facility to load a application program later is
still available.
The lack of any application program let the boot-loader resume
with the next try to get program data from the serial interface.

The figure~\ref{fig:ablauf} shows the principle function of
boot-loaders, which receive their data from a serial interface.

\begin{figure}[H]
\centering
\includegraphics[]{../FIG/ablauf.eps}
\caption{Principle function of a boot-loader}
\label{fig:ablauf}
\end{figure}

The transmitter process at the PC will reset the AVR target processor at
the beginning of transmission.
If the reset is not done automatically, you must reset the AVR processor 
manually. 
The PC tries to start the communication with the AVR processor by sending
a data byte to the serial output and wait for any serial response of
the AVR processor.
If the answer is not received in a appropriate time, the procedure is repeated
some times.
The boot-loader program at the AVR processor wait only a limited time for
new data. If the wait time is exceeded, the boot-loader ties to
start a application program in the flash memory.
