The device would need something like a bootloader like Arduino uses to upload firmware. Else you would need like JTAG or some headers to upload the firmware.
Plus you would need to dump the existing firmware, which is usually locked with fuse bits, add your infection and re-upload the firmware. Not to mention if there is even enough memory to spare.