commit | author | age
|
849fbd
|
1 |
#!/bin/bash |
G |
2 |
|
|
3 |
# bitbake target |
|
4 |
BB_TARGET=yocto-image-full |
|
5 |
|
|
6 |
# this project absolute path |
|
7 |
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
|
8 |
|
|
9 |
# top project absolute path |
|
10 |
TOP_PATH=$(realpath $PRJ_PATH/..) |
|
11 |
|
1cf118
|
12 |
# prefix install path |
G |
13 |
PRFX_PATH=$PRJ_PATH/install |
|
14 |
|
|
15 |
# final install path |
|
16 |
#INST_PATH=/srv/ftp/ |
|
17 |
|
|
18 |
# compress system image or not |
2ff83b
|
19 |
COMPRESS=yes |
849fbd
|
20 |
|
G |
21 |
# download taballs path |
|
22 |
TARBALL_PATH=$PRJ_PATH/tarballs |
|
23 |
|
|
24 |
# config file path |
|
25 |
CONF_FILE=$TOP_PATH/config.json |
|
26 |
|
|
27 |
# Download path |
8e6109
|
28 |
#DL_PATH="/srv/yocto_packets/" |
849fbd
|
29 |
|
G |
30 |
# shell script will exit once get command error |
|
31 |
set -e |
|
32 |
|
|
33 |
#+-------------------------+ |
|
34 |
#| Shell script functions | |
|
35 |
#+-------------------------+ |
|
36 |
|
|
37 |
function pr_error() { |
|
38 |
echo -e "\033[40;31m $1 \033[0m" |
|
39 |
} |
|
40 |
|
|
41 |
function pr_warn() { |
|
42 |
echo -e "\033[40;33m $1 \033[0m" |
|
43 |
} |
|
44 |
|
|
45 |
function pr_info() { |
|
46 |
echo -e "\033[40;32m $1 \033[0m" |
|
47 |
} |
|
48 |
|
|
49 |
# decompress a packet to destination path |
|
50 |
function do_unpack() |
|
51 |
{ |
|
52 |
tarball=$1 |
|
53 |
dstpath=`pwd` |
|
54 |
|
|
55 |
if [[ $# == 2 ]] ; then |
|
56 |
dstpath=$2 |
|
57 |
fi |
|
58 |
|
|
59 |
pr_info "decompress $tarball => $dstpath" |
|
60 |
|
|
61 |
mkdir -p $dstpath |
|
62 |
case $tarball in |
|
63 |
*.tar.gz) |
|
64 |
tar -xzf $tarball -C $dstpath |
|
65 |
;; |
|
66 |
|
|
67 |
*.tar.bz2) |
|
68 |
tar -xjf $tarball -C $dstpath |
|
69 |
;; |
|
70 |
|
|
71 |
*.tar.xz) |
|
72 |
tar -xJf $tarball -C $dstpath |
|
73 |
;; |
|
74 |
|
|
75 |
*.tar.zst) |
|
76 |
tar -I zstd -xf $tarball -C $dstpath |
|
77 |
;; |
|
78 |
|
|
79 |
*.tar) |
|
80 |
tar -xf $tarball -C $dstpath |
|
81 |
;; |
|
82 |
|
|
83 |
*.zip) |
|
84 |
unzip -qo $tarball -d $dstpath |
|
85 |
;; |
|
86 |
|
|
87 |
*) |
|
88 |
pr_error "decompress Unsupport packet: $tarball" |
|
89 |
return 1; |
|
90 |
;; |
|
91 |
esac |
|
92 |
} |
|
93 |
|
|
94 |
# parser configure file and export environment variable |
|
95 |
function export_env() |
|
96 |
{ |
|
97 |
export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
98 |
export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
99 |
export YCT_VER=`jq -r ".system.version" $CONF_FILE | tr 'A-Z' 'a-z'` |
8e6109
|
100 |
export BSP_URL=`jq -r ".bsp.giturl" $CONF_FILE` |
849fbd
|
101 |
|
G |
102 |
export YCT_BOARD=`echo $BOARD| cut -d- -f1` |
|
103 |
export YCT_META=meta-$YCT_BOARD |
8e6109
|
104 |
export YCT_SRC=$YCT_VER-$BSP_VER |
G |
105 |
export YCT_PATH=$PRJ_PATH/$YCT_SRC |
849fbd
|
106 |
export BUILD_DIR=${BOARD} |
G |
107 |
} |
|
108 |
|
|
109 |
function do_fetch() |
|
110 |
{ |
8e6109
|
111 |
cd $PRJ_PATH |
849fbd
|
112 |
|
8e6109
|
113 |
if [ ! -d $YCT_SRC/sources ] ; then |
849fbd
|
114 |
|
8e6109
|
115 |
if [[ $BSP_URL =~ github.com ]] ; then |
849fbd
|
116 |
|
8e6109
|
117 |
pr_info "start repo fetch Yocto $YCT_VER source code" |
849fbd
|
118 |
|
8e6109
|
119 |
mkdir -p $YCT_PATH && cd $YCT_PATH |
G |
120 |
|
|
121 |
if ! command -v repo > /dev/null 2>&1 ; then |
|
122 |
curl https://storage.googleapis.com/git-repo-downloads/repo > repo |
|
123 |
chmod a+x repo |
|
124 |
export PATH=$YCT_PATH:$PATH |
|
125 |
fi |
|
126 |
|
|
127 |
BSP_VER=`echo $BSP_VER | sed 's/lf/imx/'` |
|
128 |
repo init -u https://github.com/nxp-imx/imx-manifest -b imx-linux-$YCT_VER -m $BSP_VER.xml |
|
129 |
repo sync && rm -f repo |
|
130 |
|
|
131 |
else |
|
132 |
|
|
133 |
pr_info "start download fetch Yocto $YCT_VER source code" |
|
134 |
|
|
135 |
mkdir -p $TARBALL_PATH |
|
136 |
|
|
137 |
# Download source code packet |
|
138 |
if [ ! -s $TARBALL_PATH/$YCT_SRC.tar.xz ] ; then |
|
139 |
wget $BSP_URL/bsp/$BSP_VER/$YCT_SRC.tar.xz -P $TARBALL_PATH |
|
140 |
fi |
|
141 |
|
|
142 |
# decompress source code packet |
|
143 |
do_unpack $TARBALL_PATH/$YCT_SRC.tar.xz |
|
144 |
|
849fbd
|
145 |
fi |
G |
146 |
|
|
147 |
else |
|
148 |
pr_warn "Yocto $YCT_VER source code fetched already" |
|
149 |
fi |
|
150 |
|
|
151 |
if [ ! -d $PRJ_PATH/$YCT_META ] ; then |
|
152 |
pr_error "Yocto meta $YCT_META not exist" |
|
153 |
exit ; |
|
154 |
fi |
|
155 |
|
|
156 |
pr_warn "start update BSP patches for $YCT_META" |
1cf118
|
157 |
BSP_VER=`echo $BSP_VER | sed 's/imx/lf/'` |
849fbd
|
158 |
cp $TOP_PATH/bootloader/patches/${BOARD}/uboot-imx-${BSP_VER}.patch $PRJ_PATH/$YCT_META/recipes-bsp/u-boot/files/ |
G |
159 |
cp $TOP_PATH/kernel/patches/${BOARD}/linux-imx-${BSP_VER}.patch $PRJ_PATH/$YCT_META/recipes-kernel/linux/files/ |
|
160 |
|
|
161 |
if [ ! -e $YCT_PATH/sources/$YCT_META ] ; then |
|
162 |
ln -s $PRJ_PATH/$YCT_META $YCT_PATH/sources/$YCT_META |
|
163 |
fi |
|
164 |
} |
|
165 |
|
|
166 |
function do_build() |
|
167 |
{ |
|
168 |
cd $YCT_PATH |
|
169 |
|
|
170 |
if [ ! -f ${BUILD_DIR}/conf/local.conf ] ; then |
|
171 |
pr_info "source $YCT_BOARD-setup.sh" |
|
172 |
MACHINE=${BOARD} source sources/$YCT_META/tools/$YCT_BOARD-setup.sh -b $BUILD_DIR |
|
173 |
else |
|
174 |
pr_info "source poky/oe-init-build-env" |
|
175 |
source sources/poky/oe-init-build-env $BUILD_DIR |
|
176 |
fi |
|
177 |
|
|
178 |
if [[ -n "$DL_PATH" ]] ; then |
|
179 |
sed -i "s|^#DL_DIR.*|DL_DIR ?= \"$DL_PATH/$YCT_VER\"|g" conf/local.conf |
|
180 |
sed -i "s|^DL_DIR.*|DL_DIR ?= \"$DL_PATH/$YCT_VER\"|g" conf/local.conf |
|
181 |
fi |
|
182 |
|
|
183 |
bitbake $BB_TARGET |
|
184 |
} |
|
185 |
|
|
186 |
function do_install() |
|
187 |
{ |
2334ec
|
188 |
IMAGE_NAME=yocto-${YCT_VER}-${BSP_VER}.wic |
G |
189 |
ROOTFS_TAR=rootfs-yocto-${YCT_VER}.tar.zst |
|
190 |
|
849fbd
|
191 |
cd $YCT_PATH |
G |
192 |
|
|
193 |
echo "" |
1cf118
|
194 |
pr_info "Yocto($YCT_VER) installed to '$PRFX_PATH'" |
849fbd
|
195 |
|
1cf118
|
196 |
mkdir -p ${PRFX_PATH} |
2334ec
|
197 |
cp $YCT_PATH/$BUILD_DIR/tmp/deploy/images/$BOARD/$BB_TARGET-$BOARD.wic ${PRFX_PATH}/$IMAGE_NAME |
G |
198 |
cp $YCT_PATH/$BUILD_DIR/tmp/deploy/images/$BOARD/$BB_TARGET-$BOARD.tar.zst ${PRFX_PATH}/$ROOTFS_TAR |
6a78bd
|
199 |
|
G |
200 |
if [[ $BOARD =~ mx6ull ]] ; then |
|
201 |
cp $YCT_PATH/$BUILD_DIR/tmp/deploy/images/$BOARD/u-boot-${BOARD}.imx ${PRFX_PATH}/u-boot-${BOARD}.imx |
|
202 |
else |
|
203 |
cp $YCT_PATH/$BUILD_DIR/tmp/deploy/images/$BOARD/imx-boot ${PRFX_PATH}/u-boot-${BOARD}.imx |
|
204 |
fi |
2ff83b
|
205 |
|
G |
206 |
cd ${PRFX_PATH}/ |
|
207 |
|
|
208 |
if [[ `echo $COMPRESS | tr 'A-Z' 'a-z'` == "yes" ]] ; then |
2334ec
|
209 |
pr_info "Start bzip2 compress $IMAGE_NAME" |
G |
210 |
rm -f $IMAGE_NAME.bz2 |
|
211 |
bzip2 $IMAGE_NAME |
2ff83b
|
212 |
fi |
G |
213 |
chmod a+x u-boot-${BOARD}.imx |
|
214 |
|
|
215 |
ls && echo "" |
849fbd
|
216 |
|
1cf118
|
217 |
if [ -n "$INST_PATH" -a -w $INST_PATH ] ; then |
G |
218 |
|
|
219 |
pr_info "Start copy Yocto system images to $INST_PATH" |
2334ec
|
220 |
cp u-boot-${BOARD}.imx $INST_PATH |
G |
221 |
cp $IMAGE_NAME* $INST_PATH |
|
222 |
cp $ROOTFS_TAR $INST_PATH |
1cf118
|
223 |
|
G |
224 |
ls ${INST_PATH} && echo "" |
|
225 |
fi |
|
226 |
|
849fbd
|
227 |
} |
G |
228 |
|
|
229 |
function do_clean() |
|
230 |
{ |
|
231 |
cd $PRJ_PATH |
|
232 |
|
1cf118
|
233 |
rm -rf $PRFX_PATH |
849fbd
|
234 |
} |
G |
235 |
|
|
236 |
#+-------------------------+ |
|
237 |
#| Shell script body entry | |
|
238 |
#+-------------------------+ |
|
239 |
|
|
240 |
export_env |
|
241 |
|
|
242 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
243 |
pr_warn "start clean Yocto source code" |
|
244 |
do_clean |
|
245 |
exit; |
|
246 |
fi |
|
247 |
|
|
248 |
pr_warn "start build Yocto $YCT_VER for ${BOARD}" |
|
249 |
|
|
250 |
do_fetch |
|
251 |
|
|
252 |
do_build |
|
253 |
|
|
254 |
do_install |