You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by gu...@apache.org on 2023/01/13 20:54:20 UTC

[tvm] 01/11: [microtvm][Zephyr] Add project overlay to overwrite device tree configs (#12741)

This is an automated email from the ASF dual-hosted git repository.

guberti pushed a commit to branch acc-tests-1
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 69fbe2c48eb37f0496f47badabce371aebb2d578
Author: Mehrdad Hessar <mh...@octoml.ai>
AuthorDate: Fri Sep 9 09:25:30 2022 -0700

    [microtvm][Zephyr] Add project overlay to overwrite device tree configs (#12741)
    
    * add nucleo overlay
---
 .../app-overlay/nucleo_l4r5zi.overlay              | 23 ++++++++++++++++++++++
 .../zephyr/template_project/microtvm_api_server.py | 15 ++++++++++----
 cmake/modules/Zephyr.cmake                         |  1 +
 tests/lint/check_file_type.py                      |  1 +
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/apps/microtvm/zephyr/template_project/app-overlay/nucleo_l4r5zi.overlay b/apps/microtvm/zephyr/template_project/app-overlay/nucleo_l4r5zi.overlay
new file mode 100644
index 0000000000..360e0753d4
--- /dev/null
+++ b/apps/microtvm/zephyr/template_project/app-overlay/nucleo_l4r5zi.overlay
@@ -0,0 +1,23 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+&rcc {
+	clock-frequency = <DT_FREQ_M(120)>;
+};
diff --git a/apps/microtvm/zephyr/template_project/microtvm_api_server.py b/apps/microtvm/zephyr/template_project/microtvm_api_server.py
index b73779f681..5a0bc7309c 100644
--- a/apps/microtvm/zephyr/template_project/microtvm_api_server.py
+++ b/apps/microtvm/zephyr/template_project/microtvm_api_server.py
@@ -567,6 +567,8 @@ class Handler(server.ProjectAPIHandler):
         return cmake_args
 
     def generate_project(self, model_library_format_path, standalone_crt_dir, project_dir, options):
+        zephyr_board = options["zephyr_board"]
+
         # Check Zephyr version
         version = self._get_platform_version(get_zephyr_base(options))
         if version != ZEPHYR_VERSION:
@@ -586,6 +588,11 @@ class Handler(server.ProjectAPIHandler):
         # Copy boards.json file to generated project.
         shutil.copy2(BOARDS, project_dir / BOARDS.name)
 
+        # Copy overlay files
+        board_overlay_path = API_SERVER_DIR / "app-overlay" / f"{zephyr_board}.overlay"
+        if board_overlay_path.exists():
+            shutil.copy2(board_overlay_path, project_dir / f"{zephyr_board}.overlay")
+
         # Place Model Library Format tarball in the special location, which this script uses to decide
         # whether it's being invoked in a template or generated project.
         project_model_library_format_tar_path = project_dir / MODEL_LIBRARY_FORMAT_RELPATH
@@ -597,9 +604,9 @@ class Handler(server.ProjectAPIHandler):
             os.makedirs(extract_path)
             tf.extractall(path=extract_path)
 
-        if self._is_qemu(options["zephyr_board"], options.get("use_fvp")):
+        if self._is_qemu(zephyr_board, options.get("use_fvp")):
             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(zephyr_board, options.get("use_fvp")):
             shutil.copytree(API_SERVER_DIR / "fvp-hack", project_dir / "fvp-hack")
 
         # Populate CRT.
@@ -650,7 +657,7 @@ class Handler(server.ProjectAPIHandler):
                     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(zephyr_board, options.get("use_fvp")):
                     cmake_f.write(f"target_compile_definitions(app PUBLIC -DFVP=1)\n")
 
         self._create_prj_conf(project_dir, options)
@@ -665,7 +672,7 @@ class Handler(server.ProjectAPIHandler):
         # Populate src/
         src_dir = project_dir / "src"
         if options["project_type"] != "host_driven" or self._is_fvp(
-            options["zephyr_board"], options.get("use_fvp")
+            zephyr_board, options.get("use_fvp")
         ):
             shutil.copytree(API_SERVER_DIR / "src" / options["project_type"], src_dir)
         else:
diff --git a/cmake/modules/Zephyr.cmake b/cmake/modules/Zephyr.cmake
index be4f85dac3..644675dcf8 100644
--- a/cmake/modules/Zephyr.cmake
+++ b/cmake/modules/Zephyr.cmake
@@ -29,6 +29,7 @@ if(USE_MICRO)
       "apps/microtvm/zephyr/template_project/src/host_driven *.h -> zephyr/src/host_driven"
       "apps/microtvm/zephyr/template_project/fvp-hack * -> zephyr/fvp-hack"
       "apps/microtvm/zephyr/template_project/qemu-hack * -> zephyr/qemu-hack"
+      "apps/microtvm/zephyr/template_project/app-overlay * -> zephyr/app-overlay"
       "apps/microtvm/zephyr/template_project/crt_config *.h -> zephyr/crt_config"
     )
 
diff --git a/tests/lint/check_file_type.py b/tests/lint/check_file_type.py
index 7e09c3c7cf..51a80431d3 100644
--- a/tests/lint/check_file_type.py
+++ b/tests/lint/check_file_type.py
@@ -148,6 +148,7 @@ ALLOW_SPECIFIC_FILE = {
     "apps/microtvm/zephyr/template_project/qemu-hack/qemu-system-riscv32",
     "apps/microtvm/zephyr/template_project/qemu-hack/qemu-system-riscv64",
     "apps/microtvm/zephyr/template_project/fvp-hack/FVP_Corstone_SSE-300_Ethos-U55",
+    "apps/microtvm/zephyr/template_project/app-overlay/nucleo_l4r5zi.overlay",
     # microTVM Virtual Machines
     "apps/microtvm/poetry.lock",
     "apps/microtvm/reference-vm/Vagrantfile",