17ec681f3Smrg#!/bin/bash 27ec681f3Smrg 37ec681f3Smrg# Boot script for Chrome OS devices attached to a servo debug connector, using 47ec681f3Smrg# NFS and TFTP to boot. 57ec681f3Smrg 67ec681f3Smrg# We're run from the root of the repo, make a helper var for our paths 77ec681f3SmrgBM=$CI_PROJECT_DIR/install/bare-metal 87ec681f3SmrgCI_COMMON=$CI_PROJECT_DIR/install/common 97ec681f3Smrg 107ec681f3Smrg# Runner config checks 117ec681f3Smrgif [ -z "$BM_SERIAL" ]; then 127ec681f3Smrg echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment" 137ec681f3Smrg echo "This is the CPU serial device." 147ec681f3Smrg exit 1 157ec681f3Smrgfi 167ec681f3Smrg 177ec681f3Smrgif [ -z "$BM_SERIAL_EC" ]; then 187ec681f3Smrg echo "Must set BM_SERIAL in your gitlab-runner config.toml [[runners]] environment" 197ec681f3Smrg echo "This is the EC serial device for controlling board power" 207ec681f3Smrg exit 1 217ec681f3Smrgfi 227ec681f3Smrg 237ec681f3Smrgif [ ! -d /nfs ]; then 247ec681f3Smrg echo "NFS rootfs directory needs to be mounted at /nfs by the gitlab runner" 257ec681f3Smrg exit 1 267ec681f3Smrgfi 277ec681f3Smrg 287ec681f3Smrgif [ ! -d /tftp ]; then 297ec681f3Smrg echo "TFTP directory for this board needs to be mounted at /tftp by the gitlab runner" 307ec681f3Smrg exit 1 317ec681f3Smrgfi 327ec681f3Smrg 337ec681f3Smrg# job config checks 347ec681f3Smrgif [ -z "$BM_KERNEL" ]; then 357ec681f3Smrg echo "Must set BM_KERNEL to your board's kernel FIT image" 367ec681f3Smrg exit 1 377ec681f3Smrgfi 387ec681f3Smrg 397ec681f3Smrgif [ -z "$BM_ROOTFS" ]; then 407ec681f3Smrg echo "Must set BM_ROOTFS to your board's rootfs directory in the job's variables" 417ec681f3Smrg exit 1 427ec681f3Smrgfi 437ec681f3Smrg 447ec681f3Smrgif [ -z "$BM_CMDLINE" ]; then 457ec681f3Smrg echo "Must set BM_CMDLINE to your board's kernel command line arguments" 467ec681f3Smrg exit 1 477ec681f3Smrgfi 487ec681f3Smrg 497ec681f3Smrgset -ex 507ec681f3Smrg 517ec681f3Smrg# Clear out any previous run's artifacts. 527ec681f3Smrgrm -rf results/ 537ec681f3Smrgmkdir -p results 547ec681f3Smrg 557ec681f3Smrg# Create the rootfs in the NFS directory. rm to make sure it's in a pristine 567ec681f3Smrg# state, since it's volume-mounted on the host. 577ec681f3Smrgrsync -a --delete $BM_ROOTFS/ /nfs/ 587ec681f3Smrgmkdir -p /nfs/results 597ec681f3Smrg. $BM/rootfs-setup.sh /nfs 607ec681f3Smrg 617ec681f3Smrg# Put the kernel/dtb image and the boot command line in the tftp directory for 627ec681f3Smrg# the board to find. For normal Mesa development, we build the kernel and 637ec681f3Smrg# store it in the docker container that this script is running in. 647ec681f3Smrg# 657ec681f3Smrg# However, container builds are expensive, so when you're hacking on the 667ec681f3Smrg# kernel, it's nice to be able to skip the half hour container build and plus 677ec681f3Smrg# moving that container to the runner. So, if BM_KERNEL is a URL, fetch it 687ec681f3Smrg# instead of looking in the container. Note that the kernel build should be 697ec681f3Smrg# the output of: 707ec681f3Smrg# 717ec681f3Smrg# make Image.lzma 727ec681f3Smrg# 737ec681f3Smrg# mkimage \ 747ec681f3Smrg# -A arm64 \ 757ec681f3Smrg# -f auto \ 767ec681f3Smrg# -C lzma \ 777ec681f3Smrg# -d arch/arm64/boot/Image.lzma \ 787ec681f3Smrg# -b arch/arm64/boot/dts/qcom/sdm845-cheza-r3.dtb \ 797ec681f3Smrg# cheza-image.img 807ec681f3Smrg 817ec681f3Smrgrm -rf /tftp/* 827ec681f3Smrgif echo "$BM_KERNEL" | grep -q http; then 837ec681f3Smrg apt install -y wget 847ec681f3Smrg wget $BM_KERNEL -O /tftp/vmlinuz 857ec681f3Smrgelse 867ec681f3Smrg cp $BM_KERNEL /tftp/vmlinuz 877ec681f3Smrgfi 887ec681f3Smrgecho "$BM_CMDLINE" > /tftp/cmdline 897ec681f3Smrg 907ec681f3Smrgset +e 917ec681f3Smrgpython3 $BM/cros_servo_run.py \ 927ec681f3Smrg --cpu $BM_SERIAL \ 937ec681f3Smrg --ec $BM_SERIAL_EC 947ec681f3Smrgret=$? 957ec681f3Smrgset -e 967ec681f3Smrg 977ec681f3Smrg# Bring artifacts back from the NFS dir to the build dir where gitlab-runner 987ec681f3Smrg# will look for them. 997ec681f3Smrgcp -Rp /nfs/results/. results/ 1007ec681f3Smrg 1017ec681f3Smrgexit $ret 102