#!/bin/bash
|
|
# this project absolute path
|
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
|
|
# top project absolute path
|
TOP_PATH=$(realpath $PRJ_PATH/..)
|
|
# binaries build prefix install path
|
PRFX_PATH=$PRJ_PATH/install
|
|
# binaries finally install path if needed
|
#INST_PATH=/tftp
|
|
# 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"
|
}
|
|
# parser configure file and export environment variable
|
function export_env()
|
{
|
export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'`
|
export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'`
|
export GIT_URL=`jq -r ".bsp.giturl" $CONF_FILE | tr 'A-Z' 'a-z'`
|
export CROSS_COMPILE=`jq -r ".bsp.cortexAtool" $CONF_FILE | tr 'A-Z' 'a-z'`
|
|
export SRCS="linux-imx"
|
export BRANCH=$BSP_VER
|
export KER_PATH=$PRJ_PATH/linux-imx
|
|
export JOBS=`cat /proc/cpuinfo | grep processor | wc -l`
|
|
if [[ $BOARD =~ mx6ull ]] ; then
|
export ARCH=arm
|
else
|
export ARCH=arm64
|
fi
|
}
|
|
function build_kernel()
|
{
|
defconfig=${BOARD}_defconfig
|
patch_file=$PRJ_PATH/patches/$BOARD/linux-imx-$BSP_VER.patch
|
|
cd $PRJ_PATH
|
|
if [ -d $KER_PATH ] ; then
|
pr_info "linux kernel source code fetched already"
|
else
|
pr_info "start fetch linux kernel source code"
|
git clone $GIT_URL/linux-imx.git -b $BRANCH --depth=1
|
fi
|
|
pr_info "Start build linux kernel source code"
|
|
cd $KER_PATH
|
|
if [ ! -s arch/$ARCH/configs/$defconfig -a -s $patch_file ] ; then
|
pr_warn "do patch for $KER_PATH now..."
|
patch -p1 < $patch_file
|
fi
|
|
if [ ! -s .config ] ; then
|
make ${defconfig}
|
fi
|
|
make -j ${JOBS}
|
}
|
|
function do_install()
|
{
|
pr_info "start install linux kernel images"
|
|
cd $KER_PATH
|
|
if [ -d $PRFX_PATH ] ; then
|
rm -rf $PRFX_PATH/*
|
fi
|
|
mkdir -p $PRFX_PATH/overlays
|
|
# Install system image and device tree binaries
|
|
if [[ $BOARD =~ 6ull ]] ; then
|
set -x
|
cp -f arch/${ARCH}/boot/zImage $PRFX_PATH
|
cp -f arch/${ARCH}/boot/dts/${BOARD}.dtb $PRFX_PATH
|
cp -f arch/${ARCH}/boot/dts/${BOARD}/*.dtbo $PRFX_PATH/overlays
|
set +x
|
else
|
set -x
|
cp -f arch/${ARCH}/boot/Image $PRFX_PATH
|
cp -f arch/${ARCH}/boot/dts/freescale/${BOARD}.dtb $PRFX_PATH
|
cp -f arch/${ARCH}/boot/dts/freescale/${BOARD}/*.dtbo $PRFX_PATH/overlays
|
set +x
|
fi
|
|
# Install kernel modules
|
make modules_install INSTALL_MOD_PATH=$PRFX_PATH INSTALL_MOD_STRIP=1
|
|
echo ""
|
pr_info "linux kernel installed to '$PRFX_PATH'"
|
ls $PRFX_PATH && echo ""
|
|
if [[ -n "$INST_PATH" && -w $INST_PATH ]] ; then
|
pr_info "install linux kernel to '$INST_PATH'"
|
cp -f $PRFX_PATH/*Image $INST_PATH
|
cp -f $PRFX_PATH/${BOARD}.dtb $INST_PATH
|
fi
|
}
|
|
function do_build()
|
{
|
cd $PRJ_PATH
|
|
build_kernel
|
|
do_install
|
}
|
|
function do_clean()
|
{
|
cd $PRJ_PATH
|
|
for d in $SRCS
|
do
|
rm -rf $PRJ_PATH/$d
|
done
|
|
rm -rf $PRFX_PATH
|
}
|
|
#+-------------------------+
|
#| Shell script body entry |
|
#+-------------------------+
|
|
export_env
|
|
if [[ $# == 1 && $1 == -c ]] ;then
|
pr_warn "start clean linux kernel"
|
do_clean
|
exit;
|
fi
|
|
pr_warn "start build linux kernel for ${BOARD}"
|
|
do_build
|