Compiling Optiboot


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

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: optiboot/Makefile at master · Optiboot/optiboot · GitHub

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. :frowning: )

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?

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.

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
cd optiboot

Did I forget anything?

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).

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:

It's not THAT bad.
Install any relatively recent version of the Arduino IDE.
Install the GnuWin Make for windows (ie from Make for Windows) (use the "setup" version to make sure all the right dlls are installed too.)
Open a command prompt window. Make sure that "make.exe" works (I don't think the installer for make adds the gnuwin directory to the path.)
Execute the really neat and horribly ugly .BAT file described here: install-avr-tools | (download from here GitHub - WestfW/Arduino-avr-tools-install: Given Windows with some version of Arduino installed, set the paths to allow using avr-gcc/etc from the command line.
Connect to the ...optiboot/bootloaders/optiboot directory where the source code lives.

Then you should be able to issue "make whatever" command to do the compile...

Oh, admittedly it might be nice if more of this happened semi-automatically, and if the .bat file looked for GnuWin, and it might be a bit ... overwhelming ... if you've never used a "Command Prompt" window before, but it still ought to be better than "learn enough linux to throw away your windows box."

Ok, I've made it easier.
If you download the new omake.bat from optiboot/omake.bat at master · Optiboot/optiboot · GitHub (with or without the rest of the most recent optiboot), it is smart enough to go out and find avr-gcc in most of the likely location and version combinations before running the compile.
You still have to have Arduino and make installed somewhere, but you no longer have to fiddle with paths. So:

  • Install Arduino
  • Install the gnuwin Make.
  • get the new omake.bat and/or the rest of the current optiboot tree.
  • In a command-line window, connect to the directory that contains optiboot.c (...\bootloaders\optiboot, usually.)
  • Issue the desired build command using omake instead of make, ie: ".\omake.bat atmega32 BAUD_RATE=19200" or whatever....

Thank you all for answers!

I tried what westfw suggested and nothing really happened. Then I installed an older version of Arduino and the make failed and got the following message:

"C:\Program Files (x86)\Arduino\hardware\arduino\bootloaders\optiboot>.\omake.bat atmega328 BAUD_RATE=19200
avr-gcc already installed at C:\Program Files\avr8-gnu-toolchain\bin\avr-gcc.exe
‘DEBUG’ is not recognized as an internal or external command,
operable program or batch file.
avr-gcc (AVR_8_bit_GNU_Toolchain_3.5.4_1709) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

process_begin: CreateProcess(NULL, bash, …) failed.
make (e=2): File not found.
make: [baudcheck] Fel 2 (ignoreras)
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L -DBAUD_RATE=19200 -DLED_START_FLASHES=3 -c -o optiboot.o optiboot.c
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=16000000L -DBAUD_RATE=19200 -DLED_START_FLASHES=3 -Wl,–section-start=.text=0x7e00 -Wl,–section-start=.version=0x7ffe -Wl,–relax -nostartfiles -nostdlib -o optiboot_atmega328.elf optiboot.o -lc
avr-size optiboot_atmega328.elf
text data bss dec hex filename
464 0 0 464 1d0 optiboot_atmega328.elf
avr-objcopy -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex optiboot_atmega328.elf optiboot_atmega328.hex
avr-objdump -h -S optiboot_atmega328.elf > optiboot_atmega328.lst
Acces denied.
make: *** [optiboot_atmega328.lst] error"

"C:\Program Files (x86)\Arduino\hardware\arduino\bootloaders\optiboot>.\omake.bat atmega328
Acces denied.

You may need to copy the optiboot directory to somewhere that is writeable by non-admin users.
I think windows will object (these days) to actually writing files under the "C:\Program Files" location.

Sigh. It also looks like it needs some more modifications to work on 64bit windows :frowning: