Newer
Older
#!/bin/sh
mount -t proc proc /proc
mount -t sysfs sysfs /sys
sleep 1
/sbin/mdev -s
hostname kobo
ifconfig lo up
echo 3 > /sys/class/graphics/fb0/rotate
# Upgrading kernel if needed
mount /dev/mmcblk0p1 /mnt
KERNEL_FLASH=`cat /mnt/flags/KERNEL_FLASH` 2>/dev/null
WILL_UPDATE=`cat /mnt/flags/WILL_UPDATE` 2>/dev/null
DIAGS_BOOT=`cat /mnt/flags/DIAGS_BOOT` 2>/dev/null
STARTX=`cat /mnt/flags/X11_START` 2>/dev/null
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
if [ "$KERNEL_FLASH" == "true" ]; then
cp /mnt/boot/uImage /
sync
echo "Flashing new kernel..."
dd if=/uImage of=/dev/mmcblk0 bs=512 seek=2048
sync
echo "false" > /mnt/flags/KERNEL_FLASH
rm /mnt/boot/uImage
echo "Done, rebooting..."
reboot
else
umount /mnt
evtest /dev/input/event0 > /tmp/input-log &
read -t 3 -n 1 -s -r -p "Hit any key to stop auto-boot... " KEY
if [ "$KEY" == "" ]; then
INPUT_LOG=`cat /tmp/input-log | grep value`
export INPUT_LOG
# Device should have been wiped and restored to a factory state
# Checking if there is still a "noroot" flag in the unpartitioned space
export ROOT_FLAG=`dd if=/dev/mmcblk0 bs=512 skip=79872 count=1 status=none | head -c6`
if [ "$ROOT_FLAG" = "rooted" ]; then
echo "Security policy not enforced; root access permitted."
else
mount /dev/mmcblk0p3 /mnt
mount /dev/mmcblk0p1 /mnt/boot
echo "WARNING: User violated security policy!"
echo "Flashing a new kernel that does not allow root access..."
mkdir -p /recoveryfs
mount /dev/mmcblk0p2 /recoveryfs
dd if=/recoveryfs/opt/recovery/restore/uImage-std of=/dev/mmcblk0 bs=512 seek=2048
sync
rm /mnt/etc/passwd
sync
cp /opt/passwd_lockdown /mnt/etc/passwd
sync
# We set the ALERT flag to show a GUI warning about what happened
echo "true" > /mnt/boot/flags/ALERT
sync
echo "Done, rebooting..."
reboot
exit 0
fi
if [ "$INPUT_LOG" == "" ]; then
if [ "$DIAGS_BOOT" != "true" ]; then
# If the security policy was violated, we would not be there anymore, so from now on we are booting as usual.
mount /dev/mmcblk0p3 /mnt
mount /dev/mmcblk0p1 /mnt/boot
mkdir -p /mnt/opt/root
mkdir -p /mnt/opt/key
mkdir -p /mnt/selinux
losetup /dev/loop7 /opt/root.sqsh
mount /dev/loop7 /mnt/opt/root -o ro,nodev,nosuid,noexec
losetup /dev/loop6 /opt/key.sqsh
mount /dev/loop6 /mnt/opt/key -o ro,nodev,nosuid,noexec
mount --move /proc /mnt/proc
mount --move /sys /mnt/sys
mount -t devtmpfs devtmpfs /mnt/dev
mount -t tmpfs tmpfs /mnt/tmp
mount -t selinuxfs selinuxfs /mnt/selinux
# Starting an X server
if [ "$STARTX" == "true" ]; then
/etc/init.d/startx
fi
chroot /mnt /sbin/openrc "sysinit"
chroot /mnt /sbin/openrc "boot"
chroot /mnt /sbin/openrc "default"
exit 0
else
echo "DIAGS_BOOT is set to 'true', booting into diagnostics..."
mkdir -p /alpine
mount /dev/mmcblk0p2 /mnt -o ro
mount /dev/mmcblk0p1 /mnt/boot
losetup /dev/loop7 /opt/root.sqsh
mount /dev/loop7 /mnt/opt/root -o ro,nodev,nosuid,noexec
losetup /dev/loop6 /opt/key.sqsh
mount /dev/loop6 /mnt/opt/key -o ro,nodev,nosuid,noexec
mount /mnt/opt/recovery/restore/alpine-udev.sqsh /alpine
mount --bind /proc /mnt/proc
mount --bind /proc /alpine/proc
mount --bind /sys /mnt/sys
mount --bind /sys /alpine/sys
mount -t devtmpfs devtmpfs /mnt/dev
mount -t devtmpfs devtmpfs /alpine/dev
mount -t tmpfs tmpfs /mnt/tmp
mount -t tmpfs tmpfs /alpine/tmp
mount -t tmpfs tmpfs /alpine/run
chroot /alpine /sbin/openrc "sysinit"
chroot /mnt /opt/bin/diagnostics_splash
sleep 2
chroot /mnt /opt/recovery/launch.sh &
exit 0
fi
else
echo "Input event caught, booting into recovery partition..."
mkdir -p /alpine
mount /dev/mmcblk0p2 /mnt -o ro
mount /dev/mmcblk0p1 /mnt/boot
losetup /dev/loop7 /opt/root.sqsh
mount /dev/loop7 /mnt/opt/root -o ro,nodev,nosuid,noexec
losetup /dev/loop6 /opt/key.sqsh
mount /dev/loop6 /mnt/opt/key -o ro,nodev,nosuid,noexec
mount /mnt/opt/recovery/restore/alpine-udev.sqsh /alpine
mount --bind /proc /mnt/proc
mount --bind /proc /alpine/proc
mount --bind /sys /mnt/sys
mount --bind /sys /alpine/sys
mount -t devtmpfs devtmpfs /mnt/dev
mount -t devtmpfs devtmpfs /alpine/dev
mount -t tmpfs tmpfs /mnt/tmp
mount -t tmpfs tmpfs /alpine/tmp
mount -t tmpfs tmpfs /alpine/run
chroot /alpine /sbin/openrc "sysinit"
chroot /mnt /opt/bin/diagnostics_splash
sleep 2
chroot /mnt /opt/recovery/launch.sh &
exit 0
fi
else
rm /usr/sbin/chroot
echo -e "#!/bin/sh\n\n/sbin/getty -L ttymxc0 115200 vt100" > /usr/sbin/chroot
chmod +x /usr/sbin/chroot
exit 0
fi
fi