手機 - Motorola XT897 - Sailfish OS - Initramfs Debugging



參考資訊:
https://github.com/mer-hybris/hybris-boot

init

#!/bin/sh
set -x
exec > /init.log 2>&1
echo "running initramfs loader..."

LOCAL_IP=192.168.2.15
ANDROID_USB=/sys/class/android_usb/android0

#echo "ls -l /" >/init-ctl/stdin
#echo "continue" >/init-ctl/stdin

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
/bin/busybox --install -s

mkdir -p /dev
mount -t devtmpfs devtmpfs /dev
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
mkdir -p /proc
mkdir -p /sys
mount -t sysfs sysfs /sys
mount -t proc proc /proc
mkdir -p /config

echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
sleep 3

ln -s . /dev/block
ln -s /proc/mounts /etc/mtab

mkdir /mnt
mount /dev/mmcblk0p39 /mnt
echo /dev/mmcblk0 > /sys/class/android_usb/f_mass_storage/lun/file
    
echo 0                  > $ANDROID_USB/enable
echo ""                 > $ANDROID_USB/functions
echo 1                  > $ANDROID_USB/enable
usleep 500000
echo 0                  > $ANDROID_USB/enable
echo 18D1               > $ANDROID_USB/idVendor
echo D001               > $ANDROID_USB/idProduct
echo "MyLoader"         > $ANDROID_USB/iManufacturer
echo "initramfs"        > $ANDROID_USB/iProduct
echo "v1.0"             > $ANDROID_USB/iSerial
echo rndis,mass_storage > $ANDROID_USB/functions
echo 1                  > $ANDROID_USB/enable

/sbin/ifconfig rndis0 $LOCAL_IP
echo "start 192.168.2.20"             > /etc/udhcpd.conf
echo "end 192.168.2.90"              >> /etc/udhcpd.conf
echo "lease_file /var/udhcpd.leases" >> /etc/udhcpd.conf
echo "interface rndis0"              >> /etc/udhcpd.conf
echo "option subnet 255.255.255.0"   >> /etc/udhcpd.conf

udhcpd
telnetd -b ${LOCAL_IP}:23 -l /bin/sh

INJ_DIR=/init-ctl
INJ_STDIN=$INJ_DIR/stdin

mkdir $INJ_DIR
mkfifo $INJ_STDIN
while : ; do
  while read IN; do
  if [ "$IN" = "continue" ]; then break 2;fi
    $IN
  done <$INJ_STDIN
done
rm -rf $INJ_DIR

killall telnetd
killall udhcpd

echo "" > /proc/sys/kernel/hotplug
exec switch_root /mnt /sbin/init

步驟如下:
1. 下載https://github.com/steward-fu/website/releases/download/xt897/myloader.tar.gz
2. 透過Recovery刷入boot.zip
3. 開機後,連接USB至PC
4. 執行如下命令進行連線

$ telnet 192.168.2.15
  Trying 192.168.2.15...
  Connected to 192.168.2.15.
  Escape character is '^]'.

~ # ls
  bin       config    dev       etc       init      init-ctl  init.log  mnt       proc      root      sbin      sys       usr