这个脚本文件是用来构建uboot kernel rootfs,可以使用./build_commom_ukr.sh --h来获取帮助信息。
#!/bin/bash
shell_dir=$(cd $(dirname $0); pwd)
#uboot config
uboot_dir=${
shell_dir}/u-boot-2016.03
uboot_target=/home/jerry/Nxp_sdk/nxp_drcoffee_board/build_commom_ukr
# kernel config
kernel_file=${
shell_dir}/linux-4.9.88/arch/arm/boot/zImage
kernel_target=/home/jerry/Nxp_sdk/nxp_drcoffee_board/build_commom_ukr
# rootfs file and director
update_file=${
shell_dir}/rootfs_doc/target
rootfs_file=/home/jerry/Nxp_sdk/buildroot/output/images/rootfs.tar.bz2
rootfs_target=/home/jerry/Nxp_sdk/nxp_drcoffee_board/build_commom_ukr
# uboot and kernel target name
uk_ver_file=/home/jerry/Nxp_sdk/nxp_drcoffee_board/linux-4.9.88/.config
rootfs_ver_file=/home/jerry/Nxp_sdk/nxp_drcoffee_board/rootfs_doc/target/etc/rootfs_version_conf
uk_var=`cat ${
uk_ver_file} | grep 'CONFIG_LOCALVERSION' | awk -F "=" '{print $2}'`
rootfs_var=`cat ${
rootfs_ver_file} | awk '{print $0}'`
uboot_ver=${
uk_var:2:13}
kernel_ver=${
uk_var:16:13}
rootfs_ver=${
rootfs_var:0:13}
uboot_name=uboot-myimx6ek140-6y-256m-nand.imx_$uboot_ver
kernel_name=zImage-myimx6a7_$kernel_ver
rootfs_name=L4988-core-image-base-myimx6a7.tar.bz2_$rootfs_ver
function help()
{
cat <<EOF
module name: uboot_doc kernel_doc rootfs_doc
director: build_uboot_doc build_kernel_doc build_rootfs_doc
build image: ./script.sh module_name director_name [option]
build all: ./script.sh all build_all
sample: ./build_commom_ukr.sh module build_module [project_name/commom_ukr]
EOF
exit 0
}
# make kernel copy to project director.
function mk_kernel()
{
if [ ! $3 ]; then
commom_dir=commom_ukr
echo "No option to Default:$commom_dir"
build_kernel=`cd ./linux-4.9.88 && make drcoffee_commom_ukr_defconfig && make -j4`
if [ -d $kernel_target/$commom_dir ]; then
cp $kernel_file $kernel_target/$commom_dir/$kernel_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$commom_dir!!!---> \033[0m"
else
echo "$commom_dir Not exist to greate it!!@@@"
mkdir $kernel_target/$commom_dir
cp $kernel_file $kernel_target/$commom_dir/$kernel_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$commom_dir!!!---> \033[0m"
fi
else
build_kernel=`cd ./linux-4.9.88 && make drcoffee_commom_ukr_defconfig && make -j4`
if [ -d $kernel_target/$3 ]; then
cp $kernel_file $kernel_target/$3/$kernel_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$3!!!---> \033[0m"
else
echo "$3 Not exist to greate it!!@@@"
mkdir $kernel_target/$3
cp $kernel_file $kernel_target/$3/$kernel_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$3!!!---> \033[0m"
fi
fi
}
function mk_kernel_select()
{
case $3 in
mini_bar)
echo -e "\033[33m =====> Start building $1-$2-$3!!!---> \033[0m"
mk_kernel $@
;;
commom_ukr)
echo -e "\033[33m =====> Start building $1-$2-$3!!!---> \033[0m"
mk_kernel $@
;;
*)
echo -e "\033[33m =====> Option is empty v_v!!! \033[0m"
mk_kernel $@
;;
esac
}
# make uboot copy to project director.
function mk_uboot()
{
if [ ! $3 ]; then
commom_dir=commom_ukr
echo "No option to Default:$commom_dir"
build_uboot=`cd $uboot_dir && make -j4`
if [ -d $uboot_target/$commom_dir ]; then
cp $uboot_dir/u-boot.imx $uboot_target/$commom_dir/$uboot_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$commom_dir!!!---> \033[0m"
else
echo "$commom_dir Not exist to greate it!!@@@"
mkdir $uboot_target/$commom_dir
cp $uboot_dir/u-boot.imx $uboot_target/$commom_dir/$uboot_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$commom_dir!!!---> \033[0m"
fi
else
build_uboot=`cd $uboot_dir && make -j4`
if [ -d $uboot_target/$3 ]; then
cp $uboot_dir/u-boot.imx $uboot_target/$3/$uboot_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$3!!!---> \033[0m"
else
echo "$3 Not exist to greate it!!@@@"
mkdir $uboot_target/$3
cp $uboot_dir/u-boot.imx $uboot_target/$3/$uboot_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$3!!!---> \033[0m"
fi
fi
}
function mk_uboot_select()
{
case $3 in
f2plus)
echo -e "\033[33m =====> Start building $1-$2-$3!!!---> \033[0m"
mk_uboot $@
;;
coffee_bar)
echo -e "\033[33m =====> Start building $1-$2-$3!!!---> \033[0m"
mk_uboot $@
;;
commom_ukr)
echo -e "\033[33m =====> Start building $1-$2-$3!!!---> \033[0m"
mk_uboot $@
;;
*)
echo -e "\033[33m =====> Option is empty v_v!!! \033[0m"
mk_uboot $@
;;
esac
}
# make rootfs to specitify director
function mk_rootfs()
{
if [ ! $3 ]; then
commom_dir=commom_ukr
echo "No option to Default:$commom_dir"
# cp $shell_dir/rootfs_doc/$commom_dir/S51drcoffee ./rootfs_doc/target/etc/init.d/S51drcoffee
cp -r $update_file/* /home/jerry/Nxp_sdk/buildroot/output/target/
build_rootfs=`cd /home/jerry/Nxp_sdk/buildroot && make -j4`
if [ -d $rootfs_target/$commom_dir ]; then
cp $rootfs_file $rootfs_target/$commom_dir/$rootfs_name
sync
echo -e "\033[32m =====> Compile successfull $0-$2-$commom_dir!!!---> \033[0m"
else
echo "$commom_dir Not exist to greate it!!@@@"
mkdir $rootfs_target/$commom_dir
cp $rootfs_file $rootfs_target/$commom_dir/$rootfs_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$commom_dir!!!---> \033[0m"
fi
else
# cp $shell_dir/rootfs_doc/$3/S51drcoffee ./rootfs_doc/target/etc/init.d/S51drcoffee
cp -r $update_file/* /home/jerry/Nxp_sdk/buildroot/output/target/
build_rootfs=`cd /home/jerry/Nxp_sdk/buildroot && make -j4`
if [ -d $rootfs_target/$3 ]; then
cp $rootfs_file $rootfs_target/$3/$rootfs_name
sync
echo -e "\033[32m =====> Compile successfull $0-$2-$3!!!---> \033[0m"
else
echo "$3 Document Not exist to greate it!!@@@"
mkdir $rootfs_target/$3
cp $rootfs_file $rootfs_target/$3/$rootfs_name
sync
echo -e "\033[32m =====> Compile successfull $1-$2-$3!!!---> \033[0m"
fi
fi
}
function mk_rootfs_select()
{
case $3 in
horizontal_rootfs)
echo -e "\033[33m =====> Start building $1-$2-$3!!!---> \033[0m"
mk_rootfs $@
;;
vertical_rootfs)
echo -e "\033[33m =====> Start building $1-$2-$3!!!---> \033[0m"
mk_rootfs $@
;;
commom_ukr)
echo -e "\033[33m =====> Start building $1-$2-$3!!!---> \033[0m"
mk_rootfs $@
;;
*)
echo -e "\033[33m =====> Option is empty v_v!!! \033[0m"
mk_rootfs $@
;;
esac
}
module_name=(uboot kernel rootfs all)
module_dirt=(build_uboot build_kernel build_rootfs build_all)
function check_paraments()
{
local name_ok=0
local dirt_ok=0
for i in ${
module_name[*]}; do
if [ $1 == ${
i} ]; then
name_ok=ok
else
continue
fi
done
if [ $name_ok != "ok" ]; then
echo "!!!The paraments(1) $1 ERROR!! usage:help"
exit
fi
if [ $# -ge 2 ]; then
for j in ${
module_dirt[*]}; do
if [ $2 == ${
j} ]; then
echo "OK ~ $j"
dirt_ok=ok
else
continue
fi
done
if [ $dirt_ok != "ok" ]; then
echo "!!!The paraments(2) $2 ERROR!!!!"
exit
fi
echo -e "\033[33m =====> Project name ---> $1, func name ---> $2 \033[0m"
else
echo -e "\033[31m =====> Check module name ---> $1 Ok \033[0m"
fi
}
# help info
if [ $# -le 0 ] || [ $1 == "help" -o $1 == "--h" ]; then
help
fi
# verificat paraments of module name and dirt name and option
if [ $# -ge 2 ]; then
check_paraments $@
else
check_paraments $1
fi
case $1 in
uboot)
if [ $# -ge 2 ]; then
if [ $2 = build_uboot ]; then
mk_uboot_select $@
fi
fi
;;
kernel)
if [ $# -ge 2 ]; then
if [ $2 = build_kernel ]; then
mk_kernel_select $@
fi
fi
;;
rootfs)
if [ $# -ge 2 ]; then
if [ $2 = build_rootfs ]; then
mk_rootfs_select $@
fi
fi
;;
all)
if [ $# -ge 2 ]; then
if [ $2 = build_all ]; then
mk_uboot_select $@
mk_kernel_select $@
mk_rootfs_select $@
fi
fi
;;
*)
echo "The paramemter is: module_doc build_module_doc direct"
;;
esac
以此为基础来写出其它的自动化脚本。