凌云实验室推出的ARM Linux物联网网关开发板IGKBoard(IoT Gateway Kit Board)项目源码
guowenxue
2021-12-16 913a20efa2bf37aacf354809750e4441cdf120f0
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
#!/bin/bash
 
PRJ_PATH=`pwd`
 
BOARD=imx6ull
 
#CROSS_TOOL=arm-linux-gnueabihf-
CROSS_TOOL=/opt/buildroot/cortexA7/bin/arm-linux-
 
# bootloader, linux kernel tarball path and branch
TAR_PATH=${PRJ_PATH}/tarball
BSP_BRANCH="lf-5.10.52-2.1.0"
 
# rootfs should be buildroot/yocto or buster/bullseye for debian system
ROOTFS=buildroot
 
set -u
set -e
 
function do_modify_build()
{
    DIR=$1
 
    cd $PRJ_PATH
 
    sed -i "s|^BOARD.*|BOARD=${BOARD}|g" ${DIR}/build.sh
 
    if [ $DIR = bootloader -o $DIR == kernel ] ; then
        sed -i "s|^CROSS_TOOL.*|CROSS_TOOL=${CROSS_TOOL}|g" ${DIR}/build.sh
        sed -i "s|^BSP_BRANCH.*|BSP_BRANCH=${BSP_BRANCH}|g" ${DIR}/build.sh
    elif [ $DIR = rootfs -o $DIR == images -o $DIR = tarball ] ; then
        sed -i "s|^ROOTFS=.*|ROOTFS=${ROOTFS}|g" ${DIR}/build.sh
    fi
}
 
function do_modify()
{
    do_modify_build tarball
    do_modify_build bootloader
    do_modify_build kernel
    do_modify_build rootfs
    do_modify_build images
}
 
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
 
    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 "  Example: $0 -b bsp && sudo $0 -b 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
    cd tarball && ./build.sh && cd -
fi
 
if [ $1 == "bsp" ] ; then
    if [ $action == "build" ] ; then
        do_root "no"
    fi
    do_action bootloader $action
    do_action kernel $action
elif [ $1 == "image" ] ; then
    do_root "yes"
    do_action rootfs $action
    do_action images $action
fi