Improved failure detection for img upgrade.
Added wipe for miage.