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,firmware,basic_rootfs/{ubuntu-base,alpine}},mnt,rootfs/{alpine,ubuntu,buildroot}}
go into bringup directory:
cd bringup

update stock rom

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
download and extract VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml.zip into droid4/archives/stock_rom:
wget https://maedevu.maemo.org/images/droid4/VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml.zip -P archives/stock_rom/droid4
unzip archives/stock_rom/droid4/VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml.zip -d archives/stock_rom/droid4
rm archives/stock_rom/droid4/VRZ_XT894_9.8.2O-72_VZW-18-8_CFC.xml.zip

download Tony Lindgren script for update the stock_rom:
wget -P archives/stock_rom/droid4 -c wget https://raw.githubusercontent.com/omerlle/droid4-bringup/alpine/boot/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
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:

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.13 v5.4.13
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.13"
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:

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.11/releases/armv7/alpine-minirootfs-3.11.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
download bluetooth firmware:
wget -c https://github.com/TI-ECS/bt-firmware/raw/master/TIInit_10.6.15.bts -P archives/firmware/ti-connectivity
choose name to rootfs directory and create it:
mkdir ${droid_rootfs}

extract alpine minimal rootfs into the directory:
sudo tar -xzf archives/basic_rootfs/alpine/alpine-minirootfs-3.11.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 linux-firmware wpa_supplicant bluez wireless-tools
pip3 install --upgrade pip
pip3 install evdev

config network:
echo droid4 > /etc/hostname
echo " 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:
[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:
unmount /proc and /dev from the rootfs:
sudo umount ${droid_rootfs}/dev
sudo umount ${droid_rootfs}/proc

copy TIInit_10.6.15 to the rootfs:
sudo cp archives/firmware/ti-connectivity/TIInit_10.6.15.bts ${droid_rootfs}/lib/firmware/ti-connectivity/

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:
when you are sure what the name of the sd replace the “mmcblk0” keyword with your name and run the following commands:
set -u
mount | grep /dev/$sdcard | cut -d ' ' -f 3 | xargs umount
echo "1 : start= 2048, size= 102400, type=83
2 : start= 104448, size= 4194304, type=83
3 : start= 4298752, size= $(($(cat /sys/block/$sdcard/size)-4298752)), type=83" | sudo sfdisk /dev/$sdcard
sudo partprobe /dev/${sdcard}
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:
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:
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:
sudo umount mnt

return to your original path:
that it, insert the sdcard to the phone and turn it on(you need to wait couple of minute.
for droid4 usage you can see droid4-alpine-usage.