Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log to kmsg and enter telnet upon mount failure #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions init-script
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF > /etc/issue.net
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -176,15 +199,15 @@ 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
$IN
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
Expand All @@ -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
Expand All @@ -240,15 +263,15 @@ 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}"
set_welcome_msg $HALT_BOOT

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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand All @@ -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