From 211d57bdb4b4c14906a2e6b5702987ce5e05be72 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Mon, 05 Sep 2022 09:16:31 +0800
Subject: [PATCH] Add yocto build shell script

---
 yocto/build.sh |  192 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 192 insertions(+), 0 deletions(-)

diff --git a/yocto/build.sh b/yocto/build.sh
new file mode 100755
index 0000000..033ca00
--- /dev/null
+++ b/yocto/build.sh
@@ -0,0 +1,192 @@
+#!/bin/bash
+# This shell script used to build yocto for igkbaord
+
+BOARD=igkboard
+VERSION=honister
+
+PACKDIR=`pwd`/yocto_packets
+
+WORKDIR=`pwd`/workspace-${VERSION}
+YOCTO_SRC=imx-yocto-bsp
+PRJ_PATH=${WORKDIR}/${YOCTO_SRC}
+
+SRV_URL=http://weike-iot.com:2211/yocto/
+YOCTO_TAR=${YOCTO_SRC}-${VERSION}.tar.xz
+
+set -e
+
+# display in red
+function pr_error() {
+    echo -e "\033[40;31m --E-- $1 \033[0m"
+}
+
+# display in yellow
+function pr_warn() {
+    echo -e "\033[40;33m --W-- $1 \033[0m"
+}
+
+# display in green
+function pr_info() {
+    echo -e "\033[40;32m --I-- $1 \033[0m"
+}
+
+# decompress a packet to destination path
+function do_unpack() {
+    tarball=$1
+    dstpath=`pwd`
+
+    if [[ $# == 2 ]] ; then
+        dstpath=$2
+    fi
+
+    pr_info "decompress $tarball"
+
+    case $tarball in
+        *.tar.gz)
+            tar -xzf $tarball -C $dstpath
+            ;;
+
+        *.tar.bz2)
+            tar -xjf $tarball -C $dstpath
+            ;;
+
+        *.tar.xz)
+            tar -xJf $tarball -C $dstpath
+            ;;
+
+        *.tar)
+            tar -xf $tarball -C $dstpath
+            ;;
+
+        *.zip)
+            unzip -qo $tarball -d $dstpath
+            ;;
+
+        *)
+            pr_error "decompress Unsupport packet: $tarball"
+            return 1;
+            ;;
+    esac
+}
+
+function do_fetch()
+{
+    if [ -d $YOCTO_SRC ] ; then
+        pr_warn "$YOCTO_SRC fetched already."
+        return 0;
+    fi
+
+    if [ ! -f tarballs/$YOCTO_TAR ] ; then
+	mkdir -p tarballs/ && cd tarballs
+	wget $SRV_URL/$YOCTO_TAR
+    fi
+
+    cd $WORKDIR
+    do_unpack tarballs/$YOCTO_TAR
+
+    cd ${PRJ_PATH}
+}
+
+function do_patch()
+{
+    if [ -d ${PRJ_PATH}/sources/meta-${BOARD} ] ; then
+        pr_warn "$YOCTO_SRC patch already."
+        return 0;
+    fi
+
+    cd ${PRJ_PATH}/sources
+    cp -af ${WORKDIR}/../${VERSION}/meta-${BOARD} .
+
+    sed -i "s|^DL_DIR.*|DL_DIR ?= \"${PACKDIR}\"|g"  meta-${BOARD}/conf/local.conf
+
+    cd ${PRJ_PATH}
+}
+
+function do_build()
+{
+    TARGET=linuxsys-image
+
+    pr_warn "Build ${YOCTO_SRC} for ${TARGET}."
+
+    cd ${PRJ_PATH}
+
+    if [ -f ${BOARD}/conf/local.conf ] ; then
+        pr_info "$YOCTO_SRC source poky."
+	source sources/poky/oe-init-build-env ${BOARD}
+    else
+        pr_info "$YOCTO_SRC source meta."
+        MACHINE=${BOARD} source sources/meta-${BOARD}/tools/${BOARD}-setup.sh -b ${BOARD}
+    fi
+
+    bitbake linuxsys-image
+
+    cd ${PRJ_PATH}
+}
+
+
+function do_install()
+{
+    pr_warn "List yocto build output images."
+
+    cd $WORKDIR
+
+    set -x
+    ls $WORKDIR/imx-yocto-bsp/${BOARD}/tmp/deploy/images/igkboard/
+    set +x
+}
+
+function do_clean()
+{
+    pr_warn "Clean ${YOCTO_SRC} source code"
+
+    rm -rf $WORKDIR
+}
+
+function do_usage()
+{
+    echo ""
+    echo "Usage:"
+    echo "  $0 [-b] [-c] [-h]"
+    echo "     -b: download and build $PRJ_NAME"
+    echo "     -c: clean the source code"
+    echo "     -h: show this help message"
+    echo ""
+    exit;
+}
+
+while getopts "bch" OPTNAME
+do
+    case "${OPTNAME}" in
+        "b")
+            break;
+            ;;
+
+        "c")
+            do_clean
+            exit;
+            ;;
+
+        "h")
+            do_usage
+            exit;
+            ;;
+
+        "*")
+            do_usage
+            exit;
+            ;;
+    esac
+done
+
+#defualt do build action
+
+mkdir -p $WORKDIR
+cd $WORKDIR
+
+do_fetch
+do_patch
+do_build
+do_install
+
+exit;
+

--
Gitblit v1.9.1