ATmega8L-8AU bootloader with external crystal

I've just soldered up a new board. It has an ATmega8L-8AU micro controller with an external 8MHz crystal. Now I want to burn an Arduino bootloader with my USBasp. But I haven't found the right boards.txt and bootloader setting for this combination. I did find a bootloader for an ATmega8L but it uses the internal clock. New bootloader file for ATmega8L - hackmeister.dk
Can I use this bootloader and just change the fuse settings in boards.txt? If so how what value should they be set?

You can't just grab a bootloader from the internet.
Some are too old or just not working.

Use OptiBoot to create a bootloader for your avr chip.
And add your settings to boards.txt

make atmega8
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega8 -DF_CPU=8000000L '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -c -o optiboot.o optiboot.c
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega8 -DF_CPU=8000000L '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib -o optiboot_atmega8.elf optiboot.o
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-size optiboot_atmega8.elf
text data bss dec hex filename
480 0 0 480 1e0 optiboot_atmega8.elf
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega8.elf optiboot_atmega8.hex
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-objdump -h -S optiboot_atmega8.elf > optiboot_atmega8.lst
rm optiboot.o optiboot_atmega8.elf

Ok, I've managed to compile an optiboot bootloader for the ATmega8 @ 8MHz using the tools provided with the IDE. Took me some time to figure everything out. But I can't fugure out the fuses, so many options. Anyone that can help me? I have an ATmega8L-8AU with an external 8MHz crystal, chip is running at 5V.

http://www.engbedded.com/fusecalc

Are they different than the 16MHz ATmega8 ? I think they are the same. You could try the settings for the ATmega8 NG in boards.txt

I got it to work with these settings:

##############################################################

atmega8l.name= Bajdi ATmega8L

atmega8l.upload.protocol=arduino
atmega8l.upload.maximum_size=7168
atmega8l.upload.speed=38400

atmega8l.bootloader.low_fuses=0xbf
atmega8l.bootloader.high_fuses=0xcc
atmega8l.bootloader.path=optiboot
atmega8l.bootloader.file=optiboot_atmega8.hex
atmega8l.bootloader.unlock_bits=0x3F
atmega8l.bootloader.lock_bits=0x0F

atmega8l.build.mcu=atmega8
atmega8l.build.f_cpu=8000000L
atmega8l.build.core=arduino
atmega8l.build.variant=standard

Had to recompile the bootloader for a baudrate of 38400, couldn't upload any sketches with a baudrate of 115200. According to this site 115200 is much to fast for 8MHz: WormFood's AVR Baud Rate Calculator Ver. 2.1.1

An atmega8L is not an atmega2560 (256kbyte flash). You don't need a lot of time to upload a maximum of only 8kbyte.
As far as I know, the 115200 should be avoided with 8MHz. Perhaps it is too high or the actual baudrate is not accurate. I think that 38400 is a good (semi-high) value for a 8Mhz atmega8.

The 7168 seems a little low for optiboot. I have seen 7680 for optiboot.
Could you check the size of the bootloader once more ? How much does the optiboot use, and are the fuses set to the proper boot size ?

The few extra bytes can be very useful. Once you start adding things to your sketch, you need more flash memory along the way.

Boot flash size is set to 256 words. Boot start address is $0F00.
I recompiled the bootloader, but how can I see how big it is?

/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega8 -DF_CPU=8000000L '-DLED_START_FLASHES=3' '-DBAUD_RATE=38400' -c -o optiboot.o optiboot.c
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega8 -DF_CPU=8000000L '-DLED_START_FLASHES=3' '-DBAUD_RATE=38400' -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib -o optiboot_atmega8.elf optiboot.o
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-size optiboot_atmega8.elf
text data bss dec hex filename
480 0 0 480 1e0 optiboot_atmega8.elf
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega8.elf optiboot_atmega8.hex
/home/mathias/Arduino/arduino-mvm/hardware/tools/avr/bin/avr-objdump -h -S optiboot_atmega8.elf > optiboot_atmega8.lst
rm optiboot.o optiboot_atmega8.elf

Is the 480 the size of the bootloader? A bit of extra space wouldn't hurt :slight_smile:

Yes, I think 480 is the flash size of the bootloader.
For 480, you need 512 bytes boot sector.

Your fuses are 0xBF 0xCC which is 256 words, and $0F00, as you already have.

8192 - 512 = 7680 bytes for the sketch

I had a sketch once, which was exactly 7680 bytes. That caused a big problem. I tried to rewrite the bootloader, but that failed, so I had to cut the atmega8 out of the circuit and solder a new one in its place. Perhaps I did something wrong, but you could set it to 7679 for safety to be sure.

My atmega8 has other fuses: I have the brown-out not enabled, and I have set the eeprom preserve bit on. I collect data in eeprom, and I didn't want to erase that every time I upload a new sketch.