# Writing the bootloader program into ATmega32A

I am in a need of programming a bootloader code written in C into the boot section of AVR ATmega32A using a serial programmer. I can't write the code directly into the boot section from Atmel studio. So, I am looking for a way here. Also, is there any good way of combining application code and Boot code and write them in respective sections using C program?

• Last time I wrote an AVR bootloader was before Atmel Studio but just having a quick I think you should be able to do it under project properties | Toolchain | AVR/GNU Linker | Memory Settings. Normally if I want them combined I do the bootloader, use it to load and then read back the result. – PeterJ May 29 '14 at 11:29
• Yes. I can see the option there, but its really confusing – gzix May 29 '14 at 11:38
• I am really confused with .text and .boot. Also that boot section only take last 512 words,so from where 1234 is coming. Please tell me where to look at for your old project. – gzix May 29 '14 at 12:01
• Ok so i need to replace it with boot section address of Atmega32A. Right am I? – gzix May 29 '14 at 12:11
• I am getting an error "File contents does not map to any valid device memory for programming Flash" when i include .text. when replace it with .boot it works, but writing from the same 0x00 address. – gzix May 29 '14 at 13:11

The ATmega32A Datasheet on page 245 shows the following table of where the bootloader area starts depending on how the BOOTSZ fuses are set:
So assuming you have BOOTSZ0 and BOOTSZ1 are both cleared for the largest bootloader section it will start at 0x3800. From the memory sections documentation you can see the code goes into the .text linker segment and the address may be changed by going under Project properties | Toolchain | AVR/GNU Linker | Memory Settings and adding .text=0x3800 under the FLASH segment section: