1bf215546Sopenharmony_ci#!/bin/bash 2bf215546Sopenharmony_ci 3bf215546Sopenharmony_ci# Boot script for devices attached to a PoE switch, using NFS for the root 4bf215546Sopenharmony_ci# filesystem. 5bf215546Sopenharmony_ci 6bf215546Sopenharmony_ci# We're run from the root of the repo, make a helper var for our paths 7bf215546Sopenharmony_ciBM=$CI_PROJECT_DIR/install/bare-metal 8bf215546Sopenharmony_ciCI_COMMON=$CI_PROJECT_DIR/install/common 9bf215546Sopenharmony_ci 10bf215546Sopenharmony_ci# Runner config checks 11bf215546Sopenharmony_ciif [ -z "$BM_SERIAL" ]; then 12bf215546Sopenharmony_ci echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment" 13bf215546Sopenharmony_ci echo "This is the serial port to listen the device." 14bf215546Sopenharmony_ci exit 1 15bf215546Sopenharmony_cifi 16bf215546Sopenharmony_ci 17bf215546Sopenharmony_ciif [ -z "$BM_POE_ADDRESS" ]; then 18bf215546Sopenharmony_ci echo "Must set BM_POE_ADDRESS in your gitlab-runner config.toml [[runners]] environment" 19bf215546Sopenharmony_ci echo "This is the PoE switch address to connect for powering up/down devices." 20bf215546Sopenharmony_ci exit 1 21bf215546Sopenharmony_cifi 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ciif [ -z "$BM_POE_INTERFACE" ]; then 24bf215546Sopenharmony_ci echo "Must set BM_POE_INTERFACE in your gitlab-runner config.toml [[runners]] environment" 25bf215546Sopenharmony_ci echo "This is the PoE switch interface where the device is connected." 26bf215546Sopenharmony_ci exit 1 27bf215546Sopenharmony_cifi 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ciif [ -z "$BM_POWERUP" ]; then 30bf215546Sopenharmony_ci echo "Must set BM_POWERUP in your gitlab-runner config.toml [[runners]] environment" 31bf215546Sopenharmony_ci echo "This is a shell script that should power up the device and begin its boot sequence." 32bf215546Sopenharmony_ci exit 1 33bf215546Sopenharmony_cifi 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ciif [ -z "$BM_POWERDOWN" ]; then 36bf215546Sopenharmony_ci echo "Must set BM_POWERDOWN in your gitlab-runner config.toml [[runners]] environment" 37bf215546Sopenharmony_ci echo "This is a shell script that should power off the device." 38bf215546Sopenharmony_ci exit 1 39bf215546Sopenharmony_cifi 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ciif [ ! -d /nfs ]; then 42bf215546Sopenharmony_ci echo "NFS rootfs directory needs to be mounted at /nfs by the gitlab runner" 43bf215546Sopenharmony_ci exit 1 44bf215546Sopenharmony_cifi 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ciif [ ! -d /tftp ]; then 47bf215546Sopenharmony_ci echo "TFTP directory for this board needs to be mounted at /tftp by the gitlab runner" 48bf215546Sopenharmony_ci exit 1 49bf215546Sopenharmony_cifi 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci# job config checks 52bf215546Sopenharmony_ciif [ -z "$BM_ROOTFS" ]; then 53bf215546Sopenharmony_ci echo "Must set BM_ROOTFS to your board's rootfs directory in the job's variables" 54bf215546Sopenharmony_ci exit 1 55bf215546Sopenharmony_cifi 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ciif [ -z "$BM_BOOTFS" ]; then 58bf215546Sopenharmony_ci echo "Must set /boot files for the TFTP boot in the job's variables" 59bf215546Sopenharmony_ci exit 1 60bf215546Sopenharmony_cifi 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ciif [ -z "$BM_CMDLINE" ]; then 63bf215546Sopenharmony_ci echo "Must set BM_CMDLINE to your board's kernel command line arguments" 64bf215546Sopenharmony_ci exit 1 65bf215546Sopenharmony_cifi 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ciif [ -z "$BM_BOOTCONFIG" ]; then 68bf215546Sopenharmony_ci echo "Must set BM_BOOTCONFIG to your board's required boot configuration arguments" 69bf215546Sopenharmony_ci exit 1 70bf215546Sopenharmony_cifi 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ciset -ex 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci# Clear out any previous run's artifacts. 75bf215546Sopenharmony_cirm -rf results/ 76bf215546Sopenharmony_cimkdir -p results 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci# Create the rootfs in the NFS directory. rm to make sure it's in a pristine 79bf215546Sopenharmony_ci# state, since it's volume-mounted on the host. 80bf215546Sopenharmony_cirsync -a --delete $BM_ROOTFS/ /nfs/ 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci# If BM_BOOTFS is an URL, download it 83bf215546Sopenharmony_ciif echo $BM_BOOTFS | grep -q http; then 84bf215546Sopenharmony_ci apt install -y wget 85bf215546Sopenharmony_ci wget ${FDO_HTTP_CACHE_URI:-}$BM_BOOTFS -O /tmp/bootfs.tar 86bf215546Sopenharmony_ci BM_BOOTFS=/tmp/bootfs.tar 87bf215546Sopenharmony_cifi 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci# If BM_BOOTFS is a file, assume it is a tarball and uncompress it 90bf215546Sopenharmony_ciif [ -f $BM_BOOTFS ]; then 91bf215546Sopenharmony_ci mkdir -p /tmp/bootfs 92bf215546Sopenharmony_ci tar xf $BM_BOOTFS -C /tmp/bootfs 93bf215546Sopenharmony_ci BM_BOOTFS=/tmp/bootfs 94bf215546Sopenharmony_cifi 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci# Install kernel modules (it could be either in /lib/modules or 97bf215546Sopenharmony_ci# /usr/lib/modules, but we want to install in the latter) 98bf215546Sopenharmony_ci[ -d $BM_BOOTFS/usr/lib/modules ] && rsync -a $BM_BOOTFS/usr/lib/modules/ /nfs/usr/lib/modules/ 99bf215546Sopenharmony_ci[ -d $BM_BOOTFS/lib/modules ] && rsync -a $BM_BOOTFS/lib/modules/ /nfs/lib/modules/ 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci# Install kernel image + bootloader files 102bf215546Sopenharmony_cirsync -aL --delete $BM_BOOTFS/boot/ /tftp/ 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci# Set up the pxelinux config for Jetson Nano 105bf215546Sopenharmony_cimkdir -p /tftp/pxelinux.cfg 106bf215546Sopenharmony_cicat <<EOF >/tftp/pxelinux.cfg/default-arm-tegra210-p3450-0000 107bf215546Sopenharmony_ciPROMPT 0 108bf215546Sopenharmony_ciTIMEOUT 30 109bf215546Sopenharmony_ciDEFAULT primary 110bf215546Sopenharmony_ciMENU TITLE jetson nano boot options 111bf215546Sopenharmony_ciLABEL primary 112bf215546Sopenharmony_ci MENU LABEL CI kernel on TFTP 113bf215546Sopenharmony_ci LINUX Image 114bf215546Sopenharmony_ci FDT tegra210-p3450-0000.dtb 115bf215546Sopenharmony_ci APPEND \${cbootargs} $BM_CMDLINE 116bf215546Sopenharmony_ciEOF 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ci# Create the rootfs in the NFS directory 119bf215546Sopenharmony_cimkdir -p /nfs/results 120bf215546Sopenharmony_ci. $BM/rootfs-setup.sh /nfs 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ciecho "$BM_CMDLINE" > /tftp/cmdline.txt 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci# Add some required options in config.txt 125bf215546Sopenharmony_ciprintf "$BM_BOOTCONFIG" >> /tftp/config.txt 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ciset +e 128bf215546Sopenharmony_ciATTEMPTS=10 129bf215546Sopenharmony_ciwhile [ $((ATTEMPTS--)) -gt 0 ]; do 130bf215546Sopenharmony_ci python3 $BM/poe_run.py \ 131bf215546Sopenharmony_ci --dev="$BM_SERIAL" \ 132bf215546Sopenharmony_ci --powerup="$BM_POWERUP" \ 133bf215546Sopenharmony_ci --powerdown="$BM_POWERDOWN" \ 134bf215546Sopenharmony_ci --test-timeout ${TEST_PHASE_TIMEOUT:-20} 135bf215546Sopenharmony_ci ret=$? 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci if [ $ret -eq 2 ]; then 138bf215546Sopenharmony_ci echo "Did not detect boot sequence, retrying..." 139bf215546Sopenharmony_ci else 140bf215546Sopenharmony_ci ATTEMPTS=0 141bf215546Sopenharmony_ci fi 142bf215546Sopenharmony_cidone 143bf215546Sopenharmony_ciset -e 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_ci# Bring artifacts back from the NFS dir to the build dir where gitlab-runner 146bf215546Sopenharmony_ci# will look for them. 147bf215546Sopenharmony_cicp -Rp /nfs/results/. results/ 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ciexit $ret 150