device-os icon indicating copy to clipboard operation
device-os copied to clipboard

[boron|bsom] u-blox R510 FOTA over HTTPS support

Open technobly opened this issue 4 years ago • 1 comments

Feature

  • u-blox R510 FOTA over HTTPS upgrade support for Gen 3 Boron & B SoM

Details

  • This branch is based on develop-4.x and reverts the commits which removes FOTA support

R510 FOTA Process

R510 Firmware Update Background Check:

  1. Baked into sara_ncp_client.cpp init process
  2. When ATI9 is used to determine the modem version (thus, only when modem is on), check if there is an update firmware version available.
  3. Set updateAvailable flag appropriately for Cellular.updateStatus() if update unknown/not-available/pending/in-progress.

R510 Firmware Update

  1. (Blocking Call) Once Cellular.enableUpdates() is called, initialize state_/status_ from Idle to Qualify.
  2. Check ncpId() == PLATFORM_NCP_SARA_R510
  3. Check updateAvailable == in-progress
  4. Reboot into Safe Mode to start the update process
  5. Particle.connect()
  6. Publish a "spark/device/ncp/update" system event that Device OS has "started" a modem update.
  7. Particle.disconnect()
  8. Disable PPP link and Cellular.connect(), timeout after 10 minutes
  9. Setup HTTPS security options
  10. If an existing FOAT file is present, delete it since there is no way to validate what it is after it's present.
  11. Start the download based our database entry
  12. Download is only complete when the the MD5SUM URC of the file is received and verified
  13. Cellular.disconnect()
  14. Apply the firmware update
  15. Sit in a tight loop while the modem is updating, it will take about 18 to 20 minutes a. waiting for final INSTALL URC of 128 b. polling for AT/OK every 10 seconds c. monitoring a timeout counter of 40 minutes
  16. Save the download/install result to be published once connected to the Cloud again
  17. Re-enable PPP link and Power off the modem
  18. Particle.connect()
  19. Publish a "spark/device/ncp/update" system event that Device OS has finished with "success" or "failed"
  20. Reset the system to exit Safe Mode
  21. On next init, add result status to device diagnostics

Testing

  • Modem must be on 3.15 firmware with hardware (SARA-R510S-01B-00)
  • Use the DIFF below to enable logging during Safe Mode
  • Run the example app below, and use 3 button clicks to kick off an update to 3.30
  • There is also special Dioptra test firmware that has been running for over a week continuously upgrading and downgrading
  • For B SoM EVT3 hardware and testing, it is necessary to use in external SIM with the jumper open
  • Run tinker-serial1-debugging and switch between Kore AT&T and EtherSIM
  • Try cold boot and warm boot, modem should register quickly with 3.15.
  • Run normal Dioptra tests
diff --git a/system/src/main.cpp b/system/src/main.cpp

// UNCOMMENT TO DEBUG SAFE MODE
-// #include "debug_output_handler.h"
-// spark::Serial1LogHandler g_logHandlerSerial1(115200, LOG_LEVEL_ALL);
+#include "debug_output_handler.h"
+spark::Serial1LogHandler g_logHandlerSerial1(115200, LOG_LEVEL_ALL);

Example App

#define PARTICLE_USE_UNSTABLE_API
#include "Particle.h"
#include "log_diagnostics.h"
#include "ncp_fw_update_dynalib.h"
Serial1LogHandler logHandler(115200, LOG_LEVEL_ALL);
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
bool clicks_3 = false;
bool clicks_4 = false;

const SaraNcpFwUpdateConfig saraNcpFwUpdateData1 = {
    sizeof(SaraNcpFwUpdateConfig),
    31500010,
    33000010,
    "SARA-R510S-01B-00-IP-0315A0001_SARA-R510S-01B-01-IP-0330A0001.upd",
    "d5813d5d36e1400f70e3862362fe98f7"
};

void button_handler(system_event_t event, int clicks)
{
    if (event == button_final_click) {
        if (clicks == 3) {
            clicks_3 = true;
        } else if (clicks == 4) {
            clicks_4 = true;
        }
    }
}

void setup() {
    System.on(button_final_click, button_handler);
}

void loop() {
    if (clicks_3 || clicks_4) {
        Log.info("\r\nUpdate Status: %d", Cellular.updateStatus());
        if (clicks_3) {
            ncp_fw_udpate_config(&ncpFwUpdateData1, nullptr);
        } else if (clicks_4) {
            Log.info("\r\n\r\nLog Diagnostics\r\n\r\n");
            cellular::DVT::logDiagnostics();
            Particle.publishVitals();
        }
        Log.info("\r\nUpdate Status: %d", Cellular.updateStatus());
        if (Cellular.updateStatus() == SYSTEM_NCP_FW_UPDATE_STATUS_PENDING) {
            Log.info("Enable Updates: %d", Cellular.enableUpdates());
        }
        clicks_3 = false;
        clicks_4 = false;
    }
}

References

technobly avatar Sep 20 '21 16:09 technobly

For the moment I have reverted renaming the files to make viewing changes easier. This is a TODO for me to go back and rename ncp_fw_update.cpp/.h to sara_ncp_fw_update.cpp/.h

technobly avatar Oct 30 '21 02:10 technobly