mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2025-04-21 12:27:27 +03:00
add preinit modularization work by Daniel Dickinson (cshore)
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@19331 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
10
package/base-files/files/lib/firstboot/05_firstboot_skip
Normal file
10
package/base-files/files/lib/firstboot/05_firstboot_skip
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
check_skip() {
|
||||
if [ "$firsboot_skip_next" = "true" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
46
package/base-files/files/lib/firstboot/10_determine_parts
Normal file
46
package/base-files/files/lib/firstboot/10_determine_parts
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/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
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/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
|
||||
12
package/base-files/files/lib/firstboot/10_reset_has_mini_fo
Normal file
12
package/base-files/files/lib/firstboot/10_reset_has_mini_fo
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
reset_check_for_mini_fo() {
|
||||
if grep -q mini_fo /proc/filesystems; then
|
||||
reset_has_fo=true
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add jffs2reset reset_check_for_mini_fo
|
||||
13
package/base-files/files/lib/firstboot/20_has_mini_fo
Normal file
13
package/base-files/files/lib/firstboot/20_has_mini_fo
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
check_for_mini_fo() {
|
||||
if ! grep -q mini_fo /proc/filesystems; then
|
||||
boot_run_hook no_fo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add switch2jffs check_for_mini_fo
|
||||
15
package/base-files/files/lib/firstboot/20_no_fo_mount_jffs
Normal file
15
package/base-files/files/lib/firstboot/20_no_fo_mount_jffs
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
no_fo_mount_jffs() {
|
||||
# initialize jffs2
|
||||
mount "$mtdpart" /jffs -t jffs2 || exit
|
||||
|
||||
# workaround to ensure that union can attach properly
|
||||
sync
|
||||
ls /jffs >/dev/null
|
||||
}
|
||||
|
||||
boot_hook_add no_fo no_fo_mount_jffs
|
||||
14
package/base-files/files/lib/firstboot/20_reset_clear_jffs
Normal file
14
package/base-files/files/lib/firstboot/20_reset_clear_jffs
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/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
|
||||
10
package/base-files/files/lib/firstboot/30_is_rootfs_mounted
Normal file
10
package/base-files/files/lib/firstboot/30_is_rootfs_mounted
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
skip_if_rootfs_mounted() {
|
||||
mount "$mtdpart" /rom/jffs -t jffs2 || exit
|
||||
}
|
||||
|
||||
boot_hook_add switch2jffs skip_if_rootfs_mounted
|
||||
11
package/base-files/files/lib/firstboot/30_no_fo_pivot
Normal file
11
package/base-files/files/lib/firstboot/30_no_fo_pivot
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
no_fo_pivot() {
|
||||
# switch to the new (empty) jffs2
|
||||
fopivot /jffs /rom 1
|
||||
}
|
||||
|
||||
boot_hook_add no_fo no_fo_pivot
|
||||
13
package/base-files/files/lib/firstboot/30_reset_copy_rom
Normal file
13
package/base-files/files/lib/firstboot/30_reset_copy_rom
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/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
|
||||
15
package/base-files/files/lib/firstboot/40_copy_ramoverlay
Normal file
15
package/base-files/files/lib/firstboot/40_copy_ramoverlay
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/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/jffs 2>&-
|
||||
echo "done"
|
||||
}
|
||||
|
||||
boot_hook_add switch2jffs copy_ramoverlay
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/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
|
||||
17
package/base-files/files/lib/firstboot/50_pivot
Normal file
17
package/base-files/files/lib/firstboot/50_pivot
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/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
|
||||
|
||||
# /jffs is the overlay
|
||||
# /rom is the readonly
|
||||
fopivot /jffs /rom
|
||||
}
|
||||
|
||||
boot_hook_add switch2jffs with_fo_pivot
|
||||
13
package/base-files/files/lib/firstboot/99_10_no_fo_cleanup
Normal file
13
package/base-files/files/lib/firstboot/99_10_no_fo_cleanup
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
no_fo_cleanup() {
|
||||
echo "done"
|
||||
umount -l /jffs
|
||||
umount -l /tmp/root
|
||||
exit 0
|
||||
}
|
||||
|
||||
boot_hook_add no_fo no_fo_cleanup
|
||||
13
package/base-files/files/lib/firstboot/99_10_with_fo_cleanup
Normal file
13
package/base-files/files/lib/firstboot/99_10_with_fo_cleanup
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/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
|
||||
mount /tmp/root 2>&-
|
||||
exit 0
|
||||
}
|
||||
|
||||
boot_hook_add switch2jffs with_fo_cleanup
|
||||
95
package/base-files/files/lib/functions/boot.sh
Normal file
95
package/base-files/files/lib/functions/boot.sh
Normal file
@@ -0,0 +1,95 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
boot_hook_add() {
|
||||
local hook="${1}_hook"
|
||||
local value="$2"
|
||||
local sep=" "
|
||||
|
||||
eval "$hook=\"\${$hook:+\${$hook}\${value:+\$sep}}\$value\""
|
||||
}
|
||||
|
||||
boot_run_hook() {
|
||||
local boot_func
|
||||
for boot_func in $(eval "echo \"\$${1}_hook\""); do
|
||||
$boot_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)"
|
||||
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 ./jffs ./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/jffs /jffs 2>&-
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
fopivot() { # <rw_root> <ro_root> <dupe?>
|
||||
root=$1
|
||||
{
|
||||
if 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 root /tmp/root
|
||||
fopivot /tmp/root /rom 1
|
||||
}
|
||||
13
package/base-files/files/lib/preinit/05_mount_skip
Normal file
13
package/base-files/files/lib/preinit/05_mount_skip
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/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
|
||||
}
|
||||
|
||||
20
package/base-files/files/lib/preinit/10_check_for_mtd
Normal file
20
package/base-files/files/lib/preinit/10_check_for_mtd
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/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 rootfs_data /proc/mtd >/dev/null 2>/dev/null || {
|
||||
mount_no_mtd && pi_mount_skip_next=true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boot_hook_add preinit_mount_root check_for_mtd
|
||||
|
||||
25
package/base-files/files/lib/preinit/10_essential_fs
Normal file
25
package/base-files/files/lib/preinit/10_essential_fs
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
do_mount_procfs() {
|
||||
mount proc /proc -t proc
|
||||
}
|
||||
|
||||
do_mount_sysfs() {
|
||||
mount sysfs /sys -t sysfs
|
||||
}
|
||||
|
||||
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 tmpfs /tmp -t tmpfs -o size=$pi_size,nosuid,nodev,mode=1777
|
||||
}
|
||||
|
||||
boot_hook_add preinit_essential do_mount_procfs
|
||||
boot_hook_add preinit_essential do_mount_sysfs
|
||||
boot_hook_add preinit_essential do_mount_tmpfs
|
||||
|
||||
18
package/base-files/files/lib/preinit/10_indicate_failsafe
Normal file
18
package/base-files/files/lib/preinit/10_indicate_failsafe
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
# commands for emitting messages to network in failsafe mode
|
||||
|
||||
indicate_failsafe_led () {
|
||||
set_state failsafe
|
||||
}
|
||||
|
||||
indicate_failsafe() {
|
||||
echo "- failsafe -"
|
||||
preinit_net_echo "Entering Failsafe!\n"
|
||||
indicate_failsafe_led
|
||||
}
|
||||
|
||||
boot_hook_add failsafe indicate_failsafe
|
||||
|
||||
52
package/base-files/files/lib/preinit/10_indicate_preinit
Normal file
52
package/base-files/files/lib/preinit/10_indicate_preinit
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
preinit_ip() {
|
||||
# if the preinit interface isn't specified and ifname is set in
|
||||
# preinit.arch use that interface
|
||||
if [ -z "$pi_ifname" ]; then
|
||||
pi_ifname=$ifname
|
||||
fi
|
||||
|
||||
[ -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 0.0.0.0 down
|
||||
}
|
||||
}
|
||||
|
||||
preinit_net_echo() {
|
||||
[ -n "$pi_ifname" ] && grep "$pi_ifname" /proc/net/dev >/dev/null && {
|
||||
{
|
||||
[ "$pi_preinit_net_messages" = "y" ] || {
|
||||
[ "$pi_failsafe_net_message" = "true" ] &&
|
||||
[ "$pi_preinit_no_failsafe_netmsg" != "y" ]
|
||||
}
|
||||
|
||||
} && netmsg $pi_broadcast "$1"
|
||||
}
|
||||
}
|
||||
|
||||
preinit_echo() {
|
||||
preinit_net_echo $1
|
||||
echo $1
|
||||
}
|
||||
|
||||
pi_indicate_led() {
|
||||
set_state preinit
|
||||
}
|
||||
|
||||
pi_indicate_preinit() {
|
||||
echo "- preinit -"
|
||||
preinit_net_echo "Doing OpenWRT Preinit\n"
|
||||
pi_indicate_led
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main preinit_ip
|
||||
boot_hook_add preinit_main pi_indicate_preinit
|
||||
|
||||
19
package/base-files/files/lib/preinit/20_check_jffs2_ready
Normal file
19
package/base-files/files/lib/preinit/20_check_jffs2_ready
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/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
|
||||
|
||||
28
package/base-files/files/lib/preinit/20_device_fs_mount
Normal file
28
package/base-files/files/lib/preinit/20_device_fs_mount
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
do_mount_devfs() {
|
||||
mount devfs /dev -t devfs
|
||||
}
|
||||
|
||||
do_mount_hotplug() {
|
||||
mount -t tmpfs tmpfs /dev -o size=512K
|
||||
}
|
||||
|
||||
do_mount_udev() {
|
||||
mount -n -t tmpfs -o mode=0755 udev /dev
|
||||
}
|
||||
|
||||
choose_device_fs() {
|
||||
if grep devfs /proc/filesystems > /dev/null; 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
|
||||
|
||||
36
package/base-files/files/lib/preinit/30_device_fs_daemons
Normal file
36
package/base-files/files/lib/preinit/30_device_fs_daemons
Normal file
@@ -0,0 +1,36 @@
|
||||
#!/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 devfs /proc/filesystems > /dev/null; 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
|
||||
|
||||
86
package/base-files/files/lib/preinit/30_failsafe_wait
Normal file
86
package/base-files/files/lib/preinit/30_failsafe_wait
Normal file
@@ -0,0 +1,86 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
fs_wait_for_key () {
|
||||
local timeout=$3
|
||||
local timer
|
||||
local do_failsafe
|
||||
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 'true' >$keypress_true; lock -u $keypress_wait ; rm -f $keypress_wait" INT
|
||||
trap "echo 'true' >$keypress_true; lock -u $keypress_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
|
||||
do_failsafe=""
|
||||
{
|
||||
read -t "$timer" do_failsafe
|
||||
if [ "$do_failsafe" = "$1" ]; then
|
||||
echo "true" >$keypress_true
|
||||
lock -u $keypress_wait
|
||||
rm -f $keypress_wait
|
||||
fi
|
||||
}
|
||||
done
|
||||
}
|
||||
lock -w $keypress_wait
|
||||
|
||||
trap - INT
|
||||
trap - USR1
|
||||
|
||||
keypressed=1
|
||||
[ "$(cat $keypress_true)" = "true" ] && keypressed=0
|
||||
rm -f $keypress_true
|
||||
rm -f $keypress_wait
|
||||
rm -f $keypress_sec
|
||||
|
||||
return $keypressed
|
||||
}
|
||||
|
||||
failsafe_wait() {
|
||||
FAILSAFE=
|
||||
pi_failsafe_net_message=true
|
||||
preinit_net_echo "Please press button now to enter failsafe"
|
||||
pi_failsafe_net_message=false
|
||||
echo -n "Press CTRL-C or "
|
||||
fs_wait_for_key f 'to enter failsafe mode' $fs_failsafe_wait_timeout && FAILSAFE=true && export FAILSAFE
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main failsafe_wait
|
||||
|
||||
10
package/base-files/files/lib/preinit/40_init_shm
Normal file
10
package/base-files/files/lib/preinit/40_init_shm
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/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
|
||||
|
||||
15
package/base-files/files/lib/preinit/40_mount_devpts
Normal file
15
package/base-files/files/lib/preinit/40_mount_devpts
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/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 devpts /dev/pts -t devpts
|
||||
}
|
||||
|
||||
boot_hook_add preinit_essential init_devpts
|
||||
boot_hook_add preinit_essential do_mount_devpts
|
||||
|
||||
24
package/base-files/files/lib/preinit/40_mount_jffs2
Normal file
24
package/base-files/files/lib/preinit/40_mount_jffs2
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
find_mount_jffs2() {
|
||||
mount "$(find_mtd_part rootfs_data)" /jffs -t jffs2
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
13
package/base-files/files/lib/preinit/40_run_failsafe_hook
Normal file
13
package/base-files/files/lib/preinit/40_run_failsafe_hook
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
run_failsafe_hook() {
|
||||
if [ "$FAILSAFE" = "true" ]; then
|
||||
boot_run_hook failsafe
|
||||
lock -w /tmp/.failsafe
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main run_failsafe_hook
|
||||
|
||||
31
package/base-files/files/lib/preinit/50_choose_console
Normal file
31
package/base-files/files/lib/preinit/50_choose_console
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/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 devfs /proc/filesystems > /dev/null; 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
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
indicate_regular_preinit() {
|
||||
echo "- regular preinit -"
|
||||
preinit_net_echo "Continuing with Regular Preinit\n"
|
||||
pi_indicate_led
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main indicate_regular_preinit
|
||||
|
||||
10
package/base-files/files/lib/preinit/60_init_hotplug
Normal file
10
package/base-files/files/lib/preinit/60_init_hotplug
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/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
|
||||
|
||||
13
package/base-files/files/lib/preinit/70_initramfs_test
Normal file
13
package/base-files/files/lib/preinit/70_initramfs_test
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
initramfs_test() {
|
||||
if [ -n "$INITRAMFS" ]; then
|
||||
boot_run_hook initramfs
|
||||
break
|
||||
fi
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main initramfs_test
|
||||
|
||||
13
package/base-files/files/lib/preinit/70_pivot_jffs2_root
Normal file
13
package/base-files/files/lib/preinit/70_pivot_jffs2_root
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006-2010 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
rootfs_pivot() {
|
||||
check_skip || jffs2_not_mounted || {
|
||||
echo "switching to jffs2"
|
||||
fopivot /jffs /rom && pi_mount_skip_next=true
|
||||
}
|
||||
}
|
||||
|
||||
boot_hook_add preinit_mount_root rootfs_pivot
|
||||
|
||||
10
package/base-files/files/lib/preinit/80_mount_root
Normal file
10
package/base-files/files/lib/preinit/80_mount_root
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
do_mount_root() {
|
||||
boot_run_hook preinit_mount_root
|
||||
}
|
||||
|
||||
boot_hook_add preinit_main do_mount_root
|
||||
|
||||
14
package/base-files/files/lib/preinit/90_init_console
Normal file
14
package/base-files/files/lib/preinit/90_init_console
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/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
|
||||
|
||||
12
package/base-files/files/lib/preinit/90_mount_no_jffs2
Normal file
12
package/base-files/files/lib/preinit/90_mount_no_jffs2
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/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
|
||||
|
||||
17
package/base-files/files/lib/preinit/90_restore_config
Normal file
17
package/base-files/files/lib/preinit/90_restore_config
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/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
|
||||
|
||||
18
package/base-files/files/lib/preinit/99_10_failsafe_login
Normal file
18
package/base-files/files/lib/preinit/99_10_failsafe_login
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
failsafe_netlogin () {
|
||||
telnetd -l /bin/login.sh <> /dev/null 2>&1
|
||||
}
|
||||
|
||||
failsafe_shell() {
|
||||
lock /tmp/.failsafe
|
||||
ash --login
|
||||
echo "Please reboot system when done with failsafe network logins"
|
||||
}
|
||||
|
||||
|
||||
boot_hook_add failsafe failsafe_netlogin
|
||||
boot_hook_add failsafe failsafe_shell
|
||||
|
||||
12
package/base-files/files/lib/preinit/99_10_mount_no_mtd
Normal file
12
package/base-files/files/lib/preinit/99_10_mount_no_mtd
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/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
|
||||
|
||||
16
package/base-files/files/lib/preinit/99_10_run_init
Normal file
16
package/base-files/files/lib/preinit/99_10_run_init
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
# Copyright (C) 2010 Vertical Communications
|
||||
|
||||
run_init() {
|
||||
preinit_echo "- init -"
|
||||
preinit_ip_deconfig
|
||||
if [ "$pi_init_stderr_suppress" = "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
|
||||
|
||||
Reference in New Issue
Block a user