Skip to content

Commit

Permalink
Functioning Arduino Vagrant VM
Browse files Browse the repository at this point in the history
Begin building Arduino Vagrant VM

Mostly working Vagrant VM

Changes for debugging

Add ignored json file

Fix venv path
  • Loading branch information
guberti committed Aug 23, 2021
1 parent aafc2d5 commit df35ad4
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 16 deletions.
1 change: 1 addition & 0 deletions apps/microtvm/reference-vm/arduino/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.vagrant
27 changes: 27 additions & 0 deletions apps/microtvm/reference-vm/arduino/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--- 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. -->

# microTVM Arduino Reference Virtual Machine

This directory contains setup files for Arduino virtual machine used for testing microTVM platforms
that are supported by [Arduino](https://www.arduino.cc/).

## VM Information for Developers
Arduino VM is published under [tlcpack](https://app.vagrantup.com/tlcpack).
Here is a list of different release versions and their tools.

(none currently)
89 changes: 89 additions & 0 deletions apps/microtvm/reference-vm/arduino/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 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.

Vagrant.configure("2") do |config|
config.vm.box = "tlcpack/microtvm-arduino-0.18.3"

if ENV.has_key?("TVM_RVM_NUM_CORES")
num_cores = ENV["TVM_RVM_NUM_CORES"]
else
num_cores = 2
end

if ENV.has_key?("TVM_RVM_RAM_BYTES")
ram_bytes = ENV["TVM_RVM_RAM_BYTES"]
else
ram_bytes = 2048
end

tvm_home = "../../../.."
dirs_to_mount = [Pathname.new(Pathname.new(tvm_home).expand_path())]
if ENV.has_key?("TVM_PROJECT_DIR") then
dirs_to_mount.append(ENV["TVM_PROJECT_DIR"])
puts "NOTE: also configuring project dir: %s" % [dirs_to_mount[-1]]
end

git_file = Pathname.new(tvm_home + "/.git")
if git_file.ftype() == "file" then
gitdir_match = Regexp.new('^gitdir: (?<gitdir>.*/.git).*\n$', Regexp::MULTILINE).match(git_file.read())
if !gitdir_match.nil? then
dirs_to_mount.append(Pathname.new(tvm_home).realpath.join(gitdir_match.named_captures["gitdir"]))
puts "NOTE: also configuring git-worktree gitdir: %s" % [dirs_to_mount[-1]]
end
end

config.vm.provision "shell", path: "provision_setup.sh", env: {"TVM_HOME": dirs_to_mount[0]}, privileged: false

# Enable USB Controller on VirtualBox
vm_name = "microtvm-#{Time.now.tv_sec}"
config.vm.provider "virtualbox" do |vb, overrides|
vb.name = vm_name
vb.cpus = num_cores
vb.memory = ram_bytes
vb.customize ["modifyvm", :id, "--usb", "on"]
vb.customize ["modifyvm", :id, "--usbehci", "on"]
vb.customize ["modifyvm", :id, "--usbxhci", "on"]
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
dirs_to_mount.each do |d|
overrides.vm.synced_folder d.to_s, d.to_s
end
end

config.vm.provider "parallels" do |prl, overrides|
prl.name = vm_name
prl.cpus = num_cores
prl.memory = ram_bytes
prl.update_guest_tools = true
prl.customize ["set", :id, "--support-usb30", "on"]
dirs_to_mount.each do |d|
overrides.vm.synced_folder d.to_s, d.to_s, mount_options: ["share", "nosuid", "host_inodes"]
end
end

config.vm.provider "vmware_desktop" do |vm, overrides|
vm.cpus = num_cores
vm.memory = ram_bytes
vm.vmx["usb_xhci.present"] = "TRUE"
vm.vmx["usb.present"] = "TRUE"
vm.vmx["ehci.present"] = "TRUE"
dirs_to_mount.each do |d|
overrides.vm.synced_folder d.to_s, d.to_s
end
vm.gui = true
end

end
4 changes: 4 additions & 0 deletions apps/microtvm/reference-vm/arduino/base-box/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.box
.vagrant
/output-packer-*
/packer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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.

Vagrant.configure("2") do |config|
# From hashicorp default template:
# https://github.com/hashicorp/packer/blob/master/builder/vagrant/step_create_vagrantfile.go#L23-L37

config.vm.define "source" do |source|
source.vm.box = "{{.SourceBox}}"
config.ssh.insert_key = {{.InsertKey}}
end

config.vm.define "output" do |output|
output.vm.box = "{{.BoxName}}"
output.vm.box_url = "file://package.box"
config.ssh.insert_key = {{.InsertKey}}
end

{{ if ne .SyncedFolder "" -}}
config.vm.synced_folder "{{.SyncedFolder}}", "/vagrant"
{{- else -}}
config.vm.synced_folder ".", "/vagrant", disabled: true
{{- end}}


{{ if eq .BoxName "microtvm-base-vmware_desktop" -}}
config.vm.provision "shell", inline: "touch ~/skip_zeroing_disk", privileged: false
{{- end}}

# NOTE: base_box_setup.sh resides in the parent directory (../) because this template is expanded into a
# sub-directory of base-box (output-packer-*).
config.vm.provision "shell", path: "../base_box_setup.sh", privileged: false
end
56 changes: 56 additions & 0 deletions apps/microtvm/reference-vm/arduino/base-box/base_box_provision.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash -e
# 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.
#
# Using this script we can reuse docker/install scripts to configure the reference
# virtual machine similar to CI QEMU setup.
#

set -e
set -x

source ~/.profile

# Init Arduino
cd ~

sudo apt-get install -y ca-certificates

# Install Arduino-CLI (latest version)
export PATH="/home/vagrant/bin:$PATH"
wget -O - https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh -s

# ubuntu_init_arduino.sh only installs a few officially
# supported architectures, so we don't use it here

# 3rd party board URLs
ADAFRUIT_BOARDS_URL="https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"
ESP32_BOARDS_URL="https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json"
SPARKFUN_BOARDS_URL="https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json"
SEEED_BOARDS_URL="https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json"
SPRESENSE_BOARDS_URL="https://github.com/sonydevworld/spresense-arduino-compatible/releases/download/generic/package_spresense_index.json"
arduino-cli core update-index --additional-urls $ADAFRUIT_BOARDS_URL,$ESP32_BOARDS_URL,$SPARKFUN_BOARDS_URL,$SEEED_BOARDS_URL,$SPRESENSE_BOARDS_URL

# Install supported cores from those URLS
arduino-cli core install arduino:mbed_nano # Arduino Nano BLE
arduino-cli core install arduino:sam # Arduino Due
arduino-cli core install SPRESENSE:spresense --additional-urls $SPRESENSE_BOARDS_URL # Sony Spresense
arduino-cli core install adafruit:samd --additional-urls $ADAFRUIT_BOARDS_URL # Adafruit PyBadge
arduino-cli core install esp32:esp32 --additional-urls $ESP32_BOARDS_URL # Adafruit FeatherS2

# Cleanup
rm -f *.sh
75 changes: 75 additions & 0 deletions apps/microtvm/reference-vm/arduino/base-box/base_box_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash -e
# 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.

set -e
set -x

skip_zeroing_disk=0
if [ -e "$HOME/skip_zeroing_disk" ]; then
echo "NOTE: will not zero disk at the end due to VMWare Fusion bug"
echo "See: https://communities.vmware.com/t5/VMware-Fusion-Discussions/VMWare-Fusion-Pro-11-15-6-16696540-causes-macOS-crash-during/m-p/2284011#M139190"
skip_zeroing_disk=1
fi

sudo apt update
sudo apt install -y build-essential
sudo apt-get --purge remove modemmanager # required to access serial ports.

sudo apt install -y --no-install-recommends git \
cmake cmake-data \
ninja-build gperf ccache dfu-util device-tree-compiler wget \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
make gcc gcc-multilib g++-multilib libsdl2-dev

OLD_HOSTNAME=$(hostname)
sudo hostnamectl set-hostname microtvm
sudo sed -i.bak "s/${OLD_HOSTNAME}/microtvm.localdomain/g" /etc/hosts

# Poetry deps
sudo apt install -y python3-venv

# TVM deps
sudo apt install -y llvm

# ONNX deps
sudo apt install -y protobuf-compiler libprotoc-dev

# TODO do we need this?
echo 'export PATH=$HOME/vagrant/bin:"$PATH"' >> ~/.profile
source ~/.profile
echo PATH=$PATH

# Poetry
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
sed -i "/^# If not running interactively,/ i source \$HOME/.poetry/env" ~/.bashrc
sed -i "/^# If not running interactively,/ i\\ " ~/.bashrc

# Clean box for packaging as a base box
sudo apt-get clean
if [ $skip_zeroing_disk -eq 0 ]; then
echo "Zeroing disk..."
EMPTY_FILE="$HOME/EMPTY"
dd if=/dev/zero "of=${EMPTY_FILE}" bs=1M || /bin/true
if [ ! -e "${EMPTY_FILE}" ]; then
echo "failed to zero empty sectors on disk"
exit 2
fi
rm -f "${EMPTY_FILE}"
else
echo "NOTE: skipping zeroing disk due to command-line argument."
fi
39 changes: 39 additions & 0 deletions apps/microtvm/reference-vm/arduino/base-box/base_box_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash -e
# 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.
#
# Usage: base_box_test.sh <MICROTVM_PLATFORM>
# Execute microTVM Arduino tests.
#

set -e
set -x

if [ "$#" -lt 1 ]; then
echo "Usage: base_box_test.sh <MICROTVM_PLATFORM>"
exit -1
fi

microtvm_platform=$1

pytest tests/micro/arduino/test_arduino_workflow.py --microtvm-platforms=${microtvm_platform}

if [ $microtvm_platform == "nano33ble" ]; then
echo "NOTE: skipped test_arduino_rpc_server.py on $microtvm_platform -- known failure"
else
pytest tests/micro/arduino/test_arduino_rpc_server.py --microtvm-platforms=${microtvm_platform}
fi
30 changes: 30 additions & 0 deletions apps/microtvm/reference-vm/arduino/base-box/test-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"due": {
"vid_hex": "2341",
"pid_hex": "003d"
},
"feathers2": {
"vid_hex": "303a",
"pid_hex": "0002"
},
"nano33ble": {
"vid_hex": "2341",
"pid_hex": "805a"
},
"spresense": {
"vid_hex": "10c4",
"pid_hex": "ea60"
},
"teensy40": {
"vid_hex": "16c0",
"pid_hex": "0478"
},
"teensy41": {
"vid_hex": "16c0",
"pid_hex": "0478"
},
"wioterminal": {
"vid_hex": "2886",
"pid_hex": "802d"
}
}
Loading

0 comments on commit df35ad4

Please sign in to comment.