config_load调用:
/etc/init.d目录下的log和led(config_load system)、6delayd、dhcp
/etc/rc.button目录下rfkill(config_load wireless)
/etc/hotplug.d/tty目录下30-3g(config_load network)
/lib/network/config.sh(config_load network)
/lib/network/switch.sh(config_load network)
/lib/wifi目录下rt2860v2.sh(config_load wireless)
/sbin目录下led.sh(config_load system)
/sbin目录下ifup和ifdown(config_load wireless)
/etc/init.d/led除了调用config_load system外还调用config_foreach load_led led(load_led函数在/etc/init.d/led),
load_led函数读写/sys/class/leds目录下文件实现灯闪烁灯操作。
分析:linux\ramips\base-files\etc\uci-defaults\01_leds(或root-ramips\etc\uci-defaults),系统启动时会将wan和wifi指示灯设置到/etc/config/system文件中。
1.config_load函数:/lib/functions.sh中定义
config_load() {
[ -n "$IPKG_INSTROOT" ] && return 0
uci_load "$@"
}
含义:若IPKG_INSTROOT不为空则调用uci_load函数执行。
2.uci_load函数:/lib/config/uci.sh中定义(该函数只能加载符合lua要求的配置文件,如/etc/config目录下的)。
uci_load() {
local PACKAGE="$1"
local DATA
local RET
local VAR
_C=0
if [ -z "$CONFIG_APPEND" ]; then
for VAR in $CONFIG_LIST_STATE; do
export ${NO_EXPORT:+-n} CONFIG_${VAR}=
export ${NO_EXPORT:+-n} CONFIG_${VAR}_LENGTH=
done
export ${NO_EXPORT:+-n} CONFIG_LIST_STATE=
export ${NO_EXPORT:+-n} CONFIG_SECTIONS=
export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=0
export ${NO_EXPORT:+-n} CONFIG_SECTION=
fi
DATA="$(/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${LOAD_STATE:+-P /var/state} -S -n export "$PACKAGE" 2>/dev/null)"
RET="$?"
[ "$RET" != 0 -o -z "$DATA" ] || eval "$DATA"
unset DATA
${CONFIG_SECTION:+config_cb}
return "$RET"
}
3.config_foreach函数:/lib/functions.sh中定义
config_foreach() {
local ___function="$1"
[ "$#" -ge 1 ] && shift
local ___type="$1"
[ "$#" -ge 1 ] && shift
local section cfgtype
[ -z "$CONFIG_SECTIONS" ] && return 0
for section in ${CONFIG_SECTIONS}; do
config_get cfgtype "$section" TYPE
[ -n "$___type" -a "x$cfgtype" != "x$___type" ] && continue
eval "$___function \"\$section\" \"\$@\""
done
}
4.config_get函数:/lib/functions.sh中定义
# config_get []
# config_get
config_get() {
case "$3" in
"") eval echo "\${CONFIG_${1}_${2}:-\${4}}";;
*) eval export ${NO_EXPORT:+-n} -- "${1}=\${CONFIG_${2}_${3}:-\${4}}";;
esac
}
函数解释:用于从配置文件的关键字段中提取变量(如config_get sysfs $1 sysfs,获取某led灯在sysfs中的名称)。
====================================================================================================
target\linux\ramips\base-files\etc\uci-defaults\01_leds (或root-ramips\etc\uci-defaults)
ucidef_set_led_netdev "wifi_led" "wifi" "$1" "ra0"
ucidef_set_led_netdev "wan" "wan" "xx:blue:wan" "eth0"
ucidef_commit_leds
1.ucidef_set_led_netdev函数:定义在/lib/functions/uci-defaults.sh
ucidef_set_led_netdev() {
local cfg="led_$1"
local name=$2
local sysfs=$3
local dev=$4
uci -q get system.$cfg && return 0
uci batch <
set system.$cfg='led'
set system.$cfg.name='$name'
set system.$cfg.sysfs='$sysfs'
set system.$cfg.trigger='netdev'
set system.$cfg.dev='$dev'
set system.$cfg.mode='link tx rx'
EOF
UCIDEF_LEDS_CHANGED=1
}
2.ucidef_commit_leds函数:定义在/lib/functions/uci-defaults.sh
ucidef_commit_leds()
{
[ "$UCIDEF_LEDS_CHANGED" == "1" ] && uci commit system
}
解释:最终使用uci的接口将配置写入系统的/etc/config目录下
==================================================================================================
/etc/init.d目录下done
# set leds to normal state
. /etc/diag.sh
set_state done
--------->set_state函数:定义在/etc/diag.sh中
set_state() {
get_status_led
case "$1" in
preinit)
status_led_blink_preinit
;;
failsafe)
status_led_blink_failsafe
;;
done)
status_led_on
;;
esac
}
--------->status_led_blink_preinit函数:定义在/lib/functions/leds.sh
led_set_attr() {
[ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
}
led_timer() {
led_set_attr $1 "trigger" "timer"
led_set_attr $1 "delay_on" "$2"
led_set_attr $1 "delay_off" "$3"
}
status_led_blink_preinit() {
led_timer $status_led 200 200
}
阅读(3869) | 评论(0) | 转发(0) |