diff --git a/apps/microtvm/zephyr/template_project/microtvm_api_server.py b/apps/microtvm/zephyr/template_project/microtvm_api_server.py index 781442747cf47..4a548b9dae496 100644 --- a/apps/microtvm/zephyr/template_project/microtvm_api_server.py +++ b/apps/microtvm/zephyr/template_project/microtvm_api_server.py @@ -485,11 +485,11 @@ def _generate_cmake_args(self, mlf_extracted_path, options) -> str: if options.get("west_cmd"): cmake_args += f"set(WEST {options['west_cmd']})\n" - if self._is_qemu(options["zephyr_board"], options.get("use_fvp")): + if self._is_qemu(options["zephyr_board"]): # Some boards support more than one emulator, so ensure QEMU is set. cmake_args += f"set(EMU_PLATFORM qemu)\n" - if self._is_fvp(options["zephyr_board"], options.get("use_fvp")): + if self._is_fvp(options["zephyr_board"]): cmake_args += f"set(EMU_PLATFORM armfvp)\n" cmake_args += f"set(ARMFVP_FLAGS -I)\n" @@ -531,9 +531,9 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec os.makedirs(extract_path) tf.extractall(path=extract_path) - if self._is_qemu(options["zephyr_board"], options.get("use_fvp")): + if self._is_qemu(options["zephyr_board"]): shutil.copytree(API_SERVER_DIR / "qemu-hack", project_dir / "qemu-hack") - elif self._is_fvp(options["zephyr_board"], options.get("use_fvp")): + elif self._is_fvp(options["zephyr_board"]): shutil.copytree(API_SERVER_DIR / "fvp-hack", project_dir / "fvp-hack") # Populate CRT. @@ -569,7 +569,7 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec for item in flags: cmake_f.write(f"target_compile_definitions(app PUBLIC {item})\n") - if self._is_fvp(options["zephyr_board"], options.get("use_fvp")): + if self._is_fvp(options["zephyr_board"]): cmake_f.write(f"target_compile_definitions(app PUBLIC -DFVP=1)\n") self._create_prj_conf(project_dir, options) @@ -583,9 +583,7 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec # Populate src/ src_dir = project_dir / "src" - if options["project_type"] != "host_driven" or self._is_fvp( - options["zephyr_board"], options.get("use_fvp") - ): + if options["project_type"] != "host_driven" or self._is_fvp(options["zephyr_board"]): shutil.copytree(API_SERVER_DIR / "src" / options["project_type"], src_dir) else: src_dir.mkdir() @@ -600,10 +598,8 @@ def build(self, options): BUILD_DIR.mkdir() zephyr_board = self._find_board_from_cmake_file() - emu_platform = self._find_platform_from_cmake_file() - env = dict(os.environ) - if self._is_fvp(zephyr_board, emu_platform == "armfvp"): + if self._is_fvp(zephyr_board): env["ARMFVP_BIN_PATH"] = str(API_SERVER_DIR / "fvp-hack") env["ARMFVP_BIN_PATH"] = os.path.realpath(env["ARMFVP_BIN_PATH"]) st = os.stat(env["ARMFVP_BIN_PATH"] + "/FVP_Corstone_SSE-300_Ethos-U55") @@ -623,25 +619,19 @@ def build(self, options): # A list of all zephyr_board values which are known to launch using QEMU. Many platforms which # launch through QEMU by default include "qemu" in their name. However, not all do. This list # includes those tested platforms which do not include qemu. - _KNOWN_QEMU_ZEPHYR_BOARDS = ["mps2_an521", "mps3_an547"] + _KNOWN_QEMU_ZEPHYR_BOARDS = ["mps2_an521"] # A list of all zephyr_board values which are known to launch using ARM FVP (this script configures # Zephyr to use that launch method). _KNOWN_FVP_ZEPHYR_BOARDS = ["mps3_an547"] @classmethod - def _is_fvp(cls, board, use_fvp): - assert ( - use_fvp and board not in cls._KNOWN_FVP_ZEPHYR_BOARDS - ) == False, "fvp doesn't support this board." - - return board in cls._KNOWN_FVP_ZEPHYR_BOARDS and use_fvp + def _is_fvp(cls, board): + return board in cls._KNOWN_FVP_ZEPHYR_BOARDS @classmethod - def _is_qemu(cls, board, use_fvp=False): - return "qemu" in board or ( - board in cls._KNOWN_QEMU_ZEPHYR_BOARDS and not cls._is_fvp(board, use_fvp) - ) + def _is_qemu(cls, board): + return "qemu" in board or board in cls._KNOWN_QEMU_ZEPHYR_BOARDS @classmethod def _has_fpu(cls, zephyr_board): @@ -669,10 +659,12 @@ def _find_platform_from_cmake_file(cls) -> str: if line.startswith("set(EMU_PLATFORM"): emu_platform = line.strip("\n").strip("set(EMU_PLATFORM ").strip(")") break + return emu_platform def flash(self, options): - if self._find_platform_from_cmake_file(): + zephyr_board = self._find_board_from_cmake_file() + if self._is_qemu(zephyr_board) or self._is_fvp(zephyr_board): return # NOTE: qemu requires no flash step--it is launched from open_transport. # The nRF5340DK requires an additional `nrfjprog --recover` before each flash cycle. @@ -680,7 +672,6 @@ def flash(self, options): # Otherwise, flashing may fail with an error such as the following: # ERROR: The operation attempted is unavailable due to readback protection in # ERROR: your device. Please use --recover to unlock the device. - zephyr_board = self._find_board_from_cmake_file() if zephyr_board.startswith("nrf5340dk") and _get_flash_runner() == "nrfjprog": recover_args = ["nrfjprog", "--recover"] recover_args.extend(_get_nrf_device_args(options)) @@ -690,11 +681,10 @@ def flash(self, options): def open_transport(self, options): zephyr_board = self._find_board_from_cmake_file() - emu_platform = self._find_platform_from_cmake_file() - if self._is_fvp(zephyr_board, emu_platform == "armfvp"): - transport = ZephyrFvpTransport(options) - elif self._is_qemu(zephyr_board): + if self._is_qemu(zephyr_board): transport = ZephyrQemuTransport(options) + elif self._is_fvp(zephyr_board): + transport = ZephyrFvpTransport(options) else: transport = ZephyrSerialTransport(options)