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