Skip to content

Instantly share code, notes, and snippets.

@dreamcat4
Created May 14, 2020 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreamcat4/de84d48b8ee18b53d12cefe0ce827814 to your computer and use it in GitHub Desktop.
Save dreamcat4/de84d48b8ee18b53d12cefe0ce827814 to your computer and use it in GitHub Desktop.
espurna - Tuya dimmer. First connection and dump OFW
# read chip
sudo esptool.py --port /dev/ttyUSB0 chip_id
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 2c:f4:32:3d:15:4b
Uploading stub...
Running stub...
Stub running...
Chip ID: 0x003d154b
Hard resetting via RTS pin...
θ79° [id:~/.dev/tuya-dimmer] $
θ84° [id:~/.dev/tuya-dimmer] $
θ80° [id:~/.dev/tuya-dimmer] $
# read flash
$ sudo esptool.py --port /dev/ttyUSB0 flash_id
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 2c:f4:32:3d:15:4b
Uploading stub...
Running stub...
Stub running...
Manufacturer: c8
Device: 4015
Detected flash size: 2MB
Hard resetting via RTS pin...
[id:~/.dev/tuya-dimmer] $
# dump the first 2MB of flash to a file
$ sudo esptool.py -p /dev/ttyUSB0 read_flash 0 0x200000 dreamcat4-tuya-dimmer-ofw.bin
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 2c:f4:32:3d:15:4b
Uploading stub...
Running stub...
Stub running...
2097152 (100 %)
2097152 (100 %)
Read 2097152 bytes at 0x0 in 189.9 seconds (88.4 kbit/s)...
Hard resetting via RTS pin...
θ61° [id:~/.dev/tuya-dimmer] $
@dreamcat4
Copy link
Author

Flashing instructions here:

xoseperez/espurna#1729 (comment)

Hey the image size and md5sum of the dumped firmware were different from the one which @davebuk had previously uploaded.

[id:~/.dev/tuya-dimmer/ofw] $ ls -ls
total 4104
1024 -rw-rw-r-- 1 id   id   1048576 Jun  3  2019 davebuk-flash_contents.1mb.bin
1024 -rw-rw-r-- 1 id   id   1048576 May 14 15:07 dreamcat4-tuya-dimmer-ofw.1mb.bin
2048 -rw-r--r-- 1 root root 2097152 May 14 15:04 dreamcat4-tuya-dimmer-ofw.2mb.bin

θ63° [id:~/.dev/tuya-dimmer/ofw] $ md5sum *
abb658f8cdbac28865b4a7d140ce52cb  davebuk-flash_contents.1mb.bin
1f016c439450b959cd2d65a22e3b8dc8  dreamcat4-tuya-dimmer-ofw.1mb.bin
b172159ab527cac0baa02befea3cfc7a  dreamcat4-tuya-dimmer-ofw.2mb.bin
[id:~/.dev/tuya-dimmer/ofw] $ 

@dreamcat4
Copy link
Author

cannot verify flash in esptool

$ sudo esptool.py --baud 19200 --after no_reset --port /dev/ttyUSB0 verify_flash 0 ofw/dreamcat4-tuya-dimmer-ofw.2mb.dump2.bin 
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 2c:f4:32:3d:15:4b
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 2MB
Flash params set to 0x0030
Verifying 0x200000 (2097152) bytes @ 0x00000000 in flash against ofw/dreamcat4-tuya-dimmer-ofw.2mb.dump2.bin...
-- verify FAILED (digest mismatch)

A fatal error occurred: Verify failed.
θ60° [id:~/.dev/tuya-dimmer] 2 $ 

@mcspr
Copy link

mcspr commented May 14, 2020

Verifying 0x200000 (2097152) bytes @ 0x00000000 in flash against ofw/dreamcat4-tuya-dimmer-ofw.2mb.dump2.bin...

Aah. It is a full dump! I completely forgot about that.
SDK might change last 16kb at runtime (at random, it writes all sorts of stuff there). Everything before that should match? I'd guess the truncate existing file should help

@dreamcat4
Copy link
Author

Thanks... unfortunately I never got around to trying that out. But maybe for the next time I come across this error message. Although that is a totally different hardware (so maybe it will not appear next time).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment