forked from HASwitchPlate/openHASP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_partitions.py
69 lines (50 loc) · 2.18 KB
/
copy_partitions.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
59
60
61
62
63
64
65
66
67
68
69
#This script is based on the Tasmota rename-firmware.py script. https://github.com/arendst/Tasmota
Import('env')
import os
import shutil
buildFlags = env.ParseFlags(env['BUILD_FLAGS'])
OUTPUT_DIR = "build_output{}".format(os.path.sep)
platform = env.PioPlatform()
FRAMEWORK_DIR = platform.get_package_dir("framework-arduinoespressif32")
FRAMEWORK_DIR = "{}{}".format(FRAMEWORK_DIR, os.path.sep)
def copy_boot_partitions(source, target, env):
# check if output directories exist and create if necessary
if not os.path.isdir(OUTPUT_DIR):
os.mkdir(OUTPUT_DIR)
for d in ['firmware', 'map']:
if not os.path.isdir("{}{}".format(OUTPUT_DIR, d)):
os.mkdir("{}{}".format(OUTPUT_DIR, d))
# create string with location and file names based on variant
src = str(target[0])
dst = "{}firmware{}{}".format(OUTPUT_DIR, os.path.sep, "partitions.bin")
print(src)
print(dst)
# check if new target files exist and remove if necessary
for f in [dst]:
if os.path.isfile(f):
os.remove(f)
# copy firmware.bin to firmware/<variant>.bin
shutil.copy(src,dst)
# create string with location and file names based on variant
src = "{}tools{}partitions{}boot_app0.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, os.path.sep)
dst = "{}firmware{}{}".format(OUTPUT_DIR, os.path.sep, "boot_app0.bin")
print(src)
print(dst)
# check if new target files exist and remove if necessary
for f in [dst]:
if os.path.isfile(f):
os.remove(f)
# copy firmware.bin to firmware/<variant>.bin
shutil.copy(src,dst)
# create string with location and file names based on variant
src = "{}tools{}sdk{}bin{}bootloader_dio_40m.bin".format(FRAMEWORK_DIR, os.path.sep, os.path.sep, os.path.sep, os.path.sep)
dst = "{}firmware{}{}".format(OUTPUT_DIR, os.path.sep, "bootloader_dio_40m.bin")
print(src)
print(dst)
# check if new target files exist and remove if necessary
for f in [dst]:
if os.path.isfile(f):
os.remove(f)
# copy firmware.bin to firmware/<variant>.bin
shutil.copy(src,dst)
env.AddPostAction("$BUILD_DIR/partitions.bin", [copy_boot_partitions])