1bf215546Sopenharmony_ci#!/bin/bash
2bf215546Sopenharmony_ci
3bf215546Sopenharmony_ci# Boot script for Chrome OS devices attached to a servo debug connector, using
4bf215546Sopenharmony_ci# NFS and TFTP to boot.
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 CPU serial device."
14bf215546Sopenharmony_ci  exit 1
15bf215546Sopenharmony_cifi
16bf215546Sopenharmony_ci
17bf215546Sopenharmony_ciif [ -z "$BM_SERIAL_EC" ]; then
18bf215546Sopenharmony_ci  echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment"
19bf215546Sopenharmony_ci  echo "This is the EC serial device for controlling board power"
20bf215546Sopenharmony_ci  exit 1
21bf215546Sopenharmony_cifi
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_ciif [ ! -d /nfs ]; then
24bf215546Sopenharmony_ci  echo "NFS rootfs directory needs to be mounted at /nfs by the gitlab runner"
25bf215546Sopenharmony_ci  exit 1
26bf215546Sopenharmony_cifi
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ciif [ ! -d /tftp ]; then
29bf215546Sopenharmony_ci  echo "TFTP directory for this board needs to be mounted at /tftp by the gitlab runner"
30bf215546Sopenharmony_ci  exit 1
31bf215546Sopenharmony_cifi
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci# job config checks
34bf215546Sopenharmony_ciif [ -z "$BM_KERNEL" ]; then
35bf215546Sopenharmony_ci  echo "Must set BM_KERNEL to your board's kernel FIT image"
36bf215546Sopenharmony_ci  exit 1
37bf215546Sopenharmony_cifi
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ciif [ -z "$BM_ROOTFS" ]; then
40bf215546Sopenharmony_ci  echo "Must set BM_ROOTFS to your board's rootfs directory in the job's variables"
41bf215546Sopenharmony_ci  exit 1
42bf215546Sopenharmony_cifi
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ciif [ -z "$BM_CMDLINE" ]; then
45bf215546Sopenharmony_ci  echo "Must set BM_CMDLINE to your board's kernel command line arguments"
46bf215546Sopenharmony_ci  exit 1
47bf215546Sopenharmony_cifi
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ciset -ex
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci# Clear out any previous run's artifacts.
52bf215546Sopenharmony_cirm -rf results/
53bf215546Sopenharmony_cimkdir -p results
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci# Create the rootfs in the NFS directory.  rm to make sure it's in a pristine
56bf215546Sopenharmony_ci# state, since it's volume-mounted on the host.
57bf215546Sopenharmony_cirsync -a --delete $BM_ROOTFS/ /nfs/
58bf215546Sopenharmony_cimkdir -p /nfs/results
59bf215546Sopenharmony_ci. $BM/rootfs-setup.sh /nfs
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci# Put the kernel/dtb image and the boot command line in the tftp directory for
62bf215546Sopenharmony_ci# the board to find.  For normal Mesa development, we build the kernel and
63bf215546Sopenharmony_ci# store it in the docker container that this script is running in.
64bf215546Sopenharmony_ci#
65bf215546Sopenharmony_ci# However, container builds are expensive, so when you're hacking on the
66bf215546Sopenharmony_ci# kernel, it's nice to be able to skip the half hour container build and plus
67bf215546Sopenharmony_ci# moving that container to the runner.  So, if BM_KERNEL is a URL, fetch it
68bf215546Sopenharmony_ci# instead of looking in the container.  Note that the kernel build should be
69bf215546Sopenharmony_ci# the output of:
70bf215546Sopenharmony_ci#
71bf215546Sopenharmony_ci# make Image.lzma
72bf215546Sopenharmony_ci#
73bf215546Sopenharmony_ci# mkimage \
74bf215546Sopenharmony_ci#  -A arm64 \
75bf215546Sopenharmony_ci#  -f auto \
76bf215546Sopenharmony_ci#  -C lzma \
77bf215546Sopenharmony_ci#  -d arch/arm64/boot/Image.lzma \
78bf215546Sopenharmony_ci#  -b arch/arm64/boot/dts/qcom/sdm845-cheza-r3.dtb \
79bf215546Sopenharmony_ci#  cheza-image.img
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_cirm -rf /tftp/*
82bf215546Sopenharmony_ciif echo "$BM_KERNEL" | grep -q http; then
83bf215546Sopenharmony_ci  apt install -y wget
84bf215546Sopenharmony_ci  wget $BM_KERNEL -O /tftp/vmlinuz
85bf215546Sopenharmony_cielse
86bf215546Sopenharmony_ci  cp $BM_KERNEL /tftp/vmlinuz
87bf215546Sopenharmony_cifi
88bf215546Sopenharmony_ciecho "$BM_CMDLINE" > /tftp/cmdline
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ciset +e
91bf215546Sopenharmony_cipython3 $BM/cros_servo_run.py \
92bf215546Sopenharmony_ci        --cpu $BM_SERIAL \
93bf215546Sopenharmony_ci        --ec $BM_SERIAL_EC \
94bf215546Sopenharmony_ci        --test-timeout ${TEST_PHASE_TIMEOUT:-20}
95bf215546Sopenharmony_ciret=$?
96bf215546Sopenharmony_ciset -e
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci# Bring artifacts back from the NFS dir to the build dir where gitlab-runner
99bf215546Sopenharmony_ci# will look for them.
100bf215546Sopenharmony_cicp -Rp /nfs/results/. results/
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ciexit $ret
103