• 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
53. "${SCRIPTS_DIR}/setup-test-env.sh"
54
55section_start prepare_rootfs "Preparing rootfs components"
56
57set -ex
58
59# Clear out any previous run's artifacts.
60rm -rf results/
61mkdir -p results
62
63# Create the rootfs in the NFS directory.  rm to make sure it's in a pristine
64# state, since it's volume-mounted on the host.
65rsync -a --delete $BM_ROOTFS/ /nfs/
66mkdir -p /nfs/results
67. $BM/rootfs-setup.sh /nfs
68
69# Put the kernel/dtb image and the boot command line in the tftp directory for
70# the board to find.  For normal Mesa development, we build the kernel and
71# store it in the docker container that this script is running in.
72#
73# However, container builds are expensive, so when you're hacking on the
74# kernel, it's nice to be able to skip the half hour container build and plus
75# moving that container to the runner.  So, if BM_KERNEL is a URL, fetch it
76# instead of looking in the container.  Note that the kernel build should be
77# the output of:
78#
79# make Image.lzma
80#
81# mkimage \
82#  -A arm64 \
83#  -f auto \
84#  -C lzma \
85#  -d arch/arm64/boot/Image.lzma \
86#  -b arch/arm64/boot/dts/qcom/sdm845-cheza-r3.dtb \
87#  cheza-image.img
88
89rm -rf /tftp/*
90if echo "$BM_KERNEL" | grep -q http; then
91  curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
92      $BM_KERNEL -o /tftp/vmlinuz
93elif [ -n "${EXTERNAL_KERNEL_TAG}" ]; then
94  curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
95    "${FDO_HTTP_CACHE_URI:-}${KERNEL_IMAGE_BASE}/${DEBIAN_ARCH}/${BM_KERNEL}" -o /tftp/vmlinuz
96  curl -L --retry 4 -f --retry-all-errors --retry-delay 60 \
97    "${FDO_HTTP_CACHE_URI:-}${KERNEL_IMAGE_BASE}/${DEBIAN_ARCH}/modules.tar.zst" -o modules.tar.zst
98  tar --keep-directory-symlink --zstd -xf modules.tar.zst -C "/nfs/"
99  rm modules.tar.zst &
100else
101  cp /baremetal-files/"$BM_KERNEL" /tftp/vmlinuz
102fi
103echo "$BM_CMDLINE" > /tftp/cmdline
104
105set +e
106STRUCTURED_LOG_FILE=results/job_detail.json
107python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update dut_job_type "${DEVICE_TYPE}"
108python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update farm "${FARM}"
109python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --create-dut-job dut_name "${CI_RUNNER_DESCRIPTION}"
110python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --update-dut-time submit "${CI_JOB_STARTED_AT}"
111section_end prepare_rootfs
112
113python3 $BM/cros_servo_run.py \
114        --cpu $BM_SERIAL \
115        --ec $BM_SERIAL_EC \
116        --test-timeout ${TEST_PHASE_TIMEOUT_MINUTES:-20}
117ret=$?
118
119section_start dut_cleanup "Cleaning up after job"
120python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close-dut-job
121python3 $CI_INSTALL/custom_logger.py ${STRUCTURED_LOG_FILE} --close
122set -e
123
124# Bring artifacts back from the NFS dir to the build dir where gitlab-runner
125# will look for them.
126cp -Rp /nfs/results/. results/
127section_end dut_cleanup
128
129exit $ret
130