Skip to content

Commit

Permalink
Install required toolchains in VM
Browse files Browse the repository at this point in the history
  • Loading branch information
lschuermann committed May 13, 2024
1 parent fa3d21b commit 8505624
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 27 deletions.
78 changes: 60 additions & 18 deletions vm/provision-vm.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,71 @@
#!/usr/bin/env bash

set -x
set -e

# From https://unix.stackexchange.com/a/137639 ----------------------
function fail {
echo $1 >&2
exit 1
}

function retry {
local n=1
local max=10
local delay=15
while true; do
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
echo "Command failed. Attempt $n/$max:"
sleep $delay;
else
fail "The command has failed after $n attempts."
fi
}
done
}
# -------------------------------------------------------------------

set +e
echo "Using Google DNS to avoid around DNS resolution issues."
cat /etc/resolv.conf | sudo tee /etc/resolv.conf.bak
sudo chattr -i /etc/resolv.conf
sudo rm /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
set -e

echo "Provisioning Tock development VM..."
cd /home/tock/

echo "Cloning git repos"
git clone https://github.com/tock/tock ./tock
git clone https://github.com/tock/libtock-c ./libtock-c
git clone https://github.com/tock/libtock-rs ./libtock-rs

echo "Installing rustup"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
retry git clone https://github.com/tock/tock ./tock
retry git clone https://github.com/tock/libtock-c ./libtock-c
retry git clone https://github.com/tock/libtock-rs ./libtock-rs

echo "Installing Tockloader"
sudo pip3 install tockloader
retry sudo pip3 install tockloader

echo "Installing rustup"
curl https://sh.rustup.rs -sSf | sh -s -- -y

echo "Installing GCC toolchains"
sudo apt install -y gcc-arm-none-eabi gcc-riscv64-unknown-elf
echo "Source the Rust setup"
source /home/tock/.cargo/env

echo "Building kernel"
pushd ./tock/boards/nordic/nrf52840dk/ && make && popd
pushd ./tock/boards/opentitan/earlgrey-cw310/ && make && popd
echo "Build the libtock-c example app, downloading toolchains and elf2tab"
pushd libtock-c/examples/c_hello
retry make
popd

echo "Building libtock-c app"
pushd ./libtock-c/examples/c_hello/ && make && popd
pushd ./libtock-c/examples/cxx_hello/ && make && popd
echo "Build the nRF52840DK Tock board, which will download the Rust toolchain"
pushd tock/boards/nordic/nrf52840dk
retry make
popd

echo "Building libtock-rs app"
pushd ./libtock-rs/ && make nrf52840 EXAMPLE=blink && popd
set +e
echo "Restoring DNS configuration."
sudo chattr -i /etc/resolv.conf
sudo rm /etc/resolv.conf
sudo mv /etc/resolv.conf.bak /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
set -e
26 changes: 17 additions & 9 deletions vm/user-data
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ autoinstall:
- htop
- nload
- tmux
- gcc-arm-none-eabi
- gcc-riscv64-unknown-elf

# This adds the default snaps found on a 22.04 Ubuntu Desktop system.
# Any desired additional snaps may also be listed here.
Expand Down Expand Up @@ -114,13 +116,19 @@ autoinstall:
# Enable password-less sudo for the tock user:
- "curtin in-target -- /bin/bash -c '\
mkdir -p /etc/sudoers.d; \
chmod 0755 /etc/sudoers.d; \
echo \"tock ALL=(ALL) NOPASSWD: ALL\" > /etc/sudoers.d/tock; \
chmod 0440 /etc/sudoers.d/tock; \
chown -Rf root:root /etc/sudoers.d; \
systemctl disable apt-daily.service; \
systemctl disable apt-daily.timer; \
systemctl disable apt-daily-upgrade.service; \
systemctl disable apt-daily-upgrade.timer; \
exit 0\
chmod 0755 /etc/sudoers.d; \
echo \"tock ALL=(ALL) NOPASSWD: ALL\" > /etc/sudoers.d/tock; \
chmod 0440 /etc/sudoers.d/tock; \
chown -Rf root:root /etc/sudoers.d; \
systemctl disable apt-daily.service; \
systemctl disable apt-daily.timer; \
systemctl disable apt-daily-upgrade.service; \
systemctl disable apt-daily-upgrade.timer; \
exit 0\
'"

# Disable apparmor
- "curtin in-target -- systemctl mask apparmor.service"

# Disable systemd-networkd-wait-online, as this may hang the boot process:
- "curtin in-target -- systemctl mask systemd-networkd-wait-online.service"

0 comments on commit 8505624

Please sign in to comment.