2.Plx_unload
Plx_unload是和Plx_load配对使用的工具,用来卸载加载的驱动并删除Plx_laod工具创建的设备文件和设备节点。
Plx_unload与Plx_load一样,由于涉及到设备文件的创建,删除以及权限的更改,因此必须是root才可以执行。
下面是具体的代码和分析,同样为了方便直接在源代码上注释了。
-
#-----------------------------------------------------------------------------
-
#
-
# File : Plx_unload
-
# Abstract : Unloads a PLX module
-
#
-
#-----------------------------------------------------------------------------
-
clear
-
# Remove comment to display script commands as it runs
-
#set -x
-
# Path to the driver nodes
-
path=/dev/plx
-
#驱动设备文件的路径
-
# Verify command-line
-
if [ "$1" = "" ]; then
-
plx_error=1
-
#Plx_unload 9054 d,$1=9054,如果$1为空,则设置错误标志plx_error为1
-
else
-
plx_error=1
-
if [ "$1" = "9050" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9030" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9080" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9054" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9056" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9656" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "8311" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "6000" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "8000" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "Dma" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "EoPCIe" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "Svc" ]; then
-
plx_error=0
-
fi
-
#检测第一个参数是否是支持的芯片类型,如果是则清零错误标志plx_error
-
fi
-
if [ "${plx_error}" == "1" ]; then
-
#检测错误标志是否为1,为了则表示芯片类型为空或者不支持的芯片类型,
-
#打印出Plx_unload 用法,然后退出
-
echo
-
echo "PLX Linux module unload script"
-
echo
-
echo " Usage: Plx_unload {PLX_Chip} [DebugOption]"
-
echo
-
echo " PLX_Chip = 6000 : PLX 6254/6540/6466 NT-mode PnP driver"
-
echo " 8000 : PLX 8000 NT-mode PnP driver"
-
echo " 9050 : PLX 9050/9052 PnP driver"
-
echo " 9030 : PLX 9030 PnP driver"
-
echo " 9080 : PLX 9080 PnP driver"
-
echo " 9054 : PLX 9054 PnP driver"
-
echo " 9056 : PLX 9056 PnP driver"
-
echo " 9656 : PLX 9656 PnP driver"
-
echo " 8311 : PLX 8311 PnP driver"
-
echo " Dma : PLX 8600 DMA Controller PnP driver"
-
echo " Svc : PLX PCI/PCIe Service driver"
-
echo
-
echo " DebugOption = <none> : Unload Release build of module"
-
echo " 'd' : Unload Debug build of module"
-
echo
-
echo " E.g.: Plx_unload 9054 d - Unload 9054 module debug version"
-
echo " Plx_unload 8000 - Unload 8000 NT module release version"
-
echo
-
exit
-
fi
-
# PLX Chip to load module for
-
plx_chip=$1
-
#存储芯片类型,$1=9054
-
# Check for debug version
-
if [ "$2" != "" ]; then
-
debug=_dbg
-
#存储第二个参数,定义是否为调试版的驱动,$2=d,不为空则表示为调试版的驱动
-
fi
-
# Registered name of driver
-
name=Plx${plx_chip}
-
#存储驱动设备的名字,plx_chip=9054
-
# Name of module to unload
-
module=${name}${debug}.ko
-
#存储驱动程序的名称,$name=Plx9054,$debug=_dbg
-
echo
-
echo " ****************************************************"
-
echo " * NOTE: You must be superuser, logged in as root, *"
-
echo " * or have sufficient rights to remove *"
-
echo " * modules or this script will not work. *"
-
echo " ****************************************************"
-
echo
-
echo
-
echo -n "Clear existing device nodes..... "
-
rm -f $path/${name}*
-
#删除Plx_load创建的设备文件
-
echo "Ok (${path}/${name})"
-
# Delete the directory only if empty
-
if [ -d ${path} ]; then
-
echo -n "Delete device node path......... "
-
rmdir --ignore-fail-on-non-empty ${path}
-
#删除Plx_load创建的设备文件所在的文件夹(文件夹为空)
-
echo "Ok (${path})"
-
fi
-
echo -n "Remove module................... "
-
/sbin/rmmod $module
-
#调用/sbin目录下的rmmod删除驱动设备,$module=Plx9054_dbg.ko
-
echo "Ok ($module)"
-
echo
-
echo Module unload complete.
-
echo
-
echo
3.builddriver工具
builddriver在PlxSdk\Linux\Driver目录下,可以方便的检测当前系统是否符合驱动编译的要求,并且根据用户安装PLX_SDK时设置的PLX_SDK_DIR,PLX_CPU_BITS等环境变量设置编译的选项,调用默认的makefile进行编译。
-
#-----------------------------------------------------------------------------
-
#
-
# File : builddriver
-
# Abstract : Builds a specific PLX driver
-
#
-
#-----------------------------------------------------------------------------
-
clear
-
# Remove comment to display script commands as it runs
-
#set -x
-
#=============================================================================
-
# Modify the "export" statement below to set 'PLX_SDK_DIR' to the location
-
# of the PLX Linux installation path. Some examples are:
-
#
-
# export PLX_SDK_DIR=/usr/src/PlxSdk
-
# export PLX_SDK_DIR=/home/$USER/PlxSdk
-
#=============================================================================
-
if [ "${PLX_SDK_DIR}1" == "1" ]; then
-
# Add PLX_SDK_DIR environment variable
-
export PLX_SDK_DIR=/home/$USER/PlxSdk
-
#检测环境变量PLX_SDK_DIR是否为空,为空则导出为默认的配置,
-
#安装PLX_SDK的时候必须设置该环境变量,否则极易出错,除非PLX_SDK刚好
-
#安装在/home/$USER/目录下
-
echo
-
echo " Note:"
-
echo
-
echo " The required environment variable, PLX_SDK_DIR, is not defined"
-
echo " in the environment. The default value (\"$PLX_SDK_DIR\")"
-
echo " will be used instead. Please update your environment to override"
-
echo " the default, or modify this script accordingly. To set an"
-
echo " environment variable, use the \"export\" command as follows:"
-
echo
-
echo " export PLX_SDK_DIR=<root of PLX Linux installation>"
-
echo
-
else
-
# Make sure that PLX_SDK_DIR is in the environment, not just a shell variable
-
export PLX_SDK_DIR=${PLX_SDK_DIR}
-
fi
-
#=============================================================================
-
# The following determines the kernel version (2.4 or 2.6). The environment
-
# variable KERNEL_VER can be set to override the setting in this macro.
-
#=============================================================================
-
if [ "${KERNEL_VER}" == "" ]; then
-
# Add KERNEL_VER environment variable
-
export KERNEL_VER=`uname -r | awk -F. "{ print \\$1\".\"\\$2 }"`
-
#检测KERNEL_VER内核版本环境变量,为空则查找并导出
-
#uname -r 为查看内核版本的命令
-
fi
-
#=============================================================================
-
# For kernel 2.4, the driver needs to know whether the distribution is RedHat.
-
# Usually, the kernel headers automatically do this by including "rhconfig.h",
-
# which defines RED_HAT_LINUX_KERNEL. This seems to not always work on RH kernels,
-
# so this script attempts to detect RH and set an environment variable if so.
-
# The driver makefile will then define RED_HAT_LINUX_KERNEL if needed.
-
#=============================================================================
-
if [ "${KERNEL_VER}" == "2.4" ]; then
-
if [[ -r /etc/redhat-release ]]; then
-
# Add variable to environment
-
export PLX_RED_HAT_KERNEL=1
-
#检测KERNEL_VER是否为2.4版本内核,如果是2.4版本,
-
#则需要进一步判断是否是RedHat发行版,如果是则添加PLX_RED_HAT_KERNEL
-
#环境变量
-
else
-
# Remove variable from environment
-
unset PLX_RED_HAT_KERNEL
-
fi
-
fi
-
#=============================================================================
-
# The following determines whether a 64-bit kernel is running. The variable
-
# PLX_CPU_BITS can be set to override the setting.
-
#=============================================================================
-
if [ "${PLX_CPU_BITS}" == "" ]; then
-
# Add PLX_CPU_BITS environment variable (default=32-bit)
-
#检测PLX_CPU_BITS,如果为空,则设置为32位CPU参数
-
export PLX_CPU_BITS=32
-
if [ `uname -i` == ia64 ]; then
-
export PLX_CPU_BITS=64
-
fi
-
if [ `uname -i` == x86_64 ]; then
-
export PLX_CPU_BITS=64
-
fi
-
#查看系统硬件架构信息,如果是ia64,或者x86_64架构的,则为64位CPU
-
#设置PLX_CPU_BITS为64位
-
fi
-
# Store parameters
-
Param2=$2
-
Param3=$3
-
#buildriver 9054 d,$2=d,$3为空
-
# Check for debug version
-
if [ "$2" == "d" ]; then
-
# Add PLX_DEBUG environment variable
-
#判断第二个参数是否为d,如果是则设置调试开关PLX_DEBUG
-
export PLX_DEBUG=1
-
Param2=
-
else
-
# Make sure PLX_DEBUG is not in environment
-
unset PLX_DEBUG
-
fi
-
# Check for clean option
-
if [ "$2" == "c" ]; then Param2=clean; fi
-
if [ "$2" == "a" ]; then Param2=cleanall; fi
-
if [ "$3" == "c" ]; then Param3=clean; fi
-
if [ "$3" == "a" ]; then Param3=cleanall; fi
-
#判断第三个参数是否为c,a等清除参数,
-
# Verify command-line
-
if [ "$1" = "" ]; then
-
#$1=9054,判断是否为空,如果是则设置错误标志plx_error=1
-
plx_error=1
-
else
-
plx_error=1
-
if [ "$1" = "9050" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9030" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9080" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9054" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9056" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "9656" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "8311" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "6000" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "8000" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "Dma" ]; then
-
plx_error=0
-
fi
-
if [ "$1" = "Svc" ]; then
-
plx_error=0
-
fi
-
#判断第一个参数是否为支持的芯片类型,如果是则清零错误标志,plx_error
-
fi
-
if [ "${plx_error}" == "1" ]; then
-
#错误标志plx_error为1,则打印出builddriver用法,然后退出
-
echo
-
echo "PLX Linux module build script"
-
echo "Copyright (c) 2007, PLX Technology, Inc."
-
echo
-
echo " Usage: builddriver {PLX_Chip} [DebugOption] [CleanOption]"
-
echo
-
echo " PLX_Chip = 6000 : PLX 6254/6540/6466 NT-mode PnP driver"
-
echo " 8000 : PLX 8000 NT-mode PnP driver"
-
echo " 9050 : PLX 9050/9052 PnP driver"
-
echo " 9030 : PLX 9030 PnP driver"
-
echo " 9080 : PLX 9080 PnP driver"
-
echo " 9054 : PLX 9054 PnP driver"
-
echo " 9056 : PLX 9056 PnP driver"
-
echo " 9656 : PLX 9656 PnP driver"
-
echo " 8311 : PLX 8311 PnP driver"
-
echo " Dma : PLX 8000 DMA Controller PnP driver"
-
echo " Svc : PLX PCI/PCIe Service driver"
-
echo
-
echo " DebugOption = <none> : Build Release build of module"
-
echo " 'd' : Build Debug build of module"
-
echo
-
echo " CleanOption = <none> : Build the driver"
-
echo " 'clean' : Remove intermediate build files"
-
echo " 'cleanall' : Remove all build files"
-
echo
-
echo " E.g.: builddriver 9054 d - Build 9054 module debug version"
-
echo " builddriver Svc - Build PlxSvc service module release version"
-
echo " builddriver 8000 clean - Remove intermediate build files of 8000 module"
-
echo
-
exit
-
fi
-
# Set PLX Chip type
-
PlxChip=$1
-
#设置芯片类型,$1=9054
-
# Build the driver
-
make PLX_CHIP=$PlxChip $Param2 $Param3 $4 $5 $6 $7
-
#使用默认的makefile编译选择的驱动,$Param2=d,$Param3以及往后的参数为空