Implementation principle of embedded OTA upgrade

https://blog.csdn.net/bulebin/article/details/108428643

1. Introduction

1.1 Concept

OTA: Over-the-Air Technology, that is, over-the-air download technology.

OTA upgrade: Firmware or software upgrade is achieved through OTA.

As long as the upgrade is achieved through wireless communication, it can be called OTA upgrade, such as network/Bluetooth.

Upgrading through wired methods is called local upgrade, such as upgrading device firmware through UART, USB or SPI communication interface.

Insert image description here

1.2 Advantages

1. Through the OTA method, software upgrades can be performed on devices distributed in various places without having to have operation and maintenance personnel travel around.

2. The IoT platform supports device firmware upgrades through OTA, which is a means for smart devices to repair system vulnerabilities and achieve system upgrades.

3. In the rapidly changing and developing Internet of Things market, new product demands are constantly emerging, so the demand for updates to smart hardware devices is increasing.

At an all-time high, equipment is no longer like traditional equipment once sold and never changed. Provide users with better services through firmware upgrades.

1.3 Implementation principle

Core process:

1. Make an upgrade package

2. Download the upgrade package

3. Verify the upgrade package

4.Update program

Insert image description here

Download method:

Regardless of whether you use OTA or wired communication to upgrade, there are two ways to download the upgrade package: background download and non-background download.

Background download:

During the upgrade, the new firmware is quietly downloaded in the background, that is, the new firmware download is part of the application function. During the new firmware download process, the application can be used normally, which means that the entire download process is indifferent to the user. After the download is completed, the system jumps to the BootLoader program, and the BootLoader completes the operation of overwriting the old firmware with the new firmware. For example, smartphones are upgraded to Android or iOS systems in the background. During the downloading process of the new system, the phone can be used normally.

Insert image description here

Non-background download:

When upgrading, the system needs to jump from the application program to the BootLoader program, and the BootLoader will download the new firmware. After the download is completed, the BootLoader will continue to complete the operation of overwriting the old firmware with the new firmware, and the upgrade is over. The early feature phones used non-background to upgrade the operating system, that is, users need to press and hold some buttons to enter the bootloader mode, and then upgrade, and the normal functions of the phone cannot be used during the entire upgrade process.

Insert image description here

Old and new firmware overlay mode:

There are two ways for new firmware to replace old firmware coverage: dual-zone mode and single-zone mode.

Dual zone mode:

In dual-zone mode, the old firmware and the new firmware each occupy a bank (storage area) in the flash. Assume that the old firmware is placed in bank0 (running area) and the new firmware is placed in bank1 (download area). When upgrading, the application first downloads the new firmware to bank1. Only when the new firmware is downloaded and verified successfully, The system will jump into the BootLoader program, then erase the bank0 area where the old firmware is located, and copy the new firmware of bank1 to bank0.

Background downloads must be upgraded in dual-zone mode.

advantage:

If a problem occurs during the upgrade process or there is a problem with the new firmware, it can also choose the previous old firmware and the old system to continue execution without being affected.

shortcoming:

Occupying one more storage area of ​​flash space is more difficult when system resources are tight.

Insert image description here

Single zone mode:

The non-background download in single-area mode has only one bank0 (running area), and the old firmware and the new firmware share this bank0. When upgrading, after entering the bootloader program, erase the old firmware first, and then directly download the new firmware to the same bank. After the download is complete, verify the validity of the new firmware. The new firmware is effectively upgraded, otherwise it will require a restart.

advantage:

Compared with dual-zone mode, single-zone mode saves a bank of Flash space. When system resources are tight, single-zone mode is a good choice.

shortcoming:

If there is a problem during the upgrade process or the new firmware has a problem, the single-zone mode can only stay in the bootloader, and then wait for another upgrade attempt. At this time, the normal functions of the device can no longer be used. From the perspective of users In other words, it can be said that the device has been "bricked" at this time.

In comparison, although the dual-zone mode sacrifices a lot of storage space, it provides a better upgrade experience.

Insert image description here

2. MCU OTA upgrade

Taking MCU (microcontroller) firmware upgrade as an example, we will explain the OTA upgrade of embedded bare metal programs. Since the bare-metal firmware is solidified in the memory of the device (such as flash), that is, the memory stores the machine code, the OTA firmware upgrade of the MCU is to replace the machine code of the old firmware in the memory with the new firmware through OTA. machine code.

Insert image description here

3. Linux OTA upgrade

The composition of Linux system:

It is mainly composed of three parts, including uboot (boot program), kernel (kernel) and rootfs (root file system).

The partitions of the three in flash are as follows:

Applications are stored in rootfs.

Insert image description here

The startup process of Linux system:

Insert image description here

3.1 System upgrade

The Linux system consists of three parts: uboot\kernel\rootfs. Upgrading the Linux system means updating and replacing the data in these three partitions in flash.

Since uboot\kernel\rootfs is stored as binary data in the flash partition, just like the MCU firmware stores binary data in the flash, the upgrade files including uboot\kernel\rootfs are also directly written to the corresponding file in the form of binary numbers. Flash partition. The upgrade method is basically the same as the MCU firmware upgrade principle.

Generally, you can download the upgrade package in uboot to upgrade uboot\kernel\rootfs, similar to the MCU upgrade in the BootLoader program.

Insert image description here

3.2 Application upgrade

In the Linux system, applications are stored in the file system and exist as executable program files, which are files in the system. This is different from the way MCU firmware is stored in the flash partition.

The application upgrade process is basically the same as MCU firmware and Linux system upgrades. In addition to upgrading executable files, application upgrades can also upgrade configuration files, etc.

Application upgrade process:

Make upgrade package (package signature tool), download upgrade package (download tool), upgrade package signature verification, program update

Differences from MCU OTA upgrade:

Make an upgrade package: Package the application-related files (executable programs, library files, configuration files, etc.) into a compressed package and
then sign it as a whole.

Insert image description here

After the upgrade package is downloaded and passed the signature verification, decompress the compressed package to obtain the relevant files of the application.

Applications can be updated through programs that start the application, such as startup scripts and startup programs, similar to the BootLoader program for MCU upgrades.

Update method:

1. Directly overwrite the old program;

2. Keep the old program and execute the new program;

Directly overwrite the old program:

Insert image description here

Keep the old program and execute the new program:

Such as ping\pong operation

Insert image description here

4. Summary

The core of OTA upgrade:

Insert image description here

Guess you like

Origin blog.csdn.net/qq_41483419/article/details/132365501