|
| 1 | +# Performing Device Firmware Upgrade in the nRF Connect SDK examples |
| 2 | + |
| 3 | +The following examples for the development kits from Nordic Semiconductor |
| 4 | +support over-the-air Device Firmware Upgrade: |
| 5 | + |
| 6 | +- [CHIP nRF Connect Lock Example Application](../../examples/lock-app/nrfconnect/README.md) |
| 7 | +- [CHIP nRF Connect Lighting Example Application](../../examples/lighting-app/nrfconnect/README.md) |
| 8 | + |
| 9 | +Currently, the Bluetooth LE is the only available transport for performing the |
| 10 | +DFU operation and it uses |
| 11 | +[Simple Management Protocol](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/device_mgmt/index.html#device-mgmt). |
| 12 | +The upgrade can be done either using a smartphone application or a PC command |
| 13 | +line tool. |
| 14 | + |
| 15 | +## Device Firmware Upgrade using smartphone |
| 16 | + |
| 17 | +To upgrade your device firmware over Bluetooth LE using smartphone, complete the |
| 18 | +following steps: |
| 19 | + |
| 20 | +1. Install one of the following applications on your smartphone: |
| 21 | + |
| 22 | + - [nRF Connect for Mobile](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Connect-for-mobile) |
| 23 | + - [nRF Toolbox](https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Toolbox) |
| 24 | + |
| 25 | +2. Push **Button 1** on the device to enable the software update functionality. |
| 26 | +3. Push **Button 4** on the device to start the Bluetooth LE advertising. |
| 27 | +4. Follow the instructions about downloading the new image to a device on the |
| 28 | + [FOTA upgrades](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_nrf52.html#fota-upgrades) |
| 29 | + page in the nRF Connect documentation. |
| 30 | + |
| 31 | +## Device Firmware Upgrade using PC command line tool |
| 32 | + |
| 33 | +To upgrade your device firmware over Bluetooth LE, you can use the PC command |
| 34 | +line tool provided by the [mcumgr](https://github.com/zephyrproject-rtos/mcumgr) |
| 35 | +project. |
| 36 | + |
| 37 | +> **_WARNING:_** mcumgr tool using Bluetooth LE is available only for Linux and |
| 38 | +> macOS systems. On Windows, there is no support for Device Firmware Upgrade |
| 39 | +> over Bluetooth LE yet. |
| 40 | +
|
| 41 | +Complete the following steps to perform DFU using mcumgr: |
| 42 | + |
| 43 | +1. Install the tool by following the |
| 44 | + [mcumgr command line tool installation instructions](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/device_mgmt/index.html#command-line-tool). |
| 45 | +2. Push **Button 1** on the device to enable software update functionality. |
| 46 | +3. Push **Button 4** on the device to start the Bluetooth LE advertising. |
| 47 | + |
| 48 | +> **_NOTE:_** In all of the commands listed in the following steps, replace |
| 49 | +> `ble-hci-number` with the Bluetooth hci integer value (for example, `0`) and |
| 50 | +> `ble-device-name` with the CHIP device name advertised over Bluetooth LE (for |
| 51 | +> example, `ChipLock`). |
| 52 | +
|
| 53 | +4. Upload the firmware image to the device by running the following command in |
| 54 | + your example directory: |
| 55 | + |
| 56 | + $ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' image upload build/zephyr/app_update.bin |
| 57 | + |
| 58 | + The operation can take few minutes. Wait until the progress bar reaches |
| 59 | + 100%. |
| 60 | + |
| 61 | +5. Obtain the list of images present in the device memory by running following |
| 62 | + command: |
| 63 | + |
| 64 | + $ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' image list |
| 65 | + |
| 66 | + The displayed output contains the old image in slot 0 that is currently |
| 67 | + active and the new image in slot 1, which is not active yet (flags field |
| 68 | + empty): |
| 69 | + |
| 70 | + Images: |
| 71 | + image=0 slot=0 |
| 72 | + version: 0.0.0 |
| 73 | + bootable: true |
| 74 | + flags: active confirmed |
| 75 | + hash: 7bb0e909a846e833465cbb44c581cf045413a5446c6953a30a3dcc2c3ad51764 |
| 76 | + image=0 slot=1 |
| 77 | + version: 0.0.0 |
| 78 | + bootable: true |
| 79 | + flags: |
| 80 | + hash: cbd58fc3821e749d3abfb00b3069f98c078824735f1b2a333e8a1579971e7de1 |
| 81 | + Split status: N/A (0) |
| 82 | + |
| 83 | +6. Swap the firmware images by calling the following method with `image-hash` |
| 84 | + replaced by the image present in the slot 1 hash (for example, |
| 85 | + `cbd58fc3821e749d3abfb00b3069f98c078824735f1b2a333e8a1579971e7de1`): |
| 86 | + |
| 87 | + $ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' image test image-hash |
| 88 | + |
| 89 | + You can observe that the `flags:` field in the image for slot 1 changes |
| 90 | + value to `pending`: |
| 91 | + |
| 92 | + Images: |
| 93 | + image=0 slot=0 |
| 94 | + version: 0.0.0 |
| 95 | + bootable: true |
| 96 | + flags: active confirmed |
| 97 | + hash: 7bb0e909a846e833465cbb44c581cf045413a5446c6953a30a3dcc2c3ad51764 |
| 98 | + image=0 slot=1 |
| 99 | + version: 0.0.0 |
| 100 | + bootable: true |
| 101 | + flags: pending |
| 102 | + hash: cbd58fc3821e749d3abfb00b3069f98c078824735f1b2a333e8a1579971e7de1 |
| 103 | + Split status: N/A (0) |
| 104 | + |
| 105 | +7. Reset the device with the following command to let the bootloader swap |
| 106 | + images: |
| 107 | + |
| 108 | + $ sudo mcumgr --conntype ble --hci ble-hci-number --connstring peer_name='ble-device-name' reset |
| 109 | + |
| 110 | + The device is reset and the following notifications appear in its console: |
| 111 | + |
| 112 | + *** Booting Zephyr OS build zephyr-v2.5.0-1101-ga9d3aef65424 *** |
| 113 | + I: Starting bootloader |
| 114 | + I: Primary image: magic=good, swap_type=0x2, copy_done=0x1, image_ok=0x1 |
| 115 | + I: Secondary image: magic=good, swap_type=0x2, copy_done=0x3, image_ok=0x3 |
| 116 | + I: Boot source: none |
| 117 | + I: Swap type: test |
| 118 | + |
| 119 | + Swapping operation can take some time, and after it completes, the new |
| 120 | + firmware is booted. |
| 121 | + |
| 122 | +Visit the |
| 123 | +[mcumgr image management](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/device_mgmt/indexhtml#image-management) |
| 124 | +section to get familiar with all image management commands supported by the |
| 125 | +tool. |
0 commit comments