Custom bootloader for ATmega328P

bootloader

I am designing a board with the ATmega328P and have decided to write my own bootloader rather than use Optiboot or Arduino, etc. I understand the logic of writing the boot code. Also that it resides in a specific area of the flash (max of about 1K). I am using the AVR Studio 6.

How do I target my code to precisely reside in that area? When I generate the hex file they always end up at 0x0000. How to locate them in 0x7000 or wherever the boot section is.

Best Answer

First of all you will need to set the BOOTSZx fuses according to your bootloader size, the boot reset address is not fixed and changes with that. (page 282 of the datasheet , top). You will then need to tell the linker where to put your bootloader code, and this depends on what you are using to write code. In assembly what you need is the .org statement, with AVR studio you should mess around with the "memory settings" and put ".text=0x1234" under flash. Of course 0x1234 should be the right address as per page 282, i.e. 0x3800, 0x3c00, 0x3e00 or 0x3f00.