Post Reply

Angry CM12 - building, optimising, fixing, having fun

OP sysKin

24th December 2014, 07:56 AM   |  #1  
sysKin's Avatar
OP Member
Thanks Meter: 45
 
51 posts
Join Date:Joined: Sep 2013
Hi all o/

To celebrate two weeks of my successful CM12 building and hacking, I'm starting this thread. Its purpose is to discuss general CM12 building steps for beginners like myself, bugs and fixes, applying @JustArchi's optimisation flags, solving the resulting build failures.... and all the other CM12/S4Mini-related questions that don't belong to F4k's [ROM] thread but end up there (I was guilty of that).

First of all, my thanks go to:
@arco68 for making it possible to build ROMs for our S4mini
CyanogenMod team for the ROM itself
@F4k for his kernel and all the other excellent contributions to this forum
@JustArchi for finding what he found

In this first post I will outline the steps needed to build a vanilla unofficial CM12 for serranoltexx. serranoltexx is the only device I have so this is what I'll introduce. I suspect building serrano3gxx is just as simple (just replace the device name in all the relevant steps). I don't know what to do to build for i9192, if you do please contribute

Building your own CM12 ROM

Main article: http://wiki.cyanogenmod.org/w/Build_for_serranoltexx

The article above tells you how to build CM11, but CM12 builds just as well with minor modifications I'll outline here. To follow those steps you need a Linux installation. I will write how you can make an example Lubuntu-based virtual machine on your Windows box in a post below.

Modifications to the build steps:
"Install the SDK" -- you can skip that, because in the end we will not use any SDK tools.
"Install the Build Packages" - replace jdk6 with jdk7 everywhere, as Java 7 is needed to build Lollipop.
"Create the directories" - I will assume you've followed those steps and everything is under ~/android/system/
"Initialize the CyanogenMod source repository" replace "cm-11.0" with "cm-12.0" of course
"Extract proprietary blobs" we will do this completely differently. If you try to use extract-files.sh, the script will fail, and when I finally fixed the script my camera didn't work...
So, do this instead (credit to @F4k and @kyrillos13 for answering my question on page 90 of F4k's ROM thread)

* Go to https://github.com/TheMuppets/propri...vendor_samsung
* Switch branch to cm-12.0
* Use the "Download ZIP" button to get the copy of the entire thing. The zip is big (500 MB? ish) and 95% of it useless for us, so if you're trying to save some bandwidth you can try to do this trick to get only the "serrano-common" folder. If you do, make a post here with exact steps for others
* Copy the "serrano-common" folder to ~/android/system/vendor/samsung/ (to clarify, final directory structure should include ~/android/system/vendor/samsung/serrano-common/proprietary/app/ folder among others)

"Turn on caching to speed up build" - sounds like a good idea but we're going to be playing with compiler options, which diminishes its usefulness. It also uses a lot of disk space. Only follow it if you want your daily increments to build fast, and you don't expect to be doing global changes such as optimisation flag changes often. I didn't do this step.

This concludes my first post in this thread. I personally have never had problems with building after this part (except when I had not enough space or memory) and the resulting vanilla builds always worked for me fine. Feel encouraged!

Next post: some tricks and useful commands
Last edited by sysKin; 24th December 2014 at 12:03 PM.
The Following 14 Users Say Thank You to sysKin For This Useful Post: [ View ]
24th December 2014, 07:58 AM   |  #2  
sysKin's Avatar
OP Member
Thanks Meter: 45
 
51 posts
Join Date:Joined: Sep 2013
A random selection of interesting things:

What recovery is good for applying my builds
Well they're all good, and they all work I bet. What I use is Phil's Touch and I'm on version 6.48.4 and it's worked perfectly.

How do I dirty flash my build on top of another CM12 build
I keep doing that since early F4k's builds and have no problems (yet!!). The trick is to only keep /data, while wiping everything else:
* Copy your newly build .zip file to your sdcard (you'll want to have a large enough sd card, I think)
* (if you want to) copy F4k's kernel and/or gapps too.
* Reboot your phone, go to recovery
* Backup your current phone. Seriously, never miss that step.
* Format /system (in Phil's Touch that's under "mounts and storage")
* Format /cache (as above)
* Select "install zip from sd card" and choose your ROM
* (if you want to) repeat "install zip from sd card" for F4k's kernel and/or gapps.
* Reboot your phone. It will take ~5 minutes or so for ART to re-compile all your apps

Soo my build didn't work. Wat do??
* Reboot to Recovery
* What I do is another backup. This gives me a nice archive containing my broken build, which I can later investigate
* Use recovery to restore the backup you've made before applying your build
* Reboot. You're back on a build that worked. Phew~
* (if you want to investigate) copy both backups (one that works and one that doesn't) to your PC. Uncompress the contents of /system for both, see if they obviously differ (such as one having binary blobs and one not lol).

Use F4k's kernel if you want to
Up to you, but here it is: https://s.basketbuild.com/devs/F4k/kernel_f4k-lp
I use it and as a result, I don't bother to optimise/improve CM12 kernel. I also don't care if I ever mis-compile CM12 kernel (not that it ever happens).

Gapps location
I use "mini" from here: https://s.basketbuild.com/devs/TKruz...05.0.1%20GApps and all I can say is that it worked for me so far.

I made some changes and I forgot what I did
Command "repo status" will give you a list of all the files you've modified across all the git repositories.

I made some changes to a file and I forgot how it looked before
Go to that file's directory (or at least its git repository, but it's somewhat hard to figure out what is the repository structure in your workspace) and issue "git diff" command. It will produce a diff file with all your changes.

I made some changes to a file and I want to undo that
Go to that file's directory and issue "git checkout [filename]" command. It will drop your changes and replace the file with original.

My build finished and I want to make a new, fresh, one
You want to say "make clean" before you do "brunch serranoltexx" again.

Coming up: Basic JustArchi-inspired optimisations
The Following 4 Users Say Thank You to sysKin For This Useful Post: [ View ]
24th December 2014, 07:59 AM   |  #3  
sysKin's Avatar
OP Member
Thanks Meter: 45
 
51 posts
Join Date:Joined: Sep 2013
Main article: http://forum.xda-developers.com/show....php?t=2754997

In the mid of 2014, @JustArchi recognised that all of Android has always been built with -Os option - meaning that the binaries are optimised for small size and not for execution speed. -Os is sometimes necessary (as it was on very early Android devices), but the "usual" build optimisation has always been -O2 meaning optimise for speed. Or -O3, which runs even more optimisations for speed (which might or might not help relative to O2 and will always make compilation slower).

Applying those optimisations has never been easier, because Lollipop is already built with GCC 4.8 (which was very highly recommended, but not in default toolchain, before). So all we need to do is activate -O3 by modifying some makefiles.

Does it do anything
In 0xbenchmark, several graphics-related tests (draw-arc, draw-circle) are up to six times faster. Does it matter? Dunno! But it's fun to see such a thing anyway!

What is THE most important file to modify?

Here: ~/android/system/build/core/combo/TARGET_linux-arm.mk

Line 70 defines "TARGET_arm_CFLAGS", this is the base compiler flags for *kernel* and starts with -O2. You can change that -O2 to -O3 if you want, but if you use F4k's kernel then it will do nothing in practice.

Line 77 defines TARGET_thumb_CFLAGS, this is the base compiler flags for android binaries. It clearly has -Os staring you in the face. Aha!! Change that to -O3 (or -O2) and you've just applied 90% of all compiler optimisations you can make. Build again. Your zip will be larger, this means it worked.

So I did that and it didn't finish building

Heh you're right, I lied. Unfortunately GCC is not as perfect as we'd wish and it will produce new errors or warnings with -O3 flag. Some of them make sense, some baffle me... Here's a list of what I had to change:

Error building android/system/frameworks//media/libstagefright/codecs/amrwbenc/src/isp_az.c, compiler detects array index out of bounds
It doesn't make any sense if you ask me (and I stared at the code a lot). There are two arrays f1 and f2. f1 has size [NC16k + 1] and f2 has size [NC16k], and if f1 is big enough then f2 should be big enough, but GCC disagrees.
For an off chance that GCC is right, I made f2 bigger [NC16k + 1]. Since nobody does sizeof(f2) it causes no change in logic, it marely allocates one extra (unused) word on stack. Made GCC happy.

Error building android/system/frameworks/media/libstagefright/codecs/m4v_h263/dec/src/deringing_[chroma|luma].cpp, cryptic "assuming when assuming" message
Another weird one. It *seems* to me that GCC unrolled a loop, and then looked at the unrolled loop index condition and concluded it's dumb after the unrolling, and complains. Modify:
android/system/frameworks/media/libstagefright/codecs/m4v_h263/dec/Android.mk
Find line: Local_CFLAGS += -Werror
Replace with: Local_CFLAGS += -Werror -Wno-error=strict-overflow

Error linking libhwcomposer, symbols "configRotator", "configMdp" and "updateSource" not found
Those three functions are defined with |inline| in the c files, but without |inline| in header files, and linker can't find them (dunno why it works with -Os). Open:
~/android/system/hardware/qcom/display-caf/msm8960/libhwcomposer/hwc_utils.cpp
Line 1238, remove "inline"
Line 1309, remove "inline"
Line 1335, remove "inline"

That is all, should build now!

Anything else uses -Os?

Yes, there's a bunch of Android.mk files that locally override the -O3 flag we just set with -Os (or -O2). You can make a global search, but here's a list of some important ones:
* every makefile under external/chromium_org/. This is the built-in web browser and unfortunately every single makefile does the override, and there's over9000 of them. If you want to change them all, you probably want to write a script of some sort. If you do, share one here lol.

* third_party/android_crazy_linker/src/Android.mk, adds -Os to LOCAL_CFLAGS. I do not know what crazy linker is, but if you want that to be bigger and faster, change that to -O3.

* third_party/zlib/zlib.target.linux-arm.mk, adds -Os to MY_CFLAGS_Release. Zlib sounds like something that should be fast, change that to -O3.

* modules/audio_processing/ lots of .mk files use -Os. How weird. You're only interested in *.target.linux-arm.mk, other targets do not apply to us.

* external/... some of the Android.mk files there use -Os. Some seem to matter.

Phew ~ next up: some more interesting optimisations that worked for me.
Last edited by sysKin; 24th December 2014 at 08:29 AM.
The Following 4 Users Say Thank You to sysKin For This Useful Post: [ View ]
24th December 2014, 08:52 AM   |  #4  
sysKin's Avatar
OP Member
Thanks Meter: 45
 
51 posts
Join Date:Joined: Sep 2013
Compile for cortex-a15 target

The CPU in our S4mini is called Krait. It's neither Cortex-A9 nor Cortex-A15, but it's supposed to be similar to A15. However, the CM12 build system does not have an appropriate entry for Krait and defaults to generic A7+Neon, a choice that is not VERY bad but presumably not optimal either.

Go to file: ~/android/system/build/core/combo/arch/arm/armv7-a-neon.mk
You see a sequence of "if CPU is this, set march to this". Add one more (say, line 21):
ifeq ($(strip $(TARGET_$(combo_2nd_arch_prefix)CPU_VARIANT)), krait)
arch_variant_cflags := -mcpu=cortex-a15
else
....and add a corresponding endif in the final sequence of endifs. Your compilers will now optimize for Cortex-A15.

Activate neon vector extensions
(OK this doesn't work on CM12, it used to work for me on CM 10.2. Call it a WIP idea)
In the same file ~/android/system/build/core/combo/arch/arm/armv7-a-neon.mk, on the bottom, it says:
-mfpu=neon
However, our Krait can do better and this could be replaced with mfpu=neon-vfpv4. HOWEVER, while GCC is OK with that, clang is not for some reason and fails. Any ideas?

Activate linker optimisations
In the in file: build/core/combo/select.mk there's room for some linker parameters.
Find the line that says:
$(combo_var_prefix)GLOBAL_LDFLAGS :=
and change it to:
$(combo_var_prefix)GLOBAL_LDFLAGS := -Wl,-O1
(that's: dash whiskey lima comma dash oscar one, no spaces, in case it's not readable)
I do not know what kind of optimisations linker makes, but this parameter asks it to make them.
Last edited by sysKin; 24th December 2014 at 09:07 AM.
The Following 4 Users Say Thank You to sysKin For This Useful Post: [ View ]
24th December 2014, 09:53 AM   |  #5  
Member
Thanks Meter: 24
 
99 posts
Join Date:Joined: Feb 2014
Thanks a lot for this helpful and informative how-to. This is really appreciated if one likes to build the rom on his own.

Regards!
24th December 2014, 11:51 AM   |  #6  
Senior Member
Thanks Meter: 82
 
316 posts
Join Date:Joined: Jul 2013
where can i download YOUR build of cm12?
24th December 2014, 01:58 PM   |  #7  
Member
Thanks Meter: 3
 
53 posts
Join Date:Joined: Feb 2013
well done!
24th December 2014, 02:10 PM   |  #8  
parthabhatta's Avatar
Senior Member
Flag Calcutta
Thanks Meter: 123
 
1,026 posts
Join Date:Joined: Mar 2008
More
This is a great write up. Anybody contributing for necessary mods required for duos will value add
24th December 2014, 02:12 PM   |  #9  
sysKin's Avatar
OP Member
Thanks Meter: 45
 
51 posts
Join Date:Joined: Sep 2013
I'm glad you guys like it I'll post some more tomorrow.

Quote:
Originally Posted by Howdareme

where can i download YOUR build of cm12?

Mine? I don't upload them anywhere because I don't see much point, making a near-identical copy of F4k's rom. Plus I am very lazy ;ppp

Now, to say something useful: if you're building any time soon, you might want to include this patch: http://review.cyanogenmod.org/#/c/82572/
It seems like there's a serious resource leak any time you switch your screen off.
The Following User Says Thank You to sysKin For This Useful Post: [ View ]
26th December 2014, 05:47 AM   |  #10  
Senior Member
Thanks Meter: 23
 
128 posts
Join Date:Joined: Jan 2014
Thanks for sharing this wonderful information!


Quote:
Originally Posted by sysKin

* Go to https://github.com/TheMuppets/propri...vendor_samsung
* Switch branch to cm-12.0
* Use the "Download ZIP" button to get the copy of the entire thing.

You might wanna consider adding that repo to a local manifest instead. See also @k2wls excellent guide: How to make your own CM-11.0 for your S4 mini

The Following User Says Thank You to aguaz For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes