OSDN Git Service

init: do not mount /cache directly
[android-x86/bootable-newinstaller.git] / initrd / init
index 4756a38..9ca1621 100755 (executable)
@@ -3,7 +3,7 @@
 # By Chih-Wei Huang <cwhuang@linux.org.tw>
 # and Thorsten Glaser <tg@mirbsd.org>
 #
-# Last updated 2011/04/15
+# Last updated 2014/01/15
 #
 # License: GNU Public License
 # We explicitely grant the right to use the scripts
@@ -36,10 +36,12 @@ if test x"$HAS_CTTY" != x"Yes"; then
                # create device nodes then spawn on them
                mknod /dev/tty2 c 4 2 && openvt
                mknod /dev/tty3 c 4 3 && openvt
-       else
+       fi
+       if test -z "$DEBUG" || test -n "$INSTALL"; then
                echo 0 0 0 0 > /proc/sys/kernel/printk
        fi
        # initialise /dev (first time)
+       mkdir -p /dev/block
        echo /sbin/mdev > /proc/sys/kernel/hotplug
        mdev -s
        # re-run this script with a controlling tty
@@ -58,13 +60,56 @@ error()
 try_mount()
 {
        RW=$1; shift
+       if [ "${ROOT#*:/}" != "$ROOT" ]; then
+               # for NFS roots, use nolock to avoid dependency to portmapper
+               RW="nolock,$RW"
+       fi
        # FIXME: any way to mount ntfs gracefully?
        mount -o $RW $@ || mount.ntfs-3g -o rw,force $@
 }
 
+check_root()
+{
+       if [ "`dirname $1`" = "/dev" ]; then
+               [ -e $1 ] || return 1
+               blk=`basename $1`
+               [ ! -e /dev/block/$blk ] && ln $1 /dev/block
+               dev=/dev/block/$blk
+       else
+               dev=$1
+       fi
+       try_mount ro $dev /mnt || return 1
+       if [ -n "$iso" -a -e /mnt/$iso ]; then
+               mount --move /mnt /iso
+               mkdir /mnt/iso
+               mount -o loop /iso/$iso /mnt/iso
+               SRC=iso
+       elif [ ! -e /mnt/$SRC/ramdisk.img ]; then
+               return 1
+       fi
+       zcat /mnt/$SRC/ramdisk.img | cpio -id > /dev/null
+       if [ -e /mnt/$SRC/system.sfs ]; then
+               mount -o loop /mnt/$SRC/system.sfs /sfs
+               mount -o loop /sfs/system.img system
+       elif [ -e /mnt/$SRC/system.img ]; then
+               remount_rw
+               mount -o loop /mnt/$SRC/system.img system
+       elif [ -d /mnt/$SRC/system ]; then
+               remount_rw
+               mount --bind /mnt/$SRC/system system
+       else
+               rm -rf *
+               return 1
+       fi
+       mkdir mnt
+       echo " found at $1"
+}
+
 remount_rw()
 {
-       mount -o remount,rw /mnt
+       # "foo" as mount source is given to workaround a Busybox bug with NFS
+       # - as it's ignored anyways it shouldn't harm for other filesystems.
+       mount -o remount,rw foo /mnt
 }
 
 debug_shell()
@@ -80,33 +125,25 @@ debug_shell()
 
 echo -n Detecting Android-x86...
 
+[ -z "$SRC" -a -n "$BOOT_IMAGE" ] && SRC=`dirname $BOOT_IMAGE`
+
+for c in `cat /proc/cmdline`; do
+       case $c in
+               iso-scan/filename=*)
+                       eval `echo $c | cut -b1-3,18-`
+                       ;;
+               *)
+                       ;;
+       esac
+done
+
+mount -t tmpfs tmpfs /android
+cd /android
 while :; do
-       for device in /dev/sr* /dev/sd[a-z]*; do
-               try_mount ro $device /mnt || continue
-               cd /mnt/$SRC
-               if [ ! -e ramdisk.img -o ! \( -e system.sfs -o -e system.img -o -d system \) ]; then
-                       cd /
-                       umount /mnt
-                       continue
-               fi
-               mount -t tmpfs tmpfs /android
-               cd /android
-               zcat /mnt/$SRC/ramdisk.img | cpio -id > /dev/null
-               if [ -e /mnt/$SRC/system.sfs ]; then
-                       mount -o loop /mnt/$SRC/system.sfs /sfs
-                       mount -o loop /sfs/system.img system
-               elif [ -e /mnt/$SRC/system.img ]; then
-                       mount -o loop /mnt/$SRC/system.img system
-               else
-                       remount_rw
-                       mount --bind /mnt/$SRC/system system
-               fi
-               mkdir cache mnt mnt/sdcard
-               mount -t tmpfs tmpfs cache
-               echo " found at $device"
-               break
+       for device in ${ROOT:-/dev/[hmsv][dmr][0-9a-z]*}; do
+               check_root $device && break 2
+               mountpoint -q /mnt && umount /mnt
        done
-       mountpoint -q /android && break
        sleep 1
        echo -n .
 done
@@ -121,7 +158,7 @@ if [ -n "$INSTALL" ]; then
        zcat /src/install.img | cpio -iud > /dev/null
 fi
 
-if [ -n "$DEBUG" -o -n "$BUSYBOX" ]; then
+if [ -x system/bin/ln -a \( -n "$DEBUG" -o -n "$BUSYBOX" \) ]; then
        mv /bin /lib .
        system/bin/ln -s android/lib /lib
        system/bin/ln -s android/bin /bin
@@ -131,7 +168,10 @@ if [ -n "$DEBUG" -o -n "$BUSYBOX" ]; then
        ln -s android/sbin /
 fi
 
-if [ -n "$DEBUG" ]; then
+# ensure keyboard driver is loaded
+[ -n "$INSTALL" -o -n "$DEBUG" ] && modprobe atkbd
+
+if [ 0$DEBUG -gt 0 ]; then
        echo -e "\nType 'exit' to continue booting...\n"
        debug_shell debug-found
 fi
@@ -143,15 +183,7 @@ done
 
 # A target should provide its detect_hardware function.
 # On success, return 0 with the following values set.
-#
-# FB0DEV: framebuffer driver
-# LANDEV: lan driver
-# WIFDEV: wifi driver
-# SNDDEV: sound driver
-# CAMDEV: camera driver
-# PREDEV: any module the drivers depend on but can't be loaded automatically
-# EXTMOD: any other module
-
+# return 1 if it wants to use auto_detect
 [ "$AUTO" != "1" ] && detect_hardware && FOUND=1
 
 [ -n "$INSTALL" ] && do_install
@@ -160,16 +192,18 @@ load_modules
 mount_data
 mount_sdcard
 setup_tslib
+setup_dpi
 post_detect
 
-if [ -n "$DEBUG" ]; then
+if [ 0$DEBUG -gt 1 ]; then
        echo -e "\nUse Alt-F1/F2/F3 to switch between virtual consoles"
        echo -e "Type 'exit' to enter Android...\n"
 
        debug_shell debug-late
-       SWITCH=chroot
 fi
 
+[ -n "$DEBUG" ] && SWITCH=${SWITCH:-chroot}
+
 # We must disable mdev before switching to Android
 # since it conflicts with Android's init
 echo > /proc/sys/kernel/hotplug