Go Down

Topic: Compiling Optiboot (Read 2635 times) previous topic - next topic



I'm trying to compile an Optiboot bootloader for an ATmega328P running @14.7456 MHz.
I've added an new option to the Makefile:
Code: (arduino-1.6.8/hardware/arduino/avr/bootloaders/optiboot/Makefile) [Select]
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:
Code: [Select]
$ 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:
Code: [Select]
$ 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:
Code: [Select]
TOOLROOT = ../../../tools
This is wrong (probably the path for version 1.0.x of the IDE).
After changing it to
Code: [Select]
TOOLROOT = ../../../../tools
it now finds the compiler, but I get the same error as before:
Code: [Select]
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


It looks like you're using optiboot v4.4. Try it with the latest optiboot source. It doesn't use -mshort-calls. It even automatically deals with the different tool paths between Arduino IDE versions: https://github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/optiboot/Makefile#L80-L84


It compiles without errors with the new version, thanks a lot!

I was using the version that came with the Arduino IDE 1.6.8. Is there any reason why they don't include a newer version of Optiboot with the IDE, it's a bit pointless to include an old version that isn't even compatible with the included avr-gcc version and expects the wrong directory structure ...


Glad to hear!
The Arduino IDE includes the old version because that's the version that they used for the Arduino Uno's optiboot bootloader. They're using the old version for the Arduino bootloaders because that one works fine and I think the developers have the theory of "If it ain't broke...". The only release since v4.4 on the optiboot repository is v6.2, which is "Not a production release".


(also, the Arduino IDE distribution no longer includes all of the tools necessary to build (and version of) optiboot.  There's no "make" for instance.  :-( )


westfw, do you know why they stopped including those tools? make and rm were the only two missing for me on Windows.


do you know why they stopped including those tools?
The old IDE simply included WINAVR, which in turn included a whole bunch of other tools designed to give the user a full development environment on windows.
WINAVR hasn't been updated since 2010, and isn't likely to be updated.  So to get a newer compiler (and full control  of it), the new IDE includes petty much only the gcc-related tools themselves, built by the Arduino team from source (IIRC.) (although, it's the same set of tools that Atmel includes in their "command line tools for xxx" distributions.)  (Sigh.  WINAVR was a very convenient set of tools...)



I am trying to change the baudrade when I am uploading code to my Uno. I am doing this by changing it in optiboot.c. But when trying to compile I get the following message.

C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\optiboot>..\..\..\..\tools\avr\bin\make OS=windows ENV=arduino uno
File path not found

I have tried everything posted in this thread and I have been googling for hours but can't find a solution.

Does anyone have the same problem or a solution?


Dec 07, 2017, 10:19 pm Last Edit: Dec 11, 2017, 09:47 pm by ron_sutherland
The "make" command is a Linux thing and optiboot is built in a way that the IDE does not handle so it needs some different build tools that are controlled with the Makefile.

I think the only real best option is to use Linux which has the native tools, however, there are a few ways to run Linux:

Windows Subsystem for Linux


Ubuntu on PC hardware


Raspibian on a Raspberry Pi


Normally I have an old junk computer running one of the Ubuntu flavors that are happy on it (e.g. Xubuntu or Lubuntu).

Anyway whatever sort of Linux you go with then you need to install the software packages.

Code: [Select]
sudo apt-get update
sudo apt-get install make git picocom gcc-avr binutils-avr gdb-avr avr-libc avrdude
sudo usermod -a -G dialout your_user_name
git clone https://github.com/Optiboot/optiboot
cd optiboot

Did I forget anything?


Dec 07, 2017, 11:12 pm Last Edit: Dec 08, 2017, 02:02 am by pert
Old versions of the Arduino IDE (1.0.6 and older I think) came with make. New IDE versions do not, as we discussed above. You can get make for Windows from an old copy of the Arduino IDE, which you can download here:
or you can get it from winavr:

So no, Linux is absolutely not necessary. I compile bootloaders all the time using Windows.


I start with a 1.0.6 arduino IDE install (.zip package, not installed), and then replace the compiler and compiler supplied libraries with the ones from the latest version of the IDE (or from Atmel Studio).
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy


WinAVR looks dodgy to me, I know it had its day, but its day has passed.

Those packages in Ubuntu and Raspibin are from Debian, and for me have been reliable and up to date.



Lots of GNU tools for Windows here, including make.


As was mentioned above, I'm also using old v1.0.6 with replaced toolchain (gcc v 4.9.2 - make is missing in this one) and with old make.exe v3.81 (from the toolchain with gcc v4.7.2). It works fine for me.
Eventually, here is a link for how to build yourself and for Win download: http://andybrown.me.uk/2015/03/08/avr-gcc-492/.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

Go Up