The Allwinner MR536 Tina 5.0 OpenWRT OTA upgrade can be achieved through two methods: AB backup and Recovery system. The AB backup method involves burning two copies of uboot, kernel, and rootfs into Flash, and then using uboot environment variables to decide which set to switch between. This method consumes too much Flash space and has been commonly used in previous embedded devices. However, with the advent of Android systems, many have adopted the Recovery upgrade method. Below is a detailed explanation of the entire SDK configuration, OTA packaging, and verification process using the open-source SWUpdate project.
The commands executed in the following steps are performed after running the command below:
source build/envsetup.sh
lunch mr536-evb1-tina
1. System Configuration Commands
1) Configure OpenWRT
Main system (configuration file: openwrt/target/mr536/mr536-evb1/defconfig):
make menuconfig
Recovery system (configuration file: openwrt/target/mr536/mr536-evb1/defconfig_ota):
make ota_menuconfig
2) Configure Kernel
Main system (configuration file: device/config/chips/mr536/configs/evb1/linux-5.15-origin/bsp_defconfig):
./build.sh menuconfig
Recovery system (configuration file: device/config/chips/mr536/configs/evb1/linux-5.15-origin/bsp_recovery_defconfig):
./build.sh recovery_menuconfig
2. Configure Main System and Recovery System
Both will use the SWUpdate open-source suite, which requires the following configuration items to be included in the OpenWRT configuration:
CONFIG_PACKAGE_swupdate=y
3. Configure Recovery System Separately
OpenWRT configuration:
CONFIG_SUNXI_MAKE_REDUNDANT_ENV=y
CONFIG_SUNXI_REDUNDANT_ENV_SIZE="0x20000"
CONFIG_SUNXI_NO_ROOTFS_IMG=y
Kernel configuration:
CONFIG_BLK_DEV_INITRD=y
CONFIG_RD_GZIP=y
4. Configure env (SDK source code is pre-configured)
The entire SWUpdate suite OTA upgrade process relies on U-boot environment variables, with the corresponding configuration file being:
device/config/chips/mr536/configs/evb1/linux-5.15-origin/env-5.15.cfg
1) OpenWRT Configuration Items for Main System and Recovery System
In both the main system and Recovery system, the fw_printenv and fw_setenv tools are used to get and set the corresponding environment variable values, so the following items must be configured:
CONFIG_PACKAGE_uboot-envtools=y
2) boot_partition Variable
In the device/config/chips/mr536/configs/default/env.cfg configuration file, the following has been modified:
boot_normal=sunxi_flash read 0x4007f800 boot;bootm 0x4007f800 ${sunxi_ramd_addr} ${sunxi_fdt_addr}
Changed to:
boot_partition=boot
boot_normal=sunxi_flash read 0x4007f800 ${boot_partition};bootm 0x4007f800 ${sunxi_ramd_addr} ${sunxi_fdt_addr}
The above is for the main system; if it is Recovery, it should be changed to boot_partition=recovery to indicate loading the Recovery system mode from the recovery partition.
3) root_partition Variable
Ensure the following item exists in the above env.cfg configuration file:
root_partition=rootfs
For the recovery scheme, this variable does not need to be modified.
5. Configure Backup env (to prevent damage from power outages) (SDK source code is pre-configured)
1) Add env-redund Partition
Copy the env partition to create env-redund, with the downloadfile still being env.fex. The relevant configuration is already present in the device/config/chips/mr536/configs/evb1/linux-5.15-origin/sys_partition.fex file;
In the device/config/chips/mr536/configs/evb1/BoardConfig.mk file, ensure the following configuration item exists:
LICHEE_REDUNDANT_ENV_SIZE:=0x20000
2) Uboot Configuration
Ensure the following item exists in the brandy/brandy-2.0/u-boot-2023/u-boot.cfg configuration file:
#define CONFIG_SUNXI_REDUNDAND_ENVIRONMENT 1
Also, modify the brandy/brandy-2.0/u-boot-efex/configs/sun55iw6p1_mr536_efex_defconfig file to add the following configuration item:
CONFIG_SUNXI_REDUNDAND_ENVIRONMENT=y
3) fw_env.config Configuration
Ensure the following files:
openwrt/target/mr536/mr536-evb1/base-files/etc/fw_env.config
openwrt/target/mr536/mr536-evb1/busybox-init-base-files/etc/fw_env.config
Contain the following configuration items:
/dev/by-name/env 0x0000 0x20000
/dev/by-name/env-redund 0x0000 0x20000
This way, the user space can correctly handle the data of these two env areas using fw_printenv and fw_setenv.
6. Configure Startup Script
Ensure the openwrt/target/mr536/mr536-evb1/busybox-init-base-files/etc/init.d/load_script.conf file contains statements like S99swupdate_autorun.
7. Add Recovery Partition Configuration
Ensure the device/config/chips/mr536/configs/evb1/linux-5.15-origin/sys_partition.fex file contains the following content:
[partition] name = recovery size = 65536 downloadfile = "recovery.fex" user_type = 0x8000
8. Overview of OTA Package
The OTA package must include the sw-description file and the upgraded IMG files, and the entire OTA package is in CPIO format, requiring the sw-description file to be the first (as reflected in the OTA package configuration file).
The OTA strategy description file (build/swupdate/sw-description) will be packaged as the first file in the OTA upgrade package (*.swu), serving as the process configuration file and upgrade file configuration instructions for the entire OTA upgrade process; while the OTA package configuration file (build/swupdate/sw-subimgs.cfg) will determine which files will be used in the packaging.
9. Compilation of Recovery Image and OTA Upgrade Package
Below is the entire process of compiling and packaging the SDK source code, Recovery image, and OTA upgrade package:
1) Compile kernel and rootfs
make -j8
2) Compile Recovery
swupdate_make_recovery_img -j8
3) Compile Uboot
muboot
4) Package
pack
5) Generate OTA Package
swupdate_pack_swu
10. Verification
Push the generated OTA package (out/mr536/evb1/openwrt/swupdate/openwrt_mr536_evb1.swu) to the board’s /mnt/UDISK directory (the board must have a flashed image with the Recovery partition), then execute the following commands:
swupdate -i /mnt/UDISK/openwrt_mr536_evb1.swu -e stable,upgrade_recovery
fw_setenv swu_software stable
fw_setenv swu_param " -i /mnt/UDISK/openwrt_mr536_evb1.swu"
reboot -f
or
swupdate_cmd.sh -i /mnt/UDISK/openwrt_mr536_evb1.swu -e stable,upgrade_recovery
Both methods will allow the main system to upgrade the Recovery partition, and upon reboot, upgrade the Kernel and Rootfs partitions (depending on the strategy file sw-description). If we modify the contents of the rootfs partition in the command line and find that it has not been updated after the upgrade, this is mainly due to the Allwinner MR536 using the overlayfs mechanism to handle the read-only nature of its squashfs file system format. Below is the explanation from the original factory documentation:
Tina uses overlayfs by default, so user modifications to the original rootfs will be recorded in the rootfs_data partition. The OTA updates the rootfs partition, which by default does not modify the rootfs partition. Therefore, user operations such as adding, deleting, or modifying files in the rootfs will be retained. If the original rootfs contains file A, and the user modifies it to A1, while the OTA update changes that file to B, the final visible file will still be A1. This is determined by the characteristics of overlayfs, where files in the upper directory will mask those in the lower directory. If you want the OTA updated files to take precedence after the OTA, you can reformat the rootfs_data partition after the OTA.
Tina_Linux_OTA_Development_Guide.pdf
Allwinner also supports configuring the parts_clean environment variable to format specified partitions at boot. For example, to format the rootfs_data partition (/dev/by-name/rootfs_data), you can execute the following command:
fw_setenv parts_clean rootfs_data reboot
At boot time, the script lib/preinit/79_format_partition in the root file system will obtain the value of the parts_clean variable to determine which partition to clear.
Based on the above description, we can add or integrate the following configuration items in the sw-description file:
bootenv: ( { name = "parts_clean"; value = "rootfs_data"; });
Thus, we have perfectly resolved the issue of debugging affecting rootfs upgrades.
11. Postscript
When packaging the OTA package (*.swu), the following prompt may appear:
###storage type error######cannot choose boot0, please config storage_type in sys_config ###
After adding the storage_type = 2 configuration item in the [target] section of the device/config/chips/mr536/configs/evb1/sys_config.fex file, repackaging will resolve this issue. It can be seen from the build/buildbase.sh file that it will copy boot0_sdcard.fex to boot0.img file. (Currently, the MR536 OpenWRT SDK does not have this configuration item, so do not add it casually; it can be masked in the upgrade strategy file.)
The above is the entire process of configuration, compilation, and verification for OTA, relying on the SWUpdate open-source project to achieve.