[SOLVED]: Flashing System Firmware via COAP


I’m working on the local cloud in order to get system updates working. From what I can tell, everything should be working but maybe I’m missing something.

In my mind, the flow should work something like this for a Photon:

  1. Start sending part 1 of the system firmware
    1. Send BeginUpdate message with a value of 00 01 00 00 03 d4 4c 00 08 02 00 00.
      0x03d44c is the size of the part one firmware
      I’m not using FastOTA for now so I can test some things. I’m passing the memory address of 0x0802000
    2. Send all Chunk messages normally
    3. Wait for UpdateDone COAP message
  2. Start sending part 2 of the system firmware – Repeate all substeps in 1 but pass a memory address of 0x0806000
  3. Send application firmware - Just send an address of 0x0 and the firmware will figure out where things go.

Is this flow correct?
Is there a special COAP message I need to send which will stop the device from resetting after each piece of firmware is sent?

So I’ve spent a lot of time trying to debug this and it seems like the memory address I’m sending isn’t correct or that I’m sending an incorrect flag.

The failure is happening when the first system message chunk is sent. I am getting an empty Ack message back which tells me this code is running but I don’t know where it’s failing after that.

Alright (in case anyone looks at this topic later), I eventually figured it out by flashing debug firmware to my photon and a lot of trial and error.

The main thing is the photon is smart enough to know where to flash system firmware.

OTA system updates work like this:

  1. You flash your device with app firmware built against a newer system firmware than what is on your device.
  2. Your device resets
  3. It checks the firmware and sees that the versions don’t match – the system version is older than the app version.
  4. Goes into safe mode and sends a message to the cloud.
  5. The cloud checks the system info that is passed via the Describe COAP message.
  6. The cloud figures out which modules need to be updated and flashes the first of them.
  7. The device resets and goes to step 3 until all system firmware has been updated.

The offset value that gets passed in the BeginUpdate message only gets used when you are flashing non-firmware storage. It will just get overridden by the system firmware if you pass it anyways. The 0x0802000 only really needs to get sent when you are manually flashing with DFU.