mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
fix some target VLAN switch untagged settings
This commit is contained in:
parent
6f413dab28
commit
b1266c659b
@ -9,9 +9,10 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
include $(INCLUDE_DIR)/version.mk
|
||||
include $(INCLUDE_DIR)/feeds.mk
|
||||
|
||||
PKG_NAME:=base-files
|
||||
PKG_RELEASE:=173.3
|
||||
PKG_RELEASE:=181
|
||||
PKG_FLAGS:=nonshared
|
||||
|
||||
PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
|
||||
@ -19,7 +20,14 @@ PKG_BUILD_DEPENDS:=usign/host
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
|
||||
# Extend depends from version.mk
|
||||
PKG_CONFIG_DEPENDS += CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE
|
||||
PKG_CONFIG_DEPENDS += \
|
||||
CONFIG_SIGNED_PACKAGES CONFIG_TARGET_INIT_PATH CONFIG_TARGET_PREINIT_DISABLE_FAILSAFE \
|
||||
CONFIG_NAND_SUPPORT \
|
||||
CONFIG_CLEAN_IPKG \
|
||||
CONFIG_PER_FEED_REPO \
|
||||
CONFIG_PER_FEED_REPO_ADD_DISABLED \
|
||||
CONFIG_PER_FEED_REPO_ADD_COMMENTED \
|
||||
$(foreach feed,$(FEEDS_INSTALLED),CONFIG_FEED_$(feed))
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
@ -31,8 +39,8 @@ endif
|
||||
define Package/base-files
|
||||
SECTION:=base
|
||||
CATEGORY:=Base system
|
||||
DEPENDS:=+netifd +libc +procd +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:lede-keyring +fstools +fwtool
|
||||
TITLE:=Base filesystem for Lede
|
||||
DEPENDS:=+netifd +libc +procd +jsonfilter +SIGNED_PACKAGES:usign +SIGNED_PACKAGES:lede-keyring +NAND_SUPPORT:ubi-utils +fstools +fwtool
|
||||
TITLE:=Base filesystem for OpenWrt
|
||||
URL:=http://openwrt.org/
|
||||
VERSION:=$(PKG_RELEASE)-$(REVISION)
|
||||
endef
|
||||
@ -107,9 +115,16 @@ ifdef CONFIG_SIGNED_PACKAGES
|
||||
endef
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NAND_SUPPORT),)
|
||||
define Package/base-files/nand-support
|
||||
rm -f $(1)/lib/upgrade/nand.sh
|
||||
endef
|
||||
endif
|
||||
|
||||
define Package/base-files/install
|
||||
$(CP) ./files/* $(1)/
|
||||
$(Package/base-files/install-key)
|
||||
$(Package/base-files/nand-support)
|
||||
if [ -d $(GENERIC_PLATFORM_DIR)/base-files/. ]; then \
|
||||
$(CP) $(GENERIC_PLATFORM_DIR)/base-files/* $(1)/; \
|
||||
fi
|
||||
@ -171,6 +186,15 @@ define Package/base-files/install
|
||||
echo "$$$${conffile##$(1)}" >> $(1)/CONTROL/conffiles; \
|
||||
fi \
|
||||
done
|
||||
|
||||
$(if $(CONFIG_INCLUDE_CONFIG), \
|
||||
echo -e "# Build configuration for board $(BOARD)/$(SUBTARGET)/$(PROFILE)\n" >$(1)/etc/build.config; \
|
||||
cat $(BIN_DIR)/config.seed >>$(1)/etc/build.config)
|
||||
|
||||
$(if $(CONFIG_CLEAN_IPKG),, \
|
||||
mkdir -p $(1)/etc/opkg; \
|
||||
$(call FeedSourcesAppend,$(1)/etc/opkg/distfeeds.conf); \
|
||||
$(VERSION_SED) $(1)/etc/opkg/distfeeds.conf)
|
||||
endef
|
||||
|
||||
ifneq ($(DUMP),1)
|
||||
|
@ -223,7 +223,7 @@ generate_static_system() {
|
||||
uci -q batch <<-EOF
|
||||
delete system.@system[0]
|
||||
add system system
|
||||
set system.@system[-1].hostname='LEDE'
|
||||
set system.@system[-1].hostname='OpenWrt'
|
||||
set system.@system[-1].timezone='UTC'
|
||||
set system.@system[-1].ttylogin='0'
|
||||
set system.@system[-1].log_size='64'
|
||||
@ -233,10 +233,10 @@ generate_static_system() {
|
||||
set system.ntp='timeserver'
|
||||
set system.ntp.enabled='1'
|
||||
set system.ntp.enable_server='0'
|
||||
add_list system.ntp.server='0.lede.pool.ntp.org'
|
||||
add_list system.ntp.server='1.lede.pool.ntp.org'
|
||||
add_list system.ntp.server='2.lede.pool.ntp.org'
|
||||
add_list system.ntp.server='3.lede.pool.ntp.org'
|
||||
add_list system.ntp.server='0.openwrt.pool.ntp.org'
|
||||
add_list system.ntp.server='1.openwrt.pool.ntp.org'
|
||||
add_list system.ntp.server='2.openwrt.pool.ntp.org'
|
||||
add_list system.ntp.server='3.openwrt.pool.ntp.org'
|
||||
EOF
|
||||
|
||||
if json_is_a system object; then
|
||||
|
@ -1,6 +1,7 @@
|
||||
root:x:0:
|
||||
daemon:x:1:
|
||||
adm:x:4:
|
||||
tty:x:5:
|
||||
mail:x:8:
|
||||
audio:x:29:
|
||||
www-data:x:33:
|
||||
|
@ -72,6 +72,7 @@ load_led() {
|
||||
[ -n "$dev" ] && {
|
||||
echo $dev > /sys/class/leds/${sysfs}/device_name
|
||||
echo $mode > /sys/class/leds/${sysfs}/mode
|
||||
echo $interval > /sys/class/leds/${sysfs}/interval
|
||||
}
|
||||
;;
|
||||
|
||||
|
@ -7,7 +7,7 @@ USE_PROCD=1
|
||||
validate_system_section()
|
||||
{
|
||||
uci_validate_section system system "${1}" \
|
||||
'hostname:string:lede' \
|
||||
'hostname:string:OpenWrt' \
|
||||
'conloglevel:uinteger' \
|
||||
'buffersize:uinteger' \
|
||||
'timezone:string:UTC' \
|
||||
|
@ -1,8 +1,7 @@
|
||||
DISTRIB_ID='%D'
|
||||
DISTRIB_RELEASE='%V'
|
||||
DISTRIB_REVISION='%R'
|
||||
DISTRIB_CODENAME='%n'
|
||||
DISTRIB_TARGET='%S'
|
||||
DISTRIB_ARCH='%A'
|
||||
DISTRIB_DESCRIPTION='%D %N %V %C'
|
||||
DISTRIB_DESCRIPTION='%D %V %C'
|
||||
DISTRIB_TAINTS='%t'
|
||||
|
@ -41,14 +41,15 @@ disable() {
|
||||
}
|
||||
|
||||
enable() {
|
||||
err=1
|
||||
name="$(basename "${initscript}")"
|
||||
disable
|
||||
[ -n "$START" -o -n "$STOP" ] || {
|
||||
echo "/etc/init.d/$name does not have a START or STOP value"
|
||||
return 1
|
||||
}
|
||||
[ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
|
||||
[ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
|
||||
[ "$START" ] && \
|
||||
ln -sf "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" && \
|
||||
err=0
|
||||
[ "$STOP" ] && \
|
||||
ln -sf "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}" && \
|
||||
err=0
|
||||
return $err
|
||||
}
|
||||
|
||||
enabled() {
|
||||
@ -88,6 +89,10 @@ service_triggers() {
|
||||
return 0
|
||||
}
|
||||
|
||||
service_data() {
|
||||
return 0
|
||||
}
|
||||
|
||||
service_running() {
|
||||
return 0
|
||||
}
|
||||
@ -122,12 +127,14 @@ ${INIT_TRACE:+set -x}
|
||||
}
|
||||
|
||||
stop() {
|
||||
procd_lock
|
||||
stop_service "$@"
|
||||
procd_kill "$(basename ${basescript:-$initscript})" "$1"
|
||||
}
|
||||
|
||||
reload() {
|
||||
if eval "type reload_service" 2>/dev/null >/dev/null; then
|
||||
procd_lock
|
||||
reload_service "$@"
|
||||
else
|
||||
start
|
||||
|
@ -1,5 +1,6 @@
|
||||
kernel.panic=3
|
||||
kernel.core_pattern=/tmp/%e.%t.%p.%s.core
|
||||
fs.suid_dumpable=2
|
||||
|
||||
net.ipv4.conf.default.arp_ignore=1
|
||||
net.ipv4.conf.all.arp_ignore=1
|
||||
|
@ -202,7 +202,7 @@ add_group_and_user() {
|
||||
if [ -n "$gname" ] && [ -n "$gid" ]; then
|
||||
group_exists "$gname" || group_add "$gname" "$gid"
|
||||
elif [ -n "$gname" ]; then
|
||||
group_add_next "$gname"; gid=$?
|
||||
gid="$(group_add_next "$gname")"
|
||||
fi
|
||||
|
||||
if [ -n "$uname" ]; then
|
||||
@ -235,6 +235,10 @@ default_postinst() {
|
||||
rm -fR $root/rootfs-overlay/
|
||||
fi
|
||||
|
||||
if [ -z "$root" ] && grep -q -s "^/etc/modules.d/" "/usr/lib/opkg/info/${pkgname}.list"; then
|
||||
kmodloader
|
||||
fi
|
||||
|
||||
if [ -z "$root" ] && grep -q -s "^/etc/uci-defaults/" "/usr/lib/opkg/info/${pkgname}.list"; then
|
||||
. /lib/functions/system.sh
|
||||
[ -d /tmp/.uci ] || mkdir -p /tmp/.uci
|
||||
@ -292,9 +296,7 @@ group_add() {
|
||||
[ -f "${IPKG_INSTROOT}/etc/group" ] || return 1
|
||||
[ -n "$IPKG_INSTROOT" ] || lock /var/lock/group
|
||||
echo "${name}:x:${gid}:" >> ${IPKG_INSTROOT}/etc/group
|
||||
rc=$?
|
||||
[ -n "$IPKG_INSTROOT" ] || lock -u /var/lock/group
|
||||
return $rc
|
||||
}
|
||||
|
||||
group_exists() {
|
||||
@ -304,14 +306,17 @@ group_exists() {
|
||||
group_add_next() {
|
||||
local gid gids
|
||||
gid=$(grep -s "^${1}:" ${IPKG_INSTROOT}/etc/group | cut -d: -f3)
|
||||
[ -n "$gid" ] && return $gid
|
||||
if [ -n "$gid" ]; then
|
||||
echo $gid
|
||||
return
|
||||
fi
|
||||
gids=$(cat ${IPKG_INSTROOT}/etc/group | cut -d: -f3)
|
||||
gid=100
|
||||
while [ -n "$(echo $gids | grep $gid)" ] ; do
|
||||
gid=65536
|
||||
while [ -n "$(echo "$gids" | grep "^$gid$")" ] ; do
|
||||
gid=$((gid + 1))
|
||||
done
|
||||
group_add $1 $gid
|
||||
return $gid
|
||||
echo $gid
|
||||
}
|
||||
|
||||
group_add_user() {
|
||||
@ -334,8 +339,8 @@ user_add() {
|
||||
local rc
|
||||
[ -z "$uid" ] && {
|
||||
uids=$(cat ${IPKG_INSTROOT}/etc/passwd | cut -d: -f3)
|
||||
uid=100
|
||||
while [ -n "$(echo $uids | grep $uid)" ] ; do
|
||||
uid=65536
|
||||
while [ -n "$(echo "$uids" | grep "^$uid$")" ] ; do
|
||||
uid=$((uid + 1))
|
||||
done
|
||||
}
|
||||
@ -344,9 +349,7 @@ user_add() {
|
||||
[ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd
|
||||
echo "${name}:x:${uid}:${gid}:${desc}:${home}:${shell}" >> ${IPKG_INSTROOT}/etc/passwd
|
||||
echo "${name}:x:0:0:99999:7:::" >> ${IPKG_INSTROOT}/etc/shadow
|
||||
rc=$?
|
||||
[ -n "$IPKG_INSTROOT" ] || lock -u /var/lock/passwd
|
||||
return $rc
|
||||
}
|
||||
|
||||
user_exists() {
|
||||
|
@ -1,6 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2013 OpenWrt.org
|
||||
|
||||
get_dt_led() {
|
||||
local label
|
||||
local ledpath
|
||||
local basepath="/proc/device-tree"
|
||||
local nodepath="$basepath/aliases/led-$1"
|
||||
|
||||
[ -f "$nodepath" ] && ledpath=$(cat "$nodepath")
|
||||
[ -n "$ledpath" ] && label=$(cat "$basepath$ledpath/label")
|
||||
|
||||
echo "$label"
|
||||
}
|
||||
|
||||
led_set_attr() {
|
||||
[ -f "/sys/class/leds/$1/$2" ] && echo "$3" > "/sys/class/leds/$1/$2"
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ _ucidef_finish_switch_roles() {
|
||||
json_select ..
|
||||
json_select ..
|
||||
|
||||
if [ $n_vlan -gt $n_cpu -o ${need_tag:-0} -eq 1 ]; then
|
||||
if [ ${need_tag:-0} -eq 1 -o ${want_untag:-0} -ne 1 ]; then
|
||||
num="${num}t"
|
||||
device="${device}.${index}"
|
||||
fi
|
||||
@ -358,19 +358,59 @@ ucidef_add_vdsl_modem() {
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_netdev() {
|
||||
ucidef_set_led_ataport() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" ata"$4"
|
||||
}
|
||||
|
||||
_ucidef_set_led_common() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local dev="$4"
|
||||
local mode="${5:-link tx rx}"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string type netdev
|
||||
json_add_string sysfs "$sysfs"
|
||||
}
|
||||
|
||||
ucidef_set_led_default() {
|
||||
local default="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string default "$default"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_gpio() {
|
||||
local gpio="$4"
|
||||
local inverted="$5"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger"
|
||||
json_add_string type gpio
|
||||
json_add_int gpio "$gpio"
|
||||
json_add_boolean inverted "$inverted"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_ide() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" ide-disk
|
||||
}
|
||||
|
||||
ucidef_set_led_netdev() {
|
||||
local dev="$4"
|
||||
local mode="${5:-link tx rx}"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type netdev
|
||||
json_add_string device "$dev"
|
||||
json_add_string mode "$mode"
|
||||
json_select ..
|
||||
@ -378,24 +418,106 @@ ucidef_set_led_netdev() {
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_oneshot() {
|
||||
_ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5
|
||||
}
|
||||
|
||||
ucidef_set_led_portstate() {
|
||||
local port_state="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger port_state
|
||||
json_add_string type portstate
|
||||
json_add_string port_state "$port_state"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_rssi() {
|
||||
local iface="$4"
|
||||
local minq="$5"
|
||||
local maxq="$6"
|
||||
local offset="${7:-0}"
|
||||
local factor="${8:-1}"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string type rssi
|
||||
json_add_string name "$name"
|
||||
json_add_string iface "$iface"
|
||||
json_add_string minq "$minq"
|
||||
json_add_string maxq "$maxq"
|
||||
json_add_string offset "$offset"
|
||||
json_add_string factor "$factor"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_switch() {
|
||||
local trigger_name="$4"
|
||||
local port_mask="$5"
|
||||
local speed_mask="$6"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_add_string type switch
|
||||
json_add_string port_mask "$port_mask"
|
||||
json_add_string speed_mask "$speed_mask"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
_ucidef_set_led_timer() {
|
||||
local trigger_name="$4"
|
||||
local delayon="$5"
|
||||
local delayoff="$6"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_add_int delayon "$delayon"
|
||||
json_add_int delayoff "$delayoff"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_timer() {
|
||||
_ucidef_set_led_timer $1 $2 $3 "timer" $4 $5
|
||||
}
|
||||
|
||||
_ucidef_set_led_trigger() {
|
||||
local trigger_name="$4"
|
||||
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_add_string trigger "$trigger_name"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_usbdev() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local dev="$4"
|
||||
|
||||
json_select_object led
|
||||
_ucidef_set_led_common "$1" "$2" "$3"
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string type usb
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_string device "$dev"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_usbhost() {
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" usb-host
|
||||
}
|
||||
|
||||
ucidef_set_led_usbport() {
|
||||
local obj="$1"
|
||||
local name="$2"
|
||||
@ -404,12 +526,9 @@ ucidef_set_led_usbport() {
|
||||
shift
|
||||
shift
|
||||
|
||||
json_select_object led
|
||||
_ucidef_set_led_common "$obj" "$name" "$sysfs"
|
||||
|
||||
json_select_object "$obj"
|
||||
json_add_string name "$name"
|
||||
json_add_string type usbport
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_select_array ports
|
||||
for port in "$@"; do
|
||||
json_add_string port "$port"
|
||||
@ -421,171 +540,7 @@ ucidef_set_led_usbport() {
|
||||
}
|
||||
|
||||
ucidef_set_led_wlan() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local trigger="$4"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string type trigger
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_string trigger "$trigger"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_switch() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local trigger="$4"
|
||||
local port_mask="$5"
|
||||
local speed_mask="$6"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string type switch
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_string trigger "$trigger"
|
||||
json_add_string port_mask "$port_mask"
|
||||
json_add_string speed_mask "$speed_mask"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_portstate() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local port_state="$4"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string type portstate
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_string trigger port_state
|
||||
json_add_string port_state "$port_state"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_default() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local default="$4"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_string default "$default"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_gpio() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local gpio="$4"
|
||||
local inverted="$5"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string type gpio
|
||||
json_add_string name "$name"
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_string trigger "$trigger"
|
||||
json_add_int gpio "$gpio"
|
||||
json_add_boolean inverted "$inverted"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_ide() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string name "$name"
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_string trigger ide-disk
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
__ucidef_set_led_timer() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local trigger="$4"
|
||||
local delayon="$5"
|
||||
local delayoff="$6"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string type "$trigger"
|
||||
json_add_string name "$name"
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_int delayon "$delayon"
|
||||
json_add_int delayoff "$delayoff"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
}
|
||||
|
||||
ucidef_set_led_oneshot() {
|
||||
__ucidef_set_led_timer $1 $2 $3 "oneshot" $4 $5
|
||||
}
|
||||
|
||||
ucidef_set_led_timer() {
|
||||
__ucidef_set_led_timer $1 $2 $3 "timer" $4 $5
|
||||
}
|
||||
|
||||
ucidef_set_led_rssi() {
|
||||
local cfg="led_$1"
|
||||
local name="$2"
|
||||
local sysfs="$3"
|
||||
local iface="$4"
|
||||
local minq="$5"
|
||||
local maxq="$6"
|
||||
local offset="$7"
|
||||
local factor="$8"
|
||||
|
||||
json_select_object led
|
||||
|
||||
json_select_object "$1"
|
||||
json_add_string type rssi
|
||||
json_add_string name "$name"
|
||||
json_add_string iface "$iface"
|
||||
json_add_string sysfs "$sysfs"
|
||||
json_add_string minq "$minq"
|
||||
json_add_string maxq "$maxq"
|
||||
json_add_string offset "$offset"
|
||||
json_add_string factor "$factor"
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
_ucidef_set_led_trigger "$1" "$2" "$3" "$4"
|
||||
}
|
||||
|
||||
ucidef_set_rssimon() {
|
||||
@ -601,7 +556,6 @@ ucidef_set_rssimon() {
|
||||
json_select ..
|
||||
|
||||
json_select ..
|
||||
|
||||
}
|
||||
|
||||
ucidef_add_gpio_switch() {
|
||||
|
@ -113,7 +113,7 @@ preinit_ip() {
|
||||
preinit_config_board
|
||||
fi
|
||||
|
||||
preinit_net_echo "Doing Lede Preinit\n"
|
||||
preinit_net_echo "Doing OpenWrt Preinit\n"
|
||||
}
|
||||
|
||||
preinit_ip_deconfig() {
|
||||
|
@ -5,8 +5,12 @@
|
||||
run_failsafe_hook() {
|
||||
[ "$pi_preinit_no_failsafe" = "y" ] && return
|
||||
if [ "$FAILSAFE" = "true" ]; then
|
||||
lock /tmp/.failsafe
|
||||
boot_run_hook failsafe
|
||||
lock -w /tmp/.failsafe
|
||||
while [ ! -e /tmp/sysupgrade ]; do
|
||||
lock -w /tmp/.failsafe
|
||||
done
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -8,10 +8,13 @@ failsafe_netlogin () {
|
||||
}
|
||||
|
||||
failsafe_shell() {
|
||||
lock /tmp/.failsafe
|
||||
ash --login
|
||||
echo "Please reboot system when done with failsafe network logins"
|
||||
while true; do sleep 1; done
|
||||
local console="$(sed -e 's/ /\n/g' /proc/cmdline | grep '^console=' | head -1 | sed -e 's/^console=//' -e 's/,.*//')"
|
||||
[ -n "$console" ] || console=console
|
||||
[ -c "/dev/$console" ] || return 0
|
||||
while true; do
|
||||
ash --login <"/dev/$console" >"/dev/$console" 2>"/dev/$console"
|
||||
sleep 1
|
||||
done &
|
||||
}
|
||||
|
||||
boot_hook_add failsafe failsafe_netlogin
|
||||
|
@ -6,143 +6,33 @@ RAM_ROOT=/tmp/root
|
||||
libs() { ldd $* 2>/dev/null | sed -r 's/(.* => )?(.*) .*/\2/'; }
|
||||
|
||||
install_file() { # <file> [ <file> ... ]
|
||||
local target dest dir
|
||||
for file in "$@"; do
|
||||
if [ -L "$file" ]; then
|
||||
target="$(readlink -f "$file")"
|
||||
dest="$RAM_ROOT/$file"
|
||||
[ ! -f "$dest" ] && {
|
||||
dir="$(dirname "$dest")"
|
||||
mkdir -p "$dir"
|
||||
ln -s "$target" "$dest"
|
||||
}
|
||||
file="$target"
|
||||
fi
|
||||
dest="$RAM_ROOT/$file"
|
||||
[ -f $file -a ! -f $dest ] && {
|
||||
dir="$(dirname $dest)"
|
||||
[ -f "$file" -a ! -f "$dest" ] && {
|
||||
dir="$(dirname "$dest")"
|
||||
mkdir -p "$dir"
|
||||
cp $file $dest
|
||||
cp "$file" "$dest"
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
install_bin() { # <file> [ <symlink> ... ]
|
||||
install_bin() {
|
||||
local src files
|
||||
src=$1
|
||||
files=$1
|
||||
[ -x "$src" ] && files="$src $(libs $src)"
|
||||
install_file $files
|
||||
shift
|
||||
for link in "$@"; do {
|
||||
dest="$RAM_ROOT/$link"
|
||||
dir="$(dirname $dest)"
|
||||
mkdir -p "$dir"
|
||||
[ -f "$dest" ] || ln -s $src $dest
|
||||
}; done
|
||||
}
|
||||
|
||||
supivot() { # <new_root> <old_root>
|
||||
/bin/mount | grep "on $1 type" 2>&- 1>&- || /bin/mount -o bind $1 $1
|
||||
mkdir -p $1$2 $1/proc $1/sys $1/dev $1/tmp $1/overlay && \
|
||||
/bin/mount -o noatime,move /proc $1/proc && \
|
||||
pivot_root $1 $1$2 || {
|
||||
/bin/umount -l $1 $1
|
||||
return 1
|
||||
}
|
||||
|
||||
/bin/mount -o noatime,move $2/sys /sys
|
||||
/bin/mount -o noatime,move $2/dev /dev
|
||||
/bin/mount -o noatime,move $2/tmp /tmp
|
||||
/bin/mount -o noatime,move $2/overlay /overlay 2>&-
|
||||
return 0
|
||||
}
|
||||
|
||||
run_ramfs() { # <command> [...]
|
||||
install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount \
|
||||
/sbin/pivot_root /sbin/reboot /bin/sync /bin/dd /bin/grep \
|
||||
/bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" /bin/dd \
|
||||
/bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump \
|
||||
/bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc \
|
||||
/bin/cut /usr/bin/printf /bin/sync /bin/mkdir /bin/rmdir \
|
||||
/bin/rm /usr/bin/basename /bin/kill /bin/chmod /usr/bin/find \
|
||||
/bin/mknod
|
||||
|
||||
install_bin /bin/uclient-fetch /bin/wget
|
||||
install_bin /sbin/mtd
|
||||
install_bin /sbin/mount_root
|
||||
install_bin /sbin/snapshot
|
||||
install_bin /sbin/snapshot_tool
|
||||
install_bin /usr/sbin/ubiupdatevol
|
||||
install_bin /usr/sbin/ubiattach
|
||||
install_bin /usr/sbin/ubiblock
|
||||
install_bin /usr/sbin/ubiformat
|
||||
install_bin /usr/sbin/ubidetach
|
||||
install_bin /usr/sbin/ubirsvol
|
||||
install_bin /usr/sbin/ubirmvol
|
||||
install_bin /usr/sbin/ubimkvol
|
||||
install_bin /usr/sbin/partx
|
||||
install_bin /usr/sbin/losetup
|
||||
install_bin /usr/sbin/mkfs.ext4
|
||||
for file in $RAMFS_COPY_BIN; do
|
||||
install_bin ${file//:/ }
|
||||
done
|
||||
install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
|
||||
|
||||
[ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
|
||||
|
||||
supivot $RAM_ROOT /mnt || {
|
||||
echo "Failed to switch over to ramfs. Please reboot."
|
||||
exit 1
|
||||
}
|
||||
|
||||
/bin/mount -o remount,ro /mnt
|
||||
/bin/umount -l /mnt
|
||||
|
||||
grep /overlay /proc/mounts > /dev/null && {
|
||||
/bin/mount -o noatime,remount,ro /overlay
|
||||
/bin/umount -l /overlay
|
||||
}
|
||||
|
||||
# spawn a new shell from ramdisk to reduce the probability of cache issues
|
||||
exec /bin/busybox ash -c "$*"
|
||||
}
|
||||
|
||||
kill_remaining() { # [ <signal> ]
|
||||
local sig="${1:-TERM}"
|
||||
echo -n "Sending $sig to remaining processes ... "
|
||||
|
||||
local my_pid=$$
|
||||
local my_ppid=$(cut -d' ' -f4 /proc/$my_pid/stat)
|
||||
local my_ppisupgraded=
|
||||
grep -q upgraded /proc/$my_ppid/cmdline >/dev/null && {
|
||||
local my_ppisupgraded=1
|
||||
}
|
||||
|
||||
local stat
|
||||
for stat in /proc/[0-9]*/stat; do
|
||||
[ -f "$stat" ] || continue
|
||||
|
||||
local pid name state ppid rest
|
||||
read pid name state ppid rest < $stat
|
||||
name="${name#(}"; name="${name%)}"
|
||||
|
||||
local cmdline
|
||||
read cmdline < /proc/$pid/cmdline
|
||||
|
||||
# Skip kernel threads
|
||||
[ -n "$cmdline" ] || continue
|
||||
|
||||
if [ $$ -eq 1 ] || [ $my_ppid -eq 1 ] && [ -n "$my_ppisupgraded" ]; then
|
||||
# Running as init process, kill everything except me
|
||||
if [ $pid -ne $$ ] && [ $pid -ne $my_ppid ]; then
|
||||
echo -n "$name "
|
||||
kill -$sig $pid 2>/dev/null
|
||||
fi
|
||||
else
|
||||
case "$name" in
|
||||
# Skip essential services
|
||||
*procd*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*|*nas*|*relayd*) : ;;
|
||||
|
||||
# Killable process
|
||||
*)
|
||||
if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then
|
||||
echo -n "$name "
|
||||
kill -$sig $pid 2>/dev/null
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
}
|
||||
|
||||
run_hooks() {
|
||||
@ -175,28 +65,31 @@ v() {
|
||||
[ "$VERBOSE" -ge 1 ] && echo "$@"
|
||||
}
|
||||
|
||||
json_string() {
|
||||
local v="$1"
|
||||
v="${v//\\/\\\\}"
|
||||
v="${v//\"/\\\"}"
|
||||
echo "\"$v\""
|
||||
}
|
||||
|
||||
rootfs_type() {
|
||||
/bin/mount | awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }'
|
||||
}
|
||||
|
||||
get_image() { # <source> [ <command> ]
|
||||
local from="$1"
|
||||
local conc="$2"
|
||||
local cmd
|
||||
local cat="$2"
|
||||
|
||||
case "$from" in
|
||||
http://*|ftp://*) cmd="wget -O- -q";;
|
||||
*) cmd="cat";;
|
||||
esac
|
||||
if [ -z "$conc" ]; then
|
||||
local magic="$(eval $cmd \"$from\" 2>/dev/null | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')"
|
||||
if [ -z "$cat" ]; then
|
||||
local magic="$(dd if="$from" bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')"
|
||||
case "$magic" in
|
||||
1f8b) conc="zcat";;
|
||||
425a) conc="bzcat";;
|
||||
1f8b) cat="zcat";;
|
||||
425a) cat="bzcat";;
|
||||
*) cat="cat";;
|
||||
esac
|
||||
fi
|
||||
|
||||
eval "$cmd \"$from\" 2>/dev/null ${conc:+| $conc}"
|
||||
$cat "$from" 2>/dev/null
|
||||
}
|
||||
|
||||
get_magic_word() {
|
||||
@ -328,12 +221,14 @@ default_do_upgrade() {
|
||||
fi
|
||||
}
|
||||
|
||||
do_upgrade() {
|
||||
do_upgrade_stage2() {
|
||||
v "Performing system upgrade..."
|
||||
if type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
|
||||
platform_do_upgrade "$ARGV"
|
||||
if [ -n "$do_upgrade" ]; then
|
||||
eval "$do_upgrade"
|
||||
elif type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
|
||||
platform_do_upgrade "$IMAGE"
|
||||
else
|
||||
default_do_upgrade "$ARGV"
|
||||
default_do_upgrade "$IMAGE"
|
||||
fi
|
||||
|
||||
if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev/null 2>/dev/null; then
|
||||
@ -341,12 +236,11 @@ do_upgrade() {
|
||||
fi
|
||||
|
||||
v "Upgrade completed"
|
||||
[ -n "$DELAY" ] && sleep "$DELAY"
|
||||
ask_bool 1 "Reboot" && {
|
||||
v "Rebooting system..."
|
||||
umount -a
|
||||
reboot -f
|
||||
sleep 5
|
||||
echo b 2>/dev/null >/proc/sysrq-trigger
|
||||
}
|
||||
sleep 1
|
||||
|
||||
v "Rebooting system..."
|
||||
umount -a
|
||||
reboot -f
|
||||
sleep 5
|
||||
echo b 2>/dev/null >/proc/sysrq-trigger
|
||||
}
|
||||
|
329
package/base-files/files/lib/upgrade/nand.sh
Normal file
329
package/base-files/files/lib/upgrade/nand.sh
Normal file
@ -0,0 +1,329 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2014 OpenWrt.org
|
||||
#
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
# 'kernel' partition on NAND contains the kernel
|
||||
CI_KERNPART="${CI_KERNPART:-kernel}"
|
||||
|
||||
# 'ubi' partition on NAND contains UBI
|
||||
CI_UBIPART="${CI_UBIPART:-ubi}"
|
||||
|
||||
ubi_mknod() {
|
||||
local dir="$1"
|
||||
local dev="/dev/$(basename $dir)"
|
||||
|
||||
[ -e "$dev" ] && return 0
|
||||
|
||||
local devid="$(cat $dir/dev)"
|
||||
local major="${devid%%:*}"
|
||||
local minor="${devid##*:}"
|
||||
mknod "$dev" c $major $minor
|
||||
}
|
||||
|
||||
nand_find_volume() {
|
||||
local ubidevdir ubivoldir
|
||||
ubidevdir="/sys/devices/virtual/ubi/$1"
|
||||
[ ! -d "$ubidevdir" ] && return 1
|
||||
for ubivoldir in $ubidevdir/${1}_*; do
|
||||
[ ! -d "$ubivoldir" ] && continue
|
||||
if [ "$( cat $ubivoldir/name )" = "$2" ]; then
|
||||
basename $ubivoldir
|
||||
ubi_mknod "$ubivoldir"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
nand_find_ubi() {
|
||||
local ubidevdir ubidev mtdnum
|
||||
mtdnum="$( find_mtd_index $1 )"
|
||||
[ ! "$mtdnum" ] && return 1
|
||||
for ubidevdir in /sys/devices/virtual/ubi/ubi*; do
|
||||
[ ! -d "$ubidevdir" ] && continue
|
||||
cmtdnum="$( cat $ubidevdir/mtd_num )"
|
||||
[ ! "$mtdnum" ] && continue
|
||||
if [ "$mtdnum" = "$cmtdnum" ]; then
|
||||
ubidev=$( basename $ubidevdir )
|
||||
ubi_mknod "$ubidevdir"
|
||||
echo $ubidev
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
nand_get_magic_long() {
|
||||
dd if="$1" skip=$2 bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
|
||||
}
|
||||
|
||||
get_magic_long_tar() {
|
||||
( tar xf $1 $2 -O | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2> /dev/null
|
||||
}
|
||||
|
||||
identify_magic() {
|
||||
local magic=$1
|
||||
case "$magic" in
|
||||
"55424923")
|
||||
echo "ubi"
|
||||
;;
|
||||
"31181006")
|
||||
echo "ubifs"
|
||||
;;
|
||||
"68737173")
|
||||
echo "squashfs"
|
||||
;;
|
||||
"d00dfeed")
|
||||
echo "fit"
|
||||
;;
|
||||
"4349"*)
|
||||
echo "combined"
|
||||
;;
|
||||
*)
|
||||
echo "unknown $magic"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
identify() {
|
||||
identify_magic $(nand_get_magic_long "$1" "${2:-0}")
|
||||
}
|
||||
|
||||
identify_tar() {
|
||||
identify_magic $(get_magic_long_tar "$1" "$2")
|
||||
}
|
||||
|
||||
nand_restore_config() {
|
||||
sync
|
||||
local ubidev=$( nand_find_ubi $CI_UBIPART )
|
||||
local ubivol="$( nand_find_volume $ubidev rootfs_data )"
|
||||
[ ! "$ubivol" ] &&
|
||||
ubivol="$( nand_find_volume $ubidev rootfs )"
|
||||
mkdir /tmp/new_root
|
||||
if ! mount -t ubifs /dev/$ubivol /tmp/new_root; then
|
||||
echo "mounting ubifs $ubivol failed"
|
||||
rmdir /tmp/new_root
|
||||
return 1
|
||||
fi
|
||||
mv "$1" "/tmp/new_root/sysupgrade.tgz"
|
||||
umount /tmp/new_root
|
||||
sync
|
||||
rmdir /tmp/new_root
|
||||
}
|
||||
|
||||
nand_upgrade_prepare_ubi() {
|
||||
local rootfs_length="$1"
|
||||
local rootfs_type="$2"
|
||||
local has_kernel="${3:-0}"
|
||||
local has_env="${4:-0}"
|
||||
|
||||
local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
|
||||
if [ ! "$mtdnum" ]; then
|
||||
echo "cannot find ubi mtd partition $CI_UBIPART"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
if [ ! "$ubidev" ]; then
|
||||
ubiattach -m "$mtdnum"
|
||||
sync
|
||||
ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
fi
|
||||
|
||||
if [ ! "$ubidev" ]; then
|
||||
ubiformat /dev/mtd$mtdnum -y
|
||||
ubiattach -m "$mtdnum"
|
||||
sync
|
||||
ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
[ "$has_env" -gt 0 ] && {
|
||||
ubimkvol /dev/$ubidev -n 0 -N ubootenv -s 1MiB
|
||||
ubimkvol /dev/$ubidev -n 1 -N ubootenv2 -s 1MiB
|
||||
}
|
||||
fi
|
||||
|
||||
local kern_ubivol="$( nand_find_volume $ubidev $CI_KERNPART )"
|
||||
local root_ubivol="$( nand_find_volume $ubidev rootfs )"
|
||||
local data_ubivol="$( nand_find_volume $ubidev rootfs_data )"
|
||||
|
||||
# remove ubiblock device of rootfs
|
||||
local root_ubiblk="ubiblock${root_ubivol:3}"
|
||||
if [ "$root_ubivol" -a -e "/dev/$root_ubiblk" ]; then
|
||||
echo "removing $root_ubiblk"
|
||||
if ! ubiblock -r /dev/$root_ubivol; then
|
||||
echo "cannot remove $root_ubiblk"
|
||||
return 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
# kill volumes
|
||||
[ "$kern_ubivol" ] && ubirmvol /dev/$ubidev -N $CI_KERNPART || true
|
||||
[ "$root_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs || true
|
||||
[ "$data_ubivol" ] && ubirmvol /dev/$ubidev -N rootfs_data || true
|
||||
|
||||
# update kernel
|
||||
if [ "$has_kernel" = "1" ]; then
|
||||
if ! ubimkvol /dev/$ubidev -N $CI_KERNPART -s $kernel_length; then
|
||||
echo "cannot create kernel volume"
|
||||
return 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
# update rootfs
|
||||
local root_size_param
|
||||
if [ "$rootfs_type" = "ubifs" ]; then
|
||||
root_size_param="-m"
|
||||
else
|
||||
root_size_param="-s $rootfs_length"
|
||||
fi
|
||||
if ! ubimkvol /dev/$ubidev -N rootfs $root_size_param; then
|
||||
echo "cannot create rootfs volume"
|
||||
return 1;
|
||||
fi
|
||||
|
||||
# create rootfs_data for non-ubifs rootfs
|
||||
if [ "$rootfs_type" != "ubifs" ]; then
|
||||
if ! ubimkvol /dev/$ubidev -N rootfs_data -m; then
|
||||
echo "cannot initialize rootfs_data volume"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
sync
|
||||
return 0
|
||||
}
|
||||
|
||||
nand_do_upgrade_success() {
|
||||
local conf_tar="/tmp/sysupgrade.tgz"
|
||||
|
||||
sync
|
||||
[ -f "$conf_tar" ] && nand_restore_config "$conf_tar"
|
||||
echo "sysupgrade successful"
|
||||
umount -a
|
||||
reboot -f
|
||||
}
|
||||
|
||||
# Flash the UBI image to MTD partition
|
||||
nand_upgrade_ubinized() {
|
||||
local ubi_file="$1"
|
||||
local mtdnum="$(find_mtd_index "$CI_UBIPART")"
|
||||
|
||||
[ ! "$mtdnum" ] && {
|
||||
CI_UBIPART="rootfs"
|
||||
mtdnum="$(find_mtd_index "$CI_UBIPART")"
|
||||
}
|
||||
|
||||
if [ ! "$mtdnum" ]; then
|
||||
echo "cannot find mtd device $CI_UBIPART"
|
||||
umount -a
|
||||
reboot -f
|
||||
fi
|
||||
|
||||
local mtddev="/dev/mtd${mtdnum}"
|
||||
ubidetach -p "${mtddev}" || true
|
||||
sync
|
||||
ubiformat "${mtddev}" -y -f "${ubi_file}"
|
||||
ubiattach -p "${mtddev}"
|
||||
nand_do_upgrade_success
|
||||
}
|
||||
|
||||
# Write the UBIFS image to UBI volume
|
||||
nand_upgrade_ubifs() {
|
||||
local rootfs_length=`(cat $1 | wc -c) 2> /dev/null`
|
||||
|
||||
nand_upgrade_prepare_ubi "$rootfs_length" "ubifs" "0" "0"
|
||||
|
||||
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
local root_ubivol="$(nand_find_volume $ubidev rootfs)"
|
||||
ubiupdatevol /dev/$root_ubivol -s $rootfs_length $1
|
||||
|
||||
nand_do_upgrade_success
|
||||
}
|
||||
|
||||
nand_upgrade_tar() {
|
||||
local tar_file="$1"
|
||||
local kernel_mtd="$(find_mtd_index $CI_KERNPART)"
|
||||
|
||||
local board_dir=$(tar tf $tar_file | grep -m 1 '^sysupgrade-.*/$')
|
||||
board_dir=${board_dir%/}
|
||||
|
||||
local kernel_length=`(tar xf $tar_file ${board_dir}/kernel -O | wc -c) 2> /dev/null`
|
||||
local rootfs_length=`(tar xf $tar_file ${board_dir}/root -O | wc -c) 2> /dev/null`
|
||||
|
||||
local rootfs_type="$(identify_tar "$tar_file" ${board_dir}/root)"
|
||||
|
||||
local has_kernel=1
|
||||
local has_env=0
|
||||
|
||||
[ "$kernel_length" != 0 -a -n "$kernel_mtd" ] && {
|
||||
tar xf $tar_file ${board_dir}/kernel -O | mtd write - $CI_KERNPART
|
||||
}
|
||||
[ "$kernel_length" = 0 -o ! -z "$kernel_mtd" ] && has_kernel=0
|
||||
|
||||
nand_upgrade_prepare_ubi "$rootfs_length" "$rootfs_type" "$has_kernel" "$has_env"
|
||||
|
||||
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
[ "$has_kernel" = "1" ] && {
|
||||
local kern_ubivol="$(nand_find_volume $ubidev $CI_KERNPART)"
|
||||
tar xf $tar_file ${board_dir}/kernel -O | \
|
||||
ubiupdatevol /dev/$kern_ubivol -s $kernel_length -
|
||||
}
|
||||
|
||||
local root_ubivol="$(nand_find_volume $ubidev rootfs)"
|
||||
tar xf $tar_file ${board_dir}/root -O | \
|
||||
ubiupdatevol /dev/$root_ubivol -s $rootfs_length -
|
||||
|
||||
nand_do_upgrade_success
|
||||
}
|
||||
|
||||
# Recognize type of passed file and start the upgrade process
|
||||
nand_do_upgrade() {
|
||||
if [ -n "$IS_PRE_UPGRADE" ]; then
|
||||
# Previously, nand_do_upgrade was called from the platform_pre_upgrade
|
||||
# hook; this piece of code handles scripts that haven't been
|
||||
# updated. All scripts should gradually move to call nand_do_upgrade
|
||||
# from platform_do_upgrade instead.
|
||||
export do_upgrade="nand_do_upgrade '$1'"
|
||||
return
|
||||
fi
|
||||
|
||||
local file_type=$(identify $1)
|
||||
|
||||
if type 'platform_nand_pre_upgrade' >/dev/null 2>/dev/null; then
|
||||
platform_nand_pre_upgrade "$1"
|
||||
fi
|
||||
|
||||
[ ! "$(find_mtd_index "$CI_UBIPART")" ] && CI_UBIPART="rootfs"
|
||||
|
||||
case "$file_type" in
|
||||
"ubi") nand_upgrade_ubinized $1;;
|
||||
"ubifs") nand_upgrade_ubifs $1;;
|
||||
*) nand_upgrade_tar $1;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Check if passed file is a valid one for NAND sysupgrade. Currently it accepts
|
||||
# 3 types of files:
|
||||
# 1) UBI - should contain an ubinized image, header is checked for the proper
|
||||
# MAGIC
|
||||
# 2) UBIFS - should contain UBIFS partition that will replace "rootfs" volume,
|
||||
# header is checked for the proper MAGIC
|
||||
# 3) TAR - archive has to include "sysupgrade-BOARD" directory with a non-empty
|
||||
# "CONTROL" file (at this point its content isn't verified)
|
||||
#
|
||||
# You usually want to call this function in platform_check_image.
|
||||
#
|
||||
# $(1): board name, used in case of passing TAR file
|
||||
# $(2): file to be checked
|
||||
nand_do_platform_check() {
|
||||
local board_name="$1"
|
||||
local tar_file="$2"
|
||||
local control_length=`(tar xf $tar_file sysupgrade-$board_name/CONTROL -O | wc -c) 2> /dev/null`
|
||||
local file_type="$(identify $2)"
|
||||
|
||||
[ "$control_length" = 0 -a "$file_type" != "ubi" -a "$file_type" != "ubifs" ] && {
|
||||
echo "Invalid sysupgrade file."
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
150
package/base-files/files/lib/upgrade/stage2
Executable file
150
package/base-files/files/lib/upgrade/stage2
Executable file
@ -0,0 +1,150 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/system.sh
|
||||
|
||||
export IMAGE="$1"
|
||||
COMMAND="$2"
|
||||
|
||||
export ARGV="$IMAGE"
|
||||
export ARGC=1
|
||||
|
||||
export SAVE_CONFIG=1
|
||||
export SAVE_PARTITIONS=1
|
||||
|
||||
export INTERACTIVE=0
|
||||
export VERBOSE=1
|
||||
export CONFFILES=/tmp/sysupgrade.conffiles
|
||||
export CONF_TAR=/tmp/sysupgrade.tgz
|
||||
|
||||
RAMFS_COPY_BIN= # extra programs for temporary ramfs root
|
||||
RAMFS_COPY_DATA= # extra data files
|
||||
|
||||
|
||||
[ -f "$CONF_TAR" ] || export SAVE_CONFIG=0
|
||||
[ -f /tmp/sysupgrade.always.overwrite.bootdisk.partmap ] && export SAVE_PARTITIONS=0
|
||||
|
||||
include /lib/upgrade
|
||||
|
||||
|
||||
supivot() { # <new_root> <old_root>
|
||||
/bin/mount | grep "on $1 type" 2>&- 1>&- || /bin/mount -o bind $1 $1
|
||||
mkdir -p $1$2 $1/proc $1/sys $1/dev $1/tmp $1/overlay && \
|
||||
/bin/mount -o noatime,move /proc $1/proc && \
|
||||
pivot_root $1 $1$2 || {
|
||||
/bin/umount -l $1 $1
|
||||
return 1
|
||||
}
|
||||
|
||||
/bin/mount -o noatime,move $2/sys /sys
|
||||
/bin/mount -o noatime,move $2/dev /dev
|
||||
/bin/mount -o noatime,move $2/tmp /tmp
|
||||
/bin/mount -o noatime,move $2/overlay /overlay 2>&-
|
||||
return 0
|
||||
}
|
||||
|
||||
switch_to_ramfs() {
|
||||
for binary in \
|
||||
/bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount \
|
||||
pivot_root mount_root reboot sync kill sleep \
|
||||
md5sum hexdump cat zcat bzcat dd tar \
|
||||
ls basename find cp mv rm mkdir rmdir mknod touch chmod \
|
||||
'[' printf wc grep awk sed cut \
|
||||
mtd partx losetup mkfs.ext4 \
|
||||
ubiupdatevol ubiattach ubiblock ubiformat \
|
||||
ubidetach ubirsvol ubirmvol ubimkvol \
|
||||
snapshot snapshot_tool \
|
||||
$RAMFS_COPY_BIN
|
||||
do
|
||||
local file="$(which "$binary" 2>/dev/null)"
|
||||
[ -n "$file" ] && install_bin "$file"
|
||||
done
|
||||
install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
|
||||
|
||||
[ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
|
||||
|
||||
supivot $RAM_ROOT /mnt || {
|
||||
echo "Failed to switch over to ramfs. Please reboot."
|
||||
exit 1
|
||||
}
|
||||
|
||||
/bin/mount -o remount,ro /mnt
|
||||
/bin/umount -l /mnt
|
||||
|
||||
grep /overlay /proc/mounts > /dev/null && {
|
||||
/bin/mount -o noatime,remount,ro /overlay
|
||||
/bin/umount -l /overlay
|
||||
}
|
||||
}
|
||||
|
||||
kill_remaining() { # [ <signal> [ <loop> ] ]
|
||||
local loop_limit=10
|
||||
|
||||
local sig="${1:-TERM}"
|
||||
local loop="${2:-0}"
|
||||
local run=true
|
||||
local stat
|
||||
local proc_ppid=$(cut -d' ' -f4 /proc/$$/stat)
|
||||
|
||||
echo -n "Sending $sig to remaining processes ... "
|
||||
|
||||
while $run; do
|
||||
run=false
|
||||
for stat in /proc/[0-9]*/stat; do
|
||||
[ -f "$stat" ] || continue
|
||||
|
||||
local pid name state ppid rest
|
||||
read pid name state ppid rest < $stat
|
||||
name="${name#(}"; name="${name%)}"
|
||||
|
||||
# Skip PID1, our parent, ourself and our children
|
||||
[ $pid -ne 1 -a $pid -ne $proc_ppid -a $pid -ne $$ -a $ppid -ne $$ ] || continue
|
||||
|
||||
local cmdline
|
||||
read cmdline < /proc/$pid/cmdline
|
||||
|
||||
# Skip kernel threads
|
||||
[ -n "$cmdline" ] || continue
|
||||
|
||||
echo -n "$name "
|
||||
kill -$sig $pid 2>/dev/null
|
||||
|
||||
[ $loop -eq 1 ] && run=true
|
||||
done
|
||||
|
||||
let loop_limit--
|
||||
[ $loop_limit -eq 0 ] && {
|
||||
echo
|
||||
echo "Failed to kill all processes."
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
|
||||
killall -9 telnetd
|
||||
killall -9 dropbear
|
||||
killall -9 ash
|
||||
|
||||
kill_remaining TERM
|
||||
sleep 3
|
||||
kill_remaining KILL 1
|
||||
|
||||
sleep 1
|
||||
|
||||
|
||||
if [ -n "$IMAGE" ] && type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
|
||||
IS_PRE_UPGRADE=1 platform_pre_upgrade "$IMAGE"
|
||||
|
||||
# Needs to be unset again because of busybox weirdness ...
|
||||
IS_PRE_UPGRADE=
|
||||
fi
|
||||
|
||||
if [ -n "$(rootfs_type)" ]; then
|
||||
echo "Switching to ramdisk..."
|
||||
switch_to_ramfs
|
||||
fi
|
||||
|
||||
# Exec new shell from ramfs
|
||||
exec /bin/busybox ash -c "$COMMAND"
|
@ -1,17 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/system.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 SAVE_PARTITIONS=1
|
||||
export DELAY=
|
||||
export CONF_IMAGE=
|
||||
export CONF_BACKUP_LIST=0
|
||||
export CONF_BACKUP=
|
||||
@ -25,7 +23,6 @@ export TEST=0
|
||||
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;;
|
||||
@ -50,10 +47,9 @@ done
|
||||
export CONFFILES=/tmp/sysupgrade.conffiles
|
||||
export CONF_TAR=/tmp/sysupgrade.tgz
|
||||
|
||||
export ARGV="$*"
|
||||
export ARGC="$#"
|
||||
IMAGE="$1"
|
||||
|
||||
[ -z "$ARGV" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
|
||||
[ -z "$IMAGE" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
|
||||
cat <<EOF
|
||||
Usage: $0 [<upgrade-option>...] <image file or URL>
|
||||
$0 [-q] [-i] <backup-command> <file>
|
||||
@ -90,7 +86,7 @@ EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -n "$ARGV" -a -n "$NEED_IMAGE" ] && {
|
||||
[ -n "$IMAGE" -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.
|
||||
@ -112,14 +108,8 @@ add_uci_conffiles() {
|
||||
|
||||
add_overlayfiles() {
|
||||
local file="$1"
|
||||
if [ -d /overlay/upper ]; then
|
||||
local overlaydir="/overlay/upper"
|
||||
else
|
||||
local overlaydir="/overlay"
|
||||
fi
|
||||
find $overlaydir/etc/ -type f -o -type l | sed \
|
||||
find /overlay/upper/etc/ -type f -o -type l | sed \
|
||||
-e 's,^/overlay\/upper/,/,' \
|
||||
-e 's,^/overlay/,/,' \
|
||||
-e '\,/META_[a-zA-Z0-9]*$,d' \
|
||||
-e '\,/functions.sh$,d' \
|
||||
-e '\,/[^/]*-opkg$,d' \
|
||||
@ -130,20 +120,26 @@ add_overlayfiles() {
|
||||
# hooks
|
||||
sysupgrade_image_check="fwtool_check_image platform_check_image"
|
||||
sysupgrade_pre_upgrade="fwtool_pre_upgrade"
|
||||
[ $SAVE_OVERLAY = 0 -o ! -d /overlay/etc ] && \
|
||||
sysupgrade_init_conffiles="add_uci_conffiles" || \
|
||||
|
||||
if [ $SAVE_OVERLAY = 1 ]; then
|
||||
[ ! -d /overlay/upper/etc ] && {
|
||||
echo "Cannot find '/overlay/upper/etc', required for '-c'"
|
||||
exit 1
|
||||
}
|
||||
sysupgrade_init_conffiles="add_overlayfiles"
|
||||
else
|
||||
sysupgrade_init_conffiles="add_uci_conffiles"
|
||||
fi
|
||||
|
||||
include /lib/upgrade
|
||||
|
||||
[ "$1" = "nand" ] && nand_upgrade_stage2 $@
|
||||
|
||||
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
|
||||
rm -f "$conf_tar"
|
||||
return 0
|
||||
}
|
||||
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
|
||||
@ -157,7 +153,7 @@ do_save_conffiles() {
|
||||
}
|
||||
|
||||
if [ $CONF_BACKUP_LIST -eq 1 ]; then
|
||||
add_uci_conffiles "$CONFFILES"
|
||||
run_hooks "$CONFFILES" $sysupgrade_init_conffiles
|
||||
cat "$CONFFILES"
|
||||
rm -f "$CONFFILES"
|
||||
exit 0
|
||||
@ -184,8 +180,33 @@ type platform_check_image >/dev/null 2>/dev/null || {
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$IMAGE" in
|
||||
http://*)
|
||||
wget -O/tmp/sysupgrade.img "$IMAGE"
|
||||
IMAGE=/tmp/sysupgrade.img
|
||||
;;
|
||||
esac
|
||||
|
||||
IMAGE="$(readlink -f "$IMAGE")"
|
||||
|
||||
case "$IMAGE" in
|
||||
'')
|
||||
echo "Image file not found."
|
||||
exit 1
|
||||
;;
|
||||
/tmp/*) ;;
|
||||
*)
|
||||
v "Image not in /tmp, copying..."
|
||||
cp -f "$IMAGE" /tmp/sysupgrade.img
|
||||
IMAGE=/tmp/sysupgrade.img
|
||||
;;
|
||||
esac
|
||||
|
||||
export ARGV="$IMAGE"
|
||||
export ARGC=1
|
||||
|
||||
for check in $sysupgrade_image_check; do
|
||||
( eval "$check \"\$ARGV\"" ) || {
|
||||
( $check "$IMAGE" ) || {
|
||||
if [ $FORCE -eq 1 ]; then
|
||||
echo "Image check '$check' failed but --force given - will update anyway!"
|
||||
break
|
||||
@ -211,6 +232,7 @@ elif ask_bool $SAVE_CONFIG "Keep config files over reflash"; then
|
||||
[ $TEST -eq 1 ] || do_save_conffiles
|
||||
export SAVE_CONFIG=1
|
||||
else
|
||||
[ $TEST -eq 1 ] || rm -f "$CONF_TAR"
|
||||
export SAVE_CONFIG=0
|
||||
fi
|
||||
|
||||
@ -218,28 +240,26 @@ if [ $TEST -eq 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ $SAVE_PARTITIONS -eq 0 ]; then
|
||||
touch /tmp/sysupgrade.always.overwrite.bootdisk.partmap
|
||||
else
|
||||
rm -f /tmp/sysupgrade.always.overwrite.bootdisk.partmap
|
||||
fi
|
||||
|
||||
run_hooks "" $sysupgrade_pre_upgrade
|
||||
|
||||
# Some platforms/devices may want different sysupgrade process, e.g. without
|
||||
# killing processes yet or calling ubus system upgrade method.
|
||||
# This is needed e.g. on NAND devices where we just want to trigger stage1 at
|
||||
# this point.
|
||||
if type 'platform_pre_upgrade' >/dev/null 2>/dev/null; then
|
||||
platform_pre_upgrade "$ARGV"
|
||||
fi
|
||||
install_bin /sbin/upgraded
|
||||
v "Commencing upgrade. All shell sessions will be closed now."
|
||||
|
||||
ubus call system upgrade
|
||||
touch /tmp/sysupgrade
|
||||
COMMAND='. /lib/functions.sh; include /lib/upgrade; do_upgrade_stage2'
|
||||
|
||||
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'
|
||||
if [ -n "$FAILSAFE" ]; then
|
||||
printf '%s\x00%s\x00%s' "$RAM_ROOT" "$IMAGE" "$COMMAND" >/tmp/sysupgrade
|
||||
lock -u /tmp/.failsafe
|
||||
else
|
||||
do_upgrade
|
||||
ubus call system sysupgrade "{
|
||||
\"prefix\": $(json_string "$RAM_ROOT"),
|
||||
\"path\": $(json_string "$IMAGE"),
|
||||
\"command\": $(json_string "$COMMAND")
|
||||
}"
|
||||
fi
|
||||
|
@ -1,8 +1,8 @@
|
||||
NAME="%D"
|
||||
VERSION="%V, %N"
|
||||
VERSION="%V"
|
||||
ID="%d"
|
||||
ID_LIKE="lede openwrt"
|
||||
PRETTY_NAME="%D %N %V"
|
||||
PRETTY_NAME="%D %V"
|
||||
VERSION_ID="%v"
|
||||
HOME_URL="%m"
|
||||
BUG_URL="%b"
|
||||
@ -15,4 +15,4 @@ LEDE_DEVICE_MANUFACTURER="%M"
|
||||
LEDE_DEVICE_MANUFACTURER_URL="%m"
|
||||
LEDE_DEVICE_PRODUCT="%P"
|
||||
LEDE_DEVICE_REVISION="%h"
|
||||
LEDE_RELEASE="%D %N %V %C"
|
||||
LEDE_RELEASE="%D %V %C"
|
||||
|
@ -158,18 +158,11 @@ if VERSIONOPT
|
||||
config VERSION_DIST
|
||||
string
|
||||
prompt "Release distribution"
|
||||
default "LEDE"
|
||||
default "OpenWrt"
|
||||
help
|
||||
This is the name of the release distribution.
|
||||
If unspecified, it defaults to OpenWrt.
|
||||
|
||||
config VERSION_NICK
|
||||
string
|
||||
prompt "Release version nickname"
|
||||
help
|
||||
This is the release codename embedded in the image.
|
||||
If unspecified, it defaults to the name of source branch.
|
||||
|
||||
config VERSION_NUMBER
|
||||
string
|
||||
prompt "Release version number"
|
||||
@ -190,7 +183,7 @@ if VERSIONOPT
|
||||
config VERSION_REPO
|
||||
string
|
||||
prompt "Release repository"
|
||||
default "http://downloads.lede-project.org/releases/17.01-SNAPSHOT"
|
||||
default "http://downloads.lede-project.org/snapshots"
|
||||
help
|
||||
This is the repository address embedded in the image, it defaults
|
||||
to the trunk snapshot repo; the url may contain the following placeholders:
|
||||
@ -199,15 +192,13 @@ if VERSIONOPT
|
||||
%v .. Configured release version number or "snapshot", lowercase
|
||||
%C .. Configured release revision code or value of %R, uppercase
|
||||
%c .. Configured release revision code or value of %R, lowercase
|
||||
%N .. Release name, uppercase
|
||||
%n .. Release name, lowercase
|
||||
%D .. Distribution name or "Lede", uppercase
|
||||
%d .. Distribution name or "lede", lowercase
|
||||
%D .. Distribution name or "OpenWrt", uppercase
|
||||
%d .. Distribution name or "openwrt", lowercase
|
||||
%T .. Target name
|
||||
%S .. Target/Subtarget name
|
||||
%A .. Package architecture
|
||||
%t .. Build taint flags, e.g. "no-all busybox"
|
||||
%M .. Manufacturer name or "Lede"
|
||||
%M .. Manufacturer name or "OpenWrt"
|
||||
%P .. Product name or "Generic"
|
||||
%h .. Hardware revision or "v0"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user