developer | 04049d2 | 2022-02-24 15:22:54 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (C) 2011-2012 OpenWrt.org |
| 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 | |
developer | 79f5210 | 2022-06-13 11:55:15 +0800 | [diff] [blame] | 13 | CI_UBIPART=ubi |
| 14 | |
developer | 04049d2 | 2022-02-24 15:22:54 +0800 | [diff] [blame] | 15 | block_dev_path() { |
| 16 | local dev_path |
| 17 | |
| 18 | case "$1" in |
| 19 | /dev/mmcblk*) |
| 20 | dev_path="$1" |
| 21 | ;; |
| 22 | PARTLABEL=* | PARTUUID=*) |
| 23 | dev_path=$(blkid -t "$1" -o device) |
| 24 | [ -z "${dev_path}" -o $? -ne 0 ] && return 1 |
| 25 | ;; |
| 26 | *) |
| 27 | return 1; |
| 28 | ;; |
| 29 | esac |
| 30 | |
| 31 | echo "${dev_path}" |
| 32 | return 0 |
| 33 | } |
| 34 | |
developer | 79f5210 | 2022-06-13 11:55:15 +0800 | [diff] [blame] | 35 | nand_find_volume() { |
| 36 | local ubidevdir ubivoldir |
| 37 | ubidevdir="/sys/devices/virtual/ubi/$1" |
| 38 | [ ! -d "$ubidevdir" ] && return 1 |
| 39 | for ubivoldir in $ubidevdir/${1}_*; do |
| 40 | [ ! -d "$ubivoldir" ] && continue |
| 41 | if [ "$( cat $ubivoldir/name )" = "$2" ]; then |
| 42 | basename $ubivoldir |
| 43 | ubi_mknod "$ubivoldir" |
| 44 | return 0 |
| 45 | fi |
| 46 | done |
| 47 | } |
| 48 | |
| 49 | nand_find_ubi() { |
| 50 | local ubidevdir ubidev mtdnum |
| 51 | mtdnum="$( find_mtd_index $1 )" |
| 52 | [ ! "$mtdnum" ] && return 1 |
| 53 | for ubidevdir in /sys/devices/virtual/ubi/ubi*; do |
| 54 | [ ! -d "$ubidevdir" ] && continue |
| 55 | cmtdnum="$( cat $ubidevdir/mtd_num )" |
| 56 | [ ! "$mtdnum" ] && continue |
| 57 | if [ "$mtdnum" = "$cmtdnum" ]; then |
| 58 | ubidev=$( basename $ubidevdir ) |
| 59 | ubi_mknod "$ubidevdir" |
| 60 | echo $ubidev |
| 61 | return 0 |
| 62 | fi |
| 63 | done |
| 64 | } |
| 65 | |
developer | 04049d2 | 2022-02-24 15:22:54 +0800 | [diff] [blame] | 66 | board=$(board_name) |
| 67 | |
| 68 | case "$board" in |
| 69 | mediatek,*-emmc-rfb) |
| 70 | env_dev=$(cat /sys/module/boot_param/parameters/env_part 2>/dev/null) |
| 71 | [ -n "$env_dev" ] && env_dev=$(block_dev_path "${env_dev}") |
| 72 | [ -z "$env_dev" ] && env_dev=$(block_dev_path "PARTLABEL=u-boot-env") |
| 73 | [ -n "$env_dev" ] && \ |
| 74 | ubootenv_add_uci_config "$env_dev" "0" "0x80000" |
| 75 | ;; |
developer | 79f5210 | 2022-06-13 11:55:15 +0800 | [diff] [blame] | 76 | |
| 77 | mediatek,*-snand-rfb) |
| 78 | env_dev=$(cat /sys/module/boot_param/parameters/env_part 2>/dev/null) |
| 79 | if [ -n "$env_dev" ]; then |
| 80 | local mtdnum="$( find_mtd_index "$CI_UBIPART" )" |
| 81 | if [ ! "$mtdnum" ]; then |
| 82 | echo "cannot find ubi mtd partition $CI_UBIPART" |
| 83 | return 1 |
| 84 | fi |
| 85 | |
| 86 | local ubidev="$( nand_find_ubi "$CI_UBIPART" )" |
| 87 | if [ ! "$ubidev" ]; then |
| 88 | ubiattach -m "$mtdnum" |
| 89 | sync |
| 90 | ubidev="$( nand_find_ubi "$CI_UBIPART" )" |
| 91 | fi |
| 92 | |
| 93 | local env_ubivol="$( nand_find_volume "${ubidev}" ${env_dev} )" |
| 94 | if [ -n "${env_ubivol}" ]; then |
| 95 | ubootenv_add_uci_config "/dev/$env_ubivol" "0" "0x80000" "0x80000" 1 |
| 96 | fi |
| 97 | fi |
| 98 | ;; |
developer | 04049d2 | 2022-02-24 15:22:54 +0800 | [diff] [blame] | 99 | esac |
| 100 | |
| 101 | config_load ubootenv |
| 102 | config_foreach ubootenv_add_app_config ubootenv |
| 103 | |
| 104 | exit 0 |