xpp_debug 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #! /bin/sh
  2. #
  3. # xpp_debug: Turn on/off debugging flags via /sys/module/*/parameters/debug
  4. #
  5. modules="xpp xpp_usb xpd_fxs xpd_fxo xpd_bri xpd_pri"
  6. dbg_names="DEFAULT PCM LEDS SYNC SIGNAL PROC REGS DEVICES COMMANDS"
  7. usage() {
  8. echo 1>&2 "Usage: $0 [module_name] [[-]flags...]"
  9. echo 1>&2 " module_name => $modules"
  10. echo 1>&2 " flags => NONE $dbg_names ANY"
  11. echo 1>&2 ""
  12. echo 1>&2 " Example: $0 xpp ANY -PCM -LEDS"
  13. echo 1>&2 ""
  14. }
  15. sysfs_name() {
  16. f=''
  17. if [ -f "/sys/module/$1/parameters/debug" ]; then
  18. f="/sys/module/$1/parameters/debug"
  19. elif [ -f "/sys/module/$1/debug" ]; then
  20. f="/sys/module/$1/debug"
  21. fi
  22. echo "$f"
  23. }
  24. sysfs_value() {
  25. f=`sysfs_name "$1"`
  26. if [ "$f" != "" ]; then
  27. cat "$f"
  28. fi
  29. }
  30. show_debug() {
  31. usage
  32. for i in $modules
  33. do
  34. f=`sysfs_name "$i"`
  35. if [ -f "$f" ]; then
  36. val=`cat $f`
  37. j=0
  38. list=''
  39. for n in $dbg_names
  40. do
  41. if (( val & (1 << j) ))
  42. then
  43. list="$list $n"
  44. fi
  45. let j++
  46. done
  47. if [ "$list" = "" ]; then
  48. list=' NONE'
  49. fi
  50. echo "$i $list"
  51. fi
  52. done
  53. }
  54. calc_debug() {
  55. val="$1"
  56. shift
  57. for wanted in $*
  58. do
  59. j=0
  60. found=0
  61. for n in $dbg_names
  62. do
  63. if [ "$wanted" = "$n" ]; then
  64. (( val |= (1 << j) ))
  65. found=1
  66. elif [ "$wanted" = -"$n" ]; then
  67. (( val &= ~(1 << j) ))
  68. found=1
  69. elif [ "$wanted" = "ANY" ]; then
  70. (( val = ~0 ))
  71. found=1
  72. elif [ "$wanted" = -"ANY" -o "$wanted" = "NONE" ]; then
  73. (( val = 0 ))
  74. found=1
  75. fi
  76. let j++
  77. done
  78. if [ "$found" -eq 0 ]; then
  79. echo >&2 "$0: Unknown debug flag '$wanted'"
  80. exit 1
  81. fi
  82. done
  83. echo $val
  84. }
  85. if [ "$#" = 0 ]; then
  86. show_debug
  87. exit 0
  88. fi
  89. module="$1"
  90. shift
  91. if ! echo "$modules" | grep -w "$module" > /dev/null; then
  92. echo >&2 "$0: Unknown module $module"
  93. exit 1
  94. fi
  95. oldval=`sysfs_value "$module"`
  96. val=`calc_debug "$oldval" $*`
  97. file=`sysfs_name $module`
  98. echo "$val" > "$file"
  99. show_debug