Skip to content

Commit f6e4bcc

Browse files
committed
Allow mpconfigboard.mk to set board extensions
Looking at the PR to add Beetle esp32 c3 (adafruit#6615) I noticed that any microcontroller of this type would require modifying build_board_info, which in turn causes a build of all boards. The same would be true of esp32 boards, of which we hope a large number will be submitted soon. Instead, create two different ways for an mpconfigboard.mk file to override the default setting by port: For espressif, use the existing IDF_TARGET variable. For the general case, allow the EXTENSIONS variable to be specified. Note that the value cannot come from mpconfigport.mk and cannot be conditional. This condition could be lifted in the future if it is useful. Additionally, if IDF_TARGET and EXTENSIONS both exist, the one that appears FIRST in the mpconfigboard.mk file is used, which is a bit tricky. I ran "DEBUG=x RELEASE_TAG=x build_board_info.py > foo.json" before and after to generate a copy of the release info. When diffing them, there is no difference (as expected). I also used a new quick debug facility just for checking extensions, "build_board_info.py espressif:adafruit_feather_esp32s2", to spot check that the code was working as expected, since running the full "build_board_info" process is time consuming. The remaining special cases in "extension_by_board" should be moved to the correct mpconfigport.mk files and the whole facility of "extension by board" should be removed from build_board_info.py.
1 parent c105ec9 commit f6e4bcc

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

ports/nrf/boards/microbit_v2/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ INTERNAL_FLASH_FILESYSTEM = 1
77

88
# USB pins aren't used.
99
CIRCUITPY_USB = 0
10+
11+
EXTENSIONS = combined.hex

tools/build_board_info.py

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import json
88
import os
9+
import pathlib
10+
import re
911
import subprocess
1012
import sys
1113
import sh
@@ -66,27 +68,38 @@
6668
"pca10056": BIN_UF2,
6769
"pca10059": BIN_UF2,
6870
"electronut_labs_blip": HEX,
69-
"microbit_v2": COMBINED_HEX,
7071
# stm32
7172
"meowbit_v121": UF2,
7273
"sparkfun_stm32_thing_plus": BIN_UF2,
7374
"swan_r5": BIN_UF2,
74-
# esp32
75-
"adafruit_feather_esp32_v2": BIN,
76-
# esp32c3
77-
"adafruit_qtpy_esp32c3": BIN,
78-
"ai_thinker_esp32-c3s": BIN,
79-
"ai_thinker_esp32-c3s-2m": BIN,
80-
"espressif_esp32c3_devkitm_1_n4": BIN,
81-
"lilygo_ttgo_t-01c3": BIN,
82-
"lolin_c3_mini": BIN,
83-
"microdev_micro_c3": BIN,
84-
"lilygo_ttgo_t-oi-plus": BIN,
8575
# broadcom
8676
"raspberrypi_zero": KERNEL_IMG,
8777
"raspberrypi_zero_w": KERNEL_IMG,
8878
}
8979

80+
# Per board overrides
81+
extension_by_idftarget = {
82+
"esp32": BIN,
83+
"esp32c3": BIN,
84+
}
85+
86+
87+
def extension_by_mpconfigboard(board_path, default):
88+
89+
with open(board_path / "mpconfigboard.mk") as mpconfig:
90+
for line in mpconfig:
91+
# Handle both = and := definitions.
92+
if not (m := re.match(r"^([A-Z][A-Z0-9_]*)\s*:?=\s*(.*)$", line)):
93+
continue
94+
key = m.group(1)
95+
value = m.group(2)
96+
if key == "IDF_TARGET" and value in extension_by_idftarget:
97+
return extension_by_idftarget[value]
98+
if key == "EXTENSIONS":
99+
return tuple(value.split())
100+
return default
101+
102+
90103
language_allow_list = set(
91104
[
92105
"ID",
@@ -120,6 +133,14 @@ def get_languages(list_all=False):
120133
return sorted(list(languages), key=str.casefold)
121134

122135

136+
def get_board_extension(port, board):
137+
board_path = pathlib.Path(os.path.join("../ports", port, "boards", board))
138+
extensions = extension_by_port[port]
139+
extensions = extension_by_mpconfigboard(board_path, extensions)
140+
extensions = extension_by_board.get(board_path.name, extensions)
141+
return extensions
142+
143+
123144
def get_board_mapping():
124145
boards = {}
125146
for port in SUPPORTED_PORTS:
@@ -128,8 +149,7 @@ def get_board_mapping():
128149
if board_path.is_dir():
129150
board_files = os.listdir(board_path.path)
130151
board_id = board_path.name
131-
extensions = extension_by_port[port]
132-
extensions = extension_by_board.get(board_path.name, extensions)
152+
extensions = get_board_extension(port, board_id)
133153
aliases = aliases_by_board.get(board_path.name, [])
134154
boards[board_id] = {
135155
"port": port,
@@ -341,4 +361,10 @@ def generate_download_info():
341361
if "RELEASE_TAG" in os.environ and os.environ["RELEASE_TAG"]:
342362
generate_download_info()
343363
else:
344-
print("skipping website update because this isn't a tag")
364+
if len(sys.argv) == 1:
365+
print("skipping website update because this isn't a tag")
366+
else:
367+
for arg in sys.argv[1:]:
368+
port, board = arg.split(":", 1)
369+
extensions = get_board_extension(port, board)
370+
print(f"{port:<12} {board:30} {' '.join(extensions)}")

0 commit comments

Comments
 (0)