From f6e4bcc4197d469b7c0ba3460b5edd171157c85b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 18 Jul 2022 19:44:15 -0500 Subject: [PATCH] Allow mpconfigboard.mk to set board extensions Looking at the PR to add Beetle esp32 c3 (#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. --- ports/nrf/boards/microbit_v2/mpconfigboard.mk | 2 + tools/build_board_info.py | 56 ++++++++++++++----- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/ports/nrf/boards/microbit_v2/mpconfigboard.mk b/ports/nrf/boards/microbit_v2/mpconfigboard.mk index 78e76d3b53741..b93a627e362f1 100644 --- a/ports/nrf/boards/microbit_v2/mpconfigboard.mk +++ b/ports/nrf/boards/microbit_v2/mpconfigboard.mk @@ -7,3 +7,5 @@ INTERNAL_FLASH_FILESYSTEM = 1 # USB pins aren't used. CIRCUITPY_USB = 0 + +EXTENSIONS = combined.hex diff --git a/tools/build_board_info.py b/tools/build_board_info.py index c58dc42a9d415..8b0b6909e4101 100755 --- a/tools/build_board_info.py +++ b/tools/build_board_info.py @@ -6,6 +6,8 @@ import json import os +import pathlib +import re import subprocess import sys import sh @@ -66,27 +68,38 @@ "pca10056": BIN_UF2, "pca10059": BIN_UF2, "electronut_labs_blip": HEX, - "microbit_v2": COMBINED_HEX, # stm32 "meowbit_v121": UF2, "sparkfun_stm32_thing_plus": BIN_UF2, "swan_r5": BIN_UF2, - # esp32 - "adafruit_feather_esp32_v2": BIN, - # esp32c3 - "adafruit_qtpy_esp32c3": BIN, - "ai_thinker_esp32-c3s": BIN, - "ai_thinker_esp32-c3s-2m": BIN, - "espressif_esp32c3_devkitm_1_n4": BIN, - "lilygo_ttgo_t-01c3": BIN, - "lolin_c3_mini": BIN, - "microdev_micro_c3": BIN, - "lilygo_ttgo_t-oi-plus": BIN, # broadcom "raspberrypi_zero": KERNEL_IMG, "raspberrypi_zero_w": KERNEL_IMG, } +# Per board overrides +extension_by_idftarget = { + "esp32": BIN, + "esp32c3": BIN, +} + + +def extension_by_mpconfigboard(board_path, default): + + with open(board_path / "mpconfigboard.mk") as mpconfig: + for line in mpconfig: + # Handle both = and := definitions. + if not (m := re.match(r"^([A-Z][A-Z0-9_]*)\s*:?=\s*(.*)$", line)): + continue + key = m.group(1) + value = m.group(2) + if key == "IDF_TARGET" and value in extension_by_idftarget: + return extension_by_idftarget[value] + if key == "EXTENSIONS": + return tuple(value.split()) + return default + + language_allow_list = set( [ "ID", @@ -120,6 +133,14 @@ def get_languages(list_all=False): return sorted(list(languages), key=str.casefold) +def get_board_extension(port, board): + board_path = pathlib.Path(os.path.join("../ports", port, "boards", board)) + extensions = extension_by_port[port] + extensions = extension_by_mpconfigboard(board_path, extensions) + extensions = extension_by_board.get(board_path.name, extensions) + return extensions + + def get_board_mapping(): boards = {} for port in SUPPORTED_PORTS: @@ -128,8 +149,7 @@ def get_board_mapping(): if board_path.is_dir(): board_files = os.listdir(board_path.path) board_id = board_path.name - extensions = extension_by_port[port] - extensions = extension_by_board.get(board_path.name, extensions) + extensions = get_board_extension(port, board_id) aliases = aliases_by_board.get(board_path.name, []) boards[board_id] = { "port": port, @@ -341,4 +361,10 @@ def generate_download_info(): if "RELEASE_TAG" in os.environ and os.environ["RELEASE_TAG"]: generate_download_info() else: - print("skipping website update because this isn't a tag") + if len(sys.argv) == 1: + print("skipping website update because this isn't a tag") + else: + for arg in sys.argv[1:]: + port, board = arg.split(":", 1) + extensions = get_board_extension(port, board) + print(f"{port:<12} {board:30} {' '.join(extensions)}")