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