diff --git a/apps/microtvm/arduino/template_project/microtvm_api_server.py b/apps/microtvm/arduino/template_project/microtvm_api_server.py index e285ecc6e3b0..18c1b659dafd 100644 --- a/apps/microtvm/arduino/template_project/microtvm_api_server.py +++ b/apps/microtvm/arduino/template_project/microtvm_api_server.py @@ -36,6 +36,8 @@ import serial.tools.list_ports from tvm.micro.project_api import server +_LOG = logging.getLogger(__name__) + MODEL_LIBRARY_FORMAT_RELPATH = pathlib.Path("src") / "model" / "model.tar" API_SERVER_DIR = pathlib.Path(os.path.dirname(__file__) or os.path.getcwd()) BUILD_DIR = API_SERVER_DIR / "build" @@ -43,6 +45,10 @@ IS_TEMPLATE = not (API_SERVER_DIR / MODEL_LIBRARY_FORMAT_RELPATH).exists() +# Used to check Arduino CLI version installed on the host. +# We only check two levels of the version. +ARDUINO_CLI_VERSION = 0.18 + BOARDS = API_SERVER_DIR / "boards.json" @@ -77,6 +83,11 @@ class BoardAutodetectFailed(Exception): server.ProjectOption( "verbose", help="True to pass --verbose flag to arduino-cli compile and upload" ), + server.ProjectOption( + "warning_as_error", + choices=(True, False), + help="Treat warnings as errors and raise an Exception.", + ), ] @@ -275,7 +286,25 @@ def _find_modified_include_path(self, project_dir, file_path, include_path): # It's probably a standard C/C++ header return include_path + def _get_platform_version(self, arduino_cli_path: str) -> float: + version_output = subprocess.check_output([arduino_cli_path, "version"], encoding="utf-8") + version_output = ( + version_output.replace("\n", "").replace("\r", "").replace(":", "").lower().split(" ") + ) + full_version = version_output[version_output.index("version") + 1].split(".") + version = float(f"{full_version[0]}.{full_version[1]}") + + return version + def generate_project(self, model_library_format_path, standalone_crt_dir, project_dir, options): + # Check Arduino version + version = self._get_platform_version(options["arduino_cli_cmd"]) + if version != ARDUINO_CLI_VERSION: + message = f"Arduino CLI version found is not supported: found {version}, expected {ARDUINO_CLI_VERSION}." + if options.get("warning_as_error") is not None and options["warning_as_error"]: + raise server.ServerError(message=message) + _LOG.warning(message) + # Reference key directories with pathlib project_dir = pathlib.Path(project_dir) project_dir.mkdir() diff --git a/apps/microtvm/reference-vm/arduino/base-box/base_box_provision.sh b/apps/microtvm/reference-vm/arduino/base-box/base_box_provision.sh index 11d89f2cd44e..2724069ba722 100644 --- a/apps/microtvm/reference-vm/arduino/base-box/base_box_provision.sh +++ b/apps/microtvm/reference-vm/arduino/base-box/base_box_provision.sh @@ -31,8 +31,12 @@ cd ~ sudo apt-get install -y ca-certificates # Install Arduino-CLI (specific version) +# To keep in sync with the version +# defined in apps/microtvm/arduino/template_project/microtvm_api_server.py +ARDUINO_CLI_VERSION="0.18.3" + export PATH="/home/vagrant/bin:$PATH" -wget -O - https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh -s 0.18.3 +wget -O - https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh -s ${ARDUINO_CLI_VERSION} # Arduino (the CLI and GUI) require the dialout permission for uploading sudo usermod -a -G dialout $USER diff --git a/apps/microtvm/reference-vm/zephyr/base-box/base_box_provision.sh b/apps/microtvm/reference-vm/zephyr/base-box/base_box_provision.sh index 0631e89f3bb3..0e83d1b8be97 100644 --- a/apps/microtvm/reference-vm/zephyr/base-box/base_box_provision.sh +++ b/apps/microtvm/reference-vm/zephyr/base-box/base_box_provision.sh @@ -28,7 +28,8 @@ source ~/.profile # Init Zephyr cd ~ # Using most recent commit that passes all the tests. -~/ubuntu_init_zephyr_project.sh ~/zephyr v2.5-branch --commit dabf23758417fd041fec2a2a821d8f526afac29d +ZEPHYR_VERSION="v2.5-branch" +~/ubuntu_init_zephyr_project.sh ~/zephyr ${ZEPHYR_VERSION} --commit dabf23758417fd041fec2a2a821d8f526afac29d # Cleanup rm -f *.sh diff --git a/apps/microtvm/zephyr/template_project/microtvm_api_server.py b/apps/microtvm/zephyr/template_project/microtvm_api_server.py index f700b5774c72..36a5ff12193f 100644 --- a/apps/microtvm/zephyr/template_project/microtvm_api_server.py +++ b/apps/microtvm/zephyr/template_project/microtvm_api_server.py @@ -61,6 +61,11 @@ BOARDS = API_SERVER_DIR / "boards.json" +# Used to check Zephyr version installed on the host. +# We only check two levels of the version. +ZEPHYR_VERSION = 2.5 + + # Data structure to hold the information microtvm_api_server.py needs # to communicate with each of these boards. try: @@ -265,6 +270,11 @@ def _get_nrf_device_args(options): "config_main_stack_size", help="Sets CONFIG_MAIN_STACK_SIZE for Zephyr board.", ), + server.ProjectOption( + "warning_as_error", + choices=(True, False), + help="Treat warnings as errors and raise an Exception.", + ), ] @@ -342,7 +352,27 @@ def _create_prj_conf(self, project_dir, options): "aot_demo": "memory microtvm_rpc_common common", } + def _get_platform_version(self) -> float: + with open(pathlib.Path(os.getenv("ZEPHYR_BASE")) / "VERSION", "r") as f: + lines = f.readlines() + for line in lines: + line = line.replace(" ", "").replace("\n", "").replace("\r", "") + if "VERSION_MAJOR" in line: + version_major = line.split("=")[1] + if "VERSION_MINOR" in line: + version_minor = line.split("=")[1] + + return float(f"{version_major}.{version_minor}") + def generate_project(self, model_library_format_path, standalone_crt_dir, project_dir, options): + # Check Zephyr version + version = self._get_platform_version() + if version != ZEPHYR_VERSION: + message = f"Zephyr version found is not supported: found {version}, expected {ZEPHYR_VERSION}." + if options.get("warning_as_error") is not None and options["warning_as_error"]: + raise server.ServerError(message=message) + _LOG.warning(message) + project_dir = pathlib.Path(project_dir) # Make project directory. project_dir.mkdir() diff --git a/docker/install/ubuntu_install_arduino.sh b/docker/install/ubuntu_install_arduino.sh index c374850aa1df..a612261b2a2b 100644 --- a/docker/install/ubuntu_install_arduino.sh +++ b/docker/install/ubuntu_install_arduino.sh @@ -23,8 +23,9 @@ set -o pipefail export DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates -# Install arduino-cli latest version -wget -O - https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh -s +ARDUINO_CLI_VERSION="0.18.3" +# Install arduino-cli +wget -O - https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh -s ${ARDUINO_CLI_VERSION} # Install the cores we want to test on arduino-cli core install arduino:mbed_nano diff --git a/docker/install/ubuntu_install_zephyr.sh b/docker/install/ubuntu_install_zephyr.sh index 7e5aae96a38f..ddd1ea1c1734 100644 --- a/docker/install/ubuntu_install_zephyr.sh +++ b/docker/install/ubuntu_install_zephyr.sh @@ -44,9 +44,13 @@ sudo apt-get install -y cmake pip3 install west # Init ZephyrProject +# To keep in sync with the version +# defined in apps/microtvm/zephyr/template_project/microtvm_api_server.py +# We use `-branch` tag since it tracks the same version with extra patches for bugs. +ZEPHYR_VERSION="v2.5-branch" ZEPHYR_PROJECT_PATH=/opt/zephyrproject ZEPHYR_INIT_SCRIPT=$(find -name "ubuntu_init_zephyr_project.sh") -bash ${ZEPHYR_INIT_SCRIPT} ${ZEPHYR_PROJECT_PATH} v2.5-branch +bash ${ZEPHYR_INIT_SCRIPT} ${ZEPHYR_PROJECT_PATH} ${ZEPHYR_VERSION} cd ${ZEPHYR_PROJECT_PATH} # As part of the build process, Zephyr needs to touch some symlinks in zephyr/misc/generated/syscalls_links (this path is relative to the