OpenEdv-开源电子网

 找回密码
 立即注册
查看: 2193|回复: 1

手把手教学OneOS FOTA升级

[复制链接]
回帖奖励 1 金钱 回复本帖可获得 1 金钱奖励! 每人限 1 次(中奖概率 80%)

5

主题

23

帖子

0

精华

初级会员

Rank: 2

积分
70
金钱
70
注册时间
2021-10-17
在线时间
19 小时
发表于 2022-8-5 10:59:09 | 显示全部楼层 |阅读模式
之前已经跟各位小伙伴介绍过FOTA安全升级的升级步骤及流程,具体可查看:远程升级怕截胡?详解FOTA安全升级。接下来我带领大家手把手使用OneOS FOTA升级功能,看完不会来找我😎😎

一、OneOS FOTA概述
OneOS FOTA服务主要由OTA云平台、OTA组件两部分构成。

OTA云平台提供新建OTA项目、制作差分包、差分包测试及发布、查询升级日志等功能。

OTA组件包括BootLoader和APP,BootLoader负责保存引导、差分还原,APP负责制作差分包压缩文件(前置版本压缩包、目标版本压缩包)、版本监测、固件差分包下载、版本校验、日志上报。

1. OTA云平台

OTA平台地址:https://os.iot.10086.cn/otaplatform/ProjectHome

OTA云平台免费开放,使用通过企业认证的OneOS账号,就能免费使用OTA云平台功能。(OneOS账号注册地址为:OneOS - 中国移动物联网操作系统。登录OneOS平台,进入账户中心,可选择企业认证)

2. BootLoader

BootLoader的代码仓库不开源,获取BootLoader时,需要联系OneOS官方由技术支持来提供。

3. OneOS


OneOS的代码仓库目前已开源,码云下载地址:https://gitee.com/cmcc-oneos/OneOS,官网下载地址:https://os.iot.10086.cn/download/


二、升级流程示例

硬件:本次基于Pandora  开发板,不同开发板配置会有差异
软件:OneOS
配置工具:OneOS Cube
烧录工具:STM32 ST-LINK Utility

Step 1开发板烧录BootLoader


Pandora  支持Lunsun算法,直接烧录BootLoader。
烧录工具:STM32 ST-LINK Utility


A.Connect to the target成功以后,先做 Full chip erase擦除操作。



B. Target -> Program & Verify


选择BootLoader真实路径,执行start



烧录成功后,观察开发板启动日志如下:(jump to app failed 是正常的,当前只烧录了Bootloader,没有烧录APP)

  1. OneOS> Flash device |             onchip_flash | len: 0x00080000 | erase_size: 0x00000800
  2. ==================== FAL partition table ====================
  3. | name       | flash_dev    |   offset   |    length  |
  4. -------------------------------------------------------------
  5. | bootloader | onchip_flash | 0x00000000 | 0x00018000 |
  6. | cfg        | onchip_flash | 0x00018000 | 0x00000000 |
  7. | app        | onchip_flash | 0x00018000 | 0x00050000 |
  8. | download   | onchip_flash | 0x00068000 | 0x00018000 |
  9. =============================================================
  10. NO PACKAGE

  11. Not find user application. Will stop at bootloader.

  12. Jump to app failed, run to command mode
  13. OneOS>
复制代码

从这个启动表,可以看出app的启动地址为0x00018000,app的size为0x00050000。


注意:
BootLoader只需要烧录一次,烧录BootLoader时建议全部擦除。
BootLoader的代码仓库不开源,需要获取BootLoader时,可以私信。


Step 2 APP Board boot configure配置


OTA组件需要bootloader支持,烧录bootloader文件后,app的起始地址和app的大小需要配置以后才能跳转成功。配置参数如下:

  1. (Top) → Drivers→ Boot→ CORTEX-M Boot→ Board boot configure
  2.                                              OneOS Configuration
  3. (0x08018000) text section addr
  4. (0x00050000) text section size
  5. (0x20000000) data section addr
  6. (0x00018000) data section size
复制代码
Step 3 OTA云平台创建项目,生成关键参数



登录OTA云平台创建项目:



创建成功后,生成关键参数:

OEM、设备型号、Product ID、Product Secret、设备类型、平台

Step 2 APP开启OTA配置参数,编译生成前置版本oneos.bin,并制作前置版本压缩包


APP menuconfig 开启OTA ,OTA配置参数和平台参数保持一致。配置如下:


  1. (Top) → Components→ OTA→ Fota by CMIOT
  2.                                              OneOS Configuration
  3. [*] Enable fota by cmiot
  4.         The supported download solution (general)  --->
  5.         The supported network protocol (Http)  --->
  6.         The supported algorithm (Lusun)  --->
  7. (3)     Segment size index
  8. (panduora) Oem
  9. (stm32l475) Model
  10. (1635694904) Product id
  11. (3a812df6a04b4c87a06d68b64a50aeac) Product secret
  12. (box)   Device type
  13. (STM32F1) Platform
  14. (3.0)   Firmware version
复制代码

APP menuconfig 配置完成后,需要使用命令 scons --ide=mdk5 重新生成工程。使用keil编译工程会在工程目录下生成oneos.bin文件。也可以直接使用oneos-cube工具,进入工程目录,直接执行scons编译。

使用oneos-cube制作前置版本压缩包,在工程路径下,执行以下命令:(根据真实的工程路径、压缩软件路径替换打包软件路径)


  1. E:\Code\oneos-2.0\projects\stm32l475-atk-pandora-fota
  2. > ..\..\components\ota\cmiot\cmiot_bin.bat "C:\Program Files (x86)\360\360zip\360zip.exe" oneos_config.h oneos.bin
  3. The file cannot be copied onto itself.
  4.         0 file(s) copied.
  5. ONEOS_V1.0
  6. cmiot fota used size=0
  7. cmiot fota delta size=-2
  8. sec_cnt = 0
  9. lusun
  10. Deleted file - E:\Code\oneos-2.0\projects\stm32l475-atk-pandora-fota\cmiot_info.txt
  11. Deleted file - E:\Code\oneos-2.0\projects\stm32l475-atk-pandora-fota\fota-bootlaoder-3.0\cmiot_info.txt
  12. Complete
复制代码

制作出了的前置版本压缩包,包含2个文件,其中oneos.bin为APP文件,cmiot_info.txt就是版本信息、差分算法的信息文件。





Step 5 APP 修改其他配置、修改OTA参数 Firmware version,编译生成目标版本 oneos.bin,并制作目标版本压缩包
该部分操作可参考步骤4。


注意:OTA配置里面的Firmware version参数必须修改,其他配置可改可不改。


Step 6 OTA云平台制作差分包,测试通过,并发布


差分包平台地址:https://os.iot.10086.cn/otadiff/#/dashboard


项目、差分对比块大小、目前版本、前置版本需要替换为真实数据。





参数配置完成后,点击下一步、解析成功,再点击下一步制作差分包,制作完成后点击立即部署。







在OTA云平台对应的项目管理里面,可查看版本管理。




点击配置差分、操作状态项执行测试通过,执行成功后,操作状态项再执行发布。




发布成功后,目前版本的状态会变更为已发布



Step 7开发板烧录前置版本oneos.bin文件,启动并连接互联网


烧录工具:STM32 ST-LINK Utility


直接烧录前置版本oneos.bin。


注意:Start address变更为APP的起始地址,File path变更为oneos.bin文件的真实路径。




烧录成功后,观察开发板启动日志如下:

  1. sh />Flash device |             onchip_flash | len: 0x00080000 | erase_size: 0x00000800
  2. ==================== FAL partition table ====================
  3. | name       | flash_dev    |   offset   |    length  |
  4. -------------------------------------------------------------
  5. | bootloader | onchip_flash | 0x00000000 | 0x00018000 |
  6. | cfg        | onchip_flash | 0x00018000 | 0x00000000 |
  7. | app        | onchip_flash | 0x00018000 | 0x00050000 |
  8. | download   | onchip_flash | 0x00068000 | 0x00018000 |
  9. =============================================================
  10. NO PACKAGE

  11. Find user application success.
  12. The Bootloader will go to user application now.
  13. [33m[0] W/STARTUP: OneOS kernel start, version: Kernel-V2.0.1-20210118 [_k_startup][251]
  14. cs:cortexm_systick, mult:3355443200, shift:28, mult_t:343597384, shift_t:32
  15. ce:lptim1, mult:1074, shift:32, mult_t:4096000000, shift_t:10
  16. e:tim2, mult:171798692, shift:31, mult_t:3355443200, shift_t:28
  17. ce:tim15, mult:171798692, shift:31, mult_t:3355443200, shift_t:28
  18. ce:tim16, mult:171798692, shift:31, mult_t:3355443200, shift_t:28
  19. ce:tim17, mult:171798692, shift:31, mult_t:3355443200, shift_t:28
  20. [SFUD] Warning: The OS tick(100) is less than 1000. So the flash write will take more time.
  21. [SFUD] Find a Winbond flash chip. Size is 16777216 bytes.
  22. [SFUD] W25Q128 flash device is initialize success.
  23. ==================== FAL partition table ====================
  24. | name       | flash_dev    |   offset   |    length  |
  25. -------------------------------------------------------------
  26. | bootloader | onchip_flash | 0x00000000 | 0x00018000 |
  27. | cfg        | onchip_flash | 0x00018000 | 0x00000000 |
  28. | app        | onchip_flash | 0x00018000 | 0x00050000 |
  29. | download   | onchip_flash | 0x00068000 | 0x00018000 |
  30. | diff_patch | nor_flash    | 0x00000000 | 0x00100000 |
  31. | backup     | nor_flash    | 0x00100000 | 0x00100000 |
  32. | easyflash  | nor_flash    | 0x00200000 | 0x00080000 |
  33. | wifi_image | nor_flash    | 0x00280000 | 0x00080000 |
  34. | font       | nor_flash    | 0x00300000 | 0x00700000 |
  35. | filesystem | nor_flash    | 0x00a00000 | 0x00600000 |
  36. =============================================================
  37. [311] I/esp8266: AT version:1.7.0.0(Aug 16 2018 00:57:04) [module_esp8266_create][216]
  38. [311] I/esp8266: SDK version:3.0.0(e27cf60) [module_esp8266_create][216]
  39. [311] I/esp8266: compile time:Oct 30 2018 18:18:34 [module_esp8266_create][216]
  40. sh />
  41. sh />[817] I/esp8266.wifi: ESP8266 WIFI has get ip [urc_ip_func][829]
  42. [817] I/esp8266: Auto create esp8266 module object success! [esp8266_auto_create][343]
  43. sh />
复制代码


本次测试使用的molink基于模组esp8266连接。

使用ifconfig/ping 查看网络、判断网络连通性。



  1. sh />ifconfig

  2. LIST AT MODULE INFORMATION
  3. --------------------------------------------------------------------------------
  4. Module   Name    : esp8266
  5. WiFi     Mode    : SoftAP+Station
  6. WiFi     Status  : Connected
  7. STA IPv4 Address : 192.168.59.104
  8. --------------------------------------------------------------------------------
  9. sh />
  10. sh />
  11. sh />
  12. sh />ping www.baidu.com
  13. [0] 32 bytes from 39.156.66.14 icmp_seq=0 time=45 ms
  14. [1] 32 bytes from 39.156.66.18 icmp_seq=1 time=39 ms
  15. [2] 32 bytes from 39.156.66.14 icmp_seq=2 time=40 ms
  16. [3] 32 bytes from 39.156.66.18 icmp_seq=3 time=66 ms

  17. Ping statistics for 39.156.66.18 :
  18. Packets: Sent = 4, Received = 4, Lost = 0, Mintime = 39 ms, Maxtime = 66 ms, Avgtime = 47 ms
  19. sh />
复制代码
Step 8 开发板发起版本检测


检测版本是调用cmiot_upgrade接口,可以直接在shell调试界面直接执行cmiot_cv命令。



  1. sh />cmiot_cv
  2. [39592] I/esp8266.netconn: Module esp8266 receive close urc data of connect 0 [urc_close_func][667]
  3. [39592] I/esp8266.netconn: Module esp8266 netconn id 0 destroyed [esp8266_netconn_destroy][209]
  4. [39740] I/esp8266.netconn: Module esp8266 receive close urc data of connect 0 [urc_close_func][667]
  5. [39740] I/esp8266.netconn: Module esp8266 netconn id 0 destroyed [esp8266_netconn_destroy][209]
  6. [39821] I/esp8266.netconn: Module esp8266 receive close urc data of connect 0 [urc_close_func][667]
  7. [39821] I/esp8266.netconn: Module esp8266 netconn id 0 destroyed [esp8266_netconn_destroy][209]
  8. start upgrade rst:0
  9. sh />
复制代码


返回状态为0,说明有升级包且下载成功。


Step 9 开发板差分还原


APP下载新版本差分包完成后,本地md5校验通过。重启设备,进入BootLoader后,读取到download中记录的状态信息,就能判断有差分包,就会进行差分还原,完成差分还原后,就会跳转到APP起始位置,这时运行的APP就已经是升级后的版本了。


差分还原过程及启动如下:


  1. sh />
  2. sh />reboot
  3. Flash device |             onchip_flash | len: 0x00080000 | erase_size: 0x00000800
  4. ==================== FAL partition table ====================
  5. | name       | flash_dev    |   offset   |    length  |
  6. -------------------------------------------------------------
  7. | bootloader | onchip_flash | 0x00000000 | 0x00018000 |
  8. | cfg        | onchip_flash | 0x00018000 | 0x00000000 |
  9. | app        | onchip_flash | 0x00018000 | 0x00050000 |
  10. | download   | onchip_flash | 0x00068000 | 0x00018000 |
  11. =============================================================
  12. 0%

  13. 1%

  14. 2%

  15. 2%

  16. 3%

  17. ...... (省略过程)

  18. 97%

  19. 97%

  20. 98%

  21. 99%

  22. 100%

  23. Update succ

  24. Find user application success.
  25. The Bootloader will go to user application now.
  26. [33m[0] W/STARTUP: OneOS kernel start, version: Kernel-V2.0.1-20210118 [_k_startup][251]
  27. cs:cortexm_systick, mult:3355443200, shift:28, mult_t:343597384, shift_t:32
  28. ce:lptim1, mult:1074, shift:32, mult_t:4096000000, shift_t:10
  29. e:tim2, mult:171798692, shift:31, mult_t:3355443200, shift_t:28
  30. ce:tim15, mult:171798692, shift:31, mult_t:3355443200, shift_t:28
  31. ce:tim16, mult:171798692, shift:31, mult_t:3355443200, shift_t:28
  32. ce:tim17, mult:171798692, shift:31, mult_t:3355443200, shift_t:28
  33. [SFUD] Warning: The OS tick(100) is less than 1000. So the flash write will take more time.
  34. [SFUD] Find a Winbond flash chip. Size is 16777216 bytes.
  35. [SFUD] W25Q128 flash device is initialize success.
  36. ==================== FAL partition table ====================
  37. | name       | flash_dev    |   offset   |    length  |
  38. -------------------------------------------------------------
  39. | bootloader | onchip_flash | 0x00000000 | 0x00018000 |
  40. | cfg        | onchip_flash | 0x00018000 | 0x00000000 |
  41. | app        | onchip_flash | 0x00018000 | 0x00050000 |
  42. | download   | onchip_flash | 0x00068000 | 0x00018000 |
  43. | diff_patch | nor_flash    | 0x00000000 | 0x00100000 |
  44. | backup     | nor_flash    | 0x00100000 | 0x00100000 |
  45. | easyflash  | nor_flash    | 0x00200000 | 0x00080000 |
  46. | wifi_image | nor_flash    | 0x00280000 | 0x00080000 |
  47. | font       | nor_flash    | 0x00300000 | 0x00700000 |
  48. | filesystem | nor_flash    | 0x00a00000 | 0x00600000 |
  49. =============================================================
  50. [311] I/esp8266: AT version:1.7.0.0(Aug 16 2018 00:57:04) [module_esp8266_create][216]
  51. [311] I/esp8266: SDK version:3.0.0(e27cf60) [module_esp8266_create][216]
  52. [311] I/esp8266: compile time:Oct 30 2018 18:18:34 [module_esp8266_create][216]

  53. sh />[1115] I/esp8266.wifi: ESP8266 WIFI has get ip [urc_ip_func][829]
  54. [1115]I/esp8266: Auto create esp8266 module object success! [esp8266_auto_create][343]
  55. [1116]sh />
复制代码



Step 10 开发板上报升级结果

完成差分还原后,开发板会正常启动,BootLoader会在Download状态信息中记录升级信息。

开发板连接到互联网,联网成功后,调用cmiot_report_upgrade()接口就可以调用升级日志上报功能,可以直接在shell中输入cmiot_ru调用。

升级日志上报如下:
  1. sh />cmiot_ru
  2. [20754] I/esp8266.netconn: Module esp8266 receive close urc data of connect 0 [urc_close_func][667]
  3. [20754] I/esp8266.netconn: Module esp8266 netconn id 0 destroyed [esp8266_netconn_destroy][209]
  4. start report upgrade rst:0
  5. sh />
复制代码

返回状态为0,说明有升级结果且上报成功。

在OTA云平台->OTA升级->设备升级详情 也可以查看具体详情:





好啦,以上就是对OneOS FOTA功能的手把手教学,小伙伴若还有相关的问题或疑虑欢迎私信交流。


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

0

主题

441

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
2850
金钱
2850
注册时间
2016-3-19
在线时间
747 小时
发表于 2023-7-24 08:34:33 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-5-15 16:22

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表