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 |
849fbd
|
96 |
|
G |
97 |
export JOBS=`cat /proc/cpuinfo | grep processor | wc -l` |
d80f34
|
98 |
|
G |
99 |
if [[ $BOARD =~ mx6ull ]] ; then |
|
100 |
export ARCH=arm |
|
101 |
else |
|
102 |
export ARCH=arm64 |
|
103 |
fi |
849fbd
|
104 |
} |
G |
105 |
|
|
106 |
function build_kernel() |
|
107 |
{ |
b05652
|
108 |
defconfig=${BOARD}_defconfig |
8e6109
|
109 |
patch_file=$PRJ_PATH/patches/$BOARD/${KER_SRC}-$BSP_VER.patch |
849fbd
|
110 |
|
G |
111 |
cd $PRJ_PATH |
|
112 |
|
|
113 |
if [ -d $KER_PATH ] ; then |
|
114 |
pr_info "linux kernel source code fetched already" |
|
115 |
else |
|
116 |
pr_info "start fetch linux kernel source code" |
8e6109
|
117 |
|
G |
118 |
if [[ $BSP_URL =~ github.com ]] ; then |
|
119 |
git clone $BSP_URL/$KER_SRC.git -b $BRANCH --depth=1 |
|
120 |
else |
|
121 |
mkdir -p $TARBALL_PATH |
|
122 |
|
|
123 |
# Download source code packet |
|
124 |
if [ ! -s $TARBALL_PATH/$KER_SRC.tar.xz ] ; then |
86063e
|
125 |
wget $BSP_URL/imx/bsp/$BSP_VER/$KER_SRC.tar.xz -P $TARBALL_PATH |
8e6109
|
126 |
fi |
G |
127 |
|
|
128 |
# decompress source code packet |
|
129 |
do_unpack $TARBALL_PATH/$KER_SRC.tar.xz |
|
130 |
fi |
849fbd
|
131 |
fi |
G |
132 |
|
|
133 |
cd $KER_PATH |
|
134 |
|
d80f34
|
135 |
if [ ! -s arch/$ARCH/configs/$defconfig -a -s $patch_file ] ; then |
86063e
|
136 |
pr_warn "do patch for $KER_SRC now..." |
b05652
|
137 |
patch -p1 < $patch_file |
G |
138 |
fi |
|
139 |
|
86063e
|
140 |
pr_warn "start build $KER_SRC" |
G |
141 |
|
849fbd
|
142 |
if [ ! -s .config ] ; then |
G |
143 |
make ${defconfig} |
|
144 |
fi |
|
145 |
|
|
146 |
make -j ${JOBS} |
|
147 |
} |
|
148 |
|
|
149 |
function do_install() |
|
150 |
{ |
|
151 |
pr_info "start install linux kernel images" |
|
152 |
|
|
153 |
cd $KER_PATH |
|
154 |
|
|
155 |
if [ -d $PRFX_PATH ] ; then |
|
156 |
rm -rf $PRFX_PATH/* |
|
157 |
fi |
|
158 |
|
d80f34
|
159 |
mkdir -p $PRFX_PATH/overlays |
G |
160 |
|
|
161 |
# Install system image and device tree binaries |
|
162 |
|
|
163 |
if [[ $BOARD =~ 6ull ]] ; then |
|
164 |
set -x |
|
165 |
cp -f arch/${ARCH}/boot/zImage $PRFX_PATH |
|
166 |
cp -f arch/${ARCH}/boot/dts/${BOARD}.dtb $PRFX_PATH |
|
167 |
cp -f arch/${ARCH}/boot/dts/${BOARD}/*.dtbo $PRFX_PATH/overlays |
|
168 |
set +x |
|
169 |
else |
|
170 |
set -x |
|
171 |
cp -f arch/${ARCH}/boot/Image $PRFX_PATH |
|
172 |
cp -f arch/${ARCH}/boot/dts/freescale/${BOARD}.dtb $PRFX_PATH |
8e6109
|
173 |
#cp -f arch/${ARCH}/boot/dts/freescale/${BOARD}/*.dtbo $PRFX_PATH/overlays |
d80f34
|
174 |
set +x |
G |
175 |
fi |
849fbd
|
176 |
|
G |
177 |
# Install kernel modules |
|
178 |
make modules_install INSTALL_MOD_PATH=$PRFX_PATH INSTALL_MOD_STRIP=1 |
|
179 |
|
|
180 |
echo "" |
|
181 |
pr_info "linux kernel installed to '$PRFX_PATH'" |
|
182 |
ls $PRFX_PATH && echo "" |
|
183 |
|
|
184 |
if [[ -n "$INST_PATH" && -w $INST_PATH ]] ; then |
|
185 |
pr_info "install linux kernel to '$INST_PATH'" |
d80f34
|
186 |
cp -f $PRFX_PATH/*Image $INST_PATH |
G |
187 |
cp -f $PRFX_PATH/${BOARD}.dtb $INST_PATH |
849fbd
|
188 |
fi |
G |
189 |
} |
|
190 |
|
|
191 |
function do_build() |
|
192 |
{ |
|
193 |
cd $PRJ_PATH |
|
194 |
|
|
195 |
build_kernel |
|
196 |
|
|
197 |
do_install |
|
198 |
} |
|
199 |
|
|
200 |
function do_clean() |
|
201 |
{ |
|
202 |
cd $PRJ_PATH |
|
203 |
|
8e6109
|
204 |
rm -rf $PRJ_PATH/$KER_SRC |
G |
205 |
rm -rf $PRJ_PATH/tarballs |
849fbd
|
206 |
rm -rf $PRFX_PATH |
G |
207 |
} |
|
208 |
|
|
209 |
#+-------------------------+ |
|
210 |
#| Shell script body entry | |
|
211 |
#+-------------------------+ |
|
212 |
|
|
213 |
export_env |
|
214 |
|
|
215 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
216 |
pr_warn "start clean linux kernel" |
|
217 |
do_clean |
|
218 |
exit; |
|
219 |
fi |
|
220 |
|
|
221 |
pr_warn "start build linux kernel for ${BOARD}" |
|
222 |
|
|
223 |
do_build |
|
224 |
|