summaryrefslogtreecommitdiffstats
path: root/package/base-files/files
diff options
context:
space:
mode:
Diffstat (limited to 'package/base-files/files')
-rwxr-xr-xpackage/base-files/files/bin/ipcalc.sh15
-rw-r--r--package/base-files/files/etc/config/network8
l---------package/base-files/files/etc/functions.sh1
-rw-r--r--package/base-files/files/etc/hotplug.d/net/00-sysctl6
-rw-r--r--package/base-files/files/etc/hotplug2-init.rules5
-rwxr-xr-xpackage/base-files/files/etc/init.d/boot45
-rwxr-xr-xpackage/base-files/files/etc/init.d/done2
-rwxr-xr-xpackage/base-files/files/etc/init.d/rcS25
-rwxr-xr-xpackage/base-files/files/etc/init.d/sysctl2
-rwxr-xr-xpackage/base-files/files/etc/init.d/usb2
-rwxr-xr-xpackage/base-files/files/etc/init.d/watchdog13
-rw-r--r--package/base-files/files/etc/inittab3
-rwxr-xr-xpackage/base-files/files/etc/preinit3
-rwxr-xr-xpackage/base-files/files/etc/rc.button/failsafe2
-rwxr-xr-xpackage/base-files/files/etc/rc.button/reset18
-rwxr-xr-xpackage/base-files/files/etc/rc.button/rfkill23
-rwxr-xr-xpackage/base-files/files/etc/rc.common31
-rw-r--r--package/base-files/files/etc/sysctl.conf3
-rw-r--r--package/base-files/files/etc/uci-defaults/10_migrate-shadow (renamed from package/base-files/files/etc/uci-defaults/migrate-shadow)0
-rw-r--r--package/base-files/files/etc/uci-defaults/11_migrate-sysctl (renamed from package/base-files/files/etc/uci-defaults/migrate-sysctl)0
-rw-r--r--package/base-files/files/etc/uci-defaults/12_network-generate-ula18
-rw-r--r--package/base-files/files/lib/firstboot/05_firstboot_skip10
-rw-r--r--package/base-files/files/lib/firstboot/10_determine_parts46
-rw-r--r--package/base-files/files/lib/firstboot/10_no_fo_clear_overlay17
-rw-r--r--package/base-files/files/lib/firstboot/10_reset_has_mini_fo12
-rw-r--r--package/base-files/files/lib/firstboot/20_has_mini_fo13
-rw-r--r--package/base-files/files/lib/firstboot/20_no_fo_mount_jffs15
-rw-r--r--package/base-files/files/lib/firstboot/20_reset_clear_jffs14
-rw-r--r--package/base-files/files/lib/firstboot/30_is_rootfs_mounted10
-rw-r--r--package/base-files/files/lib/firstboot/30_no_fo_pivot11
-rw-r--r--package/base-files/files/lib/firstboot/30_reset_copy_rom13
-rw-r--r--package/base-files/files/lib/firstboot/40_copy_ramoverlay15
-rw-r--r--package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay14
-rw-r--r--package/base-files/files/lib/firstboot/50_pivot17
-rw-r--r--package/base-files/files/lib/firstboot/99_10_no_fo_cleanup13
-rw-r--r--package/base-files/files/lib/firstboot/99_10_with_fo_cleanup25
-rwxr-xr-xpackage/base-files/files/lib/functions.sh219
-rw-r--r--package/base-files/files/lib/functions/boot.sh150
-rw-r--r--package/base-files/files/lib/functions/leds.sh68
-rw-r--r--package/base-files/files/lib/functions/network.sh334
-rw-r--r--package/base-files/files/lib/functions/uci-defaults.sh6
-rw-r--r--package/base-files/files/lib/preinit/05_mount_skip13
-rw-r--r--package/base-files/files/lib/preinit/10_check_for_mtd20
-rw-r--r--package/base-files/files/lib/preinit/10_essential_fs25
-rw-r--r--package/base-files/files/lib/preinit/10_indicate_preinit1
-rw-r--r--package/base-files/files/lib/preinit/20_check_jffs2_ready19
-rw-r--r--package/base-files/files/lib/preinit/20_device_fs_mount37
-rw-r--r--package/base-files/files/lib/preinit/30_device_fs_daemons36
-rw-r--r--package/base-files/files/lib/preinit/30_failsafe_wait16
-rw-r--r--package/base-files/files/lib/preinit/40_init_shm10
-rw-r--r--package/base-files/files/lib/preinit/40_mount_devpts15
-rw-r--r--package/base-files/files/lib/preinit/40_mount_jffs226
-rw-r--r--package/base-files/files/lib/preinit/41_merge_overlay_hooks24
-rw-r--r--package/base-files/files/lib/preinit/50_choose_console31
-rw-r--r--package/base-files/files/lib/preinit/50_indicate_regular_preinit1
-rw-r--r--package/base-files/files/lib/preinit/60_init_hotplug10
-rw-r--r--package/base-files/files/lib/preinit/70_pivot_jffs2_root14
-rw-r--r--package/base-files/files/lib/preinit/80_mount_root14
-rw-r--r--package/base-files/files/lib/preinit/90_init_console14
-rw-r--r--package/base-files/files/lib/preinit/90_mount_no_jffs212
-rw-r--r--package/base-files/files/lib/preinit/90_restore_config17
-rw-r--r--package/base-files/files/lib/preinit/99_10_mount_no_mtd12
-rw-r--r--package/base-files/files/lib/preinit/99_10_run_init6
-rw-r--r--package/base-files/files/lib/upgrade/common.sh28
-rwxr-xr-xpackage/base-files/files/sbin/firstboot33
-rwxr-xr-xpackage/base-files/files/sbin/mount_root26
-rwxr-xr-xpackage/base-files/files/sbin/sysupgrade38
67 files changed, 742 insertions, 1003 deletions
diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh
index d6ef16870..7463d6bdd 100755
--- a/package/base-files/files/bin/ipcalc.sh
+++ b/package/base-files/files/bin/ipcalc.sh
@@ -22,6 +22,11 @@ function int2ip(ip,ret,x) {
return ret
}
+function compl32(v) {
+ ret=xor(v, 0xffffffff)
+ return ret
+}
+
BEGIN {
slpos=index(ARGV[1],"/")
if (slpos == 0) {
@@ -29,27 +34,27 @@ BEGIN {
netmask=ip2int(ARGV[2])
} else {
ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
- netmask=compl(2**(32-int(substr(ARGV[1],slpos+1)))-1)
+ netmask=compl32(2**(32-int(substr(ARGV[1],slpos+1)))-1)
ARGV[4]=ARGV[3]
ARGV[3]=ARGV[2]
}
network=and(ipaddr,netmask)
- broadcast=or(network,compl(netmask))
+ broadcast=or(network,compl32(netmask))
- start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
+ start=or(network,and(ip2int(ARGV[3]),compl32(netmask)))
limit=network+1
if (start<limit) start=limit
end=start+ARGV[4]
- limit=or(network,compl(netmask))-1
+ limit=or(network,compl32(netmask))-1
if (end>limit) end=limit
print "IP="int2ip(ipaddr)
print "NETMASK="int2ip(netmask)
print "BROADCAST="int2ip(broadcast)
print "NETWORK="int2ip(network)
- print "PREFIX="32-bitcount(compl(netmask))
+ print "PREFIX="32-bitcount(compl32(netmask))
# range calculations:
# ipcalc <ip> <netmask> <start> <num>
diff --git a/package/base-files/files/etc/config/network b/package/base-files/files/etc/config/network
index a35fd2ef9..87b124aa3 100644
--- a/package/base-files/files/etc/config/network
+++ b/package/base-files/files/etc/config/network
@@ -12,3 +12,11 @@ config interface lan
option proto static
option ipaddr 192.168.1.1
option netmask 255.255.255.0
+ option ip6assign 60
+
+config interface wan6
+ option ifname @wan
+ option proto dhcpv6
+
+config globals globals
+ option ula_prefix auto
diff --git a/package/base-files/files/etc/functions.sh b/package/base-files/files/etc/functions.sh
deleted file mode 120000
index 13b3190e7..000000000
--- a/package/base-files/files/etc/functions.sh
+++ /dev/null
@@ -1 +0,0 @@
-../lib/functions.sh \ No newline at end of file
diff --git a/package/base-files/files/etc/hotplug.d/net/00-sysctl b/package/base-files/files/etc/hotplug.d/net/00-sysctl
new file mode 100644
index 000000000..5d9da8ac0
--- /dev/null
+++ b/package/base-files/files/etc/hotplug.d/net/00-sysctl
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+if [ -f /etc/sysctl.conf ] && [ "$ACTION" = add ]; then
+ sed -ne "/^[[:space:]]*net\..*\.$DEVICENAME\./p" /etc/sysctl.conf | \
+ sysctl -e -p - | logger -t sysctl
+fi
diff --git a/package/base-files/files/etc/hotplug2-init.rules b/package/base-files/files/etc/hotplug2-init.rules
deleted file mode 100644
index f01169776..000000000
--- a/package/base-files/files/etc/hotplug2-init.rules
+++ /dev/null
@@ -1,5 +0,0 @@
-$include /etc/hotplug2-common.rules
-
-SUBSYSTEM == button {
- exec kill -USR1 1
-}
diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot
index 43837a80f..4f35eac7b 100755
--- a/package/base-files/files/etc/init.d/boot
+++ b/package/base-files/files/etc/init.d/boot
@@ -24,27 +24,6 @@ system_config() {
# apply timezone to kernel
date -k
-
- if [ -x /sbin/syslogd ]; then
- local args log_ip log_size log_port log_type log_file
- config_get log_ip "$cfg" log_ip
- config_get log_size "$cfg" log_size 16
- config_get log_port "$cfg" log_port 514
- config_get log_type "$cfg" log_type circular
- config_get log_file "$cfg" log_file "/var/log/messages"
- args="${log_ip:+-L -R ${log_ip}:${log_port}} ${conloglevel:+-l $conloglevel}"
- if [ "$log_type" = "file" ]; then
- args="$args -s $log_size -O $log_file -S"
- else
- args="$args -C${log_size}"
- fi
- service_start /sbin/syslogd $args
- fi
- if [ -x /sbin/klogd ]; then
- config_get klogconloglevel "$cfg" klogconloglevel
- args="${klogconloglevel:+-c $klogconloglevel}"
- service_start /sbin/klogd $args
- fi
}
apply_uci_config() {
@@ -66,10 +45,14 @@ start() {
touch /var/log/lastlog
touch /tmp/resolv.conf.auto
ln -sf /tmp/resolv.conf.auto /tmp/resolv.conf
- grep -q debugfs /proc/filesystems && mount -t debugfs debugfs /sys/kernel/debug
+ grep -q debugfs /proc/filesystems && mount -o noatime -t debugfs debugfs /sys/kernel/debug
[ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
- load_modules /etc/modules.d/*
+ if [ -f /sbin/kmodloader ]; then
+ /sbin/kmodloader
+ else
+ load_modules /etc/modules.d/*
+ fi
# allow wifi modules time to settle
sleep 1
@@ -84,20 +67,16 @@ start() {
config_load system
config_foreach system_config system
- killall -q hotplug2
- [ -x /sbin/hotplug2 ] && /sbin/hotplug2 --override --persistent \
- --set-rules-file /etc/hotplug2.rules \
- --set-coldplug-cmd /sbin/udevtrigger \
- --max-children 1 >/dev/null 2>&1 &
-
# create /dev/root if it doesn't exist
[ -e /dev/root -o -h /dev/root ] || {
rootdev=$(awk 'BEGIN { RS=" "; FS="="; } $1 == "root" { print $2 }' < /proc/cmdline)
[ -n "$rootdev" ] && ln -s "$rootdev" /dev/root
}
-}
-stop() {
- service_stop /sbin/klogd
- service_stop /sbin/syslogd
+ # early sysctl to avoid networking races
+ if [ -d /proc/sys/net/ipv6/conf ]; then
+ for i in /proc/sys/net/ipv6/conf/*/accept_ra; do
+ echo 0 > $i
+ done
+ fi
}
diff --git a/package/base-files/files/etc/init.d/done b/package/base-files/files/etc/init.d/done
index 827866912..8040766dc 100755
--- a/package/base-files/files/etc/init.d/done
+++ b/package/base-files/files/etc/init.d/done
@@ -5,7 +5,7 @@ START=95
boot() {
[ -d /tmp/root ] && {
lock /tmp/.switch2jffs
- firstboot switch2jffs
+ switch2jffs
lock -u /tmp/.switch2jffs
}
diff --git a/package/base-files/files/etc/init.d/rcS b/package/base-files/files/etc/init.d/rcS
index 3ec9bfef6..9599bbf32 100755
--- a/package/base-files/files/etc/init.d/rcS
+++ b/package/base-files/files/etc/init.d/rcS
@@ -1,26 +1,9 @@
#!/bin/sh
# Copyright (C) 2006 OpenWrt.org
-run_scripts() {
- for i in /etc/rc.d/$1*; do
- [ -x $i ] && $i $2 2>&1
- done | $LOGGER
-}
-
-system_config() {
- config_get_bool foreground $1 foreground 0
-}
-
LOGGER="cat"
-[ -x /usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit"
-
-. /lib/functions.sh
-
-config_load system
-config_foreach system_config system
+[ -x /usr/bin/logger ] && LOGGER="logger -p 6 -t sysinit"
-if [ "$1" = "S" -a "$foreground" != "1" ]; then
- run_scripts "$1" "$2" &
-else
- run_scripts "$1" "$2"
-fi
+for i in /etc/rc.d/$1*; do
+ [ -x $i ] && $i $2 2>&1
+done | $LOGGER
diff --git a/package/base-files/files/etc/init.d/sysctl b/package/base-files/files/etc/init.d/sysctl
index 239779055..3480d6641 100755
--- a/package/base-files/files/etc/init.d/sysctl
+++ b/package/base-files/files/etc/init.d/sysctl
@@ -1,7 +1,7 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
-START=99
+START=11
start() {
[ -f /etc/sysctl.conf ] && sysctl -p -e >&-
}
diff --git a/package/base-files/files/etc/init.d/usb b/package/base-files/files/etc/init.d/usb
index 7b443b651..43cdfd9a9 100755
--- a/package/base-files/files/etc/init.d/usb
+++ b/package/base-files/files/etc/init.d/usb
@@ -4,6 +4,6 @@
START=39
start() {
[ -d /proc/bus/usb ] && {
- /bin/mount -t usbfs none /proc/bus/usb
+ mount -o noatime -t usbfs none /proc/bus/usb
}
}
diff --git a/package/base-files/files/etc/init.d/watchdog b/package/base-files/files/etc/init.d/watchdog
deleted file mode 100755
index 299c89142..000000000
--- a/package/base-files/files/etc/init.d/watchdog
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh /etc/rc.common
-# Copyright (C) 2008-2011 OpenWrt.org
-
-START=97
-
-start() {
- [ -c /dev/watchdog ] || return 1
- [ -x /sbin/watchdog ] || return 1
- service_start /sbin/watchdog -t 5 /dev/watchdog
-}
-stop() {
- service_stop /sbin/watchdog
-}
diff --git a/package/base-files/files/etc/inittab b/package/base-files/files/etc/inittab
index ca90fd8a2..781718593 100644
--- a/package/base-files/files/etc/inittab
+++ b/package/base-files/files/etc/inittab
@@ -1,4 +1,3 @@
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
-ttyS0::askfirst:/bin/ash --login
-tty1::askfirst:/bin/ash --login
+::askconsole:/bin/ash --login
diff --git a/package/base-files/files/etc/preinit b/package/base-files/files/etc/preinit
index 0fdfa8cf8..ff26f96d6 100755
--- a/package/base-files/files/etc/preinit
+++ b/package/base-files/files/etc/preinit
@@ -2,6 +2,8 @@
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
+[ -z "$PREINIT" ] && exec /sbin/init
+
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
pi_ifname=
@@ -22,7 +24,6 @@ pi_init_path="/bin:/sbin:/usr/bin:/usr/sbin"
pi_init_cmd="/sbin/init"
. /lib/functions.sh
-. /lib/functions/boot.sh
boot_hook_init preinit_essential
boot_hook_init preinit_main
diff --git a/package/base-files/files/etc/rc.button/failsafe b/package/base-files/files/etc/rc.button/failsafe
new file mode 100755
index 000000000..dcdf7de80
--- /dev/null
+++ b/package/base-files/files/etc/rc.button/failsafe
@@ -0,0 +1,2 @@
+#!/bin/sh
+touch /tmp/failsafe_button
diff --git a/package/base-files/files/etc/rc.button/reset b/package/base-files/files/etc/rc.button/reset
new file mode 100755
index 000000000..229b503a6
--- /dev/null
+++ b/package/base-files/files/etc/rc.button/reset
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+[ "${ACTION}" = "released" ] || exit 0
+
+. /lib/functions.sh
+
+logger "$BUTTON pressed for $SEEN seconds"
+
+if [ "$SEEN" -lt 1 ]
+then
+ echo "REBOOT" > /dev/console
+ sync
+ reboot
+elif [ "$SEEN" -gt 5 ]
+then
+ echo "FACTORY RESET" > /dev/console
+ jffs2reset -y && reboot &
+fi
diff --git a/package/base-files/files/etc/rc.button/rfkill b/package/base-files/files/etc/rc.button/rfkill
new file mode 100755
index 000000000..7a8cfe91b
--- /dev/null
+++ b/package/base-files/files/etc/rc.button/rfkill
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+[ "${ACTION}" = "released" ] || exit 0
+
+. /lib/functions.sh
+
+local rfkill_state=0
+
+wifi_rfkill_set() {
+ uci set wireless.$1.disabled=$rfkill_state
+}
+
+wifi_rfkill_check() {
+ local disabled
+ config_get disabled $1 disabled
+ [ "$disabled" = "1" ] || rfkill_state=1
+}
+
+config_load wireless
+config_foreach wifi_rfkill_check wifi-device
+config_foreach wifi_rfkill_set wifi-device
+uci commit wireless
+wifi up
diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common
index fa2df6cd2..78e2dd494 100755
--- a/package/base-files/files/etc/rc.common
+++ b/package/base-files/files/etc/rc.common
@@ -75,10 +75,41 @@ $EXTRA_HELP
EOF
}
+# for procd
+start_service() {
+ return 0
+}
+
+stop_service() {
+ return 0
+}
+
${INIT_TRACE:+set -x}
. "$initscript"
+[ -n "$USE_PROCD" ] && {
+ . $IPKG_INSTROOT/lib/functions/procd.sh
+
+ rc_procd() {
+ procd_open_service "$(basename "$initscript")" "$initscript"
+ "$@"
+ procd_close_service
+ }
+
+ start() {
+ rc_procd start_service "$@"
+ }
+
+ stop() {
+ procd_kill "$(basename "$initscript")" "$1"
+ }
+
+ reload() {
+ start
+ }
+}
+
ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
list_contains ALL_COMMANDS "$action" || action=help
[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
diff --git a/package/base-files/files/etc/sysctl.conf b/package/base-files/files/etc/sysctl.conf
index ef3db4ec5..890e77af8 100644
--- a/package/base-files/files/etc/sysctl.conf
+++ b/package/base-files/files/etc/sysctl.conf
@@ -12,6 +12,9 @@ net.ipv4.tcp_timestamps=1
net.ipv4.tcp_sack=1
net.ipv4.tcp_dsack=1
+net.ipv6.conf.default.forwarding=2
+net.ipv6.conf.all.forwarding=2
+
net.netfilter.nf_conntrack_acct=1
net.netfilter.nf_conntrack_checksum=0
net.netfilter.nf_conntrack_max=16384
diff --git a/package/base-files/files/etc/uci-defaults/migrate-shadow b/package/base-files/files/etc/uci-defaults/10_migrate-shadow
index b7ea5718c..b7ea5718c 100644
--- a/package/base-files/files/etc/uci-defaults/migrate-shadow
+++ b/package/base-files/files/etc/uci-defaults/10_migrate-shadow
diff --git a/package/base-files/files/etc/uci-defaults/migrate-sysctl b/package/base-files/files/etc/uci-defaults/11_migrate-sysctl
index b3796a4d2..b3796a4d2 100644
--- a/package/base-files/files/etc/uci-defaults/migrate-sysctl
+++ b/package/base-files/files/etc/uci-defaults/11_migrate-sysctl
diff --git a/package/base-files/files/etc/uci-defaults/12_network-generate-ula b/package/base-files/files/etc/uci-defaults/12_network-generate-ula
new file mode 100644
index 000000000..f3e493145
--- /dev/null
+++ b/package/base-files/files/etc/uci-defaults/12_network-generate-ula
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+[ "$(uci get network.globals.ula_prefix)" != "auto" ] && exit 0
+# Sometimes results are empty, therefore try until it works...
+local r1 r2 r3
+while [ -z "$r1" -o -z "$r2" -o -z "$r3" ]; do
+ r1=$(printf "%02x" $(($(</dev/urandom tr -dc 0-9 | dd bs=9 count=1) % 256)))
+ r2=$(printf "%01x" $(($(</dev/urandom tr -dc 0-9 | dd bs=9 count=1) % 65536)))
+ r3=$(printf "%01x" $(($(</dev/urandom tr -dc 0-9 | dd bs=9 count=1) % 65536)))
+done
+
+uci -q batch <<-EOF >/dev/null
+ set network.globals.ula_prefix=fd$r1:$r2:$r3::/48
+ commit network
+EOF
+
+exit 0
+
diff --git a/package/base-files/files/lib/firstboot/05_firstboot_skip b/package/base-files/files/lib/firstboot/05_firstboot_skip
deleted file mode 100644
index 5f44df621..000000000
--- a/package/base-files/files/lib/firstboot/05_firstboot_skip
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-check_skip() {
- if [ "$firstboot_skip_next" = "true" ]; then
- return 0
- else
- return 1
- fi
-}
-
diff --git a/package/base-files/files/lib/firstboot/10_determine_parts b/package/base-files/files/lib/firstboot/10_determine_parts
deleted file mode 100644
index 3f56e32a8..000000000
--- a/package/base-files/files/lib/firstboot/10_determine_parts
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/sh
-
-set_mtd_part() {
- partname="rootfs_data"
- mtdpart="$(find_mtd_part $partname)"
-}
-
-set_rom_part() {
- rom=$(awk '/squashfs/ {print $2}' /proc/mounts)
-}
-
-set_jffs_part() {
- jffs=$(awk '/jffs2/ {print $2}' /proc/mounts)
-}
-
-determine_mtd_part() {
- set_mtd_part
- if [ -z "$mtdpart" ]; then
- echo "MTD partition not found."
- exit 1
- fi
-}
-
-determine_rom_part() {
- check_skip || {
- set_rom_part
- if [ -z "$rom" ]; then
- echo "You do not have a squashfs partition; aborting"
- echo "(firstboot cannot be run on jffs2 based firmwares)"
- exit 1
- fi
- }
-}
-
-determine_jffs2_part() {
- check_skip || {
- set_jffs_part
- }
-}
-
-boot_hook_add switch2jffs determine_mtd_part
-boot_hook_add jffs2reset determine_mtd_part
-boot_hook_add switch2jffs determine_rom_part
-boot_hook_add jffs2reset determine_rom_part
-boot_hook_add switch2jffs determine_jffs2_part
-boot_hook_add jffs2reset determine_jffs2_part
diff --git a/package/base-files/files/lib/firstboot/10_no_fo_clear_overlay b/package/base-files/files/lib/firstboot/10_no_fo_clear_overlay
deleted file mode 100644
index 8a7d9b066..000000000
--- a/package/base-files/files/lib/firstboot/10_no_fo_clear_overlay
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-no_fo_clear_overlay() {
- # switch back to squashfs temporarily
- pivot /rom /mnt
-
- # get rid of the old overlay
- umount -l /mnt
-
- # another umount to get rid of the bind from /tmp/root
- umount -l /mnt
-}
-
-boot_hook_add no_fo no_fo_clear_overlay
diff --git a/package/base-files/files/lib/firstboot/10_reset_has_mini_fo b/package/base-files/files/lib/firstboot/10_reset_has_mini_fo
deleted file mode 100644
index 4e285840a..000000000
--- a/package/base-files/files/lib/firstboot/10_reset_has_mini_fo
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-reset_check_for_overlay() {
- if grep -qE '(mini_fo|overlay)' /proc/filesystems; then
- reset_has_fo=true
- fi
-}
-
-boot_hook_add jffs2reset reset_check_for_overlay
diff --git a/package/base-files/files/lib/firstboot/20_has_mini_fo b/package/base-files/files/lib/firstboot/20_has_mini_fo
deleted file mode 100644
index 8ca6a4fe5..000000000
--- a/package/base-files/files/lib/firstboot/20_has_mini_fo
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-check_for_overlay() {
- if ! grep -qE '(mini_fo|overlay)' /proc/filesystems; then
- boot_run_hook no_fo
- exit 1
- fi
-}
-
-boot_hook_add switch2jffs check_for_overlay
diff --git a/package/base-files/files/lib/firstboot/20_no_fo_mount_jffs b/package/base-files/files/lib/firstboot/20_no_fo_mount_jffs
deleted file mode 100644
index 8a1d4e06d..000000000
--- a/package/base-files/files/lib/firstboot/20_no_fo_mount_jffs
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-no_fo_mount_jffs() {
- # initialize jffs2
- mount "$mtdpart" /overlay -t jffs2 || exit
-
- # workaround to ensure that union can attach properly
- sync
- ls /overlay >/dev/null
-}
-
-boot_hook_add no_fo no_fo_mount_jffs
diff --git a/package/base-files/files/lib/firstboot/20_reset_clear_jffs b/package/base-files/files/lib/firstboot/20_reset_clear_jffs
deleted file mode 100644
index a3cd24fe9..000000000
--- a/package/base-files/files/lib/firstboot/20_reset_clear_jffs
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-reset_clear_jffs() {
- [ "$reset_has_fo" = "true" ] && {
- rm -rf $jffs/* 2>&-
- mount -o remount $jffs / 2>&-
- exit 0
- } || reset_has_fo=false
-}
-
-boot_hook_add jffs2reset reset_clear_jffs
diff --git a/package/base-files/files/lib/firstboot/30_is_rootfs_mounted b/package/base-files/files/lib/firstboot/30_is_rootfs_mounted
deleted file mode 100644
index e2ba01d50..000000000
--- a/package/base-files/files/lib/firstboot/30_is_rootfs_mounted
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-skip_if_rootfs_mounted() {
- mount "$mtdpart" /rom/overlay -t jffs2 || exit
-}
-
-boot_hook_add switch2jffs skip_if_rootfs_mounted
diff --git a/package/base-files/files/lib/firstboot/30_no_fo_pivot b/package/base-files/files/lib/firstboot/30_no_fo_pivot
deleted file mode 100644
index b5c2601ee..000000000
--- a/package/base-files/files/lib/firstboot/30_no_fo_pivot
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-no_fo_pivot() {
- # switch to the new (empty) jffs2
- fopivot /overlay /rom 1
-}
-
-boot_hook_add no_fo no_fo_pivot
diff --git a/package/base-files/files/lib/firstboot/30_reset_copy_rom b/package/base-files/files/lib/firstboot/30_reset_copy_rom
deleted file mode 100644
index d91c68947..000000000
--- a/package/base-files/files/lib/firstboot/30_reset_copy_rom
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-reset_copy_rom() {
- [ "$reset_has_fo" != "true" ] && {
- dupe $jffs $rom
- exit 0
- }
-}
-
-boot_hook_add jffs2reset reset_copy_rom
diff --git a/package/base-files/files/lib/firstboot/40_copy_ramoverlay b/package/base-files/files/lib/firstboot/40_copy_ramoverlay
deleted file mode 100644
index 39c2edacb..000000000
--- a/package/base-files/files/lib/firstboot/40_copy_ramoverlay
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-copy_ramoverlay() {
- # try to avoid fs changing while copying
- mount -o remount,ro none / 2>&-
- # copy ramoverlay to jffs2
- echo -n "copying files ... "
- cp -a /tmp/root/* /rom/overlay 2>&-
- echo "done"
-}
-
-boot_hook_add switch2jffs copy_ramoverlay
diff --git a/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay b/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay
deleted file mode 100644
index ced7c1b66..000000000
--- a/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-no_fo_copy_ramoverlay() {
- # copy ramoverlay to jffs2, must be done after switching
- # to the new rootfs to avoid creating opaque directories
- echo -n "copying files ... "
- cp -a /tmp/root/* / >/dev/null 2>&1
- sync
-}
-
-boot_hook_add no_fo no_fo_ramoverlay
diff --git a/package/base-files/files/lib/firstboot/50_pivot b/package/base-files/files/lib/firstboot/50_pivot
deleted file mode 100644
index 53801d7a8..000000000
--- a/package/base-files/files/lib/firstboot/50_pivot
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-with_fo_pivot() {
- # switch back to squashfs (temporarily)
- # and park the ramdisk ontop of /tmp/root
- pivot /rom /mnt
- mount -o move /mnt /tmp/root
-
- # /overlay is the overlay
- # /rom is the readonly
- fopivot /overlay /rom
-}
-
-boot_hook_add switch2jffs with_fo_pivot
diff --git a/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup b/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup
deleted file mode 100644
index 6dedcb1e8..000000000
--- a/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-no_fo_cleanup() {
- echo "done"
- umount -l /overlay
- umount -l /tmp/root
- exit 0
-}
-
-boot_hook_add no_fo no_fo_cleanup
diff --git a/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup b/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup
deleted file mode 100644
index 0181b39d4..000000000
--- a/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-with_fo_cleanup() {
- # try to get rid of /tmp/root
- # this will almost always fail
- umount /tmp/root 2>&-
- grep -q overlay /proc/filesystems && {
- cd /
- (
- cd /overlay
- find -type l
- ) | while read FILE; do
- [ -z "$FILE" ] && break
- if ls -la "$FILE" 2>&- | grep -q '(overlay-whiteout)'; then
- rm -f "$FILE"
- fi
- done
- }
- exit 0
-}
-
-boot_hook_add switch2jffs with_fo_cleanup
diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
index b3a3885f2..f51bfea45 100755
--- a/package/base-files/files/lib/functions.sh
+++ b/package/base-files/files/lib/functions.sh
@@ -1,14 +1,12 @@
#!/bin/sh
-# Copyright (C) 2006-2011 OpenWrt.org
+# Copyright (C) 2006-2013 OpenWrt.org
# Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
+# Copyright (C) 2010 Vertical Communications
debug () {
${DEBUG:-:} "$@"
}
-mount() {
- busybox mount "$@"
-}
# newline
N="
@@ -200,7 +198,7 @@ config_list_foreach() {
[ -z "$len" ] && return 0
while [ $c -le "$len" ]; do
config_get val "${section}" "${option}_ITEM$c"
- eval "$function \"\$val\" \"$@\""
+ eval "$function \"\$val\" \"\$@\""
c="$(($c + 1))"
done
}
@@ -220,13 +218,85 @@ include() {
done
}
-find_mtd_part() {
+find_mtd_index() {
local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
+ local INDEX="${PART##mtd}"
+
+ echo ${INDEX}
+}
+
+find_mtd_part() {
+ local INDEX=$(find_mtd_index "$1")
local PREFIX=/dev/mtdblock
- PART="${PART##mtd}"
[ -d /dev/mtdblock ] && PREFIX=/dev/mtdblock/
- echo "${PART:+$PREFIX$PART}"
+ echo "${INDEX:+$PREFIX$INDEX}"
+}
+
+find_mtd_chardev() {
+ local INDEX=$(find_mtd_index "$1")
+ local PREFIX=/dev/mtd
+
+ [ -d /dev/mtd ] && PREFIX=/dev/mtd/
+ echo "${INDEX:+$PREFIX$INDEX}"
+}
+
+mtd_get_mac_ascii()
+{
+ local mtdname="$1"
+ local key="$2"
+ local part
+ local mac_dirty
+
+ . /lib/functions.sh
+
+ part=$(find_mtd_part "$mtdname")
+ if [ -z "$part" ]; then
+ echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2
+ return
+ fi
+
+ mac_dirty=$(strings "$part" | sed -n 's/'"$key"'=//p')
+ # "canonicalize" mac
+ printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${mac_dirty//:/ 0x}
+}
+
+mtd_get_mac_binary() {
+ local mtdname="$1"
+ local offset="$2"
+ local part
+
+ part=$(find_mtd_part "$mtdname")
+ if [ -z "$part" ]; then
+ echo "mtd_get_mac_binary: partition $mtdname not found!" >&2
+ return
+ fi
+
+ dd bs=1 skip=$offset count=6 if=$part 2>/dev/null | hexdump -v -n 6 -e '5/1 "%02x:" 1/1 "%02x"'
+}
+
+macaddr_add() {
+ local mac=$1
+ local val=$2
+ local oui=${mac%:*:*:*}
+ local nic=${mac#*:*:*:}
+
+ nic=$(printf "%06x" $((0x${nic//:/} + $val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
+ echo $oui:$nic
+}
+
+macaddr_setbit_la()
+{
+ local mac=$1
+
+ printf "%02x:%s" $((0x${mac%%:*} | 0x02)) ${mac#*:}
+}
+
+macaddr_2bin()
+{
+ local mac=$1
+
+ echo -ne \\x${mac//:/\\x}
}
strtok() { # <string> { <variable> [<separator>] ... }
@@ -337,4 +407,137 @@ pi_include() {
return 0
}
+boot_hook_splice_start() {
+ export -n PI_HOOK_SPLICE=1
+}
+
+boot_hook_splice_finish() {
+ local hook
+ for hook in $PI_STACK_LIST; do
+ local v; eval "v=\${${hook}_splice:+\$${hook}_splice }$hook"
+ export -n "${hook}=${v% }"
+ export -n "${hook}_splice="
+ done
+ export -n PI_HOOK_SPLICE=
+}
+
+boot_hook_init() {
+ local hook="${1}_hook"
+ export -n "PI_STACK_LIST=${PI_STACK_LIST:+$PI_STACK_LIST }$hook"
+ export -n "$hook="
+}
+
+boot_hook_add() {
+ local hook="${1}_hook${PI_HOOK_SPLICE:+_splice}"
+ local func="${2}"
+
+ [ -n "$func" ] && {
+ local v; eval "v=\$$hook"
+ export -n "$hook=${v:+$v }$func"
+ }
+}
+
+boot_hook_shift() {
+ local hook="${1}_hook"
+ local rvar="${2}"
+
+ local v; eval "v=\$$hook"
+ [ -n "$v" ] && {
+ local first="${v%% *}"
+
+ [ "$v" != "${v#* }" ] && \
+ export -n "$hook=${v#* }" || \
+ export -n "$hook="
+
+ export -n "$rvar=$first"
+ return 0
+ }
+
+ return 1
+}
+
+boot_run_hook() {
+ local hook="$1"
+ local func
+
+ while boot_hook_shift "$hook" func; do
+ local ran; eval "ran=\$PI_RAN_$func"
+ [ -n "$ran" ] || {
+ export -n "PI_RAN_$func=1"
+ $func "$1" "$2"
+ }
+ done
+}
+
+jffs2_ready() {
+ mtdpart="$(find_mtd_part rootfs_data)"
+ [ -z "$mtdpart" ] && return 1
+ magic=$(hexdump $mtdpart -n 4 -e '4/1 "%02x"')
+ [ "$magic" != "deadc0de" ]
+}
+
+dupe() { # <new_root> <old_root>
+ cd $1
+ echo -n "creating directories... "
+ {
+ cd $2
+ find . -xdev -type d
+ echo "./dev ./overlay ./mnt ./proc ./tmp"
+ # xdev skips mounted directories
+ cd $1
+ } | xargs mkdir -p
+ echo "done"
+
+ echo -n "setting up symlinks... "
+ for file in $(cd $2; find . -xdev -type f;); do
+ case "$file" in
+ ./rom/note) ;; #nothing
+ ./etc/config*|\
+ ./usr/lib/opkg/info/*) cp -af $2/$file $file;;
+ *) ln -sf /rom/${file#./*} $file;;
+ esac
+ done
+ for file in $(cd $2; find . -xdev -type l;); do
+ cp -af $2/${file#./*} $file
+ done
+ echo "done"
+}
+
+pivot() { # <new_root> <old_root>
+ mount -o noatime,move /proc $1/proc && \
+ pivot_root $1 $1$2 && {
+ mount -o noatime,move $2/dev /dev
+ mount -o noatime,move $2/tmp /tmp
+ mount -o noatime,move $2/sys /sys 2>&-
+ mount -o noatime,move $2/overlay /overlay 2>&-
+ return 0
+ }
+}
+
+fopivot() { # <rw_root> <ro_root> <dupe?>
+ root=$1
+ {
+ if grep -q overlay /proc/filesystems; then
+ mount -o noatime,lowerdir=/,upperdir=$1 -t overlayfs "overlayfs:$1" /mnt && root=/mnt
+ elif grep -q mini_fo /proc/filesystems; then
+ mount -t mini_fo -o noatime,base=/,sto=$1 "mini_fo:$1" /mnt 2>&- && root=/mnt
+ else
+ mount --bind -o noatime / /mnt
+ mount --bind -o noatime,union "$1" /mnt && root=/mnt
+ fi
+ } || {
+ [ "$3" = "1" ] && {
+ mount | grep "on $1 type" 2>&- 1>&- || mount -o noatime,bind $1 $1
+ dupe $1 $rom
+ }
+ }
+ pivot $root $2
+}
+
+ramoverlay() {
+ mkdir -p /tmp/root
+ mount -t tmpfs -o noatime,mode=0755 root /tmp/root
+ fopivot /tmp/root /rom 1
+}
+
[ -z "$IPKG_INSTROOT" -a -f /lib/config/uci.sh ] && . /lib/config/uci.sh
diff --git a/package/base-files/files/lib/functions/boot.sh b/package/base-files/files/lib/functions/boot.sh
deleted file mode 100644
index 8c3f27ba4..000000000
--- a/package/base-files/files/lib/functions/boot.sh
+++ /dev/null
@@ -1,150 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-mount() {
- /bin/busybox mount -o noatime "$@"
-}
-
-boot_hook_splice_start() {
- export -n PI_HOOK_SPLICE=1
-}
-
-boot_hook_splice_finish() {
- local hook
- for hook in $PI_STACK_LIST; do
- local v; eval "v=\${${hook}_splice:+\$${hook}_splice }$hook"
- export -n "${hook}=${v% }"
- export -n "${hook}_splice="
- done
- export -n PI_HOOK_SPLICE=
-}
-
-boot_hook_init() {
- local hook="${1}_hook"
- export -n "PI_STACK_LIST=${PI_STACK_LIST:+$PI_STACK_LIST }$hook"
- export -n "$hook="
-}
-
-boot_hook_add() {
- local hook="${1}_hook${PI_HOOK_SPLICE:+_splice}"
- local func="${2}"
-
- [ -n "$func" ] && {
- local v; eval "v=\$$hook"
- export -n "$hook=${v:+$v }$func"
- }
-}
-
-boot_hook_shift() {
- local hook="${1}_hook"
- local rvar="${2}"
-
- local v; eval "v=\$$hook"
- [ -n "$v" ] && {
- local first="${v%% *}"
-
- [ "$v" != "${v#* }" ] && \
- export -n "$hook=${v#* }" || \
- export -n "$hook="
-
- export -n "$rvar=$first"
- return 0
- }
-
- return 1
-}
-
-boot_run_hook() {
- local hook="$1"
- local func
-
- while boot_hook_shift "$hook" func; do
- local ran; eval "ran=\$PI_RAN_$func"
- [ -n "$ran" ] || {
- export -n "PI_RAN_$func=1"
- $func "$1" "$2"
- }
- done
-}
-
-find_mtd_part() {
- local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
- local PREFIX=/dev/mtdblock
-
- PART="${PART##mtd}"
- [ -d /dev/mtdblock ] && PREFIX=/dev/mtdblock/
- echo "${PART:+$PREFIX$PART}"
-}
-
-jffs2_ready () {
- mtdpart="$(find_mtd_part rootfs_data)"
- [ -z "$mtdpart" ] && return 1
- magic=$(hexdump $mtdpart -n 4 -e '4/1 "%02x"')
- [ "$magic" != "deadc0de" ]
-}
-
-dupe() { # <new_root> <old_root>
- cd $1
- echo -n "creating directories... "
- {
- cd $2
- find . -xdev -type d
- echo "./dev ./overlay ./mnt ./proc ./tmp"
- # xdev skips mounted directories
- cd $1
- } | xargs mkdir -p
- echo "done"
-
- echo -n "setting up symlinks... "
- for file in $(cd $2; find . -xdev -type f;); do
- case "$file" in
- ./rom/note) ;; #nothing
- ./etc/config*|\
- ./usr/lib/opkg/info/*) cp -af $2/$file $file;;
- *) ln -sf /rom/${file#./*} $file;;
- esac
- done
- for file in $(cd $2; find . -xdev -type l;); do
- cp -af $2/${file#./*} $file
- done
- echo "done"
-}
-
-pivot() { # <new_root> <old_root>
- mount -o move /proc $1/proc && \
- pivot_root $1 $1$2 && {
- mount -o move $2/dev /dev
- mount -o move $2/tmp /tmp
- mount -o move $2/sys /sys 2>&-
- mount -o move $2/overlay /overlay 2>&-
- return 0
- }
-}
-
-fopivot() { # <rw_root> <ro_root> <dupe?>
- root=$1
- {
- if grep -q overlay /proc/filesystems; then
- mount -t overlayfs -olowerdir=/,upperdir=$1 "overlayfs:$1" /mnt && root=/mnt
- elif grep -q mini_fo /proc/filesystems; then
- mount -t mini_fo -o base=/,sto=$1 "mini_fo:$1" /mnt 2>&- && root=/mnt
- else
- mount --bind / /mnt
- mount --bind -o union "$1" /mnt && root=/mnt
- fi
- } || {
- [ "$3" = "1" ] && {
- mount | grep "on $1 type" 2>&- 1>&- || mount -o bind $1 $1
- dupe $1 $rom
- }
- }
- pivot $root $2
-}
-
-ramoverlay() {
- mkdir -p /tmp/root
- mount -t tmpfs -o mode=0755 root /tmp/root
- fopivot /tmp/root /rom 1
-}
-
diff --git a/package/base-files/files/lib/functions/leds.sh b/package/base-files/files/lib/functions/leds.sh
new file mode 100644
index 000000000..743c7da78
--- /dev/null
+++ b/package/base-files/files/lib/functions/leds.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+# Copyright (C) 2013 OpenWrt.org
+
+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"
+}
+
+led_on() {
+ led_set_attr $1 "trigger" "none"
+ led_set_attr $1 "brightness" 255
+}
+
+led_off() {
+ led_set_attr $1 "trigger" "none"
+ led_set_attr $1 "brightness" 0
+}
+
+led_morse() {
+ led_set_attr $1 "trigger" "morse"
+ led_set_attr $1 "delay" "$2"
+ led_set_attr $1 "message" "$3"
+}
+
+status_led_set_timer() {
+ led_timer $status_led "$1" "$2"
+ [ -n "$status_led2" ] && led_timer $status_led2 "$1" "$2"
+}
+
+status_led_set_heartbeat() {
+ led_set_attr $status_led "trigger" "heartbeat"
+}
+
+status_led_set_morse() {
+ led_morse $status_led "$1" "$2"
+ [ -n "$status_led2" ] && led_morse $status_led2 "$1" "$2"
+}
+
+status_led_on() {
+ led_on $status_led
+ [ -n "$status_led2" ] && led_on $status_led2
+}
+
+status_led_off() {
+ led_off $status_led
+ [ -n "$status_led2" ] && led_off $status_led2
+}
+
+status_led_blink_slow() {
+ led_timer $status_led 1000 1000
+}
+
+status_led_blink_fast() {
+ led_timer $status_led 100 100
+}
+
+status_led_blink_preinit() {
+ led_timer $status_led 200 200
+}
+
+status_led_blink_failsafe() {
+ led_timer $status_led 50 50
+}
diff --git a/package/base-files/files/lib/functions/network.sh b/package/base-files/files/lib/functions/network.sh
index a4652569b..d86a504bf 100644
--- a/package/base-files/files/lib/functions/network.sh
+++ b/package/base-files/files/lib/functions/network.sh
@@ -1,125 +1,281 @@
. /usr/share/libubox/jshn.sh
-__network_ipaddr()
+__network_set_cache()
{
- local __var="$1"
- local __iface="$2"
- local __family="$3"
- local __prefix="${4:-0}"
+ if [ -n "$3" ]; then
+ eval "export -- __NETWORK_CV_$1='$3'"
+ __NETWORK_CACHE="${__NETWORK_CACHE:+$__NETWORK_CACHE }__NETWORK_CV_$1"
+ elif json_get_var "__NETWORK_CV_$1" "$2"; then
+ __NETWORK_CACHE="${__NETWORK_CACHE:+$__NETWORK_CACHE }__NETWORK_CV_$1"
+ fi
+}
- local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)"
+__network_export()
+{
+ local __v="__NETWORK_CV_$2"
+ eval "export -- \"$1=\${$__v:+\$$__v$3}\"; [ -n \"\${$__v+x}\" ]"
+}
+
+__network_parse_ifstatus()
+{
+ local __iface="$1"
+ local __key="${__iface}"
+ local __tmp
+ local __old_ns
- json_load "${__tmp:-{}}"
- json_get_type __tmp "ipv${__family}_address"
+ __network_export __tmp "${__key}__parsed" && return 0
+ __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)"
+ [ -n "$__tmp" ] || return 1
- if [ "$__tmp" = array ]; then
+ json_set_namespace "network" __old_ns
+ json_load "$__tmp"
- json_select "ipv${__family}_address"
- json_get_type __tmp 1
+ __network_set_cache "${__key}__parsed" "" "1"
- if [ "$__tmp" = object ]; then
+ for __tmp in "" "_inactive"; do
- json_select 1
- json_get_var $__var address
+ __key="${__key}${__tmp}"
- [ $__prefix -gt 0 ] && {
- json_get_var __tmp mask
- eval "export -- \"$__var=\${$__var}/$__tmp\""
- }
+ # parse addresses
+ local __family
+ for __family in 4 6; do
+ if json_is_a "ipv${__family}_address" array; then
- return 0
+ json_select "ipv${__family}_address"
+
+ if json_is_a 1 object; then
+
+ json_select 1
+ __network_set_cache "${__key}_address${__family}" address
+ __network_set_cache "${__key}_mask${__family}" mask
+ json_select ".."
+
+ fi
+
+ json_select ".."
+
+ fi
+ done
+
+ # parse prefixes
+ if json_is_a "ipv6_prefix" array; then
+ json_select "ipv6_prefix"
+
+ if json_is_a 1 object; then
+ json_select 1
+ __network_set_cache "${__key}_prefix6_address" address
+ __network_set_cache "${__key}_prefix6_mask" mask
+ json_select ".."
+ fi
+
+ json_select ".."
fi
- fi
- return 1
-}
+ # parse routes
+ if json_is_a route array; then
-network_get_ipaddr() { __network_ipaddr "$1" "$2" 4 0; }
-network_get_ipaddr6() { __network_ipaddr "$1" "$2" 6 0; }
+ json_select "route"
-network_get_subnet() { __network_ipaddr "$1" "$2" 4 1; }
-network_get_subnet6() { __network_ipaddr "$1" "$2" 6 1; }
+ local __idx=1
+ while json_is_a "$__idx" object; do
+ json_select "$((__idx++))"
+ json_get_var __tmp table
-__network_gateway()
+ if [ -z "$__tmp" ]; then
+ json_get_var __tmp target
+
+ case "${__tmp}" in
+ 0.0.0.0)
+ __network_set_cache "${__key}_gateway4" nexthop
+ ;;
+ ::)
+ __network_set_cache "${__key}_gateway6" nexthop
+ ;;
+ esac
+ fi
+
+ json_select ".."
+
+ done
+
+ json_select ".."
+
+ fi
+
+ # parse dns info
+ local __field
+ for __field in "dns_server" "dns_search"; do
+ if json_is_a "$__field" array; then
+
+ json_select "$__field"
+
+ local __idx=1
+ local __dns=""
+
+ while json_is_a "$__idx" string; do
+
+ json_get_var __tmp "$((__idx++))"
+ __dns="${__dns:+$__dns }$__tmp"
+
+ done
+
+ json_select ".."
+
+ if [ -n "$__dns" ]; then
+ __network_set_cache "${__key}_${__field}" "" "$__dns"
+ fi
+ fi
+ done
+
+ # parse up state, device and physdev
+ for __field in "up" "l3_device" "device"; do
+ if json_get_type __tmp "$__field"; then
+ __network_set_cache "${__key}_${__field}" "$__field"
+ fi
+ done
+
+ # descend into inactive table
+ json_is_a "inactive" object && json_select "inactive"
+
+ done
+
+ json_cleanup
+ json_set_namespace "$__old_ns"
+
+ return 0
+}
+
+
+__network_ipaddr()
{
local __var="$1"
local __iface="$2"
local __family="$3"
+ local __prefix="$4"
+ local __tmp
- local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)"
- local __idx=1
+ __network_parse_ifstatus "$__iface" || return 1
- json_load "${__tmp:-{}}"
+ if [ $__prefix -eq 1 ]; then
+ __network_export __tmp "${__iface}_mask${__family}" && \
+ __network_export "$__var" "${__iface}_address${__family}" "/$__tmp"
+ return $?
+ fi
- if json_get_type __tmp route && [ "$__tmp" = array ]; then
+ __network_export "$__var" "${__iface}_address${__family}"
+ return $?
- json_select route
+}
- while json_get_type __tmp "$__idx" && [ "$__tmp" = object ]; do
+# determine IPv4 address of given logical interface
+# 1: destination variable
+# 2: interface
+network_get_ipaddr() { __network_ipaddr "$1" "$2" 4 0; }
- json_select "$((__idx++))"
- json_get_var __tmp target
+# determine IPv6 address of given logical interface
+# 1: destination variable
+# 2: interface
+network_get_ipaddr6() { __network_ipaddr "$1" "$2" 6 0; }
- case "${__family}/${__tmp}" in
- 4/0.0.0.0|6/::)
- json_get_var "$__var" nexthop
- return $?
- ;;
- esac
+# determine IPv4 subnet of given logical interface
+# 1: destination variable
+# 2: interface
+network_get_subnet() { __network_ipaddr "$1" "$2" 4 1; }
- json_select ".."
+# determine IPv6 subnet of given logical interface
+# 1: destination variable
+# 2: interface
+network_get_subnet6() { __network_ipaddr "$1" "$2" 6 1; }
- done
- fi
+# determine IPv6 prefix
+network_get_prefix6() {
+ local __var="$1"
+ local __iface="$2"
+ local __address
+ local __mask
- return 1
+ __network_parse_ifstatus "$__iface" || return 1
+ __network_export __mask "${__iface}_prefix6_mask" || return 1
+ __network_export "$__var" "${__iface}_prefix6_address" "/$__mask"
+ return $?
}
-network_get_gateway() { __network_gateway "$1" "$2" 4; }
-network_get_gateway6() { __network_gateway "$1" "$2" 6; }
-
-__network_dns() {
+__network_gateway()
+{
local __var="$1"
local __iface="$2"
- local __field="$3"
+ local __family="$3"
+ local __inactive="$4"
- local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)"
- local __dns=""
- local __idx=1
+ __network_parse_ifstatus "$__iface" || return 1
- json_load "${__tmp:-{}}"
+ if [ "$__inactive" = 1 -o "$__inactive" = "true" ]; then
+ __network_export "$__var" "${__iface}_inactive_gateway${__family}" && \
+ return 0
+ fi
- if json_get_type __tmp "$__field" && [ "$__tmp" = array ]; then
+ __network_export "$__var" "${__iface}_gateway${__family}"
+ return $?
+}
- json_select "$__field"
+# determine IPv4 gateway of given logical interface
+# 1: destination variable
+# 2: interface
+# 3: consider inactive gateway if "true" (optional)
+network_get_gateway() { __network_gateway "$1" "$2" 4 "${3:-0}"; }
- while json_get_type __tmp "$__idx" && [ "$__tmp" = string ]; do
+# determine IPv6 gateway of given logical interface
+# 1: destination variable
+# 2: interface
+# 3: consider inactive gateway if "true" (optional)
+network_get_gateway6() { __network_gateway "$1" "$2" 6 "${3:-0}"; }
- json_get_var __tmp "$((__idx++))"
- __dns="${__dns:+$__dns }$__tmp"
- done
+__network_dns() {
+ local __var="$1"
+ local __iface="$2"
+ local __field="$3"
+ local __inactive="$4"
+
+ __network_parse_ifstatus "$__iface" || return 1
+
+ if [ "$__inactive" = 1 -o "$__inactive" = "true" ]; then
+ __network_export "$__var" "${__iface}_inactive_${__field}" && \
+ return 0
fi
- eval "export -- \"$__var=$__dns\""
- [ -n "$__dns" ]
+ __network_export "$__var" "${__iface}_${__field}"
+ return $?
}
-network_get_dnsserver() { __network_dns "$1" "$2" dns_server; }
-network_get_dnssearch() { __network_dns "$1" "$2" dns_search; }
+# determine the DNS servers of the given logical interface
+# 1: destination variable
+# 2: interface
+# 3: consider inactive servers if "true" (optional)
+network_get_dnsserver() { __network_dns "$1" "$2" dns_server "${3:-0}"; }
+
+# determine the domains of the given logical interface
+# 1: destination variable
+# 2: interface
+# 3: consider inactive domains if "true" (optional)
+network_get_dnssearch() { __network_dns "$1" "$2" dns_search "${3:-0}"; }
-__network_wan() {
+__network_wan()
+{
local __var="$1"
local __family="$2"
+ local __inactive="$3"
local __iface
for __iface in $(ubus list | sed -ne 's/^network\.interface\.//p'); do
- if __network_gateway "$__var" "$__iface" "$__family"; then
- eval "export -- \"$__var=$__iface\""
- return 0
+ if [ "$__iface" != loopback ]; then
+ if __network_gateway "$__var" "$__iface" "$__family" "$__inactive"; then
+ eval "export -- \"$__var=$__iface\""
+ return 0
+ fi
fi
done
@@ -127,8 +283,15 @@ __network_wan() {
return 1
}
-network_find_wan() { __network_wan "$1" 4; }
-network_find_wan6() { __network_wan "$1" 6; }
+# find the logical interface which holds the current IPv4 default route
+# 1: destination variable
+# 2: consider inactive default routes if "true" (optional)
+network_find_wan() { __network_wan "$1" 4 "${2:-0}"; }
+
+# find the logical interface which holds the current IPv6 default route
+# 1: destination variable
+# 2: consider inactive dafault routes if "true" (optional)
+network_find_wan6() { __network_wan "$1" 6 "${2:-0}"; }
__network_device()
@@ -137,20 +300,27 @@ __network_device()
local __iface="$2"
local __field="$3"
- local __tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)"
- [ -n "$__tmp" ] || return 1
-
- json_load "$__tmp"
- json_get_var "$__var" "$__field"
+ __network_parse_ifstatus "$__iface" || return 1
+ __network_export "$__var" "${__iface}_${__field}"
+ return $?
}
+# test whether the given logical interface is running
+# 1: interface
network_is_up()
{
local __up
__network_device __up "$1" up && [ $__up -eq 1 ]
}
+# determine the layer 3 linux network device of the given logical interface
+# 1: destination variable
+# 2: interface
network_get_device() { __network_device "$1" "$2" l3_device; }
+
+# determine the layer 2 linux network device of the given logical interface
+# 1: destination variable
+# 2: interface
network_get_physdev() { __network_device "$1" "$2" device; }
@@ -166,5 +336,19 @@ __network_defer()
ubus call network.device set_state "$(json_dump)" 2>/dev/null
}
+# defer netifd actions on the given linux network device
+# 1: device name
network_defer_device() { __network_defer "$1" 1; }
+
+# continue netifd actions on the given linux network device
+# 1: device name
network_ready_device() { __network_defer "$1" 0; }
+
+# flush the internal value cache to force re-reading values from ubus
+network_flush_cache()
+{
+ local __tmp
+ for __tmp in $__NETWORK_CACHE __NETWORK_CACHE; do
+ unset "$__tmp"
+ done
+}
diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh
index 477c00cfd..bf6fe1e30 100644
--- a/package/base-files/files/lib/functions/uci-defaults.sh
+++ b/package/base-files/files/lib/functions/uci-defaults.sh
@@ -150,6 +150,8 @@ set network.loopback.ifname='lo'
set network.loopback.proto='static'
set network.loopback.ipaddr='127.0.0.1'
set network.loopback.netmask='255.0.0.0'
+set network.globals='globals'
+set network.globals.ula_prefix='auto'
EOF
}
@@ -174,6 +176,7 @@ set network.lan.type='bridge'
set network.lan.proto='static'
set network.lan.ipaddr='192.168.1.1'
set network.lan.netmask='255.255.255.0'
+set network.lan.ip6assign='60'
EOF
}
@@ -184,6 +187,9 @@ ucidef_set_interface_wan() {
set network.wan='interface'
set network.wan.ifname='$ifname'
set network.wan.proto='dhcp'
+set network.wan6='interface'
+set network.wan6.ifname='@wan'
+set network.wan6.proto='dhcpv6'
EOF
}
diff --git a/package/base-files/files/lib/preinit/05_mount_skip b/package/base-files/files/lib/preinit/05_mount_skip
deleted file mode 100644
index c2b7ee79d..000000000
--- a/package/base-files/files/lib/preinit/05_mount_skip
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-check_skip() {
- if [ "$pi_mount_skip_next" = "true" ]; then
- return 0
- else
- return 1
- fi
-}
-
diff --git a/package/base-files/files/lib/preinit/10_check_for_mtd b/package/base-files/files/lib/preinit/10_check_for_mtd
deleted file mode 100644
index 66f185e1a..000000000
--- a/package/base-files/files/lib/preinit/10_check_for_mtd
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-mount_no_mtd() {
- mtd unlock rootfs
- mount -o remount,rw /dev/root /
-}
-
-check_for_mtd() {
- check_skip || {
- grep -qs rootfs_data /proc/mtd || {
- mount_no_mtd && pi_mount_skip_next=true
- }
- }
-}
-
-boot_hook_add preinit_mount_root check_for_mtd
-
diff --git a/package/base-files/files/lib/preinit/10_essential_fs b/package/base-files/files/lib/preinit/10_essential_fs
deleted file mode 100644
index 5d979fd49..000000000
--- a/package/base-files/files/lib/preinit/10_essential_fs
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-do_mount_procfs() {
- mount -t proc proc /proc
-}
-
-do_mount_sysfs() {
- mount -t sysfs sysfs /sys
-}
-
-calc_tmpfs_size() {
- pi_size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)&&(mt>l)?mt-l:s}' /proc/meminfo)
-}
-
-do_mount_tmpfs() {
- calc_tmpfs_size
- mount -t tmpfs -o size=$pi_size,nosuid,nodev,mode=1777 tmpfs /tmp
-}
-
-boot_hook_add preinit_essential do_mount_procfs
-boot_hook_add preinit_essential do_mount_sysfs
-boot_hook_add preinit_essential do_mount_tmpfs
-
diff --git a/package/base-files/files/lib/preinit/10_indicate_preinit b/package/base-files/files/lib/preinit/10_indicate_preinit
index 4a0109cc1..da70b97c4 100644
--- a/package/base-files/files/lib/preinit/10_indicate_preinit
+++ b/package/base-files/files/lib/preinit/10_indicate_preinit
@@ -41,7 +41,6 @@ pi_indicate_led() {
}
pi_indicate_preinit() {
- echo "- preinit -"
preinit_net_echo "Doing OpenWRT Preinit\n"
pi_indicate_led
}
diff --git a/package/base-files/files/lib/preinit/20_check_jffs2_ready b/package/base-files/files/lib/preinit/20_check_jffs2_ready
deleted file mode 100644
index 3c5cf67e8..000000000
--- a/package/base-files/files/lib/preinit/20_check_jffs2_ready
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-mount_no_jffs2() {
- echo "jffs2 not ready yet; using ramdisk"
- ramoverlay
-}
-
-check_for_jffs2() {
- check_skip || {
- jffs2_ready || {
- mount_no_jffs2 && pi_mount_skip_next=true
- }
- }
-}
-
-boot_hook_add preinit_mount_root check_for_jffs2
-
diff --git a/package/base-files/files/lib/preinit/20_device_fs_mount b/package/base-files/files/lib/preinit/20_device_fs_mount
deleted file mode 100644
index ed59b5b23..000000000
--- a/package/base-files/files/lib/preinit/20_device_fs_mount
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-do_move_devtmpfs() {
- local mnt="$(grep devtmpfs /proc/mounts)"
- mnt="${mnt#* }"; mnt="${mnt%% *}"
-
- [ "$mnt" = "/dev" ] || mount -o move "$mnt" /dev
-}
-
-do_mount_devfs() {
- mount -t devfs devfs /dev
-}
-
-do_mount_hotplug() {
- mount -t tmpfs -o mode=0755,size=512K tmpfs /dev
-}
-
-do_mount_udev() {
- mount -n -t tmpfs -o mode=0755 udev /dev
-}
-
-choose_device_fs() {
- if grep -q devtmpfs /proc/mounts; then
- do_move_devtmpfs
- elif grep -q devfs /proc/filesystems; then
- do_mount_devfs
- elif [ -x /sbin/hotplug2 ]; then
- do_mount_hotplug
- elif [ -x /sbin/udevd ]; then
- do_mount_udev
- fi
-}
-
-boot_hook_add preinit_essential choose_device_fs
-
diff --git a/package/base-files/files/lib/preinit/30_device_fs_daemons b/package/base-files/files/lib/preinit/30_device_fs_daemons
deleted file mode 100644
index 5b3e2ad00..000000000
--- a/package/base-files/files/lib/preinit/30_device_fs_daemons
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-init_devfs() {
- HOTPLUG=/sbin/hotplug-call
-}
-
-init_hotplug2() {
- [ -c /dev/console ] || mknod /dev/console c 5 1
- /sbin/hotplug2 --set-worker /lib/hotplug2/worker_fork.so --set-rules-file /etc/hotplug2-init.rules --no-persistent --set-coldplug-cmd /sbin/udevtrigger
- /sbin/hotplug2 --set-worker /lib/hotplug2/worker_fork.so --set-rules-file /etc/hotplug2-init.rules --persistent &
-}
-
-init_udev() {
- [ -d /lib/udev/devices ] && cp -af /lib/udev/devices/* /dev/
- [ -c /dev/console ] || mknod -m 0600 /dev/console c 5 1
- [ -c /dev/null ] || mknod -m 0666 /dev/null c 1 3
- /sbin/udevd --daemon --resolve-names=never
- /sbin/udevadm trigger
- /sbin/udevadm settle
-}
-
-init_device_fs() {
- HOTPLUG=
- if grep -q devfs /proc/filesystems; then
- init_devfs
- elif [ -x /sbin/hotplug2 ]; then
- init_hotplug2
- elif [ -x /sbin/udevd ]; then
- init_udev
- fi
-}
-
-boot_hook_add preinit_essential init_device_fs
-
diff --git a/package/base-files/files/lib/preinit/30_failsafe_wait b/package/base-files/files/lib/preinit/30_failsafe_wait
index 04dc57df2..bcf24f8bb 100644
--- a/package/base-files/files/lib/preinit/30_failsafe_wait
+++ b/package/base-files/files/lib/preinit/30_failsafe_wait
@@ -61,11 +61,10 @@ fs_wait_for_key () {
}
lock -w $keypress_wait
- trap - INT
- trap - USR1
-
keypressed=1
[ "$(cat $keypress_true)" = "true" ] && keypressed=0
+ [ -f "/tmp/failsafe_button" ] && keypressed=1
+
rm -f $keypress_true
rm -f $keypress_wait
rm -f $keypress_sec
@@ -75,10 +74,13 @@ fs_wait_for_key () {
failsafe_wait() {
FAILSAFE=
- pi_failsafe_net_message=true
- preinit_net_echo "Please press button now to enter failsafe"
- pi_failsafe_net_message=false
- fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true && export FAILSAFE
+ grep -q 'failsafe=' /proc/cmdline && FAILSAFE=true && export FAILSAFE
+ if [ "$FAILSAFE" != "true" ]; then
+ pi_failsafe_net_message=true
+ preinit_net_echo "Please press button now to enter failsafe"
+ pi_failsafe_net_message=false
+ fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true && export FAILSAFE
+ fi
}
boot_hook_add preinit_main failsafe_wait
diff --git a/package/base-files/files/lib/preinit/40_init_shm b/package/base-files/files/lib/preinit/40_init_shm
deleted file mode 100644
index 8971116a4..000000000
--- a/package/base-files/files/lib/preinit/40_init_shm
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-init_shm() {
- [ -d /dev/shm ] || mkdir -p /dev/shm
-}
-
-boot_hook_add preinit_essential init_shm
-
diff --git a/package/base-files/files/lib/preinit/40_mount_devpts b/package/base-files/files/lib/preinit/40_mount_devpts
deleted file mode 100644
index b75d69287..000000000
--- a/package/base-files/files/lib/preinit/40_mount_devpts
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-init_devpts() {
- [ -d /dev/pts ] || mkdir -p /dev/pts
-}
-
-do_mount_devpts() {
- mount -t devpts devpts /dev/pts
-}
-
-boot_hook_add preinit_essential init_devpts
-boot_hook_add preinit_essential do_mount_devpts
-
diff --git a/package/base-files/files/lib/preinit/40_mount_jffs2 b/package/base-files/files/lib/preinit/40_mount_jffs2
deleted file mode 100644
index 00f45a890..000000000
--- a/package/base-files/files/lib/preinit/40_mount_jffs2
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-find_mount_jffs2() {
- mkdir -p /tmp/overlay
- mount "$(find_mtd_part rootfs_data)" /tmp/overlay -t jffs2
- mtd -qq unlock rootfs_data
-}
-
-jffs2_not_mounted() {
- if [ "$pi_jffs2_mount_success" != "true" ]; then
- return 0
- else
- return 1
- fi
-}
-
-do_mount_jffs2() {
- check_skip || {
- find_mount_jffs2 && pi_jffs2_mount_success=true
- }
-}
-
-boot_hook_add preinit_mount_root do_mount_jffs2
-
diff --git a/package/base-files/files/lib/preinit/41_merge_overlay_hooks b/package/base-files/files/lib/preinit/41_merge_overlay_hooks
deleted file mode 100644
index 4ca6877be..000000000
--- a/package/base-files/files/lib/preinit/41_merge_overlay_hooks
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2010 OpenWrt.org
-
-merge_overlay_hooks() {
- jffs2_not_mounted || [ ! -d /tmp/overlay/lib/preinit ] || {
- echo "- merge overlay components -"
-
- mkdir -p /tmp/preinit-hook-merge
- ln -sf /lib/preinit/* /tmp/overlay/lib/preinit/[0-9][0-9]_* /tmp/preinit-hook-merge/
-
- boot_hook_splice_start
-
- local pipart
- for pipart in /tmp/preinit-hook-merge/*; do
- . $pipart
- done
-
- boot_hook_splice_finish
-
- rm -rf /tmp/preinit-hook-merge
- }
-}
-
-boot_hook_add preinit_mount_root merge_overlay_hooks
diff --git a/package/base-files/files/lib/preinit/50_choose_console b/package/base-files/files/lib/preinit/50_choose_console
deleted file mode 100644
index ecbc2eaf4..000000000
--- a/package/base-files/files/lib/preinit/50_choose_console
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-choose_console() {
- # the shell really doesn't like having stdin/out closed
- # that's why we use /dev/pty/m0 and m1 (or equivalent) as replacement
- # for /dev/console if there's no serial console available
-
- if grep -q devfs /proc/filesystems; then
- M0=/dev/pty/m0
- M1=/dev/pty/m1
- M2=/dev/pty/m1
- elif [ -x /sbin/hotplug2 ]; then
- M0=/dev/ptmx
- M1=/dev/ptmx
- M2=/dev/ptmx
- elif [ -x /sbin/udevd ]; then
- M0=/dev/pty/ptmx
- M1=/dev/pty/ptmx
- M2=/dev/pty/ptmx
- fi
- dd if=/dev/console of=/dev/null bs=1 count=0 >/dev/null 2>/dev/null && {
- M0=/dev/console
- M1=/dev/console
- M2=/dev/console
- }
-}
-
-boot_hook_add preinit_essential choose_console
-
diff --git a/package/base-files/files/lib/preinit/50_indicate_regular_preinit b/package/base-files/files/lib/preinit/50_indicate_regular_preinit
index 9cc01f219..c200dad67 100644
--- a/package/base-files/files/lib/preinit/50_indicate_regular_preinit
+++ b/package/base-files/files/lib/preinit/50_indicate_regular_preinit
@@ -3,7 +3,6 @@
# Copyright (C) 2010 Vertical Communications
indicate_regular_preinit() {
- echo "- regular preinit -"
preinit_net_echo "Continuing with Regular Preinit\n"
pi_indicate_led
}
diff --git a/package/base-files/files/lib/preinit/60_init_hotplug b/package/base-files/files/lib/preinit/60_init_hotplug
deleted file mode 100644
index dc05e0ed0..000000000
--- a/package/base-files/files/lib/preinit/60_init_hotplug
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-init_hotplug() {
- echo "$HOTPLUG" > /proc/sys/kernel/hotplug
-}
-
-boot_hook_add preinit_main init_hotplug
-
diff --git a/package/base-files/files/lib/preinit/70_pivot_jffs2_root b/package/base-files/files/lib/preinit/70_pivot_jffs2_root
deleted file mode 100644
index 821bfb14f..000000000
--- a/package/base-files/files/lib/preinit/70_pivot_jffs2_root
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-rootfs_pivot() {
- check_skip || jffs2_not_mounted || {
- echo "switching to jffs2"
- mount -o move /tmp/overlay /overlay 2>&-
- fopivot /overlay /rom && pi_mount_skip_next=true
- }
-}
-
-boot_hook_add preinit_mount_root rootfs_pivot
-
diff --git a/package/base-files/files/lib/preinit/80_mount_root b/package/base-files/files/lib/preinit/80_mount_root
index ad24fb8ac..0292d82d4 100644
--- a/package/base-files/files/lib/preinit/80_mount_root
+++ b/package/base-files/files/lib/preinit/80_mount_root
@@ -3,8 +3,16 @@
# Copyright (C) 2010 Vertical Communications
do_mount_root() {
- boot_run_hook preinit_mount_root
+ mount_root
+ boot_run_hook preinit_mount_root
+ [ -f /sysupgrade.tgz ] && {
+ echo "- config restore -"
+ cd /
+ mv sysupgrade.tgz /tmp
+ tar xzf /tmp/sysupgrade.tgz
+ rm -f /tmp/sysupgrade.tgz
+ sync
+ }
}
-boot_hook_add preinit_main do_mount_root
-
+[ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root
diff --git a/package/base-files/files/lib/preinit/90_init_console b/package/base-files/files/lib/preinit/90_init_console
deleted file mode 100644
index ca05755fd..000000000
--- a/package/base-files/files/lib/preinit/90_init_console
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-init_console() {
- if [ "$pi_suppress_stderr" = "y" ]; then
- exec <$M0 >$M1 2>&0
- else
- exec <$M0 >$M1 2>$M2
- fi
-}
-
-boot_hook_add preinit_essential init_console
-
diff --git a/package/base-files/files/lib/preinit/90_mount_no_jffs2 b/package/base-files/files/lib/preinit/90_mount_no_jffs2
deleted file mode 100644
index d8ad4ae11..000000000
--- a/package/base-files/files/lib/preinit/90_mount_no_jffs2
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-do_mount_no_jffs2() {
- check_skip || {
- mount_no_jffs2 && pi_mount_skip_next=true
- }
-}
-
-boot_hook_add preinit_mount_root do_mount_no_jffs2
-
diff --git a/package/base-files/files/lib/preinit/90_restore_config b/package/base-files/files/lib/preinit/90_restore_config
deleted file mode 100644
index 210bf6184..000000000
--- a/package/base-files/files/lib/preinit/90_restore_config
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-restore_config() {
- [ -f /sysupgrade.tgz ] && {
- echo "- config restore -"
- cd /
- mv sysupgrade.tgz /tmp
- tar xzf /tmp/sysupgrade.tgz
- rm -f /tmp/sysupgrade.tgz
- sync
- }
-}
-
-boot_hook_add preinit_main restore_config
-
diff --git a/package/base-files/files/lib/preinit/99_10_mount_no_mtd b/package/base-files/files/lib/preinit/99_10_mount_no_mtd
deleted file mode 100644
index c4f38e415..000000000
--- a/package/base-files/files/lib/preinit/99_10_mount_no_mtd
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-do_mount_no_mtd() {
- check_skip || {
- mount_no_mtd
- }
-}
-
-boot_hook_add preinit_mount_root do_mount_no_mtd
-
diff --git a/package/base-files/files/lib/preinit/99_10_run_init b/package/base-files/files/lib/preinit/99_10_run_init
index fef3a503e..a8f330f89 100644
--- a/package/base-files/files/lib/preinit/99_10_run_init
+++ b/package/base-files/files/lib/preinit/99_10_run_init
@@ -3,13 +3,7 @@
# Copyright (C) 2010 Vertical Communications
run_init() {
- preinit_echo "- init -"
preinit_ip_deconfig
- if [ "$pi_init_suppress_stderr" = "y" ]; then
- exec env - PATH=$pi_init_path $pi_init_env $pi_init_cmd 2>&0
- else
- exec env - PATH=$pi_init_path $pi_init_env $pi_init_cmd
- fi
}
boot_hook_add preinit_main run_init
diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
index e6de34849..6bb36db48 100644
--- a/package/base-files/files/lib/upgrade/common.sh
+++ b/package/base-files/files/lib/upgrade/common.sh
@@ -21,8 +21,8 @@ install_bin() { # <file> [ <symlink> ... ]
files=$1
[ -x "$src" ] && files="$src $(libs $src)"
install_file $files
- [ -e /lib/ld-linux.so.3 ] && {
- install_file /lib/ld-linux.so.3
+ [ -e /lib/ld.so.1 ] && {
+ install_file /lib/ld.so.1
}
shift
for link in "$@"; do {
@@ -33,19 +33,19 @@ install_bin() { # <file> [ <symlink> ... ]
}; done
}
-pivot() { # <new_root> <old_root>
+supivot() { # <new_root> <old_root>
mount | grep "on $1 type" 2>&- 1>&- || mount -o bind $1 $1
mkdir -p $1$2 $1/proc $1/sys $1/dev $1/tmp $1/overlay && \
- mount -o move /proc $1/proc && \
+ mount -o noatime,move /proc $1/proc && \
pivot_root $1 $1$2 || {
- umount $1 $1
+ umount -l $1 $1
return 1
}
- mount -o move $2/sys /sys
- mount -o move $2/dev /dev
- mount -o move $2/tmp /tmp
- mount -o move $2/overlay /overlay 2>&-
+ mount -o noatime,move $2/sys /sys
+ mount -o noatime,move $2/dev /dev
+ mount -o noatime,move $2/tmp /tmp
+ mount -o noatime,move $2/overlay /overlay 2>&-
return 0
}
@@ -62,7 +62,7 @@ run_ramfs() { # <command> [...]
done
install_file /etc/resolv.conf /lib/functions.sh /lib/functions.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
- pivot $RAM_ROOT /mnt || {
+ supivot $RAM_ROOT /mnt || {
echo "Failed to switch over to ramfs. Please reboot."
exit 1
}
@@ -71,7 +71,7 @@ run_ramfs() { # <command> [...]
umount -l /mnt
grep /overlay /proc/mounts > /dev/null && {
- mount -o remount,ro /overlay
+ mount -o noatime,remount,ro /overlay
umount -l /overlay
}
@@ -99,7 +99,7 @@ kill_remaining() { # [ <signal> ]
case "$name" in
# Skip essential services
- *ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*) : ;;
+ *procd*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*) : ;;
# Killable process
*)
@@ -157,14 +157,14 @@ get_image() { # <source> [ <command> ]
*) cmd="cat";;
esac
if [ -z "$conc" ]; then
- local magic="$(eval $cmd $from | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')"
+ local magic="$(eval $cmd $from 2>/dev/null | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')"
case "$magic" in
1f8b) conc="zcat";;
425a) conc="bzcat";;
esac
fi
- eval "$cmd $from ${conc:+| $conc}"
+ eval "$cmd $from 2>/dev/null ${conc:+| $conc}"
}
get_magic_word() {
diff --git a/package/base-files/files/sbin/firstboot b/package/base-files/files/sbin/firstboot
index 4da299189..081febb7b 100755
--- a/package/base-files/files/sbin/firstboot
+++ b/package/base-files/files/sbin/firstboot
@@ -1,34 +1,3 @@
#!/bin/sh
-switch2jffs_hook=
-jffs2reset_hook=
-no_fo_hook=
-
-. /lib/functions/boot.sh
-
-firstboot_skip_next=false
-
-for fb_source_file in /lib/firstboot/*; do
- . $fb_source_file
-done
-
-set_mtd_part
-set_rom_part
-set_jffs_part
-
-# invoked as an executable
-if [ "${0##*/}" = "firstboot" ]; then
- if [ "$1" = "switch2jffs" ]; then
- boot_run_hook switch2jffs
- elif [ -n "$jffs" ]; then
- reset_has_fo=true
- echo "firstboot has already been run"
- echo "jffs2 partition is mounted, only resetting files"
- boot_run_hook jffs2reset
- else
- mtd erase "$partname"
- mount "$mtdpart" /overlay -t jffs2
- fopivot /overlay /rom 1
- fi
-fi
-
+/sbin/jffs2reset
diff --git a/package/base-files/files/sbin/mount_root b/package/base-files/files/sbin/mount_root
deleted file mode 100755
index 2d73dac53..000000000
--- a/package/base-files/files/sbin/mount_root
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006-2010 OpenWrt.org
-# Copyright (C) 2010 Vertical Communications
-
-# Initialize hook variables et by pulling in from preinit
-
-preinit_essential_hook=
-preinit_main_hook=
-failsafe_hook=
-initramfs_hook=
-preinit_mount_root=
-
-. /lib/functions/boot.sh
-
-for pi_source_file in /lib/preinit/*; do
- . $pi_source_file
-done
-
-# Override function that doesn't apply to use of mount_root as a command rather
-# than as part of preinit
-
-preinit_echo() {
- echo "$@"
-}
-
-boot_run_hook preinit_mount_root
diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index 802848ade..1ad6ea44a 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -12,6 +12,7 @@ export DELAY=
export CONF_IMAGE=
export CONF_BACKUP=
export CONF_RESTORE=
+export NEED_IMAGE=
export HELP=0
export FORCE=0
@@ -24,8 +25,8 @@ while [ -n "$1" ]; do
-q) export VERBOSE="$(($VERBOSE - 1))";;
-n) export SAVE_CONFIG=0;;
-c) export SAVE_OVERLAY=1;;
- -b|--create-backup) export CONF_BACKUP="$2"; shift;;
- -r|--restore-backup) export CONF_RESTORE="$2"; shift;;
+ -b|--create-backup) export CONF_BACKUP="$2" NEED_IMAGE=1; shift;;
+ -r|--restore-backup) export CONF_RESTORE="$2" NEED_IMAGE=1; shift;;
-f) export CONF_IMAGE="$2"; shift;;
-F|--force) export FORCE=1;;
-h|--help) export HELP=1; break;;
@@ -44,38 +45,41 @@ export CONF_TAR=/tmp/sysupgrade.tgz
export ARGV="$*"
export ARGC="$#"
-[ -z "$ARGV" -a -z "$CONF_BACKUP" -o $HELP -gt 0 ] && {
+[ -z "$ARGV" -a -z "$NEED_IMAGE" -o $HELP -gt 0 ] && {
cat <<EOF
-Usage: $0 [options] <image file or URL>
+Usage: $0 [<upgrade-option>...] <image file or URL>
+ $0 [-q] [-i] <backup-command> <file>
-Options:
+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/
- -b / --create-backup <file>
+ -n do not save configuration over reflash
+ -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>
+ -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.
- -n do not save configuration over reflash
- -F / --force
- Flash image even if image checks fail, this is dangerous!
- -q less verbose
- -v more verbose
- -h / --help display this help
EOF
exit 1
}
-[ -n "$ARGV" -a -n "$CONF_BACKUP" ] && {
+[ -n "$ARGV" -a -n "$NEED_IMAGE" ] && {
cat <<-EOF
- -b/--create-backup does not perform a firmware upgrade. Do not
- specify both -b and a firmware image.
+ -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
}
@@ -175,6 +179,8 @@ fi
run_hooks "" $sysupgrade_pre_upgrade
+ubus call system upgrade
+
kill_remaining TERM
sleep 3
kill_remaining KILL