Hello everyone, I am a software upgrade package. For the next few days, I’m going on a magical web tour, from the developer’s computer to the embedded terminal.

People refer to this process as OTA, which stands for online upgrade.

So what are OTAs? Over the Air Technology is a way to download a new software package from a server and update it to a device Over the Internet.

First of all, why is it called a software upgrade pack and not a firmware upgrade pack?

In fact, in essence, firmware also belongs to software, we are written with code!

Although these two statements are very similar, some people still make some distinction between them in a narrow sense.

In this case, we will temporarily distinguish them from each other:

  1. Firmware: Divides Flash into functional partitions on embedded devices without file systems. The executable program needs to be placed at a fixed starting location before it can be started by the bootloader.

  2. Software: An embedded device with a file system in which executable programs are placed directly. When the device is started, the operating system launches executable programs in the file system.

Embedded devices without file systems:

Device with file system:

I know the above distinction is not very strict, but who can clearly define the definition of strict?

So first to distinguish, as long as it does not affect the understanding of the article can!

From a macro point of view, the software upgrade of an embedded device can be divided into two stages:

  1. Download the upgrade package.

  2. Decompress the upgrade package and write it to the flash or file system.

Today, I’ll focus on stage 1, showing you how I was downloaded from the developer’s computer, step by step, to the embedded device.

Here’s a sneak peek at the full process!





For the sake of description, consider a scenario where the software running on the device has three files in total:

  1. Main file: executable program;

  2. Config. ini: indicates the configuration file.

  3. Mylib. so: a dynamic library file containing an algorithm called by the main file;

The current version running on the device is V1.0. Now the developers have optimized the algorithm in the mylib.so library and upgraded it to V2.0. Now they need to upgrade this new version to embedded devices.

The first step is to upload the V2.0 version of the program to the file server.

A word of caution: many cloud platforms distinguish between application servers and file servers. Of course, they can coexist on the same physical server, if only for testing.

For example, on Amazon’s AWS platform, upgrade packages are uploaded to S3 servers.

Ini, mylib.so, and another script file, upgrade.sh.

The purpose of this file will be revealed later.

The bbingo – V2.0 upgrade package is now available: app_v2_0.tgz. Once uploaded to the file server, the address is http://fileserve/app_v2_0.tgz.





Now that the V2.0 upgrade package has been uploaded to the file server, can you now command the embedded device to download and upgrade it?

As we know, in an Internet of things system, there are usually many terminal devices.

These devices may be running or in a power outage, and we cannot assume that all devices will be upgraded at the same time.

Also, if a device is upgraded to the latest V2.0 version, the device should have the ability to know that the latest version on the server is V2.0, so that it does not need to be upgraded.

Therefore, a new file is needed to describe the V2.0 update package in the file server. It is called: the update package description file app_desc.json, which contains a string in JSON format:

The Version field describes the version of the upgrade package on the file server, so that the device can know the latest version on the server.

The URL field describes the download address of the upgrade package. If the version of the device is earlier than that in the Version field, the device can download a new upgrade package from this address.

The MD5 field describes the fingerprint information of the latest upgrade package on the server. After downloading the upgrade package from the server, the device calculates the MD5 value of the upgrade package and compares it with the MD5 field. If the value is the same, the downloaded upgrade package is normal and has not been replaced by malicious people.

Once you understand the purpose of the upgrade package description file app_desc.json, this file is uploaded to the application server.





At this point, as the upgrade package, I’m sitting quietly in the file server, and my brother’s upgrade package description file, app_desc.json, is ready in the application server, waiting for the embedded device to start upgrading.

Everything is ready, only the east wind! There is only one action left to trigger the embedded device to upgrade!

So, when should it be? By whom? To tell the device that the software you are running is too old, the latest version is now available on the server, you should upgrade.

The answer to this question is: the eight immortals have crossed the sea.

Such as:

  1. Amazon’s AWS platform notifies each device that needs to be upgraded by deploying a job in the cloud platform.

  2. You can also initiate a command to an embedded device via a mobile APP: Hey, buddy, please upgrade your software;

After receiving the upgrade command, the first step is to download the description of the upgrade package.

After downloading, the TEXT content in JSON format is parsed and the version information is extracted and compared with the software version currently running.

If the version on the server is new, proceed to extract the upgrade package download address in the URL field, and then start downloading the new upgrade package from the file server.

If the current running version is already up to date, that’s it!





To download the update, you can use a tool like Wget or curl library to download the code by hand.

Anyway, there are 10,000 ways you can download me to the device.

Once the download is complete, one important thing to remember is to check that the downloaded upgrade package is correct!

Remember the MD5 field in the upgrade package description file? That’s my fingerprint information.

You need to calculate the MD5 value of the downloaded upgrade package and compare it with the MD5 value in the upgrade package description file. If the value is the same, go ahead and decompress the upgrade package.





To find out what happens next, join us next time!





Hi, I’m Doug, a veteran of embedded development. This is my personal wechat, do a “like” turn is also good!











[1] C language pointer – from the underlying principle to the tricks, with graphics and code to help you explain thoroughly [2] step by step analysis – how to use C to achieve object-oriented programming [3] The original GDB underlying debugging principle is so simple [4] inline assembly is terrible? Finish this article and end it! [5] It is said that software architecture should be layered and divided into modules. What should be done specifically