Skip to content

Commit 2325713

Browse files
authored
Fix some issues with board index generator script (#42)
* [skip changelog] Fix some issues generator board index * [skip changelog] Fixed paths in generator script
1 parent 023d916 commit 2325713

File tree

2 files changed

+161
-148
lines changed

2 files changed

+161
-148
lines changed

Diff for: generator/generator.py

+33-20
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def split_property_and_drop_first_level(s):
3838

3939
# Generate and copy loader Sketch binary data for specified board
4040
def create_loader_data(simple_fqbn, binary):
41-
loader_path = f"firmwares/loader/{simple_fqbn}/loader.bin"
41+
loader_path = f"firmwares/loader/{simple_fqbn}/loader{binary.suffix}"
4242
loader = Path(__file__).parent / loader_path
4343
loader.parent.mkdir(parents=True, exist_ok=True)
4444
shutil.copyfile(binary, loader)
@@ -79,7 +79,7 @@ def get_uploader_id(tools, tool_executable):
7979
return f"{packager}:{name}@{version}"
8080

8181

82-
def create_upload_data(fqbn, installed_cores):
82+
def create_upload_data(fqbn, installed_cores): # noqa: C901
8383
upload_data = {}
8484
# Assume we're on Linux
8585
arduino15 = Path.home() / ".arduino15"
@@ -90,16 +90,14 @@ def create_upload_data(fqbn, installed_cores):
9090
# Get the core install dir
9191
core = installed_cores[core_id]
9292
(maintainer, arch) = core_id.split(":")
93-
core_install_dir = (
94-
arduino15 / "packages" / maintainer / "hardware" / arch / core["installed"]
95-
)
93+
core_install_dir = arduino15 / "packages" / maintainer / "hardware" / arch / core["installed"]
9694

9795
with open(core_install_dir / "boards.txt") as f:
9896
boards_txt = f.readlines()
9997

10098
board_upload_data = {}
10199
for line in boards_txt:
102-
if line.startswith(f"{board_id}.upload"):
100+
if line.startswith(f"{board_id}."):
103101
(k, v) = split_property_and_drop_first_level(line)
104102
board_upload_data[k] = v
105103

@@ -110,7 +108,7 @@ def create_upload_data(fqbn, installed_cores):
110108

111109
platform_upload_data = {}
112110
for line in platform_txt:
113-
if line.startswith(f"tools.{tool}"):
111+
if line.startswith(f"tools.{tool}."):
114112
(k, v) = split_property_and_drop_first_level(line)
115113
platform_upload_data[k] = v
116114

@@ -129,12 +127,11 @@ def create_upload_data(fqbn, installed_cores):
129127
tools = installed_json_data["packages"][0]["platforms"][0]["toolsDependencies"]
130128
upload_data["uploader"] = get_uploader_id(tools, tool_executable)
131129

132-
# We already store the tool name in a different manner
133-
del board_upload_data["upload.tool"]
134-
# Save also all the upload properties
135-
for k, v in board_upload_data.items():
136-
if v:
137-
upload_data[k] = v
130+
if "upload.use_1200bps_touch" in board_upload_data:
131+
upload_data["upload.use_1200bps_touch"] = board_upload_data["upload.use_1200bps_touch"]
132+
133+
if "upload.wait_for_upload_port" in board_upload_data:
134+
upload_data["upload.wait_for_upload_port"] = board_upload_data["upload.wait_for_upload_port"]
138135

139136
# Get the command used to upload and modifies it a bit
140137
command = (
@@ -145,6 +142,26 @@ def create_upload_data(fqbn, installed_cores):
145142
.replace('\\"', "")
146143
)
147144

145+
if fqbn == "arduino:megaavr:uno2018":
146+
# Long story short if we don't do this we'd have to host also the bootloader
147+
# for the Uno WiFi rev2 and we don't want to, so we just remove this field
148+
# and use a precompiled Loader Sketh binary that includes the bootloader.
149+
command = command.replace("{upload.extra_files}", "")
150+
151+
# Get the rest of the params
152+
params = {}
153+
for k, v in platform_upload_data.items():
154+
if f"{tool}.upload.params." in k:
155+
param = k.split(".")[-1]
156+
params[f"upload.{param}"] = v
157+
elif f"{tool}.upload." in k:
158+
k = ".".join(k.split(".")[1:])
159+
params[k] = v
160+
161+
# Prepare the command
162+
for k, v in {**board_upload_data, **params}.items():
163+
command = command.replace(f"{{{k}}}", v)
164+
148165
upload_data["uploader.command"] = command
149166

150167
return upload_data
@@ -174,9 +191,7 @@ def generate_boards_json(input_data, arduino_cli_path):
174191
}
175192

176193
# Gets the installed cores
177-
res = arduino_cli(
178-
cli_path=arduino_cli_path, args=["core", "list", "--format", "json"]
179-
)
194+
res = arduino_cli(cli_path=arduino_cli_path, args=["core", "list", "--format", "json"])
180195
installed_cores = {c["id"]: c for c in json.loads(res)}
181196

182197
# Verify all necessary cores are installed
@@ -193,15 +208,13 @@ def generate_boards_json(input_data, arduino_cli_path):
193208

194209
for _, v in data.items():
195210
item = v[0]
196-
binary = Path(item["Path"])
211+
binary = Path(__file__).parent / ".." / item["Path"]
197212

198213
if item["IsLoader"]:
199214
boards[fqbn]["loader_sketch"] = create_loader_data(simple_fqbn, binary)
200215
else:
201216
module, version = item["version"].split("/")
202-
boards[fqbn]["firmware"].append(
203-
create_firmware_data(binary, module, version)
204-
)
217+
boards[fqbn]["firmware"].append(create_firmware_data(binary, module, version))
205218
boards[fqbn]["module"] = module
206219

207220
res = arduino_cli(

0 commit comments

Comments
 (0)