软件包ota_downloader的http_ota解析导致内存释放断言

发布于 2020-08-19 16:46:44

硬件配置:

STM32f407ZG平台,网口是LAN8720A,外挂SPIFlash

软件环境:

RT-Thread Studio生成工程,使用设备维护云生成Bootloader,添加使用软件包ota_downloader并选择http_ota;

复现步骤:

使用rt_ota_packaging_tool生成固件并上传至CSDN资源,生成链接https://download.csdn.net/download/lf900619/12726993

测试结果如下:

msh />http_ota http://download.csdn.net/download/lf900619/12726993
[581797] D/web: host address: download.csdn.net , port: 80
[581849] D/web: request header:
[581852] D/web: GET /download/lf900619/12726993 HTTP/1.1
[581858] D/web: Host: download.csdn.net
[581862] D/web: User-Agent: RT-Thread HTTP Agent

[581867] D/web: response header:
[581888] D/web: HTTP/1.1 301 Moved Permanently
[581893] D/web: Server: openresty
[581897] D/web: Date: Wed, 19 Aug 2020 06:46:20 GMT
[581903] D/web: Content-Type: text/html
[581907] D/web: Content-Length: 182
[581911] D/web: Connection: keep-alive
[581915] D/web: Keep-Alive: timeout=20
[581920] D/web: Location: https://download.csdn.net/download/lf900619/12726993
[581929] D/web: get position handle response(301).
[581934] E/web: not support https connect, please enable webclient https configure!
[581944] E/http_ota: webclient GET request failed, response(-1) error.
to free a bad data block:
mem: 0x20012430, used flag: 0, magic code: 0x1ea0
(mem->used) assertion failed at function:rt_free, line number:587

这里出现内存释放断言

尝试过程:

将之前生成的固件并上传至七牛云,生成链接http://qfaiezlse.hn-bkt.clouddn.com/otartthread.rbl

msh />http_ota http://qfaiezlse.hn-bkt.clouddn.com/otartthread.rbl
[D/web] host address: qfaiezlse.hn-bkt.clouddn.com , port: 80
[D/web] request header:
[D/web] GET /otartthread.rbl HTTP/1.1
[D/web] Host: qfaiezlse.hn-bkt.clouddn.com
[D/web] User-Agent: RT-Thread HTTP Agent

[D/web] response header:
[D/web] HTTP/1.1 200 OK
[D/web] Server: Tengine
[D/web] Content-Type: application/octet-stream
[D/web] Content-Length: 201456
[D/web] Connection: keep-alive
[D/web] Date: Wed, 19 Aug 2020 03:00:18 GMT
[D/web] Accept-Ranges: bytes
[D/web] Access-Control-Allow-Origin: *
[D/web] Access-Control-Expose-Headers: X-Log, X-Reqid
[D/web] Access-Control-Max-Age: 2592000
[D/web] Cache-Control: public, max-age=31536000
[D/web] Content-Disposition: inline; filename="otartthread.rbl"; filename*=utf-8''otartthread.rbl
[D/web] Content-Md5: Y4E787WTimN6sCHBpMipug==
[D/web] Content-Transfer-Encoding: binary
[D/web] Etag: "FmxrK9_HJLYtPKG7lZakMLKffBJo"
[D/web] Last-Modified: Wed, 19 Aug 2020 02:55:10 GMT
[D/web] X-Log: X-Log
[D/web] X-M-Log: QNM:fs225;SRCPROXY:fs177;SRC:312;SRCPROXY:376;QNM3:390
[D/web] X-M-Reqid: 7EIAAMaAmKobjCwW
[D/web] X-Qiniu-Zone: 2
[D/web] X-Qnm-Cache: Miss
[D/web] X-Reqid: 7rcAAACRTa8bjCwW
[D/web] X-Svr: IO
[D/web] Ali-Swift-Global-Savetime: 1597806018
[D/web] Via: cache32.l2cn1851[0,200-0,H], cache28.l2cn1851[0,0], cache12.cn2310[0,200-0,H], cache1.cn2310[1,0]
[D/web] Age: 3223
[D/web] X-Cache: HIT TCP_HIT dirn:12:927091760
[D/web] X-Swift-SaveTime: Wed, 19 Aug 2020 03:14:53 GMT
[D/web] X-Swift-CacheTime: 2592000
[D/web] Timing-Allow-Origin: *
[D/web] EagleId: b73cd01515978092418594536e
[D/web] get position handle response(200).
http file_size:201456
[I/http_ota] Start erase flash (download) partition!
[I/http_ota] Erase flash (download) partition success!
[I/http_ota] Download: [====================================================================================================] 100%
[I/http_ota] Download firmware to flash success.
[I/http_ota] System now will restart...
[SFUD]Find a Winbond flash chip. Size is 16777216 bytes.
[SFUD]spi flash device is initialize success.

在七牛云上是升级成功

添加MbedTLS支持后:

msh />http_ota https://download.csdn.net/download/lf900619/12726993
[198457] D/web: host address: download.csdn.net , port: 443
[200161] E/mbedtls.clnt: verify peer certificate fail....
[200168] E/mbedtls.clnt: verification info: ! The certificate is not correctly signed by the trusted CA

[200180] D/web: request header:
[200183] D/web: GET /download/lf900619/12726993 HTTP/1.1
[200189] D/web: Host: download.csdn.net
[200193] D/web: User-Agent: RT-Thread HTTP Agent

[200198] D/web: response header:
[200363] E/mbedtls.clnt: mbedtls_client_read data error, return -0x7200
[200371] D/web: get position handle response(-29184).
[200376] E/http_ota: webclient GET request failed, response(-29184) error.

识别出身份认证失败,没有出现断言情况

查看更多

关注者
1
被浏览
453
lizhen9880
lizhen9880 认证专家 2020-08-21

题主可能并不是纠结于身份认证不对,或者是mbedtls,而是觉得即便没有打开mbedtls,直接用http去请求https链接,不应触发内存无法释放这种级别的断言,看起来像是某个内存被多释放了一次。
题主可以debug一下,在发生断言时看一下栈内容,哪些函数被压栈了,层层剥离找出原因。如果确实是bug,可发起 PR 让更多人受益,如果不熟悉如何PR,可在将查bug过程及结果在gitee或github发issues

3 个回答

你这url有问题的,你把上面的url复制到浏览器,看能不能下载到文件,再用下面的试试

xiangxistu
xiangxistu 2020-08-20

https 比 http 多了一个 mbedtls 的使用。建议使能 webclient 软件包的 TLS 功能。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览