RVB2601应用开发实战系列四:FOTA镜像升级
[复制链接]
本帖最后由 未来开发者 于 2021-9-1 11:41 编辑
关键词:RVB2601、RISC-V开发板、玄铁E906、WiFi&BLE , 低功耗, AliOS Things,RISC-V MCU,上手,好用,控制,开关
1. 概述
本文介绍如何在CH2601开发板上进行FOTA升级。 FOTA 是 Firmware Over the Air 的缩写,即固件空中升级,最常见的就是手机固件的升级。固件的定义范围比较模糊,windows操作系统升级、手机升级、嵌入式系统、单片机控制程序等都的远程升级可以笼统地称为FOTA。用这种方式,设备厂商可以更加快速地进行系统软件的迭代;能够更加快速地向市场推出具有新功能的设备并以此提高用户对其设备的满意度。 下面我们以ch2601_fota_demo为例来介绍如何进行FOTA升级。
2. 环境准备
- 硬件:RVB2601开发板一块、USB线2根
- 软件:CDK最新版本(Windows)

3. 示例获取
打开CDK软件。
点击红色处按钮,点击新建工程按钮。

在搜索框输入fota,点击右边的搜索按钮,ch2601_fota_demo就显示出来了。 点击创建工程。

在弹出框输入工程名字,版本号默认v7.4.3即可。点击下载方案按钮,等待下载完成。

4. 操作流程

我们分成3个大的步骤进行介绍:
- 不同版本固件的生成
- OCC固件添加,升级策略配置
- 设备端配置参数,下载固件并进行系统的升级
请注意:以下出现的方案目录指的是solutions/ch2601_fota_demo这个文件夹下。
4.1 编译生成不同版本固件
4.1.1 基础镜像包1.0.0生成
在示例获取那个章节我们已经把ch2601_fota_demo工程拉取下来了,接下来我们要编译这个工程并生成相应的镜像包。 如下图所示,点击红色方框处按钮进行编译。

编译结束之后,会在方案目录的generated下生成images.zip包。如下所示,打开方案目录。


将这个images.zip拷贝到上级目录(方案目录)并重命名为images_1.0.0.zip
4.1.2 镜像包1.1.1版本生成
可以在方案的app/src/app_main.c文件中加个打印保存文件,并重新编译。将生成的generated/images.zip拷贝到方案目录,并重命名为images_1.1.1.zip,作为高版本。

4.2 OCC版本管理
4.2.1 创建产品,获取许可证

- 在平头哥芯片开发社区上创建产品,在控制台->FOTA服务->添加产品,如下图所示,点击提交按钮。




如下图所示,表示开发许可证已经生成完毕

4.2.2 上传镜像包至OCC服务器,并发布

点击提交按钮

点击红色方框

点击发布按钮

返回之后,发布状态就会变成已发布,如果状态未变,可以再次刷新下。

提交完毕之后,选择1.1.1版本那一行进行发布。发布成功之后,服务器就会生成FOTA固件了。
4.2.3 云端选择升级策略
如右边红色框框,添加标签:

下图中的CID的值后面需要用到,请先记录下来

选择升级策略:

选择刚才写的标签,并提交:

到此为止,云端的配置基本结束了。
4.3 设备检测升级
4.3.1 将发布的镜像包下载到本地
点击红色框图位置下载镜像包到本地

4.3.2 取出hex文件放到指定位置用CDK进行烧录
将下载过来的镜像包解压,并取出total_image.hex文件,放到方案目录的generated目录下


切换到CDK工程,点击红色方框处按钮开始烧录。

烧录过程中。。。

烧录完毕

按复位键启动的打印如下,可以看到当前的版本为1.0.0的版本

4.3.3 设备端设置deivce_id/model,接收固件
我们需要设置一些参数才能联网并且接受新的固件。
4.3.3.1 WiFi设置
通过串口终端输入: kv set wifi_ssid <your_wifi_ssid> kv set wifi_psk <your_wifi_password>
- your_wifi_ssid:你的wifi名字
- your_wifi_password:你的wifi密码
4.3.3.2 设备信息设置
通过串口终端输入: kv set device_id <key> kv set model ch2601
- key:即4.7章节图片中提到的CID的值
- model:即4.1章节中的产品型号值
设置完毕之后按开发板上的复位键重启。
4.3.4 设备端完成固件接收,进入系统升级
请确保设备联网成功。 设备检测到新版本的打印:

开始下载数据:

下载检验完毕,设备自动重启进入系统升级:

4.3.5 系统升级完毕,设备重启,正常运行
系统升级完毕之后,设备自动重启,可以看到刚才加的打印信息出来了,版本号也更新了。

至此,说明整个FOTA升级已经成功完成了。
5. 注意事项
5.1 分区配置
使用升级功能需要指定升级包的存储区域。 配置文件:configs/config.yaml
- mtb_version: 4
- chip: ch2601
-
- diff:
- fota_version: 0
- ram_buf: 50 #DEC KB ( max ram need)
- flash_buf: 16 #DEC KB ( buffer size)
- flash_sector: 4096 #DEC byte ( flash sector)
- diff_mode: 010 #BIN
- double_control: 1
- flash:
- base_address: 0x18000000 # 存储基地址,比如FLASH的基地址
- sector: 4096 # Bytes
- size: 524288 #512kb $(sector count) * sector
-
- partitions:
- - { name: boot, address: 0x18000000, size: 0x10000 }
- - { name: imtb, address: 0x18010000, size: 0x02000 }
- - { name: bmtb, address: 0x18012000, size: 0x01000 }
- - { name: kv, address: 0x18013000, size: 0x04000 }
- - { name: prim, address: 0x18017000, size: 0x30000, verify: true, update: FULL}
- - { name: misc, address: 0x18047000, size: 0x39000 }
对需要升级的分区加上update字段。
分区
|
说明
|
boot
|
bootloader镜像
|
bmtb
|
分区表
|
imtb
|
分区表,包含所有分区位置及安全信息
|
prim
|
应用镜像
|
misc
|
升级备份区,下载下来的镜像先存储在此分区
|
kv
|
KV数据区
|
5.2 代码
有关FOTA升级相关的代码主要是在app/src/cop_fota.c文件中。
6. 结束语
以上即为整个FOTA升级示例详细的操作说明。主要是在OCC芯片开放社区和CDK中进行操作。实际应用过程中需要做好版本的管理。 更多FOTA服务的介绍,可以参考FOTA服务。
本文转自平头哥芯片开放社区(occ),更多详情请点击【这里】 。
|