|
| 1 | +<h3 id="cli-update">Updating devices with Arm Mbed CLI</h3> |
| 2 | + |
| 3 | +Arm Mbed OS allows you to update your device firmware, enabled by our Pelion IoT platform. Mbed CLI includes features to prepare and ship updates for devices managed through the [Device Management Portal](https://cloud.mbed.com/docs/current/introduction/index.html). Mbed CLI provides the subcommand `mbed device-management` to manage devices (`mbed dev-mgmt` and `mbed dm` are also available as shorter aliases). The remainder of this document uses the `mbed dm` alias for all device management subcommands. This document explains the steps to enable and use Pelion Device Management with a project. |
| 4 | + |
| 5 | +#### Project setup |
| 6 | + |
| 7 | +Configure your Mbed Cloud SDK API key, target and toolchain. Obtain the API key from the the Device Management Portal. |
| 8 | + |
| 9 | +``` |
| 10 | +$ mbed config -G CLOUD_SDK_API_KEY <API_KEY> |
| 11 | +$ mbed target K64F |
| 12 | +$ mbed toolchain GCC_ARM |
| 13 | +``` |
| 14 | + |
| 15 | +Initialize the device management feature of Mbed CLI with the following command: |
| 16 | + |
| 17 | +``` |
| 18 | +$ mbed dm init -d "<company domain name>" --model-name "<product model identifier>" |
| 19 | +``` |
| 20 | + |
| 21 | +<span class="notes">**Note:** If you do not want to enter the subject information for your update certificate (country, state, city, organization and so on), add the `-q` flag to the command above.</span> |
| 22 | + |
| 23 | +This command asks for information about your update certificate. After completing the prompts, Mbed CLI creates several files: |
| 24 | + |
| 25 | +- A certificate in `.update-certificates/default.der`. |
| 26 | +- A matching private key in `.update-certificates/default.key.pem`. |
| 27 | +- A set of default settings in `.manifest_tool.json`. |
| 28 | +- Device Management update credentials in `update_defalut_resources.c` |
| 29 | +- Device Management settings in `.mbed_cloud_config.json`, including default settings for: |
| 30 | + - A unique vendor identifier, based on the domain name supplied as the `-d` parameter to `mbed dm init`. |
| 31 | + - A unique model identifier, based on the vendor identifier and the model name supplied as the `--model-name` to `mbed dm init`. |
| 32 | + - The path of the update certificate and private key. |
| 33 | +- Device Management developer credentials in `mbed_cloud_dev_credentials.c` |
| 34 | + |
| 35 | +<span class="notes">**Note:** The certificate created in `mbed dm init` is not suitable for production. Use it for testing and development only. To create a certificate for production purposes, use an air-gapped computer or a Hardware Security Module. When going to production, conduct a security review on your manifest signing infrastructure because it is the core of the security guarantees for update client.</span> |
| 36 | + |
| 37 | +#### Single-device update |
| 38 | + |
| 39 | +Mbed CLI provides a subcommand, `mbed dm update device`, for development with a device and for testing purposes. After following the steps in [Project setup](#project-setup), perform firmware updates on a device by running: |
| 40 | + |
| 41 | +``` |
| 42 | +$ mbed compile |
| 43 | +``` |
| 44 | + |
| 45 | +This generates a payload to update the device with. After generating the payload, update the device through Device Management with: |
| 46 | + |
| 47 | +``` |
| 48 | +$ mbed dm update device -D <device ID> -m <target> |
| 49 | +``` |
| 50 | + |
| 51 | +This performs several actions: |
| 52 | + |
| 53 | +1. Upload the payload, generated by `mbed compile`, to Device Management. |
| 54 | +1. Hash the payload, and create a manifest that links to its location in Device Management. |
| 55 | +1. Create an update campaign for the supplied device ID, with the newly created manifest. |
| 56 | +1. Start the campaign. |
| 57 | +1. Wait for the campaign to complete. |
| 58 | +1. Delete the payload, manifest and update campaign out of Device Management. |
| 59 | + |
| 60 | +#### Multidevice update |
| 61 | + |
| 62 | +To update more than one device, use Mbed CLI to generate and upload a manifest and payload to the Device Management portal. Then use the Device Management portal to create device filters that include many devices in an update campaign. After the steps in [Project Setup](#project-setup), you can create and upload manifests and payloads by running: |
| 63 | + |
| 64 | +``` |
| 65 | +$ mbed compile |
| 66 | +``` |
| 67 | + |
| 68 | +This generates a payload to update the device with. After generating the payload, upload the payload and manifest with: |
| 69 | + |
| 70 | +``` |
| 71 | +$ mbed dm update prepare |
| 72 | +``` |
| 73 | + |
| 74 | +`mbed dm update prepare` automatically uses the update payload that `mbed compile` generates. You may provide a name and description for the payload and corresponding manifest with additional arguments: |
| 75 | + |
| 76 | +``` |
| 77 | +$ mbed dm update prepare -n <PAYLOAD_NAME> -d <PAYLOAD_DESCRIPTION>\ |
| 78 | + --manifest-name <MANIFEST_NAME> --manifest-description <MANIFEST_DESCRIPTION> |
| 79 | +``` |
| 80 | + |
| 81 | +Both methods of creating a manifest use the defaults created in `mbed dm init`. You can override each default using an input file or command-line arguments. |
| 82 | + |
| 83 | +Once you execute `mbed dm update prepare`, Mbed CLI automatically uploads the payload and manifest to Device Management, and you can then create and start an [update campaign](https://cloud.mbed.com/docs/current/updating-firmware/update-campaigns.html) using the Device Management Portal. |
| 84 | + |
| 85 | +### Advanced use |
| 86 | + |
| 87 | +Mbed CLI allows for significantly more flexibility than the model above shows in exactly the same way as [the manifest tool](https://cloud.mbed.com/docs/current/updating-firmware/manifest-tool.html). You can override each of the defaults that `mbed dm init` sets by using the command-line or an input file. Mbed CLI supports a variety of commands. You can print a full list of commands by using `manifest-tool --help`. |
0 commit comments