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

    2.Plx_unload

             Plx_unload是和Plx_load配对使用的工具,用来卸载加载的驱动并删除Plx_laod工具创建的设备文件和设备节点。

            Plx_unload与Plx_load一样,由于涉及到设备文件的创建,删除以及权限的更改,因此必须是root才可以执行。

           下面是具体的代码和分析,同样为了方便直接在源代码上注释了。

        

 
  1. #-----------------------------------------------------------------------------

  2. #

  3. # File : Plx_unload

  4. # Abstract : Unloads a PLX module

  5. #

  6. #-----------------------------------------------------------------------------

  7.  
  8. clear

  9.  
  10. # Remove comment to display script commands as it runs

  11. #set -x

  12.  
  13. # Path to the driver nodes

  14. path=/dev/plx

  15. #驱动设备文件的路径

  16.  
  17. # Verify command-line

  18. if [ "$1" = "" ]; then

  19. plx_error=1

  20. #Plx_unload 9054 d,$1=9054,如果$1为空,则设置错误标志plx_error为1

  21. else

  22. plx_error=1

  23.  
  24. if [ "$1" = "9050" ]; then

  25. plx_error=0

  26. fi

  27.  
  28. if [ "$1" = "9030" ]; then

  29. plx_error=0

  30. fi

  31.  
  32. if [ "$1" = "9080" ]; then

  33. plx_error=0

  34. fi

  35.  
  36. if [ "$1" = "9054" ]; then

  37. plx_error=0

  38. fi

  39.  
  40. if [ "$1" = "9056" ]; then

  41. plx_error=0

  42. fi

  43.  
  44. if [ "$1" = "9656" ]; then

  45. plx_error=0

  46. fi

  47.  
  48. if [ "$1" = "8311" ]; then

  49. plx_error=0

  50. fi

  51.  
  52. if [ "$1" = "6000" ]; then

  53. plx_error=0

  54. fi

  55.  
  56. if [ "$1" = "8000" ]; then

  57. plx_error=0

  58. fi

  59.  
  60. if [ "$1" = "Dma" ]; then

  61. plx_error=0

  62. fi

  63.  
  64. if [ "$1" = "EoPCIe" ]; then

  65. plx_error=0

  66. fi

  67.  
  68. if [ "$1" = "Svc" ]; then

  69. plx_error=0

  70. fi

  71. #检测第一个参数是否是支持的芯片类型,如果是则清零错误标志plx_error

  72. fi

  73.  
  74. if [ "${plx_error}" == "1" ]; then

  75. #检测错误标志是否为1,为了则表示芯片类型为空或者不支持的芯片类型,

  76. #打印出Plx_unload 用法,然后退出

  77. echo

  78. echo "PLX Linux module unload script"

  79. echo

  80. echo " Usage: Plx_unload {PLX_Chip} [DebugOption]"

  81. echo

  82. echo " PLX_Chip = 6000 : PLX 6254/6540/6466 NT-mode PnP driver"

  83. echo " 8000 : PLX 8000 NT-mode PnP driver"

  84. echo " 9050 : PLX 9050/9052 PnP driver"

  85. echo " 9030 : PLX 9030 PnP driver"

  86. echo " 9080 : PLX 9080 PnP driver"

  87. echo " 9054 : PLX 9054 PnP driver"

  88. echo " 9056 : PLX 9056 PnP driver"

  89. echo " 9656 : PLX 9656 PnP driver"

  90. echo " 8311 : PLX 8311 PnP driver"

  91. echo " Dma : PLX 8600 DMA Controller PnP driver"

  92. echo " Svc : PLX PCI/PCIe Service driver"

  93. echo

  94. echo " DebugOption = <none> : Unload Release build of module"

  95. echo " 'd' : Unload Debug build of module"

  96. echo

  97. echo " E.g.: Plx_unload 9054 d - Unload 9054 module debug version"

  98. echo " Plx_unload 8000 - Unload 8000 NT module release version"

  99. echo

  100. exit

  101. fi

  102.  
  103. # PLX Chip to load module for

  104. plx_chip=$1

  105. #存储芯片类型,$1=9054

  106. # Check for debug version

  107. if [ "$2" != "" ]; then

  108. debug=_dbg

  109. #存储第二个参数,定义是否为调试版的驱动,$2=d,不为空则表示为调试版的驱动

  110. fi

  111.  
  112. # Registered name of driver

  113. name=Plx${plx_chip}

  114. #存储驱动设备的名字,plx_chip=9054

  115. # Name of module to unload

  116. module=${name}${debug}.ko

  117. #存储驱动程序的名称,$name=Plx9054,$debug=_dbg

  118.  
  119.  
  120. echo

  121. echo " ****************************************************"

  122. echo " * NOTE: You must be superuser, logged in as root, *"

  123. echo " * or have sufficient rights to remove *"

  124. echo " * modules or this script will not work. *"

  125. echo " ****************************************************"

  126. echo

  127. echo

  128. echo -n "Clear existing device nodes..... "

  129. rm -f $path/${name}*

  130. #删除Plx_load创建的设备文件

  131. echo "Ok (${path}/${name})"

  132.  
  133. # Delete the directory only if empty

  134. if [ -d ${path} ]; then

  135. echo -n "Delete device node path......... "

  136. rmdir --ignore-fail-on-non-empty ${path}

  137. #删除Plx_load创建的设备文件所在的文件夹(文件夹为空)

  138. echo "Ok (${path})"

  139. fi

  140.  
  141. echo -n "Remove module................... "

  142. /sbin/rmmod $module

  143. #调用/sbin目录下的rmmod删除驱动设备,$module=Plx9054_dbg.ko

  144. echo "Ok ($module)"

  145.  
  146. echo

  147. echo Module unload complete.

  148. echo

  149. echo

 

3.builddriver工具

     builddriver在PlxSdk\Linux\Driver目录下,可以方便的检测当前系统是否符合驱动编译的要求,并且根据用户安装PLX_SDK时设置的PLX_SDK_DIR,PLX_CPU_BITS等环境变量设置编译的选项,调用默认的makefile进行编译。

 

 
  1. #-----------------------------------------------------------------------------

  2. #

  3. # File : builddriver

  4. # Abstract : Builds a specific PLX driver

  5. #

  6. #-----------------------------------------------------------------------------

  7.  
  8.  
  9. clear

  10.  
  11. # Remove comment to display script commands as it runs

  12. #set -x

  13.  
  14.  
  15. #=============================================================================

  16. # Modify the "export" statement below to set 'PLX_SDK_DIR' to the location

  17. # of the PLX Linux installation path. Some examples are:

  18. #

  19. # export PLX_SDK_DIR=/usr/src/PlxSdk

  20. # export PLX_SDK_DIR=/home/$USER/PlxSdk

  21. #=============================================================================

  22. if [ "${PLX_SDK_DIR}1" == "1" ]; then

  23. # Add PLX_SDK_DIR environment variable

  24. export PLX_SDK_DIR=/home/$USER/PlxSdk

  25. #检测环境变量PLX_SDK_DIR是否为空,为空则导出为默认的配置,

  26. #安装PLX_SDK的时候必须设置该环境变量,否则极易出错,除非PLX_SDK刚好

  27. #安装在/home/$USER/目录下

  28. echo

  29. echo " Note:"

  30. echo

  31. echo " The required environment variable, PLX_SDK_DIR, is not defined"

  32. echo " in the environment. The default value (\"$PLX_SDK_DIR\")"

  33. echo " will be used instead. Please update your environment to override"

  34. echo " the default, or modify this script accordingly. To set an"

  35. echo " environment variable, use the \"export\" command as follows:"

  36. echo

  37. echo " export PLX_SDK_DIR=<root of PLX Linux installation>"

  38. echo

  39. else

  40. # Make sure that PLX_SDK_DIR is in the environment, not just a shell variable

  41. export PLX_SDK_DIR=${PLX_SDK_DIR}

  42. fi

  43.  
  44.  
  45. #=============================================================================

  46. # The following determines the kernel version (2.4 or 2.6). The environment

  47. # variable KERNEL_VER can be set to override the setting in this macro.

  48. #=============================================================================

  49. if [ "${KERNEL_VER}" == "" ]; then

  50. # Add KERNEL_VER environment variable

  51. export KERNEL_VER=`uname -r | awk -F. "{ print \\$1\".\"\\$2 }"`

  52. #检测KERNEL_VER内核版本环境变量,为空则查找并导出

  53. #uname -r 为查看内核版本的命令

  54. fi

  55.  
  56.  
  57. #=============================================================================

  58. # For kernel 2.4, the driver needs to know whether the distribution is RedHat.

  59. # Usually, the kernel headers automatically do this by including "rhconfig.h",

  60. # which defines RED_HAT_LINUX_KERNEL. This seems to not always work on RH kernels,

  61. # so this script attempts to detect RH and set an environment variable if so.

  62. # The driver makefile will then define RED_HAT_LINUX_KERNEL if needed.

  63. #=============================================================================

  64. if [ "${KERNEL_VER}" == "2.4" ]; then

  65. if [[ -r /etc/redhat-release ]]; then

  66. # Add variable to environment

  67. export PLX_RED_HAT_KERNEL=1

  68. #检测KERNEL_VER是否为2.4版本内核,如果是2.4版本,

  69. #则需要进一步判断是否是RedHat发行版,如果是则添加PLX_RED_HAT_KERNEL

  70. #环境变量

  71. else

  72. # Remove variable from environment

  73. unset PLX_RED_HAT_KERNEL

  74. fi

  75. fi

  76.  
  77.  
  78. #=============================================================================

  79. # The following determines whether a 64-bit kernel is running. The variable

  80. # PLX_CPU_BITS can be set to override the setting.

  81. #=============================================================================

  82. if [ "${PLX_CPU_BITS}" == "" ]; then

  83. # Add PLX_CPU_BITS environment variable (default=32-bit)

  84. #检测PLX_CPU_BITS,如果为空,则设置为32位CPU参数

  85. export PLX_CPU_BITS=32

  86.  
  87. if [ `uname -i` == ia64 ]; then

  88. export PLX_CPU_BITS=64

  89. fi

  90.  
  91. if [ `uname -i` == x86_64 ]; then

  92. export PLX_CPU_BITS=64

  93. fi

  94. #查看系统硬件架构信息,如果是ia64,或者x86_64架构的,则为64位CPU

  95. #设置PLX_CPU_BITS为64位

  96. fi

  97.  
  98. # Store parameters

  99. Param2=$2

  100. Param3=$3

  101. #buildriver 9054 d,$2=d,$3为空

  102. # Check for debug version

  103. if [ "$2" == "d" ]; then

  104. # Add PLX_DEBUG environment variable

  105. #判断第二个参数是否为d,如果是则设置调试开关PLX_DEBUG

  106. export PLX_DEBUG=1

  107. Param2=

  108. else

  109. # Make sure PLX_DEBUG is not in environment

  110. unset PLX_DEBUG

  111. fi

  112.  
  113.  
  114. # Check for clean option

  115. if [ "$2" == "c" ]; then Param2=clean; fi

  116. if [ "$2" == "a" ]; then Param2=cleanall; fi

  117. if [ "$3" == "c" ]; then Param3=clean; fi

  118. if [ "$3" == "a" ]; then Param3=cleanall; fi

  119. #判断第三个参数是否为c,a等清除参数,

  120.  
  121. # Verify command-line

  122. if [ "$1" = "" ]; then

  123. #$1=9054,判断是否为空,如果是则设置错误标志plx_error=1

  124. plx_error=1

  125. else

  126. plx_error=1

  127.  
  128. if [ "$1" = "9050" ]; then

  129. plx_error=0

  130. fi

  131.  
  132. if [ "$1" = "9030" ]; then

  133. plx_error=0

  134. fi

  135.  
  136. if [ "$1" = "9080" ]; then

  137. plx_error=0

  138. fi

  139.  
  140. if [ "$1" = "9054" ]; then

  141. plx_error=0

  142. fi

  143.  
  144. if [ "$1" = "9056" ]; then

  145. plx_error=0

  146. fi

  147.  
  148. if [ "$1" = "9656" ]; then

  149. plx_error=0

  150. fi

  151.  
  152. if [ "$1" = "8311" ]; then

  153. plx_error=0

  154. fi

  155.  
  156. if [ "$1" = "6000" ]; then

  157. plx_error=0

  158. fi

  159.  
  160. if [ "$1" = "8000" ]; then

  161. plx_error=0

  162. fi

  163.  
  164. if [ "$1" = "Dma" ]; then

  165. plx_error=0

  166. fi

  167.  
  168. if [ "$1" = "Svc" ]; then

  169. plx_error=0

  170. fi

  171. #判断第一个参数是否为支持的芯片类型,如果是则清零错误标志,plx_error

  172. fi

  173.  
  174. if [ "${plx_error}" == "1" ]; then

  175. #错误标志plx_error为1,则打印出builddriver用法,然后退出

  176. echo

  177. echo "PLX Linux module build script"

  178. echo "Copyright (c) 2007, PLX Technology, Inc."

  179. echo

  180. echo " Usage: builddriver {PLX_Chip} [DebugOption] [CleanOption]"

  181. echo

  182. echo " PLX_Chip = 6000 : PLX 6254/6540/6466 NT-mode PnP driver"

  183. echo " 8000 : PLX 8000 NT-mode PnP driver"

  184. echo " 9050 : PLX 9050/9052 PnP driver"

  185. echo " 9030 : PLX 9030 PnP driver"

  186. echo " 9080 : PLX 9080 PnP driver"

  187. echo " 9054 : PLX 9054 PnP driver"

  188. echo " 9056 : PLX 9056 PnP driver"

  189. echo " 9656 : PLX 9656 PnP driver"

  190. echo " 8311 : PLX 8311 PnP driver"

  191. echo " Dma : PLX 8000 DMA Controller PnP driver"

  192. echo " Svc : PLX PCI/PCIe Service driver"

  193. echo

  194. echo " DebugOption = <none> : Build Release build of module"

  195. echo " 'd' : Build Debug build of module"

  196. echo

  197. echo " CleanOption = <none> : Build the driver"

  198. echo " 'clean' : Remove intermediate build files"

  199. echo " 'cleanall' : Remove all build files"

  200. echo

  201. echo " E.g.: builddriver 9054 d - Build 9054 module debug version"

  202. echo " builddriver Svc - Build PlxSvc service module release version"

  203. echo " builddriver 8000 clean - Remove intermediate build files of 8000 module"

  204. echo

  205. exit

  206. fi

  207.  
  208.  
  209. # Set PLX Chip type

  210. PlxChip=$1

  211. #设置芯片类型,$1=9054

  212.  
  213. # Build the driver

  214. make PLX_CHIP=$PlxChip $Param2 $Param3 $4 $5 $6 $7

  215. #使用默认的makefile编译选择的驱动,$Param2=d,$Param3以及往后的参数为空

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值