Hello
I'm trying to compile an Optiboot bootloader for an ATmega328P running @14.7456 MHz.
I've added an new option to the Makefile:
atmega328_14_7456: TARGET = atmega328
atmega328_14_7456: MCU_TARGET = atmega328p
atmega328_14_7456: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega328_14_7456: AVR_FREQ = 14745600L
atmega328_14_7456: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
atmega328_14_7456: $(PROGRAM)_atmega328_14_7456.hex
atmega328_14_7456: $(PROGRAM)_atmega328_14_7456.lst
atmega328_14_7456_isp: atmega328
atmega328_14_7456_isp: TARGET = atmega328
atmega328_14_7456_isp: MCU_TARGET = atmega328p
# 512 byte boot, SPIEN
atmega328_14_7456_isp: HFUSE = DE
# Low power xtal (14.7456MHz) 16KCK/14CK+65ms
atmega328_14_7456_isp: LFUSE = FF
# 2.7V brownout
atmega328_14_7456_isp: EFUSE = 05
atmega328_14_7456_isp: isp
I'm having problems compiling it: when using avr-gcc from the Ubuntu 16.04 repositories (sudo apt-get install gcc-avr avr-libc), I get the following error:
$ make atmega328_14_7456
avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=14745600L '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -c -o optiboot.o optiboot.c
avr-gcc: error: unrecognized command line option ‘-mshort-calls’
<builtin>: recipe for target 'optiboot.o' failed
make: *** [optiboot.o] Error 1
This is probably because the version of avr-gcc I'm using (4.9.2) is not supported. From the Optiboot wiki:
Optiboot is designed to be compiled with the same version of avr-gcc that is distributed with the Arduino environment: 4.3.2. This is actually quite an old version of gcc; some effort has been made to allow the compile to procede with new versions of the compiler. However, since Optiboot MUST compile to a total size of less than 512 bytes, it is very sensitive to changes in the way the compiler does optimizations, or the way it processes optimization options on the compile command.
So I decided to use the version that came with the Arduino IDE:
$ export ENV=arduino
$ make atmega328_14_7456
../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=14745600L '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -c -o optiboot.o optiboot.c
make: ../../../tools/avr/bin/avr-gcc: Command not found
<builtin>: recipe for target 'optiboot.o' failed
make: *** [optiboot.o] Error 127
This is because the Makefile contains the wrong paths: on line 52, it has:
TOOLROOT = ../../../tools
This is wrong (probably the path for version 1.0.x of the IDE).
After changing it to
TOOLROOT = ../../../../tools
it now finds the compiler, but I get the same error as before:
make atmega328_14_7456
../../../../tools/avr/bin/avr-gcc -g -Wall -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls -mmcu=atmega328p -DF_CPU=14745600L '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' -c -o optiboot.o optiboot.c
avr-gcc: error: unrecognized command line option '-mshort-calls'
<builtin>: recipe for target 'optiboot.o' failed
make: *** [optiboot.o] Error 1
This is because the Arduino IDE now comes with avr-gcc 4.8.1.
But both the Optiboot Wiki page and the Arduino's optiboot folder haven't been updated for over a year ...
How do I compile it? Could I just delete the -mshort flag? That'll probably compile to a hex file that's too large, right?
Thanks in advance
Pieter