#!/bin/bash PRJ_PATH=`pwd` BOARD=igkboard BSP_VER=lf-5.15.32-2.0.0 CROSS_TOOL=/opt/buildroot/cortexA7/bin/arm-linux- # SYSTEM should be: buildroot, yocto or debian # DISTRO should be: v2021.02, hardknott/honister, bullseye # SYSNAME should be: buildroot, yocto, bullseye SYSTEM=yocto DISTRO=honister SYSTEM=`echo $SYSTEM | tr 'A-Z' 'a-z'` DISTRO=`echo $DISTRO | tr 'A-Z' 'a-z'` set -u set -e function do_modify() { cd $PRJ_PATH FILE=scripts/setup_env.sh sed -i "s|^BOARD.*|BOARD=${BOARD}|g" $FILE sed -i "s|^CROSS_TOOL.*|CROSS_TOOL=${CROSS_TOOL}|g" $FILE sed -i "s|^SYSTEM=.*|SYSTEM=${SYSTEM}|g" $FILE sed -i "s|^DISTRO=.*|DISTRO=${DISTRO}|g" $FILE sed -i "s|^BSP_VER=.*|BSP_VER=${BSP_VER}|g" $FILE } function do_root() { echo "" if [[ $1 == "yes" ]] && [ `id -u` != 0 ] ; then echo "ERROR: This action must run as root!" echo "" exit; elif [[ $1 != "yes" ]] && [ `id -u` == 0 ] ; then echo "ERROR: This action cannot run as root!" echo "" exit; fi } function do_action() { folder=$1 action=$2 if [ ! -f $PRJ_PATH/$folder/build.sh ] ;then return ; fi cd $PRJ_PATH/$folder if [ $action == "build" ] ; then ./build.sh -b elif [ $action == "clean" ] ; then ./build.sh -c rm -rf ${PRJ_PATH}/tarballs fi cd $PRJ_PATH } function do_usage() { echo "" echo "Usage:" echo " $0 [-b] [-c] [-h] bsp/image" echo " -b bsp/image: build BSP or system image" echo " -c bsp/image: clean BSP or system image" echo " -h : show this help message" echo "" echo " WARNNING: build/clean image need run as sudo" echo "" echo " Build Example: $0 -b bsp && sudo $0 -b image" echo " Clean Example: $0 -c bsp && sudo $0 -c image" echo "" exit; } action="usage" while getopts "b:c:h" OPTNAME do case "${OPTNAME}" in "b") action="build" shift ;; "c") action="clean" shift ;; "*") action="usage" ;; esac done if [ $action == "usage" ] ; then do_usage fi if [ $action == "build" ] ; then do_modify fi if [ $1 == "bsp" ] ; then if [ $action == "build" ] ; then do_root "no" fi do_action bootloader $action do_action kernel $action do_action drivers $action elif [ $1 == "image" ] ; then do_root "yes" do_action rootfs $action do_action images $action fi