Events
Trade Shows
Seminars
Product Updates
 
          Home > News Center > Product Updates
 

Application Notes | Setting up OTA Functionality on MYIR's NXP i.MX 93 Development Board

 
2024-6-16   17:37:32     Click: 718
 

1. Overview

Over-the-Air Technology (OTA) is a technology that enables remote management of mobile terminal equipment and SIM card data via the air interface of mobile communication. In this article, OTA upgrades are performed utilizing the swupdate method. Swupdate is an upgrade service framework program tailored for the embedded Linux platform, offering functionalities like partition upgrades, file upgrades, and differential upgrades (patch application). Additionally, it provides open interfaces for users to add custom upgrade processing functions. This application note mainly focuses on how to use the OTA function embedded within the MYIR system, which is based on the NXP i.MX 93 SOM, to accomplish remote upgrades of the file system residing on the MYIR NXP i.MX 93 SOM.


2. Development environment preparation

2.1. Software resource

  • OTA Upgrade File Creation Tool: ota-generate_swu.tar.gz (Path: 03_Tools/ ota-tools)
  • MYC-LMX9X-Core file system: myir-image-core-myd-lmx9x.ext4
    (Path: 02_Images/ or compiled by Yocto, please refer to the Software Development Guide for compilation info)
  • For the Ubuntu operating system host environment, the virtual machine or the installed Ubuntu PC host can be used with no specific version requirements.

2.2. Hardware resource

  • MYIR's NXP i.MX 93 based development board MYD-LMX9X (Or MYC-LMX9X SOM+customized base board that at least with one Ethernet port or WiFi chip)
  • Network cable or WiFi antenna
  • Development board power supply, serial cable and other necessary accessories to ensure that the development board can starts up and operates properly.

2.3. Host environment configuration

To perform OTA upgrade, you must build an Http server in the Ubuntu host environment. The following will take the Http server construction process of Ubuntu18.04 as an example, and the username will be myir. For subsequent OTA upgrades, the Http server will be directly configured to be directly usable in the future. This process is for reference only. If any errors that are not described in the following instructions occur during the construction process using other versions of Ubuntu systems, please search the Internet for solutions.

  • Install apache2
    sudo apt install -y apache2

  • Configuration environment
    The default port number is 80. To prevent conflicts caused by other uses, change it to a custom port: 8001, modify the listening port in the /etc/apache2/ports.conf file:
    $: vi  /etc/apache2/ports.conf
    Listen 8001 ## Other rows remain unchanged

  • Modify /etc/apache2/sites-enabled/000-default.conf file port and access directory for easy subsequent use

    $: vi /etc/apache2/sites-enabled/000-default.conf

    8001> ## Other rows remain unchanged
    #DocumentRoot /var/www/html ## Access the directory using the default browser and comment it out.
    DocumentRoot /home/myir/swupdate ## Change to this directory, and please modify the username accordingly.


  • Modify the apache2 configuration file /etc/apache2/apache2.conf
    $: vi /etc/apache2/apache2.conf
    ## Find the following line and modify it to the following
    #
    Configuration file default directory, comment out

    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted


  • Service network restart
    $: sudo /etc/init.d/apache2 restart

  • Test

If it is a virtual machine, please the Ubuntu network configuration to bridge the network adapter so that the virtual machine and the Windows host are under the same IP. In other environment, you can directly open the browser and enter http://{hostIP}:8001 in the browser. Here, hostIP for HTTP server is configured with the IP address of the Ubuntu. For example, if the IP address of Ubuntu is 192.168.1.20, enter: http://192.168.1.20:8001 in the browser. If successful, it will be as shown in the figure below:

Figure 2-1. Http is successfully built

3. Upgrade principle

OTA can be simply understood as online firmware upgrading, which involves downloading the firmware from the server and writing it to the corresponding partition. However, during this process, there may be issues such as power loss during the burning process or other reasons that cause damage to the partition. Therefore, the MYD-LMX9X development board chooses to use the AB symmetrical partitioning method to preserve the file system.

3.1. AB Partition Introduction

For the AB symmetric file system of MYD-LMX9X, the following logical processing is first performed:

First, three variables boot_limit, mmcbootpart, and mmcbootpart_back are added to the env variable of Uboot, and certain logical judgments are added to them, which can be seen through the uboot command line:

u-boot=> printenv boot_limit

boot_limit=3

u-boot=> printenv mmcbootpart

mmcbootpart=2

u-boot=> printenv mmcbootpart_back

mmcbootpart_back=3

bsp_bootcmd=echo Running BSP bootcmd ...; mmc dev ${mmcdev}; if mmc rescan; then if run loadbootscript; then run bootscript; else if test ${sec_boot} = yes; then if run loadcntr; then run mmcboot; else run netboot; fi; else if run loadimage; then if test ${boot_limit} -gt 0 ;then setexpr boot_limit ${boot_limit} - 1 ;setenv boot_limit ${boot_limit} ;saveenv ;setenv mmcroot /dev/mmcblk${mmcdev}p${mmcbootpart} rootwait rw;else setenv mmcroot /dev/mmcblk${mmcdev}p${mmcbootpart_back} rootwait rw;fi;run mmcboot; else run netboot; fi; fi; fi; fi;

The value of boot_limit will be reduced by one every time the development board is powered on and enters uboot, which can be viewed from the highlighted area above. However, it will be set to 3 when the file system is successfully started. However, boot_limit cannot be set to 3 if there is a file system corruption problem that prevents booting. When the file system fails to start, the watchdog restarts automatically and the default watchdog time is 60s. The same applies to manually restarting the system after a startup failure is found. After restarting, enter uboot again. In this case, because boot_limit is not set to 3, the boot_limit value is 2, and the value will be reduced by one again.

The mmcbootpart variable is the number of the currently booted partition, for example, if the median value above is 2, it will later boot from mmcblk0p2. mmcbootpart_back indicates the number of the partition where the backup is started. For example, the median value is 3. If file system mmcblk0p2 fails to be started or is started incorrectly, the mmcblk0p3 backup partition will be started when the boot_limit value is 0 after multiple restarts.

The specific operation logic flow chart is as follows:

Figure 3-1. AB partition flowchart


You can run the following command on the file system to view the partitions in eMMC:

root@myd-lmx9x:~# cat /proc/partitions

major minor #blocks name

179 0 7634944 mmcblk0

179 1 102400 mmcblk0p1

#Image+dtb Kernel and device tree files are stored in partitions

179 2 3686400 mmcblk0p2 #A File system partition

179 3 3686400 mmcblk0p3 #B File system partition

179 32 32640 mmcblk0boot0

179       64      32640 mmcblk0boot1


3.2. Swupdate Introduction

This section describes how to perform swupdate after logging in to the file system. The SWupdate is automatically initiated by the systemd service. You only need to modify the configuration of the corresponding IP address path.


This section describes the swu file required for swupdate upgrade. The file is produced by script production. The compressed package of the production tool is stored in 03_Tools and is named ota-generate_swu.tar.gz. Here we first introduce the swu configuration file sw-description, which is as follows:


software =

{

version = "1.1";

description = "Firmware update for myd-lmx9x"

myd-lmx9x = {

hardware-compatibility: [ "1.0", "1.1" ];

stable:

{

main:

{

images:(

{

filename = "myir-image-core-myd-lmx9x.ext4";

device = "/dev/mmcblk0p3";

filesystem = "ext4" ;

}

);

bootenv:(

{

name="mmcbootpart";

value="3";

},

{

name="mmcbootpart_back";

value="2";

}

);

scripts: (

{

filename = "update.sh";

type = "shellscript";

}

);

};


This includes version, device name myd-lmx9x, hardware version hardware-compatibility, stable and the main branch in it, as well as the images, bootenv, scripts parameters.


The self-starting service has been installed in the system and will be automatically executed after the system is powered on. Enter the following command to view the service content:

[Unit]

Description=SWUpdate daemon

After=swupdate.service


[Service]

ExecStart=/etc/myir-swupdate.sh

KillMode=mixed


[Install]

WantedBy=multi-user.target


The service will automatically execute the /etc/myir-swupdate.sh script. View the content of the script:

#!/bin/sh

. /etc/board_part_info.conf

echo EMMC_DEV ${EMMC_DEV}

echo SD_DEV ${SD_DEV}

echo ROOTFS_A_PART=${ROOTFS_A_PART}

echo ROOTFS_B_PART=${ROOTFS_B_PART}

current_rootfs=""

check_root_part_cmdline()

{

cmdline=`cat /proc/cmdline`

for i in $cmdline

do

if [[ `echo $i | grep "root="` != "" ]];then

current_rootfs=${i##*/}

fi

done

}

check_need_repalce_env()

{

echo ${current_rootfs}

result=$(echo ${current_rootfs} | grep "mmcblk")

if [[ ${result} != "" ]];then

bootdev=${current_rootfs%p*}

#echo bootdev ${bootdev}

if [[ `grep ${bootdev} /etc/fw_env.config` == "" ]];then

sed -i "s/mmcblk[0-9]*/${bootdev}/g" /etc/fw_env.config

fi

fi

}

function_on_different_part()

{

case ${current_rootfs:0-1} in

${ROOTFS_A_PART})

echo "rootfs A part"

fw_setenv swu_mode 0

fw_setenv boot_limit 3

fw_setenv mmcbootpart ${ROOTFS_A_PART}

fw_setenv mmcbootpart_back ${ROOTFS_B_PART}
echo "SWUPDATE_ARGS=\"-v -d -uhttp://192.168.1.20/MYD-LMX9X-IMAGE/myd-lmx9x.swu -e stable,main\"" > /etc/myir-swupdate.cfg

;;

${ROOTFS_B_PART})

echo "rootfs B part"

fw_setenv swu_mode 0

fw_setenv boot_limit 3

fw_setenv mmcbootpart ${ROOTFS_B_PART}

fw_setenv mmcbootpart_back ${ROOTFS_A_PART}
Echo "SWUPDATE_ARGS=\"-v -d -uhttp://192.168.1.20/MYD-LMX9X-IMAGE/myd-lmx9x.swu -e stable,alt\"" > /etc/myir-swupdate.cfg

;;

*)

echo "con not distinguish part"

exit 1

esac

}

check_root_part_cmdline

check_need_repalce_env

function_on_different_part

In this script, the default setting of the env variable mentioned in the previous chapter will be implemented, and the /etc/fw_env.config file will be modified to configure the correct configuration file that the fw_env tool can use. fw_env contains fw_printenv and fw_setenv. You can modify the uboot env environment variable in the file system.

The last part of the script will add the configuration information required by swupdate to /etc/myir-swupdate.cfg:

root@myd-lmx9x:~# cat /etc/myir-swupdate.cfg

SWUPDATE_ARGS="-v -d -uhttp://192.168.1.20/MYD-LMX9X-IMAGE/myd-lmx9x.swu -e stable,main"

The above contains the specific ip address of the http server, and the path of the swu file, which has been selected in the branch of the sw-description.


4. Operating steps

To implement OTA functions, at least two devices are required, namely the server and the client. There is only one server, MYD-LMX9X (this article uses the MYD-LMX9X development board as an example). The development board connects to a PC through the serial port, or remotely accesses the serial port of the development board through ssh. For details, see the Quick Start guide and Evaluation guide. Then the swu file required by OTA is stored in the PC host, and then the development board executes the corresponding command to complete the OTA upgrade. The following describes the operation steps and precautions in detail.

4.1. Remote upgrade

4.1.1 Create swu files

Firstly, obtain the ota upgrade file maker from MYD-LMX9X's Meer Electronic Download Center via the following link: Ota-generate_SWu.tar.gz.

1) Decompression tool

Create a working directory on the Ubuntu host and extract the tool. Once the extraction is complete, navigate to the directory.

$: mkdir ~/swupdate

$: cp/ota-generate_swu.tar.gz ~/swupdate/ota-generate_swu.tar.gz

# Setto the file path as required

$: cd ~/swupdate

$: tar xvf ota-generate_swu.tar.gz

$: ls -la

total 24

drwxrwxr-x  3 beste beste  4096 4月   9 17:52 .

drwxrwx--- 55 beste beste   4096 4月   9 17:52 ..

-rw-rw-r--  1 beste beste 10240 4月   9 17:52 ota-generate_swu.tar.gz

drwxrwxr-x  2 beste beste  4096 4月   9 17:51 swupdate-ota

$: cd swupdate-ota

$: ls

generate_swu.sh  readme.txt  sw-description  update.sh

2) sw-description

The swupdate files are archived in cpio mode. The description file is named sw-description by default. This file describes the file information and upgrade information in the upgrade package archive. The sw-description is as follows:

software =

{

version = "1.1";

description = "Firmware update for myd-lmx9x"

myd-lmx9x = {

hardware-compatibility: [ "1.0", "1.1" ];

stable:

{

main:

{

images:(

{

filename = "myir-image-core-myd-lmx9x.ext4";

device = "/dev/mmcblk0p3";

filesystem = "ext4" ;

}

);

bootenv:(

{

name="mmcbootpart";

value="3";

},

{

name="mmcbootpart_back";

value="2";

}

);

scripts: (

{

filename = "update.sh";

type = "shellscript";

}

);

};

alt:

{

images:(

{

filename = "myir-image-full-mys-8mmx.ext4.gz";

compressed = "zlib";

device = "/dev/mmcblk0p2";

}

);

bootenv:(

{

name="mmcbootpart";

value="2";

},

{

name="mmcbootpart_back";

value="3";

}

);

scripts: (

{

filename = "update.sh";

type = "shellscript";

}

);

};

};

};

}


A Part
of the keywords in this file will be utilized for future updates of the development board. Firstly, you can open the serial port of the MYD-LMX9X development board to preview the scripts that will be used later, and then power on the eMMC development board and open the serial port.

root@myd-lmx9x:~# ls /etc/myir-swupdate*

/etc/myir-swupdate.cfg /etc/myir-swupdate.sh


You can see the script and cfg configuration file used by swupdate. Open the configuration file:

root@myd-lmx9x:~# cat /etc/myir-swupdate.cfg

SWUPDATE_ARGS="-v -d -uhttp://192.168.1.20/MYD-LMX9X-IMAGE/myd-lmx9x.swu -e stable,main"


If this configuration file does not exist, please execute the following script first. The detailed description of the script will be described in the subsequent section 3.1.2:

root@myd-lmx9x:~# /etc/myir-swupdate.sh

EMMC_DEV 2

SD_DEV 1

ROOTFS_A_PART=2

ROOTFS_B_PART=3

mmcblk0p2

rootfs B part

From the above, you can see that the configured swu file path is http://192.168.1.20/MYD-LMX9X-IMAGE/myd-lmx9x.swu. If you select the main branch of stable in the sw-description description file, you can refer to the content in the sw-description to read and understand it.

Selecting the content under the main branch will burn the myir-image-core-myd-lmx9x.ext4 file system to /dev/mmcblk0p3, which is the third partition under the eMMC of the development board. The first partition of mmcblk0p1 is the partition for storing kernel files and device tree files, and mmcblk0p2 and mmcblk0p3 are file system partition A and file system partition B.

3) Build the swu file

Build and compile from 02_Image or Yocto to myir-image-core-myd-lmx9x.ext4 and place it in the swupdate-ota directory.

$: cp/myir-image-core-myd-lmx9x.ext4 ~/swupdate/swupdate-ota

# In, enter the file path based on the actual situation

$: ls

generate_swu.sh  myir-image-core-myd-lmx9x.ext4  readme.txt  sw-description  update.sh

Next add the newly added file to the generate_swu.sh script:

#!/bin/bash


CONTAINER_VER="1.1"

PRODUCT_NAME="myd-lmx9x"

FILES="sw-description myir-image-core-myd-lmx9x.ext4 update.sh"


#openssl dgst -sha256 -sign swupdate-priv.pem sw-description > sw-description.sig


for i in $FILES;do

echo $i;done | cpio -ov -H crc > ${PRODUCT_NAME}_${CONTAINER_VER}.swu


Finally execute the generate_swu.sh script file:

$: ./generate_swu.sh

sw-description

myir-image-core-myd-lmx9x.ext4

update.sh

2362324 blocks


You can see that the required swu file myd-lmx9x_1.1.swu has been built.

$: ls

generate_swu.sh  myd-lmx9x_1.1.swu  myir-image-core-myd-lmx9x.ext4  readme.txt  sw-description  update.sh


Before executing the following steps, make sure that the myd-lmx9x_1.1.swu file can be accessed normally on the http server, as shown in the following figure:

Figure 4-1. http Server

Ensure that the development board and the ubuntu host system with the http server are in the same network segment. For example, the ip address of the development board is 192.168.1.56 and the ip address of the ubuntu host is 192.168.1.20, and ensure that they can ping through each other.

# Check the ubuntu host ip

$ ifconfig

enp0s3: flags=4163  mtu 1500

inet 192.168.1.20  netmask 255.255.255.0  broadcast 192.168.1.255

inet6 fe80::c403:d51c:76ad:270c  prefixlen 64  scopeid 0x20

ether 08:00:27:47:6a:48  txqueuelen 1000  (Ethernet)

RX packets 1132717  bytes 1333243911 (1.3 GB)

RX errors 0  dropped 6181  overruns 0  frame 0

TX packets 64347  bytes 19130410 (19.1 MB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# Check MYD-LMX9X development board ip

root@myd-lmx9x:~# ifconfig eth0

eth0: flags=4163  mtu 1500

inet 192.168.1.56  netmask 255.255.255.0  broadcast 192.168.1.255

inet6 fe80::443e:54ff:fea7:88fb  prefixlen 64  scopeid 0x20

ether 46:3e:54:a7:88:fb  txqueuelen 1000  (Ethernet)

RX packets 10516  bytes 989859 (966.6 KiB)

RX errors 0  dropped 0  overruns 0  frame 0

TX packets 589  bytes 46288 (45.2 KiB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

# Try Ping the ubuntu host

root@myd-lmx9x:~# ping 192.168.1.20

PING 192.168.1.20 (192.168.1.20) 56(84) bytes of data.

64 bytes from 192.168.1.20: icmp_seq=1 ttl=63 time=60.2 ms

64 bytes from 192.168.1.20: icmp_seq=2 ttl=63 time=5.73 ms

64 bytes from 192.168.1.20: icmp_seq=3 ttl=63 time=4.94 ms

64 bytes from 192.168.1.20: icmp_seq=4 ttl=63 time=2.95 ms

^C

--- 192.168.1.20 ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 3004ms

rtt min/avg/max/mdev = 2.948/18.442/60.151/24.101 ms


4.1.2 Update system

After the preceding steps are complete, boot up the file system, change /etc/swupdate.sh, and change the network address to the actual ip address and the corresponding file path:

echo "SWUPDATE_ARGS=\"-v -d -uhttp://192.168.1.20/swupdate-ota/myd-lmx9x_1.1.swu -e stable,main\"" > /etc/myir-swupdate.cfg


Save after modification. The swu file will be automatically updated after restarting the development board.


Know more about MYIR's MYD-LMX9X Development Board


https://www.myirtech.com/list.asp?id=758





MYIR's SMT smart factory offers one-stop PCBA manufacturing services. Know more about MYIR's ODM and OEM services and visit MYIR's Factory Online by watching the video.

https://www.myirtech.com/service.asp


********************************************************************************************************************************************************

Latest Star SOMs from MYIR







 
Prev:  Optimized Octa-core Cortex-A55 Platform for Advanced Commercial Display Solutions Next:  Ubuntu System Porting Guide for Renesas RZ/G2L-based Remi Pi