#!/bin/bash LYFTP_PUB=http://weike-iot.com:2211/imx6ull/tools/lintools PRJ_PATH=`pwd` WORK_SPACE=${HOME}/buildroot/ INST_PATH=/opt/buildroot/cortexA7 BR_VER=buildroot-2021.02.7 BR_PAK=${BR_VER}-packets BR_TAR=${BR_PAK}.tar.bz2 BR_CONF=${BR_VER}-cortexA7.config JOBS=`cat /proc/cpuinfo | grep processor | wc -l` set -u set -e if [ `id -u` == 0 ] ; then echo "ERROR: This shell script shouldn't be excuted by root!" exit ; fi STAGE=0 function msg_banner() { STAGE=`expr $STAGE + 1` echo "" echo "+---------------------------------------------+" printf " Stage $STAGE: $1\n" echo "+---------------------------------------------+" echo "" } function do_fetch() { msg_banner "Fetch ${BR_VER} packets" if [ -d $BR_VER ] ; then printf "\n\n -- ${BR_VER} fetched already -- \n\n" return ; fi if [ ! -s $BR_TAR ] ; then printf "\n\n -- fetch ${BR_VER} packet -- \n\n" wget ${LYFTP_PUB}/$BR_TAR fi if [ ! -d $BR_PAK ] ; then printf "\n\n -- decompress ${BR_TAR} packet -- \n\n" tar -xjf ${BR_TAR} fi printf "\n\n -- decompress ${BR_VER} -- \n\n" tar -xjf ${BR_PAK}/buildroot/${BR_VER}.tar.bz2 mv ${BR_PAK} ${BR_VER}/tarballs } function do_patch() { msg_banner "Patch for ${BR_VER} " cd $BR_VER cp tarballs/buildroot/$BR_CONF .config cp tarballs/busybox/busybox.config package/busybox/ sed -i "s|^BR2_HOST_DIR=.*|BR2_HOST_DIR=\"${INST_PATH}\"|g" .config cd - } function do_build() { msg_banner "Build ${BR_VER} " cd $BR_VER make -j ${JOBS} cd - } function do_install() { msg_banner "Install ${BR_VER} " # Packet and install crosstool cd `dirname $INST_PATH` tar -cjf ${PRJ_PATH}/${BR_VER}-`basename $INST_PATH`.tar.bz2 `basename $INST_PATH` # Install rootfs tarball cp $WORK_SPACE/$BR_VER/output/images/rootfs.tar.bz2 ${PRJ_PATH}/rootfs_buildroot.tar.bz2 echo "" echo " -- 1. Crosstool already installed to \"$INST_PATH\"."; echo " -- 2. Crosstool and rootfs packet installed to \"$PRJ_PATH\""; echo " -- 3. Build workspace path is \"$WORK_SPACE\", you can remove it now."; echo "" } function do_prepare() { INST_DIR=`dirname $INST_PATH` CUR_USER=`whoami` if [ ! -w $INST_DIR ] ; then echo "" echo "ERROR: Crosstool install path \"$INST_DIR\" not writable, please solve it by follow command: " echo " sudo sh -c 'mkdir -p $INST_DIR && chown $CUR_USER.$CUR_USER $INST_DIR' " echo "" exit ; fi echo "" echo "" echo " Switch work space to \"$WORK_SPACE\" " echo "" mkdir -p $WORK_SPACE cd $WORK_SPACE } do_prepare do_fetch do_patch do_build do_install