uboot-envtools.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2011-2012 OpenWrt.org
  4. #
  5. _ubootenv_add_uci_config() {
  6. local cfgtype=$1
  7. local dev=$2
  8. local offset=$3
  9. local envsize=$4
  10. local secsize=$5
  11. local numsec=$6
  12. uci batch <<EOF
  13. add ubootenv $cfgtype
  14. set ubootenv.@$cfgtype[-1].dev='$dev'
  15. set ubootenv.@$cfgtype[-1].offset='$offset'
  16. set ubootenv.@$cfgtype[-1].envsize='$envsize'
  17. set ubootenv.@$cfgtype[-1].secsize='$secsize'
  18. set ubootenv.@$cfgtype[-1].numsec='$numsec'
  19. EOF
  20. uci commit ubootenv
  21. }
  22. ubootenv_add_uci_config() {
  23. _ubootenv_add_uci_config "ubootenv" "$@"
  24. }
  25. ubootenv_add_uci_sys_config() {
  26. _ubootenv_add_uci_config "ubootsys" "$@"
  27. }
  28. ubootenv_add_app_config() {
  29. local cfgtype
  30. local dev
  31. local offset
  32. local envsize
  33. local secsize
  34. local numsec
  35. config_get cfgtype "$1" TYPE
  36. config_get dev "$1" dev
  37. config_get offset "$1" offset
  38. config_get envsize "$1" envsize
  39. config_get secsize "$1" secsize
  40. config_get numsec "$1" numsec
  41. grep -q "^[[:space:]]*${dev}[[:space:]]*${offset}" "/etc/fw_${cfgtype#uboot}.config" || echo "$dev $offset $envsize $secsize $numsec" >>"/etc/fw_${cfgtype#uboot}.config"
  42. }
  43. ubootenv_add_mtd() {
  44. local idx="$(find_mtd_index "${1}")"
  45. [ -n "$idx" ] && \
  46. ubootenv_add_uci_config "/dev/mtd$idx" "${2}" "${3}" "${4}" "${5}"
  47. }
  48. ubootenv_add_sys_mtd() {
  49. local idx="$(find_mtd_index "${1}")"
  50. [ -n "$idx" ] && \
  51. ubootenv_add_uci_sys_config "/dev/mtd$idx" "${2}" "${3}" "${4}" "${5}"
  52. }
  53. ubootenv_add_mmc() {
  54. local mmcpart="$(find_mmc_part "${1}" "${2}")"
  55. [ -n "$mmcpart" ] && \
  56. ubootenv_add_uci_config "$mmcpart" "${3}" "${4}" "${5}" "${6}"
  57. }
  58. ubootenv_add_ubi_default() {
  59. . /lib/upgrade/nand.sh
  60. local envubi=$(nand_find_ubi ubi)
  61. local envdev=/dev/$(nand_find_volume $envubi ubootenv)
  62. local envdev2=/dev/$(nand_find_volume $envubi ubootenv2)
  63. ubootenv_add_uci_config "$envdev" "0x0" "0x1f000" "0x1f000" "1"
  64. ubootenv_add_uci_config "$envdev2" "0x0" "0x1f000" "0x1f000" "1"
  65. }