android
2024-07-12 992d1969fcf222b072ac338908b21805611c9b36
linux_sdk/build.sh
@@ -7,7 +7,7 @@
TOP_PATH=$(realpath $PRJ_PATH/..)
# SDK build workspace
SDK_DIR=sdk_build
SDK_DIR=linuxsdk_build
# binaries build prefix install path
PRFX_PATH=$PRJ_PATH/install
@@ -97,72 +97,88 @@
    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
    export ARCH=arm64
   if [[ $BOARD =~ igkboard-rk3568 ]] ; then
      LUNCH_BOARD=rockchip_rk3568_evb1_ddr4_v10_defconfig
   fi
    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
    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_FPATH=$SDK_PATH/$SDK_VER
   PATCH_FLAG="$SDK_DIR/kernel/arch/arm64/configs/rockchip_linux_defconfig"
    SDK_FLAG=$SDK_DIR/kernel/Makefile
   if [ -e $PATCH_FLAG ] ;  then
      pr_warn "SDK source code fetched already, skip do fetch"
      return ;
   fi
    cd $PRJ_PATH
   if [ ! -d $SDK_DIR/.repo ] ; then
    if [ -e $SDK_FLAG ] ;  then
        pr_warn "SDK source code fetched already, skip do fetch"
        return ;
    fi
      SDK_FILE=`ls $SDK_FPATH/*.tar.bz2 | head -n 1`
    if [ ! -d $SDK_DIR/.repo ] ; then
      if [ ! -d $SDK_FPATH ] ; then
         pr_error "ERROR: SDK package folder '$SDK_FPATH' doesn't exist!"
         exit
      fi
        if [ ! -d $SDK_FPATH ] ; then
            pr_error "ERROR: SDK package folder '$SDK_FPATH' doesn't exist!"
            exit
        fi
      pr_info "decompress SDK tarball $SDK_FILE..."
        SDK_FILE=`ls $SDK_FPATH/*.tar.bz2 | head -n 1`
      do_unpack $SDK_FILE $SDK_DIR
   fi
   cd $SDK_DIR
        pr_info "decompress SDK tarball $SDK_FILE..."
        do_unpack $SDK_FILE $SDK_DIR
    fi
   if [ ! -e $PATCH_FLAG ] ; then
      pr_info "repo sync to checkout source code..."
      ./.repo/repo/repo sync -l
   fi
    if [ ! -e $SDK_FLAG ] ; then
        pr_info "repo sync to checkout source code..."
        cd $SDK_DIR
        ./.repo/repo/repo sync -l
    fi
   if ! grep -q '^CONFIG_CAN=y' $PATCH_FLAG ; then
      pr_info "patch for linux kernel..."
      cd kernel
      patch -p1 < $PRJ_PATH/patch/kernel.patch
   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()
{
   pr_info "Choose your board"
    cd $PRJ_PATH
    pr_info "start build $LAUNCH_BOARD..."
   cd $SDK_DIR
   ./build.sh lunch:${LUNCH_BOARD}
    cd $SDK_DIR
    ./build.sh lunch:${LAUNCH_BOARD}
    RK_ROOTFS_SYSTEM=$DISTRO ./build.sh
   RK_ROOTFS_SYSTEM=$DISTRO ./build.sh
   pr_info "System image will be installed to $PRJ_PATH/$SDK_DIR/rockdev"
   ls ./rockdev
    pr_info "System image will be installed to $SDK_DIR/rockdev"
    ls ./rockdev
}
#+-------------------------+
@@ -175,4 +191,6 @@
do_fetch
do_patch
do_build