Update devices remotely with this open source tool

Handle all your complete device updates, including firmware and bootloaders, over the air with UpdateHub Community Edition.
109 readers like this.
Working from home at a laptop

Opensource.com

The ability to access, connect, and manage multiple devices remotely through a single account is important. Going a step further, being able to completely update devices remotely is another way for sysadmins to reduce effort and minimize headaches.

UpdateHub is an open source solution that allows you to do complete device updates, including firmware and bootloaders, remotely. Its goal is to make it easier to do device updates and reduce rework and risk, whether you're updating thousands of devices or managing small deployments. UpdateHub handles all aspects of over-the-air (OTA) updates, including package integrity and authenticity, while you take care of your other work.

This step-by-step guide to UpdateHub aims to help you get started with this professional tool. There are two UpdateHub server options: UpdateHub Cloud and UpdateHub Community Edition (UpdateHub CE), a fully open source server (distributed under the MIT License), which is what this tutorial uses.

Check the requirements

First, make sure your Linux distribution has installed all the required packages to build an image using the Yocto Project.

You also need the following hardware:

  • Target is the development device. This tutorial uses a Raspberry Pi 3 Model B+, but you could also use a Raspberry Pi 3, Model B, or Model B+.
  • Host is the computer where you will build the image using the Yocto Project. This tutorial uses Yocto 3.1 Dunfell.

To start UpdateHub CE, you must have Docker installed on the host. If you don't have it, see Docker's orientation and setup instructions.

This tutorial uses Google's repo tool to facilitate the process, as it requires multiple repositories. You can learn more about repo in the Android development setup guide.

On Debian and Ubuntu distros, install repo with:

sudo apt install repo

If you're using another Linux distribution, download repo directly and set your distro with:

mkdir ~/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
PATH=${PATH}:~/bin

Finally, you need network connectivity via DHCP, or you must know how to change the internet protocol (IP) address or to create a Yocto Project layer that handles this configuration.

Prepare your environment for the build

UpdateHub provides a repository with a manifest file used by the repo tool, which makes it easier to manage multiple layers.

Download the source code by creating a directory and fetching the necessary Yocto Project layers:

mkdir updatehub-platform
cd updatehub-platform
repo init -u https://github.com/UpdateHub/updatehub-yocto-project-reference-platform.git -b dunfell
repo sync

After the repo sync command completes, you will see all the layers you need in the sources directory.

The UpdateHub platform provides support for multiple supported devices. During the Yocto Project environment setup, it will ask if you want to accept the end-user license agreement (EULA) of the meta-freescale layer; this is not necessary for this project.

Load the Yocto Project environment:

MACHINE="raspberrypi3" source ./setup-environment build

Note that this command is valid only for the terminal session where you loaded the environment. If you use a new terminal, you will need to load the environment again. However, you won't need to configure the machine again because the configuration content is stored in the conf/local.conf file.

Start UpdateHub CE

With Docker installed, download the Docker image and start the server on port 8080:

docker run -d -p 8080:8080 updatehub/updatehub-ce:latest

Access the UpdateHub CE dashboard through the host IP address and port 8080 (http://IP_ADDRESS:8080). The host IP in the example is 192.168.15.50, so that would be http://192.168.15.50:8080.

Use the default of admin for the login and password, and click Login.

You need to configure the UPDATEHUB_SERVER_URL to use the UpdateHub CE address because the device needs to know the server's IP address. By default, the meta-updatehub layer uses the UpdateHub Cloud address in the server URL variable.

You should see UpdateHub CE's main interface:

Configure the environment to generate the image

The next step is to generate the Linux image that will be used by the device. But first, you need to set up some variables in the conf/local.conf file:

UPDATEHUB_SERVER_URL = "http://IP_ADDRESS:8080"
UPDATEHUB_PACKAGE_VERSION_SUFFIX = "-test-image-1"
ENABLE_UART = "1"
UPDATEHUB_POLLING_INTERVAL = "1m"

Going line by line in the above code:

  • UPDATEHUB_SERVER_URL contains the IP address where UpdateHub CE is running.
  • UPDATEHUB_PACKAGE_VERSION_SUFFIX adds a suffix in the image version. This is useful for placing a version number and incrementing it for each new image. This variable will be the VERSION_ID, which is composed of the DISTRO_VERSION (described in the docs) plus the UPDATEHUB_PACKAGE_VERSION_SUFFIX. You can verify this in the /etc/os-release file in the target.
  • ENABLE_UART: There are several ways to access the target device, such as using the serial console or connecting a keyboard and a monitor. This variable allows access to a serial console on a Raspberry Pi by using the serial ports available on the GPIO header.
  • UPDATEHUB_POLLING_INTERVAL: By default, communication between UpdateHub's agent and server happens every 24 hours. Use this variable to set up a new consultation time of 1 minute.

This tutorial uses Minicom to connect with the target; if you want, you can learn more about using the serial connection in Raspberry Pi.

Generate the image

Now that the Yocto Project environment is ready, compile the image using the BitBake task-execution engine by running:

bitbake updatehub-image-base

Image generation can take a while, depending on the host machine. If this is the first time you are building an image for raspberrypi3 in Yocto's Dunfell branch, BitBake will download the entire source code, so your download speed will influence the time it takes to generate the image.

Once the image is compiled, navigate to the build/tmp/deploy/images/raspberrypi3/ host directory and verify the image file, updatehub-image-minimal-raspberrypi3.wic.gz, is there.

Insert an SD card into your Raspberry Pi and check its name by running dmesg. Then flash the image to your SD card with the following command, but make sure to change /dev/sdX to your SD card name:

zcat updatehub-image-base-raspberrypi3.wic.gz | sudo dd of=/dev/sdX

Insert the imaged SD card into the target device to connect to Raspberry Pi. The image has a network configured to obtain an IP address using DHCP. Access the console with user root and leave the password empty.

Confirm the version of the image running on the target using cat /etc/os-release.

Generate the update package

Your device should be running and working correctly, but you need to add the feature to create an update package. This creates an image to update your target. The following example adds support for an SSH server on the target and creates an update package to install this functionality.

Add support for the OpenSSH server by adding the following line to the build/conf/local.conf file:

IMAGE_FEATURES += "ssh-server-openssh"

To make it clear that the updated image will have another version, put the suffix -test-image-2 in the UPDATEHUB_PACKAGE_VERSION_SUFFIX variable:

UPDATEHUB_PACKAGE_VERSION_SUFFIX = "-test-image-2"

Save the file and run:

bitbake updatehub-image-base -c uhuarchive

This command generates a file with a .uhupkg extension, a format used by UpdateHub to update the system. The generated file will be in the same directory as the images are, tmp/deploy/images/raspberrypi3; in this example, that's updatehub-image-base-raspberrypi3.uhupkg.

Check your device

To access the UpdateHub CE dashboard, click the Devices tab to see if your device is listed:

Send an update package

UpdateHub CE dashboard's Packages tab shows a list of available packages, but you do not have any yet. To add a package, click the Upload Package button, and select the updatehub-image-minimal-raspberrypi3.uhupkg file. In this example, it is in tmp/deploy/images/raspberrypi3/directory. A screen showing the package details will appear. This shows the process of adding an update package to the dashboard:

Create a rollout

With the device recognized and the packet sent to the server, you can create a rollout, which is essentially a deployment plan. Navigate to the Rollouts tab and click Create Rollout. Choose which package version you want to use in the upgrade. This example only has the package from the previous step, with version 20.04-test-image-2. Choose this version, and make sure it includes the list of devices that will be updated.

Previously, you configured the image running on the target to perform an update query on the UpdateHub server every minute, so within one minute of creating the rollout, the update process will start. To track the update status, check the Rollouts tab.

After finishing an upgrade process, the target reboots automatically. The new image boots up and automatically queries the server for updates. The server responds that it does not have any updates and ends the update cycle.

When the status shows updated, run the command below on the host to access the target over SSH:

ssh root@IP_DO_TARGET

No password is required; just press Enter, and you will be in the target console. You can check the version in the /etc/os-release file to confirm.

Congratulations! You're done!

Now you have access to a professional tool to update your devices remotely. This tutorial used a Raspberry Pi 3 with the Yocto Project version Dunfell 3.1.2, but other devices and versions are supported.

If you have any questions about integrating your device, access the developers' team through Gitter or by emailing contact@updatehub.io.


This article is based on UpdateHub: Sending OTA Updates using the Yocto Project on UpdateHub's blog.

What to read next

1 Comment

Hey there, great to see updateHub here!!
It is a great product indeed. I am using it for some embedded projects!! Really easy-to-use and intuitive =D

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.