版权声明:本文为博主原创文章,未经博主同意不得转载。 https://blog.csdn.net/qianguozheng/article/details/27237175

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 }

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

最新文章

  1. 快速查找和你聊天人的IP和具体的物理所在地址
  2. UVA 10252
  3. PHP远程下载图片损坏问题
  4. pch和info.plist初探
  5. apache 访问权限基本设置
  6. sql server中NULL导入decimal字段时报错
  7. Redis源码研究--字典
  8. 局域网内sqldeveloper客户端连接oracle服务器
  9. Python之美[从菜鸟到高手]--Python垃圾回收机制及gc模块详解
  10. 被windows“折磨”了一个礼拜
  11. 排序算法简介及其C实现
  12. 【python】函数返回值
  13. 《JavaScript高级程序设计》笔记:DOM(十)
  14. 【C#】时间类型修改
  15. dubbo自定义异常传递信息丢失问题解决
  16. CMake,win10,64位,简单配置测试
  17. Linux系列教程(五)——Linux常用命令之链接命令和权限管理命令
  18. C++17尝鲜:类模板中的模板参数自动推导
  19. (博弈)Simple Game --codeforces--570B
  20. 工作流JBPM_day01:7-使用流程变量

热门文章

  1. C++中 int main(int argc, char **argv) 命令行传递参数
  2. bzoj 1623: [Usaco2008 Open]Cow Cars 奶牛飞车
  3. Spring_Bean 之间的关系
  4. JAVA文件下载,页面显示另存为效果
  5. Go语言 进程、线程、轻量级进程、协程和go中的Goroutine 那些事儿
  6. unity 使用MVC模式
  7. base64编码的 文件 图片
  8. APP耗电量专项测试整理
  9. 十二 web爬虫讲解2—Scrapy框架爬虫—Scrapy模拟浏览器登录—获取Scrapy框架Cookies
  10. 教你10步闯进google play排行榜前列