Loading bootloader and software onto atmega328p via icsp

hi there. i am familiar with installing an arduino bootloader onto an atmega328p using another arduino. i have also installed programs through that process which i believe leaves out the bootloader. my question it: is it possible to load both the bootloader and a software program onto the chip via icsp? many thanks in advance.

You mean to load both in one step, right?
It is possible. You have to create combined HEX file and that is it. Combined HEX you can create by simple copy command, just in the first file it is needed to remove end-of-file record ":00000001FF".
There are also tools for this.
srec_cat.exe
...and of course avr-objcopy.

Hi yes thats exactly what i mean. just to clarify, i would create the hex file for the sketch by sketch > export compiled binary. and then how would i go about creating the hex file for the bootloader?
after that i would need to stitch them together as you have suggested using a hex editor? or would a text editor suffice? not very well versed in this area. thanks for the reply.

Hex file is created by build process and the bootloader is part of SW in ..\avr\bootloaders\optiboot. I suppose you want optiboot.
You just need text editor like Notepad.

Here is an example.
The combined.hex is merged output and .bin is converted to binary to be able to see it as memory dump.
You can see (in .bin) that the end of sketch is at 0x0457, the beginning of the bootloader is 0x7E00 and end is 0x7FFF (max for 328P).

Xexample.zip (5.42 KB)

" i would create the hex file for the sketch by sketch > export compiled binary. and then how would i go about creating the hex file for the bootloader?"

After sketch > export compiled binary, just sketch > Show sketch folder, which will show the sketch and the sketch +bootlooder. The combined sketch works great.
Contents of show sketch folder.
Blink1.ino Blink1.ino.standard.hex Blink1.ino.with_bootloader.standard.hex

hi thanks both for the help. how would i go about uploading the hex file? keeping in mind that i want to upload over ICSP.

i have tried copying the avr dude command which the arduino ide generates C:\Program Files\Arduino_105\hardware\tools\avr/bin/avrdude -CC:\Program Files\Arduino_105\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM10 -b19200 -Uflash:w:C:\Users\EOL\AppData\Local\Temp\arduino_build_112310/hex_test.ino.hex:i

thinking that i could change the directory to the new hex files i generated but i get this error:

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

"i have also installed programs through that process which i believe leaves out the bootloader. my question it: is it possible to load both the bootloader and a software program onto the chip via icsp? many thanks in advance."

Use the same procedure , but use the (your Sketch).ino.with_bootloader.standard.hex .

Make sure you have Verbose output marked in the Preferences section of the Arduino IDE.

Copy the command you use for installing programs and move your combined Hex file to a location where your modified command can get to it.

This was pulled using Sketch>Upload using Programmer and then adding the Path to Blink1.ino.with_bootloader.standard.hex . It will be different on Windows.

/home/kprims/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/kprims/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -P/dev/ttyUSB0 -b19200 -Uflash:w:/home/kprims/Arduino/Blink1/Blink1.ino.with_bootloader.standard.hex:i

C:"Program Files"\Arduino_105\hardware\tools\avr/bin/avrdude -CC:"Program Files"

Notice the " ". Something to cover the spaces.

ok so ive tried this: C:\"Program Files"\Arduino_105\hardware\tools\avr/bin/avrdude -CC:\"Program Files"\Arduino_105\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM10 -b19200 -Uflash:w:C:\Users\EOL\AppData\Local\Temp\arduino_build_112310/hex_test.ino.hex:i
and i now get this error:

avrdude: can't open config file "C:"Program": Invalid argument
avrdude: error reading system wide configuration file "C:"Program"

Somthing like this:

"C:\Program Files" -C"C:\Program Files"

@kprims So the newest IDE has posibility to create sketch+bootloader. I missed it somehow. +1

yes.. Sketch> Export compiled Binary, exports the two Hex files to the Sketch folder. Then Sketch> Show Sketch Folder, will give you the Path and show the files. It has been this way for several Issues of the IDE.

Thanks for the Karma. :slight_smile:

thanks all for the help folks. in the end i switched over to my mac and it worked straight away. damn windows and its fussiness with bloody spaces!!!