The issue I'm having is understanding how running "program code" copies firmware update code into memory code for the bootloader the programming the device.
Not sure what you don't understand - your main application code simply has some means to get data from whatever comms or storage interface it already uses and program it into the flash.
e.g. if your application already has a SD card filesystem, you add a routine that copies a file from the SD card to the flash. Then all teh bootloader has to do is update the firmware from the flash, which is easy to access.
Intermediate memory bootloaders do not generally make sense for the simple case of updating from a simple serial port etc., though they might be useful in situations where the link may be unreliable - e.g radio - as you can ensure you have a complete and validated image before you start programming it.
The whole point is that where the means of getting the new firmware image is complex ( filesystem, tcp/ip or whatever), you're greatly simplifying the job that the bootloader has to do, minimising its size and complexity.
The bootloader is typically difficult or impossible to update, so you want it to do as little as possible to reduce the likelihood of show-stopping bugs, and leave as much space as possible for your main application code.
After a few hours of reading I have a better understanding.
Here is the catch, you cannot program flash memory from the main application code, The Store Program Memory (SPM) instruction performs self programming only from the Boot Flash section, what this means is and what I was trying to understand is application code will only be responsible for obtaining the firmware from the radio, then a highly stripped down version of optiboot will run read from SPI comms and perform the software upgrade.
I'm slowly going through the application notes and thus far it looks easy.
http://www.atmel.com/images/doc1644.pdfhttp://www.atmel.com/Images/Atmel-0943-In-System-Programming_ApplicationNote_AVR910.pdfUsing SPM Instructions
The Flash memory may be programmed using the Store Program Memory (SPM) instruction. On devices
containing the Self Programming feature the program memory is divided into two main sections: (1)
Application Flash Section and (2) Boot Flash Section.
On devices with boot block, the SPM instruction has the ability to write to the entire Flash memory, but
can only be executed from the Boot section.
Executing SPM from the Application section will have no
effect. On the smaller devices that do not have a boot block, the SPM instruction can be executed from
the entire flash memory.