Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[µTVM] Add VMWare to Reference VM instructions #7221

Merged
merged 7 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 56 additions & 12 deletions apps/microtvm/reference-vm/base-box-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


import argparse
import copy
import json
import logging
import os
Expand All @@ -38,6 +39,7 @@
ALL_PROVIDERS = (
"parallels",
"virtualbox",
"vmware_desktop",
)


Expand Down Expand Up @@ -141,9 +143,27 @@ def attach_parallels(uuid, vid_hex=None, pid_hex=None, serial=None):
)


def attach_vmware(uuid, vid_hex=None, pid_hex=None, serial=None):
print("NOTE: vmware doesn't seem to support automatic attaching of devices :(")
print("The VMWare VM UUID is {uuid}")
print("Please attach the following usb device using the VMWare GUI:")
if vid_hex is not None:
print(f" - VID: {vid_hex}")
if pid_hex is not None:
print(f" - PID: {pid_hex}")
if serial is not None:
print(f" - Serial: {serial}")
if vid_hex is None and pid_hex is None and serial is None:
print(" - (no specifications given for USB device)")
print()
print("Press [Enter] when the USB device is attached")
input()


ATTACH_USB_DEVICE = {
"parallels": attach_parallels,
"virtualbox": attach_virtualbox,
"vmware_desktop": attach_vmware,
}


Expand All @@ -153,6 +173,7 @@ def generate_packer_config(file_path, providers):
builders.append(
{
"type": "vagrant",
"box_name": f"microtvm-base-{provider_name}",
"output_dir": f"output-packer-{provider_name}",
"communicator": "ssh",
"source_path": "generic/ubuntu1804",
Expand All @@ -175,10 +196,19 @@ def generate_packer_config(file_path, providers):
def build_command(args):
generate_packer_config(
os.path.join(THIS_DIR, args.platform, "base-box", "packer.json"),
args.provider.split(",") or ALL_PROVIDERS,
args.provider or ALL_PROVIDERS,
)
env = None
packer_args = ["packer", "build"]
if args.debug_packer:
env = copy.copy(os.environ)
env["PACKER_LOG"] = "1"
env["PACKER_LOG_PATH"] = "packer.log"
packer_args += ["-debug"]

packer_args += ["packer.json"]
subprocess.check_call(
["packer", "build", "packer.json"], cwd=os.path.join(THIS_DIR, args.platform, "base-box")
packer_args, cwd=os.path.join(THIS_DIR, args.platform, "base-box"), env=env
)


Expand Down Expand Up @@ -318,16 +348,17 @@ def test_command(args):


def release_command(args):
subprocess.check_call(
[
"vagrant",
"cloud",
"version",
"create",
f"tlcpack/microtvm-{args.platform}",
args.release_version,
]
)
if not args.skip_creating_release_version:
subprocess.check_call(
[
"vagrant",
"cloud",
"version",
"create",
f"tlcpack/microtvm-{args.platform}",
args.release_version,
]
)
if not args.release_version:
sys.exit(f"--release-version must be specified")

Expand Down Expand Up @@ -399,6 +430,19 @@ def parse_args():
"--release-version",
help="Version to release, in the form 'x.y.z'. Must be specified with release.",
)
parser.add_argument(
"--skip-creating-release-version",
action="store_true",
help="With release, skip creating the version and just upload for this provider.",
)
parser.add_argument(
"--debug-packer",
action="store_true",
help=(
"When the build command is given, run packer in debug mode, and write log to the "
"base-box directory"
),
)

return parser.parse_args()

Expand Down
10 changes: 10 additions & 0 deletions apps/microtvm/reference-vm/zephyr/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ Vagrant.configure("2") do |config|
end
end

config.vm.provider "vmware_desktop" do |vm, overrides|
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@ Vagrant.configure("2") do |config|
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: 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: "../setup.sh", privileged: false
end
24 changes: 18 additions & 6 deletions apps/microtvm/reference-vm/zephyr/base-box/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

set -e

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.
Expand Down Expand Up @@ -96,10 +103,15 @@ sed -i "/^# If not running interactively,/ i\\ " ~/.bashrc

# Clean box for packaging as a base box
sudo apt-get clean
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
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
rm -f "${EMPTY_FILE}"
12 changes: 7 additions & 5 deletions tutorials/micro/micro_reference_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,27 @@

A minimal set of prerequisites are needed:


1. `Vagrant <https://vagrantup.com>`__
2. A supported Virtual Machine hypervisor.
`VirtualBox <https://www.virtualbox.org>`__ is one suggested free hypervisor, but please note
2. A supported Virtual Machine hypervisor (**VirtualBox**, **Parallels**, or **VMWare Fusion/Workstation**).
`VirtualBox <https://www.virtualbox.org>`__ is a suggested free hypervisor, but please note
that the `VirtualBox Extension Pack`_ is required for proper USB forwarding. If using VirtualBox,
also consider installing the `vbguest <https://github.com/dotless-de/vagrant-vbguest>`_ plugin.

.. _VirtualBox Extension Pack: https://www.virtualbox.org/wiki/Downloads#VirtualBox6.1.16OracleVMVirtualBoxExtensionPack

3. If required for your hypervisor, the
`Vagrant provider plugin <https://github.com/hashicorp/vagrant/wiki/Available-Vagrant-Plugins#providers>`__ (or see `here <https://www.vagrantup.com/vmware>`__ for VMWare).

First boot
----------

The first time you use a reference VM, you need to create the box locally and then provision it.

.. code-block:: bash

# Replace zepyhr with the name of a different platform, if you are not using Zephyr.
# Replace zephyr with the name of a different platform, if you are not using Zephyr.
~/.../tvm $ cd apps/microtvm/reference-vm/zephyr
# Replace <provider_name> with the name of the hypervisor you wish to use (i.e. virtualbox).
# Replace <provider_name> with the name of the hypervisor you wish to use (i.e. virtualbox, parallels, vmware_desktop).
~/.../tvm/apps/microtvm/reference-vm/zephyr $ vagrant up --provider=<provider_name>


Expand Down