In this thread you might find what you are looking for.
Flashing bootloader from post #28 onwards
About waking up from deep sleep via pin, I’m not sure this would work since you’d need the µC to keep the input circuitry powered which is not deep sleep but only sleep.