现在的位置: 首页 > 综合 > 正文

OpenWRT mt7620n 系统升级引起的问题

2014年09月05日 ⁄ 综合 ⁄ 共 5849字 ⁄ 字号 评论关闭

OpenWRT系统升级采用 sysupgrade 这个脚本存放在/sbin/sysupgrade.

#!/bin/sh
. /lib/functions.sh

# initialize defaults
RAMFS_COPY_BIN=""	# extra programs for temporary ramfs root
RAMFS_COPY_DATA=""	# extra data files
export MTD_CONFIG_ARGS=""
export INTERACTIVE=0
export VERBOSE=1
export SAVE_CONFIG=1
export SAVE_OVERLAY=0
export DELAY=
export CONF_IMAGE=
export CONF_BACKUP_LIST=0
export CONF_BACKUP=
export CONF_RESTORE=
export NEED_IMAGE=
export HELP=0
export FORCE=0
export TEST=0

# parse options
while [ -n "$1" ]; do
	case "$1" in
		-i) export INTERACTIVE=1;;
		-d) export DELAY="$2"; shift;;
		-v) export VERBOSE="$(($VERBOSE + 1))";;
		-q) export VERBOSE="$(($VERBOSE - 1))";;
		-n) export SAVE_CONFIG=0;;
		-c) export SAVE_OVERLAY=1;;
		-b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
		-r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
		-l|--list-backup) export CONF_BACKUP_LIST=1; break;;
		-f) export CONF_IMAGE="$2"; shift;;
		-F|--force) export FORCE=1;;
		-T|--test) export TEST=1;;
		-h|--help) export HELP=1; break;;
		-*)
			echo "Invalid option: $1"
			exit 1
		;;
		*) break;;
	esac
	shift;
done

export CONFFILES=/tmp/sysupgrade.conffiles
export CONF_TAR=/tmp/sysupgrade.tgz

export ARGV="$*"
export ARGC="$#"

[ -z "$ARGV" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
	cat <<EOF
Usage: $0 [<upgrade-option>...] <image file or URL>
       $0 [-q] [-i] <backup-command> <file>

upgrade-option:
	-d <delay>   add a delay before rebooting
	-f <config>  restore configuration from .tar.gz (file or url)
	-i           interactive mode
	-c           attempt to preserve all changed files in /etc/
	-n           do not save configuration over reflash
	-T | --test
	             Verify image and config .tar.gz but do not actually flash.
	-F | --force
	             Flash image even if image checks fail, this is dangerous!
	-q           less verbose
	-v           more verbose
	-h | --help  display this help

backup-command:
	-b | --create-backup <file>
	             create .tar.gz of files specified in sysupgrade.conf
	             then exit. Does not flash an image. If file is '-',
	             i.e. stdout, verbosity is set to 0 (i.e. quiet).
	-r | --restore-backup <file>
	             restore a .tar.gz created with sysupgrade -b
	             then exit. Does not flash an image. If file is '-',
	             the archive is read from stdin.
	-l | --list-backup
	             list the files that would be backed up when calling
	             sysupgrade -b. Does not create a backup file.

EOF
	exit 1
}

[ -n "$ARGV" -a -n "$NEED_IMAGE" ] && {
	cat <<-EOF
		-b|--create-backup and -r|--restore-backup do not perform a firmware upgrade.
		Do not specify both -b|-r and a firmware image.
	EOF
	exit 1
}

# prevent messages from clobbering the tarball when using stdout
[ "$CONF_BACKUP" = "-" ] && export VERBOSE=0

add_uci_conffiles() {
	local file="$1"
	( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
		/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
		-type f 2>/dev/null;
	  opkg list-changed-conffiles ) | sort -u > "$file"
	return 0
}

add_overlayfiles() {
	local file="$1"
	find /overlay/etc/ -type f | sed \
		-e 's,^/overlay/,/,' \
		-e '\,/META_[a-zA-Z0-9]*$,d' \
		-e '\,/functions.sh$,d' \
		-e '\,/[^/]*-opkg$,d' \
	> "$file"
	return 0
}

# hooks
sysupgrade_image_check="platform_check_image"
[ $SAVE_OVERLAY = 0 -o ! -d /overlay/etc ] && \
	sysupgrade_init_conffiles="add_uci_conffiles" || \
	sysupgrade_init_conffiles="add_overlayfiles"

include /lib/upgrade

do_save_conffiles() {
	local conf_tar="${1:-$CONF_TAR}"

	[ -z "$(rootfs_type)" ] && {
		echo "Cannot save config while running from ramdisk."
		ask_bool 0 "Abort" && exit
		return 0
	}
	run_hooks "$CONFFILES" $sysupgrade_init_conffiles
	ask_bool 0 "Edit config file list" && vi "$CONFFILES"

	v "Saving config files..."
	[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
	tar c${TAR_V}zf "$conf_tar" -T "$CONFFILES" 2>/dev/null

	rm -f "$CONFFILES"
}

if [ $CONF_BACKUP_LIST -eq 1 ]; then
	add_uci_conffiles "$CONFFILES"
	cat "$CONFFILES"
	rm -f "$CONFFILES"
	exit 0
fi

if [ -n "$CONF_BACKUP" ]; then
	do_save_conffiles "$CONF_BACKUP"
	exit $?
fi

if [ -n "$CONF_RESTORE" ]; then
	if [ "$CONF_RESTORE" != "-" ] && [ ! -f "$CONF_RESTORE" ]; then
		echo "Backup archive '$CONF_RESTORE' not found."
		exit 1
	fi

	[ "$VERBOSE" -gt 1 ] && TAR_V="v" || TAR_V=""
	tar -C / -x${TAR_V}zf "$CONF_RESTORE"
	exit $?
fi

type platform_check_image >/dev/null 2>/dev/null || {
	echo "Firmware upgrade is not implemented for this platform."
	exit 1
}

for check in $sysupgrade_image_check; do
	( eval "$check \"\$ARGV\"" ) || {
		if [ $FORCE -eq 1 ]; then
			echo "Image check '$check' failed but --force given - will update anyway!"
			break
		else
			echo "Image check '$check' failed."
			exit 1
		fi
	}
done

if [ -n "$CONF_IMAGE" ]; then
	case "$(get_magic_word $CONF_IMAGE cat)" in
		# .gz files
		1f8b) ;;
		*)
			echo "Invalid config file. Please use only .tar.gz files"
			exit 1
		;;
	esac
	get_image "$CONF_IMAGE" "cat" > "$CONF_TAR"
	export SAVE_CONFIG=1
elif ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
	[ $TEST -eq 1 ] || do_save_conffiles
	export SAVE_CONFIG=1
else
	export SAVE_CONFIG=0
fi

if [ $TEST -eq 1 ]; then
	exit 0
fi

run_hooks "" $sysupgrade_pre_upgrade

ubus call system upgrade
touch /tmp/sysupgrade

if [ ! -f /tmp/failsafe ] ; then
	kill_remaining TERM
	sleep 3
	kill_remaining KILL
fi

if [ -n "$(rootfs_type)" ]; then
	v "Switching to ramdisk..."
	run_ramfs '. /lib/functions.sh; include /lib/upgrade; do_upgrade'
else
	do_upgrade
fi

源码自己看吧,shell写的东西,我现在也是一知半解,但是不妨碍我解决问题,参照某某某的固件,

在rc.local里面添加了

ifup -a

仿照添加后,不起作用。

研习正常固件跑起来的wifi,一般是,

/tmp/RT2860.dat文件存在

/etc/Wireless/RT2860/RT2860.dat 为/tmp/RT2860.dat的软链接

rt2860ap_v2.ko存在

ifconfig 发下ra0也不存在

lsmod查看,ko被引用次数为0.也就是说没有用,重启系统也不起作用。恢复出厂设置就OK了。甚是费解!

初步断定: ra0没有起来,软连接不存在。可能是wireless启动不成功的原因,至于问题究竟出在哪里,我目前还是没有解决。

但是我找到了解决方案,当然这只是临时的,为什么升级后这些数据不在了,需要进一步研究。

对比无线起不来的情况,发现/etc/Wireless/RT2860/RT2860.dat
不存在。就是说软连接可能是在升级过程中转移到另一个临时文件夹,而在系统重启的时候并未建立此文件,因为系统的默认配置/etc/config/wiereless文件已经存在。

这也许就是root cause,还需验证,我的解决方案是,在rc.local下判断软连接是否存在,不存在则建立此软连接,然后ifup -a

#detect_rt2860v2函数用于检测是否存在驱动
detect_rt2860v2() {
local i=-1
#判断系统是否存在rt2860v2_ap,不存在则退出
cd /sys/module/
[ -d rt2860v2_ap ] || return
<span style="color:#FF0000;">#检测系统存在多少个wifi接口,                                      
while grep -qs "^ *ra$((++i)):" /proc/net/dev; do
config_get type ra${i} type
[ "$type" = rt2860v2 ] && continue
</span>
<span style="color:#006600;">#检查并创建WiFi驱动配置链接
[ -f /etc/Wireless/RT2860/RT2860.dat ] || {
mkdir -p /etc/Wireless/RT2860/
ln -s /tmp/RT2860.dat /etc/Wireless/RT2860/RT2860.dat
}
</span>
first_enable

cat <<EOF
config wifi-device ra${i}
option type rt2860v2
option mode 9
option channel auto
option txpower 100
option ht 20+40
option country US
# REMOVE THIS LINE TO ENABLE WIFI:
option disabled 0
config wifi-iface
option device ra${i}
option network lan
option mode ap
option ssid PandoraBox${i#0}_$(cat /sys/class/net/ra${i}/address|awk -F ":" '{print $4""$5""$6 }'| tr a-z A-Z)
option encryption none
EOF

ifconfig ra0 down
done

}

还需继续研究下启动过程,不然这个问题还是不能真像大白,虽然以上分析其实已经给出了答案。

抱歉!评论已关闭.