#!/bin/bash
|
|
# this project absolute path
|
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
|
|
# top project absolute path
|
TOP_PATH=$(realpath $PRJ_PATH/../../)
|
|
# binaries build prefix install path
|
PRFX_PATH=$PRJ_PATH/install
|
|
# binaries finally install path if needed
|
#INST_PATH=/tftp
|
|
# download taballs path
|
TARBALL_PATH=$PRJ_PATH/tarballs
|
|
# config file path
|
CONF_FILE=$TOP_PATH/config.json
|
|
# shell script will exit once get command error
|
set -e
|
|
#+-------------------------+
|
#| Shell script functions |
|
#+-------------------------+
|
|
function pr_error() {
|
echo -e "\033[40;31m $1 \033[0m"
|
}
|
|
function pr_warn() {
|
echo -e "\033[40;33m $1 \033[0m"
|
}
|
|
function pr_info() {
|
echo -e "\033[40;32m $1 \033[0m"
|
}
|
|
# decompress a packet to destination path
|
function do_unpack()
|
{
|
tarball=$1
|
dstpath=`pwd`
|
|
if [[ $# == 2 ]] ; then
|
dstpath=$2
|
fi
|
|
pr_info "decompress $tarball => $dstpath"
|
|
mkdir -p $dstpath
|
case $tarball in
|
*.tar.gz)
|
tar -xzf $tarball -C $dstpath
|
;;
|
|
*.tar.bz2)
|
tar -xjf $tarball -C $dstpath
|
;;
|
|
*.tar.xz)
|
tar -xJf $tarball -C $dstpath
|
;;
|
|
*.tar.zst)
|
tar -I zstd -xf $tarball -C $dstpath
|
;;
|
|
*.tar)
|
tar -xf $tarball -C $dstpath
|
;;
|
|
*.zip)
|
unzip -qo $tarball -d $dstpath
|
;;
|
|
*)
|
pr_error "decompress Unsupport packet: $tarball"
|
return 1;
|
;;
|
esac
|
}
|
|
# parser configure file and export environment variable
|
function export_env()
|
{
|
export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'`
|
export CROSS_COMPILE=`jq -r ".bsp.cortexAtool" $CONF_FILE`
|
export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'`
|
export BSP_URL=`jq -r ".bsp.giturl" $CONF_FILE`
|
|
export KER_SRC=linux-imx
|
export KER_PATH=$TOP_PATH/kernel/linux-imx
|
export DRV_PATH=$TOP_PATH/kernel/install
|
|
export KER_VER=`echo $BSP_VER|awk -F"-" '{print $2}'`
|
export KER_MODPATH=`ls -d $DRV_PATH/lib/modules/${KER_VER}* | head -n 1`
|
export KER_MODNAME=`basename ${KER_MODPATH}`
|
|
export JOBS=`cat /proc/cpuinfo | grep processor | wc -l`
|
|
if [[ $BOARD =~ mx6ull ]] ; then
|
export ARCH=arm
|
else
|
export ARCH=arm64
|
fi
|
}
|
|
function build_user()
|
{
|
SRC=user
|
|
if [ ! -d ${SRC} ] ; then
|
return ;
|
fi
|
|
pr_warn "Build for users driver"
|
cd ${SRC}
|
|
sed -i "s|^CROSS_COMPILE ?=.*|CROSS_COMPILE ?= ${CROSS_COMPILE}|g" Makefile
|
make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} LINUX_SRC=${KER_PATH} DRV_PATH=${DRV_PATH}/
|
|
cd ${PRJ_PATH}
|
}
|
|
function build_rtl8188fu()
|
{
|
SRC=rtl8188fu
|
|
cd $PRJ_PATH
|
|
if [ -d $SRC ] ; then
|
pr_info "$SRC USB WiFi driver source code fetched already"
|
else
|
pr_info "start fetch $SRC USB WiFi drver source code"
|
|
if [[ $BSP_URL =~ github.com ]] ; then
|
git clone https://github.com/kelebek333/rtl8188fu.git --depth=1 $SRC
|
else
|
mkdir -p $TARBALL_PATH
|
|
# Download source code packet
|
if [ ! -s $TARBALL_PATH/$SRC.tar.xz ] ; then
|
wget $BSP_URL/imx/bsp/misc/$SRC.tar.xz -P $TARBALL_PATH
|
fi
|
|
# decompress source code packet
|
do_unpack $TARBALL_PATH/$SRC.tar.xz
|
fi
|
fi
|
|
cd $SRC
|
|
pr_warn "start update $SRC USB WiFi driver source code"
|
|
sed -i "s|^CROSS_COMPILE ?=.*|CROSS_COMPILE ?= ${CROSS_COMPILE}|g" Makefile
|
sed -i "s|^ARCH ?=.*|ARCH ?= arm|g" Makefile
|
sed -i "s|^KVER.*|KVER := $KER_VER|g" Makefile
|
sed -i "s|^KSRC.*|KSRC := ${KER_PATH}|g" Makefile
|
sed -i "s|^MODDESTDIR.*|MODDESTDIR := ${DRV_PATH}|g" Makefile
|
|
sed -i "s|^#define CONFIG_DEBUG|//#define CONFIG_DEBUG|g" include/autoconf.h
|
|
sed -i "/nolinked power/d" core/rtw_pwrctrl.c
|
sed -i "/request firmware/d" hal/rtl8188f/rtl8188f_hal_init.c
|
|
pr_warn "start build $SRC USB WiFi driver"
|
make -j ${JOBS} modules
|
|
cp rtl8188fu.ko ${KER_MODPATH}/extra/
|
depmod -a -b ${DRV_PATH}/ ${KER_MODNAME}
|
|
mkdir -p ${DRV_PATH}/lib/firmware/rtlwifi/
|
cp firmware/rtl8188fufw.bin ${DRV_PATH}/lib/firmware/rtlwifi/
|
}
|
|
|
function build_rtl8723du()
|
{
|
SRC=rtl8723du
|
|
cd $PRJ_PATH
|
|
if [ -d $SRC ] ; then
|
pr_info "$SRC USB WiFi driver source code fetched already"
|
else
|
pr_info "start fetch $SRC USB WiFi drver source code"
|
|
if [[ $BSP_URL =~ github.com ]] ; then
|
git clone https://github.com/lwfinger/rtw88.git --depth=1 $SRC
|
else
|
mkdir -p $TARBALL_PATH
|
|
# Download source code packet
|
if [ ! -s $TARBALL_PATH/$SRC.tar.xz ] ; then
|
wget $BSP_URL/imx/bsp/misc/$SRC.tar.xz -P $TARBALL_PATH
|
fi
|
|
# decompress source code packet
|
do_unpack $TARBALL_PATH/$SRC.tar.xz
|
fi
|
fi
|
|
cd $SRC
|
|
pr_warn "start update $SRC USB WiFi driver source code"
|
|
sed -i "s|^KVER.*|KVER ?= $KER_VER|g" Makefile
|
sed -i "s|^KSRC.*|KSRC := ${KER_PATH}|g" Makefile
|
sed -i "s|^MODDESTDIR.*|MODDESTDIR := ${KER_MODPATH}/extra/|g" Makefile
|
sed -i "s|^FIRMWAREDIR.*|FIRMWAREDIR := ${DRV_PATH}/lib/firmware/|g" Makefile
|
sed -i '/depmod -a .*/d' Makefile
|
|
pr_warn "start build $SRC USB WiFi driver"
|
make -j ${JOBS}
|
make install
|
depmod -a -b ${DRV_PATH}/ ${KER_MODNAME}
|
}
|
|
|
function do_build()
|
{
|
cd $PRJ_PATH
|
|
build_user
|
|
build_rtl8188fu
|
|
build_rtl8723du
|
}
|
|
function do_clean()
|
{
|
cd $PRJ_PATH
|
|
rm -rf rtl8188fu rtl8723du tarballs
|
|
if [ -d user ] ; then
|
cd user
|
make clean;
|
fi
|
|
}
|
|
#+-------------------------+
|
#| Shell script body entry |
|
#+-------------------------+
|
|
export_env
|
|
if [[ $# == 1 && $1 == -c ]] ;then
|
pr_warn "start clean drivers"
|
do_clean
|
exit;
|
fi
|
|
pr_warn "start build linux driver for ${BOARD}"
|
|
do_build
|