Skip to content

Instantly share code, notes, and snippets.

@ppoffice
Last active March 14, 2023 23:44
Show Gist options
  • Save ppoffice/4c5cd790f4f1d441dab7229ad8572ec7 to your computer and use it in GitHub Desktop.
Save ppoffice/4c5cd790f4f1d441dab7229ad8572ec7 to your computer and use it in GitHub Desktop.
LG Nexus 5 Ubuntu Xfce4 Desktop with X11 fbdev and evdev
# recompile kernel first with patch:
# https://github.com/postmarketOS/pmbootstrap/blob/4b10acc2535033414cd4f358433a51626096d7ce/aports/device/linux-lg-hammerhead/06_fix_mdss_fb_rgb_mode.patch
git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8 \
-b marshmallow-mr1-release \
~/arm-eabi-4.8
git clone https://android.googlesource.com/kernel/msm \
-b android-msm-hammerhead-3.4-marshmallow-mr1 \
~/msm
git clone https://github.com/osm0sis/mkbootimg.git ~/mkbootimg
cd ~/msm
git checkout cf10b7e
export ARCH=arm
export CROSS_COMPILE=$HOME/arm-eabi-4.8/bin/arm-eabi-
make hammerhead_defconfig
# apply the above patch before make
make
cd ~/mkbootimg
make
# download stock Nexus 5 OS image and repack boot.img
# offsets should be changed to the values printed out by unpackbootimg
cd ~
mkdir boot/
~/mkbootimg/unpackbootimg -i boot.img -o boot/
./mkbootimg/mkbootimg \
--kernel msm/arch/arm/boot/zImage-dtb \
--ramdisk boot/boot.img-ramdisk.gz \
--cmdline "console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1" \
--base 0 \
--pagesize 2048 \
--kernel_offset 0x00008000 \
--ramdisk_offset 0x02900000 \
--second_offset 0x00f00000 \
--tags_offset 0x02700000 \
-o boot-new.img
# flash new boot.img to device
adb reboot bootloader
fastboot flash boot boot-new.img
# first install debootstrap in termux
pkg update
pkg install debootstrap
# flash new kernel & flash Magisk & install termux v0.75 & run via adb
su
# stop Android Surfaceflinger in adb shell
stop
export ARCH=arm
export PATH=/data/data/com.termux/files/usr/bin:/data/data/com.termux/files/usr/bin/applets
export LD_LIBRARY_PATH=/data/data/com.termux/files/usr/lib
export CHROOT_ROOT=/data/data/com.termux/files/home/rootfs
# clean up last build
umount $CHROOT_ROOT/proc
umount $CHROOT_ROOT/sys
umount $CHROOT_ROOT/dev
rm -rf $CHROOT_ROOT
# create rootfs
debootstrap --no-check-gpg --arch=$ARCH --variant=buildd bionic $CHROOT_ROOT http://ports.ubuntu.com/ubuntu-ports
echo "127.0.0.1 localhost" > $CHROOT_ROOT/etc/hosts
echo "91.189.88.150 ports.ubuntu.com" >> $CHROOT_ROOT/etc/hosts
echo "nameserver 8.8.8.8" > $CHROOT_ROOT/etc/resolv.conf
echo "nameserver 8.8.4.4" >> $CHROOT_ROOT/etc/resolv.conf
echo "deb http://ports.ubuntu.com/ubuntu-ports bionic main universe" > $CHROOT_ROOT/etc/apt/sources.list
echo "deb http://ports.ubuntu.com/ubuntu-ports bionic-updates main universe" >> $CHROOT_ROOT/etc/apt/sources.list
echo "deb http://ports.ubuntu.com/ubuntu-ports bionic-security main universe" >> $CHROOT_ROOT/etc/apt/sources.list
# fix soft links
rm -rf $CHROOT_ROOT/bin/.l2s.bunzip2.dpkg-new0001 && ln -s /bin/.l2s.bunzip2.dpkg-new0001.0003 $CHROOT_ROOT/bin/.l2s.bunzip2.dpkg-new0001
rm -rf $CHROOT_ROOT/bin/.l2s.gunzip.dpkg-new0001 && ln -s /bin/.l2s.gunzip.dpkg-new0001.0002 $CHROOT_ROOT/bin/.l2s.gunzip.dpkg-new0001
rm -rf $CHROOT_ROOT/bin/bunzip2 && ln -s /bin/.l2s.bunzip2.dpkg-new0001 $CHROOT_ROOT/bin/bunzip2
rm -rf $CHROOT_ROOT/bin/bzcat && ln -s /bin/.l2s.bunzip2.dpkg-new0001 $CHROOT_ROOT/bin/bzcat
rm -rf $CHROOT_ROOT/bin/bzip2 && ln -s /bin/.l2s.bunzip2.dpkg-new0001 $CHROOT_ROOT/bin/bzip2
rm -rf $CHROOT_ROOT/bin/gunzip && ln -s /bin/.l2s.gunzip.dpkg-new0001 $CHROOT_ROOT/bin/gunzip
rm -rf $CHROOT_ROOT/bin/uncompress && ln -s /bin/.l2s.gunzip.dpkg-new0001 $CHROOT_ROOT/bin/uncompress
rm -rf $CHROOT_ROOT/usr/bin/.l2s.perl.dpkg-new0002 && ln -s /usr/bin/.l2s.perl.dpkg-new0002.0002 $CHROOT_ROOT/usr/bin/.l2s.perl.dpkg-new0002
rm -rf $CHROOT_ROOT/usr/bin/.l2s.perlbug.dpkg-new0001 && ln -s /usr/bin/.l2s.perlbug.dpkg-new0001.0002 $CHROOT_ROOT/usr/bin/.l2s.perlbug.dpkg-new0001
rm -rf $CHROOT_ROOT/usr/bin/perl && ln -s /usr/bin/.l2s.perl.dpkg-new0002 $CHROOT_ROOT/usr/bin/perl
rm -rf $CHROOT_ROOT/usr/bin/perl5.26.1 && ln -s /usr/bin/.l2s.perl.dpkg-new0002 $CHROOT_ROOT/usr/bin/perl5.26.1
rm -rf $CHROOT_ROOT/usr/bin/perlbug && ln -s /usr/bin/.l2s.perlbug.dpkg-new0001 $CHROOT_ROOT/usr/bin/perlbug
rm -rf $CHROOT_ROOT/usr/bin/perlthanks && ln -s /usr/bin/.l2s.perlbug.dpkg-new0001 $CHROOT_ROOT/usr/bin/perlthanks
# enter chroot
mount -t proc proc $CHROOT_ROOT/proc
mount -t sysfs sysfs $CHROOT_ROOT/sys
mount -o bind /dev $CHROOT_ROOT/dev
# mount /dev using the following way if devtmpfs is enabled
# mount -t devtmpfs devtmpfs /dev $CHROOT_ROOT/dev
# mkdir -p $CHROOT_ROOT/dev/pts
mount -t devpts devpts $CHROOT_ROOT/dev/pts
chroot $CHROOT_ROOT /usr/bin/env -i /bin/bash
export HOME=/root
export PATH="/usr/bin:/usr/sbin:/bin:/sbin"
export TERM=xterm-256color
# fix apt network privilege issue on Android
usermod -g 3003 _apt
# set up X11 environment (display and touchscreen)
cat << EOF
Section "InputDevice"
Driver "evdev"
Identifier "touchscreen"
Option "Device" "/dev/input/event1"
EndSection
EOF | tee /usr/share/X11/xorg.conf.d/touchscreen.conf
cat << EOF
Section "ServerLayout"
Identifier "Layout0"
Screen "Screen0"
InputDevice "touchscreen" "Pointer"
EndSection
Section "Device"
Identifier "Card0"
Driver "fbdev"
Option "fbdev" "/dev/fb0"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Card0"
DefaultDepth 24
SubSection "Display"
Depth 32
EndSubSection
EndSection
Section "ServerFlags"
Option "Pixmap" "24"
EndSection
EOF | tee /usr/share/X11/xorg.conf.d/screen.conf
cat << EOF
#!/bin/sh
if [ -d /etc/X11/xinit/xinitrc.d ]; then
for f in /etc/X11/xinit/xinitrc.d/*; do
[ -x "$f" ] && . "$f"
done
unset f
fi
exec startxfce4
EOF | tee /root/.xinitrc
service dbus start
apt update
apt upgrade -y
apt install wget build-essential xfce4 xserver-xorg-video-fbdev xserver-xorg-input-evdev -y
cd $HOME
wget https://raw.githubusercontent.com/AsteroidOS/msm-fb-refresher/master/refresher.c
gcc refresher.c -o /usr/sbin/msm-fb-refresher
msm-fb-refresher --loop &
xinit &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment