How to Perform OTA Upgrade on the OKMX8MP-C Platform Based on Android 11 System

The OTA (Over-The-Air Technology) upgrade system is a technical architecture that enables remote firmware updates for devices via wireless networks. It is mainly composed of a Bootloader program, a firmware transmission module, and a version management module. This system divides the device's storage space into a Bootloader area, an application area, and a download area to achieve the safe replacement of old and new firmware. It supports functions such as resume from breakpoint, encryption verification, and version rollback. Widely used in fields such as smartphones, IoT devices, and automotive electronics, it allows devices to complete function updates and security patch deployments without physical connections. This article describes the specific implementation method of using the OTA upgrade system on the OKMX8MP-Android 11 system.

Build the OTA upgrade package

1. Build a complete update package

Note: The following operations are based on the initial source code, that is, you start using the first version of the OTA function source code.

1.1 Enter the corresponding path of the source code:

forlinx@ubuntu:~$ cd imx8mp/OK8MP-android-source/
forlinx@ubuntu:~/imx8mp/OK8MP-android-source$

1.2 Configure environment

forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ source env.sh
forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ source build/envsetup.sh
forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ lunch evk_8mp-userdebug
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
TARGET_PRODUCT=evk_8mp
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=cortex-a53
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a9
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.4.0-150-generic-x86_64-Ubuntu-18.04.4-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ1A.201205.003
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl external/mesa3d vendor/nxp-opensource/imx/power hardware/google/pixel vendor/partner_gms hardware/google/camera vendor/nxp-opensource/imx/camera
============================================

1.3 Start compilation:

forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ ./imx-make.sh kernel -j4
make: Entering directory '/home/forlinx/imx8mp/R3_6.28/OK8MP-android-source'
/home/forlinx/imx8mp/R3_6.28/OK8MP-android-source/device/nxp/common/build/uboot.mk:74: *** shell env AARCH64_GCC_CROSS_COMPILE is not set.  Stop.
make: Leaving directory '/home/forlinx/imx8mp/R3_6.28/OK8MP-android-source'
forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ make otapackage -j4
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
TARGET_PRODUCT=evk_8mp
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=cortex-a53
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a9
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.4.0-150-generic-x86_64-Ubuntu-18.04.4-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ1A.201205.003
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl external/mesa3d vendor/nxp-opensource/imx/power hardware/google/pixel vendor/partner_gms hardware/google/camera vendor/nxp-opensource/imx/camera
============================================
[……]
#### build completed successfully (13:07 (mm:ss)) ####

After compilation, the "evk _ 8mp-ota-" eng. Forlinx. zip "will be generated in the" out/target/product/evk _ 8mp/ "path, which is the compressed package required for OTA full upgrade.

forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ cd out/target/product/evk_8mp/
forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp$ ls evk*
evk_8mp-ota-eng.forlinx.zip

It also generates "evk _ 8mp-target _ files-eng. forlinx. zip" "under the path" out/target/product/evk _ 8mp/obj/PACKAGING/target _ files _ intermediates/ ". This is the first compressed package used to generate the incremental upgrade package during OTA incremental upgrade.

forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ cd out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates/
forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates$ ls
evk_8mp-target_files-eng.forlinx    evk_8mp-target_files-eng.forlinx.zip
evk_8mp-target_files-eng.forlinx.zip

1.4 Backup the "evk _ 8mp-ota" eng. forlinx. zip "and rename it to" full-ota _ v1.0.zip ":

forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp$ cp evk_8mp-ota-eng.forlinx.zip full-ota_v1.0.zip
forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp$ ls full*
full-ota_v1.0.zip

Backup “evk_8mp-target_files-eng.forlinx.zip”,rename it as “target_files_v1.0.zip”:

forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates$ cp evk_8mp-target_files-eng.forlinx.zip target_files_v1.0.zip
forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates$ ls
evk_8mp-target_files-eng.forlinx           evk_8mp-target_files-eng.forlinx.zip  
evk_8mp-target_files-eng.forlinx.zip.list     target_files_v1.0.zip

2. Build the object file

Note: Modify the source code according to actual requirements. After modification, execute the following operations to generate a new "evk _ 8mp-target _ files-eng. forlinx. zip" "and rename it to" target _ files _ v2.0.zip ".

2.1 Execute environment variables, same as step 2 in 2.1.

2.2 Start compilation:

forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ ./imx-make.sh kernel -j4
make: Entering directory '/home/forlinx/imx8mp/OK8MP-android-source'
Merging KERNEL config srcs: /home/forlinx/imx8mp/OK8MP-android-source/vendor/nxp-opensource/kernel_imx/arch/arm64/configs/gki_defconfig /home/forlinx/imx8mp/OK8MP-android-source/device/nxp/imx8m/evk_8mp/android_addition_defconfig /home/forlinx/imx8mp/OK8MP-android-source/vendor/nxp-opensource/kernel_imx/arch/arm64/configs/imx8mp_gki.fragment
[……]
forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ make target-files-package -j4
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
TARGET_PRODUCT=evk_8mp
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=cortex-a53
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a9
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.4.0-150-generic-x86_64-Ubuntu-18.04.4-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ1A.201205.003
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish device/generic/goldfish-opengl external/mesa3d vendor/nxp-opensource/imx/power hardware/google/pixel vendor/partner_gms hardware/google/camera vendor/nxp-opensource/imx/camera
============================================
[……]
#### build completed successfully (13:07 (mm:ss)) ####

After compilation, a new "evk _ 8mp-target _ files-eng. forlinx. zi" is generated under the path "out/target/product/evk _ 8mp/obj/PACKAGING/target _ files _ intermediates/". At this time, this is the second compressed package used to generate the incremental upgrade package during the OTA incremental upgrade.

forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ cd out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates/
forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates$ ls
evk_8mp-target_files-eng.forlinx           evk_8mp-target_files-eng.forlinx.zip
evk_8mp-target_files-eng.forlinx.zip.list     target_files_v1.0.zip

2.3 Backup new “evk_8mp-target_files-eng.forlinx.zip”,rename it as “target_files_v2.0.zip”:

forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates$ cp evk_8mp-target_files-eng.forlinx.zip target_files_v2.0.zip
forlinx@ubuntu:~/imx8mp/OK8MP-android-source/out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates$ ls
evk_8mp-target_files-eng.forlinx           evk_8mp-target_files-eng.forlinx.zip  
evk_8mp-target_files-eng.forlinx.zip.list     target_files_v1.0.zip
target_files_v2.0.zip

Full Package OTA Upgrade Process

1. Upgrade using the full package

Note: Here, the method of updating the system from the development board's storage (i.e., copying the update package via a USB flash drive) is adopted.

After the image is flashed into the development board, a full package upgrade needs to be completed first using the full-ota_v*.zip that is consistent with or has very little difference from the flashed image. Only then can the incremental package upgrade be used normally later.

1.1 Copy the compiled “full-ota_v1.0.zip” to a USB flash drive and unzip it to obtain payload.bin and payload_properties.txt.

1.2 Insert the USB flash drive into the development board. The path of the USB flash drive is a directory under /mnt/media_rw/, and the name is random. It shall be based on the actual situation. Here, it is: CA35-A916.

1.3 Copy payload.bin and payload_properties.txt to the /data/ota_package directory of the development board.

evk_8mp:/ $ su
evk_8mp:/ # cd /data/ota_package/
evk_8mp:/data/ota_package # cp /mnt/media_rw/CA35-A916/full-ota_v1.0/payload* ./
evk_8mp:/data/ota_package # ls
payload.bin  payload_properties.txt

1.4 View the contents of payload _ properties.txt as follows:

evk_8mp:/data/ota_package # cat payload_properties.txt
FILE_HASH=isiQeegRKyOdi9/aazwQjrZWRAIbB1Nyj1WdZ22L3Pk=
FILE_SIZE=555766395
METADATA_HASH=p0+xQATUAG7dZg/kuPaQACDdClkEOZDHoOhxx0lBEuA=
METADATA_SIZE=56853

Note: The contents in different payload_properties.txt files are not the same. Use the values obtained from actual queries as the basis.

Enter the following commands in the debugging serial port to perform the update:

evk_8mp:/ # update_engine_client --payload=file:///data/ota_package/payload.bin --update --headers="FILE_HASH=isiQeegRKyOdi9/aazwQjrZWRAIbB1Nyj1WdZ22L3Pk=
FILE_SIZE=555766395
METADATA_HASH=p0+xQATUAG7dZg/kuPaQACDdClkEOZDHoOhxx0lBEuA=
METADATA_SIZE=56853"

Description:

  • –payload: Specify the upgrade file. /data/ota_package/payload.bin is the path of the file.
  • –payload: Specify the upgrade file. /data/ota_package/payload.bin is the path of the file.

Note: When entering the command, several values such as FILE_HASH within the double-quotes need to be on separate lines. The system will automatically execute the command after seeing the backtick, and do not add spaces after each value, otherwise these values will be parsed incorrectly.

After the input is completed, update_engine_client will automatically perform the upgrade in the background. You can use the following command to view the progress.

evk_8mp:/ # logcat -s update_engine
[……]
08-08 16:38:33.926   569   569 I update_engine: [INFO:update_attempter_android.cc(535)] Update successfully applied, waiting to reboot.
[……]

Seeing the above information means that the upgrade is completed. Restart the development board to switch to the new system.

2. Error reporting and solutions

[0816/113702.725994:ERROR:update_engine_client_android.cc(164)] Found a positional argument 'headers=FILE_HASH=bSh+uImvMQzeETnx4ErOFLHRdFiW93VWFRJVgzhdP78=
FILE_SIZE=555773473
METADATA_HASH=5DfmnPUmTfPV0TsAiMvBiwvjorZjHzyiAxjRemDmHFE=
METADATA_SIZE=56853'. If you want to pass a value to a flag, pass it as --flag=value.

Solution: If you directly apply the full upgrade package to any version of the image, the above error will be reported. You can try to flash the version of the image used to generate full-ota_v1.0.zip into the development board before applying the full upgrade package.

Incremental Package OTA Upgrade Process

Note: Before using incremental upgrade, please ensure that you have successfully completed a full package upgrade.

1. Explanation of incremental upgrade.

Incremental upgrade is performed between two target files, and only the different parts between the two targets are replaced. The target files generated each time from the same code are different. For example, the current code is submitted to A, and A1, A2, and A3 are generated by using the target files creation command for many times, and then the code is modified. At this time, the code is B, and B1 is generated by using the target files creation command. If the program in the board is the same as the target files A1, the incremental package generated from A1 and B1 can be used to upgrade the board successfully. However, the incremental packages generated from A2, A3 and B1 cannot be used for a successful upgrade because the hash value verification of the partitions fails.

When creating an upgrade package according to the method of making an incremental package and then performing an upgrade, the upgrade often fails, mostly due to the above-mentioned reason. The upgrade can only be successful if the program in the system is the same as the old target files used to generate the upgrade package. The system is flashed through an image and the hash values of each partition are definitely different from those of the target file generated.

Therefore, if you want to use incremental upgrade, the first upgrade must be a full-package upgrade. Moreover, the target file corresponding to this full-package should be retained as the basis for the next incremental upgrade. The target file after each subsequent upgrade also needs to be retained as the basis for the next upgrade. If the hash values in the system do not match those required by the incremental package, a full-package upgrade is needed to establish the corresponding relationship.

Therefore, our incremental upgrade tests are all carried out after a full upgrade has been completed.

2. Compile the incremental upgrade package

Description:

The incremental update package only contains the encoded differences between two files. The incremental update package can only be installed on devices that use the old version or source version when building the package. Before building the incremental update package, you need to build two target files:

The old package that has been applied to the device, such as the previously saved target_files_v1.0.zip;

The old package that has been applied to the device, such as the previously saved target_files_v1.0.zip;

In the Android environment, use the following command to generate the incremental upgrade package:

forlinx@ubuntu:~/imx8mp/R3_6.28/OK8MP-android-source$ cp out/target/product/evk_8mp/obj/PACKAGING/target_files_intermediates/target_files_v* ./
forlinx@ubuntu:~/imx8mp/OK8MP-android-source$ out/host/linux-x86/bin/ota_from_target_files -i target_files_v1.0.zip target_files_v2.0.zip incremental-ota.zip

Note: You need to copy target_files_v1.0.zip and target_files_v2.0.zip to the OK8MP-android-source directory first. Otherwise, an error will occur when executing the command to generate the incremental package.

incremental-ota.zip is the incremental package used for incremental upgrades.

3. Incremental upgrade process

The operation steps for incremental upgrades are the same as those for full package upgrades. You can follow the steps in 2.3.1.

Note: The compressed package used for full package upgrades is: full-ota_v1.0.zip;

The compressed package used for incremental upgrades is: incremental-ota.zip.

4. Error reporting and solutions

If you find that the upgrade using the incremental package is not successful, check if the print information of logcat -s update_engine during the upgrade contains “Update successfully applied, waiting to reboot”. If not, check if the print information contains the information shown in the following figure:

How to Perform OTA Upgrade on the OKMX8MP Platform Based on Android 11 System

Cause of the problem:

If there is such information, it means that the differential upgrade has failed. The reason for the failure is that the old version does not match the new version, that is, the hash values do not correspond as mentioned in Section 1.4.1.

Solution:

Check whether the full package upgrade has been completed and the system has been restarted before performing the incremental upgrade. If not, first use full-ota_v1.0.zip to complete the full package upgrade.

Check the process of generating the incremental package and confirm that the target_files_v1.0.zip used when generating incremental-ota.zip was created using the make otapackage -j4 command and was generated together with full-ota_v1.0.zip.

If the upgrade still fails, follow the steps in 1.1 again, regenerate full-ota_v2.0.zip using the modified source code, and perform the full package upgrade.




Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!