| 1 |
#!/bin/bash |
| 2 |
# shellcheck disable=SC1091 |
| 3 |
# shellcheck disable=SC2034 |
| 4 |
# shellcheck disable=SC2059 |
| 5 |
# shellcheck disable=SC2086 # we want word splitting |
| 6 |
|
| 7 |
. "$SCRIPTS_DIR"/setup-test-env.sh |
| 8 |
|
| 9 |
# Boot script for devices attached to a PoE switch, using NFS for the root |
| 10 |
# filesystem. |
| 11 |
|
| 12 |
# We're run from the root of the repo, make a helper var for our paths |
| 13 |
BM=$CI_PROJECT_DIR/install/bare-metal |
| 14 |
CI_COMMON=$CI_PROJECT_DIR/install/common |
| 15 |
CI_INSTALL=$CI_PROJECT_DIR/install |
| 16 |
|
| 17 |
# Runner config checks |
| 18 |
if [ -z "$BM_SERIAL" ]; then |
| 19 |
echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment" |
| 20 |
echo "This is the serial port to listen the device." |
| 21 |
exit 1 |
| 22 |
fi |
| 23 |
|
| 24 |
if [ -z "$BM_POE_ADDRESS" ]; then |
| 25 |
echo "Must set BM_POE_ADDRESS in your gitlab-runner config.toml [[runners]] environment" |
| 26 |
echo "This is the PoE switch address to connect for powering up/down devices." |
| 27 |
exit 1 |
| 28 |
fi |
| 29 |
|
| 30 |
if [ -z "$BM_POE_INTERFACE" ]; then |
| 31 |
echo "Must set BM_POE_INTERFACE in your gitlab-runner config.toml [[runners]] environment" |
| 32 |
echo "This is the PoE switch interface where the device is connected." |
| 33 |
exit 1 |
| 34 |
fi |
| 35 |
|
| 36 |
if [ -z "$BM_POWERUP" ]; then |
| 37 |
echo "Must set BM_POWERUP in your gitlab-runner config.toml [[runners]] environment" |
| 38 |
echo "This is a shell script that should power up the device and begin its boot sequence." |
| 39 |
exit 1 |
| 40 |
fi |
| 41 |
|
| 42 |
if [ -z "$BM_POWERDOWN" ]; then |
| 43 |
echo "Must set BM_POWERDOWN in your gitlab-runner config.toml [[runners]] environment" |
| 44 |
echo "This is a shell script that should power off the device." |
| 45 |
exit 1 |
| 46 |
fi |
| 47 |
|
| 48 |
if [ ! -d /nfs ]; then |
| 49 |
echo "NFS rootfs directory needs to be mounted at /nfs by the gitlab runner" |
| 50 |
exit 1 |
| 51 |
fi |
| 52 |
|
| 53 |
if [ ! -d /tftp ]; then |
| 54 |
echo "TFTP directory for this board needs to be mounted at /tftp by the gitlab runner" |
| 55 |
exit 1 |
| 56 |
fi |
| 57 |
|
| 58 |
# job config checks |
| 59 |
if [ -z "$BM_ROOTFS" ]; then |
| 60 |
echo "Must set BM_ROOTFS to your board's rootfs directory in the job's variables" |
| 61 |
exit 1 |
| 62 |
fi |
| 63 |
|
| 64 |
if [ -z "$BM_BOOTFS" ] && { [ -z "$BM_KERNEL" ] || [ -z "$BM_DTB" ]; } ; then |
| 65 |
echo "Must set /boot files for the TFTP boot in the job's variables or set kernel and dtb" |
| 66 |
exit 1 |
| 67 |
fi |
| 68 |
|
| 69 |
if [ -z "$BM_CMDLINE" ]; then |
| 70 |
echo "Must set BM_CMDLINE to your board's kernel command line arguments" |
| 71 |
exit 1 |
| 72 |
fi |
| 73 |
|
| 74 |
section_start prepare_rootfs "Preparing rootfs components" |
| 75 |
|
| 76 |
set -ex |
| 77 |
|
| 78 |
date +'%F %T' |
| 79 |
|
| 80 |
# Clear out any previous run's artifacts. |
| 81 |
rm -rf results/ |
| 82 |
mkdir -p results |
| 83 |
|
| 84 |
# Create the rootfs in the NFS directory. rm to make sure it's in a pristine |
| 85 |
# state, since it's volume-mounted on the host. |
| 86 |
rsync -a --delete $BM_ROOTFS/ /nfs/ |
| 87 |
|
| 88 |
date +'%F %T' |
| 89 |
|
| 90 |
# If BM_BOOTFS is an URL, download it |
| 91 |
if echo $BM_BOOTFS | grep -q http; then |
| 92 |
curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \ |
| 93 |
"${FDO_HTTP_CACHE_URI:-}$BM_BOOTFS" -o /tmp/bootfs.tar |
| 94 |
BM_BOOTFS=/tmp/bootfs.tar |
| 95 |
fi |
| 96 |
|
| 97 |
date +'%F %T' |
| 98 |
|
| 99 |
# If BM_BOOTFS is a file, assume it is a tarball and uncompress it |
| 100 |
if [ -f "${BM_BOOTFS}" ]; then |
| 101 |
mkdir -p /tmp/bootfs |
| 102 |
tar xf $BM_BOOTFS -C /tmp/bootfs |
| 103 |
BM_BOOTFS=/tmp/bootfs |
| 104 |
fi |
| 105 |
|
| 106 |
date +'%F %T' |
| 107 |
|
| 108 |
# Install kernel modules (it could be either in /lib/modules or |
| 109 |
# /usr/lib/modules, but we want to install in the latter) |
| 110 |
if [ -n "${BM_BOOTFS}" ]; then |
| 111 |
[ -d $BM_BOOTFS/usr/lib/modules ] && rsync -a $BM_BOOTFS/usr/lib/modules/ /nfs/usr/lib/modules/ |
| 112 |
[ -d $BM_BOOTFS/lib/modules ] && rsync -a $BM_BOOTFS/lib/modules/ /nfs/lib/modules/ |
| 113 |
else |
| 114 |
echo "No modules!" |
| 115 |
fi |
| 116 |
|
| 117 |
|
| 118 |
date +'%F %T' |
| 119 |
|
| 120 |
# Install kernel image + bootloader files |
| 121 |
if [ -z "$BM_BOOTFS" ]; then |
| 122 |
mv "${BM_KERNEL}" "${BM_DTB}.dtb" /tftp/ |
| 123 |
else # BM_BOOTFS |
| 124 |
rsync -aL --delete $BM_BOOTFS/boot/ /tftp/ |
| 125 |
fi |
| 126 |
|
| 127 |
date +'%F %T' |
| 128 |
|
| 129 |
# Create the rootfs in the NFS directory |
| 130 |
. $BM/rootfs-setup.sh /nfs |
| 131 |
|
| 132 |
date +'%F %T' |
| 133 |
|
| 134 |
echo "$BM_CMDLINE" > /tftp/cmdline.txt |
| 135 |
|
| 136 |
# Add some options in config.txt, if defined |
| 137 |
if [ -n "$BM_BOOTCONFIG" ]; then |
| 138 |
printf "$BM_BOOTCONFIG" >> /tftp/config.txt |
| 139 |
fi |
| 140 |
|
| 141 |
section_end prepare_rootfs |
| 142 |
|
| 143 |
set +e |
| 144 |
STRUCTURED_LOG_FILE=results/job_detail.json |
| 145 |
export PYTHONPATH=$CI_INSTALL |
| 146 |
python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update dut_job_type "${DEVICE_TYPE}" |
| 147 |
python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update farm "${FARM}" |
| 148 |
ATTEMPTS=3 |
| 149 |
first_attempt=True |
| 150 |
while [ $((ATTEMPTS--)) -gt 0 ]; do |
| 151 |
section_start dut_boot "Booting hardware device ..." |
| 152 |
python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --create-dut-job dut_name "${CI_RUNNER_DESCRIPTION}" |
| 153 |
# Update subtime time to CI_JOB_STARTED_AT only for the first run |
| 154 |
if [ "$first_attempt" = "True" ]; then |
| 155 |
python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update-dut-time submit "${CI_JOB_STARTED_AT}" |
| 156 |
else |
| 157 |
python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update-dut-time submit |
| 158 |
fi |
| 159 |
python3 $BM/poe_run.py \ |
| 160 |
--dev="$BM_SERIAL" \ |
| 161 |
--powerup="$BM_POWERUP" \ |
| 162 |
--powerdown="$BM_POWERDOWN" \ |
| 163 |
--boot-timeout-seconds ${BOOT_PHASE_TIMEOUT_SECONDS:-300} \ |
| 164 |
--test-timeout-minutes ${TEST_PHASE_TIMEOUT_MINUTES:-$((CI_JOB_TIMEOUT/60 - ${TEST_SETUP_AND_UPLOAD_MARGIN_MINUTES:-5}))} |
| 165 |
ret=$? |
| 166 |
|
| 167 |
if [ $ret -eq 2 ]; then |
| 168 |
python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close-dut-job |
| 169 |
first_attempt=False |
| 170 |
error "Device failed to boot; will retry" |
| 171 |
else |
| 172 |
# We're no longer in dut_boot by this point |
| 173 |
unset CURRENT_SECTION |
| 174 |
ATTEMPTS=0 |
| 175 |
fi |
| 176 |
done |
| 177 |
|
| 178 |
section_start dut_cleanup "Cleaning up after job" |
| 179 |
python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close-dut-job |
| 180 |
python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close |
| 181 |
set -e |
| 182 |
|
| 183 |
date +'%F %T' |
| 184 |
|
| 185 |
# Bring artifacts back from the NFS dir to the build dir where gitlab-runner |
| 186 |
# will look for them. |
| 187 |
cp -Rp /nfs/results/. results/ |
| 188 |
|
| 189 |
date +'%F %T' |
| 190 |
section_end dut_cleanup |
| 191 |
|
| 192 |
exit $ret |