-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextra_script.py
More file actions
executable file
·197 lines (183 loc) · 8.29 KB
/
extra_script.py
File metadata and controls
executable file
·197 lines (183 loc) · 8.29 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import time
import hashlib
import shutil
Import("env")
env.Replace(PROGNAME="rnode_firmware_%s" % env.GetProjectOption("custom_variant"))
print("PROGNAME:", env.subst("$PROGNAME"))
#
# Custom targets
#
def target_package(target, source, env):
print("target_package...")
print("Platform:", env.GetProjectOption("platform"))
print("Board:", env.GetProjectOption("board"))
print("Variant:", env.GetProjectOption("custom_variant"))
# do some actions
platform = env.GetProjectOption("platform")
board = env.GetProjectOption("board")
firmware_package(env)
platform = env.GetProjectOption("platform")
print("Platform:", platform)
if (platform == "espressif32"):
env.AddCustomTarget(
name="package",
dependencies="$BUILD_DIR/${PROGNAME}.bin",
actions=[
target_package
],
title="Package",
description="Package esp32 firmware for delivery"
)
elif (platform == "nordicnrf52"):
# remove --specs=nano.specs to allow exceptions to work
if '--specs=nano.specs' in env['LINKFLAGS']:
env['LINKFLAGS'].remove('--specs=nano.specs')
env.AddCustomTarget(
name="package",
dependencies="$BUILD_DIR/${PROGNAME}.zip",
actions=[
target_package
],
title="Package",
description="Package nrf52 firmware for delivery"
)
#
# Upload actions
#
def pre_upload(source, target, env):
print("pre_upload...")
# do some actions
def post_upload(source, target, env):
print("post_upload...")
print("Platform:", env.GetProjectOption("platform"))
print("Board:", env.GetProjectOption("board"))
print("Variant:", env.GetProjectOption("custom_variant"))
print("Serial port:", env.subst("$UPLOAD_PORT"))
# do some actions
platform = env.GetProjectOption("platform")
board = env.GetProjectOption("board")
if (platform == "espressif32"):
time.sleep(10)
# device provisioning is incomplete and only currently appropriate for 915MHz T-Beam
device_provision(env)
firmware_hash(source, env)
# firmware pacakaging is incomplete due to missing console image
#firmware_package(env)
elif (platform == "nordicnrf52"):
time.sleep(5)
# device provisioning is incomplete and only currently appropriate for 915MHz RAK4631
device_provision(env)
firmware_hash(source, env)
# firmware pacakaging is incomplete due to missing console image
#firmware_package(env)
def post_clean(source, target, env):
print("post_clean...")
core_dir = env.subst("$CORE_DIR")
print("core_dir:", core_dir)
packages_dir = env.subst("$PACKAGES_DIR")
print("packages_dir:", packages_dir)
project_dir = env.subst("$PROJECT_DIR")
print("project_dir:", project_dir)
#build_dir = env.subst("$BUILD_DIR").get_abspath()
build_dir = env.subst("$BUILD_DIR")
print("build_dir:", build_dir)
build_cache_dir = env.subst("$PLATFORMIO_BUILD_CACHE_DIR")
print("build_cache_dir:", build_cache_dir)
workspace_dir = env.subst("$PLATFORMIO_WORKSPACE_DIR")
print("workspace_dir:", workspace_dir)
#shutil.rmtree(directory_path)
env.Execute("rm -f " + project_dir + "/Release/" + project_dir + "/" + env.subst("$PROGNAME") + ".zip")
env.AddPreAction("upload", pre_upload)
env.AddPostAction("upload", post_upload)
env.AddPostAction("clean", post_clean)
def device_wipe(env):
# Device wipe
print("Wiping device...")
env.Execute("rnodeconf --eeprom-wipe " + env.subst("$UPLOAD_PORT"))
def device_provision(env):
# Device provision
print("Provisioning device...")
platform = env.GetProjectOption("platform")
print("Platform:", platform)
board = env.GetProjectOption("board")
print("Board:", board)
variant = env.GetProjectOption("custom_variant")
print("Variant:", variant)
if variant in ("tbeam", "tbeam_local"):
env.Execute("rnodeconf --product e0 --model e9 --hwrev 1 --rom " + env.subst("$UPLOAD_PORT"))
elif variant in ("lora32v21", "lora32v21_local"):
env.Execute("rnodeconf --product b1 --model b9 --hwrev 1 --rom " + env.subst("$UPLOAD_PORT"))
elif variant in ("heltec32v4", "heltec32v4_local", "heltec32v4_boundary", "heltec32v4_boundary_local"):
env.Execute("rnodeconf --product b1 --model b9 --hwrev 1 --rom " + env.subst("$UPLOAD_PORT"))
elif variant in ("rak4631", "rak4631_local"):
env.Execute("rnodeconf --product 10 --model 12 --hwrev 1 --rom " + env.subst("$UPLOAD_PORT"))
elif variant in ("heltec_t114", "heltec_t114_local"):
env.Execute("rnodeconf --product c2 --model c7 --hwrev 1 --rom " + env.subst("$UPLOAD_PORT"))
def firmware_hash(source, env):
# Firmware hash
print("Updating firmware hash...")
source_file = source[0].get_abspath()
platform = env.GetProjectOption("platform")
print("Platform:", platform)
if (platform == "nordicnrf52"):
build_dir = env.subst("$BUILD_DIR")
env.Execute("cd " + build_dir + "; unzip -o " + source_file + " " + env.subst("$PROGNAME") + ".bin")
#source_file.replace(".zip", ".bin")
source_file = build_dir + "/" + env.subst("$PROGNAME") + ".bin";
print("source_file:", source_file)
firmware_data = open(source_file, "rb").read()
calc_hash = hashlib.sha256(firmware_data).digest()
hex_hash = calc_hash.hex()
print("firmware_hash:", hex_hash)
env.Execute("rnodeconf --firmware-hash " + hex_hash + " " + env.subst("$UPLOAD_PORT"))
else:
print("source_file:", source_file)
firmware_data = open(source_file, "rb").read()
calc_hash = hashlib.sha256(firmware_data[0:-32]).digest()
part_hash = firmware_data[-32:]
hex_hash = calc_hash.hex()
print("firmware_hash:", hex_hash)
if (calc_hash == part_hash):
env.Execute("rnodeconf --firmware-hash " + hex_hash + " " + env.subst("$UPLOAD_PORT"))
else:
print("Calculated hash does not match!")
def firmware_package(env):
platform = env.GetProjectOption("platform")
board = env.GetProjectOption("board")
# Firmware package
print("Building firmware package...")
platform = env.GetProjectOption("platform")
print("Platform:", platform)
board = env.GetProjectOption("board")
print("Board:", board)
variant = env.GetProjectOption("custom_variant")
print("Variant:", variant)
core_dir = env.subst("$CORE_DIR")
print("core_dir:", core_dir)
packages_dir = env.subst("$PACKAGES_DIR")
print("packages_dir:", packages_dir)
workspace_dir = env.subst("$WORKSPACE_DIR")
print("workspace_dir:", workspace_dir)
project_dir = env.subst("$PROJECT_DIR")
print("project_dir:", project_dir)
#build_dir = env.subst("$BUILD_DIR").get_abspath()
build_dir = env.subst("$BUILD_DIR")
print("build_dir:", build_dir)
if (platform == "espressif32"):
#env.Execute("cp " + packages_dir + "/framework-arduinoespressif32/tools/partitions/boot_app0.bin " + build_dir + "/rnode_firmware_" + variant + ".boot_app0")
env.Execute("cp ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin " + build_dir + "/rnode_firmware_" + variant + ".boot_app0")
env.Execute("cp " + build_dir + "/bootloader.bin " + build_dir + "/" + env.subst("$PROGNAME") + ".bootloader")
env.Execute("cp " + build_dir + "/partitions.bin " + build_dir + "/" + env.subst("$PROGNAME") + ".partitions")
env.Execute("rm -f " + project_dir + "/Release/" + env.subst("$PROGNAME") + ".zip")
zip_cmd = "zip --junk-paths "
zip_cmd += project_dir + "/Release/rnode_firmware_" + variant + ".zip "
zip_cmd += project_dir + "/Release/esptool/esptool.py "
zip_cmd += project_dir + "/Release/console_image.bin "
zip_cmd += build_dir + "/" + env.subst("$PROGNAME") + ".bin "
zip_cmd += build_dir + "/" + env.subst("$PROGNAME") + ".boot_app0 "
zip_cmd += build_dir + "/" + env.subst("$PROGNAME") + ".bootloader "
zip_cmd += build_dir + "/" + env.subst("$PROGNAME") + ".partitions "
env.Execute(zip_cmd)
elif (platform == "nordicnrf52"):
env.Execute("cp " + build_dir + "/" + env.subst("$PROGNAME") + ".zip " + project_dir + "/Release/.")
env.Execute("python " + project_dir + "/release_hashes.py > " + project_dir + "/Release/release.json")