Hi all,

I've refreshed the patches to work with current trunk (as the old
patches were no longer applying cleanly due to recent changes).  There
are also a couple of minor functional changes some of which make the
usb root stuff I'm working on easier.

I'd really appreciate if there could be some review/comments on these
patches soon.  It's been a significant period of time and I haven't
heard from full devs on what they think, although a couple of list
members like the idea of the modularization I have done.


I also have a question (not implemented at all).  How attached to the
sequence of preinit->mount_root->init->rcS...->firstboot are you?

It would make some things work more consistently to have firstboot
integrated into preinit instead of after all the processes have
booted.  

The disadvantage is slower boot on the first boot.

I think the current firstboot unnecessarily complicates the process of
the firstboot because there are configurations created during boot that
have to be copied from tmp root and various pivots to try and rebase
the root after having booted with with a temporary ramdisk root.  It
would be much cleaner to do all the work in preinit and once init
starts, it's a 'normal' system.

I'd like opinions on this and the provided patches, please.

Regards,

Daniel

-- 
And that's my crabbing done for the day.  Got it out of the way early, 
now I have the rest of the afternoon to sniff fragrant tea-roses or 
strangle cute bunnies or something.   -- Michael Devore
GnuPG Key Fingerprint 86 F5 81 A5 D4 2E 1F 1C      http://gnupg.org
The C Shore (Daniel Dickinson's Website) http://cshore.is-a-geek.com
Index: scripts/metadata.pl
===================================================================
--- scripts/metadata.pl	(revision 17511)
+++ scripts/metadata.pl	(working copy)
@@ -535,20 +535,24 @@
 
 sub gen_package_config() {
 	parse_package_metadata($ARGV[0]) or exit 1;
-	print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n" if %preconfig;
+	print "menuconfig IMAGEOPT\n\tbool \"Image configuration\"\n\tdefault n\n";
 	foreach my $preconfig (keys %preconfig) {
 		foreach my $cfg (keys %{$preconfig{$preconfig}}) {
 			my $conf = $preconfig{$preconfig}->{$cfg}->{id};
 			$conf =~ tr/\.-/__/;
 			print <<EOF
 	config UCI_PRECONFIG_$conf
-		string "$preconfig{$preconfig}->{$cfg}->{label}" if UCI_PRECONFIG
+		string "$preconfig{$preconfig}->{$cfg}->{label}" if IMAGEOPT
 		depends PACKAGE_$preconfig
 		default "$preconfig{$preconfig}->{$cfg}->{default}"
 
 EOF
 		}
 	}
+	print "source \"package/*/image-config.in\"\n";
+	if (scalar glob "package/feeds/*/*/image-config.in") {
+	    print "source \"package/feeds/*/*/image-config.in\"\n";
+	}
 	print_package_config_category 'Base system';
 	foreach my $cat (keys %category) {
 		print_package_config_category $cat;
Index: package/base-files/files/etc/preinit.d/run.d/failsafe_80_netlogin
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/failsafe_80_netlogin	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/failsafe_80_netlogin	(revision 0)
@@ -0,0 +1,8 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# Allow network logins in failsafe mode
+
+failsafe_80_netlogin () {
+    telnetd -l /bin/login.sh <> /dev/null 2>&1    
+}
\ No newline at end of file
Index: package/base-files/files/etc/preinit.d/run.d/preinit_base_30_failsafe_entry
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/preinit_base_30_failsafe_entry	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/preinit_base_30_failsafe_entry	(revision 0)
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# determine if failsafe mode is desired, and if so, enter it
+
+preinit_base_30_failsafe_entry () {
+    FAILSAFE=false
+
+    preinit_ip
+    preinit_echo "Please reset now to enter Failsafe!"
+
+    fs_wait_for_key "f" "to enter failsafe" $fs_timeout
+
+    if [ "$?" = "1" ]; then
+	FAILSAFE=true
+    else
+	preinit_echo "Continuing with regular boot"
+    fi
+
+    preinit_ip_deconfig
+
+    export FAILSAFE
+
+    if [ "$FAILSAFE" = "true" ]; then
+	failsafe
+    fi
+    lock -w /tmp/.failsafe
+
+    echo "- regular boot -"
+}
\ No newline at end of file
Index: package/base-files/files/etc/preinit.d/run.d/boot_80_config_restore
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/boot_80_config_restore	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/boot_80_config_restore	(revision 0)
@@ -0,0 +1,15 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# Restore configuration saved during sysupgrade
+
+boot_80_config_restore () {
+    [ -f /sysupgrade.tgz ] && {
+	echo "- config restore -"
+	cd /
+	mv sysupgrade.tgz /tmp
+	tar xzf /tmp/sysupgrade.tgz
+	rm -f /tmp/sysupgrade.tgz
+	sync
+   }
+}
\ No newline at end of file
Index: package/base-files/files/etc/preinit.d/run.d/failsafe_90_session
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/failsafe_90_session	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/failsafe_90_session	(revision 0)
@@ -0,0 +1,8 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# Start failsafe session (default is shell)
+
+failsafe_90_session () {
+	ash --login
+}
Index: package/base-files/files/etc/preinit.d/run.d/boot_20_mount
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/boot_20_mount	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/boot_20_mount	(revision 0)
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# Mount rootfs filesystem
+
+
+rootfs_ready () {
+	mtdpart="$(find_mtd_part rootfs_data)"
+	magic=$(hexdump $mtdpart -n 4 -e '4/1 "%02x"')
+	[ "$magic" != "deadc0de" ]
+}
+
+boot_20_mount () {
+    echo "- mount -"
+    grep rootfs_data /proc/mtd >/dev/null 2>/dev/null && {
+	. /bin/firstboot
+	mtd unlock rootfs_data
+	rootfs_ready && {
+	    echo "switching to jffs2"
+	    mount "$(find_mtd_part rootfs_data)" /jffs -t jffs2 && \
+		fopivot /jffs /rom
+	} || {
+	    echo "jffs2 not ready yet; using ramdisk"
+	    ramoverlay
+	}
+    } || {
+	mtd unlock rootfs
+	mount -o remount,rw /dev/root /
+    }
+}
+
Index: package/base-files/files/etc/preinit.d/run.d/failsafe_20_enter_failsafe_message
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/failsafe_20_enter_failsafe_message	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/failsafe_20_enter_failsafe_message	(revision 0)
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+failsafe_20_enter_failsafe_message () {
+    failsafe_ip
+    failsafe_echo "Entering Failsafe!"
+}
\ No newline at end of file
Index: package/base-files/files/etc/preinit.d/run.d/failsafe_10_echo
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/failsafe_10_echo	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/failsafe_10_echo	(revision 0)
@@ -0,0 +1,21 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# commands for emitting messages to network in failsafe mode
+
+failsafe_ip () {
+    [ -n "$fs_failsafe_ifname" ] && grep "$fs_failsafe_ifname" /proc/net/dev >/dev/null && {
+	ifconfig $fs_failsafe_ifname $fs_failsafe_ip netmask $fs_failsafe_netmask broadcast $fs_failsafe_broadcast up
+    }
+}
+
+failsafe_echo () {
+    [ -n "$fs_failsafe_ifname" ] && grep "$fs_failsafe_ifname" /proc/net/dev >/dev/null && {
+	netmsg $fs_failsafe_broadcast "$1"
+    }
+}
+
+failsafe_10_echo () {
+    :
+    # dummy function to satisfy pi_run_scripts
+}
\ No newline at end of file
Index: package/base-files/files/etc/preinit.d/run.d/preinit_base_10_preinit_echo
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/preinit_base_10_preinit_echo	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/preinit_base_10_preinit_echo	(revision 0)
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# commands for emitting messages to network for preinit
+
+preinit_ip () {
+    [ -n "$pi_ifname" ] && grep "$pi_ifname" /proc/net/dev >/dev/null && {
+	ifconfig $pi_ifname $pi_ip netmask $pi_netmask broadcast $pi_broadcast up
+    }
+}
+
+preinit_ip_deconfig () {
+    [ -n "$pi_ifname" ] && grep "$pi_ifname" /proc/net/dev >/dev/null && {
+	ifconfig $pi_ifname down
+    }
+}
+
+preinit_echo () {
+    [ -n "$pi_ifname" ] && grep "$pi_ifname" /proc/net/dev >/dev/null && {
+	netmsg $pi_broadcast "$1"
+    }
+}
+
+preinit_base_10_preinit_echo () {
+    :
+    # dummy function to satisfy pi_run_scripts
+}
Index: package/base-files/files/etc/preinit.d/run.d/boot_90_init
===================================================================
--- package/base-files/files/etc/preinit.d/run.d/boot_90_init	(revision 0)
+++ package/base-files/files/etc/preinit.d/run.d/boot_90_init	(revision 0)
@@ -0,0 +1,13 @@
+#!/bin/sh
+# Copyright (C) 2009 OpenWrt.org
+
+# run init
+
+boot_90_init () {
+    echo "- init -"
+    if [ "$INITSTDERR_SUPPRESS" = "y" ]; then
+	exec env - PATH=$INITPATH $INITENV $INITCMD 2>&0
+    else
+	exec env - PATH=$INITPATH $INITENV $INITCMD
+    fi
+}
\ No newline at end of file
Index: package/base-files/files/etc/preinit
===================================================================
--- package/base-files/files/etc/preinit	(revision 17511)
+++ package/base-files/files/etc/preinit	(working copy)
@@ -3,20 +3,100 @@
 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
 . /etc/diag.sh
 
-failsafe_ip() {
-	ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
+pi_run_scripts() {
+        # Scripts should contain a function that is the same name as the file
+        # (which must be a valid function name, e.g. no starting with number)
+        # The script is source and then this function executed
+        local pi_script=
+	local pi_run_funcs=
+	local pi_run_func=
+        for pi_script in /etc/preinit.d/run.d/$1*; do
+                [ -r $pi_script ] && . $pi_script && pi_run_funcs="$pi_run_funcs $(/usr/bin/basename $pi_script)" 2>&1
+        done
+	# We do it this way so that script functions may be overridden
+	for pi_run_func in $pi_run_funcs; do
+	    $pi_run_func
+	done
 }
 
 failsafe() {
-	[ -n "$ifname" ] && grep "$ifname" /proc/net/dev >/dev/null && {
-		failsafe_ip
-		netmsg 192.168.1.255 "Entering Failsafe!"
-		telnetd -l /bin/login.sh <> /dev/null 2>&1
-	}
+	echo "- enter failsafe -"
 	lock /tmp/.failsafe
-	ash --login
+	pi_run_scripts failsafe_
 }
 
+fs_wait_for_key () {
+
+    local TIMEOUT=$3
+    local TIMER=
+    local DOFAILSAFE=
+    local KEYPRESS_TRUE="$(mktemp)"
+    local KEYPRESS_WAIT="$(mktemp)"
+    local KEYPRESS_SEC="$(mktemp)"
+    if [ -z "$KEYPRESS_WAIT" ]; then
+	KEYPRESS_WAIT=/tmp/.keypress_wait
+	touch $KEYPRESS_WAIT
+    fi
+    if [ -z "$KEYPRESS_TRUE" ]; then
+	KEYPRESS_TRUE=/tmp/.keypress_true
+	touch $KEYPRESS_TRUE
+    fi
+    if [ -z "$KEYPRESS_SEC" ]; then
+	KEYPRESS_SEC=/tmp/.keypress_sec
+	touch $KEYPRESS_SEC
+    fi
+
+    trap "echo '1' >$KEYPRESS_TRUE; lock -u $KEYPRESS_WAIT ; rm -f $KEYRPESS_WAIT'" INT
+    trap "echo '1' >$KEYRPESS_TRUE; lock -u $KEYRPESS_WAIT ; rm -f $KEYPRESS_WAIT'" USR1
+
+    [ -n "$TIMEOUT" ] || TIMEOUT=1
+    [ $TIMEOUT -ge 1 ] || TIMEOUT=1
+    TIMER=$TIMEOUT
+    lock $KEYPRESS_WAIT
+    {
+	while [ $TIMER -gt 0 ]; do
+            echo "$TIMER" >$KEYPRESS_SEC
+	    TIMER=$(($TIMER - 1))
+	    sleep 1
+	done
+	lock -u $KEYPRESS_WAIT
+	rm -f $KEYPRESS_WAIT
+    } &
+
+    echo "Press $1<ENTER> $2"
+    # if we're on the console we wait for input
+    { 
+	while [ -r $KEYPRESS_WAIT ]; do
+	    TIMER="$(cat $KEYPRESS_SEC)"
+
+	    [ -n "$TIMER" ] || TIMER=1
+	    TIMER="${TIMER%%\ *}"
+	    [ $TIMER -ge 1 ] || TIMER=1
+	    DOFAILSAFE=""
+	    {
+		read -t "$TIMER" DOFAILSAFE
+		if [ "$DOFAILSAFE" = "$1" ]; then
+		    echo "1" >$KEYPRESS_TRUE
+		    lock -u $KEYPRESS_WAIT
+		    rm -f $KEYPRESS_WAIT
+ 		fi
+	    }
+	done
+    }
+    lock -w $KEYPRESS_WAIT
+
+    trap - INT
+    trap - USR1
+
+    KEYPRESSED=0
+    [ "$(cat $KEYPRESS_TRUE)" = "1" ] && KEYPRESSED=1
+    rm -f $KEYPRESS_TRUE
+    rm -f $KEYPRESS_WAIT
+    rm -f $KEYPRESS_SEC
+    
+    return $KEYPRESSED
+}
+
 mount proc /proc -t proc
 mount sysfs /sys -t sysfs
 
@@ -27,6 +107,7 @@
 	mount devfs /dev -t devfs
 	M0=/dev/pty/m0
 	M1=/dev/pty/m1
+	M2=/dev/pty/m1
 	HOTPLUG=/sbin/hotplug-call
 
 elif [ -x /sbin/hotplug2 ]; then
@@ -36,6 +117,7 @@
 	/sbin/hotplug2 --set-worker /lib/hotplug2/worker_fork.so --set-rules-file /etc/hotplug2-init.rules --persistent &
 	M0=/dev/ptmx
 	M1=/dev/ptmx
+	M2=/dev/ptmx
 	HOTPLUG=
 
 elif [ -x /sbin/udevd ]; then
@@ -48,6 +130,7 @@
 	/sbin/udevadm settle
 	M0=/dev/pty/ptmx
 	M1=/dev/pty/ptmx
+	M2=/dev/pty/ptmx
 	HOTPLUG=
 fi
 
@@ -61,14 +144,23 @@
 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
 }
 
-exec <$M0 >$M1 2>&0
+[ -r /etc/preinit.d/pi_base_conf ] && . /etc/preinit.d/pi_base_conf
 
+if [ "$pi_suppress_stderr" = "y" ]; then
+    exec <$M0 >$M1 2>&0
+else
+    exec <$M0 >$M1 2>$M2
+fi
+
 echo "- preinit -"
-echo "Press CTRL-C for failsafe"
-trap 'FAILSAFE=true' INT
-trap 'FAILSAFE=true' USR1
+
+fs_failsafe_ifname=
+pi_ifname=
+
+
 if [ -e /etc/preinit.arch ]; then
 	. /etc/preinit.arch
 else
@@ -76,22 +168,35 @@
 fi
 set_state preinit
 echo "$HOTPLUG" > /proc/sys/kernel/hotplug
-export FAILSAFE
-eval ${FAILSAFE:+failsafe}
-lock -w /tmp/.failsafe
+pi_ip=192.168.1.1
+pi_broadcast=192.168.1.255
+pi_netmask=255.255.255.0
+fs_failsafe_ip=192.168.1.1
+fs_failsafe_broadcast=192.168.1.255
+fs_failsafe_netmask=255.255.255.0
 
-if [ -z "$INITRAMFS" ]; then
-	mount_root
-	[ -f /sysupgrade.tgz ] && {
-		echo "- config restore -"
-		cd /
-		mv sysupgrade.tgz /tmp
-		tar xzf /tmp/sysupgrade.tgz
-		rm -f /tmp/sysupgrade.tgz
-		sync
-	}
+if [ -z "$fs_failsafe_ifname" ]; then
+    fs_failsafe_ifname=$ifname    
+fi
 
-	echo "- init -"
-	
-	exec /sbin/init
+# We use backslash continuation not braces to avoid scope issues
+# for variable assignments
+[ -d /etc/preinit.d/conf.d ] && \
+    OLDIFS="$IFS" ; \
+    IFS='
+' ; \
+    for fs_variable in $(cat /etc/preinit.d/conf.d/*); do \
+    eval "$fs_variable" ; \
+    done
+
+IFS="$OLDIFS"
+
+if [ "$IFS" = "" ]; then
+    unset IFS
 fi
+
+pi_run_scripts preinit_base_
+
+if [ -z "$INITRAMFS" ]; then 
+    pi_run_scripts boot_
+fi
Index: package/base-files/files/sbin/mount_root
===================================================================
--- package/base-files/files/sbin/mount_root	(revision 17511)
+++ package/base-files/files/sbin/mount_root	(working copy)
@@ -1,25 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-. /etc/functions.sh
-
-jffs2_ready () {
-	mtdpart="$(find_mtd_part rootfs_data)"
-	magic=$(hexdump $mtdpart -n 4 -e '4/1 "%02x"')
-	[ "$magic" != "deadc0de" ]
-}
-
-grep rootfs_data /proc/mtd >/dev/null 2>/dev/null && {
-	. /bin/firstboot
-	mtd unlock rootfs_data
-	jffs2_ready && {
-		echo "switching to jffs2"
-		mount "$(find_mtd_part rootfs_data)" /jffs -t jffs2 && \
-			fopivot /jffs /rom
-	} || {
-		echo "jffs2 not ready yet; using ramdisk"
-		ramoverlay
-	}
-} || {
-	mtd unlock rootfs
-	mount -o remount,rw /dev/root /
-}
Index: package/base-files/image-config.in
===================================================================
--- package/base-files/image-config.in	(revision 0)
+++ package/base-files/image-config.in	(revision 0)
@@ -0,0 +1,115 @@
+# Copyright (C) 2009 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+menuconfig PREINITOPT
+     bool "Preinit configuration options" if IMAGEOPT
+     default n
+
+config TARGET_PREINIT_SUPPRESS_STDERR
+      bool "Suppress stderr messages during preinit" if PREINITOPT
+      default y
+      help
+	Sends stderr to null during preinit.  This is the default behaviour
+	in previous versions of OpenWRT.  This also prevents init process
+	itself from display stderr, but once multiuser is entered, stderr may
+	be sent to a tty and thus appear (that's the default behaviour).
+
+config TARGET_PREINIT_TIMEOUT
+       int
+       prompt "Failsafe wait timeout" if PREINITOPT
+       default 5
+       help
+		How long to wait for failsafe mode to be entered before
+		continuing with a regular boot if failsafe not selected.
+
+config TARGET_PREINIT_IFNAME
+       string
+       prompt "Preinit network message interface" if PREINITOPT
+       default ""
+       help
+		Interface for sending preinit messages to network.  If empty
+		uses $ifname (if defined in /etc/preinit.arch).
+
+config TARGET_PREINIT_IP
+       string
+       prompt "IP address for preinit network messages" if PREINITOPT
+       default "192.168.1.1"
+       help    
+       	       IP address used to configure interface for preinit network
+	       messages.
+
+config TARGET_PREINIT_NETMASK
+       string
+       prompt "Netmask for preinit network messages" if PREINITOPT
+       default "255.255.255.0"
+       help
+		Netmask used to configure interface for preinit network	
+		messages
+
+config TARGET_PREINIT_BROADCAST
+       string
+       prompt "Broadcast address for preinit network messages" if PREINITOPT
+       default "192.168.1.255
+       help
+		Broadcast address to which to send preinit network messages
+
+config TARGET_PREINIT_FS_IP
+       string
+       prompt "Failsafe IP" if PREINITOPT
+       default 192.168.1.1
+       help
+		IP address to use for failsafe interface in failsafe mode
+
+config TARGET_PREINIT_FS_BROADCAST
+       string
+       prompt "Failsafe broadcast address" if PREINITOPT
+       default 192.168.1.255
+       help
+		Broadcast address for log messages in failsafe mode
+
+config TARGET_PREINIT_FS_NETMASK
+       string
+       prompt "Failsafe netmask" if PREINITOPT
+       default 255.255.255.0
+       help
+		Netmask for failsafe mode
+
+config TARGET_PREINIT_FS_IFNAME
+       string
+       prompt "Failsafe interface" if PREINITOPT
+       default ""
+       help
+		Interface for networking while in failsafe mode.   If empty
+		uses $ifname (if defined in /etc/preinit.arch).
+
+menuconfig INITOPT
+    bool "Init configuration options" if IMAGEOPT
+    default n
+
+    config TARGET_INIT_PATH
+    string
+    prompt "PATH for regular boot" if INITOPT
+    default "/bin:/sbin:/usr/bin:/usr/sbin"
+
+    config TARGET_INIT_ENV
+    string
+    prompt "Environment variables to set when starting init (start with none)" if INITOPT
+    default ""
+
+    config TARGET_INIT_CMD
+    string
+    prompt "Init command" if INITOPT
+    default "/sbin/init"
+
+    config TARGET_INIT_SUPPRESS_STDERR
+    bool
+    prompt "Suppress stderr messages of init" if INITOPT
+    default y
+    help
+	Prevents showing stderr messages for init command if not already
+	suppressed during preinit.  This is the default behaviour in previous 
+	versions of OpenWRT.  Removing this does nothing if stderr is 
+	suppressed during preinit (the default).
Index: package/base-files/Makefile
===================================================================
--- package/base-files/Makefile	(revision 17511)
+++ package/base-files/Makefile	(working copy)
@@ -138,6 +138,25 @@
 	$(call Build/Compile/Default)
 endef
 
+define ImageConfigOptions
+	mkdir -p $(1)/etc/preinit.d/conf.d
+	echo 'pi_suppress_stderr="$(CONFIG_TARGET_PREINIT_SUPPRESS_STDERR)"' >$(1)/etc/preinit.d/pi_base_conf
+	echo 'fs_timeout=$(if $(CONFIG_TARGET_PREINIT_TIMEOUT),$(CONFIG_TARGET_PREINIT_TIMEOUT),5)' >$(1)/etc/preinit.d/conf.d/00_fs_timeout
+	echo 'fs_failsafe_ip=$(if $(CONFIG_TARGET_PREINIT_FS_IP),$(CONFIG_TARGET_PREINIT_FS_IP),"192.168.1.1")' >$(1)/etc/preinit.d/conf.d/10_fs_failsafe_net
+	echo 'fs_failsafe_broadcast=$(if $(CONFIG_TARGET_PREINIT_FS_BROADCAST),$(CONFIG_TARGET_PREINIT_FS_BROADCAST),"192.168.1.255")' >>$(1)/etc/preinit.d/conf.d/10_fs_failsafe_net
+	echo 'fs_failsafe_netmask=$(if $(CONFIG_TARGET_PREINIT_FS_NETMASK),$(CONFIG_TARGET_PREINIT_FS_NETMASK),"255.255.255.0")' >>$(1)/etc/preinit.d/conf.d/10_fs_failsafe_net
+	echo 'fs_failsafe_ifname=$(if $(CONFIG_TARGET_PREINIT_FS_IFNAME),$(CONFIG_TARGET_PREINIT_FS_IFNAME),"")' >>$(1)/etc/preinit.d/conf.d/10_fs_failsafe_net
+	echo 'INITPATH=$(if $(CONFIG_TARGET_INIT_PATH),$(CONFIG_TARGET_INIT_PATH),"/bin:/sbin:/usr/bin:/usr/sbin")' >$(1)/etc/preinit.d/conf.d/90_init_path
+	echo 'INITENV=$(if $(CONFIG_TARGET_INIT_ENV),$(CONFIG_TARGET_INIT_ENV),"")' >$(1)/etc/preinit.d/conf.d/90_init_env
+	echo 'INITCMD=$(if $(CONFIG_TARGET_INIT_CMD),$(CONFIG_TARGET_INIT_CMD),"/sbin/init")' >$(1)/etc/preinit.d/conf.d/95_init_cmd
+	echo 'INITSTDERR_SUPPRESS="$(CONFIG_TARGET_INIT_SUPPRESS_STDERR)"' >>$(1)/etc/preinit.d/conf.d/90_init_env
+	echo 'pi_ifname=$(if $(CONFIG_TARGET_PREINIT_IFNAME),$(CONFIG_TARGET_PREINIT_IFNAME),"")' >$(1)/etc/preinit.d/conf.d/10_preinit_netmsg
+	echo 'pi_ip=$(if $(CONFIG_TARGET_PREINIT_IP),$(CONFIG_TARGET_PREINIT_IP),"192.168.1.1")' >>$(1)/etc/preinit.d/conf.d/10_preinit_netmsg
+	echo 'pi_netmask=$(if $(CONFIG_TARGET_PREINIT_NETMASK),$(CONFIG_TARGET_PREINIT_NETMASK),"255.255.255.0")' >>$(1)/etc/preinit.d/conf.d/10_preinit_netmsg
+	echo 'pi_broadcast=$(if $(CONFIG_TARGET_PREINIT_BROADCAST),$(CONFIG_TARGET_PREINIT_BROADCAST),"")' >>$(1)/etc/preinit.d/conf.d/10_preinit_netmsg
+endef
+
+
 define Package/base-files/install
 	$(CP) ./files/* $(1)/
 	if [ -d $(GENERIC_PLATFORM_DIR)/base-files/. ]; then \
@@ -191,6 +210,7 @@
 	ln -sf /tmp $(1)/var
 	mkdir -p $(1)/etc
 	ln -sf /tmp/resolv.conf /tmp/fstab /tmp/TZ $(1)/etc/
+	$(call ImageConfigOptions,$(1))
 	$(call Package/base-files/install-target,$(1))
 	for conffile in $(1)/etc/config/*; do \
 		if [ -f "$$$$conffile" ]; then \
Index: package/base-files/files/lib/upgrade/common.sh
===================================================================
--- package/base-files/files/lib/upgrade/common.sh	(revision 17511)
+++ package/base-files/files/lib/upgrade/common.sh	(working copy)
@@ -45,7 +45,7 @@
 }
 
 run_ramfs() { # <command> [...]
-	install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount /sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd /bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump /bin/sleep /bin/zcat /usr/bin/bzcat
+	install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount /sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd /bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump /bin/sleep /bin/zcat /usr/bin/bzcat /bin/lock /bin/netmsg
 	install_bin /sbin/mtd
 	for file in $RAMFS_COPY_BIN; do
 		install_bin $file
Index: utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_10_provider_echo_command
===================================================================
--- utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_10_provider_echo_command	(revision 0)
+++ utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_10_provider_echo_command	(revision 0)
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+# command to use for echoing log messages
+# Copyright 2009 Daniel Dickinson, Licensed under the GPL Version 2 or later
+
+pr_failsafe_echo () {
+	      echo "$1"
+	      netmsg $fs_failsafe_broadcast "$1"
+}
+
+failsafe_10_provider_echo_command () {
+    #dummy command
+    :
+}
Index: utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_50_get_dhcp_address
===================================================================
--- utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_50_get_dhcp_address	(revision 0)
+++ utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_50_get_dhcp_address	(revision 0)
@@ -0,0 +1,31 @@
+#!/bin/sh 
+
+# Get IP address for WAN via DHCP
+# Copyright 2009 Daniel Dickinson, Licensed under the GPL Version 2 or later
+
+pr_failsafe_dhcpc () {
+    if [ -n "$fsprovider_ifname" ] && grep "$fsprovider_ifname" /proc/net/dev >/dev/null; then  
+	pr_failsafe_echo "Getting WAN ip via DHCP"
+	/sbin/udhcpc -t10 -i $fsprovider_ifname -n
+	retval=$?
+    else
+	pr_failsafe_echo "ERROR: WAN inteface '$fsprovider_ifname' can't be configured"
+	do_reboot
+    fi
+    return $retval
+}	    
+
+failsafe_50_get_dhcp_address () {
+    if [ "$MANUALFAILSAFE" = "true" ]; then
+	return 0
+    fi
+    while [ "$retval" != "0" ]; do
+	failsafe_echo "Getting WAN IP address via DHCP"
+	pr_failsafe_dhcpc
+	retval=$?
+	sleep $fsprovider_link_status_sleep
+	reboot_link_status_changed
+    done
+    
+    poll_link_status
+}
Index: utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_10_reboot_command
===================================================================
--- utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_10_reboot_command	(revision 0)
+++ utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_10_reboot_command	(revision 0)
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+do_reboot () {
+    pr_failsafe_echo "Checking reboot status"
+    # Here we make sure that we're not flashing or some other operation
+    # where rebooting is liable to result in bricking of the router
+    lock /tmp/.reboot_semaphore
+    local reboot_status="$(cat /tmp/.reboot_status 2>/dev/null)"
+    if [ "$reboot_status" = "0" ]; then
+	pr_failsafe_echo "Not rebooting; sensitive operation in progress"
+	return 0
+    fi
+    local reboot_status="$(cat /tmp/root/tmp/.reboot_status 2>/dev/null)"
+    if [ "$reboot_status" = "0" ]; then
+	pr_failsafe_echo "Not rebooting; sensitive operation in progress"
+	return 0
+    fi
+    echo "1" >/tmp/.reboot_status
+    ( echo "1" >/tmp/root/tmp/.reboot_status ) 2>/dev/null
+    lock -u /tmp/.reboot_semaphore
+    pre_failsafe_echo "Failsafe autorestore rebooting system"
+    reboot
+    sleep 10
+    echo b 2>/dev/null >/proc/sysrq-trigger
+    # This is just in case reboot doesn't happen for some reason
+    while true; do
+	pr_failsafe_echo "Failsafe reboot failed!  Please turn the device off and back on again"
+	halt
+	sleep 10
+	echo h 2>/dev/null >/proc/sysrq-trigger
+	sleep 300
+    done
+}
+
+reboot_after_timeout () {
+    # reboot after a given amount of time has elapsed (e.g. 28 hours) without
+    # doing a sysupgrade or restore settings
+    {
+	if [ -n "$fsprovider_reboot_timeout" ]; then
+	    if [ "$fsprovider_reboot_timeout" != "0" ]; then
+		sleep $fsprovider_reboot_timeout
+		do_reboot
+	    fi
+	fi
+    } &
+}
+
+failsafe_10_reboot_command () {
+    reboot_after_timeout
+}
\ No newline at end of file
Index: utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_30_manual_failsafe
===================================================================
--- utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_30_manual_failsafe	(revision 0)
+++ utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_30_manual_failsafe	(revision 0)
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# Wait to see if we want manual failsafe or autorestore
+# Copyright 2009 Daniel Dickinson, Licensed under the GPL Version 2 or later
+
+failsafe_30_manual_failsafe () {
+    echo "- autorestore failsafe -"
+
+    MANUALFAILSAFE=false
+
+    fs_wait_for_key m "for manual failsafe mode" $fsprovider_timeout 
+
+    if [ "$?" = "1" ]; then
+	MANUALFAILSAFE=true
+	export MANUALFAILSAFE
+    fi
+}
Index: utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_70_get_settings_firmware
===================================================================
--- utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_70_get_settings_firmware	(revision 0)
+++ utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_70_get_settings_firmware	(revision 0)
@@ -0,0 +1,140 @@
+#!/bin/sh
+
+# get settings and firmware from our server
+# Copyright 2009 Daniel Dickinson, Licensed under the GPL Version 2 or later
+
+read_ip () {
+    ifconfig $fsprovider_ifname | grep 'inet addr:'|grep -v '127.0.0.1'| cut -d: -f2 | awk '{ print $1 }'
+}
+
+parse_mac_line () {
+    while [ "$1" != "HWaddr" ] && [ -n "$1" ]; do
+	shift
+    done
+    echo $2
+}
+
+read_mac () {
+    local mac_line="$(ifconfig $fsprovider_ifname | grep 'HWaddr')"
+    local mac=$(parse_mac_line $mac_line)
+    echo "$mac" | sed -e 's/:/-/g'
+}
+
+get_file () {
+    local retval=1
+    ANONYMOUS=false
+    if [ "$username" = "" ] && [ "$password" = "" ]; then
+	ANONYMOUS=true
+    fi
+    if [ "$ANONYMOUS" != "true" ] && [ "$username" = "" ]; then
+	pr_failsafe_echo "ERROR: Missing username for file download"
+	return 1
+    fi
+    if [ "$ANONYMOUS" != "true" ] && [ "$password" = "" ]; then
+	pr_failsafe_echo "ERROR: Missing password for file download"
+	return 1
+    fi
+    if [ "$server" = "" ]; then
+	pr_failsafe_echo "ERROR: Missing URL of server for download"
+	return 1
+    fi
+    if [ "$serverdir" = "" ]; then
+	pr_failsafe_echo "ERROR: Missing path to file for server download"
+	return 1
+    fi
+
+    while [ "$retval" != "0" ]; do
+	local ip2="$(read_ip)"
+	if [ "$ip2" != "$(cat /tmp/.3rdparty_failsafe_ip)" ]; then
+	    # if the IP we get from the upstream router changes we assumes 
+	    # things could break and reboot before trying again
+	    do_reboot
+	fi
+	if [ "$ANONYMOUS" = "true" ]; then
+	   curl -o /tmp/$1 $server$serverdir/$1
+	else
+	   curl --user "$username:$password" -o /tmp/$1 $server$serverdir/$1
+	fi
+	retval="$?"
+    done
+    return 0
+}
+
+failsafe_70_get_settings_firmware () {
+    if [ "$MANUALFAILSAFE" = "true" ]; then
+	return 0
+    fi
+    local WANIP="$(read_ip)"
+    
+    if [ -z "$WANIP" ]; then
+       # If we got an IP via dhcp we should have one here.  If not things are
+       # very bad and hopefully a reboot will fix them.  If not a support call 
+       # will be needed, or an RMA
+	pr_failsafe_echo "IP change in autorestore failsafe"
+	do_reboot
+    fi
+    
+    echo "$WANIP" >/tmp/.3rdparty_failsafe_ip
+    pr_failsafe_echo "WAN IP address: $WANIP"
+    
+    local md5sum_match=false
+    
+    mac="$(read_mac)"
+    eval "username=$fsprovider_username"
+    eval "password=$fsprovider_password"
+    eval "server=$fsprovider_server"
+    eval "serverdir=$fsprovider_server_dir"
+    eval "md5sum_file=$fsprovider_md5sum_file"
+    eval "settings_file=$fsprovider_settings_file"
+    eval "firmware_file=$fsprovider_firmware_file"
+
+    while [ "$md5sum_match" = "false" ]; do
+	for file in $settings_file $firmware_file $md5sum_file; do
+	    pr_failsafe_echo "Downloading $file"
+	    if ! get_file $file; then
+		return 1
+	    fi
+	done
+	pr_failsafe_echo "Verifying file integrity"
+	cd /tmp
+	md5sum -s -c $md5sum_file
+	if [ "$?" = "0" ]; then
+	    md5sum_match=true
+	else
+	    pr_failsafe_echo "WARNING: md5sum mismatch; retrying download"
+	fi
+	cd /
+    done
+
+    #    if [ "$(dd if=/tmp/firmware.bin bs=1 count=19)" != "No firmware upgrade" ]; then
+
+    echo "true" >/tmp/.kill_link_status_loop
+    lock /tmp/.killed_link_status_loop
+    lock -w /tmp/.killed_link_status_loop
+
+    pr_failsafe_echo "Checking reboot status"
+    # Here we make sure that we're not flashing or some other operation
+    # where rebooting is liable to result in bricking of the router
+    lock /tmp/.reboot_semaphore
+    local reboot_status="$(cat /tmp/.reboot_status 2>/dev/null)"
+    if [ "$reboot_status" = "1" ]; then
+	pr_failsafe_echo "Not flashing, reboot already in progress"
+	return 0
+    fi
+    echo "0" >/tmp/.reboot_status
+    lock -u /tmp/.reboot_semaphore
+    
+    pr_failsafe_echo "No reboot in progress so blocking reboot and continuing"
+    pr_failsafe_echo "Performing system upgrade/settings restore"
+    sysupgrade -f /tmp/$settings_file /tmp/$firmware_file
+	
+    # Just in case sysupgrade fails
+    sleep 3600
+    # Try again
+    pr_failsafe_echo "Sysupgrade seems to have failed; trying again"
+    sysupgrade -f /tmp/$fsprovider_settings_file /tmp/$fsprovider_firmware_file
+    # Give up and hope we're not bricked
+    sleep 3600
+    pr_failsafe_echo "Retry of sysupgrade failed; rebooting"
+    do_reboot
+}
Index: utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_40_link_status
===================================================================
--- utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_40_link_status	(revision 0)
+++ utils/failsafe-provider-restore/files/etc/preinit.d/run.d/failsafe_40_link_status	(revision 0)
@@ -0,0 +1,134 @@
+#!/bin/sh
+
+# link status functions
+# Copyright 2009 Daniel Dickinson, Licensed under the GPL Version 2 or later
+
+check_link_status () {
+    local link_status="$(cat $fsprovider_link_status_device_path 2>/dev/null)"
+    if [ "$link_status" != "0" ] && [ "$link_status" != "1" ]; then
+	echo "2"
+    fi
+    echo $link_status
+}
+
+init_link_status () {
+    local got_real_status=0
+    local link_status=
+    while [ "$got_real_status" = "0" ]; do
+	link_status="$(check_link_status)"
+	if [ "$link_status" = "2" ]; then
+	    sleep $fsprovider_link_status_sleep
+	    continue
+	fi
+	got_real_status=1
+    done	  
+    lock /tmp/.link_status_update
+    echo $link_status >/tmp/.3rdparty_link_status
+    lock -u /tmp/.link_status_update
+}
+
+reboot_link_status_changed () {
+    local link_status=
+    link_status="$(check_link_status)"
+    if [ "$link_status" = "2" ]; then
+	return
+    fi
+    lock /tmp/.link_status_update
+    rm -f /tmp/.3rdparty_link_status.old
+    mv /tmp/.3rdparty_link_status /tmp/.3rdparty_link_status.old
+    echo $link_status >/tmp/.3rdparty_link_status
+    # if we don't have both old and new status now, something has
+    # gone wrong, so reboot
+    if [ ! -r "/tmp/.3rdparty_link_status" ] || [ ! -r "/tmp/.3rdparty_link_status.old" ]; then
+	pr_failsafe_echo "ERROR: missing old or new link status"
+	do_reboot
+    fi
+    # status should be boolean, so if we don't have boolean, reboot
+    # because we've screwed up somewhere
+    if [ "$(cat /tmp/.3rdparty_link_status)" != "0" ] && \
+	[ "$(cat /tmp/.3rdparty_link_status)" != "1" ] || \
+	[ "$(cat /tmp/.3rdparty_link_status.old)" != "0" ] && \
+	[ "$(cat /tmp/.3rdparty_link_status.old)" != "1" ]; then 
+	pr_failsafe_echo "ERROR: link status not boolean"
+	do_reboot
+    fi
+    # if the link status has changed, reboot
+    if [ "$(cat /tmp/.3rdparty_link_status)" != "$(cat /tmp/.3rdparty_link_status.old)" ]; then
+	pr_failsafe_echo "NOTICE: link status changed"
+	do_reboot
+    fi
+    lock -u /tmp/.link_status_update
+}
+
+poll_link_status () {
+    touch /tmp/.kill_link_status_loop
+    {
+	local link_status=
+	local end_loop=false
+	while [ "$end_loop" = "false" ]; do
+	    link_status="$(check_link_status)"
+	    if [ "$link_status" = "2" ]; then
+		sleep $fsprovider_link_status_sleep
+		continue
+	    fi
+	    lock /tmp/.link_status_update
+	    rm -f /tmp/.3rdparty_link_status.old
+	    mv /tmp/.3rdparty_link_status /tmp/.3rdparty_link_status.old
+	    echo $link_status >/tmp/.3rdparty_link_status
+	    
+	    # if we don't have both old and new status now, something has
+	    # gone wrong, so reboot
+	    if [ ! -r "/tmp/.3rdparty_link_status" ] || [ ! -r "/tmp/.3rdparty_link_status.old" ]; then
+		pr_failsafe_echo "ERROR: missing old or new link status"
+		do_reboot
+	    fi
+	    # status should be boolean, so if we don't have boolean, reboot
+	    # because we've screwed up somewhere
+	    if [ "$(cat /tmp/.3rdparty_link_status)" != "0" ] && \
+		[ "$(cat /tmp/.3rdparty_link_status)" != "1" ] || \
+		[ "$(cat /tmp/.3rdparty_link_status.old)" != "0" ] && \
+		[ "$(cat /tmp/.3rdparty_link_status.old)" != "1" ]; then 
+		pr_failsafe_echo "ERROR: link status not boolean"
+		do_reboot
+	    fi
+	    # if the link status has changed, reboot
+	    if [ "$(cat /tmp/.3rdparty_link_status)" != "$(cat /tmp/.3rdparty_link_status.old)" ]; then
+		pr_failsafe_echo "NOTICE: link status changed"
+		do_reboot
+	    fi
+
+	    lock -u /tmp/.link_status_update
+
+	    if [ "$(cat /tmp/.kill_link_status_loop)" = "true" ]; then
+		end_loop=true
+	    fi
+	done
+	lock -u /tmp/.killed_link_status_loop
+    } &
+} 
+
+get_link_status () {
+    local link_status=
+    lock /tmp/.link_status_update
+    link_status="$(cat /tmp/.3rdparty_link_status)"
+    lock -u /tmp/.link_status_update
+    if [ "$link_status" = "0" ] || [ "$link_status" = "1" ]; then
+	return $link_status
+    fi
+    return 2
+}
+
+failsafe_40_link_status () {
+    if [ "$MANUALFAILSAFE" = "true" ]; then
+	return 0
+    fi
+    pr_failsafe_echo "Initializing WAN link"
+    if [ -n "$fsprovider_ifname" ] && grep "$fsprovider_ifname" /proc/net/dev >/dev/null; then  
+	ifconfig $fsprovider_ifname up	
+	sleep $fsprovider_link_status_sleep
+    else
+	pr_failsafe_echo "ERROR: WAN inteface '$fsprovider_ifname' can't be configured"
+	do_reboot
+    fi
+    init_link_status
+}
Index: utils/failsafe-provider-restore/image-config.in
===================================================================
--- utils/failsafe-provider-restore/image-config.in	(revision 0)
+++ utils/failsafe-provider-restore/image-config.in	(revision 0)
@@ -0,0 +1,127 @@
+# Copyright (C) 2009 Daniel Dickinson
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+menuconfig FSPROVIDEROPT
+     bool "Failsafe provider restore options" if IMAGEOPT
+     default n
+
+config TARGET_FSPROVIDER_FS_TIMEOUT
+       int
+       prompt "Manual failsafe wait timeout" if FSPROVIDEROPT
+       default 5
+       help
+		How long to wait for manual failsafe mode to be entered before
+		proceeding to an autorestore failsafe instead
+
+config TARGET_FSPROVIDER_REBOOT_TIMEOUT
+       string
+       prompt "Reboot if no system upgrade before timeout has elapsed" if FSPROVIDEROPT
+       default 0      
+       help    
+       	       Time to allow for failsafe actions to be performed before 
+	       rebooting on the assumption the autorestore isn't going to 
+	       happen if it hasn't happened by this point.  0 (the default)
+	       means don't use this timeout, but rather reboot only when
+	       indicated by the failsafe autorestore process.  The timeout is
+	       passwd as an argument to 'sleep' command, so you can use
+	       timeouts like 28h for 28 hours.
+
+
+config TARGET_FSPROVIDER_LINK_STATUS_SLEEP
+       int
+       prompt "Time to wait for link status to settle after ifup" if FSPROVIDEROPT
+       default 10
+       help
+	    Time in seconds to wait for link to settle when the link changes
+	    state due to the interface being brought up or down
+
+config TARGET_FSPROVIDER_LINK_STATUS_DEVICE_PATH
+       string
+       prompt "Path to carrier indicator for device we're watching" if FSPROVIDEROPT
+       default "/sys/class/net/eth0/carrier"
+
+config TARGET_FSPROVIDER_IFNAME
+       string
+       prompt "Interface for contacting provider" if FSPROVIDEROPT
+       default "eth0"
+
+config TARGET_FSPROVIDER_USERNAME
+       string
+       prompt "Username for downloading files" if FSPROVIDEROPT
+       default ""
+       help
+		This value is eval'd in the failsafe script, so if you use
+		something like $(ESCAPEDVAR)varname it will be replaced by
+		the runtime (on the router) value of $varname.  Also you can
+		use $(ESCAPEDVAR)(command) to cause this to be the value of
+		the output of command (via $(command)).
+
+config TARGET_FSPROVIDER_PASSWORD
+       string
+       prompt "Password for downloading files" if FSPROVIDEROPT
+       default ""
+       help
+		This value is eval'd in the failsafe script, so if you use
+		something like $(ESCAPEDVAR)varname it will be replaced by
+		the runtime (on the router) value of $varname.  Also you can
+		use $(ESCAPEDVAR)(command) to cause this to be the value of
+		the output of command (via $(command)).
+.
+config TARGET_FSPROVIDER_SERVER
+       string
+       prompt "Server base URL for downloading files" if FSPROVIDEROPT
+       default "http://someserver.example.com/";
+       help
+		This value is eval'd in the failsafe script, so if you use
+		something like $(ESCAPEDVAR)varname it will be replaced by
+		the runtime (on the router) value of $varname.  Also you can
+		use $(ESCAPEDVAR)(command) to cause this to be the value of
+		the output of command (via $(command)).
+
+config TARGET_FSPROVIDER_SERVER_FILE_DIR
+       string
+       prompt "Path to files to download" if FSPROVIDEROPT
+       default ""
+       help
+		This value is eval'd in the failsafe script, so if you use
+		something like $(ESCAPEDVAR)varname it will be replaced by
+		the runtime (on the router) value of $varname.  Also you can
+		use $(ESCAPEDVAR)(command) to cause this to be the value of
+		the output of command (via $(command)).
+
+config TARGET_FSPROVIDER_SETTINGS_FILE
+       string
+       prompt "Settings to download" if FSPROVIDEROPT
+       default "$(ESCAPEDVAR)mac-settings.tar.gz"
+       help
+		This value is eval'd in the failsafe script, so if you use
+		something like $(ESCAPEDVAR)varname it will be replaced by
+		the runtime (on the router) value of $varname.  Also you can
+		use $(ESCAPEDVAR)(command) to cause this to be the value of
+		the output of command (via $(command)).
+
+config TARGET_FSPROVIDER_FIRMWARE_FILE
+       string
+       prompt "Firmware to download" if FSPROVIDEROPT
+       default "$(ESCAPEDVAR)mac-firmware.bin"
+       help
+		This value is eval'd in the failsafe script, so if you use
+		something like $(ESCAPEDVAR)varname it will be replaced by
+		the runtime (on the router) value of $varname.  Also you can
+		use $(ESCAPEDVAR)(command) to cause this to be the value of
+		the output of command (via $(command)).
+
+config TARGET_FSPROVIDER_MD5SUM_FILE
+       string
+       prompt "MD5SUM files for files to download" if FSPROVIDEROPT
+       default "$(ESCAPEDVAR)mac-MD5SUMS"
+       help
+		This value is eval'd in the failsafe script, so if you use
+		something like $(ESCAPEDVAR)varname it will be replaced by
+		the runtime (on the router) value of $varname.  Also you can
+		use $(ESCAPEDVAR)(command) to cause this to be the value of
+		the output of command (via $(command)).
+
Index: utils/failsafe-provider-restore/Makefile
===================================================================
--- utils/failsafe-provider-restore/Makefile	(revision 0)
+++ utils/failsafe-provider-restore/Makefile	(revision 0)
@@ -0,0 +1,59 @@
+#
+# Copyright (C) 2009 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=failsafe-provider-restore
+PKG_VERSION:=0.0.1
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/failsafe-provider-restore
+  SECTION:=utils
+  CATEGORY:=Utilities
+  TITLE:=Failsafe mode autorestore to provider defaults
+  DEPENDS:=+curl
+endef
+
+define Package/failsafe-provider/description
+   When failsafe mode is entered (e.g. by pressing reset at the appropriate 
+   time), 'phone home' for provider default settings and/or firmware
+endef
+
+define Build/Prepare
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+ESCAPEDVAR=\$$$$
+
+define Package/failsafe-provider-restore/install
+	$(CP) -ar ./files/* $(1)/
+	mkdir -p $(1)/etc/preinit.d/conf.d	
+	echo 'fsprovider_timeout=$(if $(CONFIG_TARGET_FSPROVIDER_FS_TIMEOUT),$(CONFIG_TARGET_FSPROVIDER_FS_TIMEOUT),5)' >$(1)/etc/preinit.d/conf.d/50_fsprovider_timeout
+	echo 'fsprovider_reboot_timeout="$(if $(CONFIG_TARGET_FSPROVIDER_REBOOT_TIMEOUT),$(CONFIG_TARGET_FSPROVIDER_REBOOT_TIMEOUT),0)"' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_timeout
+	echo 'fsprovider_link_status_sleep=$(if $(CONFIG_TARGET_FSPROVIDER_LINK_STATUS_SLEEP),$(CONFIG_TARGET_FSPROVIDER_LINK_STATUS_SLEEP),10)' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_timeout
+	echo 'fsprovider_link_status_device_path=$(if $(CONFIG_TARGET_FSPROVIDER_LINK_STATUS_DEVICE_PATH),$(CONFIG_TARGET_FSPROVIDER_LINK_STATUS_DEVICE_PATH),"/sys/class/net/eth0/carrier")' >$(1)/etc/preinit.d/conf.d/50_fsprovider_link_status
+	echo 'fsprovider_ifname=$(if $(CONFIG_TARGET_FSPROVIDER_IFNAME),$(CONFIG_TARGET_FSPROVIDER_IFNAME),"eth0")' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_link_status
+	echo 'fsprovider_username=$(if $(CONFIG_TARGET_FSPROVIDER_USERNAME),$(CONFIG_TARGET_FSPROVIDER_USERNAME),"")' >$(1)/etc/preinit.d/conf.d/50_fsprovider_get_file_conf
+	echo 'fsprovider_password=$(if $(CONFIG_TARGET_FSPROVIDER_PASSWORD),$(CONFIG_TARGET_FSPROVIDER_PASSWORD),"")' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_get_file_conf
+	echo 'fsprovider_server=$(if $(CONFIG_TARGET_FSPROVIDER_SERVER),$(CONFIG_TARGET_FSPROVIDER_SERVER),"")' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_get_file_conf
+	echo 'fsprovider_server_dir=$(if $(CONFIG_TARGET_FSPROVIDER_SERVER_FILE_DIR),$(CONFIG_TARGET_FSPROVIDER_SERVER_FILE_DIR),"failsafe")' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_get_file_conf
+	echo 'fsprovider_settings_file=$(if $(CONFIG_TARGET_FSPROVIDER_SETTINGS_FILE),$(CONFIG_TARGET_FSPROVIDER_SETTINGS_FILE),"$(ESCAPEDVAR)mac-settings.tar.gz")' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_get_file_conf
+	echo 'fsprovider_firmware_file=$(if $(CONFIG_TARGET_FSPROVIDER_FIRMWARE_FILE),$(CONFIG_TARGET_FSPROVIDER_FIRMWARE_FILE),"$(ESCAPEDVAR)mac-firmware.bin")' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_get_file_conf
+	echo 'fsprovider_md5sum_file=$(if $(CONFIG_TARGET_FSPROVIDER_MD5SUM_FILE),$(CONFIG_TARGET_FSPROVIDER_MD5SUM_FILE),"$(ESCAPEDVAR)mac-MD5SUMS")' >>$(1)/etc/preinit.d/conf.d/50_fsprovider_get_file_conf
+	$(CP) -ar ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,failsafe-provider-restore))

Attachment: signature.asc
Description: PGP signature

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to