From b13358c51a603509c951f7ea85e122398ca98a26 Mon Sep 17 00:00:00 2001
From: doniks
Date: Thu, 25 Jan 2018 23:56:55 +0100
Subject: [PATCH] log to kmsg and enter telnet upon mount failure
Change-Id: Ia3c1557c407b22af01cf5f65815cff173b572e52
---
init-script | 63 +++++++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 19 deletions(-)
diff --git a/init-script b/init-script
index 61b1986..7a234e1 100755
--- a/init-script
+++ b/init-script
@@ -23,11 +23,22 @@
set -x
exec > /init.log 2>&1
echo "Running Mer Boat Loader"
+[ -f /dev/kmsg ] || mknod -m 600 /dev/kmsg c 1 11
BOOTLOGO=%BOOTLOGO%
ALWAYSDEBUG=%ALWAYSDEBUG%
DATA_PARTITION=%DATA_PART%
DEFAULT_OS=%DEFAULT_OS%
+DEBUG_REASON=
+
+log(){
+ # log to std out
+ echo "$*"
+
+ # log to kernel log
+ [ -w /dev/kmsg ] && echo "init-script: $*" >> /dev/kmsg
+}
+
set_welcome_msg(){
cat < /etc/issue.net
@@ -108,7 +119,7 @@ get_opt() {
# Minimal mounts for initrd or pre-init debug session
do_mount_devprocsys()
{
- echo "########################## mounting devprocsys"
+ log "mounting devprocsys"
mkdir /dev
mount -t devtmpfs devtmpfs /dev
# telnetd needs /dev/pts/ entries
@@ -137,20 +148,32 @@ bootsplash() {
mount_stowaways() {
- echo "########################## mounting stowaways"
+ log "mounting stowaways DATA_PARTITION=\"$DATA_PARTITION\", data_subdir=\"$data_subdir\""
if [ ! -z $DATA_PARTITION ]; then
data_subdir="$(get_opt data_subdir)"
- mkdir /data
- mkdir /target
-
- mount $DATA_PARTITION /data
- mount /data/rootfs.img /target
+ mkdir /data
+ mount $DATA_PARTITION /data
+ retval=$?
+ if [ $retval -ne 0 ] ; then
+ log "Failed to mount /data [$retval]" >> /diagnosis.log
+ DEBUG_REASON="/data not mounted"
+ return
+ fi
+
+ mkdir /target
+ mount /data/rootfs.img /target
+ retval=$?
+ if [ $retval -ne 0 ] ; then
+ log "Failed to mount /target [$retval]" >> /diagnosis.log
+ DEBUG_REASON="/target not mounted"
+ return
+ fi
mkdir -p /target/data # in new fs
mount --bind /data/${data_subdir} /target/data
else
- echo "Failed to mount /target, device node '$DATA_PARTITION' not found!" >> /diagnosis.log
+ log "Failed to mount /target, device node '$DATA_PARTITION' not found!" >> /diagnosis.log
fi
mount
}
@@ -176,7 +199,7 @@ inject_loop() {
mkfifo $INJ_STDIN
echo "This entire directory is for debugging init - it can safely be removed" > $INJ_DIR/README
- echo "########################## Beginning inject loop"
+ log "Beginning inject loop"
while : ; do
while read IN; do
if [ "$IN" = "continue" ]; then break 2;fi
@@ -184,7 +207,7 @@ inject_loop() {
done <$INJ_STDIN
done
rm -rf $INJ_DIR # Clean up if we exited nicely
- echo "########################## inject loop done"
+ log "inject loop done"
}
# This sets up the USB with whatever USB_FUNCTIONS are set to
@@ -202,18 +225,18 @@ usb_setup() {
write $ANDROID_USB/functions $USB_FUNCTIONS
write $ANDROID_USB/enable 1
}
+
# This lets us communicate errors to host (if it needs disable/enable then that's a problem)
usb_info() {
# make sure USB is settled
- echo "########################## usb_info: $1"
+ log "usb_info: $1"
sleep 1
write $ANDROID_USB/iSerial "$1"
}
-
run_debug_session() {
CUSTOMPRODUCT=$1
- echo "########################## Debug session : $1"
+ log "run_debug_session : $1"
usb_setup "Mer Debug setting up (DONE_SWITCH=$DONE_SWITCH)"
USB_IFACE=notfound
@@ -240,7 +263,7 @@ run_debug_session() {
echo "option subnet 255.255.255.0" >> /etc/udhcpd.conf
# Be explicit about busybox so this works in a rootfs too
- echo "########################## starting dhcpd"
+ log "starting dhcpd"
$EXPLICIT_BUSYBOX udhcpd
HALT_BOOT="${2:-y}"
@@ -248,7 +271,7 @@ run_debug_session() {
if [ -z $DISABLE_TELNET ]; then
# Non-blocking telnetd
- echo "########################## starting telnetd"
+ log "starting telnetd"
# We run telnetd on different ports pre/post-switch_root This
# avoids problems with an unterminated pre-switch_root telnetd
# hogging the port
@@ -273,9 +296,9 @@ run_debug_session() {
# writes to /diagnosis.log if there's a problem
check_kernel_config() {
- echo "Checking kernel config"
+ log "Checking kernel config"
if [ ! -e /proc/config.gz ]; then
- echo "No /proc/config.gz. Enable CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC" >> /diagnosis.log
+ log "No /proc/config.gz. Enable CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC" >> /diagnosis.log
else
# Must be =y
for x in CONFIG_CGROUPS CONFIG_AUTOFS4_FS CONFIG_DEVTMPFS_MOUNT CONFIG_DEVTMPFS CONFIG_UNIX CONFIG_INOTIFY_USER CONFIG_SYSVIPC CONFIG_NET CONFIG_PROC_FS CONFIG_SIGNALFD CONFIG_SYSFS CONFIG_TMPFS_POSIX_ACL CONFIG_VT; do
@@ -318,6 +341,7 @@ if [ "$DONE_SWITCH" = "no" ]; then
[ x$ALWAYSDEBUG = x1 ] && DBG_REASON="Always debug: rndis + mass_storage"
[ -f /target/init_enter_debug ] && DBG_REASON="/init_enter_debug exists"
[ -f /target/init_disable_telnet ] && DISABLE_TELNET="y"
+ log "DBG_REASON=\"$DBG_REASON\""
if ! [ "$DBG_REASON" = "" ] ; then
# During debug we export mmc too (some variations in location here)
@@ -346,12 +370,12 @@ if [ "$DONE_SWITCH" = "no" ]; then
echo "" > /proc/sys/kernel/hotplug
if [ -f "/target/init-debug" ]; then
- echo "hybris-boot: Running init-debug" > /target/data/init-debug-stderrout
+ log "exec switch_root /target /init-debug" > /target/data/init-debug-stderrout
exec switch_root /target /init-debug >> /target/data/init-debug-stderrout 2>&1
else
# Prefer /sbin/preinit over /sbin/init
[ -x /target/sbin/preinit ] && INIT=/sbin/preinit || INIT=/sbin/init
- echo "hybris-boot: Booting $INIT in real rootfs" > /target/data/init-stderrout
+ log "exec switch_root /target $INIT" > /target/data/init-stderrout
exec switch_root /target $INIT >> /target/data/init-stderrout 2>&1
fi
run_debug_session "Failed to boot init in real rootfs"
@@ -374,6 +398,7 @@ else
# Now try to boot the real init
# Prefer /sbin/preinit over /sbin/init
[ -x /sbin/preinit ] && INIT=/sbin/preinit || INIT=/sbin/init
+ log "exec $INIT"
exec $INIT &> /boot/systemd_stdouterr
run_debug_session "init in real rootfs failed"
fi