[Miscellaneous Android Development] yuweng:
BoardConfig.mk optional build flags

You can always find all the detail for building PhilZ Touch with optional build flags here & available screen resolutions here . . . :good: If your screen res is not available then choose the one nearest to your device res.

Others undocumented flags such as below can be found here

BATTERY_LEVEL_PATH
BOARD_POST_UNBLANK_COMMAND
RECOVERY_TOUCHSCREEN_SWAP_XY
RECOVERY_TOUCHSCREEN_FLIP_X
RECOVERY_TOUCHSCREEN_FLIP_Y
BOARD_USE_B_SLOT_PROTOCOL
BOARD_HAS_NO_FB2PNG
BOARD_RECOVERY_BLDRMSG_OFFSET
ENABLE_LOKI_RECOVERY
BOARD_CUSTOM_RECOVERY_KEYMAPPING
BOARD_CUSTOM_RECOVERY_UI
TARGET_USERIMAGES_USE_F2FS
BOARD_USES_BML_OVER_MTD
TARGET_USERIMAGES_USE_F2FS
NO_AROMA_FILE_MANAGER

To use any of these optional build flags, typically is just to add a true at the back

Eg : BOARD_HAS_NO_FB2PNG : = true to your BoardConfig.mk

Flags like BRIGHTNESS_SYS_FILE obviously then you'll need to find out the path ONLY when it doesn't work. For most android devices BRIGHTNESS_SYS_FILE := "/sys/class/backlight/panel/brightness" should work.

Use adb shell su -c "ls -R" > myandroid.txt to find out where is your BRIGHTNESS_SYS_FILE. This command will list out your whole android device directory so it shall give you some clues for the lun file path needed to mount both the sdcard too, typically this will work for most devices.

Below flags is to set different graphics modes that may be needed to correct colours on some devices. Use only when your compiled PhilZ Touch has some weird looking colours or graphics & try one at a time but not all at the same time !

TARGET_RECOVERY_PIXEL_FORMAT := "BGRA_8888"
TARGET_RECOVERY_PIXEL_FORMAT := "RGBX_8888"
TARGET_RECOVERY_PIXEL_FORMAT := "RGB_565"

Note

If your kernel doesn't support NTFS-3G then you must use this build flag BOARD_USE_NTFS_3G := false or your compiled PhilZ Touch most probably won't boot

recovery.fstab

PhilZ Touch uses recovery.fstab v2 & if you use recovery.fstab v1 then most probably it won't boot.

Always refer to here to look for the closes siblings to your device.

If your device doesn't have any cm tree, you can still find out alot of info from your stock recovery.img. Use Repack Utils or Android Image Kitchen to unpack your stock recovery.img & look at /etc/recovery.fstab to look for clues . . . :good: Unpack PhilZ Touch built by other DEV too & see how they did it . . . google is your best friend so hunt for it.

Typically you'll only need to backup boot, system, data & cache partition only. Later when you have succeeded in building PhilZ Touch for your device then you can add other optional partition. Typically basic recovery.fstab is good enough, it will be able to restore your device back to a working state. You will also need to identify the correct internal & external sdcard path too so that PhilZ Touch can make backup to either one. Note : This is not the same path as BoardConfig.mk refer to this Eg. here.

Use adb commands such as below to find out more about your device partition . . .

adb shell cat /proc/partitions
adb shell cat /proc/mtd
adb shell cat /proc/emmc
adb shell cat /proc/dumchar_info
adb shell cat /proc/cmdline
adb shell cat /proc/mounts
adb shell cat /proc/devices
adb shell ls -al /dev/block
adb shell df

If your device already have a working CWM then you can also check the existing recovery.fstab by rebooting to recovery & use below command.

adb shell cat /etc/recovery.fstab

Updates

adb shell su -c "ls -R" > myandroid.txt will tell you alot of infos regarding your device. Just found out on MTK, below can also be use for PhilZ Touch.

# Android fstab file.
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK

#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>
/dev/bootimg /bootimg emmc defaults defaults
/dev/recovery /recovery emmc defaults defaults
/dev/uboot /uboot emmc defaults defaults
[COLOR="Blue"]/dev/block/platform/mtk-sd.0/by-num/p3[/COLOR] /system ext4 ro,noatime wait
[COLOR="blue"]/dev/block/platform/mtk-sd.0/by-num/p4[/COLOR] /cache ext4 noatime,nosuid,nodev,noauto_da_alloc wait
[COLOR="blue"]/dev/block/platform/mtk-sd.0/by-num/p5[/COLOR] /data ext4 noatime,nosuid,nodev,noauto_da_alloc wait,encryptable=footer

[COLOR="blue"]/dev/block/platform/mtk-sd.0/by-num/p6[/COLOR] auto vfat defaults voldmanaged=sdcard0:auto
[COLOR="blue"]/dev/block/platform/mtk-sd.1/by-num/p1[/COLOR] auto vfat defaults voldmanaged=sdcard1:auto

OR

# Android fstab file.
# The filesystem that contains the filesystem checker binary (typically /system) cannot
# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK

#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>
/dev/bootimg /bootimg emmc defaults defaults
/dev/recovery /recovery emmc defaults defaults
/dev/uboot /uboot emmc defaults defaults
[COLOR="blue"]/dev/block/mmcblk0p3[/COLOR] /system ext4 ro,noatime wait
[COLOR="blue"]/dev/block/mmcblk0p4[/COLOR] /cache ext4 noatime,nosuid,nodev,noauto_da_alloc wait
[COLOR="blue"]/dev/block/mmcblk0p5[/COLOR] /data ext4 noatime,nosuid,nodev,noauto_da_alloc wait,encryptable=footer

[COLOR="blue"]/dev/block/mmcblk0p6[/COLOR] auto vfat defaults voldmanaged=sdcard0:auto
[COLOR="blue"]/dev/block/mmcblk1p1[/COLOR] auto vfat defaults voldmanaged=sdcard1:auto

WARNING

This could be the single most important part when it comes to building PhilZ Touch recovery.

If you wrongly use the path for recovery.fstab the outcome could be disasterous !

GIGO so please do some research first, you have been fore-warned . . . :cool:

Part-Source

i wrote this simple script that will only sync the needed projects for building PhilZ Touch, no matter how cm projects grows it will still sync only the 40 needed projects . . . :cowboy:

As mentioned at the script, if it doesn't build then obviously some of the remove projects are needed then look for clues at the build ERROR1.

There are two methods to rectify it. Eg. If the build ERROR1 something about bash . . .

Method 1

Open ~/cm11/.repo/local_manifests/local_manifest.xml, look for any keyword bash & add remarks as below or just delete that whole line, do a repo sync again & it will download & auto-extract it to ~/cm11/external/bash

[COLOR="blue"]<!--[/COLOR] <remove-project name="CyanogenMod/android_external_bash" /> [COLOR="blue"]-->[/COLOR]

Method 2

Open PhilZ script, add as below to Line 22, run the script again & it will do everything automatically for you . . . :cool:

grep -v [COLOR="blue"]bash[/COLOR] ~/Documents/x>~/Documents/x.tmp;mv ~/Documents/x.tmp ~/Documents/x

You can also add additional needed projects to Line 82 too, just follow Line 81 for reference . . .

ARM11

ARM11 AKA ARMv6 boots on PhilZ Touch too, thanks to the androidarmv6 development team . . . :good:

Add the below to Line 82, delete whole ~/cm11/bionic folder, add a # remark to bionic & execute PhilZ script to sync the Part-Source needed to build for arm11 devices

echo -e "<project path=\"bionic\" name=\"androidarmv6/android_bionic\" revision=\"cm-11.0\" />" >> ~/Documents/x

[COLOR="Red"]#[/COLOR]grep -v bionic ~/Documents/x>~/Documents/x.tmp;mv ~/Documents/x.tmp ~/Documents/x

You will also need to edit BoardConfig.mk as below for compiling PhilZ Touch for arm11 devices

TARGET_CPU_ABI := [COLOR="blue"]armeabi-v6l[/COLOR]
TARGET_ARCH_VARIANT := [COLOR="blue"]armv6-vfp[/COLOR]
TARGET_CPU_VARIANT := [COLOR="blue"]arm11[/COLOR]
[COLOR="Red"]#[/COLOR]ARCH_ARM_HAVE_TLS_REGISTER := true [COLOR="blue"]<- Most [COLOR="Blue"]arm11[/COLOR] devices doesn't have [URL="http://arowboat.wordpress.com/2011/08/10/android-linux-arm-and-tls-register-emulation/"]TLS[/URL] & if you enable it then it won't boot ![/COLOR]

Syncing Part-Source on Ubuntu or other Distro

Open Terminal & type export PATH=~/bin:$PATH first then only it'll sync correctly provided you have setup the BE correctly BUT don't come ERROR reporting here as this thread details building PhilZ Touch on BBQLinux only . . . :cool:

You are completely on your own so please look for solutions here or hunt for similar solutions here on XDA, tons of guides for building on Ubuntu & other distro . . . :cowboy:

Why use other Distro when you have BBQLinux which is specifically made for Android development by codeworkx . . . :good:

Build cm kernel

If your device have cm kernel source then un-remark Line 68, 69 & update the necessary device specific flags, defconfig & SELinux . . .

Misc Tips

Factory ROM Back Up

Always google & research how to make a Factory ROM back up for your device & always make at least x3 so that in case one corrupted, you still have another two . . . :cowboy:

Typically, you'll find all these infos at your vendors website such as Sony Devices, HTC Devices, Samsung Devices & etc.

Many vendors also offer firmware updates too at their website such as Motorola & you should have a copy before even starting modding your device !

Files from vendor

To be able to install update.zip from your vendor then you'll need to do some minor editing.

adb shell "getprop ro.product.model"
adb shell "getprop ro.product.device"

or refer to your build.prop for

ro.product.model=[COLOR="blue"]Lenovo S939[/COLOR]
ro.product.device=[COLOR="blue"]S939[/COLOR]

and update it accordingly to default.prop at compiled PhilZ Touch

Alternate commands

For building recovery

cd ~/cm11
export USE_CCACHE=1
prebuilts/misc/linux-x86/ccache/ccache -M 50G
source build/envsetup.sh

source build/tools/device/makerecoveries.sh cm_[COLOR="Red"]S939[/COLOR]-eng [COLOR="Blue"]<- Change accordingly to your [COLOR="red"]device_name[/COLOR][/COLOR][COLOR="Blue"]
OR[/COLOR]
lunch cm_[COLOR="Blue"]S939[/COLOR]-eng [COLOR="Red"]<- Change accordingly to your [COLOR="blue"]device_name[/COLOR][/COLOR]
mka recoveryimage [COLOR="blue"]<- Thanks to [B]RD[/B] [URL="http://xdaforums.com/showpost.php?p=55295969&postcount=15"]PlayfulGod[/URL]. More info [URL="http://wiki.cyanogenmod.org/w/Envsetup_help#mka"]refer to here[/URL][/COLOR]

Sync corruption

git & repo is like a Super Intelligent Source Code Auto-Resume Downloader when working together . . . :good:

You can stop it at any time, restart it back & it will auto-resume.

cm-11.0 repo & source code is located at ~/cm11/.repo, it is a hidden folder & to view hidden folder via caja, you need to press Ctrl + h

Sometimes you have corruption then repo sync wouldn't work & normally you just need to delete manifests, manifests.git, manifests.xml with a repo init & repo sync then you'll be back to normal.

If still this doesn't solve the problem then delete everything EXCEPT the folder project-objects & projects, both of this is the actual source code folder.

After this a repo init then repo sync & everything will be back to normal, i guarantee, done this many times, no worries . . . :laugh:

Make a secondary HDD & backup this hidden folder .repo & in case of OS corruption then you can anytime just copy it back to ~/cm11/.repo, repo init, repo sync & you'll have the whole cm-11.0 source code in a few minutes, no need to download it all over again. Make a backup of your bbqlinux.vdi too . . . :good:

cd ~/cm11
repo init -u git://github.com/CyanogenMod/android.git -b cm-11.0
repo sync -f -j8 [COLOR="Red"]<- You can increase this to parallel download but if ERROR then lower it[/COLOR]

git checkout

git & github again when working together is like a Super Intelligent Source Code Reviewer & Tracker.

For Eg. 6.57.5 doesn't boot while your previous compiled 6.56.8 boots.

You can use git checkout to revert it back to 6.56.8 to confirm it.

cd ~/cm11/bootable/recovery
git log [COLOR="Red"]<- Press [B]Enter[/B] to scroll & [B]Ctrl[/B] + [B]z[/B] to break[/COLOR]
git checkout [COLOR="blue"]86a7b310c2eadabbcbcd99243fc66bb197132446[/COLOR]

Screenshot

View attachment 2930541

OR

git checkout [COLOR="blue"]86a7b31[/COLOR]

Screenshot

View attachment 2930542

You can always review Phil3759 latest commits here . . .

To check your PhilZ Touch currently at which commits

cd ~/cm11/bootable/recovery
git log -1

When it boots then git checkout the next newer commits, this way you'll be able to pinpoint which commits is the culprit.

If still it doesn't boot then there is definitely something wrong with your setup . . . :laugh:

Make clean

For building PhilZ Touch you don't really have to make clean before each new build. I've notice many DEV uses various make clean commands as listed below . . .

cd ~/cm11
make clean
make clobber
make dataclean
make installclean
make -j4 clean dataclean installclean

make clean = Wipe everything inside ~/cm11/out & it will take you another 30 to 45 min to recompile if you didn't use ccache ! Just manually delete the device folder at $OUT will do.

Eg. ~/cm11/out/target/product/S939 <- just manually delete S939 folder will do

This will speed up the whole build process on the next build & typically, it will only take 2 minutes to rebuild . . . :laugh: i've wrote a script that automatically & continuously for building PhilZ Touch for MTK arm11, cortex-a9 & cortex-a7, all boots, all without make clean only remove the device folder at $OUT . . . :cool:

With ccache typically it will take 5 to 10 min after each make clean

Compiled recovery.img

If your SoC is not Qualcomm then most probably the compiled recovery.img will not boot b'cos it is not pack to your device format.

Eg. MTK & Sony Xperia L

So you'll need to find out how to repack it back to your device format then only it will boot ! Unless a DEV has already develop the format, refer to here for Eg . . .

Many doesn't know that ramdisk-recovery.img is actually the ramdisk repacked gzip file. Use below command to extract it.

cd ~/cm11
source build/envsetup.sh
lunch cm_[COLOR="Red"]S939[/COLOR]-eng <- Change accordingly to your [COLOR="red"]device_name[/COLOR]
cd $OUT
mkdir ramdisk
cd ramdisk
gzip -dc ../ramdisk-recovery.img | cpio -i

Or you can also make all the necessary editing to $OUT/recovery/root then repack it to gzip

Typical command

cd $OUT/recovery/root
find . | cpio -o -H newc | gzip > ../../newramdisk.cpio.gz

i don't own all android devices on the market so i donno what are the commands or procedures that will work for your device, you will have to find that out yourself. Typical repacking command

cd $OUT
mkbootimg --kernel kernel --ramdisk newramdisk.cpio.gz -o new_recovery.img

Again, google is your best friend . . .

Error reporting

Before reporting an error always look for solutions at Q&A here as most of them has already been answered. As mentioned, google is your best friend so go & hunt for it.

When you bump into an obstacle, typically you would wanna solve it ASAP. Try taking a break then come back a few days later & Voila, the answer will be right in front of you ! Trust me, provided you did google it . . . :cowboy:

Compilation error

If you have compilations error then refer to the compile.log & look for clues.

make -j8 recoveryimage 2>&1 | tee ~/Documents/[COLOR="Blue"]compile.log[/COLOR]

Typically, it will be a few line above ERROR1. Sometime you may need to scroll up a bit more & sometimes the build error doesn't hint anything at all !

For example below, i have remove bison

prebuilts/misc/linux-x86/bison/[COLOR="blue"]bison[/COLOR] -d -o /home/yuweng/cm11/out/target/product/MediaTek/obj/STATIC_LIBRARIES/libedify_intermediates/parser.cpp bootable/recovery/edify/parser.y
target thumb C: libminzip <= bootable/recovery/minzip/SysUtil.c
prebuilts/misc/linux-x86/bison/[COLOR="Blue"]bison[/COLOR]: external/bison/data/m4sugar/m4sugar.m4: cannot open: No such file or directory
build/core/binary.mk:375: recipe for target '/home/yuweng/cm11/out/target/product/MediaTek/obj/STATIC_LIBRARIES/libedify_intermediates/parser.cpp' failed
make: *** [/home/yuweng/cm11/out/target/product/MediaTek/obj/STATIC_LIBRARIES/libedify_intermediates/parser.cpp] [COLOR="Red"]Error 1[/COLOR]
make: *** Waiting for unfinished jobs....

Part-Source as of Aug 2014, builds working PhilZ Touch & if later it doesn't then always refer to here as Phil3759 might add new feature that requires additional projects.

Always refer to compile.log & build ERROR1 should give some hints, again, if it doesn't then google is your best friend . . . :laugh:

Error log

If compiled PhilZ Touch boots with a blank screen & adb is working then you can still get a log out of it.

adb shell pull /tmp/recovery.log

You can also try below command to capture screenshot while at PhilZ Touch

adb shell /sbin/fb2png
adb pull /data/local/fbdump.png

If compiled PhilZ Touch boots with GUI then you can generate error reporting. Advanced Functions -> Report Error.

adb commands

Sometimes you need kill adb first then only it will connect. Try below commands

adb kill-server
adb start-server
adb devices
adb reboot
adb reboot recovery

What to do when reporting error

A single line reply Unfortunately it doesn't work won't help.

Always provide as much info as possible, attach your BoardConfig.mk, recovery.fstab or any mkvendor.sh files that you have edited, attach compile.log, attach PhilZ Touch generated recovery.log this will help in trouble-shooting, identifying & solving your problems.

Credits

Phil3759 for continuously developing, improving & maintaining PhilZ Touch . . . :good:

Daniel Hillenbrand AKA codeworkx for continuously developing, improving & maintaining BBQLinux . . . :good:

CyanogenMod Team & contributors for continuously developing, improving & maintaining CyanogenMod repo . . . :good:

Samantha for doing a coverage of this thread at the XDA Portal . . . :good:

Last but not least, my Master Shifu Carliv who has taught me how to compile from source & continuously guiding me to the right direction . . . :good:

Give credit where credit is due . . . :good: