凌云实验室推出的ARM Linux物联网网关开发板IGKBoard(IoT Gateway Kit Board)项目源码
guowenxue
2021-11-12 e6fb9999d43b65a8acafde0ce8d907c65181f810
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
#!/bin/bash
 
LYFTP_PUB=http://weike-iot.com:2211/imx6ull/tools/lintools
 
PRJ_PATH=`pwd`
WORK_SPACE=${HOME}/buildroot/
INST_PATH=/opt/buildroot/cortexA7
 
BR_VER=buildroot-2021.02.7
BR_PAK=${BR_VER}-packets
BR_TAR=${BR_PAK}.tar.bz2
 
BR_CONF=${BR_VER}-cortexA7.config
 
JOBS=`cat /proc/cpuinfo | grep processor | wc -l`
 
set -u
set -e
 
if [ `id -u` == 0 ] ; then
    echo "ERROR: This shell script shouldn't be excuted by root!"
    exit ;
fi
 
STAGE=0
function msg_banner()
    STAGE=`expr $STAGE + 1`
    
    echo ""
    echo "+---------------------------------------------+" 
    printf " Stage $STAGE: $1\n" 
    echo "+---------------------------------------------+"
    echo ""
}
 
function do_fetch()
{
    msg_banner "Fetch ${BR_VER} packets"
 
    if [ -d $BR_VER ] ; then
        printf "\n\n -- ${BR_VER} fetched already -- \n\n"
        return ;
    fi
 
    if [ ! -s $BR_TAR ] ; then
        printf "\n\n -- fetch ${BR_VER} packet -- \n\n"
        wget ${LYFTP_PUB}/$BR_TAR
    fi
 
    if [ ! -d $BR_PAK ] ; then 
        printf "\n\n -- decompress ${BR_TAR} packet -- \n\n"
        tar -xjf ${BR_TAR}
    fi
 
    printf "\n\n -- decompress ${BR_VER} -- \n\n"
    tar -xjf ${BR_PAK}/buildroot/${BR_VER}.tar.bz2
 
    mv ${BR_PAK} ${BR_VER}/dl 
}
 
function do_patch()
{
    msg_banner "Patch for ${BR_VER} "
 
    cd $BR_VER
 
    cp dl/buildroot/$BR_CONF .config
    sed -i "s|^BR2_HOST_DIR=.*|BR2_HOST_DIR=\"${INST_PATH}\"|g" .config
 
    cd -
}
 
function do_build()
{
    msg_banner "Build ${BR_VER} "
    cd $BR_VER
 
    make -j ${JOBS}
 
    cd -
}
 
function do_install()
{
    msg_banner "Install ${BR_VER} "
 
    # Packet and install crosstool 
    cd `dirname $INST_PATH`
    tar -cjf ${PRJ_PATH}/${BR_VER}-`basename $INST_PATH`.tar.bz2 `basename $INST_PATH`
 
    # Install rootfs tarball
    cp $WORK_SPACE/$BR_VER/output/images/rootfs.tar.bz2 ${PRJ_PATH}/rootfs_buildroot.tar.bz2
 
    echo ""
    echo " -- 1. Crosstool already installed to \"$INST_PATH\".";
    echo " -- 2. Crosstool and rootfs packet installed to \"$PRJ_PATH\"";
    echo " -- 3. Build workspace path is \"$WORK_SPACE\", you can remove it now.";
    echo ""
}
 
function do_prepare()
{
    INST_DIR=`dirname $INST_PATH`
    CUR_USER=`whoami`
 
    if [ ! -w $INST_DIR ] ; then
        echo ""
        echo "ERROR: Crosstool install path \"$INST_DIR\" not writable, please solve it by follow command: "
        echo "          sudo sh -c 'mkdir -p $INST_DIR && chown $CUR_USER.$CUR_USER $INST_DIR' "
        echo ""
        exit ;
    fi
 
    echo " Switch work space to \"$WORK_SPACE\" " 
    mkdir -p $WORK_SPACE 
    cd $WORK_SPACE
}
 
do_prepare
 
do_fetch
 
do_patch
 
do_build
 
do_install