Skip to content

Commit

Permalink
changing _is_qemu and _is_fvp functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatanbaf committed Aug 4, 2022
1 parent 64e104b commit 12b6a69
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions apps/microtvm/zephyr/template_project/microtvm_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -669,18 +659,19 @@ 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.
# This is because readback protection is enabled by default when this device is flashed.
# 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))
Expand All @@ -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)

Expand Down

0 comments on commit 12b6a69

Please sign in to comment.