Burning Bootloader+program at once through spi

Hello, have searched info about this but I don't find anything related, if someone points me to a link or give instructions or even a clue on how to start digging I will be really thankful: I was able to burn an compile and burn an compiled application using avr-toolchain+avrdude though ISP[1] , but this will erase the bootloader, and if I want to have it again back I can reflash the bootloader but then erase the application. I see Actual arduino boards comes with the bootloader+the blink sketch program on it, but I didn't find a way to do so.

Has the bootloader sources need to be include in the compilation of the program some way to generate one hex file to flash? there is some way to merge two hex files? or a way to tell avrdude to flash one hex and following the other?

Thanks in advance

[1]http://www.tuxbrain.com/en/content/ardunote-project-arduino-nanonote

The .hex files are human-readable text. Open one up in the text viewer of your choice.

The .hex files follow the documented Intel standard. Find a copy of the standard with the search engine of your choice.

With the information you discover you should be able to figure out how to merge the two .hex files into one.

Isn't it impossible to erase the bootloader by accident? And normally the application lives at one end of the memory and the bootloader at the other, so even if the memory-lock bits are reset, the application will only overwrite the bootloader if it occupies almost all the available memory.

http://arduino.cc/forum/index.php/topic,55245.0.html

...found by searching for the end-of-file marker ":00000001FF".

Thanks :)

johnwasser: The .hex files are human-readable text. Open one up in the text viewer of your choice.

The .hex files follow the documented Intel standard. Find a copy of the standard with the search engine of your choice.

With the information you discover you should be able to figure out how to merge the two .hex files into one.

Thank you John. I found it in Wikipedia and it is educational. Another big piece of mystery is made clear!

Does the bootloader allow the MCU to read the .HEX bytes and fill program memory? And without, there is a way described in the ATMEL chip docs?

The bootloader speaks a subset of the STK500 protocol used by the old "AVR ISP" programmer. AVRDUDE (the uploader program) reads the .hex file and sends STK500 commands to write memory pages. It doesn't know (or care) if it is talking to an AVR ISP or a bootloader.

The bootloader doesn't implement lock bit setting so it can't be used to unprotect the bootloader memory and overwrite itself.

The AVR ISP (and other serial programmers) use the SPI pins and Reset (through the ICSP header) to write to memory using the protocol shown in the ATmega datasheet.