• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# shellcheck disable=SC1091 # The relative paths in this file only become valid at runtime.
3# shellcheck disable=SC2034
4# shellcheck disable=SC2086 # we want word splitting
5
6# Boot script for Chrome OS devices attached to a servo debug connector, using
7# NFS and TFTP to boot.
8
9# We're run from the root of the repo, make a helper var for our paths
10BM=$CI_PROJECT_DIR/install/bare-metal
11CI_COMMON=$CI_PROJECT_DIR/install/common
12CI_INSTALL=$CI_PROJECT_DIR/install
13
14# Runner config checks
15if [ -z "$BM_SERIAL" ]; then
16  echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment"
17  echo "This is the CPU serial device."
18  exit 1
19fi
20
21if [ -z "$BM_SERIAL_EC" ]; then
22  echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment"
23  echo "This is the EC serial device for controlling board power"
24  exit 1
25fi
26
27if [ ! -d /nfs ]; then
28  echo "NFS rootfs directory needs to be mounted at /nfs by the gitlab runner"
29  exit 1
30fi
31
32if [ ! -d /tftp ]; then
33  echo "TFTP directory for this board needs to be mounted at /tftp by the gitlab runner"
34  exit 1
35fi
36
37# job config checks
38if [ -z "$BM_KERNEL" ]; then
39  echo "Must set BM_KERNEL to your board's kernel FIT image"
40  exit 1
41fi
42
43if [ -z "$BM_ROOTFS" ]; then
44  echo "Must set BM_ROOTFS to your board's rootfs directory in the job's variables"
45  exit 1
46fi
47
48if [ -z "$BM_CMDLINE" ]; then
49  echo "Must set BM_CMDLINE to your board's kernel command line arguments"
50  exit 1
51fi
52
53set -ex
54
55# Clear out any previous run's artifacts.
56rm -rf results/
57mkdir -p results
58
59# Create the rootfs in the NFS directory.  rm to make sure it's in a pristine
60# state, since it's volume-mounted on the host.
61rsync -a --delete $BM_ROOTFS/ /nfs/
62mkdir -p /nfs/results
63. $BM/rootfs-setup.sh /nfs
64
65# Put the kernel/dtb image and the boot command line in the tftp directory for
66# the board to find.  For normal Mesa development, we build the kernel and
67# store it in the docker container that this script is running in.
68#
69# However, container builds are expensive, so when you're hacking on the
70# kernel, it's nice to be able to skip the half hour container build and plus
71# moving that container to the runner.  So, if BM_KERNEL is a URL, fetch it
72# instead of looking in the container.  Note that the kernel build should be
73# the output of:
74#
75# make Image.lzma
76#
77# mkimage \
78#  -A arm64 \
79#  -f auto \
80#  -C lzma \
81#  -d arch/arm64/boot/Image.lzma \
82#  -b arch/arm64/boot/dts/qcom/sdm845-cheza-r3.dtb \
83#  cheza-image.img
84
85rm -rf /tftp/*
86if echo "$BM_KERNEL" | grep -q http; then
87  curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
88      $BM_KERNEL -o /tftp/vmlinuz
89elif [ -n "${FORCE_KERNEL_TAG}" ]; then
90  curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
91    "${FDO_HTTP_CACHE_URI:-}${KERNEL_IMAGE_BASE}/${DEBIAN_ARCH}/${BM_KERNEL}" -o /tftp/vmlinuz
92  curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
93    "${FDO_HTTP_CACHE_URI:-}${KERNEL_IMAGE_BASE}/${DEBIAN_ARCH}/modules.tar.zst" -o modules.tar.zst
94  tar --keep-directory-symlink --zstd -xf modules.tar.zst -C "/nfs/"
95  rm modules.tar.zst &
96else
97  cp /baremetal-files/"$BM_KERNEL" /tftp/vmlinuz
98fi
99echo "$BM_CMDLINE" > /tftp/cmdline
100
101set +e
102STRUCTURED_LOG_FILE=job_detail.json
103python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update dut_job_type "${DEVICE_TYPE}"
104python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update farm "${FARM}"
105python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --create-dut-job dut_name "${CI_RUNNER_DESCRIPTION}"
106python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update-dut-time submit "${CI_JOB_STARTED_AT}"
107python3 $BM/cros_servo_run.py \
108        --cpu $BM_SERIAL \
109        --ec $BM_SERIAL_EC \
110        --test-timeout ${TEST_PHASE_TIMEOUT:-20}
111ret=$?
112python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close-dut-job
113python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close
114set -e
115
116# Bring artifacts back from the NFS dir to the build dir where gitlab-runner
117# will look for them.
118cp -Rp /nfs/results/. results/
119if [ -f "${STRUCTURED_LOG_FILE}" ]; then
120  cp -p ${STRUCTURED_LOG_FILE} results/
121  echo "Structured log file is available at https://${CI_PROJECT_ROOT_NAMESPACE}.pages.freedesktop.org/-/${CI_PROJECT_NAME}/-/jobs/${CI_JOB_ID}/artifacts/results/${STRUCTURED_LOG_FILE}"
122fi
123
124exit $ret
125