From 98d6403d29f1e5ca0f3888b3cbd355f01408b061 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Sat, 18 Dec 2021 14:37:53 +0800
Subject: [PATCH] update build.sh support driver build
---
bsp/images/build.sh | 107 ++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 89 insertions(+), 18 deletions(-)
diff --git a/bsp/images/build.sh b/bsp/images/build.sh
index 22b15ca..74dd65c 100755
--- a/bsp/images/build.sh
+++ b/bsp/images/build.sh
@@ -18,11 +18,13 @@
#
PRJ_PATH=`pwd`
+PRJ_NAME=`basename ${PRJ_PATH}`
+
IMAGE_PATH=${PRJ_PATH}/boot/
-BOARD=imx6ull
+BOARD=igkboard
-# rootfs should be buildroot or stretch/buster/bullseye for debian system
+# rootfs should be buildroot/yocto or bullseye for debian system
ROOTFS=buildroot
# linux kernel tarball path and branch
@@ -48,10 +50,10 @@
BOOT_SIZE=100
-IMG_UBOOT=${PRJ_PATH}/u-boot-imx6ull-emmc.imx
+IMG_UBOOT=${PRJ_PATH}/u-boot-${BOARD}-emmc.imx
IMG_KERNEL=${IMAGE_PATH}/zImage
-IMG_DTB=${IMAGE_PATH}/imx6ull-emmc.dtb
-ROOTFS_TAR=${TAR_PATH}/rootfs_${ROOTFS}.tar.bz2
+IMG_DTB=${IMAGE_PATH}/${BOARD}-emmc.dtb
+ROOTFS_TAR=${PRJ_PATH}/../rootfs/rootfs_${ROOTFS}.tar.bz2
MNT_POINT=./mnt
LOOP_DEV=`losetup -f | cut -d/ -f3`
@@ -59,30 +61,29 @@
set -u
set -e
-if [ `id -u` != 0 ] ; then
- echo "ERROR: This shell script must run as root"
- exit 0;
-fi
-
-trap 'exit_handler' EXIT
function exit_handler()
{
echo "Shell script exit now, do some clean work"
echo ""
+ set +e
+
mountpoint $MNT_POINT > /dev/null 2>&1
if [ $? == 0 ] ; then
+ echo "umount ${MNT_POINT}"
umount ${MNT_POINT}
fi
rm -rf ${MNT_POINT}
if [ -L /dev/mapper/${LOOP_DEV}p1 ] ; then
+ echo "kpartx -dv /dev/${LOOP_DEV}"
kpartx -dv /dev/${LOOP_DEV}
fi
losetup -a | grep "${LOOP_DEV}" > /dev/null 2>&1
if [ $? == 0 ] ; then
+ echo "losetup -d /dev/${LOOP_DEV}"
losetup -d /dev/${LOOP_DEV}
fi
}
@@ -164,21 +165,91 @@
mount -t ext4 /dev/mapper/${LOOP_DEV}p2 ${MNT_POINT}
tar -xjf ${ROOTFS_TAR} -C ${MNT_POINT} && sync
+ chown -R root.root ${MNT_POINT} && sync
umount ${MNT_POINT}
}
-mkdir -p ${MNT_POINT}
+function do_distclean()
+{
+ printf "\n\n -- do distclean in `basename ${PRJ_PATH}` --\n\n"
-generate_image
+ rm -f *${BOARD}*
+ rm -rf boot/*Image*
+ rm -rf boot/overlays/
+ rm -rf boot/*${BOARD}*
+ exit 0;
+}
-format_partition
+function do_image()
+{
+ mkdir -p ${MNT_POINT}
-install_sysimg
+ generate_image
-install_rootfs
+ format_partition
-bzip2 ${IMAGE_NAME}
+ install_sysimg
-rm -rf ${MNT_POINT}
+ install_rootfs
+ msg_banner " bzip2 compress system image "
+ rm -f ${IMAGE_NAME}*.bz2
+ bzip2 ${IMAGE_NAME}
+
+ rm -rf ${MNT_POINT}
+
+ printf "\n\n -- generate system image done --\n\n"
+}
+
+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_usage()
+{
+ echo ""
+ echo "Usage:"
+ echo " $0 [-b] [-c] [-h]"
+ echo " -b: download and build $PRJ_NAME"
+ echo " -c: clean all the source code"
+ echo " -h: show this help message"
+ echo ""
+ echo " WARNNING: This shell script must run as sudo"
+ echo ""
+ exit;
+}
+
+trap 'exit_handler' EXIT
+
+while getopts "bch" OPTNAME
+do
+ case "${OPTNAME}" in
+ "b")
+ break;
+ ;;
+
+ "c")
+ do_root "yes"
+ do_distclean
+ ;;
+
+ "*")
+ do_usage
+ ;;
+ esac
+done
+
+do_root "yes"
+do_image
+exit;
--
Gitblit v1.9.1