guowenxue
2024-07-13 0bc1e30ccf48fadc7b21424404093ce75b43481f
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
#!/bin/bash
 
CWD=$(pwd)
 
function log_error(){
    echo -ne "\e[31m $1 \e[0m\n"
}
 
function usage(){
    echo "Usage:"
    echo " MACHINE=<machine> source igkboard-setup.sh <build-dir>"
    echo "Options:"
    echo "  <machine>    machine name"
    echo "               - igkboard-imx8mp"
    echo "               - igkboard-imx6ull"
    echo "  * [-b build-dir]: Build directory, if unspecified script uses 'build' as output directory"
    echo "  * [-h]: help"
    echo "Examples: "
    echo "$ MACHINE=igkboard-imx8mp source sources/meta-igkboard/tools/igkboard-setup.sh -b igkboard-imx8mp"
    echo "$ MACHINE=igkboard-imx6ull source sources/meta-igkboard/tools/igkboard-setup.sh -b igkboard-imx6ull"
    echo
}
 
function cleanup_EULA(){
    cd $CWD/sources/meta-freescale
    if [ -h EULA ]; then
        echo Cleanup meta-freescale/EULA...
        git checkout -- EULA
    fi
    if [ ! -f classes/fsl-eula-unpack.bbclass ]; then
        echo Cleanup meta-freescale/classes/fsl-eula-unpack.bbclass...
        git checkout -- classes/fsl-eula-unpack.bbclass
    fi
    cd -
}
 
function file_override() {
    source_path=$1
    override_root=$2
    if [ -f $source_path ]; then
        override_path=$override_root/`basename $source_path`
        if [ -f $override_path ]; then
            echo "\
 
WARNING: The file '$CWD/$source_path' is replacing the upstream file '$CWD/$override_path'. \
Overrides by file replacement are error-prone and discouraged. Please find an \
alternative override mechanism that uses meta-data only.
"
            rm $override_path
        fi
    fi
}
 
function machine_overrides() {
    layer=$1
    upstream_layer=$2
    machines="../sources/$layer/conf/machine/*"
    machine_includes="../sources/$layer/conf/machine/include/*"
    for machine in $machines; do
        file_override $machine ../sources/$upstream_layer/conf/machine
    done
    for machine_include in $machine_includes; do
        file_override $machine_include ../sources/$upstream_layer/conf/machine/include
    done
}
 
function bbclass_overrides() {
    layer=$1
    upstream_layer=$2
    bbclasses="../sources/$layer/classes/*"
    for bbclass in $bbclasses; do
        file_override $bbclass ../sources/$upstream_layer/classes
    done
}
 
function hook_in_layer() {
    layer=$1
    shift
    if [ "$1" = "" ]; then
        upstream_layers="meta-freescale"
    else
        upstream_layers="$@"
    fi
 
    # echo "BBLAYERS += \"\${BSPDIR}/sources/$layer\"" >> conf/bblayers.conf
    for upstream_layer in $upstream_layers; do
        machine_overrides $layer $upstream_layer
        bbclass_overrides $layer $upstream_layer
    done
}
 
function igkboard_conf_set(){
    local build_dir=$1
    cp $CWD/sources/meta-igkboard/conf/${MACHINE}_local.conf $CWD/${build_dir}/conf/local.conf
    cp $CWD/sources/meta-igkboard/conf/bblayers.conf $CWD/${build_dir}/conf/bblayers.conf
}
 
function run(){
    local build_dir=$1
    local oeroot=$CWD/sources/poky
    if [ -e $CWD/sources/oe-core ]; then
        oeroot=$CWD/sources/oe-core
    fi
    . $oeroot/oe-init-build-env $CWD/$build_dir > /dev/null
    if [ ! -e conf/local.conf ]; then
        log_error "oe-init-build-env does not generated."
        exit -1
    fi
    igkboard_conf_set $build_dir
 
    # Clean up PATH, because if it includes tokens to current directories somehow,
    # wrong binaries can be used instead of the expected ones during task execution
    export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
 
    cat <<EOF
    Welcome LingYun IoT Gateway Kit Board Yocto BSP
 
    The Yocto Project has extensive documentation about OE including a
    reference manual which can be found at:
        http://yoctoproject.org/documentation
 
    You can now run 'bitbake <target>'
 
    Common targets are:
        yocto-image-full
        core-image-minimal
        imx-image-full
 
EOF
 
    hook_in_layer meta-imx/meta-bsp
    hook_in_layer meta-imx/meta-sdk
    hook_in_layer meta-nxp-demo-experience
}
 
function start(){
    if [ "$(whoami)" = "root" ]; then
        echo "ERROR: do not use the BSP as root. Exiting..."
        exit -1
    fi
    local BUILD_DIR;
    local OLD_OPTIND=$OPTIND
 
    while getopts "b:h" fsl_setup_flag
    do
        case $fsl_setup_flag in
            b)
                BUILD_DIR="$OPTARG";
                echo -e "\n Build directory is " $BUILD_DIR
                ;;
            h)
                usage
                exit -1
                ;;
            \?)
                usage
                exit -1;;
        esac
    done
    shift $((OPTIND-1))
 
    OPTIND=$OLD_OPTIND
 
    if [ -z "$BUILD_DIR" ]; then
        BUILD_DIR='build'
    fi
    if [ -z "$MACHINE" ]; then
        echo setting to default machine
        MACHINE='igkboard-imx8mp'
    fi
    cleanup_EULA;
 
    mkdir -p $BUILD_DIR
    run $BUILD_DIR
}
 
start $@