ci/bare-metal: Use a new serial buffer tool.
[mesa.git] / .gitlab-ci / bare-metal / cros-servo.sh
1 #!/bin/bash
2
3 # Boot script for Chrome OS devices attached to a servo debug connector, using
4 # NFS and TFTP to boot.
5
6 # We're run from the root of the repo, make a helper var for our paths
7 BM=$CI_PROJECT_DIR/install/bare-metal
8
9 # Runner config checks
10 if [ -z "$BM_SERIAL" ]; then
11 echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment"
12 echo "This is the CPU serial device."
13 exit 1
14 fi
15
16 if [ -z "$BM_SERIAL_EC" ]; then
17 echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment"
18 echo "This is the EC serial device for controlling board power"
19 exit 1
20 fi
21
22 if [ ! -d /nfs ]; then
23 echo "NFS rootfs directory needs to be mounted at /nfs by the gitlab runner"
24 exit 1
25 fi
26
27 if [ ! -d /tftp ]; then
28 echo "TFTP directory for this board needs to be mounted at /tftp by the gitlab runner"
29 exit 1
30 fi
31
32 # job config checks
33 if [ -z "$BM_KERNEL" ]; then
34 echo "Must set BM_KERNEL to your board's kernel FIT image"
35 exit 1
36 fi
37
38 if [ -z "$BM_ROOTFS" ]; then
39 echo "Must set BM_ROOTFS to your board's rootfs directory in the job's variables"
40 exit 1
41 fi
42
43 if [ -z "$BM_CMDLINE" ]; then
44 echo "Must set BM_CMDLINE to your board's kernel command line arguments"
45 exit 1
46 fi
47
48 set -ex
49
50 # Clear out any previous run's artifacts.
51 rm -rf results/
52 mkdir -p results
53 find artifacts/ -name serial\*.txt | xargs rm -f
54
55 # Create the rootfs in the NFS directory. rm to make sure it's in a pristine
56 # state, since it's volume-mounted on the host.
57 rsync -a --delete $BM_ROOTFS/ /nfs/
58 mkdir -p /nfs/results
59 . $BM/rootfs-setup.sh /nfs
60
61 # Set up the TFTP kernel/cmdline. When we support more than one board with
62 # this method, we'll need to do some check on the runner name or something.
63 rm -rf /tftp/*
64 cp $BM_KERNEL /tftp/vmlinuz
65 echo "$BM_CMDLINE" > /tftp/cmdline
66
67 # Start watching serials, and power up the device.
68 python3 $BM/serial_buffer.py \
69 --dev $BM_SERIAL_EC \
70 --file serial-ec-output.txt \
71 --prefix "SERIAL-EC> " &
72 python3 $BM/serial_buffer.py \
73 --dev $BM_SERIAL \
74 --file serial-output.txt \
75 --prefix "SERIAL-CPU> " &
76
77 while [ ! -e serial-output.txt ]; do
78 sleep 1
79 done
80 # Flush any partial commands in the EC's prompt, then ask for a reboot.
81 $BM/write-serial.py $BM_SERIAL_EC ""
82 $BM/write-serial.py $BM_SERIAL_EC reboot
83
84 # This is emitted right when the bootloader pauses to check for input. Emit a
85 # ^N character to request network boot, because we don't have a
86 # direct-to-netboot firmware on cheza.
87 $BM/expect-output.sh serial-output.txt -f "load_archive: loading locale_en.bin"
88 $BM/write-serial.py $BM_SERIAL `printf '\016'`
89
90 # Wait for the device to complete the deqp run
91 $BM/expect-output.sh serial-output.txt \
92 -f "bare-metal result" \
93 -e "---. end Kernel panic" \
94 -e "POWER_GOOD not seen in time"
95
96 # power down the CPU on the device
97 $BM/write-serial.py $BM_SERIAL_EC 'power off'
98
99 set -ex
100
101 # Bring artifacts back from the NFS dir to the build dir where gitlab-runner
102 # will look for them. Note that results/ may already exist, so be careful
103 # with cp.
104 mkdir -p results
105 cp -Rp /nfs/results/. results/
106
107 set +e
108 if grep -q "bare-metal result: pass" serial-output.txt; then
109 exit 0
110 else
111 exit 1
112 fi