Normally, we can just plug an Arduino into a USB port and update the sketch when we want, and leave it connected (for serial commands, etc...) and not update the sketch when we don't want to.
However, for a project I am doing with an Uno, I will be giving the Uno to my end user who may have it connected to USB and whom I would like to be able to update the sketch, but for safety reasons, only when they should be able to (not when someone hacks into their PC, etc...)
I would like to modify the bootloader so that when an attempt is made to upload a new sketch, the user would be asked (via the UI I am already adding) to approve and if they do, the upload would proceed normally and if they do NOT, the upload would fail and the current sketch would continue un-interrupted.
I am thinking adding a 2nd bind-point to the bootloader (in addition to app_start()) called app_upload_request() which a sketch would implement.
When write command('d') is received (line 557), if its the first time since the last Q command or if its the first time since boot, the bootloader will call app_upload_request(). The sketch (if user approves), would then call app_upload_approve() which would call the existing code for 'd'. Additional 'd' commands would be handled as normal.
If the user does not approve, then app_upload_approve() is not called and the response codes (0x14, etc...) are not sent, so avrdude will timeout.
Will this work or totally break avrdude?
Is there a better way?