Yes, now we are in a plan to working with bootloaders and create custom bootloaders. Good, but for enforcing this you will probably need to understand/refresh some useful information!
At first, note that, fundamentally a bootloader (BL) is just a normal AVR application that is positioned in a special region of flash memory. The BL can not easily update its own code, but the BL can reprogram the application region while the BL continues to run (applications very rarely update the BL).
How does a BL know when to start the application? This is a good question, and you can find number of answers for this query! If your device has an input mechanism (for example a button switch) you can just signal your intent with a simple trigger. The BL would normally run the application immediately, and only remain resident itself when a trigger event (like a button push) is initiated during reset. Another solution is for the BL to check an external communication channel (for example USB) for a particular symbol during startup. As in the first solution, here the BL would normally run the application immediately, and only remain resident itself after checking the external communication channel and receiving a certain response.
If these two methods are not practical for your application, you can try the EEPROM solution (assuming your AVR has an EEPROM). This means the storing of a byte value which indicates when the bootloader should continue running and when it should start the application. We will learn more about this procedure through the forthcoming parts of this tutorial.
AVRUSBBoot is a popular bootloader (thanks Thomas Fischl) for the Atmel AVR controllers, uses a firmware-only USB driver to transfer binary data from the PC to the flash of the microcontroller. Once the AVR is flashed with the BL, no other ISP programmer is needed. Thereafter, the microcontroller can be reprogrammed over USB interface.
In principle, AVRUSBBoot can be used with all circuits which are supported by the AVR USB driver. To switch between the BL and the application, an aditional jumper/switch is necessary. The firmware has to be adapted to your hardware. All necessary changes has to be done in the following two files:
(you need avr-gcc, avr-binutils and avr-libc, to compile the firmware)
The bootloader firmware has to be written to the controller with an ISP programmer. Once the bootloader is flashed, you don’t need a programmer and you can download the binary data over USB. However, always remember to set the fuses for the external clock source when flashing the BL for the first time. A C++ tool for downloading hex files is available.
Note that, to compile the program, you need libusb. When the device is connected and the BL is started (set the jumper before connecting the device), hex files can be written to the flash of the microcontroller.
Useful Download Links:
• avrusbboot: http://www.fischl.de/avrusbboot/avrusbboot.2006-06-25.tar.gz
• firmware-only avr usb driver: http://www.obdev.at/products/avrusb/
• libusb: http://libusb.sourceforge.net/
• libusb-win32: http://libusb-win32.sourceforge.net/
AVRUSBBoot a small bootloader enough to fit into the 2 kB boot block of the ATMega8. This boot loader is good for prototyping as there is no need to connect a programmer. Just set a jumper and the programmer is built into the target. More details available here: http://www.fischl.de/avrusbboot/
→ Part 20: Working With Bootloaders & Build Your Own Bootloader – 2
← Part 18: AVR Bootloader