sunxi.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # defaults
  3. SUNXI_BOARD_NAME="generic sunxi"
  4. SUNXI_BOARD_MODEL="generic sunxi"
  5. SUNXI_ENV_DEV=/dev/mmcblk0
  6. #Helper functions
  7. get_cmdline_opt()
  8. {
  9. cat /proc/cmdline | awk -F$1= '{print $2}' | awk '{print $1}'
  10. }
  11. #Since fw_getenv doesn't work with blockdevs let's make a hack
  12. uboot_getenv()
  13. {
  14. dd if=$SUNXI_ENV_DEV bs=1024 skip=544 count=128 2>dev/null |\strings|grep $1|cut -d"=" -f2
  15. }
  16. #Actual routines go below
  17. sunxi_env_dev()
  18. {
  19. local dev
  20. dev=`get_cmdline_opt root|cut -d"p" -f1`
  21. SUNXI_ENV_DEV=$dev
  22. echo "probing $dev for uboot env data"
  23. }
  24. sunxi_board_detect() {
  25. local board
  26. local model
  27. sunxi_env_dev
  28. [ -e "/tmp/sysinfo/" ] || mkdir -p "/tmp/sysinfo/"
  29. board="`uboot_getenv wrt_board`"
  30. model="`uboot_getenv wrt_model`"
  31. if [ "$board" != "" ]; then
  32. SUNXI_BOARD_NAME="$board"
  33. fi
  34. if [ "$model" != "" ]; then
  35. SUNXI_BOARD_MODEL="$model"
  36. fi
  37. echo "$SUNXI_BOARD_NAME" > /tmp/sysinfo/board_name
  38. echo "$SUNXI_BOARD_MODEL" > /tmp/sysinfo/model
  39. echo "Detected $SUNXI_BOARD_NAME // $SUNXI_BOARD_MODEL"
  40. }