xref: /linux/drivers/gpu/drm/ci/build.sh (revision ef9226cd56b718c79184a3466d32984a51cb449c)
1#!/bin/bash
2# SPDX-License-Identifier: MIT
3
4set -ex
5
6# Clean up stale rebases that GitLab might not have removed when reusing a checkout dir
7rm -rf .git/rebase-apply
8
9. .gitlab-ci/container/container_pre_build.sh
10
11# libssl-dev was uninstalled because it was considered an ephemeral package
12apt-get update
13apt-get install -y libssl-dev
14
15if [[ "$KERNEL_ARCH" = "arm64" ]]; then
16    GCC_ARCH="aarch64-linux-gnu"
17    DEBIAN_ARCH="arm64"
18    DEVICE_TREES="arch/arm64/boot/dts/rockchip/rk3399-gru-kevin.dtb"
19    DEVICE_TREES+=" arch/arm64/boot/dts/amlogic/meson-gxl-s805x-libretech-ac.dtb"
20    DEVICE_TREES+=" arch/arm64/boot/dts/allwinner/sun50i-h6-pine-h64.dtb"
21    DEVICE_TREES+=" arch/arm64/boot/dts/amlogic/meson-gxm-khadas-vim2.dtb"
22    DEVICE_TREES+=" arch/arm64/boot/dts/qcom/apq8016-sbc-usb-host.dtb"
23    DEVICE_TREES+=" arch/arm64/boot/dts/qcom/apq8096-db820c.dtb"
24    DEVICE_TREES+=" arch/arm64/boot/dts/amlogic/meson-g12b-a311d-khadas-vim3.dtb"
25    DEVICE_TREES+=" arch/arm64/boot/dts/mediatek/mt8173-elm-hana.dtb"
26    DEVICE_TREES+=" arch/arm64/boot/dts/mediatek/mt8183-kukui-jacuzzi-juniper-sku16.dtb"
27    DEVICE_TREES+=" arch/arm64/boot/dts/mediatek/mt8192-asurada-spherion-r0.dtb"
28    DEVICE_TREES+=" arch/arm64/boot/dts/qcom/sc7180-trogdor-lazor-limozeen-nots-r5.dtb"
29    DEVICE_TREES+=" arch/arm64/boot/dts/qcom/sc7180-trogdor-kingoftown.dtb"
30elif [[ "$KERNEL_ARCH" = "arm" ]]; then
31    GCC_ARCH="arm-linux-gnueabihf"
32    DEBIAN_ARCH="armhf"
33    DEVICE_TREES="arch/arm/boot/dts/rockchip/rk3288-veyron-jaq.dtb"
34    DEVICE_TREES+=" arch/arm/boot/dts/allwinner/sun8i-h3-libretech-all-h3-cc.dtb"
35    DEVICE_TREES+=" arch/arm/boot/dts/nxp/imx/imx6q-cubox-i.dtb"
36    apt-get install -y libssl-dev:armhf
37else
38    GCC_ARCH="x86_64-linux-gnu"
39    DEBIAN_ARCH="amd64"
40    DEVICE_TREES=""
41fi
42
43export ARCH=${KERNEL_ARCH}
44export CROSS_COMPILE="${GCC_ARCH}-"
45
46# The kernel doesn't like the gold linker (or the old lld in our debians).
47# Sneak in some override symlinks during kernel build until we can update
48# debian.
49mkdir -p ld-links
50for i in /usr/bin/*-ld /usr/bin/ld; do
51    i=$(basename $i)
52    ln -sf /usr/bin/$i.bfd ld-links/$i
53done
54
55NEWPATH=$(pwd)/ld-links
56export PATH=$NEWPATH:$PATH
57
58git config --global user.email "fdo@example.com"
59git config --global user.name "freedesktop.org CI"
60git config --global pull.rebase true
61
62# cleanup git state on the worker
63rm -rf .git/rebase-merge
64
65# Try to merge fixes from target repo
66if [ "$(git ls-remote --exit-code --heads ${UPSTREAM_REPO} ${TARGET_BRANCH}-external-fixes)" ]; then
67    git pull ${UPSTREAM_REPO} ${TARGET_BRANCH}-external-fixes
68fi
69
70# Try to merge fixes from local repo if this isn't a merge request
71# otherwise try merging the fixes from the merge target
72if [ -z "$CI_MERGE_REQUEST_PROJECT_PATH" ]; then
73    if [ "$(git ls-remote --exit-code --heads origin ${TARGET_BRANCH}-external-fixes)" ]; then
74        git pull origin ${TARGET_BRANCH}-external-fixes
75    fi
76else
77    if [ "$(git ls-remote --exit-code --heads ${CI_MERGE_REQUEST_PROJECT_URL} ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}-external-fixes)" ]; then
78        git pull ${CI_MERGE_REQUEST_PROJECT_URL} ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}-external-fixes
79    fi
80fi
81
82if [[ -n "${MERGE_FRAGMENT}" ]]; then
83    ./scripts/kconfig/merge_config.sh ${DEFCONFIG} drivers/gpu/drm/ci/${MERGE_FRAGMENT}
84else
85    make `basename ${DEFCONFIG}`
86fi
87
88for opt in $ENABLE_KCONFIGS; do
89    ./scripts/config --enable CONFIG_$opt
90done
91for opt in $DISABLE_KCONFIGS; do
92    ./scripts/config --disable CONFIG_$opt
93done
94
95make ${KERNEL_IMAGE_NAME}
96
97mkdir -p /lava-files/
98for image in ${KERNEL_IMAGE_NAME}; do
99    cp arch/${KERNEL_ARCH}/boot/${image} /lava-files/.
100done
101
102if [[ -n ${DEVICE_TREES} ]]; then
103    make dtbs
104    cp ${DEVICE_TREES} /lava-files/.
105fi
106
107make modules
108mkdir -p install/modules/
109INSTALL_MOD_PATH=install/modules/ make modules_install
110
111if [[ ${DEBIAN_ARCH} = "arm64" ]]; then
112    make Image.lzma
113    mkimage \
114        -f auto \
115        -A arm \
116        -O linux \
117        -d arch/arm64/boot/Image.lzma \
118        -C lzma\
119        -b arch/arm64/boot/dts/qcom/sdm845-cheza-r3.dtb \
120        /lava-files/cheza-kernel
121    KERNEL_IMAGE_NAME+=" cheza-kernel"
122
123    # Make a gzipped copy of the Image for db410c.
124    gzip -k /lava-files/Image
125    KERNEL_IMAGE_NAME+=" Image.gz"
126fi
127
128# Pass needed files to the test stage
129mkdir -p install
130cp -rfv .gitlab-ci/* install/.
131cp -rfv install/common install/ci-common
132cp -rfv drivers/gpu/drm/ci/* install/.
133
134. .gitlab-ci/container/container_post_build.sh
135
136if [[ "$UPLOAD_TO_MINIO" = "1" ]]; then
137    xz -7 -c -T${FDO_CI_CONCURRENT:-4} vmlinux > /lava-files/vmlinux.xz
138    FILES_TO_UPLOAD="$KERNEL_IMAGE_NAME vmlinux.xz"
139
140    if [[ -n $DEVICE_TREES ]]; then
141        FILES_TO_UPLOAD="$FILES_TO_UPLOAD $(basename -a $DEVICE_TREES)"
142    fi
143
144    for f in $FILES_TO_UPLOAD; do
145        ci-fairy s3cp --token-file "${CI_JOB_JWT_FILE}" /lava-files/$f \
146                https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}/$f
147    done
148
149    S3_ARTIFACT_NAME="kernel-files.tar.zst"
150    tar --zstd -cf $S3_ARTIFACT_NAME install
151    ci-fairy s3cp --token-file "${CI_JOB_JWT_FILE}" ${S3_ARTIFACT_NAME} https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}/${S3_ARTIFACT_NAME}
152
153    echo "Download vmlinux.xz from https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}/vmlinux.xz"
154fi
155
156mkdir -p artifacts/install/lib
157mv install/* artifacts/install/.
158rm -rf artifacts/install/modules
159ln -s common artifacts/install/ci-common
160cp .config artifacts/${CI_JOB_NAME}_config
161
162for image in ${KERNEL_IMAGE_NAME}; do
163    cp /lava-files/$image artifacts/install/.
164done
165
166tar -C artifacts -cf artifacts/install.tar install
167rm -rf artifacts/install
168