PageRenderTime 23ms CodeModel.GetById 40ms RepoModel.GetById 1ms app.codeStats 0ms

/recipes/i2c-tools/omap3-writeprom/writeprom.sh

https://bitbucket.org/lokkju/openpli-oe
Shell | 103 lines | 96 code | 6 blank | 1 comment | 5 complexity | ff8f0c2664bfd4b7eb8c72183658a9f7 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, GPL-3.0, LGPL-2.0, LGPL-2.1, LGPL-3.0
  1. #!/bin/sh
  2. machine_id() { # return the machine ID
  3. awk 'BEGIN { FS=": " } /Hardware/ { gsub(" ", "_", $2); print tolower($2) } ' </proc/cpuinfo
  4. }
  5. if [ $# -ne 4 ] && [ $# -ne 6 ];
  6. then
  7. echo "Usage:"
  8. echo ""
  9. echo "writeprom.sh vendorid deviceid rev fab_rev [envvar envsetting]"
  10. echo
  11. echo " vendorid, deviceid - expansion board device number from http://www.elinux.org/BeagleBoardPinMux#Vendor_and_Device_IDs"
  12. echo
  13. echo " rev - board revision (e.g. 0x00)"
  14. echo " fab_rev - revision marking from pcb (e.g. R2411)"
  15. echo " envvar - optional u-boot env variable name"
  16. echo " (e.g. dvimode)"
  17. echo " envsetting - optional u-boot env variable setting"
  18. echo " (e.g. 1024x768MR-16@60)"
  19. echo
  20. echo "Don't forget to make the EEPROM writeable if it has a writeprotect jumper!"
  21. exit 1
  22. fi
  23. fabrevision=$4
  24. if [ ${#fabrevision} -ge 8 ]; then
  25. echo "Error: fab revision string must less than 8 characters"
  26. exit 1
  27. fi
  28. envvar=$5
  29. if [ ${#envar} -ge 16 ]; then
  30. echo "Error: environment variable name string must less than 16 characters"
  31. exit 1
  32. fi
  33. envsetting=$6
  34. if [ ${#ensetting} -ge 64 ]; then
  35. echo "Error: environment setting string must less than 64 characters"
  36. exit 1
  37. fi
  38. case `machine_id` in
  39. "omap3_beagle_board")
  40. bus=2
  41. device=0x50
  42. ;;
  43. *)
  44. bus=3
  45. device=0x51
  46. ;;
  47. esac
  48. device=0x50
  49. vendorid=$1
  50. if [ ${#vendorid} -ge 6 ]; then
  51. echo "Error: vendorid number must be less than 6 digits"
  52. exit 1
  53. fi
  54. i2cset -y $bus $device 0x00 0x00
  55. i2cset -y $bus $device 0x01 $vendorid
  56. i2cset -y $bus $device 0x02 0x00
  57. i2cset -y $bus $device 0x03 $2
  58. i2cset -y $bus $device 0x04 $3
  59. i2cset -y $bus $device 0x05 00
  60. let i=6
  61. hexdumpargs="'${#fabrevision}/1 \"0x%02x \"'"
  62. command="echo -n \"$fabrevision\" | hexdump -e $hexdumpargs"
  63. hex=$(eval $command)
  64. for character in $hex; do
  65. i2cset -y $bus $device $i $character
  66. let i=$i+1
  67. done
  68. i2cset -y $bus $device $i 0x00
  69. if [ $# -eq 5 ]
  70. then
  71. i2cset -y $bus $device 0x05 0x01
  72. let i=14
  73. hexdumpargs="'${#envvar}/1 \"0x%02x \"'"
  74. command="echo -n \"$envvar\" | hexdump -e $hexdumpargs"
  75. hex=$(eval $command)
  76. for character in $hex; do
  77. i2cset -y $bus $device $i $character
  78. let i=$i+1
  79. done
  80. i2cset -y $bus $device $i 0x00
  81. let i=30
  82. hexdumpargs="'${#envsetting}/1 \"0x%02x \"'"
  83. command="echo -n \"$envsetting\" | hexdump -e $hexdumpargs"
  84. hex=$(eval $command)
  85. for character in $hex; do
  86. i2cset -y $bus $device $i $character
  87. let i=$i+1
  88. done
  89. i2cset -y $bus $device $i 0x00
  90. fi