commit | author | age
|
849fbd
|
1 |
#!/bin/bash |
G |
2 |
|
|
3 |
# this project absolute path |
|
4 |
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
|
5 |
|
|
6 |
# top project absolute path |
|
7 |
TOP_PATH=$(realpath $PRJ_PATH/..) |
|
8 |
|
|
9 |
# binaries build prefix install path |
|
10 |
PRFX_PATH=$PRJ_PATH/install |
|
11 |
|
|
12 |
# binaries finally install path if needed |
|
13 |
#INST_PATH=/tftp |
|
14 |
|
8e6109
|
15 |
# download taballs path |
G |
16 |
TARBALL_PATH=$PRJ_PATH/tarballs |
|
17 |
|
849fbd
|
18 |
# config file path |
G |
19 |
CONF_FILE=$TOP_PATH/config.json |
|
20 |
|
|
21 |
# shell script will exit once get command error |
|
22 |
set -e |
|
23 |
|
|
24 |
#+-------------------------+ |
|
25 |
#| Shell script functions | |
|
26 |
#+-------------------------+ |
|
27 |
|
|
28 |
function pr_error() { |
|
29 |
echo -e "\033[40;31m $1 \033[0m" |
|
30 |
} |
|
31 |
|
|
32 |
function pr_warn() { |
|
33 |
echo -e "\033[40;33m $1 \033[0m" |
|
34 |
} |
|
35 |
|
|
36 |
function pr_info() { |
|
37 |
echo -e "\033[40;32m $1 \033[0m" |
|
38 |
} |
|
39 |
|
8e6109
|
40 |
# decompress a packet to destination path |
G |
41 |
function do_unpack() |
|
42 |
{ |
|
43 |
tarball=$1 |
|
44 |
dstpath=`pwd` |
|
45 |
|
|
46 |
if [[ $# == 2 ]] ; then |
|
47 |
dstpath=$2 |
|
48 |
fi |
|
49 |
|
|
50 |
pr_info "decompress $tarball => $dstpath" |
|
51 |
|
|
52 |
mkdir -p $dstpath |
|
53 |
case $tarball in |
|
54 |
*.tar.gz) |
|
55 |
tar -xzf $tarball -C $dstpath |
|
56 |
;; |
|
57 |
|
|
58 |
*.tar.bz2) |
|
59 |
tar -xjf $tarball -C $dstpath |
|
60 |
;; |
|
61 |
|
|
62 |
*.tar.xz) |
|
63 |
tar -xJf $tarball -C $dstpath |
|
64 |
;; |
|
65 |
|
|
66 |
*.tar.zst) |
|
67 |
tar -I zstd -xf $tarball -C $dstpath |
|
68 |
;; |
|
69 |
|
|
70 |
*.tar) |
|
71 |
tar -xf $tarball -C $dstpath |
|
72 |
;; |
|
73 |
|
|
74 |
*.zip) |
|
75 |
unzip -qo $tarball -d $dstpath |
|
76 |
;; |
|
77 |
|
|
78 |
*) |
|
79 |
pr_error "decompress Unsupport packet: $tarball" |
|
80 |
return 1; |
|
81 |
;; |
|
82 |
esac |
|
83 |
} |
|
84 |
|
849fbd
|
85 |
# parser configure file and export environment variable |
G |
86 |
function export_env() |
|
87 |
{ |
|
88 |
export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
89 |
export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'` |
8e6109
|
90 |
export BSP_URL=`jq -r ".bsp.giturl" $CONF_FILE` |
G |
91 |
export CROSS_COMPILE=`jq -r ".bsp.cortexAtool" $CONF_FILE` |
849fbd
|
92 |
|
G |
93 |
export BRANCH=$BSP_VER |
8e6109
|
94 |
export KER_SRC=linux-imx |
G |
95 |
export KER_PATH=$PRJ_PATH/$KER_SRC |
256f95
|
96 |
export DRV_PATH=$TOP_PATH/drivers/${BOARD} |
849fbd
|
97 |
|
G |
98 |
export JOBS=`cat /proc/cpuinfo | grep processor | wc -l` |
d80f34
|
99 |
|
G |
100 |
if [[ $BOARD =~ mx6ull ]] ; then |
|
101 |
export ARCH=arm |
|
102 |
else |
|
103 |
export ARCH=arm64 |
|
104 |
fi |
849fbd
|
105 |
} |
G |
106 |
|
|
107 |
function build_kernel() |
|
108 |
{ |
b05652
|
109 |
defconfig=${BOARD}_defconfig |
8e6109
|
110 |
patch_file=$PRJ_PATH/patches/$BOARD/${KER_SRC}-$BSP_VER.patch |
849fbd
|
111 |
|
G |
112 |
cd $PRJ_PATH |
|
113 |
|
|
114 |
if [ -d $KER_PATH ] ; then |
|
115 |
pr_info "linux kernel source code fetched already" |
|
116 |
else |
|
117 |
pr_info "start fetch linux kernel source code" |
8e6109
|
118 |
|
G |
119 |
if [[ $BSP_URL =~ github.com ]] ; then |
|
120 |
git clone $BSP_URL/$KER_SRC.git -b $BRANCH --depth=1 |
|
121 |
else |
|
122 |
mkdir -p $TARBALL_PATH |
|
123 |
|
|
124 |
# Download source code packet |
|
125 |
if [ ! -s $TARBALL_PATH/$KER_SRC.tar.xz ] ; then |
86063e
|
126 |
wget $BSP_URL/imx/bsp/$BSP_VER/$KER_SRC.tar.xz -P $TARBALL_PATH |
8e6109
|
127 |
fi |
G |
128 |
|
|
129 |
# decompress source code packet |
|
130 |
do_unpack $TARBALL_PATH/$KER_SRC.tar.xz |
|
131 |
fi |
849fbd
|
132 |
fi |
G |
133 |
|
|
134 |
cd $KER_PATH |
|
135 |
|
d80f34
|
136 |
if [ ! -s arch/$ARCH/configs/$defconfig -a -s $patch_file ] ; then |
86063e
|
137 |
pr_warn "do patch for $KER_SRC now..." |
b05652
|
138 |
patch -p1 < $patch_file |
G |
139 |
fi |
|
140 |
|
86063e
|
141 |
pr_warn "start build $KER_SRC" |
G |
142 |
|
849fbd
|
143 |
if [ ! -s .config ] ; then |
G |
144 |
make ${defconfig} |
|
145 |
fi |
|
146 |
|
|
147 |
make -j ${JOBS} |
|
148 |
} |
|
149 |
|
|
150 |
function do_install() |
|
151 |
{ |
|
152 |
pr_info "start install linux kernel images" |
|
153 |
|
|
154 |
cd $KER_PATH |
|
155 |
|
|
156 |
if [ -d $PRFX_PATH ] ; then |
|
157 |
rm -rf $PRFX_PATH/* |
|
158 |
fi |
|
159 |
|
d80f34
|
160 |
mkdir -p $PRFX_PATH/overlays |
G |
161 |
|
|
162 |
# Install system image and device tree binaries |
|
163 |
|
|
164 |
if [[ $BOARD =~ 6ull ]] ; then |
|
165 |
set -x |
|
166 |
cp -f arch/${ARCH}/boot/zImage $PRFX_PATH |
|
167 |
cp -f arch/${ARCH}/boot/dts/${BOARD}.dtb $PRFX_PATH |
|
168 |
cp -f arch/${ARCH}/boot/dts/${BOARD}/*.dtbo $PRFX_PATH/overlays |
|
169 |
set +x |
|
170 |
else |
|
171 |
set -x |
|
172 |
cp -f arch/${ARCH}/boot/Image $PRFX_PATH |
|
173 |
cp -f arch/${ARCH}/boot/dts/freescale/${BOARD}.dtb $PRFX_PATH |
8e6109
|
174 |
#cp -f arch/${ARCH}/boot/dts/freescale/${BOARD}/*.dtbo $PRFX_PATH/overlays |
d80f34
|
175 |
set +x |
G |
176 |
fi |
849fbd
|
177 |
|
G |
178 |
# Install kernel modules |
|
179 |
make modules_install INSTALL_MOD_PATH=$PRFX_PATH INSTALL_MOD_STRIP=1 |
|
180 |
|
|
181 |
echo "" |
|
182 |
pr_info "linux kernel installed to '$PRFX_PATH'" |
|
183 |
ls $PRFX_PATH && echo "" |
|
184 |
|
|
185 |
if [[ -n "$INST_PATH" && -w $INST_PATH ]] ; then |
|
186 |
pr_info "install linux kernel to '$INST_PATH'" |
d80f34
|
187 |
cp -f $PRFX_PATH/*Image $INST_PATH |
G |
188 |
cp -f $PRFX_PATH/${BOARD}.dtb $INST_PATH |
849fbd
|
189 |
fi |
G |
190 |
} |
|
191 |
|
256f95
|
192 |
function build_driver() |
G |
193 |
{ |
|
194 |
if [ ! -d $DRV_PATH ] ; then |
|
195 |
return 0; |
|
196 |
fi |
|
197 |
|
|
198 |
pr_info "start ${BOARD} linux drivers" |
|
199 |
|
|
200 |
cd $DRV_PATH && ./build.sh |
|
201 |
|
|
202 |
cd $PRJ_PATH |
|
203 |
} |
|
204 |
|
849fbd
|
205 |
function do_build() |
G |
206 |
{ |
|
207 |
cd $PRJ_PATH |
|
208 |
|
|
209 |
build_kernel |
|
210 |
|
|
211 |
do_install |
256f95
|
212 |
|
G |
213 |
build_driver |
849fbd
|
214 |
} |
G |
215 |
|
|
216 |
function do_clean() |
|
217 |
{ |
|
218 |
cd $PRJ_PATH |
|
219 |
|
8e6109
|
220 |
rm -rf $PRJ_PATH/$KER_SRC |
G |
221 |
rm -rf $PRJ_PATH/tarballs |
849fbd
|
222 |
rm -rf $PRFX_PATH |
256f95
|
223 |
|
G |
224 |
cd $DRV_PATH && ./build.sh -c |
|
225 |
|
|
226 |
cd |
849fbd
|
227 |
} |
G |
228 |
|
|
229 |
#+-------------------------+ |
|
230 |
#| Shell script body entry | |
|
231 |
#+-------------------------+ |
|
232 |
|
|
233 |
export_env |
|
234 |
|
|
235 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
236 |
pr_warn "start clean linux kernel" |
|
237 |
do_clean |
|
238 |
exit; |
|
239 |
fi |
|
240 |
|
|
241 |
pr_warn "start build linux kernel for ${BOARD}" |
|
242 |
|
|
243 |
do_build |
|
244 |
|