summaryrefslogtreecommitdiff
path: root/jenkins_common_lib
blob: 9dae9dd12ad7c36b8cb3ed1f12df70ee7c50f3ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash

# Global Variables
bundle_stream_name_path="/private/team/linaro/ci-$bundle_stream_name/"
log_info=$BUILD_URL"consoleText"
pkg_dir="builddir-${kernel_release}"
# Default directory where config fragments are or should be stored.
conf_dir="linaro/configs"
# Default gitweb access URL.
default_git_url="http://git.linaro.org/gitweb?p=$conf_git;a=blob_plain;f=$conf_dir/$conf;hb=$conf_branch"
boot_wrapper_repo=${boot_wrapper_repo:-"git://git.kernel.org/pub/scm/linux/kernel/git/cmarinas/boot-wrapper-aarch64.git"}

echo > hwpack_info # start with empty
echo KERNEL_CONFIG=$kernel_config >> hwpack_info
echo OS_INFO=`cat /etc/lsb-release | grep DISTRIB_DESCRIPTION | cut -d '=' -f 2` >> hwpack_info
echo LOG=$log_info >> hwpack_info
echo BUILD_ID=$BUILD_NUMBER >> hwpack_info
echo GCC_VERSION=`dpkg -s gcc | grep Version | cut -d ' ' -f2` >> hwpack_info
echo GCC_CROSS_COMPILER=$gcc_version >> hwpack_info
echo BOARD_TYPES=$board_types >> hwpack_info
echo HWPACK_TYPE=$hwpack_type >> hwpack_info
echo ROOTFS_TYPE=$rootfs_type >> hwpack_info
echo BUNDLE_STREAM_NAME=$bundle_stream_name_path >> hwpack_info
echo JOB_URL=http://snapshots.linaro.org/kernel-hwpack/ >> hwpack_info
echo KERNEL_VERSION=${kernel_version} >> hwpack_info
echo KERNEL_GIT=$KERNEL_GIT >> hwpack_info
echo KERNEL_COMMIT=$KERNEL_COMMIT >> hwpack_info
echo COMMIT_TIME=`git show -s --format=%cD HEAD` >> hwpack_info
echo KERNEL_NAME=$bundle_stream_name >> hwpack_info
echo SUBMIT_LAVA_JOB=$submit_job >> hwpack_info
echo LAVA_TEST_PLAN=$lava_test_plan >> hwpack_info
echo KERNEL_BUILD_URL=$BUILD_URL >> hwpack_info
echo KERNEL_BRANCH=`git branch | grep -e '*'  | cut -d '*' -f 2` >> hwpack_info
echo KERNEL_JOB_NAME=$JOB_NAME >> hwpack_info
echo GIT_LOG=`git log -n1 --pretty=format:%s` >> hwpack_info
echo GIT_WEB_URL=$git_web_url >> hwpack_info

if test -n "$device_tags"; then
  echo DEVICE_TAGS=$device_tags >> hwpack_info
fi

build_setup()
{
    rm -f linux-*.deb
    if [ -e $WORKSPACE/lci-build-tools/build-scripts/builddeb ]
    then
        echo "Copying the local builddeb..."
        cp scripts/package/builddeb scripts/package/builddeb.orig
        cp $WORKSPACE/lci-build-tools/build-scripts/builddeb scripts/package/builddeb
    else
        echo "Using the builddeb available in the tree..."
    fi
    rm -rf $pkg_dir
    mkdir $pkg_dir
}

create_config_using_config_fragments() {
    # Retrieve first, if defined, external conf fragment.
    if test -n "$conf_git" -a -n "$conf_branch"; then
        echo "Retrieving external configuration file"
        if test -n "$conf_external"; then
            # Check that we have a place where to store everything.
            if ! test -d $conf_dir; then
                mkdir -p $conf_dir
            fi
            for conf in `printf "$conf_external" | tr ',' ' '`
            do
                curl "$default_git_url" > "$conf_dir/$conf"
                if test -e "$conf_dir/$conf"; then
                    # Store everything in $conf_filenames
                    conf_filenames="$conf_filenames $conf_dir/$conf"
                else
                    echo "Config file $conf not found at $default_git_url"
                fi
            done
        else
            echo "External configuration file to retrieve not defined, skipping"
        fi
    fi

    scripts/kconfig/merge_config.sh -O $WORKSPACE/$pkg_dir/ $conf_filenames
}

build_instructions()
{
    # Calling the function build setup to create build env
    build_setup
    START=$(date +%s)
    cpu_count=`getconf _NPROCESSORS_ONLN`
    j_count=`expr $cpu_count '*' 2`
    if [ "${make_silent}" = "true" ]; then
        redirect_output=" &>${pkg_dir}/build.log"
    fi
    if [ -n "$conf_filenames" -o -n "$conf_git" ] ; then
        create_config_using_config_fragments
        eval 'make mrproper'${redirect_output}
    elif [ -n "$kernel_config" ]; then
        eval 'make mrproper'${redirect_output}
        eval 'make O=${pkg_dir} ${kernel_config}'${redirect_output}
    else
        echo "Kernel configuration isn't set (kernel_config or conf_filenames or conf_git)"
        exit 1
    fi
    yes "" | eval 'make O=${pkg_dir} oldconfig'${redirect_output}
    if [ "${ARCH}" = "arm" ]; then
        if  [ -n "${LOADADDR}" ]; then
            kernel_img_cmd="uImage LOADADDR=${LOADADDR}"
        elif grep -Fxq 'CONFIG_ARCH_MULTIPLATFORM=y' ${WORKSPACE}/${pkg_dir}/.config; then
            kernel_img_cmd=zImage
        else
            kernel_img_cmd=uImage
        fi
        kernel_debarch=armhf
    elif [ "${ARCH}" = "arm64" ]; then
        kernel_img_cmd=${kernel_img_cmd:-Image}
        kernel_debarch=arm64
    elif [ "${ARCH}" = "x86_64" ]; then
        kernel_img_cmd=bzImage
        kernel_debarch=amd64
    fi
    eval 'make KERNELRELEASE=${kernel_release} O=${pkg_dir} -j${j_count} ${kernel_img_cmd}'${redirect_output}
    if grep -Fxq 'CONFIG_MODULES=y' ${WORKSPACE}/${pkg_dir}/.config; then
        eval 'make KERNELRELEASE=${kernel_release} O=${pkg_dir} -j${j_count} modules'${redirect_output}
    fi
    if [ "$MAKE_DTBS" = "true" ]; then
        echo "Building with DTBS support..."
        eval 'make KERNELRELEASE=${kernel_release} O=${pkg_dir} dtbs'${redirect_output}
    fi
    if [ "${make_bootwrapper}" = "true" -a "${ARCH}" = "arm64" ]; then
        echo "Building boot wrapper"
        rm -rf ${pkg_dir}/boot-wrapper
        git clone ${boot_wrapper_repo} ${pkg_dir}/boot-wrapper
        cd ${pkg_dir}/boot-wrapper/
        autoreconf -vfi
        kernel_dtb=`find ${WORKSPACE}/${pkg_dir}/arch/arm64/boot/dts/ -type f -name 'foundation-v8.dtb'`
        ./configure \
            --host=aarch64-linux-gnu \
            --with-kernel-dir=${WORKSPACE}/${pkg_dir} \
            --with-cmdline="console=ttyAMA0 earlyprintk=pl011,0x1c090000 consolelog=9 rw root=/dev/vda2" \
            --with-dtb=${kernel_dtb}
        make IMAGE=img-foundation.axf clean
        make DTC=${WORKSPACE}/${pkg_dir}/scripts/dtc/dtc \
            IMAGE=img-foundation.axf \
            KERNEL_DTB=${kernel_dtb}
        kernel_dtb=`find ${WORKSPACE}/${pkg_dir}/arch/arm64/boot/dts/ -type f -name 'rtsm_ve-aemv8a.dtb'`
        ./configure \
            --host=aarch64-linux-gnu \
            --with-kernel-dir=${WORKSPACE}/${pkg_dir} \
            --with-cmdline="console=ttyAMA0 earlyprintk=pl011,0x1c090000 consolelog=9 rw root=/dev/mmcblk0p2" \
            --with-dtb=${kernel_dtb}
        make IMAGE=img.axf clean
        make DTC=${WORKSPACE}/${pkg_dir}/scripts/dtc/dtc \
            IMAGE=img.axf \
            KERNEL_DTB=${kernel_dtb}
        cd ${WORKSPACE}
        cp -a ${pkg_dir}/boot-wrapper/*.axf ${pkg_dir}/arch/arm64/boot/
    fi
    if [ "${make_deb}" = "true" ]; then
        [ "${ARCH}" = "arm64" ] && kernel_image_arg="KBUILD_IMAGE=arch/arm64/boot/Image"
        eval 'make O=${pkg_dir} KERNELRELEASE=${kernel_release} KBUILD_DEBARCH=${kernel_debarch} ${kernel_image_arg} V=1 bindeb-pkg'${redirect_output}
        if [ "${make_perf}" = "true" ]; then
            make O=${pkg_dir} KERNELRELEASE=${kernel_release} perf-tarxz-src-pkg
            cd ${pkg_dir}
            ../lci-build-tools/build-scripts/buildperfdsc
            cd -
        fi
    fi
    if [ "${make_install}" = "true" ]; then
        install -D -p -m0644 ${pkg_dir}/.config out/kernel.config
        install -D -p -m0644 ${pkg_dir}/arch/${ARCH}/boot/${kernel_img_cmd} out/${kernel_img_cmd}
        [ "${make_silent}" = "true" ] && cp -a ${pkg_dir}/build.log out/
        if grep -q "^CONFIG_OF=y" out/kernel.config ; then
          for dtb in `find ${pkg_dir}/arch/${ARCH}/boot/dts/ -type f -name '*.dtb'`; do
            install -D -p -m0644 ${dtb} out/dtbs/`basename ${dtb}`
          done
        fi
    fi
    END=$(date +%s)
    EXECUTION_TIME_IN_SEC=$(( $END - $START ))

    if [ "$submit_job" -eq 1 ]; then
        hwpack_url=`python lci-build-tools/get_latest_slo_hwpack`
        python lci-build-tools/download_file ${hwpack_url}
        latest_hwpack_name=`basename $hwpack_url`
        hwpack_prefix=`echo ${latest_hwpack_name} | cut -d'_' -f-2`
        hwpack_version=`date +%Y%m%d`-${BUILD_NUMBER}
        hwpack_name=${hwpack_prefix}_${hwpack_version}_${kernel_debarch}_supported.tar.gz
        mv ${latest_hwpack_name} ${hwpack_name}
        rm -rf linaro-image-tools
        git clone http://git.linaro.org/git/ci/linaro-image-tools.git
        python linaro-image-tools/linaro-hwpack-replace -t ${hwpack_name} -p linux-image-${kernel_release}_*.deb -r linux-image -i
        python linaro-image-tools/linaro-hwpack-replace -t ${hwpack_name} -p linux-headers-${kernel_release}_*.deb -r linux-headers -i
        echo HWPACK_NAME=${hwpack_name} >> hwpack_info
        echo URL=${JOB_URL}/ws/${hwpack_name} >> hwpack_info
        echo EXECUTION_TIME_IN_SEC=$(( $END - $START )) >> hwpack_info
        echo HWPACK_BUILD_DATE=${hwpack_version} >>hwpack_info
    fi

    # Restore the orig buildeb, which was copied to build non linux-linaro-tracking tree
    if [ -e scripts/package/builddeb.orig ]
    then
        echo "Copying back the builddeb that was replaced.."
        cp scripts/package/builddeb.orig scripts/package/builddeb
    fi
}