测试板
ESP8266 : AOS_OTA_BANK_DUAL
MK3060 : AOS_OTA_BANK_SINGLE
升级流程
① 下载代码并选择OTA demo程序和开发板
② 登录云端账号获取四元组并开通固件升级服务
③ 根据需要是否开启安全升级功能,如开启获取云端公钥
④ 编译生成不同版本固件,一个低版本,一个高版本
⑤ 将低版本的固件烧录到对应的目标板子,运行demo程序OTA_APP pk dn ds ps
⑥ 待设备上线后将高版本的固件上传到云端
[email protected] : for ota update. 用于OTA升级。
[email protected] : for direct burning into flash memory. 用于flash烧写。
[email protected] : for ota update. 用于OTA升级。
[email protected] : for direct burning into flash memory. 用于flash烧写。
⑦ 云端推送固件,设备端接收固件,并做完整性校验
⑧ 设备端完成固件校验,进入系统升级
⑨ 系统重启后,上报新版本信息到云端
MK3060 Log
启动LOG
Hello OTA.
ota_service_init
[010598] SYSINFO_APP_VERSION app-1.5.2-20190328.1742
ota_hal_get_version app-1.5.2-20190328.1742
[010600] ....................................................
[010600] ProductKey : a1vuRZ5qR2q
[010600] DeviceName : SensorII
[010600] DeviceID : a1vuRZ5qR2q.SensorII
[010602] ....................................................
[010602] Partn
erID Buf : ,partner_id=example.demo.partner-id
[010604] ModuleID Buf : ,module_id=example.demo.module-id
[010604] Guider URL :
[010604] Guider SecMode : 2 (TLS + Direct)
[010604] Guider Timestamp : 2524608000000
[010604] .................................# ...................
[010606] -----------------------------------------
[010608] Host : a1vuRZ5qR2q.iot-as-mqtt.cn-shanghai.aliyuncs.com
[010608] Port : 1883
[010608] ClientID : a1vuRZ5qR2q.SensorII|securemode=2,timestamp=2524608000000,signmethod=hmacsha256,gw=0,ext=0,partner_id=example.demo.partner-id,module_id=example.demo.module-id,a=aos-r-2.1.0|
[010610] TLS PubKey : 0x7bb45 ('-----BEGIN CERTI ...')
[010610] -----------------------------------------
[010612] MQTT init success!
[010612] Loading the CA root certificate ...
[010616] ok (0 skipped)
[010616] Connecting to /a1vuRZ5qR2q.iot-as-mqtt.cn-shanghai.aliyuncs.com/1883...
[010660] ok
[010660] . Setting up the SSL/TLS structure...
[010660] ok
[010662] Performing the SSL/TLS handshake...
[011114] ok
[011114] . Verifying peer X.509 certificate..
[011114] certificate verification result: 0x00
[011194] mqtt connect success!
[011198] the network interface info set failed or not set, writen len is 0
[011202] Public name:/ota/device/inform/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"version":"app-1.5.2-20190328.1742"}}
[011204] upgrade:/ota/device/upgrade/a1vuRZ5qR2q/SensorII
[011206] mqtt subscribe packet sent,topic = /ota/device/upgrade/a1vuRZ5qR2q/SensorII!
[011308] ota init success, ver:app-1.5.2-20190328.1742 type:0
[071308] send MQTT ping...
[071346] receive ping response!
[131308] send MQTT ping...
[131346] receive ping response!
[191308] send MQTT ping...
[191344] receive ping response!
升级LOG
#
# [236910] mqtt cb evt:12 {"code":"1000","data":{"size":445830,"sign":"bd3493aca7eb8ba106755861c54509e8","version":"app-2.0.0-20190328.1744","url":"https://iotx-ota.oss-cn-shanghai.aliyuncs.com/ota/9094af2055e93ccbe1e58fd9ad3a3276/cjtsgfb0200003374x6a3xl6o.bin?Expires=1553852902&OSSAccessKeyId=cS8uRRy54RszYWna&Signature=KiCGHiQqKG2Ny6arW16jM2OQnk8%3D","signMethod":"Md5","md5":"bd3493aca7eb8ba106755861c54509e8"},"id":1553766502568,"message":"success"}
[237410] ota init off:0x00000000 part:3 len:445830 crc:0x0000
[237412] ota init board ALI_AOS_MK3060 success!
[237412] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "0","desc":""}}
D: 41 HAL_TCP_Establish() | establish tcp connection with server(host=iotx-ota.oss-cn-shanghai.aliyuncs.com port=80)
D: 80 HAL_TCP_Establish() | success to establish tcp, fd=4
[237460] send GET /ota/9094af2055e93ccbe1e58fd9ad3a3276/cjtsgfb0200003374x6a3xl6o.bin?Expires=1553852902&OSSAccessKeyId=cS8uRRy54RszYWna&Signature=KiCGHiQqKG2Ny6arW16jM2OQnk8%3D HTTP/1.1
Accept:*/*
User-Agent: Mozilla/5.0
Cache-Control: no-cache
Connection: close
Host:iotx-ota.oss-cn-shanghai.aliyuncs.com:80
[237464] 304 bytes send.
[237834] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "10","desc":""}}
[237838] s:45093 512 per:10
[237998] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "15","desc":""}}
[238000] s:67109 512 per:15
[238164] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "20","desc":""}}
[238166] s:89637 512 per:20
[238314] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "25","desc":""}}
[238318] s:111653 512 per:25
[238474] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "30","desc":""}}
[238476] s:134181 512 per:30
[238628] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "35","desc":""}}
[238630] s:156197 512 per:35
[238798] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "40","desc":""}}
[238802] s:178725 512 per:40
[238986] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "45","desc":""}}
[238990] s:200741 512 per:45
[239142] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "50","desc":""}}
[239144] s:223269 512 per:50
[239282] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "55","desc":""}}
[239284] s:245285 512 per:55
[239450] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "60","desc":""}}
[239452] s:267813 512 per:60
[239600] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "65","desc":""}}
[239602] s:289829 512 per:65
[239774] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "70","desc":""}}
[239776] s:312357 512 per:70
[239926] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "75","desc":""}}
[239930] s:334373 512 per:75
[240106] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "80","desc":""}}
[240108] s:356901 512 per:80
[240264] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "85","desc":""}}
[240266] s:379429 512 per:85
[240428] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "90","desc":""}}
[240430] s:401445 512 per:90
[240570] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "95","desc":""}}
[240572] s:423973 512 per:95
E: 208 HAL_TCP_Read() | connection is closed
[240720] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "100","desc":""}}
[240724] s:445830 353 per:100
[240724] download finish ret:0.
[240726] md5 src=BD3493ACA7EB8BA106755861C54509E8 dst=BD3493ACA7EB8BA106755861C54509E8
[240726] bin s:445830 off:445802
[240726] magic:0xefefefef size:445802 md5:528008882EB85EC42791666ABECFE910 crc16:0xffff
[240928] md5 src=528008882EB85EC42791666ABECFE910 dst=528008882EB85EC42791666ABECFE910
[240930] OTA md5 ret:0
[240930] AOS_OTA_BANK_SINGLE
[240934] OTA finish dst:0x00000000 src:0x00000000 len:0x00000000, crc:0x523f.
烧写完成启动LOG
[240934] upgrade over err:0
[240934] Public name:/ota/device/progress/a1vuRZ5qR2q/SensorII msg:{"id":0,"params":{"step": "100","desc":""}}
uart0 init success
254: swap offset 0x0, index 0
170: swap offset 0x0
170: swap offset 0x10000
170: swap offset 0x20000
170: swap offset 0x30000
170: swap offset 0x40000
170: swap offset 0x50000
170: swap offset 0x60000
170: swap offset 0x70000
170: swap offset 0x80000
170: swap offset 0x90000
170: swap offset 0xa0000
170: swap offset 0xb0000
170: swap offset 0xc0000
170: swap offset 0xd0000
184: update succ!
uart0 init success
Press key 'w' into 2nd boot cmd, Waiting 100ms ...
Bootup flag 0x0, num 0x0
flash txpwr table:0x7
dif g and n20 ID in flash:2
read txpwr tab from flash success
DPLL Unlock
enter low level!
mac fc:ee:e6:17:56:e3
leave low level!
app_init finished
start-----------hal
Welcome to AliOS Things
疑似AliOS Bug
int32_t hal_flash_write(hal_partition_t pno, uint32_t* poff, const void* buf ,uint32_t buf_size)
{
uint32_t start_addr, len, left_off;
int32_t ret = 0;
uint8_t *buffer = NULL;
hal_logic_partition_t *partition_info;
partition_info = hal_flash_get_info( pno );
start_addr = partition_info->partition_start_addr + *poff;
left_off = start_addr % FLASH_ALIGN;
len = ((buf_size + left_off) + ~FLASH_ALIGN_MASK) & FLASH_ALIGN_MASK;
if (len > buf_size || left_off > 0) {
buffer = (uint8_t *)aos_malloc(len);
if (!buffer)
return -1;
memset(buffer, 0xff, len);
#ifdef ESP8266FLASHBUG
//BUG : 4字节对齐
if(left_off>0){
vPortETSIntrLock();
spi_flash_read(start_addr - left_off, buffer, 4);
vPortETSIntrUnlock();
}
#endif
memcpy(buffer + left_off, buf, buf_size);
vPortETSIntrLock();
ret = spi_flash_write(start_addr - left_off, (uint32_t *)buffer, len);
vPortETSIntrUnlock();
aos_free(buffer);
} else {
vPortETSIntrLock();
ret = spi_flash_write(start_addr, (uint32_t *)buf, len);
vPortETSIntrUnlock();
}
*poff += buf_size;
return ret;
}