| #!/bin/bash |
| |
| set -e |
| set -o errtrace |
| trap 'echo Fatal error: script $0 aborting at line $LINENO, command \"$BASH_COMMAND\" returned $?; exit 1' ERR |
| |
| BOARD_LIST="sirocco-p0 sirocco-p1 sirocco-b1 sirocco-b3 sirocco-b4" |
| |
| kernel_modules="bt_interface.ko bt_rproc.ko ath.ko ath11k.ko ath11k_pci.ko ath11k_ahb.ko cfg80211.ko mac80211.ko exportfs.ko overlay.ko" |
| |
| ################################################### |
| # Setup build toollchain |
| ################################################### |
| TOP_DIR=$(readlink -e $(dirname $0)/..) |
| |
| # It exports ARCH and other build related envs. |
| source ${TOP_DIR}/sdk/build_scripts/setup_env.sh |
| |
| ################################################## |
| # Build Kernel |
| ################################################## |
| function BuildKernel() { |
| # build config |
| local config_target=ipq5018_sirocco_defconfig |
| |
| if [ "${deterministic_build}" = "true" ]; then |
| export KBUILD_BUILD_VERSION=0 |
| export KBUILD_BUILD_TIMESTAMP="$(git log -1 --format=%cd --date=rfc) ($(git rev-parse HEAD | head -c 8))" |
| export KBUILD_BUILD_USER=user |
| export KBUILD_BUILD_HOST=host |
| else |
| # Add git hash to date. This corresponds to scripts/mkcompile_h |
| # This shows up in /proc/version |
| export KBUILD_BUILD_TIMESTAMP="$(date) ($(git rev-parse HEAD | head -c 8))" |
| fi |
| |
| echo "Build ${config_target}" |
| ${CROSS_MAKE} ${config_target} |
| #diff .config arch/${ARCH}/configs/${config_target} |
| |
| # make kernel |
| echo "Build kernel" |
| ${CROSS_MAKE} KBUILD_MODPOST_WARN=1 V=1 |
| } |
| |
| ################################################# |
| # Build DTB |
| ################################################# |
| function BuildDTB() { |
| # make DTB |
| local board=$1 |
| local dtb_target="" |
| |
| if [ ${ARCH} == "arm64" ]; then |
| dtb_target="qcom/" |
| fi |
| dtb_target="${dtb_target}${board}.dtb" |
| |
| echo "Build ${dtb_target}" |
| ${CROSS_MAKE} ${dtb_target} |
| } |
| |
| # Append $1 which is an integer value to the file at path $2. $1 is appended as |
| # a binary little endian integer. |
| append_uint32_le() { |
| local val=$1 |
| local file=$2 |
| printf "0: %.8x" ${val} | sed -E 's/0: (..)(..)(..)(..)/0: \4\3\2\1/' \ |
| | xxd -r -g0 >> ${file} |
| } |
| |
| #################################################### |
| # Pack KDTB file |
| #################################################### |
| # Pack the kernel along with its dtb file |
| # The format is [header][compressed kernel][dtb file] |
| # |
| # header is little endian and consists of |
| # struct { |
| # char magic[4]; // "KDTB" |
| # uint32_t kernel_size; |
| # uint32_t dtb_size; |
| # }; |
| function PackKDTBImage() { |
| local board=$1 |
| local eureka_src_path=$2 |
| local kdtb_image=arch/${ARCH}/boot/kernel.${board} |
| local kernel_image |
| local dtb_image |
| |
| if [ "${ARCH}" == "arm" ]; then |
| kernel_image=arch/arm/boot/zImage |
| dtb_image=arch/arm/boot/dts/${board}.dtb |
| else |
| kernel_image=arch/arm64/boot/Image.gz |
| dtb_image=arch/arm64/boot/dts/qcom/${board}.dtb |
| fi |
| kdtb_image=${kdtb_image}.z-dtb |
| |
| rm -f ${kdtb_image} |
| |
| local magic="KDTB" |
| echo -n ${magic} > ${kdtb_image} |
| local kernel_size=$(stat -c %s ${kernel_image}) |
| |
| # Pad kernel size to 4-byte aligned |
| # so that the dtb is started at a 4-byte aligned address |
| # U-Boot crashes when loding dtb not started at an aligned address |
| local padded_kernel_size |
| ((padded_kernel_size=$kernel_size+3)) |
| ((padded_kernel_size=$padded_kernel_size/4*4)) |
| |
| append_uint32_le ${padded_kernel_size} ${kdtb_image} |
| append_uint32_le $(stat -c %s ${dtb_image}) ${kdtb_image} |
| cat ${kernel_image} >> ${kdtb_image} |
| |
| # Once kernel size is different from the padded size, padding the kernel. |
| echo "Kernel size is ${kernel_size}." |
| if [ "$kernel_size" != "$padded_kernel_size" ]; then |
| echo "Need padding kernel size to 4-byte aligned ${padded_kernel_size}." |
| local padding_size |
| ((padding_size=$padded_kernel_size-$kernel_size)) |
| dd if=/dev/zero bs=1 count=$padding_size 2>/dev/null >> ${kdtb_image} |
| fi |
| cat ${dtb_image} >> ${kdtb_image} |
| |
| # Install KDTB into eureka source |
| echo "Install $(basename ${kdtb_image})" |
| local product=$(echo ${board} | cut -d'-' -f1) |
| local target_kernel_path="$(GetKernelPath ${eureka_src_path} ${product})" |
| |
| mkdir -p ${target_kernel_path} |
| cp -f ${kdtb_image} ${target_kernel_path} |
| |
| # zip and install vmlinux into eureka source for debugging purpose |
| gzip -5 vmlinux |
| cp -f vmlinux.gz ${target_kernel_path}/vmlinux.${board}.gz |
| rm vmlinux.gz |
| |
| # Install kernel modules into eureka source |
| echo "Install ${kernel_modules}" |
| local kernel_module_options="" |
| for module in ${kernel_modules}; do |
| if [ -z "${kernel_module_options}" ]; then |
| kernel_module_options="-name ${module}" |
| else |
| kernel_module_options="${kernel_module_options} -o -name ${module}" |
| fi |
| done |
| local kernel_module_paths=$(find . \( ${kernel_module_options} \)) |
| local target_module_path="$(GetModulePath ${eureka_src_path} ${product})" |
| |
| if [ ! -z "${kernel_module_paths}" ]; then |
| mkdir -p ${target_module_path} |
| cp -f ${kernel_module_paths} ${target_module_path} |
| fi |
| } |
| |
| ################################################## |
| # Build All |
| ################################################## |
| function BuildAll() { |
| local board=$1 |
| local eureka_src_path=$(readlink -e $2) |
| if [ -z ${eureka_src_path} ]; then |
| echo "eureka_src_path doesn't exist" |
| exit 1 |
| fi |
| |
| # clean previous build |
| ${CROSS_MAKE} distclean |
| |
| # build kernel |
| BuildKernel |
| |
| # build DTB |
| BuildDTB ${board} |
| |
| # pack Kernel and DTB into KDTB image |
| if [ -e arch/${ARCH}/boot/Image ]; then |
| PackKDTBImage ${board} ${eureka_src_path} |
| else |
| echo "Kernel Build Fails!!!" |
| fi |
| } |
| |
| function Usage() { |
| cat << EOF |
| Usage: |
| $0 <board> <eureka_src_path> |
| Valid boards: ${BOARD_LIST} |
| EOF |
| } |
| |
| function IsBoardValid() { |
| local board |
| local ret=1 |
| |
| for board in ${BOARD_LIST}; do |
| if [ "${board}" == "$1" ]; then |
| ret=0 |
| break |
| fi |
| done |
| |
| return ${ret} |
| } |
| |
| ######################### |
| ####### Main Entry ###### |
| ######################### |
| deterministic_build=false |
| |
| while getopts ":d" arg; do |
| case "${arg}" in |
| d) |
| deterministic_build=true |
| ;; |
| ?) |
| Usage |
| exit 1 |
| ;; |
| esac |
| done |
| shift $((OPTIND-1)) |
| |
| if (( $# < 2 )); then |
| Usage |
| exit 1 |
| else |
| if IsBoardValid $1; then |
| BuildAll $1 $2 |
| else |
| echo "$1 is a invalid board" |
| Usage |
| exit 1 |
| fi |
| fi |