forked from emporia-vue-local/emporia-vue2-reversing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_nvs.py
58 lines (47 loc) · 1.66 KB
/
update_nvs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import base64
import json
import subprocess
import sys
import tempfile
import nvsjson2csv
ESPTOOL_PARAMS = ["esptool.py", "--port", "/dev/ttyUSB1", "--chip", "esp32", "-b",
"921600"]
def main(args):
dump_nvs = subprocess.run([
"python3", "esp32_image_parser/esp32_image_parser.py", "dump_nvs",
args[1],
"-partition", "nvs",
"-nvs_output_type", "json"
], capture_output=True, text=True)
nvs_pages = nvsjson2csv.load_nvsjson(json.loads(dump_nvs.stdout))
nvs_entries = nvsjson2csv.get_entries(nvs_pages)
nvs_entries = nvsjson2csv.set_entry(nvsjson2csv.Entry(
ns_name="storage",
key="ssid",
typ="BLOB_DATA",
data=base64.b64encode(b'NEW_SSID').decode(),
), nvs_entries)
nvs_entries = nvsjson2csv.set_entry(nvsjson2csv.Entry(
ns_name="storage",
key="password",
typ="BLOB_DATA",
data=base64.b64encode(b'NEW_PASSWORD').decode(),
), nvs_entries)
with tempfile.NamedTemporaryFile(mode='wt') as csv_file, \
tempfile.NamedTemporaryFile(mode='wb', suffix='.bin') as bin_file:
nvsjson2csv.nvsjson_to_csv(nvs_entries, csv_file)
csv_file.flush()
subprocess.run([
"python3", "nvs_partition_gen.py", "generate",
csv_file.name, bin_file.name,
str(327680),
])
subprocess.run(ESPTOOL_PARAMS + [
"erase_region", str(0x9000), str(327680),
])
input("Reset ESP32 & press Enter to continue...")
subprocess.run(ESPTOOL_PARAMS + [
"write_flash", str(0x9000), bin_file.name,
])
if __name__ == '__main__':
main(sys.argv)