Uploading Bootloader and Sketch at the same time?

Is there any easy way to upload the Arduino Bootloader and a Sketch to the Atmega 328 using an Arduino as the programming platform?
I'm looking to put together a project for our hackspace and so may need to add the bootloader and sketches to a lot of ICs.

Any pointers appreciated,
Albert.

That uploads a bootloader in about a second. You could modify it to add a sketch as well. Or use this:

Thank you. This looks like exactly what I'm looking for.
If only I'm smart enough to figure it out...

Based on this guide. It would be great to read a 328 with bootloader and sketch to a microSD card then program it back to blank 328s.

Again thanks,
Albert.

A follow on question. From reading the articles am I right that the Sketch when uploaded starts at 0000hx while the bootloader, depending on it's sizes starts at one of the following:

7000: 4096 byte bootloader/
7800: 2048 byte bootloader
7C00: 1024 byte bootloader
7E00: 512 byte bootloader

Meaning if I wanted to manually create a 32K hex file I could take the original sketch hex and the relevant hex file for the bootloader being used and put them together in a 32k hex file.

I assume I wouldn't have to care about what's between the Sketch hex and the Bootloader hex?
Also, even if the bootloader is smaller than 4096 (and space permitting) could I start all versions of a bootloader at 7000?

Yes that sounds right.

The bootloader is indeed just code at the top end of program memory. It you wanted to have a bootloader, and an initial sketch you need to make the BOOTRST fuse jump to the bootloader first.

I assume I wouldn't have to care about what's between the Sketch hex and the Bootloader hex?

No, it would normally be 0xFF.

I think with my hex (file) uploader sketch, if you save program memory to disk it saves all of memory, but I might be wrong.

Also, even if the bootloader is smaller than 4096 (and space permitting) could I start all versions of a bootloader at 7000?

Yes, if the bootloader is compiled to run at that address. However Optiboot, for example, is not.

There are assorted methods and utilities for merging two .hex files (assuming that they don't overlap.) It's almost trivial to do manually with a text editor. Here's one: bialix.com

My sketch doesn't write lines consisting of all 0xFF (since that is the default after an erase) so you should get a reasonably small file out of it.