Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates the bootloader for 0.7.0 firmware on photon/p1 [ch15177] #418

Merged
merged 4 commits into from
Jun 5, 2018

Conversation

m-mcgowan
Copy link
Contributor

@m-mcgowan m-mcgowan commented Jun 4, 2018

Problem

When running particle update for Device OS firmware 0.7.0 on a Photon or P1 that does not already have Wi-Fi credentials or possibly doesn't have an internet connection available, the bootloader does not get updated. This normally happens when it connects to the Cloud in Safe Mode and the dependency requirement is fulfilled by the Safe Mode Healer.

Solution

Change the particle update process for Photon / P1 only to use a special 0.7.0 system firmware that lowers bootloader dependency to v7, backs up the current user app, and applies a special "ascender" app that updates the bootloader and restores the backed up user app.

The process looks like this:
Enter DFU Mode
Run particle udpate as usual, but in the background:

  • Save current user firmware > user_firmware_backup.bin
  • Load user_firmware_backup.bin into OTA region
  • Load special 0.7.0 system firmware parts
  • Load 0.7.0 bootloader updater app (ascender), leave DFU mode
  • Reset and run ascender app in manual mode.
  • Copy bootloader directly.
  • Flag OTA region to be copied to User region on next boot
  • Reset and run.
  • Bootloader will see and copy OTA image to User space (User firmware restored)
  • Bootloader jumps to User space and runs.

There is one known corner cases which still exists:

In the ascender app, we use a retained variable to keep track of when we’ve updated the bootloader. That way if the app loops for some reason the ascender will not constantly be trying to write the bootloader. A power removal during that would be fatal. The ascender app could loop if the user runs particle update with no user app, and then runs update again with the ascender app loaded. The ascender app would constantly be applying itself in a loop.

Corner Case: If you upgrade with the new method, then downgrading the bootloader and system firmware to 0.6.3, and don’t remove power before trying to upgrade again it will still have the retained memory that says it updated the bootloader already, and it won’t update it. Also to note, if it doesn’t update the bootloader, and it gets online… since it has the new system firmware that says the bootloader >= v7 is ok, the Safe Mode Healer won’t update it either.

  • So particle update should be run on a device that was just powered up, or if downgrading and upgrading again, be sure to remove power for 30 seconds first.

Steps to test

  • Install the prerelease npm install -g https://github.com/particle-iot/particle-cli/releases/download/v1.30.0-rc.1/particle-cli-1.30.0-rc.1.tgz
  • Downgrade your Photon or P1 to 0.6.3 and place tinker on it (Eg. Photon)
particle flash --usb system-part1-0.6.3-photon.bin
particle flash --usb system-part2-0.6.3-photon.bin
particle flash --usb system-part3-0.6.3-photon.bin
particle flash --usb tinker
  • Put device in Listening mode
  • Run particle serial inspect
  • Device should have the following signature (Eg. Photon):
Platform: 6 - Photon
Modules
  Bootloader module #0 - version 11, main location, 16384 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
  System module #1 - version 109, main location, 262144 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
  System module #2 - version 109, main location, 262144 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #1 - version 109
  User module #1 - version 2, main location, 131072 bytes max size
    UUID: 2BA4E71E840F596B812003882AAE7CA6496F1590CA4A049310AF76EAF11C943A
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #2 - version 1
  empty - factory location, 131072 bytes max size
  • Remove power for 30 seconds if not the first time updating!
  • Put device in DFU mode
  • Run the CLI from the repo directory particle-cli $ PARTICLE_CLI_DEVELOPMENT=1 node bin/particle.js update
  • Put device in Listening mode
  • Run particle serial inspect
  • Device should have the following signature (Eg. Photon):
Platform: 6 - Photon
Modules
  Bootloader module #0 - version 101, main location, 16384 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
  System module #1 - version 207, main location, 262144 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
  System module #2 - version 207, main location, 262144 bytes max size
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #1 - version 207
      Bootloader module #0 - version 7
  User module #1 - version 2, main location, 131072 bytes max size
    UUID: 2BA4E71E840F596B812003882AAE7CA6496F1590CA4A049310AF76EAF11C943A
    Integrity: PASS
    Address Range: PASS
    Platform: PASS
    Dependencies: PASS
      System module #2 - version 1
  empty - factory location, 131072 bytes max size

@m-mcgowan m-mcgowan requested a review from technobly June 4, 2018 13:18
Copy link
Member

@monkbroc monkbroc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool idea.

Since the steps to release a new CLI with new system firmware have become more complex, the npm run update-firmware-binaries won't work anymore. I would like to see the steps to update system firmware documented in https://github.com/particle-iot/particle-cli/blob/master/RELEASE.md

@technobly technobly changed the title updates the bootloader for 0.7.0 firmware on photon/p1 updates the bootloader for 0.7.0 firmware on photon/p1 [15177] Jun 4, 2018
@technobly technobly changed the title updates the bootloader for 0.7.0 firmware on photon/p1 [15177] updates the bootloader for 0.7.0 firmware on photon/p1 [ch15177] Jun 4, 2018
@technobly technobly added this to the 1.29.1 milestone Jun 4, 2018
@monkbroc monkbroc force-pushed the feature/update_bootloader branch from f346ecb to 62c29de Compare June 4, 2018 19:24
@technobly technobly modified the milestones: 1.29.1, 1.30.0 Jun 5, 2018
@technobly technobly merged commit 145f74e into master Jun 5, 2018
@technobly technobly deleted the feature/update_bootloader branch June 5, 2018 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants