commit | author | age
|
256f95
|
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 |
|
|
15 |
# download taballs path |
|
16 |
TARBALL_PATH=$PRJ_PATH/tarballs |
|
17 |
|
|
18 |
# config file path |
|
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 |
|
|
40 |
# decompress a packet to destination path |
|
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 |
|
|
85 |
# parser configure file and export environment variable |
|
86 |
function export_env() |
|
87 |
{ |
|
88 |
export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
89 |
export CROSS_COMPILE=`jq -r ".bsp.cortexAtool" $CONF_FILE` |
|
90 |
export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
91 |
export BSP_URL=`jq -r ".bsp.giturl" $CONF_FILE` |
|
92 |
|
|
93 |
export KER_SRC=linux-imx |
|
94 |
export KER_PATH=$TOP_PATH/kernel/linux-imx |
|
95 |
export DRV_PATH=$TOP_PATH/kernel/install |
|
96 |
|
682e1c
|
97 |
export KER_VER=`echo $BSP_VER|awk -F"-" '{print $2}'` |
b496e5
|
98 |
export KER_MODPATH=`ls -d $DRV_PATH/lib/modules/${KER_VER}* | head -n 1` |
G |
99 |
export KER_MODNAME=`basename ${KER_MODPATH}` |
682e1c
|
100 |
|
256f95
|
101 |
export JOBS=`cat /proc/cpuinfo | grep processor | wc -l` |
G |
102 |
|
|
103 |
if [[ $BOARD =~ mx6ull ]] ; then |
|
104 |
export ARCH=arm |
|
105 |
else |
|
106 |
export ARCH=arm64 |
|
107 |
fi |
|
108 |
} |
|
109 |
|
|
110 |
function build_user() |
|
111 |
{ |
|
112 |
SRC=user |
|
113 |
|
|
114 |
if [ ! -d ${SRC} ] ; then |
|
115 |
return ; |
|
116 |
fi |
|
117 |
|
|
118 |
pr_warn "Build for users driver" |
|
119 |
cd ${SRC} |
|
120 |
|
|
121 |
sed -i "s|^CROSS_COMPILE ?=.*|CROSS_COMPILE ?= ${CROSS_COMPILE}|g" Makefile |
|
122 |
make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} LINUX_SRC=${KER_PATH} DRV_PATH=${DRV_PATH}/ |
|
123 |
|
|
124 |
cd ${PRJ_PATH} |
|
125 |
} |
|
126 |
|
597549
|
127 |
function build_rtl8188fu() |
256f95
|
128 |
{ |
G |
129 |
SRC=rtl8188fu |
|
130 |
|
|
131 |
cd $PRJ_PATH |
|
132 |
|
|
133 |
if [ -d $SRC ] ; then |
|
134 |
pr_info "$SRC USB WiFi driver source code fetched already" |
|
135 |
else |
|
136 |
pr_info "start fetch $SRC USB WiFi drver source code" |
|
137 |
|
|
138 |
if [[ $BSP_URL =~ github.com ]] ; then |
|
139 |
git clone https://github.com/kelebek333/rtl8188fu.git --depth=1 $SRC |
|
140 |
else |
|
141 |
mkdir -p $TARBALL_PATH |
|
142 |
|
|
143 |
# Download source code packet |
|
144 |
if [ ! -s $TARBALL_PATH/$SRC.tar.xz ] ; then |
|
145 |
wget $BSP_URL/imx/bsp/misc/$SRC.tar.xz -P $TARBALL_PATH |
|
146 |
fi |
|
147 |
|
|
148 |
# decompress source code packet |
|
149 |
do_unpack $TARBALL_PATH/$SRC.tar.xz |
|
150 |
fi |
|
151 |
fi |
|
152 |
|
|
153 |
cd $SRC |
|
154 |
|
|
155 |
pr_warn "start update $SRC USB WiFi driver source code" |
|
156 |
|
|
157 |
sed -i "s|^CROSS_COMPILE ?=.*|CROSS_COMPILE ?= ${CROSS_COMPILE}|g" Makefile |
|
158 |
sed -i "s|^ARCH ?=.*|ARCH ?= arm|g" Makefile |
|
159 |
sed -i "s|^KVER.*|KVER := $KER_VER|g" Makefile |
|
160 |
sed -i "s|^KSRC.*|KSRC := ${KER_PATH}|g" Makefile |
|
161 |
sed -i "s|^MODDESTDIR.*|MODDESTDIR := ${DRV_PATH}|g" Makefile |
|
162 |
|
|
163 |
sed -i "s|^#define CONFIG_DEBUG|//#define CONFIG_DEBUG|g" include/autoconf.h |
|
164 |
|
|
165 |
sed -i "/nolinked power/d" core/rtw_pwrctrl.c |
|
166 |
sed -i "/request firmware/d" hal/rtl8188f/rtl8188f_hal_init.c |
|
167 |
|
|
168 |
pr_warn "start build $SRC USB WiFi driver" |
|
169 |
make -j ${JOBS} modules |
|
170 |
|
b496e5
|
171 |
cp rtl8188fu.ko ${KER_MODPATH}/extra/ |
G |
172 |
depmod -a -b ${DRV_PATH}/ ${KER_MODNAME} |
8829b1
|
173 |
|
G |
174 |
mkdir -p ${DRV_PATH}/lib/firmware/rtlwifi/ |
256f95
|
175 |
cp firmware/rtl8188fufw.bin ${DRV_PATH}/lib/firmware/rtlwifi/ |
G |
176 |
} |
|
177 |
|
|
178 |
|
597549
|
179 |
function build_rtl8723du() |
G |
180 |
{ |
|
181 |
SRC=rtl8723du |
|
182 |
|
|
183 |
cd $PRJ_PATH |
|
184 |
|
|
185 |
if [ -d $SRC ] ; then |
|
186 |
pr_info "$SRC USB WiFi driver source code fetched already" |
|
187 |
else |
|
188 |
pr_info "start fetch $SRC USB WiFi drver source code" |
|
189 |
|
|
190 |
if [[ $BSP_URL =~ github.com ]] ; then |
|
191 |
git clone https://github.com/lwfinger/rtw88.git --depth=1 $SRC |
|
192 |
else |
|
193 |
mkdir -p $TARBALL_PATH |
|
194 |
|
|
195 |
# Download source code packet |
|
196 |
if [ ! -s $TARBALL_PATH/$SRC.tar.xz ] ; then |
|
197 |
wget $BSP_URL/imx/bsp/misc/$SRC.tar.xz -P $TARBALL_PATH |
|
198 |
fi |
|
199 |
|
|
200 |
# decompress source code packet |
|
201 |
do_unpack $TARBALL_PATH/$SRC.tar.xz |
|
202 |
fi |
|
203 |
fi |
|
204 |
|
|
205 |
cd $SRC |
|
206 |
|
|
207 |
pr_warn "start update $SRC USB WiFi driver source code" |
|
208 |
|
|
209 |
sed -i "s|^KVER.*|KVER ?= $KER_VER|g" Makefile |
|
210 |
sed -i "s|^KSRC.*|KSRC := ${KER_PATH}|g" Makefile |
b496e5
|
211 |
sed -i "s|^MODDESTDIR.*|MODDESTDIR := ${KER_MODPATH}/extra/|g" Makefile |
597549
|
212 |
sed -i "s|^FIRMWAREDIR.*|FIRMWAREDIR := ${DRV_PATH}/lib/firmware/|g" Makefile |
682e1c
|
213 |
sed -i '/depmod -a .*/d' Makefile |
597549
|
214 |
|
G |
215 |
pr_warn "start build $SRC USB WiFi driver" |
|
216 |
make -j ${JOBS} |
682e1c
|
217 |
make install |
b496e5
|
218 |
depmod -a -b ${DRV_PATH}/ ${KER_MODNAME} |
597549
|
219 |
} |
G |
220 |
|
|
221 |
|
256f95
|
222 |
function do_build() |
G |
223 |
{ |
|
224 |
cd $PRJ_PATH |
|
225 |
|
|
226 |
build_user |
|
227 |
|
597549
|
228 |
build_rtl8188fu |
G |
229 |
|
|
230 |
build_rtl8723du |
256f95
|
231 |
} |
G |
232 |
|
|
233 |
function do_clean() |
|
234 |
{ |
|
235 |
cd $PRJ_PATH |
|
236 |
|
682e1c
|
237 |
rm -rf rtl8188fu rtl8723du tarballs |
256f95
|
238 |
|
G |
239 |
if [ -d user ] ; then |
|
240 |
cd user |
|
241 |
make clean; |
|
242 |
fi |
|
243 |
|
|
244 |
} |
|
245 |
|
|
246 |
#+-------------------------+ |
|
247 |
#| Shell script body entry | |
|
248 |
#+-------------------------+ |
|
249 |
|
|
250 |
export_env |
|
251 |
|
|
252 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
253 |
pr_warn "start clean drivers" |
|
254 |
do_clean |
|
255 |
exit; |
|
256 |
fi |
|
257 |
|
|
258 |
pr_warn "start build linux driver for ${BOARD}" |
|
259 |
|
|
260 |
do_build |
|
261 |
|