uboot-envtools: adds r7800 uboot env support
[openwrt/openwrt.git] / package / boot / uboot-envtools / files / ipq806x
1 #!/bin/sh
2 #
3 # Copyright (C) 2016 LEDE
4 #
5
6 [ -e /etc/config/ubootenv ] && exit 0
7
8 touch /etc/config/ubootenv
9
10 . /lib/uboot-envtools.sh
11 . /lib/functions.sh
12
13 board=$(board_name)
14
15 ubootenv_mtdinfo () {
16 UBOOTENV_PART=$(cat /proc/mtd | grep APPSBLENV)
17 mtd_dev=$(echo $UBOOTENV_PART | awk '{print $1}' | sed 's/:$//')
18 mtd_size=$(echo $UBOOTENV_PART | awk '{print "0x"$2}')
19 mtd_erase=$(echo $UBOOTENV_PART | awk '{print "0x"$3}')
20 nor_flash=$(find /sys/bus/spi/devices/*/mtd -name ${mtd_dev})
21
22 if [ -n "$nor_flash" ]; then
23 ubootenv_size=$mtd_size
24 else
25 # size is fixed to 0x40000 in u-boot
26 ubootenv_size=0x40000
27 fi
28
29 sectors=$(( $ubootenv_size / $mtd_erase ))
30 echo /dev/$mtd_dev 0x0 $ubootenv_size $mtd_erase $sectors
31 }
32
33 case "$board" in
34 linksys,ea8500)
35 ubootenv_add_uci_config "/dev/mtd10" "0x0" "0x20000" "0x20000"
36 ;;
37 netgear,r7800)
38 ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x040000" "0x20000"
39 ;;
40 qcom,ipq8064-ap148 |\
41 qcom,ipq8064-db149)
42 ubootenv_add_uci_config $(ubootenv_mtdinfo)
43 ;;
44 zyxel,nbg6817)
45 ubootenv_add_uci_config "/dev/mtdblock9" "0x0" "0x10000" "0x10000"
46 ;;
47 esac
48
49 config_load ubootenv
50 config_foreach ubootenv_add_app_config ubootenv
51
52 exit 0