Foodloader is a tiny serial bootloader written in C for the atmel atmega microcontroller series. When this bootloader is installed, the flash and eeprom can be programmed over a simple serial line. Foodloader is minimalistic, neither reading nor writing of lock/fuse bits is supported, but it fits into a 512 words (1024 bytes) bootloader section. For a list of known working microcontrollers, see below.
These controllers are known to work using the current version:
Furthermore, the development version (from the git repository) supports:
First extract the archive into a directory. Only 115200 Baud at 16MHz is supported in the default configuration, if you need another frequency or baud-rate, you have to look up the value of UBRR in the datasheet of the controller, and put this value into uart.h (see comments there). The default is to compile the bootloader for a 512 words bootloader section. On most (all the supported) controllers, this means you have to program the BOOTSZ fuses so that BOOTSZ0 is 1 and BOOTSZ1 is 0 (see datasheet for details). If you want to use the 1024 words bootloader section, you can fine-tune the relocation offsets in the Makefile. For using this bootloader, you either have to program BOOTRST (so that the bootloader is automatically startet after reset) or jump to the bootloader manually. I recommend programming BOOTRST (see datasheet), because this method doesn't depend on working code in the application section (which messes up quiet frequently...).
Before compiling, you have to select your architecture and cpu speed, you can either pass this as commandline arguments to 'make', or put it in a new file called "config.mk", which will be included in the Makefile.
Example for Atmega8, running at 16MHz:
$ make MCU=atmega8 F_CPU=16000000 avr-gcc -g -Os -finline-limit=800 -mmcu=atmega8 -DF_CPU=16000000 -std=gnu99 -DBOOT_SECTION_START=0x1c00 -Werror -c -o foodloader.o foodloader.c avr-gcc -mmcu=atmega8 -Wl,--section-start=.text=0x1c00 -L/usr/local/avr/avr/lib foodloader.o -o foodloader avr-objcopy -O ihex -R .eeprom foodloader foodloader.hex avr-objdump -h -S foodloader > foodloader.lss =============================== compiled for: atmega8 bootloader size is: 836 ===============================
Note: All variables seen in the Makefile can be set via a new file called 'config.mk', example:
SERIAL_DEV=/dev/ttyUSB0 ISP_DEV=/dev/ttyUSB1 ISP_PROG=avr109 AVRDUDE_BAUDRATE=115200 MCU=atmega644 F_CPU=20000000 DEBUG=1 CFLAGS += -DBOOTLOADER_DDR=DDRD CFLAGS += -DBOOTLOADER_PORT=PORTD CFLAGS += -DBOOTLOADER_PIN=PIND CFLAGS += -DBOOTLOADER_PINNUM=PIND7 CFLAGS += -DSEND_BOOT_MESSAGE=1
Now you can install the resulting file "foodloader.hex" with you favourite programming software, or use the provided 'install'-target (if you like avrdude, can be trimmed via make variables).
For starting the bootloader, by default PINC0 has to be pulled low (for example via a jumper). This can also be tuned by make variables (or have a look at config.h)
This bootloader implements the block mode commands from application note AVR109. If SENDBOOTMESSAGE is set to 1, the bootloader writes "ba" (when starting the application) or "bp" (when starting into bootloader mode), you can always jump to the application section by sending "X". For using with avrdude, you have to set the serial programmer to "avr109" and the baudrate (using -b), for example (programming test.hex to an atmega32 at 115200 baud connected at /dev/ttyUSB0):
$ avrdude -p m32 -b 115200 -u -c avr109 -P /dev/ttyUSB0 -U f:w:test.hex
For use with an Atmega88 or Atmega168, you probably have to patch the avrdude configuration file, and set "avr910_devcode" to 0x33 (Atmega88) or 0x35 (Atmega168), since these devices do not have an official devicecode for serial programming via a bootloader (at least as far as I know). In case you wonder: These codes are hardcoded into the bootloader at compile time (according to the mcu it is compiled for) in config.h. A working example ~/.avrduderc can be found here.