PLX_SDK中的一些工具的介绍和分析-----1

          前面介绍了如何安装PLX_SDK,以及编译API函数库和9054驱动的具体方法和步骤。可以注意到上次我们编译9054驱动的时候使用到了一个builddriver工具进行编译的。

         类似的,PLX_SDK提供了一些已经测试完善的工具用来编译,调试驱动,用户程序。下面就简要的介绍下。

        打开 PlxSdk\Bin,可以分析有如下几个工具:

       1:Plx_load 

               Plx_load是一个自动化加载驱动的工具,Linux下我们是通过insmod命令来挂载驱动的,而insmod只是简单的挂载驱动,并不判断驱动是否匹配当前系统的设置。

                使用写字板打开发现Plx_load其实是一个shell脚本,先分析如下,为了方便,就直接在源代码上注释了。

#---------------------------------------------------------------------------
#
#      File         :  Plx_load
#      Abstract     :  Loads a PLX module
#
#-----------------------------------------------------------------------------


clear
#清屏,by hero
# Remove comment to display script commands as it runs
#set -x
#开启shell调试,会详细的显示每个命令的执行步骤
#=============================================================================
# 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/PlxSdk
#=============================================================================
if [ "${PLX_SDK_DIR}1" == "1" ]; then
    # Add PLX_SDK_DIR to environment variables
    export PLX_SDK_DIR=/usr/src/PlxSdk
#检测PLX_SDK_DIR环境变量是否存在,如果不存在,则导出为默认的配置/usr/src/PlxSdk。
#PLX_SDK_DIR为安装PLX_SDK的时候就必须设置的环境变量,必须设置,否则默认的配置会出错,除非PLX_SDK恰好安装在/usr/src目录下。
    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 \"declare\" 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


# Path to the driver nodes
path=/dev/plx

# Default to non-service driver
bServiceDriver=0


# Verify command-line
if [ "$1" = "" ]; then
    plx_error=1
#判断用户键入的第一个参数,#./builddriver 9054 d,$1=9054,$2=d
#如果为空,则设置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
        bServiceDriver=1
#检测第一个参数是否是支持的芯片类型号,如果是则清空plx_error, 
   fi
fi

if [ "${plx_error}" == "1" ]; then
#判断plx_error是否为1,如果是则打印出builddriver的用法,然后退出
    echo
    echo "PLX Linux module load script"
    echo
    echo "  Usage: Plx_load {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>     : Load Release build of module"
    echo "                   'd'        : Load Debug build of module"
    echo
    echo "  E.g.: Plx_load 9054 d   - Load 9054 module debug version"
    echo "        Plx_load 8000     - Load 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,表示加载的驱动为调试版的驱动
   debug=_dbg
fi

# Registered name of driver
name=Plx${plx_chip}

# Name of module to load
module=${name}${debug}.ko
#$name=Plx\9054,$debug=_dbg,module=Plx\9054_dbg.ko
# Install the module
echo
echo "   *****************************************************************"
echo "   * NOTES:                                                        *"
echo "   *                                                               *"
echo "   *  You must be superuser, logged in as root, or have sufficient *"
echo "   *  rights to install modules or this script will not work.      *"
echo "   *                                                               *"
echo "   *  A warning regarding 'kernel tainting' is normal.  This is    *"
echo "   *  because the PLX driver is marked with a 'Proprietary'        *"
echo "   *  license tag, not GPL.  For more information, please refer    *"
echo "   *  to:                                                          *"
echo "   *        http://www.tux.org/lkml/#export-tainted                *"
echo "   *****************************************************************"
echo

echo "Installing module ($module)...."
/sbin/insmod $PLX_SDK_DIR/Linux/Driver/${name}/${module}
echo
#调用/sbin/下的insmod命令加载驱动
# Get the major number
echo -n "Getting Module major number..... "
major=`cat /proc/devices | awk "\\$2==\"$name\" {print \\$1}"`

#获取主设备号
# Check if valid
if [ "$major" = "" ]; then
#检测major是否为空,如果为空,则表示没获取成功,退出
    echo "ERROR: Module not loaded or no device found"
    echo
    exit
fi

# Display Major ID
echo "Ok (MajorID = $major)"

# Create the device node path
echo -n "Creating device node path....... "
if [ -d ${path} ]; then
    echo "$path already exists"
else
    mkdir $path
    chmod 0777 $path
    echo "Ok ($path)"
fi

# Create the device nodes (up to 10 by default)
echo -n "Creating device nodes........... "
rm -f ${path}/${name}*
mknod ${path}/${name} c $major 255
#$path=/dev/plx,$name=Plx/9054,删除原有的设备文件,设备节点
# Create additional nodes for non-service driver
if [ "${bServiceDriver}" == "0" ]; then
    mknod ${path}/${name}-0  c $major 0
    mknod ${path}/${name}-1  c $major 1
    mknod ${path}/${name}-2  c $major 2
    mknod ${path}/${name}-3  c $major 3
    mknod ${path}/${name}-4  c $major 4
    mknod ${path}/${name}-5  c $major 5
    mknod ${path}/${name}-6  c $major 6
    mknod ${path}/${name}-7  c $major 7
    mknod ${path}/${name}-8  c $major 8
    mknod ${path}/${name}-9  c $major 9
    mknod ${path}/${name}-10 c $major 10
    mknod ${path}/${name}-11 c $major 11
    mknod ${path}/${name}-12 c $major 12
    mknod ${path}/${name}-13 c $major 13
    mknod ${path}/${name}-14 c $major 14
    mknod ${path}/${name}-15 c $major 15
    mknod ${path}/${name}-16 c $major 16
#创建新的设备节点,自动创建十六个
fi

chmod 777 $path/*
#更改创建的设备节点的读写权限,修改为777
echo "Ok ($path/$name)"

echo
echo Module load complete.
echo
echo


 

    今天时间有限,就先写这么多了哈,后面的有时间继续写吧。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值