WIP: Use kexec to boot Tizen
[platform/core/system/initrd-recovery.git] / src / initrd-recovery / init
1 #!/bin/sh
2
3 export PATH=/usr/bin:/bin:/usr/sbin:/sbin
4
5 FAKE_ROOT=/system
6 FAKE_ROOT_RO=/system-ro
7 INFORM_PATH=/mnt/inform
8 BOOT_PATH=/boot
9 REBOOT_PARAM_PATH=${INFORM_PATH}/reboot-param.bin
10
11 reboot_upgrade_val=upgr
12 reboot_recovery_val=rcvr
13 reboot_nodef_val=ndef
14 reboot_download_val=dwnl
15
16 STATUS_DIR=${FAKE_ROOT}/opt/data/recovery
17 STATUS_FILE=${STATUS_DIR}/RW.STATUS
18 DELTA_PATH_FILE=${STATUS_DIR}/DELTA.PATH
19
20 SYNC="/bin/sync"
21 MKDIR="/bin/mkdir"
22 MOUNT="/bin/mount"
23 UMOUNT="/bin/umount"
24 REBOOT="/sbin/reboot"
25 BLKID="/usr/sbin/blkid"
26
27
28 #------------------------------------------------
29 #       mount_partitions
30 #------------------------------------------------
31 mount_apifs() {
32     "$MOUNT" -t proc none /proc
33     "$MOUNT" -t sysfs none /sys
34     "$MOUNT" -t smackfs smackfs /smack
35     "$MOUNT" -t tmpfs tmpfs /run -o rw,nosuid,nodev,mode=755
36     "$MOUNT" -t tmpfs tmpfs /tmp -o mode=1777,smackfsroot=*
37
38     "$MKDIR" /dev/pts
39     "$MOUNT" -t devpts devpts /dev/pts
40 }
41
42 #------------------------------------------------
43 #       mount_inform
44 #------------------------------------------------
45 mount_partitions() {
46     PART_BOOT=$("$BLKID" -L "BOOT" -o device)
47     if [ "z$PART_BOOT" != "z" ]; then
48         "$MKDIR" -p ${BOOT_PATH}
49         "$MOUNT" -t vfat ${PART_BOOT} ${BOOT_PATH}
50     fi
51
52     PART_INFORM=$("$BLKID" -L "inform" -o device)
53     if [ "z$PART_INFORM" != "z" ]; then
54         "$MKDIR" -p ${INFORM_PATH}
55         "$MOUNT" -t ext4 ${PART_INFORM} ${INFORM_PATH}
56     fi
57 }
58
59 #------------------------------------------------
60 #       do_reboot
61 #------------------------------------------------
62 do_reboot() {
63     echo "Reboot"
64     "$UMOUNT" "$INFORM_PATH"
65     "$UMOUNT" "$BOOT_PATH"
66     "$SYNC"
67     "$REBOOT"
68     while [ 1 ]
69     do
70         sleep 1
71         echo "."
72     done
73 }
74
75 #------------------------------------------------
76 #       Main Routine Start
77 #------------------------------------------------
78 echo "You entered into /sbin/init on initrd"
79
80 mount_apifs
81 mount_partitions
82
83 cd /
84
85 BOOT_MODE=normal
86
87 # Logic from boot.scr
88 if [ -f "$REBOOT_PARAM_PATH" ]; then
89     REBOOT_PARAM="$(cat $REBOOT_PARAM_PATH)"
90     if [ "$REBOOT_PARAM" = "$reboot_upgrade_val" ]; then
91         BOOT_MODE=fota
92     elif [ "$REBOOT_PARAM" = "$reboot_recovery_val" ]; then
93         BOOT_MODE=recovery
94     elif [ "$REBOOT_PARAM" = "$reboot_download_val" ]; then
95         BOOT_MODE=flash
96     elif [ "$REBOOT_PARAM" = "$reboot_nodef_val" ]; then
97         echo "This reboot parameter is not supported..."
98     fi
99 fi
100
101 echo "BOOTMODE is ${BOOT_MODE}"
102
103 if [ -f /sbin/${BOOT_MODE}-init ]; then
104     exec "/sbin/${BOOT_MODE}-init"
105 else
106     echo "no ${BOOT_MODE}-init!!"
107     echo "Do reboot!!"
108     do_reboot
109 fi