I was doing a bit of digging on how the Yun reset button works.http://www.procyonengineering.com/embedded/avr/bootloader/
If I read it correctly when the 32u4 on the Yun resets, the default 32u4 fuse bits for the Yun as used in run-avrdude (Low 0xFF, High, 0xD8, Extended 0xFB) tell it to jump first to the boot reset vector which should be the starting address of the bootloader.
I don't understand enough about the the ATMega32 series of microcontrollers but gleaning a little from herehttp://winavr.scienceprog.com/general-avr/avr-microcontroller-memory-map.html
It would appear the boot vector address is at the top end of the flash memory rather than at the beginning.
So what I suspect is happening is this
1.) I compile for a 32k board
2.) I flash it over the air by disabling the merge with bootloader.
3.) When I press reset the 32u4 attempts to jump to the bootloader address expecting to find boot code there.
4.) Instead it finds an arbitrary line of my code which causes it to lock
So after a little playing with this useful tool http://www.engbedded.com/fusecalc/
I have determined that for me the correct fuse bits (Both preserving EEPROM through the chip cycle and disabling the the BOOTRST feature) should be Low 0xFF, High, 0xD1, Extended 0xFB)
If I have this correct on reset my code should then happily jump to instruction 0x0000 on the reset line being triggered.
If my thinking is correct its a miracle i've ever managed to get my sketch to boot at all