droid4 alpine-bring up

Note:Modifying or replacing your device’s software will void your device’s warranty, and can cause to damage to the device and to your computer or losing data(of device and computer), execute the following commands is entirely at your own risk.



Note:this guide try to apply the bringup of droid4 flowing Tony Lindgren blog. there still missing parts such as camera or connact to internet, that i hope that will fill up in the next time

requires:linux computer,Motorola Droid4(XT894),sdcard(more then 3G),usb cable.

optional-Debug UART

you need also a micro-USB-B breakout board and USB-TTL Adapter with 3.3V signal-A detailed explanation is available in Tony Lindgren blog Debug UART.

get started

go to the path that you want to create the project(replace “/path/to/project/” with the path):
pushd /path/to/project/
create directory hierarchy structure for boot components:
install -d bringup/{linux/{linux-stable,images},mnt,archives/{stock_rom/droid4,kexecboot/droid4,buildroot,basic_rootfs/{ubuntu-base,alpine}},mnt,rootfs/{alpine,ubuntu,buildroot}}
go into bringup directory:
cd bringup

update stock rom

this part is also describe in Sebastian Reichel blog in elektranox.org

first of all we need to update the stock rom to VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml.zip.
for that we need fastboot, if you don’t have fastboot you can install it by:
sudo apt-get install android-tools-fastboot
you can download VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml.zip from mega.nz(you can find more site in forum.xda-developers.com) extract it into droid4/archives/stock_rom
after download you can use the command(you can replace “~/Downloads” in your download path):
unzip ~/Downloads/VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml.zip -d archives/stock_rom/droid4
download Tony Lindgren script for update the stock_rom:
wget -P archives/stock_rom/droid4 -c http://elektranox.org/files/flash-droid-4-fw.sh
turn on the device by press on Vol Down & Power buttons this will go into Fastboot mode(the first line in the screen is:”AP Fastboot Flash Mode (S)”)
connect the device to the computer via usb and make sure the bottom lines are “Transfer Mode: USB Connected”
make sure you see the device by the command:
fastboot devices
the output supposed to be something like:
0123456789ABCDEF fastboot
if you get this output:
permissions fastboot
try:
sudo fastboot devices
if it solve the problem change the script to run “sudo fastboot” by the command:
sed -i 's/fastboot=fastboot/fastboot="sudo fastboot"/' archives/stock_rom/droid4/flash-droid-4-fw.sh
go into VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml directory:
pushd archives/stock_rom/droid4/VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml
and run the script:
bash ../flash-droid-4-fw.sh
return to base directory by:
popd

install Kexecboot bootloader

if you don’t have git you can install it by:
sudo apt-get install git
clone Tony Lindgren repository for droid4 kexecboot by the command:
git clone https://github.com/tmlind/droid4-kexecboot.git archives/kexecboot/droid4/
install the Kexecboot by the commands(you can remove sudo keyword if you don’t need sudo for fastboot)[my current version is 2018-05-06]:
sudo fastboot flash mbm archives/stock_rom/droid4/VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml/allow-mbmloader-flashing-mbm.bin
sudo fastboot reboot bootloader
sudo fastboot flash bpsw archives/kexecboot/droid4/current/droid4-kexecboot.img
sudo fastboot flash utags archives/kexecboot/droid4/utags-mmcblk1p13.bin
sudo fastboot flash mbm archives/stock_rom/droid4/VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml/mbm.bin

you can poweroff the device for now by press Power button

build kernel

if you don’t have the following tools you can install it by:
sudo apt-get install libncurses5-dev make exuberant-ctags bc libssl-dev
and the arm cross compailer:
apt-get install gcc-arm-linux-gnueabihf
clone upstream repository:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux/linux-stable
go into linux-stable:
pushd linux/linux-stable
checkout the latest stable kernel branch(you can see the tag via “git tag -l“)
git checkout -b local/v5.4.2 v5.4.2
fetch Tony Lindgren repository for voice calls and gnss serdev driver patches:
git remote add linux-omap git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git
git fetch linux-omap

merge mdm branch:
git merge linux-omap/droid4-pending-v5.4 -m "Merge remote-tracking branch 'linux-omap/droid4-pending-v5.4' into local/v5.4.2"
setup your default kernel configuration:
make ARCH=arm omap2plus_defconfig
compaile the kernel:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- omap4-droid4-xt894.dtb bzImage modules -j9
return to base directory by:
popd

build rootfs

you can create a ubuntu rootfs instead of alpine rootfs following this page
install qemu-user-static arm emulator:
sudo apt-get install qemu-user-static
download the alpine minimal rootfs archive:
wget -P archives/basic_rootfs/alpine/ -c http://dl-cdn.alpinelinux.org/alpine/v3.10/releases/armv7/alpine-minirootfs-3.10.3-armv7.tar.gz
clone bringup repository for droid4 more rootfs scripts:
git clone https://github.com/omerlle/droid4-bringup.git archives/droid4_bringup
checkout the alpine branch:
git -C archives/droid4_bringup/ checkout alpine
choose name to rootfs directory and create it:
droid_rootfs="$PWD/rootfs/alpine/3.10.3_armv7"
mkdir ${droid_rootfs}

extract alpine minimal rootfs into the directory:
sudo tar -xzf archives/basic_rootfs/alpine/alpine-minirootfs-3.10.3-armv7.tar.gz -C ${droid_rootfs}/
add usage scripts:
sudo rsync -a --chown=root:root archives/droid4_bringup/overlay/ ${droid_rootfs}
add files and mount some directories for chroot work properly:
sudo cp /etc/resolv.conf ${droid_rootfs}/etc/
sudo cp -a /usr/bin/qemu-arm-static ${droid_rootfs}/usr/bin/
sudo mount -t proc /proc ${droid_rootfs}/proc
sudo mount -o bind /dev ${droid_rootfs}/dev

run chroot to config the rootfs on pc:
sudo chroot ${droid_rootfs} sh
install useful packages:
apk update
apk upgrade
apk add bash openrc udev openssh python3 alsa-utils util-linux rsync xorg-server xinit i3wm evince xterm tmux eog linux-headers build-base python3-dev sqlite kbd libqmi emacs
pip3 install evdev

config network:
echo droid4 > /etc/hostname
echo "127.0.0.1 droid4" >> /etc/hosts
sed -i 's/^#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

add some rc scripts:
rc-update add devfs sysinit
rc-update add sysfs boot
rc-update add hwclock boot
rc-update add hostname boot
rc-update add bootmisc boot
rc-update add sshd default
rc-update add droid4-startup default
rc-update add droid4-usb default
rc-update add droid4-modem-app default
rc-update add droid4-buttons-handle default

mount mass storage directory /root/user_data:
echo "/dev/mmcblk0p3 /root/user_data vfat defaults" >> /etc/fstab
set the databases:
sqlite3 /root/.droid4/hardware.db < /usr/local/share/droid4/python3_packages/hardware/config/hardware_db.back
sqlite3 /tmp/modem.db < /usr/local/share/droid4/python3_packages/modem/config/modem_db.back

set the password for root user:
passwd
[for uart debug:echo ttyS2 >> /etc/securetty;sed -i 's/^#ttyS0\:\:respawn\:\/sbin\/getty -L ttyS0 115200 vt100/ttyS2\:\:respawn\:\/sbin\/getty -L ttyS2 115200 vt100/' /etc/inittab]
exit from chroot:
exit
unmount /proc and /dev from the rootfs:
sudo umount ${droid_rootfs}/dev
sudo umount ${droid_rootfs}/proc

create bootable sd

format the sdcard:

note:this part is very dangerous because you can erase your hard disk if you will not do it right

use this command to figure out your sdcard name, you need be sure it appear and disappear when you connect it and disconnect it otherwise you can erase important data:
lsblk
when you are sure what the name of the sd replace the “mmcblk0” keyword with your name and run the following commands:
sdcard="mmcblk0"
set -u
mount | grep /dev/$sdcard | cut -d ' ' -f 3 | xargs umount
echo "1 : start= 2048, size= 102400, type=83
2 : start= 104448, size= 2097152, type=83
3 : start= 2201600, size= $(($(cat /sys/block/$sdcard/size)-2201600)), type=83" | sudo sfdisk /dev/$sdcard
sudo partprobe /dev/mmcblk0
sudo mkfs.vfat /dev/${sdcard}p1 -n BOOT
sudo mkfs.ext4 /dev/${sdcard}p2 -L rootfs
sudo mkfs.vfat /dev/${sdcard}p3 -n USER_DATA
set +u

mount the first partition of sdcard:
sudo mount /dev/${sdcard}p1 mnt
copy the boot components:
sudo rsync --chown=root:root archives/droid4_bringup/boot/boot.cfg linux/linux-stable/arch/arm/boot/zImage linux/linux-stable/arch/arm/boot/dts/omap4-droid4-xt894.dtb mnt/boot
[for uart debug:sudo rsync --chown=root:root archives/droid4_bringup/boot/boot.cfg.uart mnt/boot/boot.cfg ]
unmount the first partition of sdcard and mount the second partition:
sync
sudo umount mnt
sudo mount /dev/${sdcard}p2 mnt

copy the rootfs to the second partition:
sudo rsync --delete -av ${droid_rootfs}/ mnt/
install the modules in the rootfs:
sudo make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules_install INSTALL_MOD_PATH=${PWD}/mnt/ -C linux/linux-stable
save and umount the second partition of sdcard and mount the third partition:
sync
sudo umount mnt
sudo mount /dev/${sdcard}p3 mnt

copy the rootfs to the third partition:
sudo install -d mnt/droid4/modem/{dynamic_data,logs}
sudo mv ${droid_rootfs}/tmp/modem.db mnt/droid4/modem/dynamic_data/

save and umount the third partition:
sync
sudo umount mnt

return to your original path:
popd
that it, insert the sdcard to the phone and turn it on(you need to wait couple of minute.