hn / ginlong-solis

Solis inverter ESP8266 data logger, S3 WiFi stick reverse engineering and ESPhome firmware
75 stars 13 forks source link

Problems with flashing wifi stick (data transfer issues?) #23

Closed ErwinP closed 4 months ago

ErwinP commented 4 months ago

Hi all,

I'm quite used to flashing devices using UART (mostly shelly plugs and sonoff switches) but this wifi stick is giving me more problems that I anticipated :-/

I had the same as user Belaial (from the image here) and I can confirm what kuba2k2 mentioned here: these adapters are apparently not strong enough for the required baudrate. I bought a new one, based on the FT232 and only with that adapter was able to communicate in the download mode, using ltchiptool-v4.10.2.

I compiled the firmware using esphome on my other computer, and tried to flash the firmware.uf2 using the Windows version. However, during upload, I get the following errors:

I: Found new device: COM7 - USB Serial Port - FTDI (0403/6001)
I: Transmission successful (ACK received).
I: Transmission successful (ACK received).
E: send error: expected ACK; got b'\x15' for block 2
E: send error: expected ACK; got b'\x15' for block 2
E: send error: expected ACK; got b'\x15' for block 19
E: send error: expected ACK; got b'\x15' for block 19
E: send error: expected ACK; got b'\x15' for block 23
E: send error: expected ACK; got b'\x15' for block 23
...
E: send error: expected ACK; got b'\x15' for block 168
E: send error: expected ACK; got b'\x15' for block 168
I: Transmission successful (ACK received).
I: Transmission successful (ACK received).
I: Transmission successful (ACK received).
I: Transmission successful (ACK received).

I'm not quite sure what these write errors have as a consequence, but I've tried it multiple times and I think the amount of errors differs between some runs. When I read out the terminal during normal boot, it always reboots during the scanning of the wifi:

<RTL8195A>ROM:[V0.1]
FLASHRATE:4
BOOT TYPE:0 XTAL:40000000
IMG1 DATA[1128:10002000]
IMG1 ENTRY[800053d:100021ef]
IMG1 ENTER
CHIPID[000000ff]
read_mode idx:0, flash_speed idx:0
calibration_result:[1:0:0][ff:ff] 
calibration_result:[2:0:0][ff:ff] 
calibration_result:[3:0:0][ff:ff] 

FLASH Calibration Fail!!!
Please set proper flash speed and read mode in SYSTEM DATA!!!

OTA2 ADDR[8100000]
OTAx SELE[ffffffff]
OTA1 USE
IMG2 DATA[0x80b40d0:4520:0x10005000]
IMG2 SIGN[RTKWin(10005008)]
IMG2 ENTRY[0x10005000:0x8041eb1]
BOOT_FLASH_RDP RDP enable 
SYSTEM.bin RDP Empty.
System_Init1
System_Init2
I [      0.000] LibreTiny v1.5.0 on generic-rtl8710bx-4mb-980k, compiled at Feb 29 2024 05:55:03, GCC 10.3.1 (-Os)
[I][logger:395]: Log initialized
[C][ota:473]: There have been 9 suspected unsuccessful boot attempts.
[D][lt.preferences:104]: Saving 1 preferences to flash...
[D][lt.preferences:132]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[C][uart.lt:049]: Setting up UART...
[C][switch.gpio:011]: Setting up GPIO Switch 'led_orange_com'...
[D][switch:016]: 'led_orange_com' Turning OFF.
[D][switch:055]: 'led_orange_com': Sending state OFF
[D][switch:016]: 'led_orange_com' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'led_green_net'...
[D][switch:016]: 'led_green_net' Turning OFF.
[D][switch:055]: 'led_green_net': Sending state OFF
[D][switch:016]: 'led_green_net' Turning OFF.
[C][switch.gpio:011]: Setting up GPIO Switch 'wdt_reset'...
[D][switch:016]: 'wdt_reset' Turning OFF.
[D][switch:055]: 'wdt_reset': Sending state OFF
[D][switch:016]: 'wdt_reset' Turning OFF.
[D][binary_sensor:034]: 'button_reset': Sending initial state OFF
[C][wifi:038]: Setting up WiFi...
[C][wifi:051]: Starting WiFi...
[C][wifi:052]:   Local MAC: D0:BA:E4:88:8E:EC
interface 0 is initialized
interface 1 is initialized

Initializing WIFI ...
WIFI initialized
[D][wifi:455]: Starting scan...
<RTL8195A>ROM:[V0.1]
FLASHRATE:4
BOOT TYPE:0 XTAL:40000000
IMG1 DATA[1128:10002000]
IMG1 ENTRY[800053d:100021ef]
IMG1 ENTER
CHIPID[000000ff]
read_mode idx:0, flash_speed idx:0
calibration_result:[1:0:0][ff:ff] 
calibration_result:[2:0:0][ff:ff] 
calibration_result:[3:0:0][ff:ff] 

FLASH Calibration Fail!!!
Please set proper flash speed and read mode in SYSTEM DATA!!!

OTA2 ADDR[8100000]
OTAx SELE[ffffffff]
OTA1 USE
IMG2 DATA[0x80b40d0:4520:0x10005000]
IMG2 SIGN[RTKWin(10005008)]
IMG2 ENTRY[0x10005000:0x8041eb1]
BOOT_FLASH_RDP RDP enable 
SYSTEM.bin RDP Empty.
System_Init1
System_Init2
I [      0.000] LibreTiny v1.5.0 on generic-rtl8710bx-4mb-980k, compiled at Feb 29 2024 05:55:03, GCC 10.3.1 (-Os)
[I][logger:395]: Log initialized
[C][ota:473]: There have been 10 suspected unsuccessful boot attempts.
[D][lt.preferences:104]: Saving 1 preferences to flash...
[D][lt.preferences:132]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[E][ota:480]: Boot loop detected. Proceeding to safe mode.
[I][app:029]: Running through setup()...
[C][wifi:038]: Setting up WiFi...
[C][wifi:051]: Starting WiFi...
[C][wifi:052]:   Local MAC: D0:BA:E4:88:8E:EC
interface 0 is initialized
interface 1 is initialized

Initializing WIFI ...
WIFI initialized
[D][wifi:455]: Starting scan...
<RTL8195A>ROM:[V0.1]
FLASHRATE:4
BOOT TYPE:0 XTAL:40000000

I think there is a problem during data transfer, but I've already tried 2 different set of cables, including the one that came with the adapter. Can anyone recommend cables? Or is there an other issue at play?

Thanks in advance, Erwin

hn commented 4 months ago

I think ltchiptool does a final check of the written data (-c Check hash/CRC of the written data (default: True)) and therefore it should warn you if things have gone horribly wrong.

Your WiFi problem is https://github.com/hn/ginlong-solis/issues/22 which @kuba2k2 fortunately fixed just today with LT 1.5.1: https://github.com/libretiny-eu/libretiny/issues/257 . If your environment does not update to the latest version automatically you can force it with

rtl87xx:
  board: generic-rtl8710bx-4mb-980k
  framework:
    version: 1.5.1

If you hurry up, you may be the first person on earth to use this version on an EMW3080 :)

ErwinP commented 4 months ago

Bingo! It seems like I've beaten Belaial on being the first (reported) user that confirms the fix. Now I'm having an error when my network SSID is hidden, which seems to be reported already here. But that is out of your control ;)

I can't say it enough: thank you!!

Belaial commented 4 months ago

Damn it! I wanted to be the first :smile: Am I reading this right? There is no known issue with OTA updates? This was just a serial-adapter issue as I understand it. (just woke up so sorry if I missed something....)

ErwinP commented 4 months ago

I thought that the error was a consequence of a flakey connection, but it appeared to be an issue with the board definition itself, which caused it to crash after scanning for wifi. I was able to recompile the firmware and it now worked, but I still flashed it manually.

If your issue was related to esphome compiling a faulty firmware and pushing it to your device OTA, then the issue is resolved (because technically, the OTA update mechanism wasn't broken but your device wasn't able to come online anymore). However, if the issue was truly the OTA feature, then most likely it is still broken. But at this moment I lack time (and bravery) to test it :)

Belaial commented 4 months ago

Tested this morning, OTA worked just fine after the edit suggested here https://github.com/hn/ginlong-solis/issues/23#issuecomment-1972006075

I assume I at least claimed world second running this on EMW3080 :2nd_place_medal: