凌云实验室推出的ARM Linux物联网网关开发板IGKBoard(IoT Gateway Kit Board)项目源码
guowenxue
2022-06-12 78ccd1ebce0fa24c8fde2eb529bcb544800fa26c
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
#!/bin/bash
 
PRJ_PATH=`pwd`
 
BOARD=igkboard
CROSS_TOOL=/opt/buildroot/cortexA7/bin/arm-linux-
 
# SYSTEM  should be: buildroot, yocto or debian
# DISTRO  should be: 2021.02, hardknott/honister, bullseye
# SYSNAME should be: buildroot, yocto, bullseye
SYSTEM=buildroot
DISTRO=2021.02
 
SYSTEM=`echo $SYSTEM | tr 'A-Z' 'a-z'`
DISTRO=`echo $DISTRO | tr 'A-Z' 'a-z'`
 
set -u
set -e
 
 
function do_modify()
{
    cd $PRJ_PATH
 
    FILE=scripts/setup_env.sh
 
    sed -i "s|^BOARD.*|BOARD=${BOARD}|g" $FILE
    sed -i "s|^CROSS_TOOL.*|CROSS_TOOL=${CROSS_TOOL}|g" $FILE
 
    sed -i "s|^SYSTEM=.*|SYSTEM=${SYSTEM}|g" $FILE
    sed -i "s|^DISTRO=.*|DISTRO=${DISTRO}|g" $FILE
}
 
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_action()
{
    folder=$1
    action=$2
 
    if [ ! -f $PRJ_PATH/$folder/build.sh ] ;then
        return ;
    fi
 
    cd $PRJ_PATH/$folder
 
    if [ $action == "build" ] ; then
        ./build.sh -b
    elif [ $action == "clean" ] ; then
        ./build.sh -c
    fi
 
    cd $PRJ_PATH
}
 
function do_usage()
{
    echo ""
    echo "Usage:"
    echo " $0 [-b] [-c] [-h] bsp/image"
    echo "     -b bsp/image: build BSP or system image"
    echo "     -c bsp/image: clean BSP or system image"
    echo "     -h          : show this help message"
    echo ""
    echo " WARNNING: build/clean image need run as sudo"
    echo ""
    echo " Build Example: $0 -b bsp && sudo $0 -b image"
    echo " Clean Example: $0 -c bsp && sudo $0 -c image"
    echo ""
    exit;
}
 
 
action="usage"
 
while getopts "b:c:h" OPTNAME
do
    case "${OPTNAME}" in
        "b")
            action="build"
            shift
            ;;
 
        "c")
            action="clean"
            shift
            ;;
 
        "*")
            action="usage"
            ;;
    esac
done
 
if [ $action == "usage" ] ; then
    do_usage
fi
 
if [ $action == "build" ] ; then
    do_modify
fi
 
if [ $1 == "bsp" ] ; then
    if [ $action == "build" ] ; then
        do_root "no"
    fi
    do_action bootloader $action
    do_action kernel $action
    do_action drivers $action
elif [ $1 == "image" ] ; then
    do_root "yes"
    do_action rootfs $action
    do_action images $action
fi