9.2.2. eMMC OTA参数配置

eMMC OTA参数配置主要分为主系统配置, Recovery系统配置, 以d211_per1_mmc为例进行说明

系统名称

配置文件

主系统

d211_per1_mmc_defconfig

Recovery系统

d211_ota_emmc_defconfig

主系统配置涉及到的文件如下:

1. target/d211/per1/image_cfg.json //分区配置和烧录
2. target/d211/common/env.txt //U-Boot环境变量
3. target/d211/per1/rootfs_overlay/etc/fw_env.config
4. target/d211/per1/rootfs_overlay/etc/swupdate_main
5. target/d211/per1/swupdate/sw-description
6. target/d211/per1/swupdate/sw-images.cfg
7. target/configs/d211_per1_mmc_defconfig

Recovery系统配置涉及到的文件如下:

1. target/d211/ota_emmc/rootfs_overlay/etc/fw_env.config
2. target/d211/ota_emmc/rootfs_overlay/etc/init.d/S91swupdate_ota
3. target/configs/d211_ota_emmc_defconfig

9.2.2.1. Recovery系统配置

9.2.2.1.1. SWUpdate包配置

Recovery系统配置文件路径如下:

target/configs/d211_ota_emmc_defconfig

进入到Recovery系统 SDK 生产环境

lunch ota_emmc

在Luban根目录下执行命令

make m

进入Luban SDK 功能配置, 按如下选择:

Third-party packages  --->
    -*- libubootenv  --->
    -*- libconfig  --->
    -*- libcurl  --->
    [*] swupdate  --->

9.2.2.1.2. 配置 RootFS 为initramfs

默认切换RootFS配置为initramfs, 执行命令

make m

配置如下:

Filesystem images  --->
    RootFS images  --->
        -*- cpio the root filesystem (for use as an initial RAM filesystem)
            Compression method (gzip)  --->
    [*] initial RAM filesystem linked into linux kernel

默认将initramfs编译进Kernel, 执行命令

make km

配置如下:

General setup  --->
    [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
    [*]   Support initial ramdisk/ramfs compressed using gzip

9.2.2.2. 主系统配置

9.2.2.2.1. SWUpdate包配置

进入主系统 SDK 生产环境

lunch d211_per1_mmc

在Luban根目录下执行配置命令

make m

进入Luban SDK 功能配置, 按如下配置选择:

Third-party packages  --->
    -*- libubootenv  --->
    -*- libconfig  --->
    -*- libcurl  --->
    [*] swupdate  --->

查看SWUpdate库相关配置如下:

[*]   use prebuilt binary instead of building from source
(package/third-party/swupdate/luban_swupdate.config) swupdate configuration file
[*]   swupdate webserver

查看SWUpdate相关配置, 需要先关闭SWUpdate预编译功能:

[ ]   use prebuilt binary instead of building from source

执行命令查看SWUpdate相关配置

make swupdate-menuconfig

SWUpdate包重要配置信息解析:

文件

说明

CONFIG_UBOOT=y

支持U-Boot

CONFIG_DOWNLOAD=y

使能通过libcurl的方式下载程序

CONFIG_DOWNLOAD_SSL=y

在使用libcurl时使能ssl校验

CONFIG_WEBSERVER=y

编译web服务器, 设备端作为服务器使用

CONFIG_HASH_VERIFY=y

解析升级包时使能sha256校验

CONFIG_BOOTLOADERHANDLER=y

在升级过程中允许修改U-Boot环境变量

CONFIG_CFI=y

允许给flash烧录程序

CONFIG_RAW=y

默认烧录方式, 给eMMC使用

CONFIG_SHELLSCRIPTHANDLER=y

支持shell脚本升级

注解

如果需要重新配置SWUpdate参数, 必须关掉SWUpdate预编译功能, 修改的SWUpdate配置才能够生效

9.2.2.3. 增加recovery分区并烧录程序

增加 recovery分区, 烧录Recovery 系统镜像。在 image_cfg.json 修改如下:

"kernel":   { "size": "12m" },
+ "recovery": { "size": "10m" },          //在kernel分区后面增加recovery分区

"kernel": {
        "file": "kernel.itb",
        "attr": ["mtd", "required"],      //在kernel镜像烧录配置后面添加recovery镜像烧录配置
        "part": ["kernel"]
},
+ "recovery": {
+    "file": "recovery.itb",              //将recovery.itb镜像文件烧录到recovery分区里面
+    "attr": ["mtd", "required"],
+    "part": ["recovery"]
+ },

"kernel.itb": {
        "its": "kernel.its"               //在kernel镜像生成方法后面增加recovery镜像生成方法

},
+ "recovery.itb": {
+    "its": "recovery.its"                //配置recovery.itb文件通过recovery.its指导编译完成
+ },

注解

  1. 在image目录中检查recovery.itb 文件是否生成

  2. 通过升级信息判断recovery.itb是否烧录到recovery分区

9.2.2.4. U-Boot 环境变量配置

通过环境变量boot_partition决定从kernel分区还是recovery分区引导启动

在d211/common/env.txt修改如下:

+ set_commonargs_recovery=setenv bootargs earlycon=${earlycon} earlyprintk console=${console} rdinit=/linuxrc
+  //从Recovery系统启动, 引导initramfs启动

+ set_mmc_bootargs_recovery=run set_commonargs_recovery; \ //设置环境变量set_mmc_bootargs_recovery
                      run set_mmc_root; \
                      setenv bootargs "${bootargs}";

+ boot_partition=kernel   //初始化环境变量boot_partition从kernel分区启动

+ run set_mmc_bootargs_recovery; \
+ loadknl mmc ${boot_devnum} recovery ${knl_addr}; \
+ bootm ${knl_addr};      //nand_boot环境变量增加从recovery分区引导启动

注解

手动配置环境变量boot_partition并保存, 重启测试U-Boot是否能够引导Recovery系统启动, 判断配置文件是否生效

9.2.2.4.1. fw_env.config配置

OTA升级过程中, 主系统和Recovery系统都使用到SWUpdate命令, SWUpdate依赖U-Boot环境变量, 需要在 Linux 中配置 U-Boot 环境变量索引路径。

fw_printenv/fw_setenv命令默认索引路径为:

/etc/fw_env.config

因为使用到了 env_r 备份分区, fw_env.config 需要包含 env, env_r 分区信息, eMMC 的默认的配置信息如下:

//device name       Device offset   Env. size
/dev/mmcblk0        0x180000        0x4000

注解

  1. /dev/mmcblk0表示emmc分区的设备号

  2. Device offset 为env分区的偏移值

  3. Env. size 表示实际 env 的大小

Recovery系统 SDK 生产环境默认存在fw_env.config文件, 具体路径如下:

target/d211/ota_emmc/rootfs_overlay/etc/fw_env.config

主系统 SDK 生产环境默认存在fw_env.config文件, 具体路径如下:

fw_env.config在主系统的路径如下:

target/d211/<board>/rootfs_overlay/etc/fw_env.config

注解

  1. 客户env、env_r分区信息如果修改, 以上两个fw_env.config文件需要同时更新

  2. 在 Linux 环境下执行fw_printenv/fw_setenv命令, 测试能够正常打印U-Boot环境变量信息

至此, OTA 手动升级环境搭建完成, 下面继续搭建OTA 自动升级环境, 首先配置一个 ota 分区, 用来保存 OTA 升级swu包数据

9.2.2.4.2. 配置 ota 分区烧录OTA升级包

在target/d211/per1/image_cfg.json文件修改

"partitions": { // Partition table apply to device
                    "rootfs": { "size": "72m" },
    +               "ota": { "size": "96m" },
},

"rootfs": {
    "file": "rootfs.ext4",
    "attr": ["block", "required"],
    "part": ["rootfs"]
},
+ "ota": {
+    "file": "ota.ext4",
+    "attr": ["block", "required"],
+    "part": ["ota"]
+ },

9.2.2.4.3. 主系统配置生成 ota.ext4 目标文件

将OTA升级包下载到ota分区里面, 方便测试OTA本地升级功能

ota 分区如下所示:

../../../_images/part1.png

进入主系统 SDK 生产环境

lunch d211_per1_mmc

在Luban根目录下执行配置命令

make m

配置如下:

Filesystem images  --->
    [*] UserFS 1  --->
        (ota) Name                                                                                                                                 │ │
        FS Type (Ext4)  --->
        (96M) Size
        (target/$(LUBAN_CHIP_NAME)/$(LUBAN_BOARD_NAME)/ota) Overlay directory

注解

编译生成的 swu 包文件d211_per1_mmc.swu需要拷贝到目录 target/$(LUBAN_CHIP_NAME)/$(LUBAN_BOARD_NAME)/ota 下, 将target/$(LUBAN_CHIP_NAME)/$(LUBAN_BOARD_NAME)/ota目录里的内容生成ota.ext4镜像文件, 之后整个文件烧录到ota分区里面。

9.2.2.4.4. 启动脚本配置

主系统自动挂载ota分区到/mnt/ota 目录下, 之后直接执行命令就可以启动 OTA 升级了

脚本路径如下:

target/d211/per1/rootfs_overlay/etc/swupdate_main

主要内容如下:

mkdir -p /mnt/ota
mount /dev/mmcblk0p12 /mnt/ota              //挂载ota分区到mnt/ota目录下

注解

客户如果自定义分区, 对应的设备节点有变更,需要修改对应的挂载方式

Recovery系统执行后, 也需要自动挂载ota分区到/mnt/ota 目录下, 并根据 U-Boot 环境变量自动触发 OTA 升级功能。

Recovery系统启动脚本路径如下:

target/d211/<board>/rootfs_overlay/init.d/S91swupdate_ota

主要内容如下:

mkdir -p /mnt/ota
mount /dev/mmcblk0p12 /mnt/ota              //挂载ota分区到mnt/ota目录下
./usr/lib/swupdate/swupdate_cmd.sh          //执行OTA升级程序

注解

客户如果自定义分区, 对应的设备节点有变更,需要修改对应的挂载方式