blob: 6102d9b867a278b8aa21e6583bca1d55792a245e [file] [log] [blame]
developer04049d22022-02-24 15:22:54 +08001#!/bin/sh
2#
3# Copyright (C) 2011-2012 OpenWrt.org
4#
5
6[ -e /etc/config/ubootenv ] && exit 0
7
8touch /etc/config/ubootenv
9
10. /lib/uboot-envtools.sh
11. /lib/functions.sh
12
developer79f52102022-06-13 11:55:15 +080013CI_UBIPART=ubi
14
developer04049d22022-02-24 15:22:54 +080015block_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
developer79f52102022-06-13 11:55:15 +080035nand_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
49nand_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
developer04049d22022-02-24 15:22:54 +080066board=$(board_name)
67
68case "$board" in
69mediatek,*-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 ;;
developer79f52102022-06-13 11:55:15 +080076
77mediatek,*-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 ;;
developer04049d22022-02-24 15:22:54 +080099esac
100
101config_load ubootenv
102config_foreach ubootenv_add_app_config ubootenv
103
104exit 0