guowenxue
2023-12-12 849fbd3ab201e2e4694d302787fed48fb2172898
commit | author | age
849fbd 1 #!/bin/bash
G 2
3 CWD=$(pwd)
4
5 function log_error(){
6     echo -ne "\e[31m $1 \e[0m\n"
7 }
8
9 function usage(){
10     echo "Usage:"
11     echo " MACHINE=<machine> source igkboard-setup.sh <build-dir>"
12     echo "Options:"
13     echo "  <machine>    machine name"
14     echo "               - igkboard-imx8mp"
15     echo "  * [-b build-dir]: Build directory, if unspecified script uses 'build' as output directory"
16     echo "  * [-h]: help"
17     echo "Examples: "
18     echo "$ MACHINE=igkboard-imx8mp source sources/meta-igkboard/tools/igkboard-setup.sh -b igkboard-imx8mp"
19     echo
20 }
21
22 function cleanup_EULA(){
23     cd $CWD/sources/meta-freescale
24     if [ -h EULA ]; then
25         echo Cleanup meta-freescale/EULA...
26         git checkout -- EULA
27     fi
28     if [ ! -f classes/fsl-eula-unpack.bbclass ]; then
29         echo Cleanup meta-freescale/classes/fsl-eula-unpack.bbclass...
30         git checkout -- classes/fsl-eula-unpack.bbclass
31     fi
32     cd -
33 }
34
35 function file_override() {
36     source_path=$1
37     override_root=$2
38     if [ -f $source_path ]; then
39         override_path=$override_root/`basename $source_path`
40         if [ -f $override_path ]; then
41             echo "\
42
43 WARNING: The file '$CWD/$source_path' is replacing the upstream file '$CWD/$override_path'. \
44 Overrides by file replacement are error-prone and discouraged. Please find an \
45 alternative override mechanism that uses meta-data only.
46 "
47             rm $override_path
48         fi
49     fi
50 }
51
52 function machine_overrides() {
53     layer=$1
54     upstream_layer=$2
55     machines="../sources/$layer/conf/machine/*"
56     machine_includes="../sources/$layer/conf/machine/include/*"
57     for machine in $machines; do
58         file_override $machine ../sources/$upstream_layer/conf/machine
59     done
60     for machine_include in $machine_includes; do
61         file_override $machine_include ../sources/$upstream_layer/conf/machine/include
62     done
63 }
64
65 function bbclass_overrides() {
66     layer=$1
67     upstream_layer=$2
68     bbclasses="../sources/$layer/classes/*"
69     for bbclass in $bbclasses; do
70         file_override $bbclass ../sources/$upstream_layer/classes
71     done
72 }
73
74 function hook_in_layer() {
75     layer=$1
76     shift
77     if [ "$1" = "" ]; then
78         upstream_layers="meta-freescale"
79     else
80         upstream_layers="$@"
81     fi
82
83     # echo "BBLAYERS += \"\${BSPDIR}/sources/$layer\"" >> conf/bblayers.conf
84     for upstream_layer in $upstream_layers; do
85         machine_overrides $layer $upstream_layer
86         bbclass_overrides $layer $upstream_layer
87     done
88 }
89
90 function igkboard_conf_set(){
91     local build_dir=$1
92     cp $CWD/sources/meta-igkboard/conf/local.conf $CWD/${build_dir}/conf/local.conf
93     cp $CWD/sources/meta-igkboard/conf/bblayers.conf $CWD/${build_dir}/conf/bblayers.conf
94 }
95
96 function run(){
97     local build_dir=$1
98     local oeroot=$CWD/sources/poky
99     if [ -e $CWD/sources/oe-core ]; then
100         oeroot=$CWD/sources/oe-core
101     fi
102     . $oeroot/oe-init-build-env $CWD/$build_dir > /dev/null
103     if [ ! -e conf/local.conf ]; then
104         log_error "oe-init-build-env does not generated."
105         exit -1
106     fi
107     igkboard_conf_set $build_dir
108
109     # Clean up PATH, because if it includes tokens to current directories somehow,
110     # wrong binaries can be used instead of the expected ones during task execution
111     export PATH="`echo $PATH | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
112
113     cat <<EOF
114     Welcome LingYun IoT Gateway Kit Board Yocto BSP
115
116     The Yocto Project has extensive documentation about OE including a
117     reference manual which can be found at:
118         http://yoctoproject.org/documentation
119
120     You can now run 'bitbake <target>'
121
122     Common targets are:
123         yocto-image-full
124         core-image-minimal
125         imx-image-full
126
127 EOF
128
129     hook_in_layer meta-imx/meta-bsp
130     hook_in_layer meta-imx/meta-sdk
131     hook_in_layer meta-nxp-demo-experience
132 }
133
134 function start(){
135     if [ "$(whoami)" = "root" ]; then
136         echo "ERROR: do not use the BSP as root. Exiting..."
137         exit -1
138     fi
139     local BUILD_DIR;
140     local OLD_OPTIND=$OPTIND
141
142     while getopts "b:h" fsl_setup_flag
143     do
144         case $fsl_setup_flag in
145             b)
146                 BUILD_DIR="$OPTARG";
147                 echo -e "\n Build directory is " $BUILD_DIR
148                 ;;
149             h)
150                 usage
151                 exit -1
152                 ;;
153             \?)
154                 usage
155                 exit -1;;
156         esac
157     done
158     shift $((OPTIND-1))
159
160     OPTIND=$OLD_OPTIND
161
162     if [ -z "$BUILD_DIR" ]; then
163         BUILD_DIR='build'
164     fi
165     if [ -z "$MACHINE" ]; then
166         echo setting to default machine
167         MACHINE='igkboard-imx8mp'
168     fi
169     cleanup_EULA;
170
171     mkdir -p $BUILD_DIR
172     run $BUILD_DIR
173 }
174
175 start $@
176