Depending on different flash layout , there are two OTA schemes: supporting Bank switching and non-supporting Bank switching.
Whether or not Bank switching is supported, the boot patch image is always independently dual-banked, serving the same function and acting as a backup
for each other.
For example, if the current boot patch is running in bank0, the OTA can only upgrade the boot patch in bank1.
After the upgrade is complete, the system will restart and choose the bank with the higher version number to run. If the version numbers are the same,
it will run in bank0.
In the non-supporting Bank switching OTA scheme, the OTA TMP area is used as an OTA backup area to store backup firmware. The BootLoader will eventually copy and activate the backup firmware.
On the other hand, in the supporting Bank switching OTA scheme, OTA Bank0 and OTA Bank1 are used as mutually backup firmware storage areas. During the firmware update process, these two storage areas can be alternately used, ensuring that in the event of a firmware update failure, the system can revert to the previous backup firmware, thereby maintaining system stability and security.
The flash layout of the non-supporting Bank switching scheme and the supporting Bank switching scheme have the following differences.
The capacity of the OTA Bank1 area is not allocated.
The OTA TMP area needs to be allocated, and its size should not be less than the largest image size in OTA Bank0. Therefore, the non-supporting bank switching scheme relatively saves flash space. After the OTA transmission is completed, the boot program will copy the data in the OTA TMP area to the specified image area in OTA Bank0, and then restart to take effect, which relatively increases the restart time after the OTA upgrade is completed.
The non-supporting Bank switching scheme also supports combined image upgrades, which is enabled by default. When using a combined image upgrade, when writing the image data to the OTA TMP area, it will calculate whether the remaining space in the OTA TMP area can accommodate the next image file that needs to be written. If it can, it will continue to write the next image file to the OTA TMP area. When it can’t, it will copy the data in the OTA TMP area to the OTA Bank0 area. The advantage of combined upgrading is to reduce the number of restarts and speed up the transmission rate.
Advantages: The total size of the bank is fixed. There is a backup bank. It is possible to dynamically adjust the size of each image in the bank.
Disadvantages: The utilization rate of flash space is low.
Maintenance: It is necessary to maintain images for two bank corresponding addresses. The image released by Realtek by default only supports running on bank0. If it is necessary to run on bank1, contact Realtek to obtain it.
Advantages: The utilization rate of flash space is higher.
Disadvantages: Each image cannot be upgraded at the same time, and there are situations where old and new combinations coexist. After OTA is completed, activating the image will increase the boot time for that time.
Generate flash_map.h, flashmap.ini and OTAHeaderfile. Please refer to Flash Map Generate Tool.
Note
flash_map.h needs to be placed in the upper-level directory of the project to participate in the compilation and generate the APP image.
flashmap.ini is the input file of MPPackTool and MP Tool, and it is necessary to ensure that the image is consistent with all the output addresses set.
The APP Data file is generated through the SDK generation script. For details, please refer to the APP Data Tool Quick Start Guide:rtl87x2g_sdk_xxxx\tools\AppData.
Use Flash Map Generate Tool to flashmap.ini, flash_map.h, Bank0OTAHeaderfile and Bank1OTAHeaderfile.
Select Flash Size.
Select Enable bank switch.
Set up two-level flash layout.
Click Confirm to complete the flash layout settings.
Modify OTA Header file version.
Click Confirm to generate flash_map.h, flashmap.ini, Bank0OTAHeaderfile and Bank1OTAHeaderfile.
Flash layout config and generate ota header image
Note
The version number of the OTA Header used for packaging is higher than the version number of the original running version, so that the new bank can take effect normally after the OTA upgrade.
Copy flash_map.h to the upper-level directory with project.
Link and compile the project to generate app_MP_sdk#####+version+MD5.bin file for packaging.
Supporting Bank switching scheme needs to compile the app images of OTA BANK0 and OTA BANK1. The demo app project in the Realtek released SDK can only compile the app image of OTA BANK0 by default. Compiling app image of OTA BANK1 needs modifying the macro ‘APP_BANK’ in mem_config.h in the upper-level directory as the project file to 1.
/** @brief set app bank to support OTA: 1 is ota bank1, 0 is ota bank0 */#define APP_BANK 1
Get the System Patch, BT Stack Patch, and BT Host image that runs in OTA Bank1.
Note
The default released System Patch, BT Stack Patch, and BT host image can only run in OTA Bank0. Please consult Realtek to get the system patch, stack patch, and BT Host image that runs in OTA Bank1 when choosing the supporting Bank switching scheme.
Generate a packet file of ImgPacketFile-xxxxxx.bin in the current directory, which is used for updating.
Select the ForOTA option.
Load the generated flashmap.ini.
Load all OTA Bank0 and Bank1 images according to the set flash map.
Click Confirm to generate the package file.
Use the MP Pack Tool to package files – supporting Bank switching
Note
Both the Bank0 OTA Header file and the Bank1 OTA Header file need to be packaged, different from the non-supporting Bank switching scheme.
All the contents defined in the flash layout need to be packaged.
It is recommended to package both Bank0 and Bank1.
Use Flash Map Generate Tool to flashmap.ini, flash_map.h and Bank0OTAHeaderfile.
Select Flash Size.
Select Disable bank switch.
Set up two-level flash layout.
Click Confirm to complete the flash layout settings.
Modify OTA Header file version.
Click Confirm to generate flash_map.h, flashmap.ini and Bank0OTAHeaderfile.
Configure Flash Layout and generate Bank0 OTA Header file
Note
The flashmap.ini generated here needs to be consistent with the flashmap.ini used in the MP stage.
Copy flash_map.h to the project directory. Link and compile the project to generate app_MP_sdk#####+version+MD5.bin file for packaging. To apply the non-support Bank switching scheme, mem_config.h in the project directory should be modified.
/* @brief set app bank to support OTA: 1 is ota bank1, 0 is ota bank0 */#define APP_BANK 0
Open MP Pack Tool to load flash_map.ini generated in the previous step and load the corresponding image.
Select ForOTA option.
Load the generated flashmap.ini.
Load all OTA Bank0 images according to the set flash map.
Click Confirm to generate the package file.
Use the MP Pack Tool to package files – non-supporting Bank switching
Note
Bank0 OTA Header file can’t be packaged, which is different from the supporting Bank switching scheme.
If only Patch Image or APP Image, either of them can be packaged.
OTA is divided into silent OTA and normal OTA depending on the transmission protocol.
Silent OTA
During the image upgrade process, the original functions of the device can be used normally. After the upgrade is completed, it only takes a short restart time for the program to automatically switch to the new functions.
Normal OTA
The function is stable. However, the upgrade process requires switching the device to DFU mode, and the original functions cannot be used until the upgrade is completed.
Both types of upgrades will use the OTA Service and DFU Service.
The OTA Service is used to obtain device information or enter DFU mode, while the DFU Service is used to execute the upgrade process.
After receiving the control header of the image, it needs to be decrypted and then parsed. not_ready will be temporarily written to 1 and then written to flash.
During data transmission, if AES encryption is supported, every 16 bytes are encrypted. After the receiving end receives the data, it needs to be decrypted first. The last part, less than 16 bytes, is sent without encryption. When the buffer check size is full, write to flash.
supporting combined image upgrades: while writing the image data to the OTA TMP area, the remaining space in the OTA TMP area will be calculated to determine if it can accommodate the next image file to be written. If it can, the process continues by writing the next image file to the OTA TMP area. If it cannot, the data in the OTA TMP area is moved to the OTA Bank0 region, and after a restart, the copy and activation take effect. Subsequently, the next file can be upgraded.
non-supporting combined image upgrades: when the packaged file to be upgraded contains Patch, APP or APP DATA, one file upgrade needs to be successfully verified. After the copy is restarted and activated to take effect, the next file can be upgraded.
supporting Bank switching
When the packaged files to be upgraded contains OTA Header file, Patch, APP, or APP DATA, each file must be individually transmitted and validated as successfully received before transmitting and validating the next file. All files must be successfully transmitted and validated before a reboot can occur; otherwise, the current upgrade attempt will be invalid. This is because, in the bank switching scheme, all files in the Bank area need to become effective together for the system to run properly.