找回密码
 立即注册

微信扫码登录

楼主: wes58

Device OTA upgrade

[复制链接]

27

主题

121

回帖

447

积分

版主

积分
447
发表于 2024-11-6 16:51:05 | 显示全部楼层
1. If the remote device has enabled the OTA query function, it will periodically check for upgradable firmware. The function of the Image Notify command is to notify remote devices to immediately trigger OTA query.
2. In addition to supporting remote device upgrades, self upgrades can also be used. When upgrading its own firmware, this option needs to be selected.
3. The attachment is the complete data package.
all_packets.7z (331.74 KB, 下载次数: 1)





10

主题

18

回帖

158

积分

注册会员

积分
158
 楼主| 发表于 2024-11-7 11:00:38 | 显示全部楼层
本帖最后由 wes58 于 2024-11-7 17:10 编辑
TL_YB 发表于 2024-11-6 16:51
1. If the remote device has enabled the OTA query function, it will periodically check for upgradabl ...

Thank you very much. I will look at the file.
But regarding your response. You wrote: " If the remote device has enabled the OTA query function, it will periodically check for upgradable firmware."
After you transfer firmware to the gateway, how does the gateway know which device the firmware is for? It doesn't know the network nor IEEE address of the device? That's why I thought you have to send "Image Notify" message?

I have tried today using 1MB flash module with ZigBee BLE concurrent SDK. And it is the same issue.
Now I wonder whether BLE_ZBHCI is going to work if UART ZBHCI doesn't work (for me)?

And that leads me to another question. I have asked the question in Tools forum. How to update SDK to include my old projects? I didn't get any response.
In the past I just copied all proejcts into "app" folder and replaced .project and .cproject files in the build/tlsr_tc32 folder. And it work.
Today I tried this with the latest ZigBee BLE concurrent SDK and it didn't work. I couldn't compile sample gatway project. The problem was with sampleGatewayMultiBLE.c file. I didn't look into this file but it wasn't in the previous SDK.
I had to copy back .project and .cproject files to compile without errors.

So how can I upgrade the SDK?
Cna I use the patch files from the folder "sdk_v2.1.x.x_patch"?
Do I have to add sampleGatewayMultiBLE.c to my existing gateway project?

Thanks again for your help.
And the last test was using the scope to have a look at the packets captured.
Normal 1 packet and responses - see picture 1-pkt.png and 1-pkt.csv
2 packets sent without response after the first one - see picture 2-pkt.png and 2-pkt.csv
3 packets sent without responses between the packets - see picture 3-pkt.png and 3-pkt.csv
What do you think?

1-pkt.png
2-pkt.png
3-pkt.png

packets.7z

1.88 KB, 下载次数: 0

27

主题

121

回帖

447

积分

版主

积分
447
发表于 2024-11-8 10:01:09 | 显示全部楼层

1. My suggestion regarding the concurrent SDK you mentioned is to import your application code onto the new SDK.



2. Excerpted from official spec.

微信截图_20241107141547.png


We are unable to reproduce the issue with the serial port.
Can you use Demo to conduct a comparative verification in your environment?

10

主题

18

回帖

158

积分

注册会员

积分
158
 楼主| 发表于 2024-11-8 12:18:51 | 显示全部楼层
本帖最后由 wes58 于 2024-11-8 13:09 编辑

Re 1
It is fine if you have 1 or 2 projects.
It is not the best option if you have to do it for example 20 times.

2. I had a look at your packet files and you never had a "bad packet".
So I have no idea what is going on.

I can't use the Demo because I can't transer the image to the gateway - yet.

I am currently writing a code for my phone app to do OTA over BLE_ZBHCI. I will see how it goes.

How to reduce OTA image transfer time to the Gateway?
Is it possible to increase the size of the packet sent when transferring firmware to the gateway?

10

主题

18

回帖

158

积分

注册会员

积分
158
 楼主| 发表于 2024-11-10 12:16:30 | 显示全部楼层
本帖最后由 wes58 于 2024-11-13 07:51 编辑

1. Importing application code is not a solution. You need to import build configuration (which is stored in .cproject file, And I don't see how you can do it.

2. I have finished adding OTA image transfer via BLE_ZBHCI to my Android app. I have tried and it works much faster then using UART (which didn't work for me).
It took me less time to do it than I spent on trying to figure out why UART transfer didn't work.

I used ZigBee BLE concurrent Sdk. And of course there were some problems. In the sample app there is a file app_ble2zigbee.c and function zb_ble_hci_cmd_handler() which calls zbhciCmdHandler().
But this function doesn't work for messages that have crc8 byte in them. It took me some time to figure out why I get an error response.

I have triansferred OTA image to the gateway got the last message - 82 12 00 09 99 00 02 A1 F2 00 02 A1 F2 00 AA

I sent "Image Notify" message to the gateway -  55 01 90 00 07 37 02 17 AC 01 1A 03 00 AA
The device sends zcl_ota_queryNextImageReqCmdSend() with
manuCode 0x1141
imageType 0x0201
curFileVer 0x30011001
dstAddr 0x0000
dstEp 0x01
g_otaCtx.simpleDesc->endpoint 0x1a ->device EP

Gateway ZBHCI msg 55 82 00 00 09 C7 02 17 AC 01 1A 00 19 00 F7 AA
55 82 00 00 09 C8 02 17 AC 01 1A 00 19 00 F8 AA
Device never gets call ota_queryNextImageReqHandler()?

The device keeps sending zcl_ota_queryNextImageReqCmdSend() from ota_periodicQueryServerCb()
I don't know what should happen. That's why I asked you for messages for complete OTA upgrade. At least, I could check what am I missing.

On the device there is a callback function but it is never called. I thought that it will process messages?
ota_callBack_t Light_otaCb =
{
    Light_otaProcessMsgHandler,
};

And device is not being updated and I don't get any error messages.
When looking in the code you have to send "Image notify" message because it calls the function zbhci_clusterOTAHandle() -> and cust_ota_start_req(&dstEpInfo,srcEp,&pCmd); -> and zcl_ota_imageNotifyCmdSend(srcEp, dstEpInfo, FALSE, &in);
zcl_ota_imageNotifyCmdSend() has correct information about destination device.

What is a fucntion on the device that receives and processing message from the gateway from zcl_ota_imageNotifyCmdSend(srcEp, dstEpInfo, FALSE, &in)?
Ok, I found out that it is function ota_imageNotifyHandler()
Image
    if(ZB_NWK_IS_ADDRESS_BROADCAST(pAddrInfo->dstAddr)){
        if((pImageNotify->payloadType >= IMAGE_NOTIFY_QUERT_JITTER_MFG)
            && (pImageNotify->manuCode != g_otaCtx.pOtaPreamble->manufacturerCode)){
            return ZCL_STA_SUCCESS;
        }
        if((pImageNotify->payloadType >= IMAGE_NOTIFY_QUERY_JITTER_MFG_TYPE)
            && (pImageNotify->imageType != g_otaCtx.pOtaPreamble->imageType)){
            return ZCL_STA_SUCCESS;
        }
        if((pImageNotify->payloadType >= IMAGE_NOTIFY_QUERY_JITTER_MFG_TYPE_VER)
            && (pImageNotify->newFileVer == zcl_attr_currFileVer)){
            return ZCL_STA_SUCCESS;
        }
        if((zb_random() % 100) > pImageNotify->queryJitter){
           return ZCL_STA_SUCCESS;
        }
   }

From this code I understood that when I sent broadcast address the device sends zcl_ota_queryNextImageReqCmdSend after a preset time.
When I send device network address the device sends zcl_ota_queryNextImageReqCmdSend and receives responsein ota_queryNextImageRspHandler

But what i get is pQueryNextImageRsp->st = ZCL_STA_NO_IMAGE_AVAILABLE?
Here is what is sent by the gateway:
rsp.st = 0x98   <- ZCL_STA_NO_IMAGE_AVAILABLE
rsp.imageType = 0x0201;
rsp.manuCode = 0x1141
rsp.fileVer = 0x30011001
pQueryNextImageReq->curFileVer = 0x30011001
rsp.imageSize 0x02A482
It looks like it fails because file version are the same.
But file version are not the same. Here are the pictures of the files.

image1.png shows the header added to the .bin file by zigbee_ota_tool_v2.2.exe
image2.png show the end of this file which shows the file version.
You can see that file version is 03 not 01. Why?




image2.png
image1.png

10

主题

18

回帖

158

积分

注册会员

积分
158
 楼主| 发表于 2024-11-13 09:09:36 | 显示全部楼层
本帖最后由 wes58 于 2024-11-17 12:03 编辑

The last test.
1 I have manually changed the file version number in the header of the file - at offset 10.
I have tried and changed in the project all: APP_RELEASE, APP_BUILD, STACK_RELEASE and STACK_BUILD but none of the values has changed in the added header. So this doesn't work at all!
- So, this has to be fixed
2 The firmware started to upgrade than stops.
- The only messages received are 8200 and they don't tell me anything.
I have tried a couple of times and it upgrades.
- There is no information from ZBHCI messages are type 8200. It doesn't tell me if upgrade is complete.
The second time I tried, it just stops after 24 8200 type messages.
I tried again and it worked.
Edit:
After doing more testing I found out what the issue could be.
Here is a message received with error 0xE9  5582000009000217AC011A0019E903AA

I think this happens (slows down upgrade, stops) because the gateway was connected to my phone via BLE and the gateway was sending to the phone ZCL_CMD_OTA_IMAGE_BLOCK_REQ message during firwmare transfer to the device. Once I disconnected my phone, the gateway was working fine.
There is no problem when those messages are sent via UART so it is switching between BLE and Zigbee that causes the problem.


If there was a ZBHCI message that the firmware can't be upgraded because the file versions are the same, I wouldn't have wasted 2 days trying to find out how the process works and where the problem is.

10

主题

18

回帖

158

积分

注册会员

积分
158
 楼主| 发表于 6 天前 | 显示全部楼层
And here is the last test I did,
1. I had 2 devices connected to the test gateway.
They were different devices with different GPIO configuration and different function.
Device versions were as follows:
Device #1
APP_RELEASE                                0x10
APP_BUILD                                        0x01
STACK_RELEASE                        0x30
STACK_BUILD                                0x01

Device #2
APP_RELEASE                                0x20
APP_BUILD                                0x02
STACK_RELEASE                        0x30
STACK_BUILD                                0x01

The new Firmware version was:
APP_RELEASE                                0x30
APP_BUILD                                0x04
STACK_RELEASE                        0x30
STACK_BUILD                                0x01
2. I have transferred the new firmware to the gateway.
3. I didn't send ZBHCI_CMD_ZCL_OTA_IMAGE_NOTIFY message to the gateway to update any of the devices.
4. What I noticed was that both devices were automatically updated by the gateway because their version was lower than the new firmware
5. After upgrade
Device #1 was working because the firmware was built based on this device firmware.
Device #2 was not working because it had different configuration of GPIO's and different function from the device #1.

This shouldn't have happened. The gateway shouldn't update both devices without receiving ZBHCI_CMD_ZCL_OTA_IMAGE_NOTIFY
message.
As long as the new firmware version is higher than current firmware the device is updated. There is nothing stopping it.
I believe, that's why you need to send ZBHCI_CMD_ZCL_OTA_IMAGE_NOTIFY message with address and EP of the device that you want to upgrade.

I was lucky that I was doing the tests on the test gateway. If I used my main gateway I would have all my devices (which are different) updated to the firmware of device #1!
And this would be a disaster.

I think that Telink needs to fix the code for OTA so this can''t happen.

10

主题

18

回帖

158

积分

注册会员

积分
158
 楼主| 发表于 4 天前 | 显示全部楼层
本帖最后由 wes58 于 2024-11-22 09:24 编辑

Just to summarize the issues I have found with OTA upgrade of the device - based on posts above

1. There is no ZBHCI messages telling the user that the firmware update (from Gateway to Device) has started, what is the progress of update and when it finished, or it failed.
2. The file zigbee_ota_tool_v2.2.exe that is used to convert firmware .bin file to the OTA file is not working correctly. The added header is not updated with the information from the firmware .bin file - file version and probably type and manufacturer. That's why firmware update always fails.
3. All devices are upgraded - no matter whether they are the same application firmware - as long as the file version is lower from the new firmware. This can cause big issues.

Edit: I have just noticed that it is the first byte of "Image Type" that can be used of defining what project/app type it is.
I still believe that all devices of the same "Image Type" shouldn't be automatically upgraded without the user sending "Image Notify" message.

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

本版积分规则

Telink forum ( 沪ICP备17008231号-1 )

GMT+8, 2024-11-24 03:23 , Processed in 0.096473 second(s), 19 queries .

Powered by Telink 隐私政策

泰凌微电子版权所有 © 。保留所有权利。 2024

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