Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/scripts/create_OEM_board.py
Views: 1798
#!/usr/bin/env python12"""3script to automatically create a copy of a board for an OEM setup4usage example : ./Tools/scripts/create_OEM_board.py mRoPixracerPro mRoPixracerPro-MyCompany56AP_FLAKE8_CLEAN7"""89import sys10import os11import subprocess1213import pathlib1415sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../libraries/AP_HAL_ChibiOS/hwdef/scripts'))16import chibios_hwdef # noqa171819class OEMCreate:20def __init__(self, oem_board_name, board_name):21self.oem_board_name = oem_board_name22self.board_name = board_name2324def run(self):25hwdef_dir = "libraries/AP_HAL_ChibiOS/hwdef"26oem_board_dirpath = f"{hwdef_dir}/{oem_board_name}"2728if os.path.exists(oem_board_dirpath):29raise ValueError(f"{oem_board_dirpath} already exists") # FIXME exception type3031hwdef_include_relpath = None32for extension in "dat", "inc":33tmp = f"../{board_name}/hwdef.{extension}"34tmp_norm = os.path.normpath(f"{oem_board_dirpath}/{tmp}")35if os.path.exists(tmp_norm):36hwdef_include_relpath = tmp37hwdef_include_normpath = tmp_norm38break3940hwdef_content = f"include {hwdef_include_relpath}\n"4142ch = chibios_hwdef.ChibiOSHWDef(hwdef_include_normpath)43use_bootloader_from_board = ch.get_config('USE_BOOTLOADER_FROM_BOARD', default=None, required=False)44if use_bootloader_from_board is None:45hwdef_content += "\n"46hwdef_content += f"USE_BOOTLOADER_FROM_BOARD {board_name}\n"4748subprocess.run(["mkdir", oem_board_dirpath])4950# create files and add reference to originals51new_hwdef = pathlib.Path(oem_board_dirpath, "hwdef.dat")5253if hwdef_include_relpath is None:54raise ValueError(f"Could not find .inc or .dat for {board_name}")5556new_hwdef.write_text(hwdef_content)5758if os.path.exists(f"{hwdef_dir}/{board_name}/defaults.parm"):59path = pathlib.Path(f"{hwdef_dir}/{oem_board_name}/defaults.parm")60path.write_text(f"@include ../{board_name}/defaults.parm\n") # noqa616263board_name = sys.argv[1]64oem_board_name = sys.argv[2]6566oemcreate = OEMCreate(board_name, oem_board_name)67oemcreate.run()686970