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