How to: Compiling the Arduino Bootloader…

A project we’ve been recently working on requires a custom Arduino boot loader.  Working in an incremental fashion, the first step is getting the stock Arduino boot loader to compile with the latest WinAVR libraries and current Arduino 1.0 IDE.  While this wasn’t terribly difficult, it did require a bit of searching, debugging, testing and then a bit more debugging before it worked as intended.  Presented here for your convenience, are the fruits of this labor, outlined are the following steps:

  1. Download the latest Arduino IDE – 1.0
  2. Modify the boot loader source
  3. Modify the makefile
  4. Compile in command prompt

Step 1: Download the latest Arduino IDE – 1.0

The latest Arduino IDE, version 1.0 can be downloaded directly here:
The complete package is an 86MB zip that unpacks to about 240 MB.
You can also locate the specific files in the Github Arduino repository.

Once you’ve downloaded and unzipped it, navigate to the bootloaders folder at the following path in Windows:  arduino-1.0hardwarearduinobootloaders.  On the Mac, the path is /Applications/  For purposes of testing, I’ve made a new folder here called: atmega168test.  And populated the new test folder with the two files ATmegaBOOT_168.c and Makefile from the folder atmega.

For programming under Windows, I prefer to use Programmers Notepad 2, an open source editor with syntax highlighting for many common languages (it makes the words pretty colors).  You can download it here:  Windows Notepad or any other text editor will also suffice.

Step 2: Modify the boot loader source

The first (and only) compiler error we will tackle is due to the EEWE bit definition missing in versions 1.6.7 and newer of the file /avr/eeprom.h.  The actual compiler error reads as:

ATmegaBOOT_168.c: In function ‘main’:
ATmegaBOOT_168.c:596:11: error: ‘EEWE’ undeclared (first use in this function)
ATmegaBOOT_168.c:596:11: note: each undeclared identifier is reported only once for each function it appears in
make: *** [ATmegaBOOT_168.o] Error 1

This EEWE issue (152) has been around for a while and was originally reported in 2009.  Within the source file ATmegaBOOT_168.c, around line 584, we will comment out the old and add in the new:

// ?kraz? -fixed EEWE bit definition missing in versions 1.6.7 and newer of the file /avr/eeprom.h
// According to this issue reported in 2009:
#if defined(EEPE)
				while(bit_is_set(EECR,EEPE));			//Wait for previous EEPROM writes to complete
				while(bit_is_set(EECR,EEWE));			//Wait for previous EEPROM writes to complete

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__)
				while(bit_is_set(EECR,EEPE));			//Wait for previous EEPROM writes to complete
				while(bit_is_set(EECR,EEWE));			//Wait for previous EEPROM writes to complete

And don’t forget to save the file!

Step 3: Modify the makefile

Now that we have the bootloader fixed, it does compile without error, but it ends up larger than the 2k space allocation for the bootloader section of the MCUs flash.  The easiest solution here is to bump the compiler optimization level up to -0s.  This is in the makefile on line 52, beware the makefile isn’t C language, it uses the # operator to comment out a line:

# ?kraz? - changed opt level to fit under 2k
# OPTIMIZE   = -O2

Step 4: Compile in command prompt
The final step is to compile, under Windows we will be using the command prompt.  The location of command prompt will depend on your version of Windows, in 7 it can be found by typing the first few letters of command in the search box of the start menu.  Once it’s open, use the “CD” command navigate to the bootloader folder of your Arduino install as seen below in Windows, like this:

cd C:arduino-1.0hardwarearduinobootloadersatmega168test

And on the Mac, like this:

cd /Applications/

We then compile with the command “make pro8”, which specifies the target board, in this case it’s an Mega168 clocked at a relaxing 8Mhz.  Other board target definitions can be found listed in the makefile, such as diecimila, lilypad, ng, atmega328_pro8, mega, etc.   If the hex already exists in the folder, you will get a message make: Nothing to be done for `pro8′.  In this case just delete the hex and compile again with “make pro8”.  If everything went alright, you should see the compiler report as in the first image at the top of this post.  Good luck and happy compiling!

5 Responses to “How to: Compiling the Arduino Bootloader…

  • What would be the reasons for redoing the bootloader?

  • Re-compiling the bootloader (and testing it) was the first step before making some changes to support an alternative boot load method. This alternative method allowing the Arduino device to boot load wirelessly over low cost IR. A variation on the Asuro bootlaoder…

  • i ran in this issue again- I am using a board from myavr with 20MHz. Intereting that this issue is still not fixed in arduino 1.0.1- even though there is a bug report from 2010:

  • A very useful page thanks.
    I needed to rebuild the bootloader with the watchdog fix enabled.

  • How do I make “make” work?
    On Windows 10, I get:
    ‘make’ is not recognized as an internal or external command, operable program or batch file.

Leave a Reply

Your email address will not be published. Required fields are marked *