commit | author | age
|
5f67ca
|
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 |
|
|
97 |
export JOBS=`cat /proc/cpuinfo | grep processor | wc -l` |
|
98 |
|
|
99 |
if [[ $BOARD =~ mx6ull ]] ; then |
|
100 |
export ARCH=arm |
|
101 |
else |
|
102 |
export ARCH=arm64 |
|
103 |
fi |
|
104 |
} |
|
105 |
|
|
106 |
function build_user() |
|
107 |
{ |
|
108 |
SRC=user |
|
109 |
|
|
110 |
if [ ! -d ${SRC} ] ; then |
|
111 |
return ; |
|
112 |
fi |
|
113 |
|
|
114 |
pr_warn "Build for users driver" |
|
115 |
cd ${SRC} |
|
116 |
|
|
117 |
sed -i "s|^CROSS_COMPILE ?=.*|CROSS_COMPILE ?= ${CROSS_COMPILE}|g" Makefile |
|
118 |
make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} LINUX_SRC=${KER_PATH} DRV_PATH=${DRV_PATH}/ |
|
119 |
|
|
120 |
cd ${PRJ_PATH} |
|
121 |
} |
|
122 |
|
|
123 |
function build_rtl8723du() |
|
124 |
{ |
|
125 |
SRC=rtl8723du |
|
126 |
|
|
127 |
cd $PRJ_PATH |
|
128 |
|
|
129 |
if [ -d $SRC ] ; then |
|
130 |
pr_info "$SRC USB WiFi driver source code fetched already" |
|
131 |
else |
|
132 |
pr_info "start fetch $SRC USB WiFi drver source code" |
|
133 |
|
|
134 |
if [[ $BSP_URL =~ github.com ]] ; then |
|
135 |
git clone https://github.com/lwfinger/rtw88.git --depth=1 $SRC |
|
136 |
else |
|
137 |
mkdir -p $TARBALL_PATH |
|
138 |
|
|
139 |
# Download source code packet |
|
140 |
if [ ! -s $TARBALL_PATH/$SRC.tar.xz ] ; then |
|
141 |
wget $BSP_URL/imx/bsp/misc/$SRC.tar.xz -P $TARBALL_PATH |
|
142 |
fi |
|
143 |
|
|
144 |
# decompress source code packet |
|
145 |
do_unpack $TARBALL_PATH/$SRC.tar.xz |
|
146 |
fi |
|
147 |
fi |
|
148 |
|
|
149 |
cd $SRC |
|
150 |
|
|
151 |
pr_warn "start update $SRC USB WiFi driver source code" |
|
152 |
|
|
153 |
KER_VER=`echo $BSP_VER|awk -F"-" '{print $2}'` |
|
154 |
|
|
155 |
sed -i "s|^KVER.*|KVER ?= $KER_VER|g" Makefile |
|
156 |
sed -i "s|^KSRC.*|KSRC := ${KER_PATH}|g" Makefile |
|
157 |
sed -i "s|^MODDESTDIR.*|MODDESTDIR := ${DRV_PATH}/lib/modules/${KER_VER}-dirty/extra/|g" Makefile |
|
158 |
sed -i "s|^FIRMWAREDIR.*|FIRMWAREDIR := ${DRV_PATH}/lib/firmware/|g" Makefile |
|
159 |
sed -i '/depmod -a .*/d' Makefile |
|
160 |
|
|
161 |
pr_warn "start build $SRC USB WiFi driver" |
|
162 |
make -j ${JOBS} |
|
163 |
make install |
|
164 |
depmod -a -b ${DRV_PATH}/ ${KER_VER}-dirty |
|
165 |
} |
|
166 |
|
|
167 |
|
|
168 |
function do_build() |
|
169 |
{ |
|
170 |
cd $PRJ_PATH |
|
171 |
|
|
172 |
build_user |
|
173 |
|
|
174 |
build_rtl8723du |
|
175 |
} |
|
176 |
|
|
177 |
function do_clean() |
|
178 |
{ |
|
179 |
cd $PRJ_PATH |
|
180 |
|
|
181 |
rm -rf rtl8188fu rtl8723du tarballs |
|
182 |
|
|
183 |
if [ -d user ] ; then |
|
184 |
cd user |
|
185 |
make clean; |
|
186 |
fi |
|
187 |
|
|
188 |
} |
|
189 |
|
|
190 |
#+-------------------------+ |
|
191 |
#| Shell script body entry | |
|
192 |
#+-------------------------+ |
|
193 |
|
|
194 |
export_env |
|
195 |
|
|
196 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
197 |
pr_warn "start clean drivers" |
|
198 |
do_clean |
|
199 |
exit; |
|
200 |
fi |
|
201 |
|
|
202 |
pr_warn "start build linux driver for ${BOARD}" |
|
203 |
|
|
204 |
do_build |
|
205 |
|