Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Created optiboot_copy which is equivalent to memcpy() for program memory. This allowed me to make self-updating firmware.
To work, your sketch must consume less than half of the available program memory. This allows you to temporarily write your entire sketch to the free flash memory and then use optiboot_copy to copy the sketch from the temporary location to the correct address.
When the copy is done, obviously the return address in the call stack is incorrect. Hence the last line of optiboot_copy calls to a user-specified address instead of returning. In my case, that address is 0 which reboots the device.