凌云实验室推出的ARM Linux物联网网关开发板IGKBoard(IoT Gateway Kit Board)项目源码
guowenxue
2022-10-06 be687f8b1295b4cd747b9d28ae6bf5abb8373a26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
# This shell script used to build yocto for igkbaord
 
BOARD=igkboard
VERSION=honister
 
PACKDIR=`pwd`/yocto_packets
#PACKDIR=${HOME}/yocto/yocto_packets
BUILDIR=$BOARD
 
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} .
 
    cd ${PRJ_PATH}
}
 
function do_build()
{
    TARGET=linuxsys-image
 
    pr_warn "Build ${YOCTO_SRC} for ${TARGET}."
 
    cd ${PRJ_PATH}
 
    if [ -f ${BUILDIR}/conf/local.conf ] ; then
        pr_info "$YOCTO_SRC source poky."
        source sources/poky/oe-init-build-env ${BUILDIR}
    else
        pr_info "$YOCTO_SRC source meta."
        MACHINE=${BOARD} source sources/meta-${BOARD}/tools/${BOARD}-setup.sh -b ${BUILDIR}
    fi
 
    sed -i "s|^DL_DIR.*|DL_DIR ?= \"${PACKDIR}\"|g" conf/local.conf
 
    #bitbake -c clean u-boot-imx linux-imx ${TARGET}
    bitbake ${TARGET}
 
    cd ${PRJ_PATH}
}
 
 
function do_install()
{
    pr_warn "List yocto build output images."
 
    cd $WORKDIR
 
    set -x
    ls $WORKDIR/imx-yocto-bsp/${BUILDIR}/tmp/deploy/images/${BOARD}/
    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;