Embedded OTA detailed explanation

Overview

For IoT products, the OTA upgrade function is always indispensable, and the user experience of the terminal product can be updated at any time. However, OTA requires extremely high security during the upgrade process to prevent accidental equipment from becoming bricks.

Upgrade method

1. Dual zone backup upgrade-pingpong upgrade

As the name implies, Flash is divided into two areas, A, B, and A as the initial firmware operating area. When the upgrade requirement is detected, the new firmware is written to area B, and the device is restarted after verifying that the new upgraded firmware is completely downloaded and written. After Bootloader startup code reads the area that should be run currently from the upgrade information area, and then jumps to the designated area to run the program.
Advantages: After the upgrade code is downloaded to the device, no processing is required, and the device resource is small.
Disadvantages: flash takes up a lot

2. Compress and upgrade

The compression upgrade also divides the Flash into two areas A and B, but the boot area is one. OTA firmware is an upgraded firmware compressed in a certain way. After the compressed firmware is written to the device, the device restarts and queries the upgrade area information. For compressed upgrades, the device needs to be decompressed first, and then transported to area A after decompression.
Advantages: Flash occupies small.
Disadvantages: The upgrade process is cumbersome, and there may be problems, such as power failure.

3. Differential upgrade

Differential upgrade requires higher requirements for firmware version control. It is better to use if the firmware is not changed much before and after the upgrade. The differential upgrade firmware is a comparison package between the upgraded firmware and the original firmware. After the device receives the firmware, it needs to update the existing firmware through a differential recovery algorithm.
Advantages: upgrade firmware is smaller, download speed is faster, and save storage space.
Disadvantages: It takes a relatively long time to restore the differential firmware to the new firmware and requires relatively large memory.

Detailed explanation of the OTA program of 872 and 808

1. The upgrade method that comes with the SDK

SDK comes with several upgrades:
1. http upgrade
2. SD card upgrade
Call interface:
ota_status_tota_get_image(ota_protocol_tprotocol,void*url);
parameter: protocol: protocol for downloading firmware, currently supports http and file two protocols
url: downloaded Address
Return value: Return to download status

Example:
Insert picture description here

2. Custom upgrade method

The main docking interface:
typedef ota_status_t (*ota_update_init_t)(void *url);
This interface is the initialization interface, if you don’t need to initialize, just return OTA_STATUS_OK.
typedef ota_status_t (*ota_update_get_t)(uint8_t *buf, uint32_t buf_size, uint32_t *recv_size, uint8_t *eof_flag);
Parameters: input parameter buf to upgrade the firmware data
input parameter buf_size The data length required this time, you can set it yourself, the system defaults to 2k
Input parameter recv_szie Actual data length
Input parameter eof_flag Whether the data has been received
After the above interfaces are connected, register in the ota.c file: ota_status_t ota_get_image(ota_protocol_t protocol, void *url) function. And increase the type of ota_protocol enumeration in ota.h

The interface is called in turn: ota_init() -> ota_get_image() ->ota_get_verify_data()->ota_verify_image()-> ota_reboot()

Insert picture description here

Guess you like

Origin blog.csdn.net/tulongyongshi/article/details/108038510