xref: /linux/drivers/gpu/drm/ci/build.sh (revision 2b0cfa6e49566c8fa6759734cf821aa6e8271a9e)
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"
29elif [[ "$KERNEL_ARCH" = "arm" ]]; then
30    GCC_ARCH="arm-linux-gnueabihf"
31    DEBIAN_ARCH="armhf"
32    DEVICE_TREES="arch/arm/boot/dts/rockchip/rk3288-veyron-jaq.dtb"
33    DEVICE_TREES+=" arch/arm/boot/dts/allwinner/sun8i-h3-libretech-all-h3-cc.dtb"
34    DEVICE_TREES+=" arch/arm/boot/dts/nxp/imx/imx6q-cubox-i.dtb"
35    apt-get install -y libssl-dev:armhf
36else
37    GCC_ARCH="x86_64-linux-gnu"
38    DEBIAN_ARCH="amd64"
39    DEVICE_TREES=""
40fi
41
42export ARCH=${KERNEL_ARCH}
43export CROSS_COMPILE="${GCC_ARCH}-"
44
45# The kernel doesn't like the gold linker (or the old lld in our debians).
46# Sneak in some override symlinks during kernel build until we can update
47# debian.
48mkdir -p ld-links
49for i in /usr/bin/*-ld /usr/bin/ld; do
50    i=$(basename $i)
51    ln -sf /usr/bin/$i.bfd ld-links/$i
52done
53
54NEWPATH=$(pwd)/ld-links
55export PATH=$NEWPATH:$PATH
56
57git config --global user.email "fdo@example.com"
58git config --global user.name "freedesktop.org CI"
59git config --global pull.rebase true
60
61# cleanup git state on the worker
62rm -rf .git/rebase-merge
63
64# Try to merge fixes from target repo
65if [ "$(git ls-remote --exit-code --heads ${UPSTREAM_REPO} ${TARGET_BRANCH}-external-fixes)" ]; then
66    git pull ${UPSTREAM_REPO} ${TARGET_BRANCH}-external-fixes
67fi
68
69# Try to merge fixes from local repo if this isn't a merge request
70# otherwise try merging the fixes from the merge target
71if [ -z "$CI_MERGE_REQUEST_PROJECT_PATH" ]; then
72    if [ "$(git ls-remote --exit-code --heads origin ${TARGET_BRANCH}-external-fixes)" ]; then
73        git pull origin ${TARGET_BRANCH}-external-fixes
74    fi
75else
76    if [ "$(git ls-remote --exit-code --heads ${CI_MERGE_REQUEST_PROJECT_URL} ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}-external-fixes)" ]; then
77        git pull ${CI_MERGE_REQUEST_PROJECT_URL} ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}-external-fixes
78    fi
79fi
80
81if [[ -n "${MERGE_FRAGMENT}" ]]; then
82    ./scripts/kconfig/merge_config.sh ${DEFCONFIG} drivers/gpu/drm/ci/${MERGE_FRAGMENT}
83else
84    make `basename ${DEFCONFIG}`
85fi
86
87for opt in $ENABLE_KCONFIGS; do
88    ./scripts/config --enable CONFIG_$opt
89done
90for opt in $DISABLE_KCONFIGS; do
91    ./scripts/config --disable CONFIG_$opt
92done
93
94make ${KERNEL_IMAGE_NAME}
95
96mkdir -p /lava-files/
97for image in ${KERNEL_IMAGE_NAME}; do
98    cp arch/${KERNEL_ARCH}/boot/${image} /lava-files/.
99done
100
101if [[ -n ${DEVICE_TREES} ]]; then
102    make dtbs
103    cp ${DEVICE_TREES} /lava-files/.
104fi
105
106make modules
107mkdir -p install/modules/
108INSTALL_MOD_PATH=install/modules/ make modules_install
109
110if [[ ${DEBIAN_ARCH} = "arm64" ]]; then
111    make Image.lzma
112    mkimage \
113        -f auto \
114        -A arm \
115        -O linux \
116        -d arch/arm64/boot/Image.lzma \
117        -C lzma\
118        -b arch/arm64/boot/dts/qcom/sdm845-cheza-r3.dtb \
119        /lava-files/cheza-kernel
120    KERNEL_IMAGE_NAME+=" cheza-kernel"
121
122    # Make a gzipped copy of the Image for db410c.
123    gzip -k /lava-files/Image
124    KERNEL_IMAGE_NAME+=" Image.gz"
125fi
126
127# Pass needed files to the test stage
128mkdir -p install
129cp -rfv .gitlab-ci/* install/.
130cp -rfv install/common install/ci-common
131cp -rfv drivers/gpu/drm/ci/* install/.
132
133. .gitlab-ci/container/container_post_build.sh
134
135if [[ "$UPLOAD_TO_MINIO" = "1" ]]; then
136    xz -7 -c -T${FDO_CI_CONCURRENT:-4} vmlinux > /lava-files/vmlinux.xz
137    FILES_TO_UPLOAD="$KERNEL_IMAGE_NAME vmlinux.xz"
138
139    if [[ -n $DEVICE_TREES ]]; then
140        FILES_TO_UPLOAD="$FILES_TO_UPLOAD $(basename -a $DEVICE_TREES)"
141    fi
142
143    for f in $FILES_TO_UPLOAD; do
144        ci-fairy s3cp --token-file "${CI_JOB_JWT_FILE}" /lava-files/$f \
145                https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}/$f
146    done
147
148    S3_ARTIFACT_NAME="kernel-files.tar.zst"
149    tar --zstd -cf $S3_ARTIFACT_NAME install
150    ci-fairy s3cp --token-file "${CI_JOB_JWT_FILE}" ${S3_ARTIFACT_NAME} https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}/${S3_ARTIFACT_NAME}
151
152    echo "Download vmlinux.xz from https://${PIPELINE_ARTIFACTS_BASE}/${DEBIAN_ARCH}/vmlinux.xz"
153fi
154
155mkdir -p artifacts/install/lib
156mv install/* artifacts/install/.
157rm -rf artifacts/install/modules
158ln -s common artifacts/install/ci-common
159cp .config artifacts/${CI_JOB_NAME}_config
160
161for image in ${KERNEL_IMAGE_NAME}; do
162    cp /lava-files/$image artifacts/install/.
163done
164
165tar -C artifacts -cf artifacts/install.tar install
166rm -rf artifacts/install
167