-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupdate_bootloader.py
43 lines (35 loc) · 1.21 KB
/
update_bootloader.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
import os
import shutil
import urllib.request
import zipfile
# Get all variants
all_variant = []
for entry in os.scandir("variants"):
if entry.is_dir():
all_variant.append(entry.name)
all_variant.sort()
# Detect version in platform.txt
version = '';
with open('platform.txt') as pf:
platform_txt = pf.read()
e = '{build.variant}_bootloader-'
v1 = platform_txt.index(e) + len(e)
v2 = platform_txt.index('_', v1)
version = platform_txt[v1:v2]
print('version {}'.format(version))
for variant in all_variant:
# Download from bootloader release
name = '{}_bootloader-{}.zip'.format(variant, version)
url = 'https://github.com/adafruit/Adafruit_nRF52_Bootloader/releases/download/{}/{}'.format(version, name)
print("Downloading", name)
urllib.request.urlretrieve(url, name)
# remove existing bootloader
shutil.rmtree('bootloader/{}'.format(variant), ignore_errors=True)
# unzip
with zipfile.ZipFile(name, "r") as zip_ref:
zip_ref.extractall("bootloader/{}".format(variant))
# Remove update.uf2 for 832
if variant == 'feather_nrf52832':
os.remove("bootloader/{}/update-{}_nosd.uf2".format(variant, name[:-4]))
# remove zip file
os.remove(name)