I have implemented support for firmware upgrade over ethernet for my board using Arduino OTA library.
Link for reference:
https://github.com/JAndrassy/ArduinoOTAThis library loads the new firmware to a specific STORAGE LOCATION in Flash Memory. Then, it re-writes or copies the same new firmware to the APPLICATION REGION of the flash memory and does a reset.
However, if there is a power failure during this re-write, the operation is interrupted and does not complete. The application region does not have the complete code re-written and the system breaks. When I power ON the board again, it is unable to execute the new firmware and cannot rollback on to the old firmware either.
I want to implement a mechanism that protects the system from this kind of failure. I want to modify the bootloader such that it does the following checks before jumping to APPLICATION REGION directly:
Check if a valid firmware image is available in APPLICATION REGION?
Yes? => Jump to application region and run
No? => Check the STORAGE LOCATION in the flash for a valid new firmware?
- - - - - - Yes? => Copy to APPLICATION REGION and reset
Is there any way to check if the firmware is valid? Any in-built support in the bootloader to check the integrity of the firmware?
Any help, guidance or support to do the above mentioned steps by modifying the bootloader will be very useful.