compiling "ATmegaBOOT_168" Bootloader using Atmel Studio

Hello Friends of tiny MCUs.

I'd like to compile the Arduino Bootloader "ATmegaBOOT_168" and flash it to an Arduino Duemilanove using Atmel Studio 6.2 ( I am new to Atmel Studio - bloady thing).

Therefore I've copied the file to a Project and added the missing definitions that normally come from the Makefile.

#define BAUD_RATE 57600
#define F_CPU 16000000L
#define MAX_TIME_COUNT F_CPU>>4
#define NUM_LED_FLASHES 3
#define EEWE 1

The file compiles fine and I am able to upload the bootloader using avrdude (added as external tool). I recognize that the bootloader is running because it repeats blinking the LED three times as defined.

But when I try to upload a Sketch using Arduino 1.6.4, I get the message that there are some verification errors AFTER the upload (and the sketch does not start).

avrdude: verification error, first mismatch at byte 0x0002
0x34 != 0x5c
avrdude: verification error; content mismatch

Does anybody know how to set up an Atmel Studio Project in order to compile the bootloader for Arduino correctly?

Does anybody know how to set up this Project to use the Arduino's Version of the avr toolchain and libraries so I do not need to define EEWE at all ( I know that there are version differences and maybe some Arduino-specific changes??)

Thanks a lot in advance.

You ask why?
Because I'd like to play around with the bootloader in order to dig deeper into this rabbit hole.

Found one mistake I made but now I run into other problems.

My mystake: I did not set .text to the position where the bootloader should be.
I now added .text=3C00 to the linkers Memory Options.

I verified that I set fuses correctly. I wrote a small batch file that is doing everyting that should be neccessary to set fuses and upload a hex-File. I checked it using the original arduino bootloader hex-File and it is working.

When I upload my own (not further modified) version of this buutloader it does not work (even the LED does not flash).

I hope that someone can give me some hints or advices.

Thansk in advance.

Found out myself what was wrong:

In another thread I read about setting some Linker-options:

-nostartfiles
-nodefaultlibs
-nostdlibs

I un-set those options again and now it is working.

Great point to start... :slight_smile: