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

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

Open
wants to merge 1 commit into
base: develop-4.x
Choose a base branch
from

Conversation

technobly
Copy link
Member

@technobly technobly commented Sep 20, 2021

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 technobly force-pushed the feature/SARA-R510-NCP-FW-update branch 3 times, most recently from c960d0c to 6afbd81 Compare September 20, 2021 22:17
@technobly technobly changed the title [boron|bsom] u-blox R510 support with FOTA over HTTPS [boron|bsom] u-blox R510 FOTA over HTTPS support Sep 20, 2021
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch 3 times, most recently from 545fa28 to 8d591c0 Compare September 27, 2021 18:42
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from 8d591c0 to 89d39b8 Compare October 6, 2021 00:02
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from 89d39b8 to 0e2f5db Compare October 6, 2021 01:11
Copy link
Member

@avtolstoy avtolstoy left a comment

Choose a reason for hiding this comment

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

There is quite a lot of complexity here and since things are not that tightly coupled to NCP client or other subsystems, it would be really nice to see unit tests for this. cellular_command(), callbacks, system methods and other dependent functions can easily be mocked and we can validate all the steps under various conditions.

hal/inc/cellular_hal.h Outdated Show resolved Hide resolved
hal/inc/cellular_hal.h Outdated Show resolved Hide resolved
hal/network/ncp/cellular/cellular_hal.cpp Outdated Show resolved Hide resolved
hal/network/ncp/cellular/cellular_ncp_client.h Outdated Show resolved Hide resolved
hal/network/ncp_client/sara/sara_ncp_client.h Outdated Show resolved Hide resolved
services/src/ncp_fw_update.cpp Outdated Show resolved Hide resolved
services/src/ncp_fw_update.cpp Outdated Show resolved Hide resolved
services/src/ncp_fw_update.cpp Outdated Show resolved Hide resolved
services/src/ncp_fw_update.cpp Outdated Show resolved Hide resolved
services/src/ncp_fw_update.cpp Outdated Show resolved Hide resolved
@technobly
Copy link
Member Author

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 technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from 3c678a4 to 33ff8bf Compare November 15, 2021 18:22
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch 2 times, most recently from 16a5c06 to ae61beb Compare November 23, 2021 20:45
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch 5 times, most recently from 02d203d to e36500c Compare December 15, 2021 17:55
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch 2 times, most recently from 6b634a8 to 9d4d141 Compare January 12, 2022 21:01
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from 9d4d141 to 1296304 Compare January 27, 2022 16:46
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from 1296304 to faf307c Compare February 4, 2022 19:01
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from faf307c to 8f4a7c8 Compare February 28, 2022 22:44
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch 2 times, most recently from c761976 to 5526632 Compare March 25, 2022 21:16
@technobly technobly requested a review from avtolstoy May 12, 2022 02:29
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch 2 times, most recently from e1df053 to 8646a46 Compare July 21, 2022 04:33
@technobly technobly changed the base branch from develop to develop-4.x July 21, 2022 04:40
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from 8646a46 to d611b47 Compare August 31, 2022 01:16
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from d611b47 to a1a35cf Compare June 23, 2023 00:09
…re/SARA-R510-NCP-FW-update)

Author: Technobly <[email protected]>
Date:   Wed Dec 15 16:26:50 2021 -0600

    reduce specificity of expected publishEvent calls

commit c9d846b
Author: Technobly <[email protected]>
Date:   Wed Dec 15 13:24:25 2021 -0600

    update CI unit tests to output verbose logs on failure

commit 62c8fd9
Author: Technobly <[email protected]>
Date:   Tue Dec 14 13:17:39 2021 -0600

    addresses final PR comments

    - Adds SaraNcpFwUpdateLock to make user interfaces thread-safe
    - Fixes issue with sUrcHandlers not retaining unique pointers
    - Allows cellular disconnect timeouts to proceed
    - Adds cellular_lock() before accessing variables used in urcHandlers
    - Fixes errors with comm. unit_tests caused by some initial code added for ncp_fw_update testing
    - Moves all NCPFW_LOG statements during SAFE_MODE to NCPFW_LOG_DEBUG to reduce size

commit b509fbf
Author: Technobly <[email protected]>
Date:   Fri Dec 10 22:42:52 2021 -0600

    adds system_errors and diagnostics

commit ac13d10
Author: Technobly <[email protected]>
Date:   Tue Nov 30 23:20:27 2021 -0600

    adds SaraNcpFwUpdate unit tests

commit 41f4093
Author: Technobly <[email protected]>
Date:   Mon Nov 22 23:19:58 2021 -0600

    [hal] cellular add/remove urc handler

commit 7c0d8f9
Author: Technobly <[email protected]>
Date:   Mon Nov 15 12:21:38 2021 -0600

    skeleton for SaraNcpFwUpdate unit tests

commit 5bb6334
Author: Technobly <[email protected]>
Date:   Fri Oct 29 20:59:23 2021 -0500

    addresses most PR comments

commit d22aaf6
Author: Technobly <[email protected]>
Date:   Fri Oct 22 15:13:34 2021 -0500

    prevent a dependency issue causing a safe mode loop

commit f762226
Author: Technobly <[email protected]>
Date:   Thu Sep 30 10:36:21 2021 -0500

    Implements background modem update checks, Cellular.updateStatus(), Cellular.enableUpdates()

commit 3d09a76
Author: Technobly <[email protected]>
Date:   Wed Sep 29 13:27:24 2021 -0500

    rebase and whitespace fixes

commit 6c2f5e9
Author: Technobly <[email protected]>
Date:   Mon Sep 27 10:34:43 2021 -0500

    Move modem firmware version check to sara_ncp_client

commit ca5cd65
Author: Technobly <[email protected]>
Date:   Tue Sep 21 17:21:37 2021 -0500

    Revert "Remove more R510 FOTA support"

    This reverts commit 532acce.

commit 59b5ec8
Author: Technobly <[email protected]>
Date:   Mon Sep 20 17:13:28 2021 -0500

    Revert "Remove R510 FOTA support"

    This reverts commit a0b92dd.

commit 6ececed
Author: Technobly <[email protected]>
Date:   Fri Sep 17 22:40:41 2021 -0500

    Removes System feature FEATURE_NCP_FW_UPDATES and some cleanup

commit a78f8c1
Author: Technobly <[email protected]>
Date:   Fri Sep 10 17:04:29 2021 -0500

    Remove R510 support for Gen2

commit 82b8b9f
Author: Technobly <[email protected]>
Date:   Fri Aug 13 09:57:55 2021 -0500

    implements System feature FEATURE_NCP_FW_UPDATES and performs NCP FW update in Safe Mode
@technobly technobly force-pushed the feature/SARA-R510-NCP-FW-update branch from a1a35cf to 67d49f3 Compare September 11, 2024 04:00
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.

2 participants