凌云实验室推出的ARM Linux物联网网关开发板IGKBoard(IoT Gateway Kit Board)项目源码
guowenxue
2022-10-29 e699b35d841124f4322a7ec27e44a8d64f79d9fa
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
#!/bin/bash
 
PRJ_PATH=`pwd`
PRJ_NAME=`basename $PRJ_PATH`
 
# update by top build.sh
BOARD=igkboard
CROSS_TOOL=/opt/gcc-arm-10.3-2021.07/bin/arm-none-linux-gnueabihf-
 
# Source code download address
SRV_URL=http://weike-iot.com:2211
#SRV_URL=http://127.0.0.1:2211
BSP_VER=lf-5.15.32-2.0.0
BSP_URL=${SRV_URL}/imx/bsp/${BSP_VER}
 
# SYSTEM  should be: yocto or debian
# DISTRO  should be: hardknott, buster
# SYSNAME should be: yocto, buster
SYSTEM=yocto
DISTRO=kirkstone
 
TARBALL_DIR=${PRJ_PATH}/../tarballs/
 
if [ $SYSTEM == "debian" ] ; then
    SYSNAME=${DISTRO}
else
    SYSNAME=${SYSTEM}
fi
 
ROOTFS_DIR=rootfs_${DISTRO}
 
JSON_CONF=${PRJ_PATH}/${BOARD}.json
JOBS=`cat /proc/cpuinfo | grep processor | wc -l`
 
set -u
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
}
 
# copy a file and decompress it if needed
function install_file()
{
    # parameters maybe got variable, use eval to fix it.
    src=`eval echo $1`
    dst=`eval echo $2`
 
    pr_info "install $src => $dst"
 
    mkdir -p $dst
 
    if [[ "$src" =~ ".tar" ]] || [[ "$src" =~ ".zip" ]] ; then
        do_unpack $src ${dst}
    else
        rm -rf ${dst}/`basename ${src}`
        cp -rf `eval ls -d ${src}` ${dst}
    fi
}
 
# install all the files specified in JSON configure file
function do_install_json()
{
    json_conf=$1
    json_id=$2
 
    jq_args=".$json_id | keys[] as \$k | \"\(\$k):\(.[\$k])\""
    for row in $( jq -r "${jq_args}" $json_conf ) ; do
        # parser the source file and destination install path
        src=`echo $row | cut -d: -f1`
        dst=`echo $row | cut -d: -f2`
 
        # $src maybe got * to match all the files, use eval to extend it
        for f in `eval ls -d $src` ; do
            install_file $f $dst
        done
    done
}
 
# fetch source code by git
function do_fetch_git() {
    url=$1
    branch=$2
    dirname=$3
 
    if [ $branch != "null" ] ; then
        pr_info "git clone -b ${branch} ${url} ${dirname}"
        git clone -b ${branch} ${url} ${dirname}
    else
        pr_info "git clone ${url} ${dirname}"
        git clone ${url} ${dirname}
    fi
}
 
# fetch source code by wget
function do_fetch_wget() {
    url=`eval echo $1`
    dirname=$2
    tarfile=`basename $url`
 
    mkdir -p ${TARBALL_DIR}
 
    if [ ! -f ${TARBALL_DIR}/$tarfile ] ; then
        pr_info "wget $url"
 
    wget $url -P ${TARBALL_DIR} > /dev/null 2>&1
    fi
    do_unpack ${TARBALL_DIR}/$tarfile $dirname
}
 
# fetch source code by copy
function do_fetch_file() {
    url=`eval echo $1`
    dirname=$2
    tarfile=`basename $url`
 
    cp -rf $url $tarfile
 
    if [[ "$tarfile" =~ ".tar" ]] || [[ "$tarfile" =~ ".zip" ]] ; then
        do_unpack $tarfile $dirname
    fi
}
 
# parser JSON configure file to find the way to fetch source code
function do_fetch_json() {
    json_conf=$1
    node_src=$2
    dirname=$3
 
    pr_info "start fetch $dirname source code."
 
    method=`jq -r ".$node_src.PROTOCAL" $json_conf`
    url=`jq -r ".$node_src.URL" $json_conf`
 
    if [[ "$method" =~ "git" ]] ; then
        branch=`jq -r ".$node_src.BRANCH" $json_conf`
        do_fetch_git $url $branch $dirname
    elif [[ "$method" =~ "wget" ]] ; then
        do_fetch_wget $url $dirname
    elif [[ "$method" =~ "file" ]] ; then
        do_fetch_file $url $dirname
    fi
}