#!/bin/bash # this project absolute path PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) # top project absolute path TOP_PATH=$(realpath $PRJ_PATH/..) # SDK build workspace SDK_DIR=linuxsdk_build # binaries build prefix install path PRFX_PATH=$PRJ_PATH/install # binaries finally install path if needed #INST_PATH=/tftp # download taballs path TARBALL_PATH=$PRJ_PATH/tarballs # config file path CONF_FILE=$TOP_PATH/config.json # shell script will exit once get command error set -e #+-------------------------+ #| Shell script functions | #+-------------------------+ function pr_error() { echo -e "\033[40;31m $1 \033[0m" } function pr_warn() { echo -e "\033[40;33m $1 \033[0m" } function pr_info() { echo -e "\033[40;32m $1 \033[0m" } # decompress a packet to destination path function do_unpack() { tarball=$1 dstpath=`pwd` if [[ $# == 2 ]] ; then dstpath=$2 fi pr_info "decompress $tarball => $dstpath" mkdir -p $dstpath case $tarball in *.tar.gz) tar -xzf $tarball -C $dstpath ;; *.tgz) tar -xzf $tarball -C $dstpath ;; *.tar.bz2) tar -xjf $tarball -C $dstpath ;; *.tar.xz) tar -xJf $tarball -C $dstpath ;; *.tar.zst) tar -I zstd -xf $tarball -C $dstpath ;; *.tar) tar -xf $tarball -C $dstpath ;; *.zip) unzip -qo $tarball -d $dstpath ;; *) pr_error "decompress Unsupport packet: $tarball" return 1; ;; esac } # parser configure file and export environment variable function export_env() { export BOARD=`jq -r ".board" $CONF_FILE | tr 'A-Z' 'a-z'` export SDK_VER=`jq -r ".linux.sdk_ver" $CONF_FILE` export SDK_PATH=`jq -r ".linux.sdk_path" $CONF_FILE` export DISTRO=`jq -r ".linux.distro" $CONF_FILE | tr 'A-Z' 'a-z'` export ARCH=arm64 if [[ $BOARD =~ igkboard-rk3568 ]] ; then LAUNCH_BOARD=rockchip_rk3568_evb1_ddr4_v10_defconfig fi PYTHON_VERSION=$(python --version 2>&1 | awk '{print $2}' | cut -d. -f1) if [ $PYTHON_VERSION != "3" ] ; then PYTHON_VERSION=$(python --version 2>&1) pr_error "ERROR: This SDK build need Python3, current version is $PYTHON_VERSION" pr_warn "You can use 'sudo update-alternatives --config python' command to switch it" exit fi } function do_fetch() { SDK_FPATH=$SDK_PATH/$SDK_VER SDK_FLAG=$SDK_DIR/kernel/Makefile cd $PRJ_PATH if [ -e $SDK_FLAG ] ; then pr_warn "SDK source code fetched already, skip do fetch" return ; fi if [ ! -d $SDK_DIR/.repo ] ; then if [ ! -d $SDK_FPATH ] ; then pr_error "ERROR: SDK package folder '$SDK_FPATH' doesn't exist!" exit fi SDK_FILE=`ls $SDK_FPATH/*.tar.bz2 | head -n 1` pr_info "decompress SDK tarball $SDK_FILE..." do_unpack $SDK_FILE $SDK_DIR fi if [ ! -e $SDK_FLAG ] ; then pr_info "repo sync to checkout source code..." cd $SDK_DIR ./.repo/repo/repo sync -l fi } function do_patch() { PATCH_FLAG="$SDK_DIR/kernel/arch/arm64/configs/rockchip_linux_defconfig" cd $PRJ_PATH if grep -q '^CONFIG_CAN=y' $PATCH_FLAG ; then pr_warn "INFO: Patch for Linux SDK already" return ; fi pr_info "patch for linux kernel..." cd $SDK_DIR/kernel patch -p1 < $PRJ_PATH/patches/kernel.patch cd - pr_info "patch for linux buildroot..." cd $SDK_DIR/buildroot patch -p1 < $PRJ_PATH/patches/buildroot.patch cd - } function do_build() { cd $PRJ_PATH pr_info "start build $LAUNCH_BOARD..." cd $SDK_DIR ./build.sh lunch:${LAUNCH_BOARD} RK_ROOTFS_SYSTEM=$DISTRO ./build.sh pr_info "System image will be installed to $SDK_DIR/rockdev" ls ./rockdev } #+-------------------------+ #| Shell script body entry | #+-------------------------+ export_env pr_warn "start build linux kernel for ${BOARD}" do_fetch do_patch do_build