Photon Default to user firmware

I want to have a backup copy of my code to fall back on if anything happen during OTA also when user click and hold the mode/reset button (aka flashing white).

I know how to achieve that on Core but Photon.

You can flash the user firmware to 0x80E0000, this is the factory restore location. Keep in mind that due to space constraints this firmware is overwritten when performing a system upgrade OTA.

Factory backup is much less of a necessity on the photon for these reasons:

  • OTA images are fully validated before applying, so there’s never a bad OTA update
  • the system firmware is separate from the application and can be ran without your application by invoking safe mode, so recovery from a badly behaved application is possible without performing a factory reset.

You mentioned reset with flashing white - note that this also erases the wifi credentials. We have now also a Firmware Reset mode that resets the application firmware without clearing wifi credentials.

So I hope after reading that you feel less need to rely upon a factory reset.

  1. What will happen if OTA Verification failed? Will it set a flag or how user app can tell something like that happened.

  2. What if I unplug the device in middle of OTA? a) while downloading firmware, b) while copying firmware to flash

  3. I need to make sure my code will run even if user do the factory reset. I don’t care about WiFi cred being cleared. but running on spark default firmware is not an option.

4. I need to be able to perform restore within my code.

I’ll try to answer these questions/demands, but would be much easier to know what problem you’re trying to solve with some context. :wink:

  1. When an OTA update is cancelled for any reason, the image simply isn’t flashed. At present there is no way to know that OTA has been attempted and failed. Later, system events will allow your app to know OTA has started. You could then for example save the current version of the app and on next restart see if the actual version matches the previously recorded current version. If they are different, an update happened.

  2. You can unplug the device mid-OTA download and it will be as if the OTA was never started. OTA updates are atomic. If the device is unplugged while copying the downloaded firmware to flash (this happens during reboot), the copy will be attempted again on next power up.

  3. If you flash your code to the factory reset region then it will be used to replace the current application on factory reset. If a system OTA update is performed, this region will be overwritten and factory reset unavailable until the factory reset image is restored again. You can restore the factory reset image from your own firmware by writing to flash.

  4. System.factoryReset() reverts to the factory reset firmware

I want to hand the device I built with photon to different people so they can evaluate and wanted to make sure that my firmware will almost always be in there even if they did the factory reset.

The only question left is about “System OTA update”. Who will trigger that? Do I have control over it or will it be auto triggered once device is connected to Spark Cloud?

I’m running with SYSTEM_MODE(MANUAL) but will connect to Spark cloud for OTA

@mdma Flashing Firmware to 0x80E0000 did solved my issue with “flashing white” mode. Now it restores my firmware. But if I put the photon in “Flashing magenta” it won’t load my firmware anymore and goes to flashing cyan mode!

Flashing magenta is “Safe Mode” it doesn’t run your firmware so that you can connect to the cloud in case of flashing broken application firmware.

@mdma How can I disable that?

At present, you cant. When a user enters safe mode, the system will revert to normal operation on the next reset.

Reading between the lines, I’m sensing you’re concerned about the user accessing the bootloader functions, would simply hiding the mode button suffice? The mode button is then only used for configuring WiFi credentials, and that is controllable via your own firmware using the WiFI.listen() function. So you could hide the mode button and instead provide your own means to instigate WiFi setup, should you need that.

I think I can live with the Safe Mode for now.

I’ve added an issue to our backlog to provide a flag that firmware can enable/disable various bootloader modes/functions.

1 Like