From 562cc9007ceb361c6959804ffe160722592dda15 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 4 Feb 2020 16:53:46 +0100 Subject: [PATCH] tools/packer: adapt for Ubuntu 18.04 This change is also a complete refactoring of the generation of the vagrant image --- Vagrantfile | 40 +++--- dist/tools/packer/.gitignore | 1 + dist/tools/packer/README.md | 2 +- dist/tools/packer/http/preseed.cfg | 43 +++++++ dist/tools/packer/preseed.cfg | 35 ------ dist/tools/packer/riot.json | 107 +++++++++------- dist/tools/packer/scripts/base.sh | 14 +++ dist/tools/packer/scripts/cleanup.sh | 91 ++++++++++++++ dist/tools/packer/scripts/riot.sh | 41 ++++++ dist/tools/packer/scripts/toolchains.sh | 104 ++++++++++++++++ dist/tools/packer/scripts/udev_rules.sh | 50 ++++++++ dist/tools/packer/scripts/vagrant.sh | 10 ++ dist/tools/packer/scripts/virtualbox.sh | 7 ++ dist/tools/packer/setup.sh | 159 ------------------------ dist/tools/packer/vagrantfile.tpl | 4 +- 15 files changed, 443 insertions(+), 265 deletions(-) create mode 100644 dist/tools/packer/http/preseed.cfg delete mode 100644 dist/tools/packer/preseed.cfg create mode 100644 dist/tools/packer/scripts/base.sh create mode 100644 dist/tools/packer/scripts/cleanup.sh create mode 100644 dist/tools/packer/scripts/riot.sh create mode 100644 dist/tools/packer/scripts/toolchains.sh create mode 100644 dist/tools/packer/scripts/udev_rules.sh create mode 100644 dist/tools/packer/scripts/vagrant.sh create mode 100644 dist/tools/packer/scripts/virtualbox.sh delete mode 100755 dist/tools/packer/setup.sh diff --git a/Vagrantfile b/Vagrantfile index 4e0c04aa6337..8ab07f32047d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -5,28 +5,20 @@ require 'fileutils' RIOTBASE ||= "./" -Vagrant.configure(2) do |config| - # For a complete reference, please see the online documentation at https://docs.vagrantup.com. - - config.vm.box = "RIOT/ubuntu1604" - - config.vm.provider "virtualbox" do |vb| - vb.name = "RIOT-VM" - - vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-interval", 10000] - vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust", 100] - vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore", 1] - vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000] - - # additional USB passthrough entries - # vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', '', '--vendorid', '', '--productid', ''] - end - - config.vm.synced_folder RIOTBASE, "/home/vagrant/RIOT" - - if File.exists?(File.join(Dir.home, ".gitconfig")) - config.vm.provision "file", source: File.join(Dir.home, ".gitconfig"), destination: ".gitconfig" - end -# use a custom provisioning script -# config.vm.provision "shell", path: "dist/tools/vagrant/bootstrap.sh" +Vagrant.configure("2") do |config| + config.vm.define "RIOT-VM" + config.vm.box = "RIOT/ubuntu1804" + config.ssh.username = "user" + config.vm.synced_folder RIOTBASE, "/home/user/RIOT" + + if File.exists?(File.join(Dir.home, ".gitconfig")) + config.vm.provision "file", source: File.join(Dir.home, ".gitconfig"), destination: ".gitconfig" + end + + config.vm.provider :virtualbox do |v, override| + v.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore", 0] + + # additional USB passthrough entries + # v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', '', '--vendorid', '', '--productid', ''] + end end diff --git a/dist/tools/packer/.gitignore b/dist/tools/packer/.gitignore index ec0d4e31174f..3a58627320b1 100644 --- a/dist/tools/packer/.gitignore +++ b/dist/tools/packer/.gitignore @@ -1,2 +1,3 @@ packer_cache +output-*-virtualbox-iso/ *.box diff --git a/dist/tools/packer/README.md b/dist/tools/packer/README.md index 89b2c3d8f82c..4c7708df5559 100644 --- a/dist/tools/packer/README.md +++ b/dist/tools/packer/README.md @@ -13,4 +13,4 @@ A simple build of the vagrant box can be done by: packer build riot.json ``` This command must be executed in the packer directory [RIOT/dist/tools/packer](https://github.com/RIOT-OS/RIOT/tree/master/dist/tools/packer). -Note that the build process might take several minutes. \ No newline at end of file +Note that the build process might take several minutes. diff --git a/dist/tools/packer/http/preseed.cfg b/dist/tools/packer/http/preseed.cfg new file mode 100644 index 000000000000..be1be6706d23 --- /dev/null +++ b/dist/tools/packer/http/preseed.cfg @@ -0,0 +1,43 @@ +#choose-mirror-bin mirror/http/proxy string +d-i base-installer/kernel/override-image string linux-server +d-i clock-setup/utc boolean true +d-i clock-setup/utc-auto boolean true +d-i finish-install/reboot_in_progress note +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i partman-auto-lvm/guided_size string max +d-i partman-auto/choose_recipe select atomic +d-i partman-auto/method string lvm +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm boolean true +d-i partman-lvm/confirm_nooverwrite boolean true +d-i partman-lvm/device_remove_lvm boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true +d-i partman/confirm_write_new_label boolean true + +# Default mirror +d-i mirror/country string FR +d-i mirror/http/hostname string ftp.fr.debian.org +d-i mirror/http/directory string /ubuntu +d-i mirror/http/proxy string +d-i mirror/http/mirror string ftp.fr.debian.org + +# Default user +d-i passwd/user-fullname string user +d-i passwd/username string user +d-i passwd/user-password password user +d-i passwd/user-password-again password user +d-i passwd/username string user + +# Minimum packages (see postinstall.sh) +d-i pkgsel/include string openssh-server +d-i pkgsel/install-language-support boolean true +d-i pkgsel/update-policy select none +d-i pkgsel/upgrade select none + +d-i time/zone string UTC +d-i user-setup/allow-password-weak boolean true +d-i user-setup/encrypt-home boolean false +tasksel tasksel/first multiselect standard, ubuntu-server diff --git a/dist/tools/packer/preseed.cfg b/dist/tools/packer/preseed.cfg deleted file mode 100644 index 30eaa4a1610d..000000000000 --- a/dist/tools/packer/preseed.cfg +++ /dev/null @@ -1,35 +0,0 @@ -choose-mirror-bin mirror/http/proxy string -d-i base-installer/kernel/override-image string linux-server -d-i clock-setup/utc boolean true -d-i clock-setup/utc-auto boolean true -d-i finish-install/reboot_in_progress note -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean true -d-i partman-auto-lvm/guided_size string max -d-i partman-auto/choose_recipe select atomic -d-i partman-auto/method string lvm -d-i partman-lvm/confirm boolean true -d-i partman-lvm/confirm_nooverwrite boolean true -d-i partman-lvm/device_remove_lvm boolean true -d-i partman/choose_partition select finish -d-i partman/confirm boolean true -d-i partman/confirm_nooverwrite boolean true -d-i partman/confirm_write_new_label boolean true -d-i user-setup/allow-password-weak boolean true -d-i user-setup/encrypt-home boolean false -d-i passwd/user-default-groups string adm cdrom dialout lxd plugdev sudo - -d-i pkgsel/include string openssh-server ntp curl nfs-common build-essential \ - linux-headers-$(uname -r) perl dkms pcregrep libpcre3 python3 git vim \ - gcc-arm-none-eabi gcc-msp430 unzip qemu-system-x86 g++-multilib \ - gcc-multilib gcc-avr binutils-avr avr-libc avrdude doxygen cppcheck \ - python-setuptools libusb-1.0-0 libusb-1.0-0-dev libudev-dev libftdi1 \ - libftdi-dev libftdipp1-dev libftdipp1-2v5 libhidapi-dev libhidapi-hidraw0 \ - libhidapi-libusb0 cmake autotools-dev autoconf pkg-config jimsh libtool \ - valgrind openocd python-serial python3-serial xsltproc dfu-util - -d-i pkgsel/install-language-support boolean false -d-i pkgsel/update-policy select none -d-i pkgsel/upgrade select full-upgrade -d-i time/zone string UTC -tasksel tasksel/first multiselect standard, server diff --git a/dist/tools/packer/riot.json b/dist/tools/packer/riot.json index d14c000489a1..ab21daee7525 100644 --- a/dist/tools/packer/riot.json +++ b/dist/tools/packer/riot.json @@ -1,25 +1,34 @@ { - "_comment": "Build with `packer build riot.json`", "builders": [ { + "type": "virtualbox-iso", "boot_command": [ - "{{ user `boot_command_prefix` }}", - "/install/vmlinuz noapic ", - "initrd=/install/initrd.gz ", - "file=/floppy/{{ user `preseed` }} ", - "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ", - "hostname={{ user `hostname` }} ", - "fb=false debconf/frontend=noninteractive ", - "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ", - "keyboard-configuration/variant=USA console-setup/ask_detect=false ", - "passwd/user-fullname={{ user `ssh_fullname` }} ", - "passwd/user-password={{ user `ssh_password` }} ", - "passwd/user-password-again={{ user `ssh_password` }} ", - "passwd/username={{ user `ssh_username` }} ", - "-- " + "", + "", + "", + "/install/vmlinuz", + " auto", + " console-setup/ask_detect=false", + " console-setup/layoutcode=us", + " console-setup/modelcode=pc105", + " debconf/frontend=noninteractive", + " debian-installer=en_US", + " fb=false", + " initrd=/install/initrd.gz", + " kbd-chooser/method=us", + " keyboard-configuration/layout=USA", + " keyboard-configuration/variant=USA", + " locale=en_US", + " netcfg/get_domain=vm", + " netcfg/get_hostname={{ user `hostname` }}", + " grub-installer/bootdev=/dev/sda", + " noapic", + " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", + " -- ", + "" ], + "boot_wait": "10s", "disk_size": "{{ user `disk_size` }}", - "floppy_files": [ "{{ user `preseed` }}" ], "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", "guest_os_type": "{{ user `virtualbox_guest_os_type` }}", "headless": "{{ user `headless` }}", @@ -27,30 +36,35 @@ "iso_checksum_type": "{{ user `iso_checksum_type` }}", "iso_urls": [ "{{ user `iso_path` }}/{{ user `iso_name` }}", "{{ user `iso_url` }}" ], "output_directory": "output-{{ user `vm_name` }}-virtualbox-iso", + "http_directory": "http", "shutdown_command": "echo '{{ user `ssh_password` }}'|sudo -S shutdown -P now", - "ssh_password": "{{ user `ssh_password` }}", "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "ssh_port": 22, "ssh_wait_timeout": "10000s", - "type": "virtualbox-iso", "vboxmanage": [ [ "modifyvm", "{{.Name}}", "--memory", "{{ user `memory` }}" ], [ "modifyvm", "{{.Name}}", "--cpus", "{{ user `cpus` }}" ], [ "modifyvm", "{{.Name}}", "--usb", "on" ], - [ "modifyvm", "{{.Name}}", "--usbxhci", "on" ], [ "modifyvm", "{{.Name}}", "--audio", "none"], [ "modifyvm", "{{.Name}}", "--ioapic", "on"], [ "modifyvm", "{{.Name}}", "--rtcuseutc", "on"], - [ "modifyvm", "{{.Name}}", "--clipboard", "bidirectional"], ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "FTDI USB-TTL", "--vendorid", "0x0403", "--productid", "0x6001"], ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "CP2102 USB to UART", "--vendorid", "0x10c4", "--productid", "0xea60"], ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "STM32 STLink", "--vendorid", "0x0483", "--productid", "0x3748"], + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "STM32 STLink", "--vendorid", "0x0483", "--productid", "0x374b"], ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "USBasp", "--vendorid", "0x16c0", "--productid", "0x05dc"], ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "iotlab-m3", "--vendorid", "0x0403", "--productid", "0x6010"], - ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "samr21-xpro", "--vendorid", "0x03eb", "--productid", "0x2111"], - ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Arduino Mega 2560", "--vendorid", "0x2341", "--productid", "0x0042"], + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "iotlab-m3-cn", "--vendorid", "0x0403", "--productid", "0x6011"], + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "CMSIS-DAP", "--vendorid", "0x03eb", "--productid", "0x2111"], + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Arduino UNO", "--vendorid", "0x2341", "--productid", "0x0042"], + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Arduino Mega 2560", "--vendorid", "0x2a03", "--productid", "0x0042"], ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Phytec phyWAVE KW22", "--vendorid", "0x0d28", "--productid", "0x0204"], ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Bluepill", "--vendorid", "0x1d50", "--productid", "0x6017"], - ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Bluepill", "--vendorid", "0x1d50", "--productid", "0x6018"] + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Bluepill", "--vendorid", "0x1d50", "--productid", "0x6018"], + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "JLink", "--vendorid", "0x1366", "--productid", "0x1015"], + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "Arduino Zero", "--vendorid", "0x03eb", "--productid", "0x2157"], + ["usbfilter", "add", "0", "--target", "{{.Name}}", "--name", "DAPLink", "--vendorid", "0x0d28", "--productid", "0x0204"] ], "virtualbox_version_file": ".vbox_version", "vm_name": "{{user `vm_name`}}" @@ -68,36 +82,39 @@ ], "provisioners": [ { - "type": "file", - "source": "./udev_rules", - "destination": "/tmp" - }, - { + "type": "shell", "environment_vars": [ - "SSH_USERNAME={{user `ssh_username`}}", - "SSH_PASSWORD={{user `ssh_password`}}" + "SSH_USERNAME={{ user `ssh_username` }}" ], - "execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -E -S bash '{{.Path}}'", - "scripts": [ "setup.sh" ], - "type": "shell" + "execute_command": "echo '{{ user `ssh_password` }}' | {{.Vars}} sudo -S -E bash '{{.Path}}'", + "override": { + "virtualbox-iso": { + "scripts": [ + "scripts/base.sh", + "scripts/vagrant.sh", + "scripts/riot.sh", + "scripts/toolchains.sh", + "scripts/udev_rules.sh", + "scripts/virtualbox.sh", + "scripts/cleanup.sh" + ] + } + } } ], "variables": { - "boot_command_prefix": "", - "cpus": "1", - "disk_size": "65536", + "cpus": "2", + "disk_size": "10240", "headless": "true", - "iso_checksum": "a06cd926f5855d4f21fb4bc9978a35312f815fbda0d0ef7fdc846861f4fc4600", + "iso_checksum": "e2ecdace33c939527cbc9e8d23576381c493b071107207d2040af72595f8990b", "iso_checksum_type": "sha256", - "iso_name": "ubuntu-16.04.3-server-amd64.iso", - "iso_path": "/Volumes/Storage/software/ubuntu", - "iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.3-server-amd64.iso", + "iso_name": "ubuntu-18.04.4-server-amd64.iso", + "iso_path": "iso", + "iso_url": "http://cdimage.ubuntu.com/ubuntu/releases/bionic/release/ubuntu-18.04.4-server-amd64.iso", "memory": "1024", - "preseed" : "preseed.cfg", - "hostname": "vagrant", - "ssh_fullname": "vagrant", - "ssh_password": "vagrant", - "ssh_username": "vagrant", + "hostname": "riot-vm", + "ssh_username": "user", + "ssh_password": "user", "vagrantfile_template": "vagrantfile.tpl", "virtualbox_guest_os_type": "Ubuntu_64", "vm_name": "RIOT-VM" diff --git a/dist/tools/packer/scripts/base.sh b/dist/tools/packer/scripts/base.sh new file mode 100644 index 000000000000..3be416d3e6b8 --- /dev/null +++ b/dist/tools/packer/scripts/base.sh @@ -0,0 +1,14 @@ +apt-get update +apt-get -y upgrade +apt-get -y install linux-headers-$(uname -r) + +# Fix locale setup +locale-gen +localectl set-locale LANG="en_US.UTF-8" + +# Allow usage of serial port +adduser ${SSH_USERNAME} dialout + +echo '%sudo ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers + +echo "UseDNS no" >> /etc/ssh/sshd_config diff --git a/dist/tools/packer/scripts/cleanup.sh b/dist/tools/packer/scripts/cleanup.sh new file mode 100644 index 000000000000..30a17dbb040f --- /dev/null +++ b/dist/tools/packer/scripts/cleanup.sh @@ -0,0 +1,91 @@ +apt-get -y upgrade +apt-get -y autoremove +apt-get -y clean + +echo "cleaning up guest additions" +rm -rf VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.? + +echo "cleaning permissions" +chown -R ${SSH_USERNAME}:${SSH_USERNAME} /home/${SSH_USERNAME} + +# Remove some packages to get a minimal install +echo "==> Removing all linux kernels except the current one" +dpkg --list | awk '{ print $2 }' | grep 'linux-image-*-generic' | grep -v $(uname -r) | xargs apt-get -y purge +echo "==> Removing linux source" +dpkg --list | awk '{ print $2 }' | grep linux-source | xargs apt-get -y purge +echo "==> Removing documentation" +dpkg --list | awk '{ print $2 }' | grep -- '-doc$' | xargs apt-get -y purge +echo "==> Removing default system Ruby" +apt-get -y purge ruby ri doc +echo "==> Removing obsolete networking components" +apt-get -y purge ppp pppconfig pppoeconf +echo "==> Removing other oddities" +apt-get -y purge popularity-contest installation-report landscape-common wireless-tools wpasupplicant + +# Clean up the apt cache +apt-get -y autoremove --purge +apt-get -y autoclean +apt-get -y clean + +echo "removing man pages" +rm -rf /usr/share/man/* +echo "removing APT files" +find /var/lib/apt -type f | xargs rm -f +echo "removing any docs" +rm -rf /usr/share/doc/* +echo "removing caches" +find /var/cache -type f -exec rm -rf {} \; + +echo "cleaning up tmp" +rm -rf /tmp/* + +# Remove Bash history +unset HISTFILE +rm -f /root/.bash_history +rm -f ${SSH_USER_HOME}/.bash_history + +# Clean up log files +find /var/log -type f | while read f; do echo -ne '' > "${f}"; done; + +echo "clearing last login information" +>/var/log/lastlog +>/var/log/wtmp +>/var/log/btmp + +echo "whiteout /" +count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}') +let count-- +dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count +rm /tmp/whitespace + +echo "whiteout /boot" +count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}') +let count-- +dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count +rm /boot/whitespace + +echo "clear out swap and disable until reboot" +set +e +swapuuid=$(/sbin/blkid -o value -l -s UUID -t TYPE=swap) +case "$?" in + 2|0) ;; + *) exit 1 ;; +esac +set -e +if [ "x${swapuuid}" != "x" ]; then + # Whiteout the swap partition to reduce box size + # Swap is disabled till reboot + swappart=$(readlink -f /dev/disk/by-uuid/$swapuuid) + /sbin/swapoff "${swappart}" + dd if=/dev/zero of="${swappart}" bs=1M || echo "dd exit code $? is suppressed" + /sbin/mkswap -U "${swapuuid}" "${swappart}" +fi + +echo "whiteout free space" +dd if=/dev/zero of=/EMPTY bs=1M || echo "dd exit code $? is suppressed" +rm -f /EMPTY + +sync + +echo "disk usage" +df -h diff --git a/dist/tools/packer/scripts/riot.sh b/dist/tools/packer/scripts/riot.sh new file mode 100644 index 000000000000..1681792a7a3b --- /dev/null +++ b/dist/tools/packer/scripts/riot.sh @@ -0,0 +1,41 @@ +apt-get update +apt-get install -y ccache clang cmake curl git build-essential vim python-setuptools \ + python-argparse python3-pip python-pip mosquitto-clients socat g++-multilib \ + net-tools pcregrep libpcre3 gcc-avr binutils-avr avr-libc \ + avrdude doxygen cppcheck valgrind coccinelle \ + gcc-msp430 mspdebug unzip pkg-config jimsh libtool \ + # + +DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true apt-get install -y tshark + +# Add .local/bin to PATH +# Required for Python packages installed in user home directory +echo "export PATH=\$PATH:/home/${SSH_USERNAME}/.local/bin" >> /home/${SSH_USERNAME}/.bashrc + +# IoT-LAB CLI tools +sudo -u /${SSH_USERNAME} pip3 install --user iotlabwscli iotlabsshcli iotlabcli + +# Python tools +sudo -u /${SSH_USERNAME} pip3 install --user aiocoap pyocd paho-mqtt pyserial flake8 tox \ + pyasn1 ecdsa pexpect pycrypto ed25519 cbor cryptography \ + scapy codespell protobuf jupyterlab \ + # + +# OpenOCD +apt-get install -y build-essential libftdi-dev libhidapi-dev \ + libusb-1.0-0-dev libudev-dev autoconf libsqlite3-dev \ + libpopt-dev libxml2-dev ruby libtool pkg-config + +git clone https://github.com/ntfreak/openocd openocd && \ + cd openocd && \ + git checkout 09ac9ab135ed35c846bcec4f7d468c3656852f26 && \ + ./bootstrap && ./configure && \ + make && \ + make install && \ + cd .. && rm -rf openocd + +# JLink +JLINK_PKG_DEB="JLink_Linux_V644g_x86_64.deb" +wget -nv http://demo-fit.saclay.inria.fr/vms/utils/${JLINK_PKG_DEB} && \ +dpkg -i ${JLINK_PKG_DEB} && \ +rm -f ${JLINK_PKG_DEB} diff --git a/dist/tools/packer/scripts/toolchains.sh b/dist/tools/packer/scripts/toolchains.sh new file mode 100644 index 000000000000..1406232ef451 --- /dev/null +++ b/dist/tools/packer/scripts/toolchains.sh @@ -0,0 +1,104 @@ +# Install ARM GNU Embedded toolchain +ARM_GCC_URL="https://developer.arm.com/-/media/Files/downloads/gnu-rm" +ARM_GCC_VERSION="9-2019q4" +ARM_GCC_ARCHIVE="gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2" +ARM_GCC_ARCHIVE_URL="${ARM_GCC_URL}/${ARM_GCC_VERSION}/${ARM_GCC_ARCHIVE}" + +cd /opt && wget -nv -O - "${ARM_GCC_ARCHIVE_URL}" | tar -jxf - + +echo "export PATH=/opt/gcc-arm-none-eabi-9-2019-q4-major/bin:\$PATH" >> /home/${SSH_USERNAME}/.bashrc + +# Install MIPS toolchain +MIPS_VERSION=2018.09-03 +curl -L "https://codescape.mips.com/components/toolchain/${MIPS_VERSION}/Codescape.GNU.Tools.Package.${MIPS_VERSION}.for.MIPS.MTI.Bare.Metal.CentOS-6.x86_64.tar.gz" -o - \ + | tar -C /opt -zx +rm -rf /opt/mips-mti-elf/*/share/{doc,info,man,locale} +cd /opt/mips-mti-elf/*/mips-mti-elf/bin +for f in *; do test -f "../../bin/mips-mti-elf-$f" && ln -f "../../bin/mips-mti-elf-$f" "$f"; done +cd - + +echo "export MIPS_ELF_ROOT=/opt/mips-mti-elf/${MIPS_VERSION}" >> /home/${SSH_USERNAME}/.bashrc +echo "export PATH=\$MIPS_ELF_ROOT/bin:\$PATH" >> /home/${SSH_USERNAME}/.bashrc + +# Install MSP430 toolchain +MSP430_URL=https://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/latest/exports +MSP430_VERSION=8.3.0.16_linux64 +wget -q ${MSP430_URL}/msp430-gcc-${MSP430_VERSION}.tar.bz2 -O- | tar -C /opt -xj +echo "export PATH=\$PATH:/opt/msp430-gcc-${MSP430_VERSION}/bin" >> /home/${SSH_USERNAME}/.bashrc + +# Install RISC-V +RISCV_VERSION=8.2.0-2.2-20190521 +RISCV_BUILD=0004 +wget -q https://github.com/gnu-mcu-eclipse/riscv-none-gcc/releases/download/v${RISCV_VERSION}/gnu-mcu-eclipse-riscv-none-gcc-${RISCV_VERSION}-${RISCV_BUILD}-centos64.tgz -O- \ + | tar -C /opt -xz +rm -rf /opt/gnu-mcu-eclipse/riscv-none-gcc/*/share/doc +cd /opt/gnu-mcu-eclipse/riscv-none-gcc/*/riscv-none-embed/bin +for f in *; do test -f "../../bin/riscv-none-embed-$f" && \ + ln -f "../../bin/riscv-none-embed-$f" "$f"; \ +done +cd - + +echo "export PATH=/opt/gnu-mcu-eclipse/riscv-none-gcc/${RISCV_VERSION}-${RISCV_BUILD}/bin:\$PATH" >> /home/${SSH_USERNAME}/.bashrc + +# Install ESP32 toolchain +echo 'Installing ESP32 toolchain' +mkdir -p /opt/esp +cd /opt/esp +git clone https://github.com/espressif/esp-idf.git +cd esp-idf +git checkout -q f198339ec09e90666150672884535802304d23ec +git submodule update --init --recursive +rm -rf .git* docs examples make tools +rm -f add_path.sh CONTRIBUTING.rst Kconfig Kconfig.compiler +cd components +rm -rf app_trace app_update aws_iot bootloader bt coap console cxx \ + esp_adc_cal espcoredump esp_http_client esp-tls expat fatfs \ + freertos idf_test jsmn json libsodium log lwip mbedtls mdns \ + micro-ecc nghttp openssl partition_table pthread sdmmc spiffs \ + tcpip_adapter ulp vfs wear_levelling xtensa-debug-module && \ +find . -name '*.[csS]' -exec rm {} \; +cd /opt/esp +git clone https://github.com/gschorcht/xtensa-esp32-elf.git && \ +cd xtensa-esp32-elf +git checkout -q ca40fb4c219accf8e7c8eab68f58a7fc14cadbab + +echo "export PATH=/opt/esp/xtensa-esp32-elf/bin:\$PATH" >> /home/${SSH_USERNAME}/.bashrc + +# Install ESP8266 toolchain +# Install complete ESP8266 toolchain in /opt/esp (146 MB after cleanup) +echo 'Installing ESP8266 toolchain' >&2 && \ + cd /opt && \ + git clone https://github.com/gschorcht/RIOT-Xtensa-ESP8266-toolchain.git esp && \ + cd esp && \ + git checkout -q df38b06 && \ + rm -rf .git + +echo "export PATH=\$PATH:/opt/esp/esp-open-sdk/xtensa-lx106-elf/bin" >> /home/${SSH_USERNAME}/.bashrc +echo "export ESP8266_SDK_DIR=/opt/esp/esp-open-sdk/sdk" >> /home/${SSH_USERNAME}/.bashrc +echo "export ESP8266_NEWLIB_DIR=/opt/esp/newlib-xtensa" >> /home/${SSH_USERNAME}/.bashrc + +# Install complete ESP8266 toolchain in /opt/esp (139 MB after cleanup) +# remember https://github.com/RIOT-OS/RIOT/pull/10801 when updating +# NOTE: We install the toolchain for the RTOS SDK in parallel in the first +# step and remove the old version as soon as the RIOT port for the ESP8266 +# RTOS SDK has been merged. +echo 'Installing ESP8266 toolchain' >&2 && \ + mkdir -p /opt/esp && \ + cd /opt/esp && \ + git clone https://github.com/gschorcht/xtensa-esp8266-elf && \ + cd xtensa-esp8266-elf && \ + git checkout -q 696257c2b43e2a107d3108b2c1ca6d5df3fb1a6f && \ + rm -rf .git && \ + cd /opt/esp && \ + git clone https://github.com/gschorcht/RIOT-Xtensa-ESP8266-RTOS-SDK.git ESP8266_RTOS_SDK && \ + cd ESP8266_RTOS_SDK/ && \ + git checkout -q f074414c0705715a44b8e59d53b03d90b7630382 && \ + rm -rf .git* docs examples make tools && \ + cd components && \ + rm -rf app_update aws_iot bootloader cjson coap espos esp-tls freertos \ + jsmn libsodium log mdns mqtt newlib partition_table pthread \ + smartconfig_ack spiffs ssl tcpip_adapter vfs && \ + find . -name '*.[csS]' -exec rm {} \; + +echo "export PATH=\$PATH:/opt/esp/xtensa-esp8266-elf/bin" >> /home/${SSH_USERNAME}/.bashrc +echo "export ESP8266_RTOS_SDK_DIR=/opt/esp/ESP8266_RTOS_SDK" >> /home/${SSH_USERNAME}/.bashrc diff --git a/dist/tools/packer/scripts/udev_rules.sh b/dist/tools/packer/scripts/udev_rules.sh new file mode 100644 index 000000000000..92226797b7fc --- /dev/null +++ b/dist/tools/packer/scripts/udev_rules.sh @@ -0,0 +1,50 @@ +# Udev rules +# JLink +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="1366", ATTRS{idProduct}=="1015", MODE="0664", GROUP="dialout"' \ + > /etc/udev/rules.d/riot-dev.rules + +# ST-Link +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", MODE="0664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3748", MODE="0666", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules + +# UBSASP +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", MODE="0666", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules + +# USBTTL +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", MODE="0666", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules + +# ATmega32u4 +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0036", MODE="0666", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules + +# ATmega2560 +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0042", MODE="0666", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules + +# CMSIS-DAP (EDBG) +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2111", MODE="0664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules +echo 'KERNEL=="hidraw*", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2111", MODE="664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules + +# Arduino Zero +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2157", MODE="0664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules +echo 'KERNEL=="hidraw*", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2157", MODE="664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules + +# DAPLink +echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0204", MODE="0664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules +echo 'KERNEL=="hidraw*", ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0204", MODE="664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules + +# IoT-LAB M3 +echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="6010", ATTR{idVendor}=="0403", MODE="0664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules +echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="6011", ATTR{idVendor}=="0403", MODE="0664", GROUP="dialout"' \ + >> /etc/udev/rules.d/riot-dev.rules diff --git a/dist/tools/packer/scripts/vagrant.sh b/dist/tools/packer/scripts/vagrant.sh new file mode 100644 index 000000000000..5b1bb7cd23d6 --- /dev/null +++ b/dist/tools/packer/scripts/vagrant.sh @@ -0,0 +1,10 @@ +date > /etc/vagrant_box_build_time + +mkdir /home/${SSH_USERNAME}/.ssh +wget --no-check-certificate \ + 'https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub' \ + -O /home/${SSH_USERNAME}/.ssh/authorized_keys +chown -R user /home/${SSH_USERNAME}/.ssh +chmod -R go-rwsx /home/${SSH_USERNAME}/.ssh +# Create SSH key pair +yes y | ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa diff --git a/dist/tools/packer/scripts/virtualbox.sh b/dist/tools/packer/scripts/virtualbox.sh new file mode 100644 index 000000000000..226a4f4a60e7 --- /dev/null +++ b/dist/tools/packer/scripts/virtualbox.sh @@ -0,0 +1,7 @@ +mkdir /tmp/virtualbox +VERSION=$(cat /home/${SSH_USERNAME}/.vbox_version) +mount -o loop /home/${SSH_USERNAME}/VBoxGuestAdditions_$VERSION.iso /tmp/virtualbox +sh /tmp/virtualbox/VBoxLinuxAdditions.run +umount /tmp/virtualbox +rmdir /tmp/virtualbox +rm /home/${SSH_USERNAME}/*.iso diff --git a/dist/tools/packer/setup.sh b/dist/tools/packer/setup.sh deleted file mode 100755 index c2e366cc5e9e..000000000000 --- a/dist/tools/packer/setup.sh +++ /dev/null @@ -1,159 +0,0 @@ -#!/usr/bin/env bash -eux - -# inspired by https://github.com/boxcutter/ubuntu - -echo "==> Disabling the release upgrader" -sed -i.bak 's/^Prompt=.*$/Prompt=never/' /etc/update-manager/release-upgrades - -systemctl disable apt-daily.service -systemctl disable apt-daily.timer - -echo "==> Updating list of repositories" -apt-get -y update - -echo "==> Performing dist-upgrade (all packages and kernel)" -DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade - -SSH_USER=${SSH_USERNAME:-vagrant} -SSH_PASS=${SSH_PASSWORD:-vagrant} -SSH_USER_HOME=${SSH_USER_HOME:-/home/${SSH_USER}} -VAGRANT_INSECURE_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" - -echo "==> Giving ${SSH_USER} sudo powers" -echo "${SSH_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant -chmod 440 /etc/sudoers.d/vagrant - -if grep -q -E "^mesg n$" /root/.profile && sed -i "s/^mesg n$/tty -s \\&\\& mesg n/g" /root/.profile; then - echo "==> Fixed stdin not being a tty." -fi - -echo "==> Installing vagrant key" -mkdir $SSH_USER_HOME/.ssh -chmod 700 $SSH_USER_HOME/.ssh - -# https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -echo "${VAGRANT_INSECURE_KEY}" > $SSH_USER_HOME/.ssh/authorized_keys -chmod 600 $SSH_USER_HOME/.ssh/authorized_keys -chown -R $SSH_USER:$SSH_USER $SSH_USER_HOME/.ssh - -echo "UseDNS no" >> /etc/ssh/sshd_config - -if [[ $PACKER_BUILDER_TYPE =~ virtualbox ]]; then - echo "==> Installing VirtualBox guest additions" - VBOX_VERSION=$(cat ${SSH_USER_HOME}/.vbox_version) - mount -o loop ${SSH_USER_HOME}/VBoxGuestAdditions_$VBOX_VERSION.iso /mnt - sh /mnt/VBoxLinuxAdditions.run - umount /mnt - rm ${SSH_USER_HOME}/VBoxGuestAdditions_$VBOX_VERSION.iso - rm ${SSH_USER_HOME}/.vbox_version -fi - -echo "==> Install stlink" -wget -qO - https://github.com/texane/stlink/archive/master.tar.gz | tar xz -mkdir stlink-master/build && cd stlink-master/build && cmake .. && make && make install -cd ../.. && rm -rf stlink.git - -echo "==> Install cli-tools" -wget -qO - https://github.com/iot-lab/cli-tools/archive/2.1.0.tar.gz | tar xz -cd cli-tools-* && python setup.py install && cd .. && rm -rf cli-tools-* - -# Remove some packages to get a minimal install -echo "==> Removing all linux kernels except the current one" -dpkg --list | awk '{ print $2 }' | grep 'linux-image-*-generic' | grep -v $(uname -r) | xargs apt-get -y purge -echo "==> Removing linux source" -dpkg --list | awk '{ print $2 }' | grep linux-source | xargs apt-get -y purge -echo "==> Removing documentation" -dpkg --list | awk '{ print $2 }' | grep -- '-doc$' | xargs apt-get -y purge -echo "==> Removing default system Ruby" -apt-get -y purge ruby ri doc -echo "==> Removing X11 libraries" -apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6 -echo "==> Removing obsolete networking components" -apt-get -y purge ppp pppconfig pppoeconf -echo "==> Removing other oddities" -apt-get -y purge popularity-contest installation-report landscape-common wireless-tools wpasupplicant - -# Clean up the apt cache -apt-get -y autoremove --purge -apt-get -y autoclean -apt-get -y clean - -# Clean up orphaned packages with deborphan -apt-get -y install deborphan -while [ -n "$(deborphan --guess-all --no-guesspython --libdevel)" ]; do - deborphan --guess-all --no-guess-python --libdevel | xargs apt-get -y purge -done -apt-get -y purge deborphan dialog - -echo "==> Removing man pages" -rm -rf /usr/share/man/* -echo "==> Removing APT files" -find /var/lib/apt -type f | xargs rm -f -echo "==> Removing any docs" -rm -rf /usr/share/doc/* -echo "==> Removing caches" -find /var/cache -type f -exec rm -rf {} \; - -echo "==> Cleaning up leftover dhcp leases" -if [ -d "/var/lib/dhcp" ]; then - rm /var/lib/dhcp/* -fi - -# Add delay to prevent "vagrant reload" from failing -echo "pre-up sleep 2" >> /etc/network/interfaces - -mv /tmp/udev_rules/* /etc/udev/rules.d/ - -echo "==> Cleaning up tmp" -rm -rf /tmp/* - -# Remove Bash history -unset HISTFILE -rm -f /root/.bash_history -rm -f ${SSH_USER_HOME}/.bash_history - -# Clean up log files -find /var/log -type f | while read f; do echo -ne '' > "${f}"; done; - -echo "==> Clearing last login information" ->/var/log/lastlog ->/var/log/wtmp ->/var/log/btmp - -echo "==> whiteout /" -count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}') -let count-- -dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count -rm /tmp/whitespace - -echo "==> whiteout /boot" -count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}') -let count-- -dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count -rm /boot/whitespace - -echo '==> Clear out swap and disable until reboot' -set +e -swapuuid=$(/sbin/blkid -o value -l -s UUID -t TYPE=swap) -case "$?" in - 2|0) ;; - *) exit 1 ;; -esac -set -e -if [ "x${swapuuid}" != "x" ]; then - # Whiteout the swap partition to reduce box size - # Swap is disabled till reboot - swappart=$(readlink -f /dev/disk/by-uuid/$swapuuid) - /sbin/swapoff "${swappart}" - dd if=/dev/zero of="${swappart}" bs=1M || echo "dd exit code $? is suppressed" - /sbin/mkswap -U "${swapuuid}" "${swappart}" -fi - -echo "==> whiteout free space" -dd if=/dev/zero of=/EMPTY bs=1M || echo "dd exit code $? is suppressed" -rm -f /EMPTY - -sync - -echo "==> Disk usage" -df -h diff --git a/dist/tools/packer/vagrantfile.tpl b/dist/tools/packer/vagrantfile.tpl index 352e680892d2..db583c9498e0 100644 --- a/dist/tools/packer/vagrantfile.tpl +++ b/dist/tools/packer/vagrantfile.tpl @@ -3,7 +3,9 @@ Vagrant.configure("2") do |config| config.vm.define "RIOT-VM" - config.vm.box = "RIOT/ubuntu1604" + config.vm.box = "RIOT/ubuntu1804" + config.ssh.username = "user" + config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.provider :virtualbox do |v, override| v.gui = false