niceboygithub / AqaraM1SM2fw

Aqara Gateway M1S (ZHWG15LM) , P3(KTBL12LM), H1(QBCZWG11LM), M2 (ZHWG12LM) Firmwares
170 stars 30 forks source link

M2 stop on "Downloading the flasher" #45

Closed KFlab closed 2 years ago

KFlab commented 2 years ago

我用的是 2022 04 生产的 M2网关 设备固件是 3.2.4_0013.0520 没有焊线 用手按的杜邦线 开机可以在串口看到回显

固件升级时候红灯常亮 然后等好久软件都没有进度 "Downloading the flasher" 一步 然后进度条读完 后面就没有然后了

是不是因为手按接触不良?我已经买了烧录夹 这两天快递到了我试试

joelliang commented 2 years ago

Please have a test with fix

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher_with_fixed_boot_info/tools/aqaragateway.exe

Still boot_info.sum error

Warn: boot_info.sum error
Info: reset boot_info.

boot_info_and_logs.zip

yuyamin commented 2 years ago

Please have a test with fix

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher_with_fixed_boot_info/tools/aqaragateway.exe

Still boot_info.sum error

Warn: boot_info.sum error
Info: reset boot_info.

boot_info_and_logs.zip

Although it can't start,after flashing the boot_info which u backuped, my gateway start successfully. I tested it with my homeassistant, it worked well.

niceboygithub commented 2 years ago

Please help to have a test with this one.

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher_fixed_again_with_debug/tools/aqaragateway.exe

Also have the logs of flasher. Fix the baudrate of UART in AccessPort to 230400.

joelliang commented 2 years ago

It's exactly the same as https://github.com/niceboygithub/AqaraM1SM2fw/issues/45#issuecomment-1195609863

niceboygithub commented 2 years ago

It's exactly the same as #45 (comment)

Did you log it? Not boot log. I need the logs while flashing. Otherwise it is hard to debug.

joelliang commented 2 years ago
<RealTek>boot_ctrl set_bootinfo 64 0xfff6
Unknown command or error format: [set_bootinfo]

flashing_logs.txt

niceboygithub commented 2 years ago
<RealTek>boot_ctrl set_bootinfo 64 0xfff6
Unknown command or error format: [set_bootinfo]

flashing_logs.txt

This log is that you try to flash boot_info by AqaraGateway. This function is not supported. I need the logs that flashing rootfs.

joelliang commented 2 years ago

Here it's flashing_rootfs_logs.txt

niceboygithub commented 2 years ago

There is no problem on checksum. Did you flash other kernel, or boot_info after flashed rootfs?

joelliang commented 2 years ago

The rootfs I flashed into rootfs_0 is the same as the one already in the SPI flash. So, the size and check sum should be the same.

<RealTek>boot_ctrl set_rootfs0 9754628 0xd23b
Setting rootfs 0 size: 9754628 -> 9754628
Setting rootfs 0 checksum: 3bd23b -> 0xd23b

But you changed the checksum from 3bd23b to 0xd23b. Are you using int16 to store a int32 data?

niceboygithub commented 2 years ago

The rootfs I flashed into rootfs_0 is the same as the one already in the SPI flash. So, the size and check sum should be the same.

<RealTek>boot_ctrl set_rootfs0 9754628 0xd23b
Setting rootfs 0 size: 9754628 -> 9754628
Setting rootfs 0 checksum: 3bd23b -> 0xd23b

But you changed the checksum from 3bd23b to 0xd23b. Are you using int16 to store a int32 data?

I think that it is just display problem I saw the problem

While boot_ctrl set_rootfs0 9754628 0xd23b The boot_info is

7c ffffff91 00 00 7d ffffffd2 01 00 01 00 00 22 14 04 ffffff80 fffffff2 00 00 22 14 04 ffffff81 53 00 00 ffffff94 ffffffd8 04 ffffffd2 3b 00 00 ffffff94 fffffff0 04 ffffffc8 0f 00 00 00 01 31 2e 30 2e 30 5f 30 30 30 31 00 00 00 00

The checksum is '7d d2' (ignore ffffff)

Next command is 'Setting newest rootfs: 0 -> 0' The boot_info is

7c ffffff91 00 00 7d 32 01 00 01 00 00 22 14 04 ffffff80 fffffff2 00 00 22 14 04 ffffff81 53 00 00 ffffff94 ffffffd8 04 ffffffd2 3b 00 00 ffffff94 fffffff0 04 ffffffc8 0f 00 00 00 01 31 2e 30 2e 30 5f 30 30 30 31 00 00 00 00

The checksum is '7d 32' and it is wrong.

joelliang commented 2 years ago

There is no problem on checksum. Did you flash other kernel, or boot_info after flashed rootfs?

I did flash 3.4.4 kernel to linux_0, and I'm not using the commands you told me at https://github.com/niceboygithub/AqaraM1SM2fw/issues/45#issuecomment-1194983567

Is that the problem?

Should I flash both kernel and rootfs again?

joelliang commented 2 years ago

I think Setting newest rootfs: 0 -> 0 should not change the check sum. Is that a bug in boot_ctrl?

niceboygithub commented 2 years ago

I think Setting newest rootfs: 0 -> 0 should not change the check sum. Is that a bug in boot_ctrl?

Before update flasher, there is no problem on the checksum of boot_info.

Let me check the bug.

niceboygithub commented 2 years ago

I update new AqaraGateway. Can you help to test?

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher_fixed_again_with_debug/tools/aqaragateway.exe
yuyamin commented 2 years ago

I update new AqaraGateway. Can you help to test?

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher_fixed_again_with_debug/tools/aqaragateway.exe

i'll test today

joelliang commented 2 years ago

I update new AqaraGateway. Can you help to test?

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher_fixed_again_with_debug/tools/aqaragateway.exe

The boot_info check sum still not correct.

Also, I could not use the updated EXE to flash my previously backuped boot_info.bin It will prints out this error message:

Unknow or unsupported firmware type!

flashing_rootfs_0.txt

KFlab commented 2 years ago

I notice there's new version of M1S ( NOT M1S 2022) is [zhwg15lm] And M1S 2022 productioned.

niceboygithub commented 2 years ago

I update new AqaraGateway. Can you help to test?

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher_fixed_again_with_debug/tools/aqaragateway.exe

The boot_info check sum still not correct.

Also, I could not use the updated EXE to flash my previously backuped boot_info.bin It will prints out this error message:

Unknow or unsupported firmware type!

Yes, I removed this feature on flash boot_info.

flashing_rootfs_0.txt

it is really strange.

niceboygithub commented 2 years ago

I notice there's new version of M1S ( NOT M1S 2022) is [zhwg15lm] And M1S 2022 productioned.

That's mean that ZHWG15LM was probably changed to use new SPI NAND flash. M1S can use soft_hack to enable telnet then use m1s_update to flash cfw without problems.

yuyamin commented 2 years ago

I update new AqaraGateway. Can you help to test?

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher_fixed_again_with_debug/tools/aqaragateway.exe

The boot_info check sum still not correct.

Also, I could not use the updated EXE to flash my previously backuped boot_info.bin It will prints out this error message:

Unknow or unsupported firmware type!

flashing_rootfs_0.txt

let me sum up the situation now: 1.The latest version of AqaraGateway.exe could clash the modified firmware. 2.After finishing flash, the gateway wouldn't start. 3.Then flashing the boot_info(use the previous version AqaraGateway.exe), the M2 could start?

yuyamin commented 2 years ago

我注意到有新版本的 M1S(不是 M1S 2022)是 [zhwg15lm] 和 M1S 2022 生产的。

这意味着 ZHWG15LM 可能已更改为使用新的 SPI NAND 闪存。 M1S 可以使用 soft_hack 启用 telnet,然后使用 m1s_update 刷新 cfw 没有问题。

if it's possible I could mail u a M2 gateway

joelliang commented 2 years ago

Not a good idea to manipulate the check sum like this: https://github.com/niceboygithub/AqaraM1SM2fw/blob/f91da7cf80b96973d5aa362816f20196a8086ac1/binutils/src/boot_ctrl/boot_ctrl.c#L266

You should always use calcuate_checksum to recalculate the check sum. You could define a union like this:

typedef union BOOT_INFO {
    struct {
        uint16_t magic;
        uint16_t vernum;
        uint16_t check_sum;
        ...
    };
    unsigned char buffer[SIZE_BOOT_INFO];
} boot_info_t;

And then

// Change fields in the boot_info_t
info.rootfs_newest = 1;
// Recalculate the check sum
info.checksum = calcuate_checksum(info.buffer);
niceboygithub commented 2 years ago

Not a good idea to manipulate the check sum like this:

https://github.com/niceboygithub/AqaraM1SM2fw/blob/f91da7cf80b96973d5aa362816f20196a8086ac1/binutils/src/boot_ctrl/boot_ctrl.c#L266

You should always use calcuate_checksum to recalculate the check sum. You could define a union like this:

typedef union BOOT_INFO {
    struct {
        uint16_t magic;
        uint16_t vernum;
        uint16_t check_sum;
        ...
    };
    unsigned char buffer[SIZE_BOOT_INFO];
} boot_info_t;

And then

// Change fields in the boot_info_t
info.rootfs_newest = 1;
// Recalculate the check sum
info.checksum = calcuate_checksum(info.buffer);

Thx for your info. But these are old codes.

niceboygithub commented 2 years ago

我注意到有新版本的 M1S(不是 M1S 2022)是 [zhwg15lm] 和 M1S 2022 生产的。

这意味着 ZHWG15LM 可能已更改为使用新的 SPI NAND 闪存。 M1S 可以使用 soft_hack 启用 telnet,然后使用 m1s_update 刷新 cfw 没有问题。

if it's possible I could mail u a M2 gateway

Thanks. I prefer to get M2 2022 to develop. I will try to get old M2 here to debug.

By the way, I am in vacation and will be slow response.

joelliang commented 2 years ago

Thx for your info. But these are old codes.

The same logic should apply to your latest code. If we never manipulate the check sum like that. And always recalculate the check sum before writing to the SPI flash. We should not have any check sum problems.

Or, could you upload your latest code somewhere? I could help you debug the issue.

yuyamin commented 2 years ago

我注意到有新版本的 M1S(不是 M1S 2022)是 [zhwg15lm] 和 M1S 2022 生产的。

这意味着 ZHWG15LM 可能已更改为使用新的 SPI NAND 闪存。 M1S 可以使用 soft_hack 启用 telnet,然后使用 m1s_update 刷新 cfw 没有问题。

if it's possible I could mail u a M2 gateway

Thanks. I prefer to get M2 2022 to develop. I will try to get old M2 here to debug.

By the way, I am in vacation and will be slow response.

I mean the m2(ZHWG17LM)2022 gateway. After ur vacation, just give me an address.

KFlab commented 2 years ago

new tool still not work for me . I find that my USB to UART bridge is using CP210x chip not common ch340 chip

I hope to hear that which chipset you guys use untitle.txt

KFlab commented 2 years ago

new tool still not work for me . I find that my USB to UART bridge is using CP210x chip not common ch340 chip

I hope to hear that which chipset you guys use untitle.txt

OK I fand the problem ... my USB to UART devise not support over 2M baud :( I buy a new one :(

joelliang commented 2 years ago

My USB to UART board is using FT232R chipset.

With the new USB to UART, you could continue after "Downloading the flasher". And you could flash the CFW(Customized Firmware). But, it will hit the bootinfo check sum error problem. And then, you could not boot your M2.

We still working on the bootinfo check sum error issue.

yuyamin commented 2 years ago

My USB to UART board is using FT232R chipset.

With the new USB to UART, you could continue after "Downloading the flasher". And you could flash the CFW(Customized Firmware). But, it will hit the bootinfo check sum error problem. And then, you could not boot your M2.

We still working on the bootinfo check sum error issue.

OK. Waiting for solving. Now, i could flash the boot_info u uploaded and the gateway runs properly for now.

KFlab commented 2 years ago

ok check sum error on me ReceivedTofile-COM4-2022_8_1_11-31-30.log

KFlab commented 2 years ago

flash.txt flashing logs here

niceboygithub commented 2 years ago

This one shall solve the boot_info problem.

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher/tools/aqaragateway.exe
joelliang commented 2 years ago

This one shall solve the boot_info problem.

https://github.com/niceboygithub/AqaraM1SM2fw/blob/new_flasher/tools/aqaragateway.exe

Yes, it works. Thanks

niceboygithub commented 2 years ago

Merged to main.